import { imgServerUrl } from '../../config/config.js' import $wuxCountDown from '../../utils/coutdown.js' import { sendPhoneCode } from '../../services/index.js' import { saveMinaPhone } from '../../services/wx.js' import { showToast } from '../../utils/tips.js' Page({ /** * 页面的初始数据 */ data: { imgServerUrl: imgServerUrl, iphone: '', yzm: "", }, /** * 生命周期函数--监听页面加载 */ onLoad: function(options) { }, // 手机号输入 bindPhoneInput(e) { this.setData({ iphone: e.detail.value }) }, // 验证码号输入 bindYzmInput(e) { this.setData({ yzm: e.detail.value }) }, // 验证码发送 sendCode(e) { if (this.data.iphone.length != 11) { showToast('请输入11位手机号码!') return } if (this.data.djs && this.data.djs != '获取验证码') { return false; } sendPhoneCode({ phone: this.data.iphone }).then(data => { }) this.vcode() }, //倒计时 vcode() { if (this.djs && this.djs.interval) return !1 this.djs = new $wuxCountDown({ date: +(new Date) + 60000, onEnd() { this.setData({ djs: '获取验证码', }) }, render(date) { const sec = this.leadingZeros(date.sec, 2) + ' 秒 ' date.sec !== 0 && this.setData({ djs: '剩余' + sec + '', }) }, }) }, //绑定手机号 phone_login() { if (this.data.iphone.length != 11) { return false; } if (this.data.yzm.length != 6) { return false; } var openId = wx.getStorageSync('openId'); var sessionKey = wx.getStorageSync('sessionKey'); var unionId = wx.getStorageSync('unionId'); let paramsObj = { phone: this.data.iphone, code: this.data.yzm, openId: openId, unionId: unionId, sessionKey: sessionKey } Object.assign(paramsObj); saveMinaPhone(paramsObj).then(data => { console.log("save", data) wx.setStorageSync("hpuser", data.data.hpUser); wx.setStorageSync("hpMember", data.data.hpMember); wx.setStorageSync("user_id", data.data.hpUser.id); wx.setStorageSync("member_id", data.data.hpMember.id); wx.setStorageSync("user_token", data.data.hpUser.userToken); showToast("登录成功"); setTimeout(function() { wx.navigateBack(); }, 500) }) }, })