Blame view

admin-web-master/src/views/renovation/commdityClass/Edit.vue 14.2 KB
3f535f30   杨鑫   '初始'
1
2
3
4
5
6
7
  <template>
    <el-dialog
      :close-on-click-modal="false"
      :title="title"
      :type="type"
      :visible.sync="isVisible"
      center
855bef33   杨鑫   '最新版本'
8
      width="60%"
3f535f30   杨鑫   '初始'
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
      top="50px"
      class="group-dialog"
    >
      <div class="add-dialog-component">
        <el-alert
          :style="{ backgroundColor: '#fff' }"
          title="保存后将生效在移动端的分类里"
          type="info"
          :closable="false"
        />
        <el-tree
          class="tree-box"
          :data="treeData"
          :props="{ children: 'childs' }"
          node-key="id"
          default-expand-all
          :expand-on-click-node="false"
        >
          <div
            slot-scope="{ node, data }"
            class="custom-tree-node"
          >
            <div class="content">
              <template v-if="data.depth < 3">
                <el-input
                  v-model="data.categoryName"
                  class="input"
                  :disabled="isCheck"
                  maxlength="6"
                  size="mini"
                  :placeholder="data.depth | placeholderTips"
                />
                <el-upload
                  class="upload-uploader"
                  :on-success="handleImageSuccessOne"
                  :multiple="false"
                  :show-file-list="false"
                  :action="action"
                  :file-list="data.categoryImgArray"
41c84754   杨鑫   '最新'
48
  				 v-if="title!='查看类别'"	    
3f535f30   杨鑫   '初始'
49
                >
41c84754   杨鑫   '最新'
50
51
52
53
54
55
  				<img
  				 v-if="data.categoryImgArray.length && data.categoryImgArray[0].imgPath && title != '查看类别'"
  					    width="80"
  					    height="80"
  					    :src="$baseURL+data.categoryImgArray.length && $baseURL+data.categoryImgArray[0].imgPath"
  					  >
3f535f30   杨鑫   '初始'
56
                  <i
41c84754   杨鑫   '最新'
57
                v-else
3f535f30   杨鑫   '初始'
58
59
60
                    class="el-icon-plus"
                  />
                </el-upload>
41c84754   杨鑫   '最新'
61
62
63
64
65
66
  			  <img
  		v-if="title == '查看类别'"
  			    width="80"
  			    height="80"
  			    :src="$baseURL+data.categoryImgArray.length && $baseURL+data.categoryImgArray[0].imgPath"
  			  >
3f535f30   杨鑫   '初始'
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
              </template>
              <template v-else>
                <div
                  class="content"
                  :class="isCheck ? 'disabled' : ''"
                >
                  <el-input
                    v-model="data.categoryName"
                    class="input"
                    :disabled="isCheck"
                    size="mini"
                    maxlength="6"
                    placeholder="输入三级类别名称(最大6个字符)"
                  />
                  <el-upload
                    :headers="headers"
                    :data="dataObj"
                    :multiple="false"
                    :show-file-list="false"
                    :file-list="data.categoryImgArray"
                    :on-success="handleImageSuccess"
                    class="upload-uploader"
                    :action="action"
                  >
                    <img
                      v-if="
                        data.categoryImgArray && data.categoryImgArray[0].url
                      "
                      width="80"
                      height="80"
                      :src="
855bef33   杨鑫   '最新版本'
98
                        $baseURL+data.categoryImgArray && $baseURL+data.categoryImgArray[0].url
3f535f30   杨鑫   '初始'
99
100
101
102
103
104
105
106
107
108
109
110
111
                      "
                    >
                    <i
                      v-else
                      class="el-icon-plus"
                    />
                  </el-upload>
                </div>
              </template>
            </div>
            <div
              v-if="!isCheck"
              class="setting-box"
855bef33   杨鑫   '最新版本'
112
  	
3f535f30   杨鑫   '初始'
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
            >
              <div
              class="tableBtn greens"
                @click="() => append(data)"
              >{{ data.depth | addTips }}
              </div>
              <div
               class="tableBtn greens"
                @click="() => remove(node, data)"
              >删除
              </div>
            </div>
          </div>
        </el-tree>
        <div class="add-btn-wrap">
          <template v-if="isCheck">
            <el-button
            style="background-color: #3F9B6A;color: #fff"
              @click="close"
            >确定
            </el-button>
          </template>
          <template v-else>
            <div
              v-if="type === 'add'"
             class="tableBtn greens"
              @click="addClassification"
            >添加一级类别名称
            </div>
            <el-button
             style="background-color: #3F9B6A;color: #fff"
              @click="onSubmit"
            >保存
            </el-button>
          </template>
        </div>
      </div>
    </el-dialog>
  </template>
  <script>
1991126c   杨鑫   '最新'
153
  import { upUrl } from '@/utils/request'
