// pages/login/reg/reg.js const app = getApp() Page({ /** * 页面的初始数据 */ data: { phone: '', psw: '', psw2: '', codeNum: '', userName: '', tjCode: '', imgSrc: '', address: '', detailedaddress: '', checked: false, }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.getImg() if (wx.getStorageSync('user')) { app.setUser(wx.getStorageSync('user')) wx.switchTab({ url: '/pages/home/home', }) } }, // 绑定用户名 bindUserName(e) { this.setData({ userName: e.detail.value }) }, bindPhone(e) { this.setData({ phone: e.detail.value }) }, // 绑定密码 bindPSW(e) { this.setData({ psw: e.detail.value }) }, bindPSW2(e) { this.setData({ psw2: e.detail.value }) }, // 验证码 bindcodeNum(e) { this.setData({ codeNum: e.detail.value }) }, bindTJ(e) { this.setData({ tjCode: e.detail.value }) }, onChangeRadio(e) { // console.log(e); if(e.detail.value.length>0){ this.setData({ checked:true }) }else{ this.setData({ checked:false }) } }, // 验证码 getImg() { this.setData({ imgSrc: "", uuid: "" }) wx.request({ url: `https://puyue.yhupai.com/prod-api/captchaImage`, method: 'GET', // header: { // "Access-Control-Allow-Headers": 'token' // }, dataType: 'json', success: (res, header) => { if (res.data.code != 200) { // wx.showToast({ // title: res.data.msg, // icon: 'none' // }); this.getImg() } else { console.log(res); this.setData({ imgSrc: "data:image/gif;base64," + res.data.img, uuid: res.data.uuid, }) } }, }); }, choseLocation() { wx.chooseLocation({ success: (res) => { console.log(res) this.setData({ address: res.name, detailedaddress: res.address, locmap: { latitude: res.latitude, longitude: res.longitude }, markers: [{ id: 0, latitude: res.latitude, longitude: res.longitude, iconPath: '/images/ProRep/weizhi.png', width: '50rpx', height: '50rpx' }] }) }, fail: () => { wx.getSetting({ success: (res) => { var statu = res.authSetting; if (!statu['scope.userLocation']) { //未授权 wx.showModal({ title: '授权定位', content: '需要获取您的地理位置,请先设置授权', // cancelColor: 'skyblue', confirmText: "去设置", success: (res) => { console.log(res); if (res.cancel) { //点击取消,默认隐藏弹框 } else { //点击确定 wx.openSetting({ withSubscriptions: true, success: (res) => { console.log(res); this.onLoad() } }) } } }) } } }) } }) }, login() { let reg_user = /^[\u4e00-\u9fa5]{2,4}$/; //2-4个中文字符正则 let reg_tel = /^1(3|4|5|6|7|8|9)\d{9}$/; if (!reg_user.test(this.data.userName)) { wx.showToast({ title: '请输入真实姓名', icon: 'none' }); return false } else if (!reg_tel.test(this.data.phone)) { wx.showToast({ title: '请输入手机号', icon: 'none' }); return false } else if (!this.data.codeNum) { wx.showToast({ title: '请输入验证码', icon: 'none' }); return false } else if (!this.data.psw) { wx.showToast({ title: '请输入密码', icon: 'none' }); return false } else if (!this.data.psw2) { wx.showToast({ title: '请输入确认密码', icon: 'none' }); return false } else if (this.data.psw2 !== this.data.psw) { wx.showToast({ title: '两次密码不一致', icon: 'none' }); return false } else if (!this.data.detailedaddress) { wx.showToast({ title: '请选择地址', icon: 'none' }); return false }else if(!this.checked){ wx.showToast({ title: '请阅读并同意用户协议', icon: 'none' }); return false } let data = { bindId: '', username: this.data.userName, phonenumber: this.data.phone, code: this.data.codeNum, confirmPassword: this.data.psw2, password: this.data.psw, uuid: this.data.uuid, advisecode: this.data.tjCode, address: this.data.detailedaddress } wx.request({ url: `https://puyue.yhupai.com/prod-api/iot/tool/register`, method: 'POST', header: { "Access-Control-Allow-Headers": 'token' }, data: data, success: (res, header) => { if (res.data.code != 200) { wx.showToast({ title: res.data.msg, icon: 'none' }); this.getImg() } else { wx.showToast({ title: res.data.msg, icon: 'none' }); setTimeout(() => { wx.navigateTo({ url: '/pages/login/login', }) }, 2000); } }, }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })