Skip to content

Commit 89af6ca

Browse files
committed
promotion:增加满减送活动的关闭功能
1 parent d1eab9e commit 89af6ca

File tree

3 files changed

+379
-0
lines changed

3 files changed

+379
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import request from '@/utils/request'
2+
3+
// 创建满减送活动
4+
export function createRewardActivity(data) {
5+
return request({
6+
url: '/promotion/reward-activity/create',
7+
method: 'post',
8+
data: data
9+
})
10+
}
11+
12+
// 更新满减送活动
13+
export function updateRewardActivity(data) {
14+
return request({
15+
url: '/promotion/reward-activity/update',
16+
method: 'put',
17+
data: data
18+
})
19+
}
20+
21+
// 关闭满减送活动
22+
export function closeRewardActivity(id) {
23+
return request({
24+
url: '/promotion/reward-activity/close?id=' + id,
25+
method: 'put'
26+
})
27+
}
28+
29+
// 删除满减送活动
30+
export function deleteRewardActivity(id) {
31+
return request({
32+
url: '/promotion/reward-activity/delete?id=' + id,
33+
method: 'delete'
34+
})
35+
}
36+
37+
// 获得满减送活动
38+
export function getRewardActivity(id) {
39+
return request({
40+
url: '/promotion/reward-activity/get?id=' + id,
41+
method: 'get'
42+
})
43+
}
44+
45+
// 获得满减送活动分页
46+
export function getRewardActivityPage(query) {
47+
return request({
48+
url: '/promotion/reward-activity/page',
49+
method: 'get',
50+
params: query
51+
})
52+
}

