Skip to content

Commit f3ed145

Browse files
committed
promotion:完善限时折扣的修改逻辑
1 parent 90b4562 commit f3ed145

File tree

1 file changed

+47
-30
lines changed
  • src/views/mall/promotion/discountActivity

1 file changed

+47
-30
lines changed

src/views/mall/promotion/discountActivity/index.vue

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@
8484
</el-form-item>
8585
<el-form-item label="商品选择">
8686
<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">
87+
multiple filterable style="width: 880px" @change="changeFormSku">
88+
<el-option v-for="item in productSkus" :key="item.id" :label="item.spuName + ' ' + item.name" :value="item.id">
8989
<span style="float: left">{{ item.spuName }} &nbsp; {{ item.name}}</span>
9090
<span style="float: right; color: #8492a6; font-size: 13px">¥{{ (item.price / 100.0).toFixed(2) }}</span>
9191
</el-option>
@@ -102,7 +102,7 @@
102102
</template>
103103
</el-table-column>
104104
<el-table-column label="库存" align="center" prop="stock" />
105-
<el-table-column label="优惠类型" align="center">
105+
<el-table-column label="优惠类型" align="center" property="discountType">
106106
<template slot-scope="scope">
107107
<el-select v-model="scope.row.discountType" placeholder="请选择优惠类型">
108108
<el-option v-for="dict in getDictDatas(DICT_TYPE.PROMOTION_DISCOUNT_TYPE)"
@@ -114,7 +114,7 @@
114114
<template slot-scope="scope">
115115
<el-form-item v-if="scope.row.discountType === PromotionDiscountTypeEnum.PRICE.type" prop="discountPrice">
116116
减 <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" /> 元
118118
</el-form-item>
119119
<el-form-item v-if="scope.row.discountType === PromotionDiscountTypeEnum.PERCENT.type" prop="discountPercent">
120120
打 <el-input-number v-model="scope.row.discountPercent" placeholder="请输入优惠折扣"
@@ -139,12 +139,20 @@
139139
</template>
140140

141141
<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";
143150
import {
144151
PromotionActivityStatusEnum, PromotionDiscountTypeEnum,
145152
PromotionProductScopeEnum
146153
} from "@/utils/constants";
147154
import { getSkuOptionList } from "@/api/mall/product/sku";
155+
import { deepClone } from "@/utils";
148156
149157
export default {
150158
name: "DiscountActivity",
@@ -165,7 +173,7 @@ export default {
165173
// 弹出层名称
166174
title: "",
167175
// 是否显示弹出层
168-
open: true,
176+
open: false,
169177
// 查询参数
170178
queryParams: {
171179
pageNo: 1,
@@ -178,28 +186,12 @@ export default {
178186
form: {
179187
skuIds: [], // 选中的 SKU
180188
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-
// }]
198189
},
199190
// 表单校验
200191
rules: {
201192
name: [{ required: true, message: "活动名称不能为空", trigger: "blur" }],
202193
startAndEndTime: [{ required: true, message: "活动时间不能为空", trigger: "blur" }],
194+
skuIds: [{ required: true, message: "选择商品不能为空", trigger: "blur" }],
203195
},
204196
// 商品 SKU 列表
205197
productSkus: [],
@@ -268,7 +260,24 @@ export default {
268260
const id = row.id;
269261
getDiscountActivity(id).then(response => {
270262
this.form = response.data;
263+
// 修改数据
271264
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+
// 打开弹窗
272281
this.open = true;
273282
this.title = "修改限时折扣活动";
274283
});
@@ -279,19 +288,29 @@ export default {
279288
if (!valid) {
280289
return;
281290
}
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+
284303
// 修改的提交
285304
if (this.form.id != null) {
286-
updateDiscountActivity(this.form).then(response => {
305+
updateDiscountActivity(data).then(response => {
287306
this.$modal.msgSuccess("修改成功");
288307
this.open = false;
289308
this.getList();
290309
});
291310
return;
292311
}
293312
// 添加的提交
294-
createDiscountActivity(this.form).then(response => {
313+
createDiscountActivity(data).then(response => {
295314
this.$modal.msgSuccess("新增成功");
296315
this.open = false;
297316
this.getList();
@@ -312,7 +331,7 @@ export default {
312331
handleClose(row) {
313332
const id = row.id;
314333
this.$modal.confirm('是否确认关闭限时折扣活动编号为"' + id + '"的数据项?').then(function() {
315-
return closeRewardActivity(id);
334+
return closeDiscountActivity(id);
316335
}).then(() => {
317336
this.getList();
318337
this.$modal.msgSuccess("关闭成功");
@@ -325,13 +344,11 @@ export default {
325344
// 获得对应的 SKU 信息
326345
const sku = this.productSkus.find(item => item.id === skuId);
327346
if (!sku) {
328-
// debugger
329347
return;
330348
}
331349
// 判断已存在,直接跳过
332350
const product = this.form.products.find(item => item.skuId === skuId);
333351
if (product) {
334-
// debugger
335352
return;
336353
}
337354
this.form.products.push({

0 commit comments

Comments
 (0)