fuliqi
2024-01-24 29c1e7eb5ac16e90d8991a86c1c071bc312ec8d9
1
2
3
4
5
6
7
8
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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
153
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
216
217
218
219
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
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
343
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
395
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
507
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
<template>
  <div>
    <!-- <div class="formBlock">
            <span>商品信息</span>
        </div>
        <el-form-item label="商品名称:" >{{form.prodSpu.spuName}}</el-form-item>
        <el-form-item label="商品品牌:" >{{form.prodSpu.brandName }}</el-form-item>
        <el-form-item label="商品分类:" >{{form.prodSpu.cascaderLabel}}</el-form-item> -->
    <div class="formBlock">
      <span>价格库存</span>
    </div>
    <el-form-item label="扣减方式:" prop="shopSpu.storageMinusType">
      下单后扣减
      <!-- <el-select placeholder="请选择扣减方式" v-model="form.shopSpu.storageMinusType" clearable>
                    <el-option v-for="item in reduceArray" :key="item.id" :value="item.id" :label="item.name"></el-option>
                </el-select> -->
    </el-form-item>
    <div v-if="form.prodSpu.spuType !== '3'">
      <el-form-item label="商品总库存:" prop="shopSpu.spuStorage">
        <el-input-number disabled v-model="form.shopSpu.spuStorage" :min='0'
                         @keydown.native="limiInputType" clearable></el-input-number>
      </el-form-item>
      <el-form-item label="商品库存预警:" prop="shopSpu.spuFreezeStorage">
        <el-input-number disabled v-model="form.shopSpu.spuFreezeStorage" :min='0'
                         @keydown.native="limiInputType" clearable></el-input-number>
      </el-form-item>
    </div>
    <!-- <div  v-for="(item,index) in form.skuMetasArray" :key="index">
            <el-form-item :label="item.productProp.propName+':'" :prop="'skuMetasArray.'+index+'.checkList'"  :rules="{type: 'array',required: showSkuMetas && item.productProp.propRequired ? true : false,message:`请选择${item.productProp.propName}`}">
               <el-checkbox-group v-model="item.checkList" @change="selectedSkuMetas(item.checkList,item)">
                    <el-checkbox v-for="itemProp in item.propMetaValues"  :key="itemProp.propValueId" :label="itemProp.propValueId">{{itemProp.propValue}}</el-checkbox>
                </el-checkbox-group>
            </el-form-item>
        </div>
        <el-form-item v-show="setShowProductTip()">
             <span class="productTip">温馨提示:请选择以上商品属性(至少选择一种属性)</span>
        </el-form-item> -->
    <!-- v-show="showTable" -->
    <div>
      <div v-if="isTip" class="itemTip">温馨提示:销售价格不应低于红线价格</div>
      <el-form-item label="商品规格:">
        <el-form ref="skuMetaForm" :model="skuMetaForm" size="mini"
                 :disabled="$route.query.pageTag === 'detail'">
          <el-form-item>
            <el-table ref="table" :data="skuMetaForm.tableData" border>
              <!-- <el-table-column :label="form.tableLabel">
                            <template slot-scope="scope">
                                {{scope.row.columnsText}}
                            </template>
                        </el-table-column> -->
              <el-table-column v-if="form.prodSpu.spuType === '3'" key="spuNum" label="商品主编码"
                               prop="spuNum" min-width="150px" show-overflow-tooltip>
              </el-table-column>
              <el-table-column v-if="form.prodSpu.spuType === '3'" key="spuName" label="商品名称"
                               prop="spuName" show-overflow-tooltip min-width="220px">
              </el-table-column>
              <el-table-column label="商品类型" prop="spuTypeName" key="spuTypeName"
                               v-if="form.prodSpu.spuType === '3'" width="150px"
                               show-overflow-tooltip>
              </el-table-column>
              <el-table-column label="规格" key="skuId" min-width="200px">
                <template slot-scope="scope">
                  <el-form-item :prop="'tableData.' + scope.$index + '.propValueId'"
                                :rules="formRules.skuPropValueId">
                    <el-select v-if="form.prodSpu.spuType !== '3'" v-model="scope.row.propValueId"
                               filterable remote reserve-keyword placeholder="请输入规格"
                               :remote-method="(query) => remoteMethod(query, scope.row)"
                               @change="changeSkuId(scope.row)"
                               @visible-change="(tag) => skuIdSelectVisible(tag, scope.row, scope.$index)"
                               :loading="scope.row.loading">
                      <el-option v-for="item in scope.row.options" :disabled="item.disabled"
                                 :key="item.propValueId" :label="item.propValue"
                                 :value="item.propValueId">
                      </el-option>
                    </el-select>
                    <span v-else>{{scope.row.columnsText}}</span>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column v-if="form.prodSpu.spuType !== '3'" key="file" label="规格图片"
                               align="center" width="120px">
                <template slot-scope="scope">
                  <el-form-item class="table-item">
                    <custom-upload-img class="table-upload-img"
                                       @handle-success="(param)=>handleSuccess(param,scope.row)"
                                       @handle-remove="(file)=>handleRemove(file,scope.row)"
                                       @handle-file-data="(arr)=>handleFileData(arr,scope.row)"
                                       :isHideDelete="$route.query.pageTag !== 'detail'"
                                       :fileList="scope.row.fileList">
                    </custom-upload-img>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column label="挂牌/横线价格" min-width="180px">
                <template slot-scope="scope">
                  <el-form-item :prop="'tableData.' + scope.$index + '.listPrice'"
                                :rules="formRules.listPrice">
                    <el-input-number :disabled="form.prodSpu.spuType === '3'"
                                     v-model="scope.row.listPrice"
                                     @keydown.native="limiInputType"></el-input-number>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column label="红线价格(瓶)" min-width="150px" show-overflow-tooltip>
                <template slot="header">
                  红线价格(瓶)
                  <el-popover placement="top" trigger="click">
                    1.指该商品规格最低销售价格,不得低于红线价<br />
                    2.该价统一由工管部规划
                    <i class="el-icon-question" style="cursor:pointer;" slot="reference"></i>
                  </el-popover>
                </template>
                <template slot-scope="scope">
                  <el-form-item>
                    {{scope.row.redLinePrice !== null ? '¥' + scope.row.redLinePrice.toFixed(2) : '-'}}
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column label="销售价格" width="180px">
                <template slot-scope="scope">
                  <el-form-item :prop="'tableData.' + scope.$index + '.salePrice'"
                                :rules="formRules.salePrice">
                    <el-input-number :class="scope.row.isTip ? 'inputTip':''"
                                     :disabled="form.prodSpu.spuType === '3' || !scope.row.propValueId"
                                     v-model="scope.row.salePrice"
                                     @change="changeSalePrice(scope.row)"
                                     @keydown.native="limiInputType"></el-input-number>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column v-if="form.prodSpu.spuType === '3'" key="skuStorage" label="商品库存"
                               prop="skuStorage" width="150px" show-overflow-tooltip>
                <template slot-scope="scope">
                  {{scope.row.skuStorage === +scope.row.skuStorage ?  scope.row.skuStorage : '-'}}
                </template>
              </el-table-column>
              <el-table-column label="商品扣减数" min-width="180px">
                <template slot-scope="scope">
                  <el-form-item :prop="'tableData.' + scope.$index + '.skuReduceStorage'"
                                :rules="formRules.skuReduceStorage">
                    <el-input-number :disabled="form.prodSpu.spuType === '3'"
                                     v-model="scope.row.skuReduceStorage" :min='0'
                                     @keydown.native="limiInputType"></el-input-number>
                  </el-form-item>
                </template>
              </el-table-column>
              <!-- <el-table-column v-if="$route.query.spuId && form.prodSpu.spuType !== '3'"  key="packageCode" prop="agglomerateOrderNum" >
                          <template slot="header">
                            平台套餐编码
                            <el-popover
                              placement="top"
                              width="200"
                              trigger="click"
                              content="注:此商品规格已关联渠道平台套餐,请谨慎操作,若确需操作,请修改后确认平台套餐是否正常(当前商品规格与套餐编码规格扣减数是否一致)"
                            >
                              <i class="el-icon-question" style="cursor:pointer;" slot="reference"></i>
                            </el-popover>
                          </template>
                          <template slot-scope="scope">
                            {{scope.row.packageCode}}
                          </template>
                        </el-table-column> -->
              <!-- <el-table-column label="商品库存" width="160px">
                            <template slot-scope="scope">
                               <el-form-item :prop="'tableData.' + scope.$index + '.spuStorage'" :rules="formRules.spuStorage">
                                 <el-input-number  v-model="scope.row.spuStorage" :min='0' @keydown.native="limiInputType" ></el-input-number>
                               </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column  label="预警库存" width="160px">
                            <template slot-scope="scope">
                               <el-form-item :prop="'tableData.' + scope.$index + '.spuFreezeStorage'" :rules="formRules.spuFreezeStorage">
                                  <el-input-number v-model="scope.row.spuFreezeStorage" :min='0' @keydown.native="limiInputType" ></el-input-number>
                               </el-form-item>
                            </template>
                        </el-table-column> -->
              <el-table-column v-if="form.prodSpu.spuType !== '3'" key="action" label="操作"
                               width="80px">
                <template slot-scope="scope">
                  <el-form-item>
                    <el-button type="danger"
                               @click="deleteSku(scope.row, scope.$index)">删除</el-button>
                  </el-form-item>
                </template>
              </el-table-column>
            </el-table>
          </el-form-item>
          <div class="buttonPosition">
            <el-button v-if="form.prodSpu.spuNum && form.prodSpu.spuType !== '3'" type="primary"
                       @click="addSpecs">添加规格</el-button>
          </div>
        </el-form>
      </el-form-item>
      <div v-if="form.prodSpu.spuType === '3'">
        <el-form-item label="组套商品挂牌价:" prop="shopSpu.prodPrice.listPrice">
          <el-input-number v-model="form.shopSpu.prodPrice.listPrice"
                           @keydown.native="limiInputType" clearable></el-input-number>
        </el-form-item>
        <el-form-item label="组套商品销售价:" prop="shopSpu.prodPrice.salePrice">
          <el-input-number v-model="form.shopSpu.prodPrice.salePrice"
                           @keydown.native="limiInputType" clearable></el-input-number>
        </el-form-item>
      </div>
      <!-- <div class="formBlock">
                <span>单品图片</span>
            </div>
            <div v-for="(item,index) in skuMetaForm.tableData" :key='index'>
                <div>{{item.columnsText}}:</div>
                <el-form-item>
                    <custom-upload-img
                          :imageSize="'754 * 754'"
                          @handle-success="(param)=>handleSuccess(param,item)"
                          @handle-remove="(file)=>handleRemove(file,item)"
                          @handle-file-data="(arr)=>handleFileData(arr,item)"
                          :fileList="item.fileList">
                    </custom-upload-img>
                </el-form-item>
            </div> -->
    </div>
  </div>
