index.vue
6.87 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
<template>
<LayoutContent :breads="[{url: parentUrl, title: '优惠券列表'}, {title: '优惠券发放'}]">
<i-form>
<i-card class="manual-send-wrapper">
<p slot="title">手动发放</p>
<div>
<i-row class="manual-send-container">
<i-col span="4" class="title">
UID<span class="red">*</span>
</i-col>
<i-col span="14" class="content">
<textarea rows="5" id="txt_uids" placeholder="请输入UID,多个UID用英文逗号分隔,单次限制输入50个UID" v-model="uidValue"></textarea>
</i-col>
<i-col span="5" class="button">
<i-button type="success" @click="manualSend">发送</i-button>
</i-col>
</i-row>
</div>
</i-card>
<i-card class="import-send-wrapper">
<p slot="title">批量发放</p>
<div>
<i-row class="import-send-container">
<i-col span="3"> </i-col>
<i-col span="4">
<div class="button-upload">
上传文件
<form id="formUpload">
<input type="file" id="upload" @change="fileChange" accept=".csv, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">
</form>
</div>
<span class="file-name">{{fileName}}</span>
</i-col>
<i-col span="2"> </i-col>
<i-col span="8"> </i-col>
</i-row>
<i-row style="margin-top: 20px;">
<i-col span="3"> </i-col>
<i-col span="4">
<a href="..\..\common/uid_import.xlsx" class="btn-download" target="_blank">下载样例</a>
<p>1.表头:UID</p>
<p>2.同一张券可以给同一个用户发多张?</p>
</i-col>
<i-col span="2"> </i-col>
<i-col span="8">
<a href="javascript:void(0)" style="color: red;">校验场景</a>
<p>1.优惠券数量</p>
<p>2.优惠券状态是否为未生效,或生效中</p>
</i-col>
</i-row>
<i-row>
<p style="color: red;text-align: center;margin-top: 30px; font-size: 30px;">{{uploadMessage}}</p>
</i-row>
</div>
</i-card>
<div class="bottom">
<i-button type="success" id="btn_import_send" @click="importSend">批量发送</i-button>
</div>
</i-form>
</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 {
components: {},
name: 'SendCouponPage',
data() {
return {
parentUrl: '',
couponId: 0,
couponToken: '',
uidValue: '',
fileName: '',
showModal: false,
message: '',
uploadMessage: '',
isSending: false
};
},
created() {
this.$nextTick(() => {
const queryString = qs.parse(location.search ? location.search.slice(1) : '');
this.parentUrl = `coupon.html?${qs.stringify(queryString.param)}`;
this.couponId = queryString.id;
this.couponToken = queryString.token;
});
},
methods: {
manualSend() { // 手动发放优惠券
if(this.uidValue && !this.isSending) {
let uidArr = this.uidValue.replace(/,/g, ',').split(',');
if (uidArr.length > 50) {
uidArr.length = 50;
}
if (uidArr.length > 0) {
this.isSending = true;
api._get('/ufoPlatform/coupon/couponSend', {
couponToken: this.couponToken,
uids: uidArr.join(',')
}).then(result => {
this.showModal = true;
this.message = result.message;
this.isSending = false;
this.$Modal.info({
title: '提示' + 'code:' + result.code,
content: result.message,
onOK: this.ok
});
}).catch(() => {
this.isSending = false;
this.$Modal.info({
title: '提示',
content: '发送失败',
onOK: this.ok
});
});
}
}
},
fileChange() {
let fileUpload = document.getElementById('upload');
if (fileUpload.files.length > 0) {
this.fileName = fileUpload.files[0].name;
}
},
importSend() {
if (this.fileName && !this.isSending) {
let formData = new FormData();
let file = document.getElementById('upload').files[0];
let config = {
headers: {
'Content-Type': 'multipart/form-data'
}
};
formData.append('file', file);
formData.append('couponToken', this.couponToken);
this.isSending = true;
this.uploadMessage = '文件上传中...';
api._postForm('/ufoPlatform/coupon/couponSendByImport', formData, false, config).then(result => {
this.isSending = false;
this.uploadMessage = '';
this.$Modal.info({
title: '提示' + 'code:' + result.code,
content: result.message,
onOK: this.ok
});
}).catch(() => {
this.isSending = false;
this.uploadMessage = '';
this.$Modal.info({
title: '提示',
content: '上传失败',
onOK: this.ok
});
});
}
},
ok() {
this.showModal = false;
}
},
};
</script>
<style>
.manual-send-wrapper {
height: 205px;
}
.import-send-wrapper {
height: 100%;
}
.ivu-card-body {
padding: 0;
margin: 0;
}
.ivu-card-bordered {
/*border: none;*/
border-bottom: none;
}
.ivu-card-head {
background-color: #f7f7f7;
}
.manual-send-container {
margin-top: 20px;
height: 130px;
}
.import-send-container {
margin-top: 40px;
/*margin-bottom: 200px;*/
}
.manual-send-container .title {
text-align: right;
margin-right: 20px;
}
.manual-send-container .content {
}
#txt_uids {
width: 98%;
height: 100%;
}
#upload {
width: 100%;
height: 100%;
opacity: 0;
position: absolute;
left: 0;
top: 0;
}
.button-upload {
position: relative;
display: inline-block;
background-color: #17b566;
-webkit-border-radius: 5px;
border-radius: 5px;
color: #fff;
width: 80px;
height: 32px;
line-height: 32px;
text-align: center;
overflow: hidden;
}
.file-name {
height: 32px;
line-height: 32px;
margin-left: 20px;
color: #2b85e4;
display: inline-table;
vertical-align: middle;
}
.red {
color: #ff0000;
}
.bottom {
position: absolute;
bottom: 0;
width: 100%;
height: 80px;
background-color: #f7f7f7;
line-height: 80px;
text-align: center;
}
a {
text-decoration: none;
}
</style>