70
70
@pagination =" getList" />
71
71
72
72
<!-- 对话框(添加 / 修改) -->
73
- <el-dialog :title =" title" :visible.sync =" open" width =" 600px " v-dialogDrag append-to-body >
73
+ <el-dialog :title =" title" :visible.sync =" open" width =" 1000px " v-dialogDrag append-to-body >
74
74
<el-form ref =" form" :model =" form" :rules =" rules" label-width =" 80px" >
75
75
<el-form-item label =" 活动名称" prop =" name" >
76
76
<el-input v-model =" form.name" placeholder =" 请输入活动名称" />
80
80
</el-form-item >
81
81
<el-form-item label =" 活动时间" prop =" startAndEndTime" >
82
82
<el-date-picker clearable v-model =" form.startAndEndTime" type =" datetimerange" :default-time =" ['00:00:00', '23:59:59']"
83
- value-format =" timestamp" placeholder =" 选择开始时间" style =" width : 480px " />
83
+ value-format =" timestamp" placeholder =" 选择开始时间" style =" width : 880px " />
84
+ </el-form-item >
85
+ <el-form-item label =" 商品选择" >
86
+ <el-select v-model =" form.skuIds" placeholder =" 请选择活动商品" clearable size =" small"
87
+ multiple filterable style =" width : 400px " @change =" changeFormSku" >
88
+ <el-option v-for =" item in productSkus" :key =" item.id" :label =" item.name" :value =" item.id" >
89
+ <span style =" float : left " >{{ item.spuName }}   ; {{ item.name}}</span >
90
+ <span style =" float : right ; color : #8492a6 ; font-size : 13px " >¥{{ (item.price / 100.0).toFixed(2) }}</span >
91
+ </el-option >
92
+ </el-select >
93
+ <el-table v-loading =" loading" :data =" form.products" >
94
+ <el-table-column label =" 商品名称" align =" center" width =" 200" >
95
+ <template slot-scope="scope">
96
+ {{ scope.row.spuName }}   ; {{ scope.row.name}}
97
+ </template >
98
+ </el-table-column >
99
+ <el-table-column label =" 商品价格" align =" center" prop =" price" >
100
+ <template slot-scope="scope">
101
+ ¥{{ (scope.row.price / 100.0).toFixed(2) }}
102
+ </template >
103
+ </el-table-column >
104
+ <el-table-column label =" 库存" align =" center" prop =" stock" />
105
+ <el-table-column label =" 优惠类型" align =" center" >
106
+ <template slot-scope="scope">
107
+ <el-select v-model =" scope.row.discountType" placeholder =" 请选择优惠类型" >
108
+ <el-option v-for =" dict in getDictDatas(DICT_TYPE.PROMOTION_DISCOUNT_TYPE)"
109
+ :key =" dict.value" :label =" dict.label" :value =" parseInt(dict.value)" />
110
+ </el-select >
111
+ </template >
112
+ </el-table-column >
113
+ <el-table-column label =" 优惠" align =" center" prop =" startTime" width =" 250" >
114
+ <template slot-scope="scope">
115
+ <el-form-item v-if =" scope.row.discountType === PromotionDiscountTypeEnum.PRICE.type" prop =" discountPrice" >
116
+ 减 <el-input-number v-model =" scope.row.discountPrice" placeholder =" 请输入优惠金额"
117
+ style =" width : 190px " :precision =" 2" :min =" 0" /> 元
118
+ </el-form-item >
119
+ <el-form-item v-if =" scope.row.discountType === PromotionDiscountTypeEnum.PERCENT.type" prop =" discountPercent" >
120
+ 打 <el-input-number v-model =" scope.row.discountPercent" placeholder =" 请输入优惠折扣"
121
+ style =" width : 190px " :precision =" 1" :min =" 1" :max =" 9.9" /> 折
122
+ </el-form-item >
123
+ </template >
124
+ </el-table-column >
125
+ <el-table-column label =" 操作" align =" center" class-name =" small-padding fixed-width" >
126
+ <template slot-scope="scope">
127
+ <el-button size =" mini" type =" text" icon =" el-icon-delete" @click =" removeFormSku(scope.row.skuId)" >删除</el-button >
128
+ </template >
129
+ </el-table-column >
130
+ </el-table >
84
131
</el-form-item >
85
132
</el-form >
86
133
<div slot =" footer" class =" dialog-footer" >
93
140
94
141
<script >
95
142
import { createDiscountActivity , updateDiscountActivity , deleteDiscountActivity , getDiscountActivity , getDiscountActivityPage } from " @/api/mall/promotion/discountActivity" ;
96
- import {PromotionActivityStatusEnum , PromotionProductScopeEnum } from " @/utils/constants" ;
97
- import {closeRewardActivity } from " @/api/mall/promotion/rewardActivity" ;
143
+ import {
144
+ PromotionActivityStatusEnum , PromotionDiscountTypeEnum ,
145
+ PromotionProductScopeEnum
146
+ } from " @/utils/constants" ;
147
+ import { getSkuOptionList } from " @/api/mall/product/sku" ;
98
148
99
149
export default {
100
150
name: " DiscountActivity" ,
@@ -115,7 +165,7 @@ export default {
115
165
// 弹出层名称
116
166
title: " " ,
117
167
// 是否显示弹出层
118
- open: false ,
168
+ open: true ,
119
169
// 查询参数
120
170
queryParams: {
121
171
pageNo: 1 ,
@@ -125,17 +175,38 @@ export default {
125
175
createTime: [],
126
176
},
127
177
// 表单参数
128
- form: {},
178
+ form: {
179
+ skuIds: [], // 选中的 SKU
180
+ 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
+ },
129
199
// 表单校验
130
200
rules: {
131
201
name: [{ required: true , message: " 活动名称不能为空" , trigger: " blur" }],
132
202
startAndEndTime: [{ required: true , message: " 活动时间不能为空" , trigger: " blur" }],
133
203
},
134
- // 商品列表
135
- productSpus : [], // TODO 芋艿:需要重新写下
204
+ // 商品 SKU 列表
205
+ productSkus : [],
136
206
// 如下的变量,主要为了 v-if 判断可以使用到
137
207
PromotionProductScopeEnum: PromotionProductScopeEnum,
138
208
PromotionActivityStatusEnum: PromotionActivityStatusEnum,
209
+ PromotionDiscountTypeEnum: PromotionDiscountTypeEnum,
139
210
};
140
211
},
141
212
created () {
@@ -151,6 +222,10 @@ export default {
151
222
this .total = response .data .total ;
152
223
this .loading = false ;
153
224
});
225
+ // 获得 SKU 商品列表
226
+ getSkuOptionList ().then (response => {
227
+ this .productSkus = response .data ;
228
+ });
154
229
},
155
230
/** 取消按钮 */
156
231
cancel () {
@@ -166,6 +241,8 @@ export default {
166
241
startTime: undefined ,
167
242
endTime: undefined ,
168
243
remark: undefined ,
244
+ skuIds: [],
245
+ products: [],
169
246
};
170
247
this .resetForm (" form" );
171
248
},
@@ -240,7 +317,49 @@ export default {
240
317
this .getList ();
241
318
this .$modal .msgSuccess (" 关闭成功" );
242
319
}).catch (() => {});
243
- }
320
+ },
321
+ /** 当 Form 的 SKU 发生变化时 */
322
+ changeFormSku (skuIds ) {
323
+ // 处理【新增】
324
+ skuIds .forEach (skuId => {
325
+ // 获得对应的 SKU 信息
326
+ const sku = this .productSkus .find (item => item .id === skuId);
327
+ if (! sku) {
328
+ // debugger
329
+ return ;
330
+ }
331
+ // 判断已存在,直接跳过
332
+ const product = this .form .products .find (item => item .skuId === skuId);
333
+ if (product) {
334
+ // debugger
335
+ return ;
336
+ }
337
+ this .form .products .push ({
338
+ skuId: sku .id ,
339
+ name: sku .name ,
340
+ price: sku .price ,
341
+ stock: sku .stock ,
342
+ spuId: sku .spuId ,
343
+ spuName: sku .spuName ,
344
+ discountType: PromotionDiscountTypeEnum .PRICE .type ,
345
+ });
346
+ });
347
+ // 处理【移除】
348
+ this .form .products .map ((product , index ) => {
349
+ if (! skuIds .includes (product .skuId )) {
350
+ this .form .products .splice (index, 1 );
351
+ }
352
+ });
353
+ },
354
+ /** 移除 Form 的 SKU */
355
+ removeFormSku (skuId ) {
356
+ this .form .skuIds .map ((id , index ) => {
357
+ if (skuId === id) {
358
+ this .form .skuIds .splice (index, 1 );
359
+ }
360
+ });
361
+ this .changeFormSku (this .form .skuIds );
362
+ },
244
363
}
245
- };
364
+ }
246
365
</script >
0 commit comments