30
30
</el-radio-group >
31
31
</el-form-item >
32
32
<el-form-item label =" 优惠设置" >
33
- <!-- TODO 待实现!这个实现下哈 -->
33
+ <template v-for =" (item ,index ) in formData .rules " :key =" index " >
34
+ <el-row type =" flex" >
35
+ <el-col :span =" 24" style =" font-weight : bold ;display : flex ;" >活动层级{{ index+1 }}<el-button link type =" danger" style =" margin-left : auto ;" v-if =" index!=0" @click =" deleteStratum(index)" >删除</el-button ></el-col >
36
+ <e-form :ref =" 'formRef'+index" :model =" item" >
37
+ <el-form-item label =" 优惠门槛:" prop =" limit" label-width =" 100px" style =" padding-left : 50px ;" >满<el-input style =" width : 150px ;padding :0 10px ;" v-model =" item.limit" type =' number' placeholder =" " /> 元
38
+ </el-form-item >
39
+ <el-form-item label =" 优惠内容:" label-width =" 100px" style =" padding-left : 50px ;" >
40
+ <el-checkbox-group v-model =" rules[index]" style =" width :100% " >
41
+ <el-col :span =" 24" >
42
+ <el-checkbox label =" 订单金额优惠" name =" type" />
43
+ <el-form-item v-if =" rules[index].includes('订单金额优惠')" >
44
+ 减<el-input style =" width : 150px ;padding :0 20px ;" v-model =" item.discountPrice" type =' number' placeholder =" " />元
45
+ </el-form-item >
46
+ </el-col >
47
+ <el-col :span =" 24" ><el-checkbox v-model =" item.freeDelivery" label =" 包邮" name =" type" /></el-col >
48
+ <el-col :span =" 24" >
49
+ <el-checkbox label =" 送积分" name =" type" />
50
+ <el-form-item v-if =" rules[index].includes('送积分')" >
51
+ 送<el-input style =" width : 150px ;padding :0 20px ;" v-model =" item.point" type =' number' placeholder =" " />积分
52
+ </el-form-item >
53
+ </el-col >
54
+ <!-- 优惠券待处理 也可以参考优惠劵的SpuShowcase-->
55
+ <!-- TODO 待实现!-->
56
+ <el-col :span =" 24" ><el-checkbox label =" 送优惠券" name =" type" /></el-col >
57
+ </el-checkbox-group >
58
+ </el-form-item >
59
+ </e-form >
60
+ </el-row >
61
+ </template >
62
+ <el-button type =" primary" @click =" addStratum" >添加活动层级</el-button >
34
63
</el-form-item >
35
64
<el-form-item label =" 活动商品" prop =" productScope" >
36
65
<el-radio-group v-model =" formData.productScope" >
78
107
import { getSpuSimpleList } from ' @/api/mall/product/spu'
79
108
import { DICT_TYPE , getIntDictOptions } from ' @/utils/dict'
80
109
import { CommonStatusEnum } from ' @/utils/constants'
81
- import * as ProductBrandApi from ' @/api/mall/product/brand '
110
+ import * as RewardActivityApi from ' @/api/mall/promotion/reward/rewardActivity '
82
111
import {
83
112
PromotionConditionTypeEnum ,
84
113
PromotionProductScopeEnum ,
@@ -112,16 +141,27 @@ const formData = ref({
112
141
remark: undefined ,
113
142
productScope: PromotionProductScopeEnum .ALL .scope ,
114
143
productSpuIds: undefined ,
115
- rules: undefined
144
+ rules: [{
145
+ limit: undefined ,
146
+ discountPrice: undefined ,
147
+ freeDelivery: undefined ,
148
+ point: undefined ,
149
+ couponIds: [],
150
+ couponCounts: []
151
+ }],
116
152
})
153
+ // 优惠设置
154
+ let rules= reactive ([]);
155
+ // 优惠券列表
156
+
117
157
const formRules = reactive ({
118
158
name: [{ required: true , message: ' 活动名称不能为空' , trigger: ' blur' }],
119
159
startAndEndTime: [{ required: true , message: ' 活动时间不能为空' , trigger: ' blur' }],
120
160
conditionType: [{ required: true , message: ' 条件类型不能为空' , trigger: ' change' }],
121
161
productScope: [{ required: true , message: ' 商品范围不能为空' , trigger: ' blur' }],
122
162
productSpuIds: [{ required: true , message: ' 商品范围不能为空' , trigger: ' blur' }]
123
163
})
124
- const formRef = ref () // 表单 Ref
164
+ const formRef = ref ([] ) // 表单 Ref
125
165
126
166
/** 打开弹窗 */
127
167
const open = async (type : string , id ? : number ) => {
@@ -133,19 +173,23 @@ const open = async (type: string, id?: number) => {
133
173
if (id ) {
134
174
formLoading .value = true
135
175
try {
136
- // formData.value = await ProductBrandApi.getBrand(id)
137
- formData .value = {
138
- conditionType: 10 ,
139
- description: ' ' ,
140
- id: undefined ,
141
- name: ' 测试活动' ,
142
- picUrl: ' ' ,
143
- productScope: 2 ,
144
- productSpuIds: [634 ],
145
- remark: ' 测试备注' ,
146
- startAndEndTime: [new Date (), new Date (' 2023-12-31' )],
147
- status: 0
176
+ let data= await RewardActivityApi .getReward (id );
177
+ data .startAndEndTime = [new Date (data .startTime ), new Date (data .endTime )];
178
+ rules .splice (0 ,rules .length );
179
+ data .rules .forEach ((item )=> {
180
+ let ars: string []= reactive ([]);
181
+ if (item .freeDelivery ){
182
+ ars .push (' 包邮' )
183
+ }
184
+ if (item .point ){
185
+ ars .push (' 送积分' )
186
+ }
187
+ if (item .discountPrice ){
188
+ ars .push (' 订单金额优惠' )
148
189
}
190
+ rules .push (ars )
191
+ })
192
+ formData .value = data
149
193
} finally {
150
194
formLoading .value = false
151
195
}
@@ -160,18 +204,33 @@ const submitForm = async () => {
160
204
if (! formRef ) return
161
205
const valid = await formRef .value .validate ()
162
206
if (! valid ) return
163
- console .log (formData .value )
164
- message .success (' 已在控制台打印数据' )
165
- return
207
+ // 处理下数据兼容接口
208
+ formData .value .startTime = + new Date (formData .value .startAndEndTime [0 ])
209
+ formData .value .endTime = + new Date (formData .value .startAndEndTime [1 ])
210
+ console .log (rules )
211
+ rules .forEach ((item ,index )=> {
212
+ if (item .includes (' 包邮' )){
213
+ formData .value .rules [index ].freeDelivery = true ;
214
+ }else {
215
+ formData .value .rules [index ].freeDelivery = false ;
216
+ }
217
+ if (! item .includes (' 送积分' )){
218
+ formData .value .rules [index ].point = undefined ;
219
+ }
220
+ if (! item .includes (' 订单金额优惠' )){
221
+ formData .value .rules [index ].discountPrice = undefined ;
222
+ }
223
+ })
224
+
166
225
// 提交请求
167
226
formLoading .value = true
168
227
try {
169
- const data = formData .value as ProductBrandApi . BrandVO
228
+ const data = formData .value as RewardActivityApi . DiscountActivityVO
170
229
if (formType .value === ' create' ) {
171
- await ProductBrandApi . createBrand (data )
230
+ await RewardActivityApi . createRewardActivity (data )
172
231
message .success (t (' common.createSuccess' ))
173
232
} else {
174
- await ProductBrandApi . updateBrand (data )
233
+ await RewardActivityApi . updateRewardActivity (data )
175
234
message .success (t (' common.updateSuccess' ))
176
235
}
177
236
dialogVisible .value = false
@@ -182,15 +241,50 @@ const submitForm = async () => {
182
241
}
183
242
}
184
243
244
+ const addStratum = ()=> {
245
+ formData .value .rules .push ({
246
+ limit: undefined ,
247
+ discountPrice: undefined ,
248
+ freeDelivery: undefined ,
249
+ point: undefined ,
250
+ couponIds: [],
251
+ couponCounts: []
252
+ })
253
+ rules .push ([]);
254
+ console .log (rules )
255
+ }
256
+
257
+ const deleteStratum= (index )=> {
258
+ formData .value .rules .splice (index ,1 )
259
+ rules .splice (index ,1 )
260
+ }
261
+
185
262
/** 重置表单 */
186
263
const resetForm = () => {
187
264
formData .value = {
188
265
id: undefined ,
189
- name: ' ' ,
190
- picUrl: ' ' ,
191
- status: CommonStatusEnum .ENABLE ,
192
- description: ' '
266
+ name: undefined ,
267
+ startAndEndTime: undefined ,
268
+ startTime: undefined ,
269
+ endTime: undefined ,
270
+ conditionType: PromotionConditionTypeEnum .PRICE .type ,
271
+ remark: undefined ,
272
+ productScope: PromotionProductScopeEnum .ALL .scope ,
273
+ productSpuIds: undefined ,
274
+ rules: [{
275
+ limit: undefined ,
276
+ discountPrice: undefined ,
277
+ freeDelivery: undefined ,
278
+ point: undefined ,
279
+ couponIds: [],
280
+ couponCounts: []
281
+ }],
193
282
}
283
+ rules .splice (0 ,rules .length );
284
+ rules .push (reactive ([]));
285
+ // 解决下有时刷新页面第一次点编辑报错
286
+ nextTick (()=> {
194
287
formRef .value ?.resetFields ()
288
+ })
195
289
}
196
290
</script >
0 commit comments