import request from '~/api/request'; const { md5Encrypt } = require('../../utils/encrypt'); Page({ data: { phoneNumber: '', isPhoneNumber: false, isCheck: false, isSubmit: false, isPasswordLogin: true, passwordInfo: { account: '', password: '', }, radioValue: '', code: '' }, /* 自定义功能函数 */ changeSubmit() { if (this.data.isPasswordLogin) { if (this.data.passwordInfo.account !== '' && this.data.passwordInfo.password !== '' && this.data.isCheck) { this.setData({ isSubmit: true }); } else { this.setData({ isSubmit: false }); } } else if (this.data.isPhoneNumber && this.data.isCheck) { this.setData({ isSubmit: true }); } else { this.setData({ isSubmit: false }); } }, // 手机号变更 onPhoneInput(e) { const isPhoneNumber = /^[1][3,4,5,7,8,9][0-9]{9}$/.test(e.detail.value); this.setData({ isPhoneNumber, phoneNumber: e.detail.value, }); this.changeSubmit(); }, // 用户协议选择变更 onCheckChange(e) { const { value } = e.detail; this.setData({ radioValue: value, isCheck: value === 'agree', }); this.changeSubmit(); }, onAccountChange(e) { this.setData({ passwordInfo: { ...this.data.passwordInfo, account: e.detail.value } }); this.changeSubmit(); }, onPasswordChange(e) { this.setData({ passwordInfo: { ...this.data.passwordInfo, password: e.detail.value } }); this.changeSubmit(); }, // 切换登录方式 changeLogin() { this.setData({ isPasswordLogin: !this.data.isPasswordLogin, isSubmit: false }); }, async login() { if (this.data.isPasswordLogin) { const res = await request('patient/password_login', 'post', { mobile: this.data.passwordInfo.account, password: md5Encrypt(this.data.passwordInfo.password) }); console.log(res) await wx.setStorageSync('access_token', res.token); wx.switchTab({ url: `/pages/my/index`, }); } else { const res = await request('/patient/code_login', 'post', {code: this.data.code, mobile: this.data.phoneNumber}); await wx.setStorageSync('access_token', res.token); wx.switchTab({ url: `/pages/my/index`, }); // if (res.success) { // wx.navigateTo({ // url: `/pages/loginCode/loginCode?phoneNumber=${this.data.phoneNumber}`, // }); // } } }, // 获取验证码 async getCode() { const res = await request('patient/send_code', 'post', { mobile: this.data.phoneNumber, type: 1 }); }, uploadPass() { console.log('1222') wx.navigateTo({ url: `/pages/forGetPassword/index`, }) } });