const app = require('../../utils/util.js'); import WxValidate from '../../utils/WxValidate'; Page({ data: { isRz: 0, userName: "", phone: "", card: "", isInput1: false, isInput2: false, isInput3: false }, showModal(error) { wx.showModal({ content: error.msg, showCancel: false, }) }, tj(sessionKey, params) { wx.request({ url: app.globalData.publicUrl2 + '/wx/student/uthentication', method: "post", data: { studentName: params.userName, studentCard: params.card, phone: params.phone, sessionKey: sessionKey }, success: function (res) { if (res.data.code == 0) { wx.showModal({ showCancel: false, content: res.data.msg, success(res) { if (res.confirm) { wx.switchTab({ url: '../index/index' }) } } }) } else { wx.showModal({ showCancel: false, content: res.data.msg, success(res) { // if (res.confirm) {} } }) } } }) }, formSubmit: function (e) { wx.showLoading({ mask: true, title: '加载中', }) let _this = this; if (_this.data.isRz == 0) { const params = e.detail.value let _this = this; if (!this.WxValidate.checkForm(params)) { const error = this.WxValidate.errorList[0] this.showModal(error) wx.hideLoading() return false } wx.checkSession({ success: () => { console.log("我有缓存") var sessionKey = wx.getStorageSync('sessionKey'); if (sessionKey == "") { wx.login({ success(res) { console.log(res); var code = res.code wx.request({ url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login', method: "get", data: { code }, success: function (res) { sessionKey = res.data.sessionKey; wx.setStorageSync('sessionKey', res.data.sessionKey); _this.tj(sessionKey, params); wx.hideLoading() } }) } }) } else { _this.tj(sessionKey, params); wx.hideLoading() } }, fail() { console.log("我没有缓存并去登录请求") wx.login({ success(res) { console.log(res); var code = res.code wx.request({ url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login', method: "get", data: { code }, success: function (res) { wx.setStorageSync('sessionKey', res.data.sessionKey); var sessionKey = res.data.sessionKey; _this.tj(sessionKey, params); wx.hideLoading() } }) } }) } }) } else { wx.hideLoading() wx.showModal({ showCancel: false, content: "您已经认证过了" }) } }, getXx(sessionKey) { let _this = this; wx.request({ url: app.globalData.publicUrl2 + '/wx/student/selStudentSessionKeyEcho', method: "post", data: { sessionKey: sessionKey }, success: function (res) { if (res.data.code == 0) { if (res.data.data !== null || res.data.data !== "") { _this.setData({ isRz: 1, userName: res.data.data.miniName, phone: res.data.data.miniPhone, card: res.data.data.studentCard, isInput3: true }) } else { console.log("我没认证,需要认证") } } else { console.log("报错额") } console.log(res) // sessionKey = res.data.sessionKey; // wx.setStorageSync('sessionKey', res.data.sessionKey); // _this.getXx(sessionKey); } }) }, onLoad: function () { var _this = this; wx.checkSession({ success: () => { console.log("我有缓存") var sessionKey = wx.getStorageSync('sessionKey'); if (sessionKey == "") { wx.login({ success(res) { console.log(res); var code = res.code wx.request({ url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login', method: "get", data: { code }, success: function (res) { sessionKey = res.data.sessionKey; wx.setStorageSync('sessionKey', res.data.sessionKey); _this.getXx(sessionKey); _this.initValidate(); } }) } }) } else { _this.getXx(sessionKey); _this.initValidate(); } }, fail() { console.log("我没有缓存并去登录请求") wx.login({ success(res) { console.log(res); var code = res.code wx.request({ url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login', method: "get", data: { code }, success: function (res) { wx.setStorageSync('sessionKey', res.data.sessionKey); var sessionKey = res.data.sessionKey _this.getXx(sessionKey); _this.initValidate(); } }) } }) } }) }, // onLoad: function () { // this.initValidate(); // wx.login({ // success(res) { // console.log(res); // var code = res.code // wx.request({ // url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login', // method: "get", // data: { // code // }, // success: function (res) { // console.log(res,"我是测试") // // wx.setStorageSync('sessionKey', res.data.sessionKey); // // var sessionKey = res.data.sessionKey; // // _this.tj(sessionKey, params); // } // }) // } // }) // }, initValidate() { // 验证字段的规则 const rules = { userName: { required: true }, phone: { required: true, tel: true, }, card: { required: true, idcard: true, } } // 验证字段的提示信息,若不传则调用默认的信息 const messages = { userName: { required: '请输入姓名' }, phone: { required: '请输入手机号', tel: '请输入正确的手机号', }, card: { required: '请输入身份证号码', idcard: '请输入正确的身份证号码', } } // 创建实例对象 this.WxValidate = new WxValidate(rules, messages) } })