移动系统liao
2025-02-17 557c2711a3e103ebc3d0492344eca9730d5e92b2
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
<template>
    <view>
        <u-toast ref="uToast" /><u-no-network></u-no-network>
        <u-navbar title="添加银行卡" safeAreaInsetTop fixed placeholder>
            <view class="coreshop-navbar-left-slot" slot="left">
                <u-icon name="arrow-left" size="19" @click="goNavigateBack"></u-icon>
                <u-line direction="column" :hairline="false" length="16" margin="0 8px"></u-line>
                <u-icon name="home" size="22" @click="goHome"></u-icon>
            </view>
            <view slot="right">
            </view>
        </u-navbar>
        <view class="coreshop-padding-10">
            <u--form :model="form" :rules="rules" ref="uForm" errorType="message" labelPosition="top" labelWidth="80">
                <u-form-item label="银行卡号" prop="cardNumber" borderBottom>
                    <u--input type="text" v-model="form.cardNumber" placeholder="请输入银行卡号" @blur="checkCard()"></u--input>
                </u-form-item>
                <u-form-item label="持卡人姓名" prop="name" borderBottom>
                    <u--input type="text" v-model="form.name" placeholder="请输入持卡人姓名"></u--input>
                </u-form-item>
                <u-form-item label="银行名称" borderBottom>
                    <u--input type="text" :disabled="true" v-model="form.bankName"></u--input>
                </u-form-item>
                <u-form-item label="银行卡类型" borderBottom>
                    <u--input type="text" :disabled="true" v-model="form.cardTypeName"></u--input>
                </u-form-item>
                <u-form-item label="开户行名" borderBottom>
                    <u--input type="text" v-model="form.accountBank" placeholder="请输入开户银行名"></u--input>
                </u-form-item>
                <u-form-item label="开户行地址" borderBottom>
                    <coreshop-select v-model="show" mode="mutil-column-auto" :list="pickerList" :default-value="pickerIndex" @confirm="onConfirm"></coreshop-select>
                    <!-- 注意:由于兼容性差异,如果需要使用前后插槽,nvue下需使用u--input,非nvue下需使用u-input -->
                    <!-- #ifndef APP-NVUE -->
                    <u-input :value="pickerValue" type="select" placeholder="请选择省市区区域">
                        <template slot="suffix">
                            <u-button text="选择" type="success" size="mini" @click="show = true"></u-button>
                        </template>
                    </u-input>
                    <!-- #endif -->
                    <!-- #ifdef APP-NVUE -->
                    <u--input :value="pickerValue" type="select" placeholder="请选择省市区区域">
                        <template slot="suffix">
                            <u-button text="选择" type="success" size="mini" @click="show = true"></u-button>
                        </template>
                    </u--input>
                    <!-- #endif -->
                </u-form-item>
                <!--<u-form-item label="设为默认">
                    <u-checkbox v-model="checked" @change="defaultChange">勾选将设为默认提现账户</u-checkbox>
                </u-form-item>-->
                <view class="coreshop-padding-15 flex coreshop-flex-nowrap">
                    <u-checkbox-group>
                        <u-checkbox v-model="checked" @change="defaultChange" label="勾选将设为默认提现账户"></u-checkbox>
                    </u-checkbox-group>
                </view>
            </u--form>
        </view>
        <!--按钮-->
        <view class="coreshop-bg-white coreshop-footer-fixed coreshop-foot-padding-bottom">
            <u-button type="error" size="normal" @click="addCard" :disabled='submitStatus' :loading='submitStatus'>保存</u-button>
        </view>
    </view>
</template>
 
