add-edit.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. <div id="app" v-cloak>
  2. <el-card shadow="never" style="border:0" class="box-card" body-style="background-color: #f3f3f3;padding: 10px 0 0;" v-loading="cardLoading" v-loading="cardLoading">
  3. <div slot="header">
  4. <div flex="cross:center box:first">
  5. <div><span @click="$navigate({r:'mch/store-category/index'})" class="text">分类</span>/分类编辑</div>
  6. <div flex="dir:right">
  7. <div>
  8. <el-button class="button-item" :loading="btnLoading" type="primary" @click="store('ruleForm')" size="small">保存</el-button>
  9. </div>
  10. </div>
  11. </div>
  12. </div>
  13. <div class="form-body">
  14. <el-form :model="ruleForm" :rules="rules" size="small" ref="ruleForm" label-width="120px">
  15. <el-form-item label="选择分类级别">
  16. <div flex="dir:left" class="radio-box">
  17. <div @click="changeParent(1)">
  18. <el-radio :disabled="ruleForm.id ? true : false" v-model="currentRadioKey" :label="1">一级分类</el-radio>
  19. </div>
  20. <div @click="changeParent(2)">
  21. <el-radio :disabled="ruleForm.id ? true : false" v-model="currentRadioKey" :label="2">二级分类</el-radio>
  22. </div>
  23. <div @click="changeParent(3)">
  24. <el-radio :disabled="ruleForm.id ? true : false" v-model="currentRadioKey" :label="3">三级分类</el-radio>
  25. </div>
  26. </div>
  27. </el-form-item>
  28. <el-form-item v-if="currentCatLevelShow == 2 && currentCatShow.value" label="一级分类">
  29. <div flex="dir:left">
  30. <div>{{currentCatShow.label}}</div>
  31. <div v-if="!ruleForm.id" @click="changeParent(currentCatLevelShow)" class="cat-edit-text">修改</div>
  32. </div>
  33. </el-form-item>
  34. <template v-if="currentCatLevelShow == 3 && currentCatShow.value">
  35. <el-form-item label="一级分类">
  36. <div flex="dir:left">
  37. <div>{{currentCatShow.label}}</div>
  38. <div v-if="!currentCatShow.oneChildren && !ruleForm.id" @click="changeParent(currentCatLevelShow)" class="cat-edit-text">修改
  39. </div>
  40. </div>
  41. </el-form-item>
  42. <el-form-item v-if="currentCatShow.oneChildren" label="二级分类">
  43. <div flex="dir:left">
  44. <div>{{currentCatShow.oneChildren.label}}</div>
  45. <div v-if="!ruleForm.id" @click="changeParent(currentCatLevelShow)" class="cat-edit-text">修改</div>
  46. </div>
  47. </el-form-item>
  48. </template>
  49. <el-form-item label="分类名称" prop="name">
  50. <el-input v-model="ruleForm.name"></el-input>
  51. </el-form-item>
  52. <el-form-item prop="sort">
  53. <template slot='label'>
  54. <span>排序</span>
  55. <el-tooltip effect="dark" content="排序值越小排序越靠前" placement="top">
  56. <i class="el-icon-info"></i>
  57. </el-tooltip>
  58. </template>
  59. <el-input type="number" v-model="ruleForm.sort"></el-input>
  60. </el-form-item>
  61. <el-form-item label="分类图标" prop="pic">
  62. <com-attachment :multiple="false" :max="1" v-model="ruleForm.pic">
  63. <el-tooltip effect="dark" content="建议尺寸200*200" placement="top">
  64. <el-button style="margin-bottom: 10px;" size="mini">选择文件</el-button>
  65. </el-tooltip>
  66. </com-attachment>
  67. <com-gallery :url="ruleForm.pic" :show-delete="true" @deleted="ruleForm.pic = ''" width="80px" height="80px">
  68. </com-gallery>
  69. </el-form-item>
  70. <template>
  71. <el-form-item prop="advert_pic" :rules="ruleForm.advert_pic&&ruleForm.advert_pic.length > 0 ? rules.advert_pic : [{required: true, message: '请选择图片', trigger: 'change'}]" class="com-goods">
  72. <template slot="label">
  73. <span>分类广告图</span>
  74. </template>
  75. <div class="pic-url-remark">
  76. 可拖拽使其改变顺序,最多支持上传9张
  77. </div>
  78. <div flex="dir:left">
  79. <draggable v-model="ruleForm.advert_pic" flex>
  80. <template v-if="ruleForm.advert_pic && ruleForm.advert_pic.length>0">
  81. <div v-for="(item,index) in ruleForm.advert_pic" :key="index" style="margin-right: 20px;position: relative;cursor: move;">
  82. <com-attachment @selected="selectedAdvertPic" :params="{'currentIndex': index}">
  83. <com-image mode="aspectFill" width="100px" height='100px' :src="item"> </com-image>
  84. </com-attachment>
  85. <el-button class="del-btn" size="mini" type="danger" icon="el-icon-close" circle @click="delPic(index)"></el-button>
  86. </div>
  87. </template>
  88. </draggable>
  89. <template v-if="ruleForm.advert_pic&&ruleForm.advert_pic.length < 9">
  90. <com-attachment style="margin-bottom: 10px;" :multiple="true" :max="9" @selected="selectedAdvertPic">
  91. <el-tooltip class="item" effect="dark" content="建议尺寸:750 * 420" placement="top">
  92. <div flex="main:center cross:center" class="add-image-btn">
  93. + 添加图片
  94. </div>
  95. </el-tooltip>
  96. </com-attachment>
  97. </template>
  98. </div>
  99. </el-form-item>
  100. <el-form-item label="分类广告链接" prop="advert_url">
  101. <el-input size="small" v-model="advertUrl" placeholder="点击选择链接">
  102. <com-pick-link @selected="selectAdvertUrl" slot="append">
  103. <el-button size="small">选择链接</el-button>
  104. </com-pick-link>
  105. </el-input>
  106. </el-form-item>
  107. </template>
  108. <el-form-item label="是否启用" prop="status">
  109. <el-switch v-model="ruleForm.status" :active-value="1" :inactive-value="0"></el-switch>
  110. </el-form-item>
  111. <el-form-item label="是否显示" prop="is_show">
  112. <el-switch v-model="ruleForm.is_show" :active-value="1" :inactive-value="0"></el-switch>
  113. </el-form-item>
  114. </el-form>
  115. </div>
  116. </el-card>
  117. <div class="el-dialog-1">
  118. <el-dialog title="选择归属的一级分类" :visible.sync="dialogVisible1" width="20%">
  119. <el-form v-loading="dialogLoading" size="small" :inline="true" :model="search" @submit.native.prevent>
  120. <el-form-item>
  121. <div class="search-input-item">
  122. <el-input style="width:100%" @keyup.enter.native="searchCat" size="small" placeholder="请输入分类名称搜索" v-model="search.keyword" clearable @clear="searchCat">
  123. <el-button slot="append" icon="el-icon-search" @click="searchCat"></el-button>
  124. </el-input>
  125. </div>
  126. </el-form-item>
  127. <div class="dialog-cat-box">
  128. <el-table :show-header="false" :data="catList1" highlight-current-row @current-change="tableRowClick" :row-class-name="tableRowClassName" style="width: 100%">
  129. <el-table-column prop="label">
  130. </el-table-column>
  131. </el-table>
  132. </div>
  133. </el-form>
  134. <span slot="footer" class="dialog-footer">
  135. <el-button size="small" @click="dialogVisible1 = false">取 消</el-button>
  136. <el-button size="small" type="primary" @click="selectCatSubmit">确 定</el-button>
  137. </span>
  138. </el-dialog>
  139. </div>
  140. <div class="el-dialog-2">
  141. <el-dialog title="选择归属的二级分类" :visible.sync="dialogVisible2" width="30%">
  142. <el-form v-loading="dialogLoading" size="small" :inline="true" :model="search" @submit.native.prevent>
  143. <el-form-item>
  144. <div class="search-input-item">
  145. <el-input style="width:100%" @keyup.enter.native="searchCat" size="small" placeholder="请输入分类名称搜索" v-model="search.keyword" clearable @clear="searchCat">
  146. <el-button slot="append" icon="el-icon-search" @click="searchCat"></el-button>
  147. </el-input>
  148. </div>
  149. </el-form-item>
  150. <div flex="dir:left">
  151. <div class="dialog-cat-box">
  152. <el-table :show-header="false" :data="catList2" highlight-current-row @current-change="tableRowClick" :row-class-name="tableRowClassName2" style="width: 100%">
  153. <el-table-column>
  154. <template slot-scope="scope">
  155. <div flex="box:last">
  156. <div>{{scope.row.label}}</div>
  157. <div v-if="scope.row.child">
  158. <i class="el-icon-arrow-right"></i>
  159. </div>
  160. </div>
  161. </template>
  162. </el-table-column>
  163. </el-table>
  164. </div>
  165. <div class="dialog-cat-box">
  166. <el-table :show-header="false" :data="catList3" highlight-current-row @current-change="tableRowClick2" :row-class-name="tableRowClassName3" style="width: 100%">
  167. <el-table-column prop="label">
  168. </el-table-column>
  169. </el-table>
  170. </div>
  171. </div>
  172. </el-form>
  173. <span slot="footer" class="dialog-footer">
  174. <el-button size="small" @click="dialogVisible2 = false">取 消</el-button>
  175. <el-button size="small" type="primary" @click="selectCatSubmit">确 定</el-button>
  176. </span>
  177. </el-dialog>
  178. </div>
  179. <el-dialog :title="imageShowData.title" :visible.sync="imageDialogVisible" width="20%">
  180. <div class="image-show-box" flex="main:center">
  181. <image :src="imageShowData.image_url"></image>
  182. </div>
  183. <div slot="footer">
  184. <el-button type="primary" size="small" @click="imageDialogVisible = false">我知道了</el-button>
  185. </div>
  186. </el-dialog>
  187. </div>
  188. <script src="/resources/js/Sortable.min.js"></script>
  189. <script src="/resources/unpkg/vuedraggable@2.18.1/dist/vuedraggable.umd.min.js"></script>
  190. <script>
  191. const app = new Vue({
  192. el: '#app',
  193. data() {
  194. return {
  195. ruleForm: {
  196. pic: '',
  197. big_pic: '',
  198. advert_pic: [],
  199. status: 1,
  200. advert_url: {},
  201. sort: 100,
  202. is_show: 1,
  203. advert_open_type: '',
  204. advert_params: '',
  205. },
  206. parentIds: [],
  207. options: [],
  208. rules: {
  209. name: [{
  210. required: true,
  211. message: '请输入分类名称',
  212. trigger: 'change'
  213. },
  214. {
  215. min: 1,
  216. max: 16,
  217. message: '长度在 1 到 16 个字符',
  218. trigger: 'blur'
  219. }
  220. ],
  221. sort: [{
  222. required: true,
  223. message: '请输入排序',
  224. trigger: 'change'
  225. }, ],
  226. },
  227. btnLoading: false,
  228. cardLoading: false,
  229. dialogVisible1: false,
  230. dialogVisible2: false,
  231. search: {
  232. keyword: ''
  233. },
  234. catList1: [],
  235. catList2: [],
  236. catList3: [],
  237. dialogLoading: false,
  238. currentCat: null,
  239. currentCatShow: null,
  240. currentCatLevel: 1,
  241. currentCatLevelShow: 1,
  242. imageDialogVisible: false,
  243. imageShowData: {
  244. title: '',
  245. image_url: ''
  246. },
  247. currentRadioKey: 1,
  248. advertUrl: '', // 广告链接
  249. };
  250. },
  251. mounted: function() {
  252. this.getOptions();
  253. },
  254. methods: {
  255. store(formName) {
  256. this.$refs[formName].validate((valid) => {
  257. let self = this;
  258. if (valid) {
  259. self.btnLoading = true;
  260. this.ruleForm.parent_id = this.parentIds[this.parentIds.length - 1];
  261. request({
  262. params: {
  263. r: 'mch/store-category/storage'
  264. },
  265. method: 'post',
  266. data: {
  267. form: self.ruleForm,
  268. }
  269. }).then(e => {
  270. self.btnLoading = false;
  271. if (e.data.code == 0) {
  272. self.$message.success(e.data.msg);
  273. navigateTo({
  274. r: 'mch/store-category/index'
  275. })
  276. } else {
  277. self.$message.error(e.data.msg);
  278. }
  279. }).catch(e => {
  280. self.$message.error(e.data.msg);
  281. self.btnLoading = false;
  282. });
  283. } else {
  284. console.log('error submit!!');
  285. return false;
  286. }
  287. });
  288. },
  289. getOptions() {
  290. let self = this;
  291. request({
  292. params: {
  293. r: 'mch/store-category/storage',
  294. id: getQuery('id'),
  295. keyword: this.search.keyword
  296. },
  297. method: 'get',
  298. }).then(e => {
  299. this.dialogLoading = false;
  300. if (e.data.code === 0) {
  301. if (!Array.isArray(e.data.data.detail)) {
  302. self.ruleForm = e.data.data.detail;
  303. self.handleData();
  304. }
  305. if (e.data.data.detail.advert_url) {
  306. this.advertUrl = e.data.data.detail.advert_url.title + ' [ ' + e.data.data.detail.advert_url.route + ' ]';
  307. } else {
  308. this.advertUrl = '';
  309. }
  310. self.options = e.data.data.cates;
  311. self.setCatList1();
  312. self.setCatList2();
  313. } else {
  314. self.$message.error(e.data.msg);
  315. }
  316. }).catch(e => {
  317. console.log(e);
  318. });
  319. },
  320. // 所有一级分类列表
  321. setCatList1() {
  322. let self = this;
  323. self.catList1 = [];
  324. self.options.forEach(function(item) {
  325. if (self.ruleForm.id != item.value) {
  326. self.catList1.push({
  327. label: item.label,
  328. value: item.value,
  329. })
  330. }
  331. });
  332. },
  333. // 所有二级分类列表
  334. setCatList2() {
  335. let self = this;
  336. self.catList2 = [];
  337. self.options.forEach(function(item) {
  338. if (self.ruleForm.id != item.value) {
  339. self.catList2.push({
  340. label: item.label,
  341. value: item.value,
  342. child: item.children ? item.children : null,
  343. });
  344. }
  345. });
  346. },
  347. // 所有三级分类列表
  348. setCatList3(list) {
  349. let self = this;
  350. self.catList3 = [];
  351. if (list) {
  352. list.forEach(function(item) {
  353. if (self.ruleForm.id != item.value) {
  354. self.catList3.push({
  355. label: item.label,
  356. value: item.value,
  357. });
  358. }
  359. });
  360. }
  361. },
  362. // 分类 编辑时数据处理
  363. handleData() {
  364. let self = this;
  365. self.currentCatShow = {};
  366. self.parentIds = [];
  367. self.currentRadioKey = self.ruleForm.parents.length + 1;
  368. self.currentCatLevelShow = self.ruleForm.parents.length + 1;
  369. let parents = self.ruleForm.parents.reverse();
  370. parents.forEach(function(item, index) {
  371. self.parentIds.push(item.id);
  372. // 一级分类
  373. if (index === 0) {
  374. self.currentCatShow.label = item.name;
  375. self.currentCatShow.value = item.id;
  376. }
  377. // 二级分类
  378. if (index === 1) {
  379. self.currentCatShow.oneChildren = {
  380. label: item.name,
  381. value: item.id
  382. }
  383. }
  384. })
  385. },
  386. selectAdvertUrl(e) {
  387. // console.log('kkkkkkkk: ', e);
  388. let self = this;
  389. if (e.length) {
  390. self.ruleForm.advert_url = e[0];
  391. self.advertUrl = e[0].title + ' [ ' + e[0].route + ' ]';
  392. }
  393. // console.log('jjjjjjj: ', self.ruleForm);
  394. },
  395. changeParent(catLevel) {
  396. if (this.ruleForm.id) {
  397. return false;
  398. }
  399. this.currentRadioKey = catLevel;
  400. if (catLevel !== 1) {
  401. this.currentCatLevel = catLevel;
  402. if (this.currentCatShow) {
  403. this.currentCat = this.currentCatShow;
  404. }
  405. if (catLevel === 2) {
  406. this.setCatList1();
  407. this.dialogVisible1 = true;
  408. }
  409. if (catLevel === 3) {
  410. this.setCatList2();
  411. this.dialogVisible2 = true;
  412. }
  413. } else {
  414. this.currentCat = null;
  415. this.currentCatShow = {};
  416. this.parentIds = [];
  417. }
  418. },
  419. searchCat() {
  420. this.dialogLoading = true;
  421. this.getOptions();
  422. },
  423. // 选择分类 表格行点击事件
  424. tableRowClick(currentRow, oldCurrentRow) {
  425. if (currentRow) {
  426. this.currentCat = currentRow;
  427. if (this.currentCatLevel === 3) {
  428. this.setCatList3(currentRow.child)
  429. }
  430. }
  431. },
  432. tableRowClick2(currentRow, oldCurrentRow) {
  433. this.currentCat.oneChildren = currentRow;
  434. },
  435. // 选择分类 确认事件
  436. selectCatSubmit() {
  437. this.dialogVisible1 = false;
  438. this.dialogVisible2 = false;
  439. this.currentCatShow = this.currentCat;
  440. this.currentCatLevelShow = this.currentCatLevel;
  441. if (this.currentCatShow) {
  442. this.parentIds = [];
  443. this.parentIds.push(this.currentCatShow.value);
  444. if (this.currentCatShow.oneChildren) {
  445. this.parentIds.push(this.currentCatShow.oneChildren.value);
  446. }
  447. }
  448. if (this.currentCatLevel == 3 && !this.currentCat.oneChildren) {
  449. this.currentRadioKey = 2;
  450. this.currentCatLevel = 2;
  451. this.currentCatLevelShow = 2;
  452. }
  453. },
  454. imageShow(type) {
  455. this.imageDialogVisible = true;
  456. if (type === 1) {
  457. this.imageShowData.title = '分类大图图例';
  458. this.imageShowData.image_url = 'resources/img/mall/cat/example-1.png';
  459. }
  460. if (type === 2) {
  461. this.imageShowData.title = '分类广告图图例';
  462. this.imageShowData.image_url = 'resources/img/mall/cat/example-2.png';
  463. }
  464. },
  465. tableRowClassName({
  466. row,
  467. rowIndex
  468. }) {
  469. if (this.currentCat && this.currentCat.value == row.value) {
  470. return 'current-row';
  471. }
  472. return '';
  473. },
  474. tableRowClassName2({
  475. row,
  476. rowIndex
  477. }) {
  478. console.log(this.currentCat)
  479. console.log(row.value)
  480. if (this.currentCat && this.currentCat.value == row.value) {
  481. this.currentCat.child = row.child;
  482. this.catList3 = row.child;
  483. return 'current-row';
  484. }
  485. return '';
  486. },
  487. tableRowClassName3({
  488. row,
  489. rowIndex
  490. }) {
  491. if (this.currentCat && this.currentCat.oneChildren &&
  492. this.currentCat.oneChildren.value == row.value) {
  493. return 'current-row';
  494. }
  495. return '';
  496. },
  497. // 选中图片
  498. selectedAdvertPic(e) {
  499. console.log('ttttt: ', e);
  500. this.ruleForm.advert_pic.push(e[0].url);
  501. },
  502. // 删除图片
  503. delPic(index) {
  504. this.ruleForm.advert_pic.splice(index, 1)
  505. },
  506. }
  507. });
  508. </script>
  509. <style>
  510. .form-body {
  511. padding: 20px 0;
  512. background-color: #fff;
  513. margin-bottom: 20px;
  514. padding-right: 50%;
  515. }
  516. .form-button {
  517. margin: 0;
  518. }
  519. .form-button .el-form-item__content {
  520. margin-left: 0 !important;
  521. }
  522. .button-item {
  523. padding: 9px 25px;
  524. }
  525. .radio-box div {
  526. margin-right: 20px;
  527. }
  528. .input-item {
  529. display: inline-block;
  530. width: 250px;
  531. margin: 0;
  532. }
  533. .input-item .el-input__inner {
  534. border-right: 0;
  535. }
  536. .input-item .el-input__inner:hover {
  537. border: 1px solid #dcdfe6;
  538. border-right: 0;
  539. outline: 0;
  540. }
  541. .input-item .el-input__inner:focus {
  542. border: 1px solid #dcdfe6;
  543. border-right: 0;
  544. outline: 0;
  545. }
  546. .input-item .el-input-group__append {
  547. background-color: #fff;
  548. border-left: 0;
  549. width: 10%;
  550. padding: 0 10px;
  551. }
  552. .input-item .el-input-group__append .el-button {
  553. padding: 15px;
  554. }
  555. .el-dialog-1 .el-dialog {
  556. min-width: 350px;
  557. }
  558. .dialog-cat-box {
  559. border: 1px solid #E3E3E3;
  560. height: 250px;
  561. -webkit-border-radius: 5px;
  562. -moz-border-radius: 5px;
  563. border-radius: 5px;
  564. width: 100%;
  565. margin-right: 10px;
  566. overflow-y: auto;
  567. }
  568. .el-dialog__body {
  569. padding: 10px 20px;
  570. }
  571. .el-table td,
  572. .el-table th {
  573. padding: 5px 0;
  574. }
  575. .cat-edit-text {
  576. color: #409EFF;
  577. margin-left: 10px;
  578. cursor: pointer;
  579. }
  580. .com-gallery .com-gallery-item {
  581. margin-bottom: 0;
  582. margin-right: 0;
  583. cursor: pointer;
  584. }
  585. .show-example {
  586. cursor: pointer;
  587. color: #409EFF;
  588. }
  589. .text {
  590. cursor: pointer;
  591. color: #419EFB;
  592. }
  593. .pic-url-remark {
  594. font-size: 13px;
  595. color: #c9c9c9;
  596. margin-bottom: 12px;
  597. }
  598. .add-image-btn {
  599. width: 100px;
  600. height: 100px;
  601. color: #419EFB;
  602. border: 1px solid #e2e2e2;
  603. cursor: pointer;
  604. }
  605. .del-btn {
  606. position: absolute;
  607. top: -4%;
  608. right: -4%;
  609. }
  610. </style>