src/utils/constants.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,3 +292,25 @@ export const PromotionConditionTypeEnum = {
292292
name: '满 N 件'
293293
}
294294
}
295+
296+
/**
297+
* 促销活动的状态枚举
298+
*/
299+
export const PromotionActivityStatusEnum = {
300+
WAIT: {
301+
type: 10,
302+
name: '未开始'
303+
},
304+
RUN: {
305+
type: 20,
306+
name: '进行中'
307+
},
308+
END: {
309+
type: 30,
310+
name: '已结束'
311+
},
312+
CLOSE: {
313+
type: 40,
314+
name: '已关闭'
315+
}
316+
}
Lines changed: 305 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,305 @@
1+
<template>
2+
<div class="app-container">
3+
4+
<!-- 搜索工作栏 -->
5+
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
6+
<el-form-item label="活动名称" prop="name">
7+
<el-input v-model="queryParams.name" placeholder="请输入活动名称" clearable @keyup.enter.native="handleQuery"/>
8+
</el-form-item>
9+
<el-form-item label="活动状态" prop="status">
10+
<el-select v-model="queryParams.status" placeholder="请选择活动状态" clearable size="small">
11+
<el-option v-for="dict in this.getDictDatas(DICT_TYPE.PROMOTION_ACTIVITY_STATUS)"
12+
:key="dict.value" :label="dict.label" :value="dict.value"/>
13+
</el-select>
14+
</el-form-item>
15+
<el-form-item>
16+
<el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
17+
<el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
18+
</el-form-item>
19+
</el-form>
20+
21+
<!-- 操作工具栏 -->
22+
<el-row :gutter="10" class="mb8">
23+
<el-col :span="1.5">
24+
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
25+
v-hasPermi="['promotion:reward-activity:create']">新增</el-button>
26+
</el-col>
27+
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
28+
</el-row>
29+
30+
<!-- 列表 -->
31+
<el-table v-loading="loading" :data="list">
32+
<el-table-column label="活动名称" align="center" prop="name" />
33+
<el-table-column label="活动时间" align="center" prop="startTime" width="240">
34+
<template slot-scope="scope">
35+
<div>开始:{{ parseTime(scope.row.startTime) }}</div>
36+
<div>结束:{{ parseTime(scope.row.endTime) }}</div>
37+
</template>
38+
</el-table-column>
39+
<el-table-column label="状态" align="center" prop="status">
40+
<template slot-scope="scope">
41+
<dict-tag :type="DICT_TYPE.PROMOTION_ACTIVITY_STATUS" :value="scope.row.status" />
42+
</template>
43+
</el-table-column>
44+
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
45+
<template slot-scope="scope">
46+
<span>{{ parseTime(scope.row.createTime) }}</span>
47+
</template>
48+
</el-table-column>
49+
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
50+
<template slot-scope="scope">
51+
<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
52+
v-if="scope.row.status !== PromotionActivityStatusEnum.CLOSE.type"
53+
v-hasPermi="['promotion:reward-activity:update']">修改</el-button>
54+
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleClose(scope.row)"
55+
v-if="scope.row.status !== PromotionActivityStatusEnum.CLOSE.type &&
56+
scope.row.status !== PromotionActivityStatusEnum.END.type"
57+
v-hasPermi="['promotion:reward-activity:close']">关闭</el-button>
58+
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
59+
v-if="scope.row.status === PromotionActivityStatusEnum.CLOSE.type"
60+
v-hasPermi="['promotion:reward-activity:delete']">删除</el-button>
61+
</template>
62+
</el-table-column>
63+
</el-table>
64+
<!-- 分页组件 -->
65+
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
66+
@pagination="getList"/>
67+
68+
<!-- 对话框(添加 / 修改) -->
69+
<el-dialog :title="title" :visible.sync="open" width="600px" v-dialogDrag append-to-body>
70+
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
71+
<el-form-item label="活动名称" prop="name">
72+
<el-input v-model="form.name" placeholder="请输入活动名称" />
73+
</el-form-item>
74+
<el-form-item label="活动时间" prop="startAndEndTime">
75+
<el-date-picker clearable v-model="form.startAndEndTime" type="datetimerange" :default-time="['00:00:00', '23:59:59']"
76+
value-format="timestamp" placeholder="选择开始时间" style="width: 480px" />
77+
</el-form-item>
78+
<el-form-item label="条件类型" prop="conditionType">
79+
<el-radio-group v-model="form.conditionType">
80+
<el-radio v-for="dict in this.getDictDatas(DICT_TYPE.PROMOTION_CONDITION_TYPE)"
81+
:key="dict.value" :label="parseInt(dict.value)">{{dict.label}}</el-radio>
82+
</el-radio-group>
83+
</el-form-item>
84+
<el-form-item label="优惠设置" prop="conditionType">
85+
<!-- TODO 芋艿:待实现! -->
86+
</el-form-item>
87+
<el-form-item label="活动商品" prop="productScope">
88+
<el-radio-group v-model="form.productScope">
89+
<el-radio v-for="dict in this.getDictDatas(DICT_TYPE.PROMOTION_PRODUCT_SCOPE)"
90+
:key="dict.value" :label="parseInt(dict.value)">{{dict.label}}</el-radio>
91+
</el-radio-group>
92+
</el-form-item>
93+
<el-form-item v-if="form.productScope === PromotionProductScopeEnum.SPU.scope" prop="productSpuIds">
94+
<el-select v-model="form.productSpuIds" placeholder="请选择活动商品" clearable size="small"
95+
multiple filterable style="width: 400px">
96+
<el-option v-for="item in productSpus" :key="item.id" :label="item.name" :value="item.id">
97+
<span style="float: left">{{ item.name }}</span>
98+
<span style="float: right; color: #8492a6; font-size: 13px">¥{{ (item.minPrice / 100.0).toFixed(2) }}</span>
99+
</el-option>
100+
</el-select>
101+
</el-form-item>
102+
<el-form-item label="备注" prop="remark">
103+
<el-input v-model="form.remark" placeholder="请输入备注" />
104+
</el-form-item>
105+
</el-form>
106+
<div slot="footer" class="dialog-footer">
107+
<el-button type="primary" @click="submitForm">确 定</el-button>
108+
<el-button @click="cancel">取 消</el-button>
109+
</div>
110+
</el-dialog>
111+
</div>
112+
</template>
113+
114+
<script>
115+
import {
116+
createRewardActivity,
117+
updateRewardActivity,
118+
deleteRewardActivity,
119+
getRewardActivity,
120+
getRewardActivityPage,
121+
closeRewardActivity
122+
} from "@/api/mall/promotion/rewardActivity";
123+
import {
124+
PromotionConditionTypeEnum,
125+
PromotionProductScopeEnum,
126+
PromotionActivityStatusEnum
127+
} from "@/utils/constants";
128+
import {getSpuSimpleList} from "@/api/mall/product/spu";
129+
130+
export default {
131+
name: "RewardActivity",
132+
components: {
133+
},
134+
data() {
135+
return {
136+
// 遮罩层
137+
loading: true,
138+
// 导出遮罩层
139+
exportLoading: false,
140+
// 显示搜索条件
141+
showSearch: true,
142+
// 总条数
143+
total: 0,
144+
// 满减送活动列表
145+
list: [],
146+
// 弹出层标题
147+
title: "",
148+
// 是否显示弹出层
149+
open: false,
150+
// 查询参数
151+
queryParams: {
152+
pageNo: 1,
153+
pageSize: 10,
154+
name: null,
155+
status: null,
156+
},
157+
// 表单参数
158+
form: {},
159+
// 表单校验
160+
rules: {
161+
name: [{ required: true, message: "活动名称不能为空", trigger: "blur" }],
162+
startAndEndTime: [{ required: true, message: "活动时间不能为空", trigger: "blur" }],
163+
conditionType: [{ required: true, message: "条件类型不能为空", trigger: "change" }],
164+
productScope: [{ required: true, message: "商品范围不能为空", trigger: "blur" }],
165+
productSpuIds: [{ required: true, message: "商品范围不能为空", trigger: "blur" }],
166+
},
167+
// 商品列表
168+
productSpus: [],
169+
// 如下的变量,主要为了 v-if 判断可以使用到
170+
PromotionProductScopeEnum: PromotionProductScopeEnum,
171+
PromotionActivityStatusEnum: PromotionActivityStatusEnum,
172+
};
173+
},
174+
created() {
175+
this.getList();
176+
// 查询商品列表
177+
getSpuSimpleList().then(response => {
178+
this.productSpus = response.data
179+
})
180+
},
181+
methods: {
182+
/** 查询列表 */
183+
getList() {
184+
this.loading = true;
185+
// 执行查询
186+
getRewardActivityPage(this.queryParams).then(response => {
187+
this.list = response.data.list;
188+
this.total = response.data.total;
189+
this.loading = false;
190+
});
191+
},
192+
/** 取消按钮 */
193+
cancel() {
194+
this.open = false;
195+
this.reset();
196+
},
197+
/** 表单重置 */
198+
reset() {
199+
this.form = {
200+
id: undefined,
201+
name: undefined,
202+
startAndEndTime: undefined,
203+
startTime: undefined,
204+
endTime: undefined,
205+
conditionType: PromotionConditionTypeEnum.PRICE.type,
206+
remark: undefined,
207+
productScope: PromotionProductScopeEnum.ALL.scope,
208+
productSpuIds: undefined,
209+
rules: undefined,
210+
};
211+
this.resetForm("form");
212+
},
213+
/** 搜索按钮操作 */
214+
handleQuery() {
215+
this.queryParams.pageNo = 1;
216+
this.getList();
217+
},
218+
/** 重置按钮操作 */
219+
resetQuery() {
220+
this.resetForm("queryForm");
221+
this.handleQuery();
222+
},
223+
/** 新增按钮操作 */
224+
handleAdd() {
225+
this.reset();
226+
this.open = true;
227+
this.title = "添加满减送活动";
228+
},
229+
/** 修改按钮操作 */
230+
handleUpdate(row) {
231+
this.reset();
232+
const id = row.id;
233+
getRewardActivity(id).then(response => {
234+
this.form = response.data;
235+
this.form.startAndEndTime = [response.data.startTime, response.data.endTime];
236+
this.open = true;
237+
this.title = "修改满减送活动";
238+
});
239+
},
240+
/** 提交按钮 */
241+
submitForm() {
242+
this.$refs["form"].validate(valid => {
243+
if (!valid) {
244+
return;
245+
}
246+
this.form.startTime = this.form.startAndEndTime[0];
247+
this.form.endTime = this.form.startAndEndTime[1];
248+
// TODO 芋艿:临时实现
249+
this.form.rules = [
250+
{
251+
limit: 1,
252+
discountPrice: 10,
253+
freeDelivery: true,
254+
point: 10,
255+
couponIds: [10, 20],
256+
couponCounts: [1, 2]
257+
}, {
258+
limit: 2,
259+
discountPrice: 20,
260+
freeDelivery: false,
261+
point: 20,
262+
couponIds: [30, 40],
263+
couponCounts: [3, 4]
264+
}
265+
];
266+
// 修改的提交
267+
if (this.form.id != null) {
268+
updateRewardActivity(this.form).then(response => {
269+
this.$modal.msgSuccess("修改成功");
270+
this.open = false;
271+
this.getList();
272+
});
273+
return;
274+
}
275+
// 添加的提交
276+
createRewardActivity(this.form).then(response => {
277+
this.$modal.msgSuccess("新增成功");
278+
this.open = false;
279+
this.getList();
280+
});
281+
});
282+
},
283+
/** 删除按钮操作 */
284+
handleDelete(row) {
285+
const id = row.id;
286+
this.$modal.confirm('是否确认删除满减送活动编号为"' + id + '"的数据项?').then(function() {
287+
return deleteRewardActivity(id);
288+
}).then(() => {
289+
this.getList();
290+
this.$modal.msgSuccess("删除成功");
291+
}).catch(() => {});
292+
},
293+
/** 关闭按钮操作 */
294+
handleClose(row) {
295+
const id = row.id;
296+
this.$modal.confirm('是否确认关闭满减送活动编号为"' + id + '"的数据项?').then(function() {
297+
return closeRewardActivity(id);
298+
}).then(() => {
299+
this.getList();
300+
this.$modal.msgSuccess("关闭成功");
301+
}).catch(() => {});
302+
}
303+
}
304+
};
305+
</script>

0 commit comments

Comments
 (0)