3f535f30   杨鑫   '初始'
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
  import {
    getSelect,
    commdityClassAdd,
    commdityClassgetById,
    commdityClassUpdate
  } from '@/api/renovation'
  
  let idx = 1000
  let imgId = 1
  export default {
    filters: {
      addTips (depth) {
        depth = depth + ''
        const tipsMp = {
          1: '添加二级类别名称',
          2: '添加三级类别名称'
        }
        return tipsMp[depth]
      },
      placeholderTips (depth) {
        depth = depth + ''
        const tipsMp = {
          1: '输入一级类别名称(最大6个字符)',
          2: '输入二级类别名称(最大6个字符)'
        }
        return tipsMp[depth]
      }
    },
    props: {
      dialogVisible: {
        type: Boolean,
        default: false
      },
      type: {
        type: String,
        default: 'add'
      }
    },
    data () {
      return {
        params: {
          categoryName: ''
        },
        file: this.image ? this.image : '',
        imgList: [],
        customParams: {
          current: 1,
          map: {},
          model: {
            config: '',
            isCustom: true,
            isDelete: 0,
            name: ''
          },
          order: 'descending',
          size: 100,
          sort: 'id'
        },
        treeData: [],
        headers: {
          Authorization: ''
        },
1991126c   杨鑫   '最新'
216
        action: upUrl,
3f535f30   杨鑫   '初始'
217
        dataObj: {
1991126c   杨鑫   '最新'
218
219
          folderId: 1,
         
3f535f30   杨鑫   '初始'
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
        },
        deleteArr: []
      }
    },
    computed: {
      isVisible: {
        get () {
          return this.dialogVisible
        },
        set () {
          this.close()
          this.reset()
        }
      },
      title () {
        const stateMap = {
          add: '新建类别',
          edit: '修改类别',
          check: '查看类别'
        }
        return stateMap[this.type]
      },
      isCheck () {
        return this.type === 'check'
      }
    },
    async created () {
      /*
      const res = await getSelect({
        dictName: '商品类别链接'
      })
855bef33   杨鑫   '最新版本'
251
      
3f535f30   杨鑫   '初始'
252
253
254
255
256
      this.dictList = res.data
      */
    },
    methods: {
      async queryOneCategory (oneClassifyId) {
855bef33   杨鑫   '最新版本'
257
        
3f535f30   杨鑫   '初始'
258
259
260
261
262
263
264
        if (oneClassifyId === undefined) {
          this.treeData = []
          return
        }
        const res = await commdityClassgetById({
          oneClassifyId
        })
855bef33   杨鑫   '最新版本'
265
        
3f535f30   杨鑫   '初始'
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
        const resData = res.data
        const treeFilter = item => {
          const {
            categoryName,
            categoryImg,
            categoryPath,
            parentName,
            categoryImgArray,
            depth,
            id,
            link
          } = item
          const newMap = {
            depth: depth,
            categoryName,
            categoryPath: categoryPath || '',
            parentName,
            categoryImgArray,
            link,
            id
          }
855bef33   杨鑫   '最新版本'
287
288
          
  		
3f535f30   杨鑫   '初始'
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
          if (depth === 3) {
            newMap.categoryImgArray = [
              {
                url: categoryImg
              }
            ]
          }
          if (item.childs && item.childs.length) {
            newMap.childs = item.childs.map(treeFilter)
          }
          return newMap
        }
        if (resData) {
          resData.childs =
            resData && resData.childs && resData.childs.map(treeFilter)
          this.treeData = [resData]
        } else {
          this.treeData = []
        }
        console.log(this.treeData)
      },
      handleImageSuccess (response, file, fileList) {
        console.log(response)
855bef33   杨鑫   '最新版本'
312
        const url = response.data
3f535f30   杨鑫   '初始'
313
314
315
        fileList[0].url = url
      },
      handleImageSuccessOne (response, file, fileList) {
855bef33   杨鑫   '最新版本'
316
317
        const url = response.data
        console.log('图片商城',response)
3f535f30   杨鑫   '初始'
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
        fileList[0].imgPath = url
      },
      close () {
        this.$emit('close')
      },
      reset () {
        this.treeData = []
      },
      addClassification () {
        this.treeData.push({
          placeholder: '输入一级类别名称',
          addTips: '添加二级类别名称',
          categoryName: '',
          categoryPath: '',
          depth: 1,
          idx: idx++,
          categoryImgArray: [
            {
              id: imgId++,
              imgPath: ''
            }
          ]
        })
      },
      append (data) {
855bef33   杨鑫   '最新版本'
343
        
3f535f30   杨鑫   '初始'
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
        const { categoryName } = data
        const depth = data.depth + 1
        let newChild
        if (!data.childs) {
          this.$set(data, 'childs', [])
        }
        if (depth < 3) {
          newChild = {
            placeholder: '输入二级类别名称',
            addTips: '添加三级类别名称',
            depth,
            parentName: categoryName,
            categoryName: '',
            categoryPath: '',
            categoryImgArray: [
              {
                id: imgId++,
                imgPath: ''
              }
            ],
            childs: [],
            idx: idx++
          }
        } else {
          newChild = {
            parentName: categoryName,
            categoryImgArray: [
              {
                id: imgId++,
                url: ''
              }
            ],
            depth: 3,
            categoryName: '',
            idx: idx++
          }
        }
        data.childs.push(newChild)
      },
      remove (node, data) {
        const parent = node.parent
        const children = parent.data.childs || parent.data
        const index = children.findIndex(d => d.idx === data.idx)
        if (index !== -1) {
          children.splice(index, 1)
          this.deleteArr.push(data.id || '')
        } else {
          this.$message.warning('数据错误,请重试')
        }
      },
      onSubmit () {
855bef33   杨鑫   '最新版本'
395
        
3f535f30   杨鑫   '初始'
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
        if (this.type === 'add') {
          this.addGroup()
        } else {
          this.updateGroup()
        }
      },
      async addGroup () {
        console.log(this.treeData)
        const treeFilter = item => {
          const {
            categoryName,
            categoryImgArray,
            categoryPath,
            parentName,
            depth,
            link
          } = item
          const newMap = {
            depth: depth,
            categoryName,
            categoryPath: categoryPath || '',
            parentName,
            link
          }
          if (categoryImgArray) {
            newMap.categoryImg = categoryImgArray[0].imgPath
          }
          if (depth === 3) {
            newMap.categoryImg = categoryImgArray[0].url
          }
          if (!newMap.categoryImg) {
            this.$message.error('分类\"' + categoryName + '\"请上传分类图片')
            throw new Error('未上传分类图片')
          }
          if (item.childs && item.childs.length) {
            newMap.childs = item.childs.map(treeFilter)
          }
          return newMap
        }
        const params = this.treeData.map(treeFilter)
        console.log(params)
        if (params.length === 0) {
          this.$message.error('请添加分类')
          return
        }
        const obj = {
          classifies: params
        }
        const res = await commdityClassAdd(obj)
        if (res.code === '') {
          this.isVisible = false
          this.$message({
            message: '新增成功',
            type: 'success'
          })
          this.$emit('success')
          this.deleteArr = []
        }
      },
      async updateGroup () {
        const treeFilter = item => {
          const {
            categoryName,
            categoryImgArray,
            categoryPath,
            parentName,
            depth,
            id,
            link
          } = item
          const newMap = {
            depth: depth,
            categoryName,
            categoryPath: categoryPath || '',
            parentName,
            link,
            id
          }
          if (categoryImgArray) {
            newMap.categoryImg = categoryImgArray[0].imgPath
          }
          if (depth === 3) {
            newMap.categoryImg = categoryImgArray[0].url
          }
          if (!newMap.categoryImg) {
            this.$message.error('分类\"' + categoryName + '\"请上传分类图片')
            throw new Error('未上传分类图片')
          }
          if (item.childs && item.childs.length) {
            newMap.childs = item.childs.map(treeFilter)
          }
          return newMap
        }
        console.log(this.treeData)
        const params = this.treeData.map(treeFilter)
        const obj = {
          classifies: params,
          deleteIds: this.deleteArr
        }
        const res = await commdityClassUpdate(obj)
        if (res.code === '') {
          this.isVisible = false
          this.$message({
            message: '成功',
            type: 'success'
          })
          this.$emit('success')
          this.deleteArr = []
        }
      },
      setParams ({ id }) {
855bef33   杨鑫   '最新版本'
507
        
3f535f30   杨鑫   '初始'
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
        this.queryOneCategory(id)
      }
    }
  }
  </script>
  <style lang="scss">
  .add-dialog-component {
    .tree-box {
      .el-tree-node__content {
        margin-bottom: 15px;
        height: auto;
      }
    }
  }
  </style>
  <style
    lang="scss"
    scoped
  >
  @import url("../../../styles/elDialog.scss");
  
  .group-dialog {
    .el-dialog {
      min-width: 500px;
      max-width: 600px;
    }
  }
  
  .add-dialog-component {
    padding: 15px 20px;
    max-height: 60vh;
    overflow: auto;
  
    .el-tree-node__content {
      &:hover {
        background-color: #fff;
      }
    }
  
    .tree-box {
      margin: 15px 0;
  
      .custom-tree-node {
        display: flex;
        width: 100%;
        text-align: left;
  
        .content {
          flex: 1;
          display: flex;
          align-items: center;
  
          .input {
            width: 60%;
            margin-right: 20px;
          }
  
          .textarea-input {
            width: 100%;
            margin-left: 15px;
  
            textarea {
              height: 80px;
            }
          }
        }
  
        .level-3-wrap {
          display: flex;
          width: 300px;
  
          .upload-wrap {
            position: relative;
  
            &.disabled::after {
              content: "";
              position: absolute;
              left: 0;
              right: 0;
              top: 0;
              bottom: 0;
              z-index: 999;
              background-color: #f5f7fa;
              opacity: 0.5;
            }
  
            .el-upload {
              border: 1px dashed #d9d9d9;
            }
  
            i {
            }
  
            img {
              width: 80px;
              height: 80px;
            }
          }
        }
      }
    }
  
    .add-btn-wrap {
      text-align: center;
    }
  }
  
  .upload-uploader {
    margin-left: 30px;
  }
  .tableBtn {
         display: inline-block;
         margin-right: 10px;
       }
  
     .greens {
         color: #3F9B6A ;
       }
  </style>