edit.php 25 KB

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