// pages/phone/phone.js const app = getApp() Page({ /** * 页面的初始数据 */ data: { times:60, isTimes:false, tips:'获取验证码', myTime: null }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData(options) console.log(options) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { clearInterval(this.myTime); }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, /** * 底部导航跳转 */ redirectCtl: app.redirectCtl, /** * 路由跳转 */ navigateCtl: app.navigateCtl, /** * input */ inputCtl: function (e) { const mobileExp = /^1[0-9]{10}$/; const { temp = {}, type } = e.currentTarget.dataset const { value } = e.detail temp[type] = value; const { phone, verificationCode } = temp; if (type == 'phone') { this.setData({ phone }) // if (phone != '') { // if (!mobileExp.test(phone)) { // wx.showToast({ // title: '手机号码位数不对', // icon: 'none', // duration: 2000 // }) // this.setData({ phone }) // return // } else { // this.setData({ phone}) // } // } } else if (type == 'verificationCode') { return this.setData({ verificationCode }) } }, /** * 再次获取验证码 */ setStime:function(){ const mobileExp = /^1[0-9]{10}$/; const { times, phone}=this.data; if (!phone) { wx.showToast({ title: '手机号码不能为空', icon: 'none' }) return } else if (!mobileExp.test(phone)) { wx.showToast({ title: '手机号码位数不对', icon: 'none', duration: 1000 }) return } if (times == 60 || times ==0){ this.getNumber() } if(times>0){ this.startSetInter() }else if(times==0){ this.setData({times:60}) this.startSetInter() } }, /** * 开始计时 */ startSetInter: function () { var that = this; const {phone, tips, times} = that.data; // console.log(phone, tips, times) if (times == 0) { that.setData({ tips: "获取验证码"}); return ; } else { var numVal =that.data.times--; that.setData({ tips: "重新发送(" + numVal + ")"}); } this.myTime=setTimeout(function () { that.startSetInter(); }, 1000); }, /** * 获取验证码 */ getNumber:function(){ const { phone} = this.data; const postData = { fn: this.getNumber, param: { ...arguments } } app.post('/api/parents/parents/V2/getVerificationCode', { phone, type: 2 }, 0, postData).then(res => { wx.showToast({ title: '已发送', icon: 'none', duration: 1000 }); }) }, /** * 提交 */ sureSumbit:function(){ const mobileExp = /^1[0-9]{10}$/; const { phone, verificationCode, vipId, isFrist, derver}=this.data; console.log(phone, verificationCode, vipId, isFrist, derver) const postData = { fn: this.sureSumbit, param: { ...arguments } } if (!phone) { wx.showToast({ title: '手机号码不能为空', icon: 'none' }) return } else if (!mobileExp.test(phone)) { wx.showToast({ title: '手机号码位数不对', icon: 'none', duration: 1000 }) return } if (!verificationCode) { wx.showToast({ title: '请输入验证码', icon: 'none' }) return } clearInterval(this.myTime); this.setData({ times: 0, tips: "重新验证码"}) app.post('/api/parents/parents/V2/bindPhone', { phone, verificationCode }, 0, postData).then(res => { clearInterval(this.myTime); wx.showToast({ title: '绑定成功', icon: 'none', duration: 1000 }); if (isFrist == 1) { app.redirectCtl({ url: 'homework_list', method: { vipId } }, true) } else { app.redirectCtl({ url: 'wechat_addchild', method: { derver } }, true) } }) } })