石广澎
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
<template>
    <view>
        <view class="u-p-30 color-666">请绑定持卡人本人的银行卡</view>
        <u--form class="bg-fff u-p-h-30" labelWidth="80" :model="form" :rules="rules" ref="uForm">
            <u-form-item label="持卡人" prop="acctName" borderBottom>
                <u--input v-model="form.acctName" border="none" placeholder="请输入持卡人姓名"></u--input>
            </u-form-item>
            <u-form-item label="卡号" prop="cardNo">
                <u--input v-model="form.cardNo" border="none" placeholder="请输入卡号"></u--input>
            </u-form-item>
        </u--form>
        <view class="u-p-40">
            <u-button @click="doNext" :loading="loading" :disabled="loading" type="error" text="下一步"></u-button>
        </view>
 
    </view>
</template>
 
<script>
    import {
        isContain,
    } from '@/common/api/index'
    const bankName = require("@/common/bankName.js");
    export default {
        data() {
            return {
                loading: false,
                form: {
                    acctName: '',
                    cardNo: ''
                },
                rules: {
                    acctName: [{
                        required: true,
                        message: '持卡人姓名不能为空',
                        trigger: 'blur'
                    }, {
                        // 自定义验证函数,见上说明
                        validator: (rule, value, callback) => {
                            // 上面有说,返回true表示校验通过,返回false表示不通过
                            // uni.$u.test.mobile()就是返回true或者false的
                            return uni.$u.test.rangeLength(value, [2, 6]) && uni.$u.test.chinese(value);
                        },
                        message: '持卡人姓名不正确',
                        trigger: 'change'
                    }],
                    cardNo: [{
                        required: true,
                        message: '卡号不能为空',
                        trigger: 'blur'
                    }, {
                        // 自定义验证函数,见上说明
                        validator: (rule, value, callback) => {
                            // 上面有说,返回true表示校验通过,返回false表示不通过
                            // uni.$u.test.mobile()就是返回true或者false的
                            return this.$utils.verifyBankCard(value);
                        },
                        message: '卡号不正确',
                        trigger: 'change'
                    }]
                }
            };
        },
        onReady() {
            //如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则。
            this.$refs.uForm.setRules(this.rules)
        },
        methods: {
            doNext() {
                this.$refs.uForm.validate().then(res => {
                    this.loading = true
                    isContain({
                        cardNum: this.form.cardNo
                    }).then(res => {
                        uni.request({
                            url: 'https://ccdcapi.alipay.com/validateAndCacheCardInfo.json?_input_charset=utf-8&cardBinCheck=true&cardNo=' +
                                this.form.cardNo,
                            method: "GET",
                            complete: (res) => {
                                this.loading = false
                                if (res.statusCode == 200) {
                                    if (res.data.validated) {
                                        const bank = bankName.bankName[res.data.bank]
                                        const params = uni.$u.deepClone(this.form);
                                        params.cardType = res.data.cardType
                                        params.bankName = bank
                                        uni.$u.route({
                                            url: '/pages/pay/addCardSecond',
                                            params: params
                                        })
                                    } else {
                                        uni.$u.toast("卡号不正确!");
                                    }
                                } else {
                                    uni.$u.toast("卡类型获取失败!");
                                }
                            }
                        })
                    }).catch(() => {
                        this.loading = false
                    })
 
                }).catch(errors => {
 
                })
            }
        }
    }
</script>
 
<style lang="scss">
 
</style>