石广澎
2025-11-17 8771da2ccf6f7c3fd2a8c89a1a0e230c6386db7f
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
<template>
    <view>
        <view class="u-p-30 color-666">已发送至手机号{{form.mobile|mobile_asterisk}}</view>
        <u--form class="bg-fff u-p-h-30" labelWidth="80" :model="form" :rules="rules" ref="uForm">
            <u-form-item label="验证码" prop="code">
                <u--input v-model="form.code" border="none" placeholder="请输入手机验证码"></u--input>
                <u-button slot="right" @click="getCode" type="error" size="mini" plain :text="tips"></u-button>
            </u-form-item>
        </u--form>
        <view class="u-p-40">
            <u-button @click="doBind" :loading="loading" :disabled="loading" type="error" text="确认绑卡"></u-button>
        </view>
        <u-toast ref="uToast"></u-toast>
        <u-code :seconds="seconds" ref="uCode" @change="codeChange"></u-code>
    </view>
</template>
 
<script>
    import {
        signUpToApply,
        bindCard
    } from '@/common/api/index'
    const bankName = require("@/common/bankName.js");
    export default {
        data() {
            return {
                tips: '',
                seconds: 60,
                loading: false,
                form: {
                    acctName: '',
                    cardNo: '',
                    bankName: '',
                    cardType: 'DC',
                    validdate: '',
                    cvv2: '',
                    idNo: '',
                    mobile: '18737516907',
                    thpinfo: '',
                    code: ''
                },
                rules: {
                    code: [{
                        required: true,
                        message: '验证码不能为空',
                        trigger: 'blur'
                    }, {
                        // 自定义验证函数,见上说明
                        validator: (rule, value, callback) => {
                            // 上面有说,返回true表示校验通过,返回false表示不通过
                            // uni.$u.test.mobile()就是返回true或者false的
                            return uni.$u.test.code(value, 6);
                        },
                        message: '验证码格式不正确',
                        trigger: 'change'
                    }]
                }
            };
        },
        filters: {
            mobile_asterisk(mobile) {
                if (uni.$u.test.isEmpty(mobile)) {
                    return ''
                }
                return mobile.substr(0, 4) +
                    "****" + mobile.substr(8, 3);
            }
        },
        onLoad(opt) {
            opt.acctName = decodeURIComponent(opt.acctName || '')
            opt.bankName = decodeURIComponent(opt.bankName || '')
            this.form = opt
        },
        onReady() {
            //如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则。
            this.$refs.uForm.setRules(this.rules)
            this.$refs.uCode.start();
        },
        methods: {
            codeChange(text) {
                this.tips = text;
            },
            getCode() {
                if (this.$refs.uCode.canGetCode) {
                    // 模拟向后端请求验证码
                    uni.showLoading({
                        title: '正在获取验证码'
                    })
                    const params = uni.$u.deepClone(this.form);
                    delete params.thpinfo
                    delete params.code
                    delete params.bankName
                    delete params.cardType
                    signUpToApply(params).then(res => {
                        this.form.thpinfo = res
                        uni.hideLoading();
                        uni.$u.toast('验证码已发送');
                        // 通知验证码组件内部开始倒计时
                        this.$refs.uCode.start();
                    }).catch(() => {
                        uni.$u.toast('验证码发送失败');
                        uni.hideLoading();
                    })
                } else {
                    uni.$u.toast('倒计时结束后再发送');
                }
            },
            doBind() {
                this.$refs.uForm.validate().then(res => {
                    this.loading = true
                    const params = uni.$u.deepClone(this.form);
                    delete params.bankName
                    delete params.cardType
                    bindCard(params).then(res => {
                        this.loading = false
                        this.$refs.uToast.show({
                            type: 'success',
                            title: '成功',
                            message: "绑卡成功",
                            iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png',
                            complete: () => {
                                uni.navigateBack({
                                    delta: 3
                                })
                            }
                        })
 
                    }).catch(() => {
                        this.loading = false
                    })
                }).catch(errors => {
 
                })
            }
        }
    }
</script>
 
<style lang="scss">
 
</style>