edit.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. <?php
  2. use common\helpers\ComponentHelper;
  3. $mchId = Yii::$app->user->identity->mch_id;
  4. ComponentHelper::loadComponentView('component/com-attachment', dirname(__DIR__));
  5. ComponentHelper::loadComponentView('component/com-attachment-edit', dirname(__DIR__));
  6. ComponentHelper::loadComponentView('component/com-upload', dirname(__DIR__));
  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. <el-breadcrumb separator="/">
  97. <el-breadcrumb-item>
  98. <span style="color: #409EFF;cursor: pointer" @click="$navigate({r:'store/client/cate/index'})">
  99. 分类
  100. </span>
  101. </el-breadcrumb-item>
  102. <el-breadcrumb-item>分类编辑</el-breadcrumb-item>
  103. </el-breadcrumb>
  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. <div>
  199. <el-button class="button-item" :loading="btnLoading" type="primary" @click="store('ruleForm')" size="small">保存</el-button>
  200. </div>
  201. </el-card>
  202. <div class="el-dialog-1">
  203. <el-dialog title="选择归属的一级分类" :visible.sync="dialogVisible1" width="20%">
  204. <el-form v-loading="dialogLoading" size="small" :inline="true" :model="search" @submit.native.prevent>
  205. <el-form-item>
  206. <div class="search-input-item">
  207. <el-input style="width:100%" @keyup.enter.native="searchCat" size="small" placeholder="请输入分类名称搜索" v-model="search.keyword" clearable @clear="searchCat">
  208. <el-button slot="append" icon="el-icon-search" @click="searchCat"></el-button>
  209. </el-input>
  210. </div>
  211. </el-form-item>
  212. <div class="dialog-cat-box">
  213. <el-table :show-header="false" :data="catList1" highlight-current-row @current-change="tableRowClick" :row-class-name="tableRowClassName" style="width: 100%">
  214. <el-table-column prop="label">
  215. </el-table-column>
  216. </el-table>
  217. </div>
  218. </el-form>
  219. <span slot="footer" class="dialog-footer">
  220. <el-button size="small" @click="dialogVisible1 = false">取 消</el-button>
  221. <el-button size="small" type="primary" @click="selectCatSubmit">确 定</el-button>
  222. </span>
  223. </el-dialog>
  224. </div>
  225. <div class="el-dialog-2">
  226. <el-dialog title="选择归属的二级分类" :visible.sync="dialogVisible2" width="30%">
  227. <el-form v-loading="dialogLoading" size="small" :inline="true" :model="search" @submit.native.prevent>
  228. <el-form-item>
  229. <div class="search-input-item">
  230. <el-input style="width:100%" @keyup.enter.native="searchCat" size="small" placeholder="请输入分类名称搜索" v-model="search.keyword" clearable @clear="searchCat">
  231. <el-button slot="append" icon="el-icon-search" @click="searchCat"></el-button>
  232. </el-input>
  233. </div>
  234. </el-form-item>
  235. <div flex="dir:left">
  236. <div class="dialog-cat-box">
  237. <el-table :show-header="false" :data="catList2" highlight-current-row @current-change="tableRowClick" :row-class-name="tableRowClassName2" style="width: 100%">
  238. <el-table-column>
  239. <template slot-scope="scope">
  240. <div flex="box:last">
  241. <div>{{scope.row.label}}</div>
  242. <div v-if="scope.row.child">
  243. <i class="el-icon-arrow-right"></i>
  244. </div>
  245. </div>
  246. </template>
  247. </el-table-column>
  248. </el-table>
  249. </div>
  250. <div class="dialog-cat-box">
  251. <el-table :show-header="false" :data="catList3" highlight-current-row @current-change="tableRowClick2" :row-class-name="tableRowClassName3" style="width: 100%">
  252. <el-table-column prop="label">
  253. </el-table-column>
  254. </el-table>
  255. </div>
  256. </div>
  257. </el-form>
  258. <span slot="footer" class="dialog-footer">
  259. <el-button size="small" @click="dialogVisible2 = false">取 消</el-button>
  260. <el-button size="small" type="primary" @click="selectCatSubmit">确 定</el-button>
  261. </span>
  262. </el-dialog>
  263. </div>
  264. <el-dialog :title="imageShowData.title" :visible.sync="imageDialogVisible" width="20%">
  265. <div class="image-show-box" flex="main:center">
  266. <image :src="imageShowData.image_url"></image>
  267. </div>
  268. <div slot="footer">
  269. <el-button type="primary" size="small" @click="imageDialogVisible = false">我知道了</el-button>
  270. </div>
  271. </el-dialog>
  272. </div>
  273. <script>
  274. const app = new Vue({
  275. el: '#app',
  276. data() {
  277. return {
  278. ruleForm: {
  279. pic: '',
  280. big_pic: '',
  281. advert_pic: '',
  282. status: 1,
  283. advert_url: '',
  284. sort: 100,
  285. is_show: 1,
  286. advert_open_type: '',
  287. advert_params: '',
  288. },
  289. parentIds: [],
  290. options: [],
  291. rules: {
  292. name: [{
  293. required: true,
  294. message: '请输入分类名称',
  295. trigger: 'change'
  296. },
  297. { min: 1, max: 16, message: '长度在 1 到 16 个字符', trigger: 'blur' }
  298. ],
  299. sort: [{
  300. required: true,
  301. message: '请输入排序',
  302. trigger: 'change'
  303. }, ],
  304. },
  305. btnLoading: false,
  306. cardLoading: false,
  307. is_mch: <?= $mchId > 0 ? 1 : 0 ?>,
  308. dialogVisible1: false,
  309. dialogVisible2: false,
  310. search: {
  311. keyword: ''
  312. },
  313. catList1: [],
  314. catList2: [],
  315. catList3: [],
  316. dialogLoading: false,
  317. currentCat: null,
  318. currentCatShow: null,
  319. currentCatLevel: 1,
  320. currentCatLevelShow: 1,
  321. imageDialogVisible: false,
  322. imageShowData: {
  323. title: '',
  324. image_url: ''
  325. },
  326. currentRadioKey: 1,
  327. };
  328. },
  329. mounted: function() {
  330. this.getOptions();
  331. },
  332. methods: {
  333. store(formName) {
  334. this.$refs[formName].validate((valid) => {
  335. let self = this;
  336. if (valid) {
  337. self.btnLoading = true;
  338. this.ruleForm.parent_id = this.parentIds[this.parentIds.length - 1];
  339. request({
  340. params: {
  341. r: 'store/client/cate/edit'
  342. },
  343. method: 'post',
  344. data: {
  345. form: self.ruleForm,
  346. }
  347. }).then(e => {
  348. self.btnLoading = false;
  349. if (e.data.code == 0) {
  350. self.$message.success(e.data.msg);
  351. navigateTo({
  352. r: 'store/client/cate/index'
  353. })
  354. } else {
  355. self.$message.error(e.data.msg);
  356. }
  357. }).catch(e => {
  358. self.$message.error(e.data.msg);
  359. self.btnLoading = false;
  360. });
  361. } else {
  362. console.log('error submit!!');
  363. return false;
  364. }
  365. });
  366. },
  367. getOptions() {
  368. let self = this;
  369. request({
  370. params: {
  371. r: 'store/client/cate/edit',
  372. id: getQuery('id'),
  373. keyword: this.search.keyword
  374. },
  375. method: 'get',
  376. }).then(e => {
  377. this.dialogLoading = false;
  378. if (e.data.code === 0) {
  379. if(!Array.isArray(e.data.data.detail)){
  380. self.ruleForm = e.data.data.detail;
  381. self.handleData();
  382. }
  383. self.options = e.data.data.cates;
  384. self.setCatList1();
  385. self.setCatList2();
  386. } else {
  387. self.$message.error(e.data.msg);
  388. }
  389. }).catch(e => {
  390. console.log(e);
  391. });
  392. },
  393. // 所有一级分类列表
  394. setCatList1() {
  395. let self = this;
  396. self.catList1 = [];
  397. self.options.forEach(function(item) {
  398. if (self.ruleForm.id != item.value) {
  399. self.catList1.push({
  400. label: item.label,
  401. value: item.value,
  402. })
  403. }
  404. });
  405. },
  406. // 所有二级分类列表
  407. setCatList2() {
  408. let self = this;
  409. self.catList2 = [];
  410. self.options.forEach(function(item) {
  411. if (self.ruleForm.id != item.value) {
  412. self.catList2.push({
  413. label: item.label,
  414. value: item.value,
  415. child: item.children ? item.children : null,
  416. });
  417. }
  418. });
  419. },
  420. // 所有三级分类列表
  421. setCatList3(list) {
  422. let self = this;
  423. self.catList3 = [];
  424. if (list) {
  425. list.forEach(function(item) {
  426. if (self.ruleForm.id != item.value) {
  427. self.catList3.push({
  428. label: item.label,
  429. value: item.value,
  430. });
  431. }
  432. });
  433. }
  434. },
  435. // 分类 编辑时数据处理
  436. handleData() {
  437. let self = this;
  438. self.currentCatShow = {};
  439. self.parentIds = [];
  440. self.currentRadioKey = self.ruleForm.parents.length + 1;
  441. self.currentCatLevelShow = self.ruleForm.parents.length + 1;
  442. let parents = self.ruleForm.parents.reverse();
  443. parents.forEach(function(item, index) {
  444. self.parentIds.push(item.id);
  445. // 一级分类
  446. if (index === 0) {
  447. self.currentCatShow.label = item.name;
  448. self.currentCatShow.value = item.id;
  449. }
  450. // 二级分类
  451. if (index === 1) {
  452. self.currentCatShow.oneChildren = {
  453. label: item.name,
  454. value: item.id
  455. }
  456. }
  457. })
  458. },
  459. selectAdvertUrl(e) {
  460. let self = this;
  461. if (e.length) {
  462. const item = e.shift();
  463. self.ruleForm.advert_url = item.new_link_url;
  464. self.ruleForm.advert_open_type = item.open_type;
  465. self.ruleForm.advert_params = item.params ? item.params : [];
  466. }
  467. },
  468. changeParent(catLevel) {
  469. if (this.ruleForm.id) {
  470. return false;
  471. }
  472. this.currentRadioKey = catLevel;
  473. if (catLevel !== 1) {
  474. this.currentCatLevel = catLevel;
  475. if (this.currentCatShow) {
  476. this.currentCat = this.currentCatShow;
  477. }
  478. if (catLevel === 2) {
  479. this.setCatList1();
  480. this.dialogVisible1 = true;
  481. }
  482. if (catLevel === 3) {
  483. this.setCatList2();
  484. this.dialogVisible2 = true;
  485. }
  486. } else {
  487. this.currentCat = null;
  488. this.currentCatShow = {};
  489. this.parentIds = [];
  490. }
  491. },
  492. searchCat() {
  493. this.dialogLoading = true;
  494. this.getOptions();
  495. },
  496. // 选择分类 表格行点击事件
  497. tableRowClick(currentRow, oldCurrentRow) {
  498. if (currentRow) {
  499. this.currentCat = currentRow;
  500. if (this.currentCatLevel === 3) {
  501. this.setCatList3(currentRow.child)
  502. }
  503. }
  504. },
  505. tableRowClick2(currentRow, oldCurrentRow) {
  506. this.currentCat.oneChildren = currentRow;
  507. },
  508. // 选择分类 确认事件
  509. selectCatSubmit() {
  510. this.dialogVisible1 = false;
  511. this.dialogVisible2 = false;
  512. this.currentCatShow = this.currentCat;
  513. this.currentCatLevelShow = this.currentCatLevel;
  514. if (this.currentCatShow) {
  515. this.parentIds = [];
  516. this.parentIds.push(this.currentCatShow.value);
  517. if (this.currentCatShow.oneChildren) {
  518. this.parentIds.push(this.currentCatShow.oneChildren.value);
  519. }
  520. }
  521. if (this.currentCatLevel == 3 && !this.currentCat.oneChildren) {
  522. this.currentRadioKey = 2;
  523. this.currentCatLevel = 2;
  524. this.currentCatLevelShow = 2;
  525. }
  526. },
  527. imageShow(type) {
  528. this.imageDialogVisible = true;
  529. if (type === 1) {
  530. this.imageShowData.title = '分类大图图例';
  531. this.imageShowData.image_url = 'resources/img/mall/cat/example-1.png';
  532. }
  533. if (type === 2) {
  534. this.imageShowData.title = '分类广告图图例';
  535. this.imageShowData.image_url = 'resources/img/mall/cat/example-2.png';
  536. }
  537. },
  538. tableRowClassName({
  539. row,
  540. rowIndex
  541. }) {
  542. if (this.currentCat && this.currentCat.value == row.value) {
  543. return 'current-row';
  544. }
  545. return '';
  546. },
  547. tableRowClassName2({
  548. row,
  549. rowIndex
  550. }) {
  551. console.log(this.currentCat)
  552. console.log(row.value)
  553. if (this.currentCat && this.currentCat.value == row.value) {
  554. this.currentCat.child = row.child;
  555. this.catList3 = row.child;
  556. return 'current-row';
  557. }
  558. return '';
  559. },
  560. tableRowClassName3({
  561. row,
  562. rowIndex
  563. }) {
  564. if (this.currentCat && this.currentCat.oneChildren &&
  565. this.currentCat.oneChildren.value == row.value) {
  566. return 'current-row';
  567. }
  568. return '';
  569. },
  570. }
  571. });
  572. </script>