card-add.vue
6.86 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
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
<template>
<LayoutApp :title="title">
<p class="mian-tip">请添加持卡人本人银行卡</p>
<div class="form-wrap">
<div v-for="(item, index) in formList" :key="index" class="form-row">
<text class="cell-left">{{item.title}}</text>
<input class="cell-right" :placeholder="item.placeholder" :readonly="isReadonly(item)" :value="formValue[index]" @input="inputChange(index, $event)"/>
<div v-if="item.select" class="tap-act">
<Select
:options="selectOptions[item.select]"
:placeholder="item.placeholder"
@change="selectChange(index, $event)"
class="tab-go">
</Select>
›
</div>
</div>
</div>
<p class="error-tip">{{errorTip}}</p>
<div class="option-wrap">
<button class="save-btn" @click="checkBankCardInfo">确定</button>
</div>
</LayoutApp>
</template>
<script>
import { createNamespacedHelpers } from 'vuex';
import LayoutApp from '../../components/layout/layout-app';
import {Select} from 'cube-ui';
const {mapState, mapActions} = createNamespacedHelpers('mine/bankCard');
export default {
name: 'cardAdd',
title: '',
data() {
return {
title: '我的银行卡',
formList: [
{
title: '持卡人',
placeholder: '请输入持卡人姓名',
type: 'name',
errorTip: '您输入的姓名不符合规范,请重新输入',
regx: /^([\u4e00-\u9fa5]|[A-Za-z]){2,}$/
},
{
title: '身份证号',
placeholder: '请输入身份证号',
type: 'idCardNo',
errorTip: '您输入的身份证号码不符合规范,请重新输入',
regx: /^(\d|X|x){15,18}$/
},
{
title: '开户行',
placeholder: '请选择开户行',
type: 'bankCode',
errorTip: '请选择开户行',
select: 'bankList',
},
{
title: '分行 支行',
placeholder: '例如:南京分行雨花支行',
type: 'bankBranch',
errorTip: '请输入正确的分行和支行信息'
},
{
title: '银行卡号',
placeholder: '请输入银行卡号',
type: 'bankCardNo',
errorTip: '您输入的银行卡号不符合规范,请重新输入',
regx: /^\d{10,22}$/
},
],
formValue: [],
errorTip: '',
};
},
mounted() {
if (!this.banks.length) {
this.fetchBankList();
}
},
computed: {
...mapState(['banks']),
selectOptions() {
let bankList = [];
this._bankObj = {};
if (this.banks && this.banks.length) {
this.banks.forEach(val => {
this._bankObj[val.bankCode] = val.bankName;
bankList.push({
text: val.bankName,
value: val.bankCode
});
});
}
return {bankList};
}
},
methods: {
...mapActions(['fetchBankList', 'checkBankCard', 'bindBankCard']),
isReadonly(item) {
return !!item.select;
},
inputChange(index, e) {
this.changeFormValue(index, e.target.value);
},
selectChange(index, val) {
let name = this._bankObj[val] || '';
this.changeFormValue(index, {
name,
value: val,
toString() {
return this.name
}
});
},
changeFormValue(index, val) {
let max = Math.max(index, this.formValue.length);
let formValue = [];
this.errorTip = '';
for (let i = 0; i <= max; i++) {
if (i === index) {
formValue[i] = val || '';
} else {
formValue[i] = this.formValue[i] || '';
}
}
this.formValue = formValue;
},
checkBankCardInfo() {
let errorTip = '';
let data = {};
this.formList.some((val, index) => {
if (errorTip) {
return true;
}
let input = this.formValue[index] || '';
let value = input.value || input || '';
if (val.regx) {
if (!val.regx.test(value)) {
errorTip = val.errorTip;
}
} else if (!value) {
errorTip = val.errorTip;
}
data[val.type] = value;
});
if (errorTip) {
this.errorTip = errorTip;
} else {
this.checkBankCard(data).then(res => {
if (res.code === 200) {
this.bindBankCardInfo(data);
} else {
this.errorTip = res.message || '信息有误或网络异常,请稍后重试';
}
});
}
},
bindBankCardInfo(info) {
let confirm = this.$createDialog({
type: 'confirm',
title: '提示',
content: `请确认您填写的银行信息,提交后只能致电客服修改<br><br>持卡人: ${info.name}<br>身份证号: ${info.idCardNo || ''}<br>银行卡号: ${info.bankCardNo || ''}`,
confirmBtn: {
text: '提交',
active: true,
},
cancelBtn: {
text: '取消',
},
onConfirm: () => {
this.bindBankCard(info).then(res => {
if (res.code === 200) {
this.$router.replace({name: 'bankcard'});
} else {
this.$createDialog({
type: 'alert',
content: res.message || '提交失败或网络异常,请稍后重试',
confirmBtn: {
text: '我知道了',
active: true
}
}).show()
}
});
}
}).show();
}
},
components: {
LayoutApp,
Select
}
};
</script>
<style lang="scss" scoped>
/deep/ .layout-context {
background-color: #f0f0f0!important;
}
.mian-tip {
padding: 0 30px;
line-height: 80px;
margin-top: 28px;
font-size: 28px;
color: #444;
}
.form-wrap {
background-color: #fff;
padding-left: 30px;
font-size: 28px;
.form-row:first-child {
border-top: 0;
}
}
.form-row {
height: 88px;
line-height: 90px;
padding-right: 30px;
border-top: 1px solid #e9e9e9;
display: flex;
position: relative;
box-sizing: border-box;
.cell-left {
width: 150px;
}
.cell-right {
flex-grow: 1;
}
.tap-act {
font-size: 50px;
color: #b0b0b0;
font-weight: 300;
}
.tab-go {
position: absolute;
left: 150px;
right: 30px;
top: 0;
bottom: 0;
z-index: 2;
opacity: 0;
}
}
.error-tip {
padding: 30px 30px 0 30px;
font-size: 28px;
line-height: 1.5;
color: #d0021b;
min-height: 72px;
}
.option-wrap {
margin: 20px 30px;
.save-btn {
width: 100%;
display: block;
font-size: 32px;
line-height: 100px;
color: #fff;
background: #444;
border: 0;
border-radius: 8px;
}
}
</style>