index.vue
7.04 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
<template>
<LayoutContent :breads="[{title: '优惠券列表'}]">
<LayoutFilter @on-filter="onFilter" @on-clear="onClear">
<i-form ref="filterForm" inline :model="filter">
<i-form-item prop="id">
<i-input placeholder="输入ID" v-model="filter.id"></i-input>
</i-form-item>
<i-form-item prop="name">
<i-input placeholder="输入券名称" v-model="filter.name"></i-input>
</i-form-item>
<i-form-item prop="status">
<i-select placeholder="选择状态" v-model="filter.status" style="width: 100px;">
<i-option :value="0">未生效</i-option>
<i-option :value="1">生效中</i-option>
<i-option :value="2">已过期</i-option>
<i-option :value="3">已作废</i-option>
</i-select>
</i-form-item>
<i-form-item prop="time">
<i-date-picker type="datetimerange" v-model="filter.time" placeholder="开始-结束时间" format="yyyy-MM-dd HH:mm" style="width: 250px"></i-date-picker>
</i-form-item>
</i-form>
</LayoutFilter>
<LayoutTools>
<i-button type="success" icon="md-add" @click="onCreateCoupon">新增优惠券</i-button>
</LayoutTools>
<LayoutTable
:page="page"
:total="total"
:columns="columns"
:data="data"
@on-page-change="onPageChange">
<template slot="footer" class="btns">
<i-button type="primary" icon="ios-cloud-download" @click="onExport">导出</i-button>
</template>
</LayoutTable>
<ModalCreateCoupon ref="modalCreateCoupon" @on-created="onCreated"></ModalCreateCoupon>
</LayoutContent>
</template>
<script>
import {Button} from 'iview'; //eslint-disable-line
import Api from '@/api/api';
import dayjs from 'dayjs';
import BlobUtil from 'libs/blob';
import qs from 'qs';
import ModalCreateCoupon from './components/modal-create-coupon';
const api = new Api();
export default {
name: 'CouponPage',
data() {
return {
filter: {
id: '',
name: '',
status: '',
time: ['', '']
},
page: 1,
total: 0,
data: [],
columns: [{
title: 'ID',
key: 'id',
width: 80
}, {
title: '券名称',
key: 'name',
width: 180
},
{
title: 'token',
key: 'token',
width: 180
}, {
title: '数量',
key: 'couponNum',
width: 90
},
{
title: '已发放',
key: 'sendNum',
width: 90
},
{
title: '已使用',
key: 'useNum',
width: 90
},
{
title: '使用期限',
key: 'useTime',
width: 165
},
{
title: '优惠券说明',
key: 'remark',
align:'center',
width: 150
}, {
title: '状态',
align: 'center',
key: 'status'
}, {
title: '操作',
align: 'center',
width: 200,
render: (h, {row}) => {
return (
<div>
<i-button type="success" size="small" onClick={() => this.onEditCoupon(row, true, true)}>查看详情</i-button>
{(row.status === '未生效' || row.status === '生效中') ?
(<i-button type="primary" size="small" onClick={() => this.onEditCoupon(row)}>修改</i-button>) :
void 0}
<i-button type="warning" size="small" onClick={() => this.onToRecord(row)}>发放记录</i-button>
{(row.status === '未生效' || row.status === '生效中') ?
(<i-button type="success" size="small" onClick={() => this.onSendCoupon(row)}>发券</i-button>) : void 0}
</div>
);
}
}]
};
},
created() {
this.$nextTick(() => {
const {page, id, name, status, startTime, endTime} = qs.parse(location.search ? location.search.slice(1) : '');
this.filter.id = id || this.filter.id;
this.filter.name = name ? decodeURIComponent(name) : this.filter.name;
this.filter.status = status ? parseInt(status) : this.filter.status;
this.filter.time = (startTime && endTime) ? [dayjs(startTime), dayjs(endTime)] : this.filter.time;
this.page = page ? parseInt(page) : 1;
this.fetchData(this.filter, this.page);
});
},
methods: {
onToRecord({id}) {
location.href = `send-record.html?${qs.stringify({
id,
param: {
id: this.filter.id || void 0,
name: this.filter.name || void 0,
status: this.filter.status || void 0,
startTime: this.filter.time[0] || void 0,
endTime: this.filter.time[1] || void 0,
page: this.page || void 0
}
})}`;
},
onSendCoupon({id, token}) {
if (id && token) {
location.href= `send-coupon.html?${qs.stringify({
id,
token
})}`;
}
},
onCreated() {
this.fetchData(this.filter);
},
onFilter() {
this.fetchData(this.filter);
},
onClear() {
this.$refs.filterForm.resetFields();
this.fetchData(this.filter);
},
onPageChange(page) {
this.fetchData(this.filter, page);
},
onCreateCoupon() {
this.$refs.modalCreateCoupon.show();
},
onEditCoupon(row, readonly, allreadonly) {
let id = row.id;
if (row.sendNum > 0) {
readonly = true;
}
this.$refs.modalCreateCoupon.show(id, readonly, allreadonly);
},
async onExport() {
this.$Loading.start();
const result = await api._get('/ufoPlatform/coupon/export', {
param: {
method: 'coupon',
param: api._2params(this.getParams(this.filter))
}
}, {
responseType: 'blob'
});
if (result instanceof Blob) {
BlobUtil.downloadBlob(result, `优惠券导出_${dayjs().format('YYYY-MM-DD')}.xlsx`);
this.$Loading.finish();
} else if (result) {
result.message && this.$Message.warning(result.message);
this.$Loading.error();
}
},
async fetchData(params, page = 1) {
this.page = page;
this.$Loading.start();
const result = await api._get('/ufoPlatform/coupon/queryCoupons', Object.assign({
page,
}, this.getParams(params)));
if (result.code === 200) {
this.total = result.data.total;
this.data = result.data.coupons;
this.$Loading.finish();
} else {
result.message && this.$Message.warning(result.message);
this.$Loading.error();
}
},
getParams(params) {
let startTime = params.time[0] ? dayjs(params.time[0]).unix() : void 0;
let endTime = params.time[1] ? dayjs(params.time[1]).unix() : void 0;
let status = parseInt(params.status) >= 0 ? params.status : void 0;
let curTime = dayjs().unix()
return {
id: params.id,
name: params.name,
status,
startTime,
endTime,
curTime
};
}
},
components: {ModalCreateCoupon}
};
</script>
<style>
button {
margin: 5px;
}
.ivu-form-item-label {
width: 90px !important;
}
</style>