84
84
</el-form-item >
85
85
<el-form-item label =" 商品选择" >
86
86
<el-select v-model =" form.skuIds" placeholder =" 请选择活动商品" clearable size =" small"
87
- multiple filterable style =" width : 400 px " @change =" changeFormSku" >
88
- <el-option v-for =" item in productSkus" :key =" item.id" :label =" item.name" :value =" item.id" >
87
+ multiple filterable style =" width : 880 px " @change =" changeFormSku" >
88
+ <el-option v-for =" item in productSkus" :key =" item.id" :label =" item.spuName + ' ' + item. name" :value =" item.id" >
89
89
<span style =" float : left " >{{ item.spuName }}   ; {{ item.name}}</span >
90
90
<span style =" float : right ; color : #8492a6 ; font-size : 13px " >¥{{ (item.price / 100.0).toFixed(2) }}</span >
91
91
</el-option >
102
102
</template >
103
103
</el-table-column >
104
104
<el-table-column label =" 库存" align =" center" prop =" stock" />
105
- <el-table-column label =" 优惠类型" align =" center" >
105
+ <el-table-column label =" 优惠类型" align =" center" property = " discountType " >
106
106
<template slot-scope="scope">
107
107
<el-select v-model =" scope.row.discountType" placeholder =" 请选择优惠类型" >
108
108
<el-option v-for =" dict in getDictDatas(DICT_TYPE.PROMOTION_DISCOUNT_TYPE)"
114
114
<template slot-scope="scope">
115
115
<el-form-item v-if =" scope.row.discountType === PromotionDiscountTypeEnum.PRICE.type" prop =" discountPrice" >
116
116
减 <el-input-number v-model =" scope.row.discountPrice" placeholder =" 请输入优惠金额"
117
- style =" width : 190px " :precision =" 2" :min =" 0" /> 元
117
+ style =" width : 190px " :precision =" 2" :min =" 0" :max = " scope.row.price / 100.0 - 0.01 " /> 元
118
118
</el-form-item >
119
119
<el-form-item v-if =" scope.row.discountType === PromotionDiscountTypeEnum.PERCENT.type" prop =" discountPercent" >
120
120
打 <el-input-number v-model =" scope.row.discountPercent" placeholder =" 请输入优惠折扣"
139
139
</template >
140
140
141
141
<script >
142
- import { createDiscountActivity , updateDiscountActivity , deleteDiscountActivity , getDiscountActivity , getDiscountActivityPage } from " @/api/mall/promotion/discountActivity" ;
142
+ import {
143
+ createDiscountActivity ,
144
+ updateDiscountActivity ,
145
+ deleteDiscountActivity ,
146
+ getDiscountActivity ,
147
+ getDiscountActivityPage ,
148
+ closeDiscountActivity
149
+ } from " @/api/mall/promotion/discountActivity" ;
143
150
import {
144
151
PromotionActivityStatusEnum , PromotionDiscountTypeEnum ,
145
152
PromotionProductScopeEnum
146
153
} from " @/utils/constants" ;
147
154
import { getSkuOptionList } from " @/api/mall/product/sku" ;
155
+ import { deepClone } from " @/utils" ;
148
156
149
157
export default {
150
158
name: " DiscountActivity" ,
@@ -165,7 +173,7 @@ export default {
165
173
// 弹出层名称
166
174
title: " " ,
167
175
// 是否显示弹出层
168
- open: true ,
176
+ open: false ,
169
177
// 查询参数
170
178
queryParams: {
171
179
pageNo: 1 ,
@@ -178,28 +186,12 @@ export default {
178
186
form: {
179
187
skuIds: [], // 选中的 SKU
180
188
products: [], // 商品信息
181
- // products: [{
182
- // id: 2,
183
- // name: '白色',
184
- // price: 500,
185
- // stock: 20,
186
- // spuId: 1,
187
- // spuName: 'iPhone 14 Pro',
188
- // discountType: 1,
189
- // }, {
190
- // id: 10,
191
- // name: '蓝色',
192
- // price: 1000,
193
- // stock: 100,
194
- // spuId: 20,
195
- // spuName: 'iPhone 14 Pro',
196
- // discountType: 2,
197
- // }]
198
189
},
199
190
// 表单校验
200
191
rules: {
201
192
name: [{ required: true , message: " 活动名称不能为空" , trigger: " blur" }],
202
193
startAndEndTime: [{ required: true , message: " 活动时间不能为空" , trigger: " blur" }],
194
+ skuIds: [{ required: true , message: " 选择商品不能为空" , trigger: " blur" }],
203
195
},
204
196
// 商品 SKU 列表
205
197
productSkus: [],
@@ -268,7 +260,24 @@ export default {
268
260
const id = row .id ;
269
261
getDiscountActivity (id).then (response => {
270
262
this .form = response .data ;
263
+ // 修改数据
271
264
this .form .startAndEndTime = [response .data .startTime , response .data .endTime ];
265
+ this .form .skuIds = response .data .products .map (item => item .skuId );
266
+ this .form .products .forEach (product => {
267
+ // 获得对应的 SKU 信息
268
+ const sku = this .productSkus .find (item => item .id === product .skuId );
269
+ if (! sku) {
270
+ return ;
271
+ }
272
+ // 设置商品信息
273
+ product .name = sku .name ;
274
+ product .spuName = sku .spuName ;
275
+ product .price = sku .price ;
276
+ product .stock = sku .stock ;
277
+ product .discountPrice = product .discountPrice !== undefined ? product .discountPrice / 100.0 : undefined ;
278
+ product .discountPercent = product .discountPercent !== undefined ? product .discountPercent / 10.0 : undefined ;
279
+ });
280
+ // 打开弹窗
272
281
this .open = true ;
273
282
this .title = " 修改限时折扣活动" ;
274
283
});
@@ -279,19 +288,29 @@ export default {
279
288
if (! valid) {
280
289
return ;
281
290
}
282
- this .form .startTime = this .form .startAndEndTime [0 ];
283
- this .form .endTime = this .form .startAndEndTime [1 ];
291
+ // 处理数据
292
+ const data = deepClone (this .form ); // 必须深拷贝,不然后面的 products 操作会有影响
293
+ data .startTime = this .form .startAndEndTime [0 ];
294
+ data .endTime = this .form .startAndEndTime [1 ];
295
+ data .products .forEach (product => {
296
+ product .discountPrice = product .discountPrice !== undefined ? product .discountPrice * 100 : undefined ;
297
+ product .discountPercent = product .discountPercent !== undefined ? product .discountPercent * 10 : undefined ;
298
+ });
299
+ if (! valid) {
300
+ return ;
301
+ }
302
+
284
303
// 修改的提交
285
304
if (this .form .id != null ) {
286
- updateDiscountActivity (this . form ).then (response => {
305
+ updateDiscountActivity (data ).then (response => {
287
306
this .$modal .msgSuccess (" 修改成功" );
288
307
this .open = false ;
289
308
this .getList ();
290
309
});
291
310
return ;
292
311
}
293
312
// 添加的提交
294
- createDiscountActivity (this . form ).then (response => {
313
+ createDiscountActivity (data ).then (response => {
295
314
this .$modal .msgSuccess (" 新增成功" );
296
315
this .open = false ;
297
316
this .getList ();
@@ -312,7 +331,7 @@ export default {
312
331
handleClose (row ) {
313
332
const id = row .id ;
314
333
this .$modal .confirm (' 是否确认关闭限时折扣活动编号为"' + id + ' "的数据项?' ).then (function () {
315
- return closeRewardActivity (id);
334
+ return closeDiscountActivity (id);
316
335
}).then (() => {
317
336
this .getList ();
318
337
this .$modal .msgSuccess (" 关闭成功" );
@@ -325,13 +344,11 @@ export default {
325
344
// 获得对应的 SKU 信息
326
345
const sku = this .productSkus .find (item => item .id === skuId);
327
346
if (! sku) {
328
- // debugger
329
347
return ;
330
348
}
331
349
// 判断已存在,直接跳过
332
350
const product = this .form .products .find (item => item .skuId === skuId);
333
351
if (product) {
334
- // debugger
335
352
return ;
336
353
}
337
354
this .form .products .push ({
0 commit comments