// pages/register/register.js Page({ /** * 页面的初始数据 */ data: { userName: null, phone: null, email: null, carNum:null, password: null, rePassword: null, checkPass: false, errorMsg: '' }, /** * 生命周期函数--监听页面加载 */ onLoad: function(options) { //var that = this; //查看是否授权 //wx.getSetting({ //success(res) { //console.log(res); //if (res.authSetting['scope.userInfo']) { //that.setData({ //authSet: true //}); //已经授权,可以直接调用 getUserInfo 获取头像昵称 //wx.getUserInfo({ //success(res) { //console.log(res) //that.setData({ //userInfo: res.userInfo //}); //} //}); //} //} //}); }, bindGetUserInfo(e) { //console.log(e); //console.log(e.detail.userInfo) let that = this; if (e.detail.userInfo) { let { nickName: userName, gender: sex, avatarUrl: avatar } = e.detail.userInfo; let { userName: loginName, password, phone, carNum, email } = this.data; wx.login({ success(res) { //console.log(res); if (res.code) { wx.request({ url: getApp().globalData.postHeadAgreement + '/restapi/wechat/register', data: { userName, sex, avatar, loginName, password, phonenumber: phone, email, license_number: carNum, code: res.code }, method: 'POST', success(res1) { //console.log(res1); //console.log(res1.data.code == 1); if (res1.data.code == 1) { that.setData({ errorMsg: res1.data.msg }) } else { //返回该用户 //跳转到上一页 wx.setStorageSync("userInfo", res1.data); wx.setStorageSync("isLogin", true); wx.navigateBack(); //let url = `/pages/ucenter/index/index`; //wx.redirectTo({ //url //}); } } }); } else { console.log('登录失败!' + res.errMsg) } } }); } }, inputAccount(e) { this.setData({ userName: e.detail.value }); this.checkAll(); }, inputPassword(e) { this.setData({ password: e.detail.value }); this.checkAll(); }, inputRepassword(e) { this.setData({ rePassword: e.detail.value }); this.checkAll(); }, inputPhone(e) { this.setData({ phone: e.detail.value }); this.checkAll(); }, inputEmail(e) { this.setData({ email: e.detail.value }); this.checkAll(); }, inputCarNum(e){ this.setData({ carNum: e.detail.value }); this.checkAll(); }, checkPassword() { if (!this.data.password || !this.data.rePassword || this.data.password != this.data.rePassword) { return false; } return true; }, checkPhone() { if (!(/^1[3456789]\d{9}$/.test(this.data.phone))) { return false; } return true; }, checkMail() { if (!(/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/.test(this.data.email))) { return false; } return true; }, checkCarNum(){ if (this.data.carNum){ if (!(/^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z](([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳使领]))$/.test(this.data.carNum))) { return false; } } return true; }, checkAll() { if (!this.data.userName || !this.data.userName.replace(/(^\s*)|(\s*$)/g,"")) { this.setData({ errorMsg: '账号不能为空' }); this.setData({ checkPass: false }); return; } else if (this.data.userName.length < 2 || this.data.userName.length > 20) { this.setData({ errorMsg: '账号长度应为2-20' }); this.setData({ checkPass: false }); return; } else if (!(/^[a-zA-Z0-9_.\u4e00-\u9fa5]+$/.test(this.data.userName))) { this.setData({ errorMsg: '账号只能包含字母、数字、中文、下划线和点' }); this.setData({ checkPass: false }); return; }else{ this.setData({ errorMsg: '' }); } if (!this.checkPhone()) { this.setData({ errorMsg: '手机号输入有误,请重新输入' }); this.setData({ checkPass: false }); return; } else { this.setData({ errorMsg: '' }); } if (!this.checkMail()) { this.setData({ errorMsg: '邮箱输入有误,请重新输入' }); this.setData({ checkPass: false }); return; } else { this.setData({ errorMsg: '' }); } if (!this.checkCarNum()) { this.setData({ errorMsg: '车牌号输入有误,请重新输入' }); this.setData({ checkPass: false }); return; } else { this.setData({ errorMsg: '' }); } if (this.data.password && (this.data.password.length < 5 || this.data.password.length > 20)) { this.setData({ errorMsg: '密码长度应为5-20' }); this.setData({ checkPass: false }); return; } if (!this.checkPassword()) { this.setData({ errorMsg: '两次密码输入不一致,请重新输入' }); this.setData({ checkPass: false }); return; } else { this.setData({ errorMsg: '' }); } this.setData({ checkPass: true }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function() { }, /** * 生命周期函数--监听页面显示 */ onShow: function() { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function() { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function() { }, /** * 用户点击右上角分享 */ onShareAppMessage: function() { } })