Files
xuan_wechat/pages/resetPassword/resetPassword.js
2023-08-25 14:04:31 +08:00

131 lines
3.4 KiB
JavaScript

Page({
/**
* 页面的初始数据
*/
data: {
codename : '获取验证码',
smsDisabled : false, // 获取验证码 禁止点击
seeState : false, // 小眼睛
againState : false, // 小眼睛-再次输入密码
passwordState : true, // 小眼睛-显示
passwordAgain : true, // 小眼睛-显示-再次输入密码
phone : "", // 手机号
code : "", // 验证码
},
/**
* 手机号码
*/
bindInput(e) {
this.setData({
phone: e.detail.value
})
},
/**
* 短信验证码
*/
bindCode(e) {
this.setData({
code: e.detail.value
})
},
/**
* 获取短信验证码
*/
getPhoneCode(e) {
let mobile = this.data.phone
var _this = this
if (mobile == "") {
wx.showToast({
title : '手机号不能为空',
icon : 'none',
duration : 1000
})
return false;
}else{
wx.$api.auth.getSms({
mobileNo: mobile
}).then(res=>{
console.log(res)
_this.setData({
smsDisabled : true
})
wx.showToast({
title : '发送成功',
icon : 'success',
duration: 2000
})
var num = 60;
var timer = setInterval(function () {
num--;
if (num <= 0) {
clearInterval(timer);
_this.setData({
codename : '重新发送',
smsDisabled : false
})
} else {
_this.setData({
codename : num + "s后重新获取",
smsDisabled : true
})
}
}, 1000)
}).catch(err=>{})
}
},
/**
* 查看密码
*/
seeClick() {
this.setData({
seeState : !this.data.seeState,
passwordState: !this.data.passwordState
})
},
/**
* 查看密码-再次
*/
seeAgain() {
this.setData({
againState : !this.data.againState,
passwordAgain : !this.data.passwordAgain
})
},
/**
* 重置密码
*/
registerForm(e) {
wx.showLoading({
title: '加载中...',
mask : true
})
let value = e.detail.value
let data = {
username : this.data.phone,
code : value.code,
password : value.password,
password_confirmation : value.password_confirmation
}
wx.$api.auth.resetPassword(data).then(res => {
wx.hideLoading()
wx.showModal({
content : res.data,
showCancel : false,
confirmText : '确定',
confirmColor: '#da2b54',
success : () => {
wx.navigateBack()
}
})
}).catch(() =>{ })
}
})