quanwei
2025-10-28 36cacbaf78e510713002fcd5e3d61cece2e01421
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
<template>
  <el-dialog title="商品规格" :visible.sync="dialogVisible" @close='dialogFormVisible' :close-on-click-modal="false"
    :close-on-press-escape="false">
    <el-form size="small" ref="form" :model="form1" label-width="250px" :loading="loading">
      <el-form-item label="" label-width="20px">
        <el-table :data="productDetail.specData.spec_list" :span-method="objectSpanMethod" border style="width: 100%; margin-top: 20px">
          <el-table-column width="180" :label="item.group_name" :key="item.group_name" v-for="(item, index) in productDetail.specData.spec_attr">
            <template slot-scope="scope">
              {{scope.row.rows[index].spec_value}}
            </template>
          </el-table-column>
          <el-table-column label="兑换积分">
            <template slot-scope="scope">
              <el-form-item label="" style="margin-bottom: 0;">
                <el-input size="small" type="number" v-model="scope.row.spec_form.point_num"  :disabled="true"></el-input>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column label="兑换金额">
            <template slot-scope="scope">
              <el-form-item label="" style="margin-bottom: 0;">
                <el-input size="small" type="number" v-model="scope.row.spec_form.point_money"  :disabled="true"></el-input>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column label="活动库存">
            <template slot-scope="scope">
              <el-form-item label="" style="margin-bottom: 0;">
                <el-input size="small" type="number" v-model="scope.row.spec_form.stock"  :disabled="true"></el-input>
              </el-form-item>
            </template>
          </el-table-column>
        </el-table>
      </el-form-item>
 
 
    </el-form>
 
 
 
  </el-dialog>
</template>
 
<script>
  import PointProductApi from '@/api/pointproduct.js';
  export default {
    data() {
      return {
        form1: {
          deduct_stock_type: 10,
          status: 0,
          product_id: 0,
          sort: 1,
        },
        /*左边长度*/
        formLabelWidth: '120px',
        /*是否显示*/
        loading: false,
        dialogVisible: false,
        point_product_id: 0,
        /*商品详情*/
        productDetail: {
          spec_type: 10,
          sku: {},
          specData: {}
        },
      };
    },
    props: ['open_edit', 'userModel'],
    created() {
 
      this.dialogVisible = this.open_edit;
      this.point_product_id = this.userModel.point_product_id;
 
 
      /*获取列表*/
      this.getData();
    },
    methods: {
 
      getData() {
        let self = this;
        let point_product_id = self.point_product_id;
        PointProductApi.getProductData({
            point_product_id: point_product_id
          }, true)
          .then(data => {
            self.form1 = data.data.data;
            self.form1.product_id = data.data.data.product_id;
            self.productDetail.spec_type = self.form1.product.spec_type;
            self.productDetail.specData = data.data.specData;
 
            // self.form1 = data.data.data;
            // self.productDetail.spec_type = self.form1.product.spec_type;
            // self.productDetail.specData = data.data.specData;
 
            self.buildSkulist();
 
          })
          .catch(error => {
            self.loading = false;
          });
      },
 
 
      /**
       * 构建规格组合列表
       */
      buildSkulist: function() {
        var self = this;
        var spec_attr = self.productDetail.specData.spec_attr;
        var specArr = [];
        for (var i = 0; i < spec_attr.length; i++) {
          specArr.push(spec_attr[i].spec_items);
        }
        var specListTemp = self.calcDescartes(specArr);
 
        var specList = [];
        for (var i = 0; i < specListTemp.length; i++) {
          var rows = [];
          var specSkuIdAttr = [];
          if (!Array.isArray(specListTemp[i])) {
            rows.push(specListTemp[i]);
          } else {
            rows = specListTemp[i];
          }
          for (var j = 0; j < rows.length; j++) {
            specSkuIdAttr.push(rows[j].item_id);
          }
          specList.push({
            spec_sku_id: specSkuIdAttr.join('_'),
            rows: rows,
            spec_form: {}
          });
        }
 
        // 合并旧sku数据
        if (self.productDetail.specData.spec_list.length > 0 && specList.length > 0) {
          for (i = 0; i < specList.length; i++) {
            var overlap = self.productDetail.specData.spec_list.filter(function(val) {
              return val.spec_sku_id === specList[i].spec_sku_id;
            });
            if (overlap.length > 0) {
              specList[i].spec_form = overlap[0].spec_form;
              specList[i].spec_form.product_sku_id = overlap[0].product_sku_id;
            }
            overlap = self.form1.sku.filter(function(val) {
              return val.product_sku_id === specList[i].spec_form.product_sku_id;
            });
            if (overlap.length > 0) {
              specList[i].spec_form.point_money = overlap[0].point_money;
              specList[i].spec_form.point_num = overlap[0].point_num;
              specList[i].spec_form.stock = overlap[0].stock;
              specList[i].spec_form.point_product_sku_id = overlap[0].point_product_sku_id;
            }
          }
        }
        self.productDetail.specData.spec_list = specList;
 
      },
      calcDescartes: function(array) {
        if (array.length < 2) return array[0] || [];
        return [].reduce.call(array, function(col, set) {
          var res = [];
          col.forEach(function(c) {
            set.forEach(function(s) {
              var t = [].concat(Array.isArray(c) ? c : [c]);
              t.push(s);
              res.push(t);
            });
          });
          return res;
        });
      },
 
      objectSpanMethod({
        row,
        column,
        rowIndex,
        columnIndex
      }) {
        var spec_attr = this.productDetail.specData.spec_attr;
        // 规格组合总数 (table行数)
        var totalRow = 1;
        //比如2个规格,只有第一列有多行
        if (columnIndex < spec_attr.length - 1) {
          let startRowIndex = columnIndex + 1;
          let endRowIndex = spec_attr.length - 1;
          for (var i = startRowIndex; i <= endRowIndex; i++) {
            totalRow *= spec_attr[i].spec_items.length;
          }
          if (rowIndex % totalRow === 0) {
            return {
              rowspan: totalRow,
              colspan: 1
            };
          } else {
            return {
              rowspan: 0,
              colspan: 0
            };
          }
        }
      },
 
      /*关闭弹窗*/
      dialogFormVisible(e) {
        if (e) {
          this.$emit('closeDialog', {
            type: 'success',
            openDialog: false
          })
        } else {
          this.$emit('closeDialog', {
            type: 'error',
            openDialog: false
          })
        }
      }
 
    }
  };
</script>
 
<style></style>