edit.php 22 KB

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