index.vue
4.21 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
<template>
<LayoutContent :breads="[{url: parentUrl, title: '优惠券列表'}, {title: '发放记录'}]">
<LayoutFilter @on-filter="onFilter" @on-clear="onClear">
<i-form ref="filterForm" inline :model="filter">
<i-form-item prop="couponCode">
<i-input placeholder="输入ID" v-model="filter.couponCode"></i-input>
</i-form-item>
<i-form-item prop="uid">
<i-input placeholder="输入uid" v-model="filter.uid"></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-select>
</i-form-item>
</i-form>
</LayoutFilter>
<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>
</LayoutContent>
</template>
<script>
import Api from '@/api/api';
import dayjs from 'dayjs';
import BlobUtil from 'libs/blob';
import qs from 'qs';
const api = new Api();
export default {
name: 'SendRecordPage',
data() {
return {
filter: {
couponId: 0,
couponCode: '',
uid: '',
status: '',
},
parentUrl: '',
page: 1,
total: 0,
data: [],
columns: [{
title: '单券号',
key: 'couponCode'
}, {
title: '用户ID',
key: 'uid'
}, {
title: '发放时间',
render(h, {row}) {
return (
<span>{row.createTime}</span>
);
}
}, {
title: '使用状态',
key: 'status'
}, {
title: '使用时间',
render(h, {row}) {
return (
<span>{row.useTime || '--'}</span>
);
}
}]
};
},
created() {
this.$nextTick(() => {
const queryString = qs.parse(location.search ? location.search.slice(1) : '');
this.filter.couponId = queryString.id;
this.filter.couponCode = queryString.couponCode || this.filter.couponCode;
this.filter.uid = queryString.uid || this.filter.uid;
this.filter.status = queryString.status ? parseInt(queryString.status) : this.filter.status;
this.parentUrl = `coupon.html?${qs.stringify(queryString.param)}`;
this.page = queryString.page ? parseInt(queryString.page) : 1;
this.fetchData(this.filter, this.page);
});
},
methods: {
onFilter() {
this.fetchData(this.filter);
},
onClear() {
this.$refs.filterForm.resetFields();
this.fetchData(this.filter);
},
onPageChange(page) {
this.fetchData(this.filter, page);
},
async fetchData(params, page = 1) {
this.page = page;
this.$Loading.start();
const result = await api._get('/ufoPlatform/coupon/queryUserCoupons', Object.assign({
page,
}, this.getParams(params)));
if (result.code === 200) {
this.total = result.data.total;
this.data = result.data.userCoupons;
this.$Loading.finish();
} else {
result.message && this.$Message.warning(result.message);
this.$Loading.error();
}
},
async onExport() {
this.$Loading.start();
const result = await api._get('/ufoPlatform/coupon/export', {
param: {
method: 'userCoupon',
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();
}
},
getParams(params) {
return {
couponId: params.couponId,
couponCode: params.couponCode,
uid: params.uid,
status: parseInt(params.status) >= 0 ? params.status : void 0,
};
}
},
};
</script>
<style>
</style>