1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
| <template>
| <div class="search">
| <Card>
| <Form
| ref="searchForm"
| :model="searchForm"
| inline
| :label-width="75"
| class="search-form mb_10"
| >
| <Form-item label="优惠券名称" prop="couponName">
| <Input
| type="text"
| v-model="searchForm.couponName"
| placeholder="请输入优惠券名称"
| clearable
| style="width: 200px"
| />
| </Form-item>
| <Form-item label="获取方式" prop="getType">
| <Select
| v-model="searchForm.getType"
| placeholder="请选择"
| clearable
| style="width: 200px"
| >
| <Option value="FREE">免费获取</Option>
| <Option value="ACTIVITY">活动获取</Option>
| </Select>
| </Form-item>
| <Form-item label="活动状态" prop="promotionStatus">
| <Select
| v-model="searchForm.promotionStatus"
| placeholder="请选择"
| clearable
| style="width: 200px"
| >
| <Option value="NEW">未开始</Option>
| <Option value="START">已开始/上架</Option>
| <Option value="END">已结束/下架</Option>
| <Option value="CLOSE">紧急关闭/作废</Option>
| </Select>
| </Form-item>
| <Form-item label="活动时间">
| <DatePicker
| v-model="selectDate"
| type="daterange"
| clearable
| placeholder="选择起始时间"
| style="width: 200px"
| ></DatePicker>
| </Form-item>
| <Button
| @click="handleSearch"
| type="primary"
| icon="ios-search"
| class="search-btn"
| >搜索</Button
| >
| </Form>
| <Row class="operation padding-row" v-if="getType !== 'ACTIVITY'">
| <Button @click="add" type="primary">添加优惠券</Button>
| <Button @click="delAll">批量关闭</Button>
| <Button @click="receivePage()" type="info">优惠券领取记录</Button>
| </Row>
| <Table
| v-if="refreshTable"
| :loading="loading"
| border
| :columns="columns"
| :data="data"
| ref="table"
| @on-selection-change="changeSelect"
| >
| <template slot-scope="{ row }" slot="action">
| <Button
| v-if="
| row.promotionStatus === 'CLOSE' || row.promotionStatus === 'NEW'
| "
| type="info"
| size="small"
| @click="see(row)"
| >编辑
| </Button>
| <Button
| v-else
| type="default"
| size="small"
| @click="see(row, 'onlyView')"
| >查看
| </Button>
| <Button
| class="ml_5"
| v-if="
| row.promotionStatus === 'START' || row.promotionStatus === 'NEW'
| "
| type="error"
| size="small"
| @click="close(row)"
| >关闭
| </Button>
| <!--<Button-->
| <!--class="ml_5"-->
| <!--v-if="-->
| <!--row.promotionStatus === 'CLOSE' || row.promotionStatus === 'END'-->
| <!--"-->
| <!--type="error"-->
| <!--size="small"-->
| <!--@click="remove(row)"-->
| <!-->删除-->
| <!--</Button>-->
| <Button
| style="margin: 5px"
| type="info"
| size="small"
| @click="receivePage(row.id)"
| >领取记录
| </Button>
| </template>
| </Table>
| <Row type="flex" justify="end" class="mt_10">
| <Page
| :current="searchForm.pageNumber"
| :total="total"
| :page-size="searchForm.pageSize"
| @on-change="changePage"
| @on-page-size-change="changePageSize"
| :page-size-opts="[10, 20, 50]"
| size="small"
| show-total
| show-elevator
| show-sizer
| ></Page>
| </Row>
| </Card>
| </div>
| </template>
| <script>
| import {
| getPlatformCouponList,
| updatePlatformCouponStatus,
| deletePlatformCoupon,
| } from "@/api/promotion";
| import {
| promotionsStatusRender,
| promotionsScopeTypeRender,
| } from "@/utils/promotions";
|
| export default {
| name: "coupon",
| data() {
| return {
| loading: true, // 表单加载状态
| searchForm: {
| // 搜索框初始化对象
| pageNumber: 1, // 当前页数
| pageSize: 10, // 页面大小
| sort: "create_time", // 默认排序字段
| order: "desc", // 默认排序方式
| getType: "", // 默认排序方式
| },
| selectList: [], // 多选数据
| selectCount: 0, // 多选计数
| columns: [
| // 表头
| {
| type: "selection",
| width: 100,
| align: "center",
| fixed: "left",
| },
| {
| title: "优惠券名称",
| key: "couponName",
| width: 180,
| tooltip: true,
| },
| {
| title: "面额/折扣",
| key: "price",
| width: 150,
| render: (h, params) => {
| if (params.row.price) {
| return h("priceColorScheme", {props:{value:params.row.price,color:this.$mainColor}} );
|
| } else {
| return h("div", params.row.couponDiscount + "折");
| }
| },
| },
|
| {
| title: "已领取数量/总数量",
| key: "publishNum",
| width: 180,
| render: (h, params) => {
| return h(
| "div",
| params.row.receivedNum +
| "/" +
| (params.row.publishNum === 0 ? "不限制" : params.row.publishNum)
| );
| },
| },
|
| {
| title: "已被使用的数量/已领取数量",
| key: "publishNum",
| width: 100,
| render: (h, params) => {
| return h("div", params.row.usedNum + "/" + params.row.receivedNum);
| },
| },
| {
| title: "获取方式",
| width: 120,
| key: "getType",
| render: (h, params) => {
| if (params.row.getType === "FREE") {
| return h("Tag", { props: { color: "red" } }, "免费获取");
| } else if (params.row.getType === "ACTIVITY") {
| return h("Tag", { props: { color: "volcano" } }, "活动获取");
| } else if (params.row.getType === "INSIDE") {
| return h("Tag", { props: { color: "lime" } }, "内购");
| } else if (params.row.getType === "IGAME") {
| return h("Tag", { props: { color: "lime" } }, "游戏人生");
| } else {
| return h("Tag", { props: { color: "purple" } }, "未知");
| }
| },
| },
| {
| title: "优惠券类型",
| key: "couponType",
| width: 150,
| render: (h, params) => {
| let text = "";
| if (params.row.couponType === "DISCOUNT") {
| return h("Tag", { props: { color: "blue" } }, "打折");
| } else if (params.row.couponType === "PRICE") {
| return h("Tag", { props: { color: "geekblue" } }, "减免现金");
| } else {
| return h("Tag", { props: { color: "purple" } }, "未知");
| }
| },
| },
| {
| title: "品类描述",
| key: "scopeType",
| width: 120,
| render: (h, params) => {
| return promotionsScopeTypeRender(h, params);
| },
| },
| {
| title: "活动时间",
| width: 200,
| render: (h, params) => {
| if (
| params?.row?.getType === "ACTIVITY" &&
| params?.row?.rangeDayType === "DYNAMICTIME"
| ) {
| return h("div", "长期有效");
| } else if (params?.row?.startTime && params?.row?.endTime) {
| return h("div", {
| domProps: {
| innerHTML:
| params.row.startTime + "<br/>" + params.row.endTime,
| },
| });
| }
| },
| },
| {
| title: "状态",
| width: 100,
| key: "promotionStatus",
| align: "center",
| fixed: "right",
| render: (h, params) => {
| return promotionsStatusRender(h, params);
| },
| },
| {
| title: "操作",
| slot: "action",
| align: "center",
| fixed: "right",
| width: 250,
| },
| ],
| data: [], // 表单数据
| total: 0, // 表单数据总数
| refreshTable: true, // 修改选中状态后刷新表格
| selectDate: [], //选中的信息
| };
| },
| props: {
| //优惠券类型 查询参数
| getType: {
| type: String,
| default: "",
| },
| promotionStatus: {
| type: String,
| default: "",
| },
| //已选择优惠券
| selectedList: {
| type: Array,
| default: () => {
| return [];
| },
| },
| },
| watch: {
| $route(to, from) {
| if (to.fullPath == "/promotions/manager-coupon") {
| this.init();
| }
| },
| // 选中优惠券 父级传值
| selectedList: {
| handler(val) {
| // 判断是否是父级回调给自己已选择优惠券
| if (val.length) {
| this.selectList = val;
| this.data.forEach((item) => {
| item._checked = false;
| if (this.selectList.length) {
| this.selectList.forEach((child) => {
| if (item.id == child.id) {
| item._checked = true;
| }
| });
| }
| });
| } else {
| this.data.forEach((item) => {
| item._checked = false;
| });
| }
| this.refreshTable = false;
| this.$nextTick(() => {
| this.refreshTable = true;
| });
| },
| deep: true,
| },
| },
| methods: {
| check() {
| // 选中的优惠券
| this.$emit("selected", this.selectList);
| },
| receivePage(id) {
| if (id) {
| this.$router.push({ name: "coupon-receive", query: { couponId: id } });
| } else {
| this.$router.push({ name: "coupon-receive" });
| }
| },
| // 初始化数据
| init() {
| this.getDataList();
| },
| add() {
| // 跳转添加页面
| this.$router.push({ name: "add-platform-coupon" });
| },
| info(v) {
| // 查看优惠券
| this.$router.push({ name: "platform-coupon-info", query: { id: v.id } });
| },
| changePage(v) {
| // 改变页码
| this.searchForm.pageNumber = v;
| this.getDataList();
| },
| changePageSize(v) {
| // 改变页数
| this.searchForm.pageNumber = 1;
| this.searchForm.pageSize = v;
| this.getDataList();
| },
| handleSearch() {
| // 搜索
| this.searchForm.pageNumber = 1;
| this.searchForm.pageSize = 10;
| this.getDataList();
| },
| clearSelectAll() {
| // 清除选中状态
| this.$refs.table.selectAll(false);
| },
| /**
| * 选择优惠券
| */
| changeSelect(e) {
| this.selectList = e;
| this.selectCount = e.length;
| if (this.getType === "ACTIVITY") this.check();
| },
| getDataList() {
| // 获取数据
| this.loading = true;
| if (this.selectDate && this.selectDate[0] && this.selectDate[1]) {
| this.searchForm.startTime = this.selectDate[0].getTime();
| this.searchForm.endTime = this.selectDate[1].getTime();
| } else {
| this.searchForm.startTime = null;
| this.searchForm.endTime = null;
| }
| getPlatformCouponList(this.searchForm).then((res) => {
| this.loading = false;
| if (res.success) {
| console.log(res);
| this.data = res.result.records;
| this.total = res.result.total;
| }
| });
| this.total = this.data.length;
| this.loading = false;
| },
|
| see(v, only) {
| // 跳转编辑页面
| let data;
| only ? (data = { onlyView: true, id: v.id }) : (data = { id: v.id });
| this.$router.push({ name: "edit-platform-coupon", query: data });
| },
| close(v) {
| // 下架优惠券
| this.$Modal.confirm({
| title: "确认关闭",
| // 记得确认修改此处
| content: "确认要关闭此优惠券么?",
| loading: true,
| onOk: () => {
| // 删除
| updatePlatformCouponStatus({
| couponIds: v.id,
| effectiveDays: 0,
| })
| .then((res) => {
| this.$Modal.remove();
| if (res.success) {
| this.$Message.success("优惠券已关闭");
| this.getDataList();
| }
| })
| .catch(() => {
| this.$Modal;
| });
| },
| });
| },
| remove(v) {
| // 下架优惠券
| this.$Modal.confirm({
| title: "确认删除",
| // 记得确认修改此处
| content: "确认要删除此优惠券么?",
| loading: true,
| onOk: () => {
| // 删除
| deletePlatformCoupon(v.id)
| .then((res) => {
| this.$Modal.remove();
| if (res.success) {
| this.$Message.success("优惠券已删除");
| this.getDataList();
| }
| })
| .catch(() => {
| this.$Modal;
| });
| },
| });
| },
| delAll() {
| // 批量下架
| if (this.selectCount <= 0) {
| this.$Message.warning("您还未选择要下架的优惠券");
| return;
| }
| this.$Modal.confirm({
| title: "确认下架",
| content: "您确认要下架所选的 " + this.selectCount + " 条数据?",
| loading: true,
| onOk: () => {
| let ids = [];
| this.selectList.forEach(function (e) {
| ids.push(e.id);
| });
| let params = {
| couponIds: ids.toString(),
| promotionStatus: "CLOSE",
| };
| // 批量删除
| updatePlatformCouponStatus(params).then((res) => {
| this.$Modal.remove();
| if (res.success) {
| this.$Message.success("下架成功");
| this.clearSelectAll();
| this.getDataList();
| }
| });
| },
| });
| },
| },
| mounted() {
| //如果作为组件方式,传入了类型值,则搜索参数附加类型
| if (this.getType) {
| this.searchForm.getType = this.getType;
| this.columns.pop();
| }
| if (this.promotionStatus) {
| this.searchForm.promotionStatus = this.promotionStatus;
| this.columns.pop();
| }
| this.init();
| },
| };
| </script>
|
|