add-edit.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. <?php
  2. use common\helpers\ComponentHelper;
  3. ComponentHelper::loadComponentView('com-dialog-activity');
  4. ComponentHelper::loadComponentView('com-image');
  5. ?>
  6. <style>
  7. .form-body {
  8. padding: 20px 0;
  9. background-color: #fff;
  10. margin-bottom: 20px;
  11. padding-right: 50%;
  12. }
  13. .form-button {
  14. margin: 0 !important;
  15. }
  16. .form-button .el-form-item__content {
  17. margin-left: 0 !important;
  18. }
  19. .button-item {
  20. padding: 9px 25px;
  21. }
  22. .text {
  23. cursor: pointer;
  24. color: #419EFB;
  25. }
  26. </style>
  27. <section id="app" v-cloak>
  28. <el-card class="box-card" shadow="never" style="border:0" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
  29. <div slot="header" class="clearfix">
  30. <div flex="cross:center box:first">
  31. <div>分类设置</div>
  32. </div>
  33. </div>
  34. <div class="form-body">
  35. <el-form :model="ruleForm" label-width="80px" v-loading="loading" :rules="formRules" ref="ruleForm">
  36. <el-form-item label="分类名称" size="small" prop="title">
  37. <el-input v-model="ruleForm.title" auto-complete="off"></el-input>
  38. </el-form-item>
  39. <el-form-item label="排序" size="small" prop="sort">
  40. <el-input v-model="ruleForm.sort" auto-complete="off"></el-input>
  41. </el-form-item>
  42. <el-form-item label="是否启用" prop="status">
  43. <el-switch v-model="ruleForm.status" :active-value="1" :inactive-value="0" inactive-text="不启用" active-text="启用">
  44. </el-switch>
  45. </el-form-item>
  46. <!-- <el-form-item label="选择活动:" required>
  47. <com-dialog-activity :multiple="true" :extra-search="{from:'lucky_group'}" @selected="activitySelect" title="选择活动">
  48. <el-button type="primary">选择活动</el-button>
  49. </com-dialog-activity>
  50. <el-table max-height="400" :data="activity_list" size="small" stripe border style="width: 100%;margin-top: 20px;">
  51. <el-table-column type="index" label="序号" align="center" width="60">
  52. </el-table-column>
  53. <el-table-column prop="id" label="活动id" align="center" min-width="80">
  54. </el-table-column>
  55. <el-table-column label="活动名称" min-width="150">
  56. <template slot-scope="scope">
  57. <div style="display: flex;align-items: center;">
  58. <div>
  59. <div>{{scope.row.title}}</div>
  60. </div>
  61. </div>
  62. </template>
  63. </el-table-column>
  64. <el-table-column prop="num" label="操作" align="center" min-width="80">
  65. <template slot-scope="scope">
  66. <el-button type="warning" @click="delFun(scope.$index)">删除</el-button>
  67. </template>
  68. </el-table-column>
  69. </el-table>
  70. </el-form-item> -->
  71. <el-form-item prop="pic_path">
  72. <label slot="label">
  73. <span>分类图片</span>
  74. <el-tooltip effect="dark" content="上传图片,建议尺寸:64 * 64" placement="top">
  75. <i class="el-icon-info"></i>
  76. </el-tooltip>
  77. </label>
  78. <com-attachment v-model="ruleForm.pic_path" :multiple="false" :max="1">
  79. <el-tooltip class="item" effect="dark" content="建议尺寸:64 * 64" placement="top">
  80. <el-button size="mini">选择图片</el-button>
  81. </el-tooltip>
  82. </com-attachment>
  83. <div class="customize-share-title">
  84. <com-image mode="aspectFill" width='80px' height='80px' :src="ruleForm.pic_path ? ruleForm.pic_path : ''"></com-image>
  85. <el-button v-if="ruleForm.pic_path" class="del-btn" size="mini" type="danger" icon="el-icon-close" circle @click="ruleForm.pic_path = ''"></el-button>
  86. </div>
  87. </el-form-item>
  88. <el-form-item prop="pic_adv">
  89. <label slot="label">
  90. <span>分类广告</span>
  91. <el-tooltip effect="dark" content="上传图片,建议尺寸:750 * 438" placement="top">
  92. <i class="el-icon-info"></i>
  93. </el-tooltip>
  94. </label>
  95. <com-attachment v-model="ruleForm.pic_adv" :multiple="false" :max="1">
  96. <el-tooltip class="item" effect="dark" content="建议尺寸:750 * 438" placement="top">
  97. <el-button size="mini">选择图片</el-button>
  98. </el-tooltip>
  99. <!-- <span style="margin-left: 35px; color:red">建议尺寸:750 * 300</span> -->
  100. </com-attachment>
  101. <div class="customize-share-title">
  102. <com-image mode="aspectFill" width='80px' height='80px' :src="ruleForm.pic_adv ? ruleForm.pic_adv : ''"></com-image>
  103. <el-button v-if="ruleForm.pic_adv" class="del-btn" size="mini" type="danger" icon="el-icon-close" circle @click="ruleForm.pic_adv = ''"></el-button>
  104. </div>
  105. <!-- <el-button @click="app_share.dialog = true;app_share.type = 'pic_bg'"
  106. type="text">查看图例
  107. </el-button> -->
  108. </el-form-item>
  109. <el-form-item label="广告链接" size="small" prop="adv_link">
  110. <el-input v-model="selectedLink" placeholder="点击选择链接" readonly size="small">
  111. <com-pick-link slot="append" @selected="linkSelected">
  112. <el-button size="small">选择链接</el-button>
  113. </com-pick-link>
  114. </el-input>
  115. </el-form-item>
  116. <el-form-item label="背景色" prop="bgcolor">
  117. <el-color-picker @active-change="noticeBgColorChange" style="margin-left: 20px;" color-format="rgb" v-model="ruleForm.bgcolor" :predefine="predefineColors">
  118. </el-color-picker>
  119. </el-form-item>
  120. <div flex="dir:right">
  121. <div>
  122. <el-button class="button-item" type="primary" size="small" :loading=btnLoading @click="submit('ruleForm')">提交</el-button>
  123. </div>
  124. </div>
  125. </el-form>
  126. </div>
  127. </el-card>
  128. </section>
  129. <script>
  130. const app = new Vue({
  131. el: '#app',
  132. data() {
  133. return {
  134. loading: false,
  135. btnLoading: false,
  136. selectedLink: '',
  137. ruleForm: {
  138. title: '',
  139. sort: '',
  140. status: '',
  141. pic_path: '',
  142. adv_link: {},
  143. pic_adv: '',
  144. bgcolor: '',
  145. // activity_ids: '',
  146. },
  147. activity_list: [],
  148. formRules: {
  149. title: [{
  150. required: true,
  151. message: '名称不能为空',
  152. trigger: 'blur'
  153. }
  154. ],
  155. sort: [{
  156. required: true,
  157. pattern: /^[0-9]\d{0,8}$/,
  158. message: '排序必须在9位整数内',
  159. trigger: 'blur'
  160. }],
  161. status: [{
  162. required: true,
  163. message: '请选择是否启用分类',
  164. trigger: 'blur'
  165. }],
  166. pic_path: [{
  167. required: true,
  168. message: '请上传图片',
  169. trigger: 'blur'
  170. }],
  171. pic_adv: [{
  172. required: true,
  173. message: '请上传详情图',
  174. trigger: 'blur'
  175. }],
  176. // activity_ids: [{
  177. // required: true,
  178. // message: '请选择活动',
  179. // trigger: 'blur'
  180. // }],
  181. },
  182. predefineColors: [
  183. '#000',
  184. '#fff',
  185. '#888',
  186. '#ff4544'
  187. ],
  188. };
  189. },
  190. methods: {
  191. noticeBgColorChange(e) {
  192. this.ruleForm.bgcolor = e;
  193. },
  194. // delFun(index) {
  195. // this.activity_list.splice(index, 1)
  196. // },
  197. // activitySelect(param) {
  198. // for (let j in param) {
  199. // let item = param[j];
  200. // let flag = true;
  201. // for (let i in this.activity_list) {
  202. // if (this.activity_list[i].id == item.id) {
  203. // flag = false;
  204. // break;
  205. // }
  206. // }
  207. // if (flag) {
  208. // this.activity_list.push({
  209. // id: item.id,
  210. // title: item.title,
  211. // });
  212. // }
  213. // }
  214. // },
  215. submit(formName) {
  216. // console.log('submit ==>>> ', this.ruleForm);return null;
  217. if (!this.ruleForm.adv_link) {
  218. this.ruleForm.adv_link = '';
  219. }
  220. this.ruleForm.title += '';
  221. if (this.ruleForm.title.length > 30 || this.ruleForm.title.length < 2) {
  222. this.$message.error('分类名称长度在 2-30 字符');
  223. return false;
  224. }
  225. this.$refs[formName].validate((valid, obj) => {
  226. if (valid) {
  227. this.btnLoading = true;
  228. request({
  229. params: {
  230. r: 'lucky-group/group-category/storage',
  231. },
  232. data: this.ruleForm,
  233. method: 'post'
  234. }).then(e => {
  235. this.btnLoading = false;
  236. if (e.data.code == 0) {
  237. const h = this.$createElement;
  238. this.$message({
  239. message: e.data.msg,
  240. type: 'success'
  241. });
  242. setTimeout(function() {
  243. navigateTo({
  244. r: 'lucky-group/group-category/index'
  245. });
  246. }, 300);
  247. } else {
  248. this.$message({
  249. message: e.data.msg,
  250. type: 'error'
  251. });
  252. }
  253. }).catch(e => {
  254. this.btnLoading = false;
  255. this.$message.error(e.data.msg);
  256. });
  257. } else {
  258. var msg = '';
  259. for (let index in obj) {
  260. msg = msg + '*' + obj[index][0].message + ' ';
  261. }
  262. this.$message({
  263. message: msg,
  264. type: 'error'
  265. });
  266. return false;
  267. }
  268. });
  269. },
  270. linkSelected(list) {
  271. console.log('linkSelected ====>>>> ', list);
  272. if (!list.length) {
  273. this.ruleForm.adv_link = {};
  274. this.selectedLink = '';
  275. return false;
  276. }
  277. this.ruleForm.adv_link = list[0];
  278. this.selectedLink = list[0].title + ' [ ' + list[0].route + ' ]';
  279. return;
  280. },
  281. getcategoryInfo() {
  282. this.loading = true;
  283. let self = this;
  284. request({
  285. params: {
  286. r: 'lucky-group/group-category/storage',
  287. id: getQuery('id'),
  288. },
  289. method: 'get'
  290. }).then(e => {
  291. this.loading = false;
  292. console.log(e);
  293. if (e.data.code == 0 && e.data.data.id) {
  294. self.ruleForm = e.data.data;
  295. if (e.data.data.adv_link) {
  296. this.selectedLink = e.data.data.adv_link.title + ' [ ' + e.data.data.adv_link.route + ' ]';
  297. }
  298. // self.activity_list = Array.isArray(e.data.data.activity_list) ? e.data.data.activity_list : [];
  299. // e.data.data.activity_ids && (this.ruleForm.activity_ids = e.data.data.activity_ids);
  300. console.log(this.ruleForm.activity_ids, 222222222);
  301. }
  302. }).catch(e => {
  303. this.loading = false;
  304. this.$alert(e.data.msg, '提示', {
  305. confirmButtonText: '确定'
  306. })
  307. });
  308. },
  309. },
  310. mounted() {
  311. this.getcategoryInfo();
  312. }
  313. })
  314. </script>