WithdrawForm.vue
6.77 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
<template>
<view class="withdrawal-apply-container">
<!-- 顶部导航栏 -->
<!-- 提现至区域 -->
<van-cell-group>
<van-cell title="提现至" value="原充值渠道" :border="true" is-link custom-style="display: flex; align-items: center; height: 60px;"/>
</van-cell-group>
<!-- 提现金额区域 -->
<view class="withdrawal-amount-section">
<view class="section-label">提现金额</view>
<view class="amount-input-area">
<uni-forms ref="amountForm" :modelValue="formData" :rules="rules" validateTrigger="bind" label-width="24">
<uni-forms-item required name="withdrawalAmount">
<template v-slot:label>
<text class="currency-symbol">¥</text>
</template>
<uni-easyinput v-model="formData.withdrawalAmount" placeholder="请输入提现金额" class="amount-input" type="digit" :styles="amountStyle" :maxlength="9"
:placeholderStyle="placeholderStyle"
:input-border="false" @input="handleInput"></uni-easyinput>
</uni-forms-item>
</uni-forms>
</view>
<view class="available-amount">
当前可提现余额{{ $filters.formatNumber(availableAmount) }}元
<text class="available-amount-value" @click="withdrawAll">全部提现</text>
</view>
</view>
<!-- 确认提现按钮 -->
<view class="confirm-button-container">
<van-button type="primary" round @click="confirmWithdrawal" block>确认提现</van-button>
</view>
<!-- 温馨提示 -->
<view class="footer">
温馨提示:提现申请发起后,预计在3个工作日内日到账
</view>
</view>
</template>
<script lang="ts">
import {Component, Vue} from "vue-facing-decorator";
import {onLoad} from "@dcloudio/uni-app";
import {WithdrawController} from "@/api/WithdrawController";
import {Withdraw} from "lib/src/entity/finance/entity/Withdraw";
import {TransactionController} from "@/api/TransactionController";
@Component({
components: {}
})
export default class WithdrawForm extends Vue {
availableAmount = 0;
amountStyle = {color: 'rgba(24, 94, 254, 1)', 'font-size': '36px'};
placeholderStyle = 'font-size:24px';
formData = {withdrawalAmount: 0};
rules = {
withdrawalAmount: {
rules: [{
required: true,
errorMessage: '请输入提现金额',
}, {
validateFunction: this.validAmount
}]
}
}
validAmount(rule: any, value: number, data: any, callback: any) {
if (value < 1) {
callback('最低提现金额为1.00元');
return;
}
if (value > this.availableAmount) {
callback('提现金额不能超过可提现金额');
return
}
if (value > 5000) {
callback('微信单笔提现最高为5,000.00元');
return
}
return true;
}
created(): void {
onLoad((option) => {
TransactionController.getTransactionStat(this.axios).then(res => {
this.availableAmount = res.data.surplus - Math.abs(res.data.freezeDeposit) - res.data.withdraw;
});
});
}
handleInput(event: any) {
let inputValue = event;
setTimeout(() => {
const pureNumberStr = inputValue.replace(/[^0-9]/g, '');
let noLeadingZeroStr = pureNumberStr;
if (pureNumberStr.length > 1) { // 只有长度大于1时,才需要去前置零
noLeadingZeroStr = pureNumberStr.replace(/^0+/, '');
noLeadingZeroStr = noLeadingZeroStr || '0';
}
this.formData.withdrawalAmount = noLeadingZeroStr;
}, 100);
}
withdrawAll() {
// 全部提现逻辑
this.formData.withdrawalAmount = this.availableAmount;
}
confirmWithdrawal() {
this.$refs.amountForm.validate().then((res: any) => {
// 模拟提现确认
uni.showModal({
title: '提现确认',
content: `确定要提现 ${this.formData.withdrawalAmount} 元吗?`,
success: (res) => {
if (res.confirm) {
// 确认提现后的逻辑
const withdraw = new Withdraw();
withdraw.bankAccount = '微信零钱';
withdraw.amount = this.formData.withdrawalAmount;
uni.showLoading({title: '提交中...', mask: true});
WithdrawController.addWithdraw(this.axios, withdraw).then(res => {
uni.navigateTo({url: '/module/deposit/WithdrawSuccess'});
}).finally(() => {
uni.hideLoading();
});
}
}
})
}).catch((err: any) => {
console.log('表单错误信息:', err);
});
}
}
</script>
<style lang="scss" scoped>
.withdrawal-apply-container {
background-color: #ffffff;
min-height: 90vh;
padding-bottom: 40px;
}
/* 提现至区域 */
.withdrawal-to-section {
background-color: #fff;
margin-top: 4px;
padding: 16px;
border-bottom: 1px solid #f0f0f0;
}
.section-label {
font-size: 14px;
color: #333;
margin-bottom: 8px;
}
.account-info {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 16px;
color: #333;
}
/* 提现金额区域 */
.withdrawal-amount-section {
background-color: #fff;
padding: 16px;
}
.amount-input-area {
display: flex;
align-items: baseline;
padding: 6px 0;
border-bottom: 1px solid #f0f0f0;
}
.currency-symbol {
font-size: 36px;
color: rgba(24, 94, 254, 1);
line-height: 36px;
//margin-right: 8px;
}
.amount-input {
font-size: 36px;
font-weight: 500;
color: rgba(24, 94, 254, 1);
//flex: 1;
//padding: 0;
//border: none;
//outline: none;
}
.available-amount {
margin-top: 12px;
font-size: 14px;
color: #999;
}
.available-amount-value {
color: rgba(24, 94, 254, 1);
}
/* 全部提现按钮 */
.withdraw-all-btn {
background-color: #fff;
padding: 16px;
text-align: right;
color: rgba(24, 94, 254, 1);
font-size: 14px;
border-bottom: 1px solid #f0f0f0;
}
/* 确认提现按钮 */
.confirm-button-container {
padding: 24px 16px 8px 16px;
}
/* 温馨提示 */
.footer {
font-size: 12px;
color: #999;
text-align: left;
padding: 0 24px;
}
</style>