WithdrawForm.vue 6.77 KB
<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>