You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

207 lines
4.6 KiB
JavaScript

2 years ago
// pages/makeInfoSure/index.js
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
userInformation: {},
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var that = this;
wx.getStorage({
key: 'userInformation',
success: function(res) {
console.log(res.data);
that.data.userInformation = res.data;
that.setData({
userInformation: that.data.userInformation
});
}
})
},
showTips: function (_that, msg) {
_that.setData({
popErrorMsg: msg,
pop: 1,
});
setTimeout(() => {
_that.setData({
popErrorMsg: '',
pop: 0,
});
return;
}, 2000)
},
dialog: function (title, content, btxt) {
wx.showModal({
title: title,
content: content,
showCancel: false,
confirmColor: "#e60012",
confirmText: btxt,
success: function (res) {
if (res.confirm) {
console.log('用户点击确定')
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
},
formSubmit: function (e) {
var that = this;
var username = /^[\u4E00-\u9FA5\uf900-\ufa2d·s]{2,20}$/;
if (!username.test(e.detail.value.userName)) {
that.showTips(this, "请输入正确的姓名");
return
}
if (e.detail.value.idCard.length != 18) {
that.showTips(this, "请输入正确的身份证号");
return
}
wx.showLoading({
title: '保存中...',
mask: true
})
var realName = e.detail.value.userName;
var IDCard = e.detail.value.idCard;
wx.request({
url: app.globalData.ip + '/commons/validatecard',
data: {
name: e.detail.value.userName,
cardno: e.detail.value.idCard
},
header: app.globalData.header,
method: "POST",
success: function (res) {
console.log(res);
// if (res.data.status == 9999) {
// app.dialogNotLogin();
// return;
// }
var state = res.data.data.state;
if(state == 101) {
wx.hideLoading();
that.dialog("已被占用", "你输入的身份证号已经被其他人占用了", "知道了")
} else if(state == 102) {
wx.hideLoading();
that.dialog("次数超限", "你今天已经认证失败3次明天再认证吧", "知道了");
} else if(state == 5 || state == 14 || state == 96) {
wx.hideLoading();
that.dialog("认证失败", "姓名或身份证号错误,认证失败", "知道了");
} else if(state == 0){
that.saveIDCard(realName, IDCard);
} else {
wx.hideLoading();
that.dialog("认证失败", res.data.msg, "知道了");
}
}
})
},
saveIDCard: function(realName, IDCard) {
let that = this;
wx.request({
url: app.globalData.ip + '/user/auth/authIDCard',
data: {
realName: realName,
IDCard: IDCard
},
header: app.globalData.header,
method: "POST",
success: function (res) {
// console.log(res);
if (res.data.status == 200) {
app.globalData.user.realName = realName;
wx.showToast({
title: '保存成功',
icon: 'success',
image: '',
duration: 1000,
mask: true,
success: function(res) {
wx.hideLoading();
app.globalData.user.idauth = 1;//如果身份证上传成功,登录缓存的实名认证状态更新为已实名
that.makeInfoSuccess();
},
fail: function(res) {
wx.hideLoading();
},
complete: function(res) {},
})
} else {
app.showTips(that, res.data.msg);
}
}
})
},
makeInfoSuccess:function(){
wx.redirectTo({
url: '/pages/makeInfoSuccess/index',
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})