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
<template>
  <div>
    <el-form-item class="formItemContent" required>
      <el-button @click="addProduct" type="primary">选择活动商品</el-button>
      <el-button @click="clearTable" v-if="!isHide">清空</el-button>
    </el-form-item>
    <el-form-item prop="promotionProducts" class="formItemContent">
      <table-pagination :tableData="tableData">
        <template>
          <el-table-column label="商品主编码" prop="prodMainCode" width="160px" show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="商品名称" prop="prodName" width="160px" show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="商品图片" prop="prodImgUrl">
            <template slot-scope="scope">
              <product-img :imgUrl="scope.row.prodImgUrl"></product-img>
            </template>
          </el-table-column>
          <el-table-column label="商品规格*数量" width="160px">
            <template slot-scope="scope">
              <span v-if="scope.row.prodSpecs">{{scope.row.prodSpecs}}</span>
              <span v-else>-</span>
            </template>
          </el-table-column>
          <el-table-column label="商品价格" prop="prodPrice">
            <template slot-scope="scope">
              {{ scope.row.prodPrice ? '¥ '+scope.row.prodPrice : '-' }}
            </template>
          </el-table-column>
          <el-table-column label="剩余库存" prop="spuStorage" width="100px" show-overflow-tooltip
                           align="center" v-if="isShowSpuStorage"></el-table-column>
          <el-table-column label="拼团价" width="210px">
            <template slot-scope="scope">
              <el-form-item :prop="`promotionProducts.${scope.$index}.salePrice`"
                            :rules="formRules.salePrice">
                ¥
                <el-input-number :min="0" v-model="scope.row.salePrice"
                                 :disabled="scope.row.isShow"></el-input-number>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column label="拼团库存" width="195px">
            <template slot="header">
              拼团库存
              <el-popover placement="top" width="260" trigger="click"
                          content="注:拼团活动创建保存后即扣减【剩余库存】数量至拼团库存进行锁定,活动结束后返还余下拼团库存至剩余库存中">
                <i class="el-icon-question" style="cursor:pointer;" slot="reference"></i>
              </el-popover>
            </template>
            <template slot-scope="scope">
              <el-form-item :prop="`promotionProducts.${scope.$index}.reservestock`"
                            :rules="formRules.ensalequantity">
                <el-input-number :min="0" v-model="scope.row.reservestock"></el-input-number>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column label="限购数量" width="165px">
            <template slot-scope="scope">
              <el-form-item :prop="`promotionProducts.${scope.$index}.maxbuyquantity`"
                            :rules="formRules.maxbuyquantity">
                <el-input-number :min="0" v-model="scope.row.maxbuyquantity"></el-input-number>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column width="80px" label="操作">
            <template slot-scope="scope">
              <el-form-item>
                <el-button type="danger" :disabled="scope.row.isShow" size="mini"
                           @click="deleteItem(scope.row,scope.$index)">删除</el-button>
              </el-form-item>
            </template>
          </el-table-column>
        </template>
      </table-pagination>
      <div class="prodTip">注:拼团库存不得高于商品库存</div>
    </el-form-item>
    <product-selected :show.sync='selectedDialog.show' :multipleSKuId="true"
                      :selectedTable="tableData" :multipleSelected="false"
                      :title="selectedDialog.title" :isShowSpuStorage="isShowSpuStorage"
                      @hand-selected-row-data="handSelectedRowData">
    </product-selected>
  </div>
</template>
 
<script>
import tablePagination from '../../blindBoxActivity/components/tablePagination.vue'
import productSelected from '@/views/product/components/productSelected.vue'
import productImg from '@/views/product/components/productImg.vue'
export default {
  components: { tablePagination, productSelected, productImg },
  props: ['productData', 'formRules', 'isHide', 'isShowSpuStorage'],
  data() {
    return {
      selectedDialog: {
        show: false,
        title: '选择活动商品'
      },
      tableData: []
    }
  },
  watch: {
    productData: {
      immediate: true, // immediate选项可以开启首次赋值监听
      handler: function(newValue, oldValue) {
        this.tableData = newValue
      }
    },
    tableData(newValue, oldValue) {
      this.$emit('update:productData', newValue)
    }
  },
  methods: {
    /**
     * 处理表格数据(把每个单品拆开)
     */
    handTableData() {
      const resultTable = []
      this.tableData.forEach(item => {
        if (!item.extparams) {
          item.extparams = {
            shopSpuId: item.shopSpuId,
            shopSkuId: item.shopSkuId,
            shopId: item.shopId,
            skuId: item.skuId
          }
          item.extparams = JSON.stringify(item.extparams)
        }
        resultTable.push(item)
      })
      return resultTable
    },
    /**
       * 清空表格数据
       */
    clearTable() {
      this.tableData = []
    },
    /**
       * 删除表格数据
       */
    deleteItem(row, index) {
      this.tableData.splice(index, 1)
      this.$emit('hand-clear-validate')
    },
    /**
       * 打开添加商品弹窗
       */
    addProduct() {
      this.selectedDialog.show = true
    },
    /**
     * 获取弹出框返回的数据
     */
    handSelectedRowData(rows) {
      // 当取消勾选后表格数据删除
      if (!rows.length) {
        this.tableData = []
      }
      var length = this.tableData.length
      for (let i = 0; i < length; i++) {
        let index = 1
        if (this.tableData[i]) {
          index = rows.find(rowItem => {
            return rowItem.skuId === this.tableData[i].skuId
          })
        }
        if (!index) {
          this.tableData.splice(i, 1)
          i--
          length--
        }
      }
      this.$parent.clearValidate()
      // 勾选后的数增加
      rows.forEach(rowItem => {
        if (!this.tableData.find(item => {
          return rowItem.skuId === item.skuId
        })) {
          const row = rowItem.skuInfos.find(v => v.skuId === rowItem.skuId)
          this.tableData.push({
            prodMainCode: rowItem.spuNum,
            prodImgUrl: rowItem.imageUrl,
            prodId: rowItem.spuId,
            prodName: rowItem.spuName,
            spuStorage: rowItem.spuStorage,
            prodSpecs: rowItem.prodSpecs,
            skuId: rowItem.skuId,
            shopId: rowItem.shopId,
            salePrice: null, // 拼团价
            reservestock: null, // 拼团库存
            maxbuyquantity: null, // 限购数量
            prodPrice: rowItem.salePrice,
            shopSpuId: rowItem.shopSpuId,
            shopSkuId: rowItem.shopSkuId,
            skuArr: rowItem.skuInfos,
            spuNum: rowItem.spuNum,
            skuReduceStorage: row && Number(row.skuReduceStorage)
          })
          console.log(this.tableData)
        }
      })
      this.$emit('hand-selected', rows)
    }
  }
}
</script>
 
<style lang="scss">
.formItemContent {
  .el-form-item__content {
    margin-left: 0 !important;
  }
  .prodTip {
    color: #d70012;
  }
}
</style>