| | |
| | | import { sendSms,loginByPhone, getDictData } from '../../api/index' |
| | | import { |
| | | sendSms, |
| | | getDictData, |
| | | getWxMiniPhone, |
| | | loginByPhone, |
| | | bindingOpenid |
| | | } from '../../api/index' |
| | | Page({ |
| | | |
| | | /** |
| | |
| | | getCode() { |
| | | let countDown = this.data.countDown |
| | | if(countDown > 0) return |
| | | const { phone } = this.data |
| | | const { |
| | | phone |
| | | } = this.data |
| | | if(!phone || phone.length != 11){ |
| | | return wx.showToast({ |
| | | title: '请输入正确的手机号', |
| | |
| | | title: '验证码发送成功', |
| | | icon: 'none' |
| | | }) |
| | | this.setData({ countDown: 60 }) |
| | | this.setData({ |
| | | countDown: 60 |
| | | }) |
| | | let timer = setInterval(() => { |
| | | let countDown = this.data.countDown |
| | | if(countDown === 0){ |
| | | return clearInterval(timer) |
| | | } |
| | | countDown -- |
| | | this.setData({ countDown }) |
| | | this.setData({ |
| | | countDown |
| | | }) |
| | | }, 1000) |
| | | }) |
| | | }, |
| | | loginPhone() { |
| | | const { code, phone } = this.data |
| | | loginByPhone({code, phone}).then(res => { |
| | | const { |
| | | code, |
| | | phone |
| | | } = this.data |
| | | loginByPhone({ |
| | | code, |
| | | phone |
| | | }).then(res => { |
| | | if (res.data && res.data.token) { |
| | | wx.login({ |
| | | timeout: 5000, |
| | | success: (loginRes) => { |
| | | if (loginRes.code) { |
| | | this.bindingOpenid(loginRes.code, res.data.token) |
| | | } |
| | | } |
| | | }) |
| | | if(res.data.phone){ |
| | | res.data.users.phone = res.data.phone || res.data.users.phone |
| | | } |
| | | wx.setStorageSync('member', res.data.users) |
| | | wx.setStorageSync('token', res.data.token) |
| | | wx.showToast({ |
| | |
| | | url: '/pages/index/index', |
| | | }) |
| | | }, 300) |
| | | }else{ |
| | | wx.showToast({ |
| | | title: '你还不是该系统用户,请联系相关管理员注册', |
| | | }) |
| | | } |
| | | }) |
| | | }, |
| | | changeStatus() { |
| | |
| | | }) |
| | | this.initData() |
| | | }, |
| | | getPhoneNumber(e) { |
| | | const data = { |
| | | ...e.detail |
| | | } |
| | | getWxMiniPhone({ |
| | | encryptedData: data.encryptedData, |
| | | iv: data.iv, |
| | | sessionKey: wx.getStorageSync('sessionKey') || data.iv, |
| | | }).then(res => { |
| | | if (res.data && res.data.token) { |
| | | wx.login({ |
| | | timeout: 5000, |
| | | success: (loginRes) => { |
| | | if (loginRes.code) { |
| | | this.bindingOpenid(loginRes.code, res.data.token) |
| | | } |
| | | } |
| | | }) |
| | | if(res.data.phone){ |
| | | res.data.users.phone = res.data.phone || res.data.users.phone |
| | | } |
| | | wx.setStorageSync('member', res.data.users) |
| | | wx.setStorageSync('token', res.data.token) |
| | | wx.switchTab({ |
| | | url: '/pages/index/index', |
| | | }) |
| | | }else{ |
| | | wx.showToast({ |
| | | title: '你还不是该系统用户,请联系相关管理员注册', |
| | | }) |
| | | } |
| | | |
| | | }) |
| | | }, |
| | | bindingOpenid(code, token) { |
| | | bindingOpenid({code, token}) |
| | | }, |
| | | loginIn() { |
| | | const { |
| | | agreementFalg |
| | | } = this.data |
| | | if (!agreementFalg) return wx.showToast({ |
| | | title: '请先阅读并同意相关协议', |
| | | icon: 'none', |
| | | duration: 2000 |
| | | }) |
| | | }, |
| | | onOpen(e){ |
| | | const { serviceHtml, privacyHtml } = this.data |
| | | const { index } = e.target.dataset |
| | | const { |
| | | serviceHtml, |
| | | privacyHtml |
| | | } = this.data |
| | | const { |
| | | index |
| | | } = e.target.dataset |
| | | let activeHtml = index == '0' ? serviceHtml : privacyHtml |
| | | this.setData({ |
| | | activeHtml, |
| | |
| | | }) |
| | | }, |
| | | onClose() { |
| | | this.setData({showModal: false}) |
| | | this.setData({ |
| | | showModal: false |
| | | }) |
| | | }, |
| | | initData(){ |
| | | getDictData({ |