You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
254 lines
5.9 KiB
254 lines
5.9 KiB
// pages/user/bindtel/index.js
|
|
import util from "../../../utils/util.js"
|
|
import user from "../../../utils/https/user.js"
|
|
import https from "../../../utils/https.js"
|
|
var app = getApp();
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
tel:"",
|
|
picCode:"",
|
|
code:"",
|
|
buttonText:"获取验证码",
|
|
sendFlag:true,
|
|
regToken:null,
|
|
codeId:null,
|
|
imgCodeInfo:null,
|
|
|
|
isApproval: false
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
this.changeImgCode();
|
|
this.setData({
|
|
regToken: options.regToken?decodeURIComponent(options.regToken):null
|
|
})
|
|
},
|
|
cancel:function(){
|
|
wx.switchTab({
|
|
url: '/pages/index/index',
|
|
})
|
|
},
|
|
changeImgCode:function(){
|
|
user._post("user/getCaptchaImg",{}).then(res=>{
|
|
console.log(res)
|
|
this.setData({
|
|
imgCodeInfo:res.data
|
|
})
|
|
})
|
|
},
|
|
// 一些input操作 为什么不是双向绑定啊 脑子疼
|
|
telInput:function(e){
|
|
this.setData({
|
|
tel:e.detail.value
|
|
})
|
|
},
|
|
codeInput:function(e){
|
|
this.setData({
|
|
code: e.detail.value
|
|
})
|
|
},
|
|
picCodeInput:function(e){
|
|
this.setData({
|
|
picCode: e.detail.value
|
|
})
|
|
},
|
|
// 获取验证码
|
|
getCode:function(){
|
|
// 如果已经在发送则不能继续发送验证码
|
|
if (!this.data.sendFlag){
|
|
return false;
|
|
}
|
|
if(!this.data.tel){
|
|
wx.showToast({
|
|
title: '请输入手机号',
|
|
icon:"none"
|
|
})
|
|
return false;
|
|
}
|
|
if(!util.isTel(this.data.tel)){
|
|
wx.showToast({
|
|
title: '请输入正确的手机号码',
|
|
icon: "none"
|
|
})
|
|
return false;
|
|
}
|
|
if(!this.data.picCode){
|
|
wx.showToast({
|
|
title: '请输入图形验证码',
|
|
icon:"none"
|
|
})
|
|
return false;
|
|
}
|
|
// 获取验证码则需要改变按钮的文字
|
|
this.setData({
|
|
buttonText:"发送中...",
|
|
sendFlag:false
|
|
})
|
|
let service = "user/getMobileCodeForChange",data={
|
|
mobile:this.data.tel,
|
|
captchaCode:this.data.picCode,
|
|
captchaCodeId:this.data.imgCodeInfo.id
|
|
},api = user.user_post;
|
|
if(this.data.regToken){
|
|
service="user/getMobileCodeForBind";
|
|
data.openid = this.data.regToken
|
|
api = user._post
|
|
}
|
|
api(service, data).then(res=>{
|
|
console.log('sendmsg',res)
|
|
if(res.code==1){
|
|
// 发送成功 即接口调用成功
|
|
this.setData({
|
|
buttonText: "发送成功",
|
|
sendFlag: false,
|
|
codeId: res.data.id
|
|
})
|
|
// 获取成功之后需要马上改变成倒计时
|
|
let time = 59;
|
|
var timer = setInterval(() => {
|
|
// 倒计时结束需要重置可发送验证码状态和按钮文字
|
|
if (time < 0) {
|
|
// 清除定时器
|
|
clearInterval(timer)
|
|
this.setData({
|
|
buttonText: "重新发送",
|
|
sendFlag: true
|
|
})
|
|
return false;
|
|
}
|
|
this.setData({
|
|
buttonText: time + "秒后重新发送"
|
|
})
|
|
time--;
|
|
}, 1000)
|
|
}
|
|
else {
|
|
this.setData({
|
|
buttonText: "重新发送",
|
|
sendFlag: true
|
|
})
|
|
}
|
|
|
|
})
|
|
// wx.navigateToMiniProgram({
|
|
// appId: 'wx5a3a7366fd07e119',
|
|
// path: '/pages/captcha/index',
|
|
// extraData: {
|
|
// appId: '2037722291'//您申请的验证码的 appId
|
|
// }
|
|
// })
|
|
},
|
|
// 绑定
|
|
submit:function(){
|
|
if(!this.data.code){
|
|
wx.showToast({
|
|
title: '请输入验证码',
|
|
icon: "none"
|
|
})
|
|
return false;
|
|
}
|
|
|
|
if (this.data.regToken && !this.data.isApproval) {
|
|
wx.showToast({
|
|
title: '请先阅读并同意相关协议',
|
|
icon: "none"
|
|
});
|
|
return
|
|
}
|
|
|
|
let service = "user/changeMobile",data={smsCode:this.data.code,mobile:this.data.tel,smsCodeId:this.data.codeId},api = user.user_post;
|
|
if(this.data.regToken){
|
|
service = "user/wxBindPhoneAndLogin"
|
|
data.openid = this.data.regToken
|
|
data.fromSource = "WECHATXCX"
|
|
if(app.globalData.category_id){
|
|
data.category_id = app.globalData.category_id;
|
|
}
|
|
api = user._post
|
|
}
|
|
api(service,data).then(res=>{
|
|
if(res.code==1){
|
|
// 绑定成功
|
|
wx.showToast({
|
|
title: this.data.regToken?"绑定成功":"更换",
|
|
icon: "success"
|
|
})
|
|
setTimeout(()=>{
|
|
wx.navigateBack({
|
|
delta:this.data.regToken?2:1
|
|
})
|
|
},500)
|
|
if(this.data.regToken){
|
|
https.set_logininfo(res);
|
|
}
|
|
// wx.setStorageSync("jstrip_userid", res.data.id)
|
|
// wx.setStorageSync("jstrip_token", res.data.token)
|
|
// wx.setStorageSync("jstrip_userInfo", res.data)
|
|
// app.globalData.userInfo = res.data;
|
|
}
|
|
})
|
|
},
|
|
|
|
changeIsApproval:function (e) {
|
|
this.setData({isApproval: !this.data.isApproval})
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
// const captchaResult = app.globalData.captchaResult;
|
|
// app.globalData.captchaResult = null; // 验证码的票据为一次性票据,取完需要置空
|
|
// if (captchaResult && captchaResult.ret === 0) {
|
|
// // 将验证码的结果返回至服务端校验
|
|
// const ticket = captchaResult.ticket;
|
|
// const randstr = captchaResult.randstr;
|
|
// // 这个时候才可以获取验证码
|
|
// // 获取验证码接口
|
|
// // todo
|
|
|
|
// }
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
|
|
}
|
|
})
|