edit.php 24 KB

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