// pages/register/index.js const request = require('../../utils/request.js'); const app = getApp() Page({ /** * 页面的初始数据 */ data: { nvabarData: { showCapsule: 0, //是否显示左上角图标,消息中心 1表示显示 0表示不显示 showBack: 1, //返回 title: '注册', //导航栏 中间的标题 // 此页面 页面内容距最顶部的距离 height: app.globalData.height * 2 + 20, }, instructionBook: '已阅读并同意使用', radioCheck: false, disabled: false, phone:'', password:'', againpassword:'', yanzhengma:'', code: '获取验证码', defaultType: true, passwordType: true, defaultType1: true, passwordType1: true }, radioClick: function (event) { var radioCheck = this.data.radioCheck; this.setData({ "radioCheck": !radioCheck }); }, agreementBtn: function () { wx.navigateTo({ url: '/pages/agreement/index' }) // wx.navigateTo({ // url: '/pages/agreement/index?phone='this.data.phone +'&password=' +this.data.password+ '&againpassword=' + this.data.againpassword + '&yanzhengma=' + this.data.yanzhengma // 希望跳转过去的页面 // }) }, getCode:function (e) { this.setData({ code:e.detail.value }) }, talks:function (e) { this.setData({ phone:e.detail.value }) wx.setStorage({ key:"phone", data:e.detail.value }) }, getYanzhengma:function (e) { console.log("e",e); this.setData({ yanzhengma:e.detail.value }); wx.setStorage({ key:"yanzhengma", data:e.detail.value }); }, getPassword:function (e) { console.log("e",e); this.setData({ password:e.detail.value }); wx.setStorage({ key:"password", data:e.detail.value }); }, getPassword1:function (e) { this.setData({ againpassword:e.detail.value }) wx.setStorage({ key:"againpassword", data:e.detail.value }) }, //校验手机号 async isPoneAvailable(str) { var myreg = /^[1][3,4,5,7,8][0-9]{9}$/; if (!myreg.test(str)) { wx.showToast({ title: '请输入正确手机号', image:'/pages/images/jinggao.png', duration: 2000 }) return false; } else { var that = this; var time = 60; that.setData({ code: '60秒后重发', disabled: true }) var Interval = setInterval(function() { time--; if (time>0){ that.setData({ code: time + '秒后重发' }) }else{ clearInterval(Interval); that.setData({ code: '获取验证码', disabled: false }) } },1000) let list = await request.query({ url: 'api/financial/phoneMessage/sendMessage', data: {phone:this.data.phone}, method: 'post' }); if (list && list.data.data.Message && list.data.data.Message == 'OK' && list.data.data.Code && list.data.data.Code== 'OK') { if (list.data.data.number) { wx.setStorage({ key: 'code', data: list.data.data.number, }) } } else{ wx.showToast({ title: '获取验证码失败', icon: 'none', duration: 2000 }) } } }, getCode(){ if (this.data.phone) { wx.hideKeyboard() this.isPoneAvailable(this.data.phone); // var that = this; // var time = 60; // that.setData({ // code: '60秒后重发', // disabled: true // }) // let list = await request.query({ // url: 'api/financial/phoneMessage/sendMessage', // data: {phone:this.data.phone}, // method: 'post' // }); // if (list && list.data.data.Message && list.data.data.Message == 'OK' && list.data.data.Code && list.data.data.Code== 'OK') { // if (list.data.data.number) { // wx.setStorage({ // key: 'code', // data: list.data.data.number, // }) // } // var Interval = setInterval(function() { // time--; // if (time>0){ // that.setData({ // code: time + '秒后重发' // }) // }else{ // clearInterval(Interval); // that.setData({ // code: '获取验证码', // disabled: false // }) // } // },1000) // } else{ // wx.showToast({ // title: '获取验证码失败', // icon: 'none', // duration: 2000 // }) // } }else{ wx.showToast({ title: '请输入手机号', icon: 'none', duration: 2000 }) } }, // 注册账号 formSubmit: function (e) { console.log('form发生了submit事件,携带数据为:', e.detail.value) if(e.detail.value.person==""||e.detail.value.phone==""||e.detail.value.yanzhengma==""||e.detail.value.password==""||e.detail.value.againpassword==""){ wx.showToast({ title: '缺少部分信息项', icon: 'none', duration: 1500 }) return false } let code = wx.getStorageSync('code') if (code == e.detail.value.yanzhengma) { if (this.data.radioCheck ) { if(e.detail.value.password==e.detail.value.againpassword){ let pwdRegex = new RegExp('(?=.*[0-9])(?=.*[a-zA-Z])'); if (!pwdRegex.test(e.detail.value.password) || e.detail.value.password.length < 8|| e.detail.value.password.length >20) { wx.showModal({ title: '提示', content: '密码格式错误', confirmText: '确定', success(res) { if (res.confirm) { // console.log('用户点击取消') } else if (res.cancel) { // console.log('用户点击取消') } } }) // wx.showModal({ // title: '密码格式错误', // // content: '密码至少为8位字母数字组合。', // success (res) { // if (res.confirm) { // // console.log('用户点击取消') // } else if (res.cancel) { // // console.log('用户点击取消') // } // } // }) }else{ wx.setStorage({ key:"phone", data:e.detail.value.phone }) wx.setStorage({ key:"password", data:e.detail.value.password }) wx.request({ method: "POST", url: app.globalData.publicUrl + 'api/financial/companyuser', data: { phone: e.detail.value.phone, passwd: e.detail.value.password, // person: e.detail.value.person }, success: (e) => { console.log('success', e); if (e.data.errcode == 0) { wx.showModal({ title: '注册成功', content: '如需获得更多服务请进行企业认证', success (res) { if (res.confirm) { wx.navigateTo({ url: '/pages/login/index' }) } else if (res.cancel) { // console.log('用户点击取消') } } }) } else { if (e.data.details === "phone无效") { wx.showToast({ title: '请重新输入手机号', icon: 'none', duration: 1500 }) } else if (e.data.errmsg === "数据已存在") { wx.showToast({ title: '该手机号已被注册', icon: 'none', duration: 1500 }) } else { wx.showToast({ title: e.data.details ? e.data.details : e.data.errmsg, icon: 'none', duration: 1500 }) } } } }) } }else{ wx.showToast({ title: '两次密码输入不一致', icon: 'none', duration: 1500 }) } } else { wx.showToast({ title: '请勾选企业授权协议', icon: 'none', duration: 1500 }) } } else{ wx.showToast({ title: '验证码错误', icon: 'none', duration: 1500 }) } }, // 眼镜变色 eyeStatus(){ if (this.data.defaultType) { this.setData({ passwordType: false, defaultType: false, }) } else { this.setData({ passwordType: true, defaultType: true, }) } }, eyeStatus1(){ if (this.data.defaultType1) { this.setData({ passwordType1: false, defaultType1: false, }) } else { this.setData({ passwordType1: true, defaultType1: true, }) } }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ radioCheck: options.radioCheck }); let that = this; wx.getStorage({ key: 'phone', success (res) { console.log(res.data) that.setData({ phone:res.data }) } }) wx.getStorage({ key: 'password', success (res) { console.log(res.data) that.setData({ password:res.data }) } }) wx.getStorage({ key: 'againpassword', success (res) { console.log(res.data) that.setData({ againpassword:res.data }) } }) wx.getStorage({ key: 'yanzhengma', success (res) { console.log(res.data) that.setData({ yanzhengma:res.data }) } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })