212 lines
4.9 KiB
JavaScript
212 lines
4.9 KiB
JavaScript
// pages/bind/bind.js
|
|
const $api = require("../../utils/api").API;
|
|
import Dialog from '../../miniprogram_npm/@vant/weapp/dialog/dialog';
|
|
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
sms: "",
|
|
phone: "",
|
|
phoneErr: "",
|
|
sendMsgBtn: true,
|
|
sendMsgBtnText: "发送验证码",
|
|
verificationCode: "",
|
|
//用户协议
|
|
personShow:false,
|
|
//隐私政策
|
|
privacyShow:false,
|
|
privacy:false,
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
|
|
},
|
|
checkPhone() {
|
|
let regs = /^(?:(?:\+|00)86)?1[3-9]\d{9}$/;
|
|
console.log(this.data.phone)
|
|
if (regs.test(this.data.phone)) {
|
|
this.setData({
|
|
phoneErr: "",
|
|
sendMsgBtn: false
|
|
});
|
|
} else {
|
|
this.setData({
|
|
phoneErr: "手机号码有误"
|
|
});
|
|
}
|
|
},
|
|
sendMsg() {
|
|
let that = this;
|
|
$api.getMsgCode({
|
|
"phone": this.data.phone
|
|
}).then(obj => {
|
|
if (obj.code == 200) {
|
|
//保存校验code至页面变量
|
|
//改变按钮为不可用用状态
|
|
that.setData({
|
|
verificationCode: obj.data.verificationCode,
|
|
sendMsgBtn: true
|
|
});
|
|
//生成倒计时文本
|
|
// 启动以1s为步长的倒计时
|
|
let seconds = 60;
|
|
let interval = setInterval(() => {
|
|
seconds--;
|
|
that.setData({
|
|
sendMsgBtnText: seconds + "秒后重发"
|
|
})
|
|
}, 1000);
|
|
// 停止倒计时
|
|
setTimeout(function () {
|
|
clearInterval(interval);
|
|
that.setData({
|
|
sendMsgBtnText: "发送验证码",
|
|
sendMsgBtn: false
|
|
})
|
|
}, seconds * 1000);
|
|
}
|
|
}).catch(err => {
|
|
console.log(err);
|
|
})
|
|
},
|
|
wxBind() {
|
|
let that = this;
|
|
if(!that.data.phone){
|
|
wx.showToast({
|
|
title:'请输入手机号!',
|
|
duration:1500,
|
|
icon:"none"
|
|
});
|
|
return false;
|
|
}
|
|
if(!that.data.sms){
|
|
wx.showToast({
|
|
title:'请输入手机号验证码!',
|
|
duration:1500,
|
|
icon:"none"
|
|
});
|
|
return false;
|
|
}
|
|
if(!that.data.privacy){
|
|
wx.showToast({
|
|
title:'请勾选阅读用户协议!',
|
|
duration:1500,
|
|
icon:"none"
|
|
});
|
|
return false;
|
|
}
|
|
if (that.data.sms === that.data.verificationCode) {
|
|
$api.saveBind({
|
|
"phone": that.data.phone,
|
|
"openId": wx.getStorageSync("openId")
|
|
}).then(res => {
|
|
if (res.code == 200) {
|
|
wx.reLaunch({
|
|
url: "/pages/loading/loading"
|
|
})
|
|
} else {
|
|
Dialog.alert({
|
|
message: res.msg,
|
|
}).then(() => {
|
|
// on close
|
|
});
|
|
}
|
|
}).catch(err => {
|
|
console.log(err);
|
|
})
|
|
} else {
|
|
wx.showToast({
|
|
title:'验证码不一致!',
|
|
duration:1500,
|
|
icon:"none"
|
|
});
|
|
}
|
|
},
|
|
//选中隐私
|
|
handleCheckbox(e){
|
|
let _arr = e.detail.value;
|
|
let _isShow = false;
|
|
if(_arr.length > 0){
|
|
_isShow = true;
|
|
}
|
|
this.setData({
|
|
privacy:_isShow
|
|
})
|
|
},
|
|
//点击隐私政策·
|
|
handlePrivacyOpen(){
|
|
this.setData({
|
|
privacyShow:true
|
|
})
|
|
},
|
|
handlePrivacyClose(){
|
|
this.setData({
|
|
privacyShow:false
|
|
})
|
|
},
|
|
//用户协议事件
|
|
handlePersonOpen(){
|
|
this.setData({
|
|
personShow:true
|
|
})
|
|
},
|
|
handlePersonClose(){
|
|
this.setData({
|
|
personShow:false
|
|
})
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage() {
|
|
|
|
}
|
|
}) |