96 lines
2.2 KiB
JavaScript
96 lines
2.2 KiB
JavaScript
import { API } from './../../utils/network/api'
|
|
const api = new API()
|
|
Page({
|
|
data: {
|
|
navbarData: {
|
|
showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
|
|
title: '手机号登录', //导航栏 中间的标题
|
|
},
|
|
checked: true,
|
|
phone: "",
|
|
sms: "",
|
|
btn_msg: "获取验证码",
|
|
btn_disabled: false,
|
|
login_disabled: true,
|
|
},
|
|
onChange(event) {
|
|
this.setData({
|
|
checked: event.detail,
|
|
});
|
|
},
|
|
getCodePhone(e){
|
|
if(!this.data.checked){
|
|
wx.showToast({
|
|
title: '请同意协议',
|
|
icon: "error"
|
|
})
|
|
return;
|
|
}
|
|
this.setData({
|
|
btn_disabled: true
|
|
})
|
|
//获取手机号验证码
|
|
var params = {};
|
|
params.phone = this.data.phone;
|
|
params.scene = 1;
|
|
api.getCodePhone(params).then(response => {
|
|
console.log(response);
|
|
this.beginDaoJiShi();
|
|
this.setData({
|
|
login_disabled: false
|
|
})
|
|
}).catch(errors => {
|
|
this.setData({
|
|
btn_disabled: false
|
|
})
|
|
console.error(errors);
|
|
})
|
|
},
|
|
mobileLogin(e){
|
|
if(!this.data.checked){
|
|
wx.showToast({
|
|
title: '请同意协议',
|
|
icon: "error"
|
|
})
|
|
return;
|
|
}
|
|
var params = {};
|
|
params.phone = this.data.phone;
|
|
params.code = this.data.sms;
|
|
params.user_type = wx.getStorageSync('usertype');
|
|
|
|
api.mobileLogin(params).then(response => {
|
|
console.log(response);
|
|
wx.setStorageSync('AUTH_TOKEN', response.data.token);
|
|
wx.setStorageSync('user_id', response.data.user_id);
|
|
wx.setStorageSync('client_user_id', response.data.client_user_id);
|
|
wx.switchTab({
|
|
url: wx.getStorageSync('next_url')
|
|
})
|
|
}).catch(errors => {console.error(errors);})
|
|
},
|
|
beginDaoJiShi(){
|
|
console.log("开始倒计时")
|
|
let _this = this;
|
|
let time = 60;
|
|
let time_index = setInterval(function(){
|
|
console.log("time: ", time);
|
|
if(time > 1){
|
|
time--;
|
|
_this.setData({
|
|
btn_msg: time+" 秒后获取",
|
|
btn_disabled: true
|
|
})
|
|
}else{
|
|
_this.setData({
|
|
btn_msg: "获取验证码",
|
|
btn_disabled: false
|
|
})
|
|
clearInterval(time_index);
|
|
}
|
|
},1000)
|
|
|
|
|
|
}
|
|
|
|
}) |