// pages/user/personalData/index.js const app = getApp(); Page({ /** * 页面的初始数据 */ data: { navTopHeight: app.globalData.menuTop + app.globalData.navTopHeight + 20, form: { realName:'', idcard:'', phone:'', code: '', city:'请选择所在城市', profession:'', position: '请选择', }, disabled: false, second: 60, positionArr: ['企业负责人','高层管理者','中层管理者','基层管理者','普通员工'], timer: null }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ userInfo: wx.getStorageSync('userInfo') }) if(this.data.userInfo.phone){ this.setData({ ['form.phone']: this.data.userInfo.phone }) } if(app.globalData.inviterId){ this.bindInviter() } }, //绑定上级 bindInviter(){ app.http('get','user/bindInviter',{inviterId:app.globalData.inviterId}).then((res)=>{ if(res.data.success){ console.log('绑定成功') } else{ console.log('绑定失败') } }) }, setFormStorage(){ wx.setStorageSync('form', this.data.form) }, changeName(e){ this.setData({ ['form.realName'] : e.detail.value }) this.setFormStorage() }, changePhone(e){ this.setData({ ['form.phone'] : e.detail.value }) }, changeidCard(e){ this.setData({ ['form.idCard'] : e.detail.value }) this.setFormStorage() }, bindRegionChange(e){ this.setData({ ['form.city'] : e.detail.value.join(' ') }) this.setFormStorage() }, bindPickerChange(e){ this.setData({ ['form.position']: this.data.positionArr[e.detail.value] }) this.setFormStorage() }, changeCode(e){ this.setData({ ['form.code']: e.detail.value }) this.setFormStorage() }, toProfession(){ wx.navigateTo({ url: '../profession/index', }) this.setFormStorage() }, getPhoneNumber(e){ if(e.detail.errMsg == 'getPhoneNumber:ok'){ app.http('post','wxapp/binding', {encryptedData: e.detail.encryptedData, iv: e.detail.iv }).then((res)=>{ if(res.data.success){ this.setData({ ['form.phone']: res.data.data.phone }) wx.showToast({ title: res.data.msg, }) } else{ wx.showToast({ title: res.data.msg, icon: 'none' }) } }) } }, backPage(){ wx.navigateBack({ delta: 1, }) }, sendCode(){ var reg=/^1[3456789]\d{9}$/; if (this.data.form.phone === '') { wx.showModal({ title: '手机号码不能为空', type: 'none' }); return } else if(!reg.test(this.data.form.phone)){ wx.showModal({ title: '请输入有效的手机号码', type: 'none' }); return } else{ if(this.data.disabled == false){ clearInterval(this.data.timer) this.setData({ disabled: true }) let timer = setInterval(()=>{ //设置延迟执行 this.timeup() },1000); this.setData({ timer: timer }) } app.http('post','user/getVerificationCode',{phone: this.data.form.phone}).then((res)=>{ if(res.data.success){ wx.showToast({ title:'短信已发送!' }) } else{ wx.showToast({ title:res.data.msg, icon:'none' }) } }) } }, timeup(){ this.setData({ second: this.data.second - 1 }) if (this.data.second == 0) { this.second = 60; this.setData({ disabled: false, second: 60 }) clearInterval(this.data.timer) return; } }, toComplete(){ let data = { realName: this.data.form.realName, idCard: this.data.form.idCard, code: this.data.form.code, phone: this.data.form.phone, city: this.data.form.city, industry: this.data.form.profession, position: this.data.form.position } app.http('post','user/edit',data).then((res)=>{ if(res.data.success){ wx.navigateTo({ url: '../completeData/index', }) app.getInfo() } else{ wx.showToast({ title: res.data.msg, icon: 'none' }) } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { if(wx.getStorageSync('form')){ let form = wx.getStorageSync('form') this.setData({ ['form.realName']: form.realName, ['form.city']: form.city, ['form.idCard']: form.idCard, ['form.code']: form.code, ['form.position']: form.position }) } }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ // onShareAppMessage: function () { // } })