<script>
    export default {
        data() {
            return {
                form: {
                    cardNumber: '', // 银行卡号
                    name: '',    // 开户人姓名
                    bankName: '',    // 银行名称
                    bankCode: '', // 银行缩写码
                    accountBank: '', // 开户行
                    cardType: 1, // 卡类型
                    cardTypeName: '', // 卡片类型
                    isDefault: 0,
                },
                region: ['湖南省', '怀化市', '鹤城区'],
                areaId: 0,
                checked: false,
                pickerValue: '',
                submitStatus: false,
                show: false,
                pickerList: this.$db.get("areaList"),
                province: this.$db.get("areaList"),
                pickerIndex: [0, 0, 0], // picker索引值
                provinceKey: -1,//省份id
                cityKey: -1,//市id
                areaKey: -1,//区域id
                rules: {
                    cardNumber: [
                        {
                            required: true,
                            message: '请输入密码',
                            trigger: ['change', 'blur'],
                        },
                        {
                            type: 'number',
                            message: '请输入数字银行卡号',
                            trigger: ['change', 'blur'],
                        }
                    ],
                    name: [
                        {
                            required: true,
                            message: '请输入姓名',
                            trigger: 'blur',
                        },
                        {
                            min: 2,
                            max: 4,
                            message: '姓名长度在2到4个字符',
                            trigger: ['change', 'blur'],
                        },
                        {
                            validator: (rule, value, callback) => {
                                return this.$u.test.chinese(value);
                            },
                            message: '必须为中文',
                            trigger: ['change', 'blur'],
                        }
                    ],
                },
            }
        },
        computed: {},
        onReady() {
            this.$refs.uForm.setRules(this.rules);
        },
        methods: {
            checkboxChange(n) {
                this.form.checked = n;
                console.log('change', n);
            },
            // 省市区联动初始化
            showThreePicker() {
                this.show = true;
            },
            // 选择收货地址
            onConfirm(e) {
                console.log(e);
                let provinceName = e[0].label;
                let cityName = e[1].label;
                let countyName = e[2].label;
                this.pickerValue = e[0].label + " " + e[1].label + " " + e[2].label
                let data = {
                    provinceName: provinceName,
                    cityName: cityName,
                    countyName: countyName
                }
                //let regionName = [provinceName, cityName, countyName];
                this.$u.api.getAreaId(data).then(res => {
                    if (res.status) {
                        this.areaId = res.data;
                        this.init();
                    } else {
                        uni.showModal({
                            title: '提示',
                            content: '地区选择出现问题,请重新选择地区',
                            showCancel: false
                        });
                    }
                });
            },
            // 选择/取消默认
            defaultChange(e) {
                this.form.isDefault = e.value ? 1 : 0;
                console.log(this.form.isDefault);
            },
            // 判断获取银行卡类型
            checkCard() {
                let _this = this;
                if (this.form.cardNumber) {
                    let data = {
                        id: this.form.cardNumber
                    }
                    this.$u.api.getBankCardOrganization(data).then(res => {
                        if (res.status) {
                            let data = res.data
                            _this.form.bankName = data.name
                            _this.form.cardType = data.type
                            _this.form.bankCode = data.bankCode
                            _this.form.cardTypeName = data.typeName
                        } else {
                            _this.$refs.uToast.show({
                                message: res.msg, type: 'error', complete: function () {
                                    _this.form.bankCode = _this.form.bankName = _this.form.cardType = _this.form.cardTypeName = ''
                                }
                            })
 
                        }
                    })
                } else {
                    this.form.bankCode = this.form.bankName = this.form.cardType = this.form.cardTypeName = ''
                }
            },
            // 添加银行卡
            addCard() {
                this.$refs.uForm.validate().then(res => {
                    console.log('验证通过');
                    if (!this.form.cardNumber) {
                        this.$u.toast('请输入银行卡号')
                    } else if (!this.form.bankName || !this.form.cardType || !this.form.bankCode) {
                        this.$u.toast('请输入正确的银行卡号')
                    } else if (!/^[\u4E00-\u9FA5\uf900-\ufa2d·s]{2,30}$/.test(this.form.name)) {
                        this.$u.toast('请输入正确的持卡人名称')
                    } else if (this.areaId <= 0) {
                        this.$u.toast('请选择开户行所在地区')
                    } else if (!this.form.accountBank) {
                        this.$u.toast('请输入开户银行信息')
                    } else {
                        this.submitStatus = true;
                        let data = {
                            bankName: this.form.bankName,
                            bankCode: this.form.bankCode,
                            bankAreaId: this.areaId,
                            accountBank: this.form.accountBank,
                            accountName: this.form.name,
                            cardNumber: this.form.cardNumber,
                            cardType: this.form.cardType,
                            isDefault: this.form.isDefault
                        }
                        this.$u.api.addBankCard(data).then(res => {
                            this.submitStatus = false;
                            if (res.status) {
                                this.$refs.uToast.show({
                                    message: res.msg, type: 'success', complete: function () {
                                        uni.navigateBack({
                                            delta: 1
                                        });
                                    }
                                })
                            } else {
                                this.$u.toast(res.msg);
                            }
                        });
                    }
                }).catch(errors => {
                    uni.$u.toast('提交的数据校验失败,请输入合法信息!')
                })
            },
            //倒查城市信息
            getFullPath(id, data) {
                for (var i = 0; i < data.length; i++) {
                    if (id == data[i].value) {
                        if (!data[i].children) {
                            this.areaKey = i;
                            return true;
                        } else if (data[i].hasOwnProperty("children")) {
                            if (data[i].children[0] && !data[i].children[0].children) {
                                this.cityKey = i;
                                return true;
                            } else {
                                this.provinceKey = i;
                                return true;
                            }
                        }
                    } else {
                        if (data[i].hasOwnProperty("children")) {
                            if (data[i].children[0] !== undefined) {
                                if (data[i].children[0].hasOwnProperty("children")) {
                                    this.provinceKey = i;
                                } else {
                                    this.cityKey = i;
                                }
                            }
                            if (typeof data[i].children != 'undefined') {
                                var res = this.getFullPath(id, data[i].children);
                                if (res) {
                                    return true;
                                }
                            }
                        }
                    }
                }
            },
            //增加默认省市区选中
            init() {
                this.getFullPath(this.areaId, this.province);
                this.pickerIndex = [this.provinceKey, this.cityKey, this.areaKey];
                console.log(this.pickerIndex);
            },
        },
        onLoad(e) {
            if (e.ship_id) {
                //编辑
                this.id = e.ship_id;
                this.getShipInfo();
            } else {
                //添加(取消初始化)
                //this.pickerValue = this.region[0] + " " + this.region[1] + " " + this.region[2];
                //this.init();
            }
        },
    }
</script>
 
<style lang="scss">
    page { background: #fff; }
</style>