// pages/sendCreatorCode/index.js const app = getApp(); const commonUtil = require("../../utils/commonUtil.js"); import { customRequest } from '../../utils/request.js'; Page({ /** * 页面的初始数据 */ data: { tel: null, telStr: '', timer: null, // 定时器 codeBtn: { // 按钮状态切换 codeName: '获取验证码', // 状态名称 codeNumber: 60, // 倒计时秒数 isCode: false // 是否获取验证码 }, code: '', // 验证码字段 focus: false, // input是否聚焦 }, /** * 生命周期函数--监听页面加载 */ onLoad (options) { console.log(options); if (options.info) { let info = JSON.parse(options.info) // let tel = info.tel.slice(0, 3) + '****' + info.tel.slice(7, 11) this.setData({ telStr: info.telEncrypt, tel: info.tel }) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady () { }, /** * 生命周期函数--监听页面显示 */ onShow () { this.getCode() }, // 获取验证码 getCode () { let that = this if (that.data.timer != null) { clearInterval(that.data.timer) } // this.data.codeBtn.isCode = false // this.data.codeBtn.codeNumber = 10 // return customRequest("/yishoudan/commons/sendMsgCode",{header:'headers', method: 'post', data: { tel: that.data.tel}}).then(({data})=>{ if (data.status == 200) { that.data.timer = setInterval(() => { if (that.data.codeBtn.codeNumber == 0) { clearInterval(that.data.timer) return } that.data.codeBtn.codeNumber-- that.setData({ codeBtn: that.data.codeBtn }) }, 1000) that.setData({ codeBtn: that.data.codeBtn }) } else { wx.showToast({ title: data.msg, icon: 'none' }) } }) // wx.request({ // url: app.globalData.ip + "/yishoudan/commons/sendMsgCode", // method: "post", // header: app.globalData.headers, // data: { tel: that.data.tel }, // success: function ({ data }) { // console.log(data); // if (data.status == 200) { // that.data.timer = setInterval(() => { // if (that.data.codeBtn.codeNumber == 0) { // clearInterval(that.data.timer) // return // } // that.data.codeBtn.codeNumber-- // that.setData({ // codeBtn: that.data.codeBtn // }) // }, 1000) // that.setData({ // codeBtn: that.data.codeBtn // }) // } else { // wx.showToast({ // title: data.msg, // icon: 'none' // }) // } // } // }) }, // 点击聚焦输入框 focusClick () { console.log(this.data.focus); if (this.data.focus == false) { this.setData({ focus: true }) console.log(this.data.focus); } }, // 输入框失去焦点 inputCodeBlur (e) { let value = e.detail.value // this.data.focus = false this.setData({ focus: false }) }, // 输入框内容变化事件 inputCode (e) { console.log(e); let value = e.detail.value this.data.code = value this.setData({ code: value }) if (e.detail.cursor == 4) { console.log('输入完毕'); this.verifyCode(this.data.code) } }, /** * 校验验证码 */ verifyCode (code) { let that = this // var pages = getCurrentPages(); // var prevPage = pages[pages.length - 2]; // 上一个页面 // console.log(prevPage); // if (prevPage) { // prevPage.data.allowTrans = true // console.log(); // } // wx.navigateBack({ // delta: 1 // }); // return customRequest( "/yishoudan/commons/validateMsgCode",{header:'headers', method: 'post', data: { tel: that.data.tel, code}}).then(({data})=>{ if (data.status == 200) { wx.navigateTo({ url: '/pages/creatorSelectPage/index' }) // var pages = getCurrentPages(); // var prevPage = pages[pages.length - 2]; // 上一个页面 // if (prevPage) { // prevPage.data.allowTrans = true // wx.navigateBack({ // delta: 1 // }); // } } else { wx.showToast({ title: data.msg, icon: 'none' }) } }) // wx.request({ // url: app.globalData.ip + "/yishoudan/commons/validateMsgCode", // method: "post", // header: app.globalData.headers, // data: { tel: that.data.tel, code }, // success: function ({ data }) { // console.log(data); // if (data.status == 200) { // wx.navigateTo({ // url: '/pages/creatorSelectPage/index' // }) // // var pages = getCurrentPages(); // // var prevPage = pages[pages.length - 2]; // 上一个页面 // // if (prevPage) { // // prevPage.data.allowTrans = true // // wx.navigateBack({ // // delta: 1 // // }); // // } // } else { // wx.showToast({ // title: data.msg, // icon: 'none' // }) // } // } // }) }, /** * 生命周期函数--监听页面隐藏 */ onHide () { }, /** * 生命周期函数--监听页面卸载 */ onUnload () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom () { }, /** * 用户点击右上角分享 */ onShareAppMessage () { } })