</template>
<script>
import { limiInputType } from '@/utils/limiInputType'
import productListApi from '@/api/productmanagement/productList'
 
export default {
  props: ['form', 'reduceArray', 'showSkuMetas', 'formRules'],
  data() {
    return {
      skuMetaForm: {
        tableData: []
      },
      showTable: false,
      dialogVisible: false,
      dialogImageUrl: null
    }
  },
  created() {
    this.setShowProductTip()
  },
  computed: {
    // 是否展示提示信息
    isTip() {
      for (const i of this.skuMetaForm.tableData) {
        if (i.isTip) {
          return true
        }
      }
      return false
    }
  },
  methods: {
    changeSkuId(item) {
      const row = item.options.find(i => i.propValueId === item.propValueId)
      item.redLinePrice = row?.redLinePrice || null
    },
    // 展开propValueId时
    skuIdSelectVisible(tag, row, $index) {
      if (tag && row.propValueId) {
        const arr = this.skuMetaForm.tableData
        row.options.forEach(item => {
          this.$set(item, 'disabled', false)
        })
        arr.forEach((item, index) => {
          row.options.forEach(i => {
            if ($index !== index && item.propValueId === i.propValueId) {
              if (item.propValueId === i.propValueId) {
                this.$set(i, 'disabled', true)
              }
            }
          })
        })
      }
    },
    // 模糊搜索规格
    remoteMethod(query, row) {
      if (query !== '') {
        row.loading = true
        clearTimeout(this.timeout)
        this.timeout = setTimeout(async () => {
          const form = this.form.prodSpu
          const res = await productListApi.querySpecsPropList({ spuNum: form.spuNum, catId: form.catId, keyWord: query })
          if (res.data) {
            row.options = []
            const arr = this.skuMetaForm.tableData
            res.data.forEach(item => {
              if (arr.find(i => i.propValueId === item.propValueId)) {
                item.disabled = true
              }
            })
            row.options = res.data
            row.loading = false
          }
        }, 2000)
      } else {
        row.options = []
      }
    },
    // 添加规格
    addSpecs() {
      this.skuMetaForm.tableData.push({
        propValueId: null,
        fileList: [],
        listPrice: null,
        redLinePrice: null,
        salePrice: null,
        skuReduceStorage: null,
        loading: false,
        options: null,
        isTip: false
      })
    },
    // 当销售价格改变时
    changeSalePrice(row) {
      if (row.redLinePrice !== null && row.salePrice < row.redLinePrice) {
        row.isTip = true
      } else {
        row.isTip = false
      }
    },
    // 删除规格
    deleteSku(row, index) {
      this.skuMetaForm.tableData.splice(index, 1)
    },
    // 数组更新时重新获取数据
    handleFileData(arr, item) {
      item.fileList = arr
    },
    /**
     * 设置商品属性展示的提示信息
     */
    setShowProductTip() {
      let isShow = false
      for (const key of this.form.skuMetasArray) {
        if (key.productProp.propRequired) {
          isShow = false
          break
        } else {
          isShow = true
        }
      }
      return isShow
    },
    /**
     * 获取上传成功的图片
     */
    handleSuccess(data, item) {
      item.fileList.push({
        id: data.id,
        url: data.url
      })
    },
    /**
     * 移除图片
     */
    handleRemove(file, item) {
      item.fileList = item.fileList.filter(v => {
        return v.id !== file.id
      })
    },
    /**
     * 限制不能输入数字
     */
    limiInputType(e) {
      limiInputType(e)
    },
    /**
       *初始化表格
       */
    initTable() {
      this.skuMetaForm.tableData = []
      this.showTable = false
    },
    /**
     * 处理表单数据
     */
    handFormData() {
      const formData = {
        skuProps: [],
        shopSpu: {
          prodSkus: [],
          spuFreezeStorage: this.form.shopSpu.spuFreezeStorage,
          spuStorage: this.form.shopSpu.spuStorage
        }
      }
      this.form.skuMetasArray.forEach(item => {
        formData.skuProps.push({
          propId: item.productProp.propId,
          metaValues: this.skuMetaForm.tableData.map(item => { return { propValueId: item.propValueId } })
        })
      })
      this.skuMetaForm.tableData.forEach((item, index, arr) => {
        formData.shopSpu.prodSkus.push({
          listProdImg: item.fileList.map((item, index) => { return { imgId: item.id, imgNum: index + 1, imgUrl: item.url } }),
          prodPrice: { listPrice: item.listPrice, salePrice: item.salePrice },
          skuPropValuesId: [item.propValueId],
          skuReduceStorage: item.skuReduceStorage,
          oldSkuId: item.skuId || null,
          packageCode: item.packageCode || null
          // listProdStorage: [{ spuStorage: item.spuStorage, spuFreezeStorage: item.spuFreezeStorage }]
        })
      })
      formData.shopSpu.storageMinusType = this.form.shopSpu.storageMinusType
      return formData
    },
    /**
      * 选中单品信息时触发
      */
    selectedSkuMetas(val, row) {
      row.propId = row.productProp.propId
      this.form.tableLabel = ''
      for (const i of this.form.skuMetasArray) {
        if (i.checkList.length <= 0 && i.productProp.propRequired) {
          this.showTable = false
          return
        } else {
          this.form.tableLabel += i.productProp.propName + '/'
          row.propsLable = []
          val.forEach(item => {
            row.propMetaValues.forEach(v => {
              if (item === v.propValueId) {
                row.propsLable.push(v.propValue)
              }
            })
          })
        }
      }
      this.showTable = true
      this.form.tableLabel = this.form.tableLabel.substring(0, this.form.tableLabel.length - 1)
 
      this.getCheckedText() // 获取选中的checkBox的label
    },
    /**
     * 获取选中的checkBox的label
     */
    getCheckedText() {
      const columnsArray = []
      const columnsIdArray = []
      this.form.skuMetasArray.forEach(item => {
        if (item.checkList.length) {
          columnsArray.push(item.propsLable)
          columnsIdArray.push(item.checkList)
        }
      })
 
      const combinationArray = this.getCombination(columnsArray) // 获取选中值的多种组合形式Label
      const combinationPropIdArray = this.getCombination(columnsIdArray) // 获取选中值的多种组合形式propId
 
      this.getColumnsText(combinationArray, combinationPropIdArray) // 获取选中的label
    },
    /**
     * 删除
     */
    del(row) {
      const arr = []
      this.skuMetaForm.tableData.forEach((v) => {
        v.skuPropIds && v.skuPropIds.forEach(k => {
          arr.push(k)
        })
      })
      const idsBefore = Array.from(new Set(arr))
      this.skuMetaForm.tableData = this.skuMetaForm.tableData.filter(v => {
        return v.skuPropIds.sort().toString() !== row.skuPropIds.sort().toString()
      })
      const array = []
      this.skuMetaForm.tableData.forEach((v) => {
        v.skuPropIds.forEach(k => {
          array.push(k)
        })
      })
      const idsAfter = Array.from(new Set(array))
      const delArray = idsBefore.filter((item) => {
        return idsAfter.indexOf(item) === -1
      })
      this.form.skuMetasArray.forEach(v => {
        v.checkList = v.checkList.filter(k => {
          let flag = true
          delArray.forEach(l => {
            if (k === l) {
              flag = false
            }
          })
          return flag
        })
        // 获取对应ID的label
        v.propsLable = []
        v.checkList.forEach(item => {
          v.propMetaValues.forEach(i => {
            if (item === i.propValueId) {
              v.propsLable.push(i.propValue)
            }
          })
        })
      })
    },
    /**
     *获取选中的label
     */
    getColumnsText(array, combinationPropIdArray) {
      let tableData = []
      array.forEach((item, index) => {
        combinationPropIdArray[index] && tableData.push({
          columnsText: item.join('/'),
          salePrice: null,
          listPrice: null,
          skuPropIds: combinationPropIdArray[index],
          fileList: [],
          skuReduceStorage: null
        })
      })
      this.skuMetaForm.tableData.forEach(v => {
        tableData = tableData.map(k => {
          if (v.skuPropIds.sort().toString() === k.skuPropIds.sort().toString()) {
            return v
          }
          return k
        })
      })
      this.skuMetaForm.tableData = JSON.parse(JSON.stringify(tableData))
    },
    /**
     * 获取选中值的多种组合形式
     */
    getCombination(array) {
      let resultArr = []
      array.forEach((arrItem) => {
        if (resultArr.length === 0) {
          const firstItem = []
          arrItem.forEach(item => {
            firstItem.push([item])
          })
          resultArr = firstItem
        } else {
          const emptyArray = []
          resultArr.forEach((item) => {
            arrItem.forEach((value) => {
              emptyArray.push([...item, value])
            })
          })
          resultArr = emptyArray
        }
      })
      return resultArr
    }
  }
}
</script>
<style lang="scss" scoped>
/* .disabled .el-upload--picture-card {
    display: none!important;
}
.productTip{
  color: #D70012;
} */
$wh: 80px;
.itemTip {
  text-align: right;
  margin-bottom: 5px;
}
.table-item {
  margin-bottom: 0;
  /deep/.el-form-item__content {
    display: flex;
  }
}
/deep/.table-upload-img {
  // width: $wh;
  // height: $wh;
  margin: 0 auto;
  .avatar-uploader-icon {
    width: $wh;
    height: $wh;
    line-height: $wh !important;
    font-size: 12px;
  }
  .upload-list__item {
    margin: 0;
    width: $wh !important;
    height: $wh !important;
    border-radius: 6px;
    img {
      border: 1px solid #c0ccda;
    }
    img,
    .el-upload-list__item-actions {
      width: $wh !important;
      height: $wh !important;
      line-height: $wh !important;
    }
  }
}
/deep/.el-dialog .el-dialog__body {
  img,
  video {
    width: 100% !important;
  }
}
.inputTip {
  border: 1px solid #d70012;
  border-radius: 4px;
}
</style>