verify_info.js
5.5 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
// pages/main/verify/verify_info.js
var format = require('../../../utils/util.js');
const reg_18_Number = /^[0-9]{18}$/;
const reg_9_n_a = /^([a-zA-z]|[0-9]){9}$/;
const reg_15_n_a = /^([a-zA-z]|[0-9]){15}$/;
const reg_20_n_a = /^([a-zA-z]|[0-9]){20}$/;
var baseUrl = getApp().globalData.baseUrl;
let Authorization = '';
Page({
/**
* Page initial data
*/
data: {
is_foreigner: false,
btn_text: "下一步",
info_steps: [{
label: '身份信息',
status: 'success'
}, {
label: '上传证件照',
status: 'circle'
}],
cardTypeArray: ['中国护照', '港澳居民来往内地通行证', '港澳居民居住证', '台湾居民来往大陆通行证', '台湾居民居住证', '外国护照', '外国人永久居留身份证', '外国人工作许可证(A类)', '外国人工作许可证(B类)', '外国人工作许可证(C类)'],
cardtype: "",
card_number: "",
name: "",
},
/**
* Lifecycle function--Called when page load
*/
onLoad: function(options) {
console.log("options", options);
this.setData({
is_foreigner: options.foreigner,
btn_text: "true" == options.foreigner ? "提交" : "下一步"
})
},
/**
* Lifecycle function--Called when page is initially rendered
*/
onReady: function() {
},
/**
* Lifecycle function--Called when page show
*/
onShow: function() {
},
bindCardtypeChange: function(e) {
console.log("bindCardtypeChange", e)
var cardTypeArray = this.data.cardTypeArray
var new_type = cardTypeArray[e.detail.value] //['name']
this.setData({
cardtype: new_type
})
},
bindinputcardnum: function(e) {
var idCardNo = e.detail.value
this.setData({
card_number: idCardNo
})
},
nameInput: function(e) {
this.setData({
name: e.detail.value
})
},
dealCardType: function() { //提交前验证输入的内容规则
},
gonext: function() {
var that = this
//校验证照类型,证照号码,姓名
var type = this.data.cardtype;
var idCardNo = this.data.card_number;
var name = this.data.name.replace(/(^\s*)|(\s*$)/g, "");
var regname_c = /^[\u4E00-\u9FA5\uf900-\ufa2d·s]{2,30}$/; //中文
var regname_e = /^[A-Za-z][A-Za-z\s]*[A-Za-z]$/; //英文
console.log('cardtype', type)
if (this.data.is_foreigner == 'true') { //非身份证
if (type.length < 1) {
this.showtoast('请选择证照类型');
return
}
if (name.length < 1) {
this.showtoast('请输入姓名');
return
}
name = name.replace(/(^\s*)|(\s*$)/g, "");
if (!regname_c.test(name) && !regname_e.test(name)) {
this.showtoast('请输入正确的姓名');
return
}
if (idCardNo.length < 1) {
this.showtoast('请填写证照号码');
return
}
if (type.indexOf('居住证') > -1 && !reg_18_Number.test(idCardNo)) {
this.showtoast('证照号码有误0');
return
}else if (type.indexOf('中国护照') > -1 && !reg_9_n_a.test(idCardNo)) {
this.showtoast('证照号码有误');
return
}else if (type.indexOf('永久居留') > -1 && !reg_15_n_a.test(idCardNo)) {
this.showtoast('证照号码有误');
return
}
if (type.indexOf('居住证') < 0 && type.indexOf('中国护照') < 0 && type.indexOf('永久居留') < 0 &&!reg_20_n_a.test(idCardNo)) {
this.showtoast('证照号码有误');
return
}
//TODO 请求数据,上传用户身份信息
Authorization = getApp().globalData.Authorization;
wx.request({
url: baseUrl + 'uaa/v1/users/auth-extend',
method: 'POST',
data: {
name: name,
id_card_type: type,
id_card_no: idCardNo
},
header: {
'content-type': 'application/json',
"Authorization": Authorization
},
success: function(res) {
console.log("SUCC", res.data)
if (res.data.code && res.data.code >= 300) {
wx.navigateTo({
url: 'verify_result/verify_result?result=fail',
})
that.showtoast(res.data.message);
} else {
wx.navigateTo({
url: 'verify_result/verify_result?result=succ',
})
}
}
})
} else { //身份证
if (name.length < 1) {
this.showtoast('请输入姓名');
return
}
if (!regname_c.test(name)) {
this.showtoast('请输入正确的姓名');
return
}
if (idCardNo.length < 1) {
this.showtoast('请填写证照号码');
return
}
if (!format.isIDCardNum(idCardNo)) {
this.showtoast('证照号码有误');
return;
}
wx.navigateTo({
url: 'verify_idcard/verify_idcard?input_name=' + name + '&input_card_number=' + idCardNo,
})
}
},
showtoast: function(title) {
wx.showToast({
title: title,
duration: 2000,
icon: 'none'
// image: '/images/error.png'
})
},
/**
* Lifecycle function--Called when page hide
*/
onHide: function() {
},
/**
* Lifecycle function--Called when page unload
*/
onUnload: function() {
},
/**
* Page event handler function--Called when user drop down
*/
onPullDownRefresh: function() {
},
/**
* Called when page reach bottom
*/
onReachBottom: function() {
},
/**
* Called when user click on the top right corner to share
*/
onShareAppMessage: function() {
}
})