index.vue
15.4 KB
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
<!-- 优惠券列表 -->
<template>
<div class="marketing pro-group">
<div class="m-b-10">
<GLButton :size="size" type="default" class="el-icon-plus default-blue-btn color-transparent" @click="addService()" fn="新建服务券" display="disabled" mode="el-button">新建服务券</GLButton>
<GLButton :size="size" type="default" class="el-icon-plus default-blue-btn color-transparent" @click="addCashCoupon()" fn="新建代金券" display="disabled" mode="el-button">新建代金券</GLButton>
<GLButton :size="size" type="default" class="el-icon-plus default-blue-btn color-transparent" @click="addDiscountCoupon()" fn="新建折扣券" display="disabled" mode="el-button">新建折扣券</GLButton>
<GLButton :size="size" type="default" class="el-icon-plus default-blue-btn color-transparent" @click="addExchangeCoupon()" fn="新建兑换券" display="disabled" mode="el-button">新建兑换券</GLButton>
</div>
<div class="container">
<GLCombiForm ref="showSearch" :rowNumber="1" :formObj="searchForm" :formData="searchFormData" @handleOk="handleSearch" @handleRest="handleReset"></GLCombiForm>
<div class="flex m-b-10 w-100-percent">
<span class="table-title">优惠券列表</span>
<el-button :size="size" class="default-blue-btn" type="default" @click="handleExport">全部导出</el-button>
</div>
<!-- 表格区域 开始 -->
<GLTable ref="coupon" :getListApi="getListApi" :noDataImg="url" :searchForm="tableSearchForm" :tableParams="tableParams" :pageConf="pageConf" :beforeSearchFn="beforeSearchFn" @setTableFinishFun="setTableFinishFun">
<template slot="discountType" slot-scope="scope">
<img :src="require(`@/assets/coupon/icon-${attrToIcon[scope.scope.discountType]}.png`)" />
</template>
<div slot="status" slot-scope="scope">
<span :class="['table-circle', 'm-r-8', scope.scope.status == 1 ? 'back-orange' : scope.scope.status == 2 ? 'back-blue' : 'back-grey']"></span>
<span>{{ baseData.statusList.find(item => item.confId == scope.scope.status).confName }}</span>
</div>
<div class="table-btns" slot="auth-button" slot-scope="scope">
<GLTableButton :buttonList="tableButtonList" :buttonItem="scope.scope" :buttonNum="3"></GLTableButton>
</div>
</GLTable>
<!-- 表格区域 end -->
</div>
</div>
</template>
<script>
import * as dayjs from 'dayjs'
import url from '@/assets/empty.png'
import { exportFn } from '@/common/constant'
export default {
name: 'coupon',
data() {
return {
size: 'small',
url: url,
// 下架
isDownVisible: false,
downForm: {
id: '',
offReason: '',
goodsStatus: 0
},
downRules: {
offReason: [{ required: true, message: '请输入下架备注', trigger: 'change' }]
},
// 分享
isShareVisible: false,
shareForm: {},
// 表格按钮
tableButtonList: [
{
type: 'GLButton',
name: '生效',
attrs: {
type: 'text',
fn: '生效'
},
condition: row => {
return row.status == '1'
},
listeners: {
click: this.start
}
},
{
type: 'el-button',
name: '失效',
attrs: {
type: 'text'
},
condition: row => {
return row.status == '2'
},
listeners: {
click: this.end
}
},
{
type: 'GLButton',
name: '查看',
attrs: {
type: 'text',
fn: row => {
return row.discountType == 3 ? '查看代金券' : row.discountType == 7 ? '查看会员服务' : row.discountType == 2 ? '查看折扣券' : '查看兑换券'
}
},
condition: row => {
return row.status == '2' || row.status == '3'
},
listeners: {
click: row => this.handleEdit(3, row)
}
},
{
type: 'GLButton',
name: '删除',
attrs: {
type: 'text',
fn: '删除'
},
condition: row => {
return row.status == '1' || row.status == '3'
},
listeners: {
click: this.del
}
},
{
type: 'GLButton',
name: '领取详情',
attrs: {
type: 'text',
fn: '领取详情'
},
listeners: {
click: this.receiveDetail
}
}
],
// 表格
searchForm: {
couponName: '',
discountType: '',
status: '',
discountTypes: [2, 3, 4, 7]
},
tableSearchForm: {},
// 搜索
searchFormData: [
{
label: '券名称',
name: 'couponName',
type: 'input',
maxlength: 20
},
{
label: '券类型',
name: 'discountType',
type: 'select',
optionList: [],
optionId: 'confId',
optionLabel: 'confName',
optionsName: 'discountTypeList'
},
{
label: '状态',
name: 'status',
type: 'select',
optionList: [],
optionId: 'confId',
optionLabel: 'confName',
optionsName: 'statusList'
}
],
// 表格
getListApi: this.$apis.couponManage.getCouponListApi,
tableParams: {
listName: 'list',
tableOption: true,
tableColumns: [
{
label: '券类型',
name: 'discountType',
width: '100',
addHtml: 'discountType'
},
{
label: '券名称',
prop: 'couponName',
width: 200,
line: 2
},
{
label: '有效期',
prop: 'effectiveType',
width: 200,
formatter: cellValue => {
switch (cellValue.effectiveType) {
case 1:
return '领取后' + cellValue.effectiveDays + '天内有效'
case 2:
return dayjs(cellValue.effectiveStartTime).format('YYYY-MM-DD HH:mm:ss') + '-' + dayjs(cellValue.effectiveEndTime).format('YYYY-MM-DD HH:mm:ss')
case 3:
return '永久有效'
default:
return '-'
}
}
},
{
label: '可用次数',
prop: 'useType',
width: 200,
line: 2,
formatter: cellValue => {
switch (cellValue.useType) {
case 0:
return '不限制次数'
case 1:
return '有效期内可使用' + cellValue.useAmount + '次'
case 2:
return '有效期内' + cellValue.useLimitDays + '天可使用' + cellValue.useAmount + '次'
default:
return '-'
}
}
},
{
label: '库存',
prop: 'stock',
width: 120,
formatter: cellValue => {
return cellValue.limitStockFlag == 1 ? cellValue.stock : '无库存限制'
}
},
{
label: '使用途径',
name: 'useChannel',
width: 160,
formatter: cellValue => {
var useChannel = '-'
if (cellValue.useChannel) {
useChannel = this.baseData.useChannelList.find(item => item.confId == cellValue.useChannel).confName
}
return useChannel
}
},
{
label: '状态',
name: 'status',
width: '100px',
addHtml: 'status'
},
// {
// label: '适用范围',
// name: 'scopeApplication',
// width: 160,
// formatter: cellValue => {
// return {
// 1: '旗下所有店通用',
// 2: '旗下品牌店通用'
// }[cellValue.scopeApplication]
// }
// },
{
label: '已领取',
prop: 'getAmount'
},
{
label: '已使用',
prop: 'usedAmount'
}
]
},
pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' },
attrToIcon: {
2: 'discount',
3: 'cash',
4: 'exchange',
7: 'service'
},
baseData: {
discountTypeList: [
{
confId: '2',
confName: '折扣券'
},
{
confId: '3',
confName: '代金券'
},
{
confId: '4',
confName: '兑换券'
},
{
confId: '7',
confName: '服务券'
}
],
statusList: [
{
confId: '1',
confName: '未生效'
},
{
confId: '2',
confName: '生效中'
},
{
confId: '3',
confName: '已失效'
}
],
useChannelList: [
{
confId: '1',
confName: '线上商品'
},
{
confId: '2',
confName: '到店核销'
}
]
}
}
},
components: {},
created() {
this.userInfo = this.$globalState.session
// if (!this.$isGroupUp) {
// let idx = this.tableParams.tableColumns.findIndex(item => item.label == '适用范围')
// this.tableParams.tableColumns.splice(idx, 1)
// }
},
mounted() {
this.getOptionsList('searchFormData')
},
methods: {
getParams() {
var params = JSON.parse(JSON.stringify(this.searchForm))
return params
},
beforeSearchFn() {
return new Promise(resolve => {
this.tableSearchForm = this.getParams()
resolve()
})
},
secondConfirm(title, txt, apiModule, apiName, apiParams, fn) {
this.$confirm(txt, title, {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
callback: action => {
if (action == 'confirm') {
this.$apis[apiModule][apiName](apiParams).then(res => {
this.$message({
message: res.code == '0' ? '操作成功' : res.message,
type: res.code == '0' ? 'success' : 'error'
})
if (res.code == '0') {
fn && fn()
this.handleSearch()
}
})
}
}
})
},
//生效
start(item) {
this.startOrEndConfirm('生效', item)
},
//失效
end(item) {
this.startOrEndConfirm('失效', item)
},
startOrEndConfirm(txt, row) {
var title = txt
var params = {}
params.couponId = row.id
if (txt == '生效') {
params.status = '2' //优惠券状态(2:生效,3:失效)
} else if (txt == '失效') {
params.status = '3' //优惠券状态(2:生效,3:失效)
}
this.secondConfirm(title, '确定要' + txt + '该优惠券?', 'couponManage', 'effectiveCouponApi', params)
},
//核销记录
// writeOffDetail(row) {
// this.$router.push('/couponManage/writeOffDetail/' + row.id)
// },
//领取记录
receiveDetail(row) {
this.$router.push('/couponManage/receiveDetail/' + row.id)
},
//删除
del(row) {
var params = {}
params.couponId = row.id
this.secondConfirm('删除', '确定删除此优惠券?', 'couponManage', 'deleteCouponApi', params)
},
//新增代金券
addCashCoupon() {
this.$router.push('/couponManage/editCashCoupon/1')
},
//新增服务券
addService() {
// this.$router.push('/couponManage/editMemberService/1')
this.$router.push({
path: '/couponManage/editMemberService',
query: {
$title: encodeURI('创建服务')
}
})
},
//新增折扣券
addDiscountCoupon() {
this.$router.push('/couponManage/editDiscountCoupon/1')
},
//新增兑换券
addExchangeCoupon() {
this.$router.push('/couponManage/editExchangeCoupon/1')
},
// addOrEdit:1-新增;2-编辑;3-查看
handleEdit(addOrEdit, row) {
var goto = ''
//优惠券类型 1:满减券,2:折扣券,3:代金券,4:实物券 5:购车代金券 6:商品折扣券,7:服务券
if (row.discountType == '3') {
//代金券
goto = '/couponManage/editCashCoupon/'
} else if (row.discountType == '7') {
//服务券
this.$router.push({
path: '/couponManage/editMemberService',
query: {
couponId: row.id,
title: addOrEdit == 2 ? '编辑' : '查看',
$title: encodeURI('编辑服务')
}
})
return true
} else if (row.discountType == '2') {
//折扣券
goto = '/couponManage/editDiscountCoupon/'
} else if (row.discountType == '4') {
//兑换券
goto = '/couponManage/editExchangeCoupon/'
}
this.$router.push(goto + addOrEdit + '/' + row.id)
},
getOptionsList(formName, hasAll = true, refreshSigle) {
if (refreshSigle) {
var item = this[formName].find(k => k.name == refreshSigle)
var index = this[formName].findIndex(k => k.name == refreshSigle)
this.$set(this[formName][index], 'optionList', this.$common.utils.deepClone(this.baseData[item.optionsName]))
if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== '全部') {
const temp = {}
temp[this[formName][index].optionId] = ''
temp[this[formName][index].optionLabel] = '全部'
this[formName][index].optionList.unshift(temp)
}
} else {
this[formName].forEach((item, index) => {
if (item.type === 'select' && this.baseData[item.optionsName].length) {
this.$set(this[formName][index], 'optionList', this.$common.utils.deepClone(this.baseData[item.optionsName]))
if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== '全部') {
const temp = {}
temp[this[formName][index].optionId] = ''
temp[this[formName][index].optionLabel] = '全部'
this[formName][index].optionList.unshift(temp)
}
}
})
}
},
handleExport(row) {
var params = this.getParams()
var apiName = this.$isGroupUp ? 'couponGroupExportApi' : 'couponStoreExportApi'
this.$apis.couponManage[apiName](params).then(res => {
exportFn(res)
})
},
handleSearch() {
this.$refs.coupon.refreshTable()
},
handleReset() {
this.searchForm = {
couponName: '',
discountType: '',
status: '',
discountTypes: [2, 3, 4, 7]
}
this.handleSearch()
},
setTableFinishFun() {
//接收到的数据为空
this.$refs.coupon.data.length ? (this.$refs.coupon.tableHeightValues = '') : this.$refs.coupon.setTableHeightFun()
}
}
}
</script>
<style scoped></style>