withdraw-apply.vue
9.93 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
<template>
<layout-body>
<Form v-if="showLoading" ref="withdraw" :model="data" class="detail" :label-width="100" :rules="withdrawRules">
<Form-item label="店铺名称">
<span>{{ data.shopName }}</span>
</Form-item>
<Form-item label="可提现金额(元)">
<span>{{ data.availableAmount }}</span>
<br />
<span class="red">*支付宝每日转账最高限额10万元人民币,单日超过10万人民币限额的,请联系平台客服</span>
</Form-item>
<Form-item label="提现方式">
<span>最大可提现</span><span>{{ beginTimeStr }}</span>
~
<span>{{ endTimeStr }}</span>
<br />
<span>请选择账单日期</span>
<Date-picker
v-model="beginStr"
type="date"
:options="beginTimeOptions"
placeholder="选择日期时间"
@on-change="changeBeginStr"
/>
~
<Date-picker
v-model="endStr"
type="date"
:options="endTimeOptions"
placeholder="选择日期时间"
@on-change="changeEndStr"
/>
</Form-item>
<Form-item label="提现金额" prop="withdrawAmount">
<input v-model="data.withdrawAmount" :disabled="isAble" placeholder="请选择日期获取提现金额" />
</Form-item>
<Form-item label="短信验证码">
<input v-model="data.verifyCode" placeholder="短信验证码" />
<Button v-show="show" type="primary" size="large" @click="getVerifyCode">获取验证码</Button>
<Button v-show="!show" type="default" size="large" disabled> {{ timeCount }}s 后重新发送</Button>
</Form-item>
<Form-item label="提现到帐号">
<span>{{ data.withdrawAccount }}</span>
</Form-item>
<Form-item label="账号名称">
<span>{{ data.withdrawAccountName }}</span>
</Form-item>
<Form-item label="备注">
<span>{{ data.remark }}</span>
</Form-item>
<Form-item>
<Button id="btnSubmit" type="primary" size="large" :disabled="submitDisabled" @click="save">确认提现</Button>
<Button id="cancel" type="primary" size="large" @click="backList">取消</Button>
</Form-item>
</Form>
<Spin v-else-if="showLoading" size="large" fix></Spin>
</layout-body>
</template>
<script>
import moment from 'moment';
import crypto from 'util/crypto';
import FinanceService from 'services/finance/finance-service';
import ShopService from 'services/shop/shop-service';
import { WithdrawApply } from './store';
export default {
data() {
return WithdrawApply.call(this);
},
created() {
const params = {
token: this.$user.token,
timestamps: Math.round(new Date().getTime() / 1000),
};
this.shopService = new ShopService();
this.financeService = new FinanceService();
this.financeService
.shopWithdrawApplyInit(params)
.then(result => {
if (result.code === 200) {
this.data = result.data;
this.beginStr = this.formatDate(result.data.billBeginTime);
this.endStr = this.formatDate(result.data.billEndTime);
this.beginTimeStr = this.formatDate(result.data.billBeginTime);
this.endTimeStr = this.formatDate(result.data.billEndTime);
this.submitDisabled = false;
this.data.beginTime = result.data.billBeginTime;
this.data.endTime = result.data.billEndTime;
this.data.withdrawAmount = result.data.withdrawAmount ? result.data.withdrawAmount : 0;
this.beginTimeOptions = {
disabledDate(date) {
return date && date.valueOf() < result.data.billBeginTime * 1000 - 86400000;
},
};
this.endTimeOptions = {
disabledDate(date) {
return date && date.valueOf() > result.data.billEndTime * 1000;
},
};
}
})
.catch(() => {
this.$Message.error('请求出错');
this.showLoading = false;
});
this.getShopInfo();
},
mounted() {},
methods: {
//获取店铺信息
getShopInfo() {
this.shopService.getShop().then(res => {
const { checkTel } = res.data;
this.shopPhone = checkTel;
});
},
//验证短信验证码
verifySmsCode(verifyCode) {
if (!verifyCode || verifyCode === '') {
this.$Notice.error({
title: '提交错误',
desc: '验证码不能为空',
});
return false;
}
this.financeService.verifySmsCode({ phones: this.shopPhone, verifyCode }).then(res => {
if (res.code !== 200) {
this.$Notice.error({
title: '提交错误',
desc: res.message,
});
return false;
} else {
return true;
}
});
},
//获取短信验证码
getVerifyCode() {
if (this.shopPhone === '') {
this.$Notice.error({
title: '发送失败',
desc: '店铺绑定手机为空,请先绑定手机',
});
return false;
}
this.validateBtn();
const smsParams = {
phones: this.shopPhone,
project: 'shop',
className: 'withdraw',
methodName: 'getVerifyCode',
};
return this.financeService.sendShopVerifyCode(smsParams).then(result => {
if (result.code === 200) {
this.$Notice.success({
title: '发送成功',
desc: '验证码已发送到您手机!',
});
} else {
this.$Notice.error({
title: '发送失败',
desc: result.message,
});
}
});
},
// 点击验证码后倒计时
validateBtn() {
const timeCount = 60;
if (!this.timer) {
this.timeCount = timeCount;
this.show = false;
this.timer = setInterval(() => {
if (this.timeCount > 0 && this.timeCount <= timeCount) {
this.timeCount--;
} else {
this.show = true;
clearInterval(this.timer);
this.timer = null;
}
}, 1000);
}
},
backList() {
this.$router.push({ name: 'finance.withdraw.withdrawlist' });
},
getInfo() {
return this.financeService.shopWithdrawApplyInit().then(result => {
if (result.code === 200) {
this.data = result.data;
this.$emit('on-change', this.data);
}
});
},
beforeSave() {
const params = {};
params.shopId = this.$user.currentShop.shopsId;
params.applyPid = this.$user.pid;
params.applyAmount = this.data.withdrawAmount ? this.data.withdrawAmount : 0;
params.applyType = this.apply.applyType;
params.beginTime = this.data.beginTime;
params.endTime = this.data.endTime;
params.applyPhone = this.apply.applyPhone;
params.targetAccount = this.data.withdrawAccount;
params.token = this.$user.token;
params.timestamp = Math.round(new Date().getTime() / 1000);
params.salt = this.apply.salt;
const arrParams = Object.keys(params).map(key => {
return params[key];
});
params.sign = crypto.md5(arrParams.join('|'));
params.account = this.$user.name;
params.timeout = 60000; // 提现超时时间60秒
// 短信验证码
params.verifyCode = this.data.verifyCode;
return params;
},
save() {
if (!this.beforeSave()) {
return false;
}
const applyParams = this.beforeSave();
if (!this.verifySmsCode(applyParams.verifyCode)) {
return false;
}
this.$Loading.start();
this.submitDisabled = true;
return this.financeService.shopWithdrawApply(applyParams).then(result => {
if (result.code === 200) {
this.$Loading.finish();
this.$Notice.success({
title: '提交成功',
desc: '确认提现成功!',
});
this.backList();
} else {
this.$Loading.error();
this.submitDisabled = false;
this.$Notice.error({
title: '提交错误',
desc: result.message,
});
}
});
},
submit() {
this.validateWithdrawApply()
.then(([r1, r2]) => {
if (r1 & r2) {
return Promise.resolve();
} else {
this.$Message.error('请填写必填项');
return Promise.reject();
}
})
.then(this.save)
.catch(() => this.$Loading.error());
},
refresh() {
this.getInfo();
},
formatDate(date) {
if (date) {
return moment.unix(date).format('YYYY-MM-DD');
}
},
getAvailableAmount() {
if (this.beginStr > this.endStr) {
this.$Notice.error({
title: '时间范围异常',
desc: '请正确选择开始结束时间',
});
return;
}
this.financeService.shopGetAvailableAmount(this.params).then(result => {
if (result.code === 200) {
this.data.withdrawAmount = result.data.availableAmount;
} else {
this.$Notice.error({
title: '查询错误',
desc: result.message,
});
}
});
},
changeBeginStr(value) {
this.params.beginTime = value;
},
changeEndStr(value) {
this.params.endTime = value;
this.getAvailableAmount();
},
},
};
</script>
<style lang="scss">
.detail {
.ivu-input-wrapper {
width: 300px;
}
.ivu-date-picker-editor {
width: 150px;
}
.ivu-select {
width: 200px;
}
.ivu-table-cell {
.ivu-input-wrapper {
width: auto;
}
}
.btn-fixed {
&.fix {
width: calc(100% - 200px);
position: fixed;
bottom: 0;
left: 200px;
text-align: right;
padding-right: 50px;
height: 60px;
line-height: 60px;
background: rgba(255, 255, 255, 0.7);
box-shadow: 1px 0 5px 1px #ccc;
z-index: 1002;
}
}
.red {
color: red;
}
}
</style>