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.

270 lines
6.2 KiB

1 year ago
import util from "../../../utils/util.js"
1 year ago
import commonApi from "../../../utils/https/common"
import pwEncode from "../../../utils/passwordEncode"
1 year ago
var app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
type:'add',
title: '',
editConfrim: false,
vcode: '',//验证码内容
isFoucs: true,
inputData: {
phone: '',
code: '',
password: '',
confirmPassword: '',
},
canSubmit: false,
code:"",
buttonText:"获取验证码",
sendFlag:true,
regToken:null,
codeId:null,
isApproval: false
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({
type: options.type||'add',
title: options.type=='reset'?'忘记密码':options.type=='edit'?'修改密码':'设置支付密码',
editConfrim: options.type == 'edit'?true:false
})
},
1 year ago
// 编辑时输入原密码
1 year ago
passwordChange: function (e) {
1 year ago
let _this = this
1 year ago
let val = e.detail.value
1 year ago
console.log("passwordChange")
1 year ago
this.setData({
vcode: val
})
if (val.length==6) {
// 验证密码
1 year ago
let password = pwEncode.handleEncrypt(val)
// 验证密码
commonApi.user_post("pay_password/verifyPassword",{password:password})
.then(res=>{
// 密码校验成功
if (res.code == 1) {
_this.setData({editConfrim: false})
} else {
_this.setData({
vcode: '',
isFoucs: true
})
}
})
// this.setData({editConfrim: false})
1 year ago
}
},
handleFoucs() {
this.setData({
isFoucs: true
})
1 year ago
console.log("focus")
1 year ago
},
// 输入框
inputChange:function(e){
let inputData = this.data.inputData
let keyname =e.currentTarget.dataset.keyname;
inputData[keyname] = e.detail.value
this.setData({
inputData: inputData
})
let canSubmit = false
if (this.data.type == 'edit' && inputData.password && inputData.confirmPassword) {
canSubmit = true
}
if (this.data.type != 'edit' && inputData.phone && inputData.code && inputData.password && inputData.confirmPassword) {
canSubmit = true
}
this.setData({canSubmit: canSubmit})
},
// 获取验证码
getCode:function(){
// 如果已经在发送则不能继续发送验证码
if (!this.data.sendFlag){
return false;
}
if(!this.data.inputData.phone){
wx.showToast({
title: '请输入手机号',
icon:"none"
})
return false;
}
if(!util.isTel(this.data.inputData.phone)){
wx.showToast({
title: '请输入正确的手机号码',
icon: "none"
})
return false;
}
// 获取验证码则需要改变按钮的文字
this.setData({
buttonText:"发送中...",
sendFlag:false
})
1 year ago
commonApi.user_post("uservice/user/getMobileCodeForResetPayPass",{mobile:this.data.inputData.phone}).then(res=>{
if(res.code==1){
// 发送成功 即接口调用成功
this.setData({
buttonText: "发送成功",
sendFlag: false,
codeId: res.data.smsCodeId
})
// 获取成功之后需要马上改变成倒计时
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 {
1 year ago
this.setData({
buttonText: "重新发送",
sendFlag: true
})
}
1 year ago
}).catch(e=>{
1 year ago
this.setData({
1 year ago
buttonText: "重新发送",
sendFlag: true
1 year ago
})
})
},
// 绑定
submit:function(){
1 year ago
if (!this.data.canSubmit) {
return
}
if(this.data.type!='edit'&&!this.data.inputData.code){
1 year ago
wx.showToast({
title: '请输入验证码',
icon: "none"
})
return false;
}
1 year ago
let data={
code:this.data.inputData.code,
mobile:this.data.inputData.phone,
smsCodeId:this.data.codeId,
password: pwEncode.handleEncrypt(this.data.inputData.password),
confirm_password:pwEncode.handleEncrypt(this.data.inputData.confirmPassword)
1 year ago
}
1 year ago
let service = "pay_password/set"
if (this.data.type == 'reset') service = 'pay_password/reset'
if (this.data.type == 'edit') {
service = "pay_password/modify"
data.old_password = pwEncode.handleEncrypt(this.data.vcode)
}
console.log(data)
commonApi.user_post(service,data).then(res=>{
1 year ago
if(res.code==1){
1 year ago
wx.showToast({
title: '密码设置成功',
icon: 'none'
})
1 year ago
setTimeout(()=>{
wx.navigateBack({
delta:1
})
},500)
// if(this.data.regToken){
// https.set_logininfo(res);
// }
}
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
1 year ago
commonApi.user_post("uservice/user/getMyInfo",{}).then(res=>{
1 year ago
let userinfo = res.data
if (userinfo && userinfo.mobile) {
this.data.inputData.phone = userinfo.mobile
this.setData({
inputData: this.data.inputData
})
}
})
1 year ago
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
}
})