Files
HnyhuaXCX/pages/forgetPassword/index.js

204 lines
4.6 KiB
JavaScript
Raw Normal View History

var app=getApp()
var that=null
var sopenFrame=null
var wait=120
var username=""
var phone=""
Page( {
data: {
getcode:"获取验证码",
savebutton:"重置密码"
},
onLoad: function() {
that = this
that.rdata()
},rdata: function() {
},login:function(e) {
var username = "";//e.detail.value.username
var phone = e.detail.value.phone
var code = e.detail.value.code
var psd=e.detail.value.psd
var psd2=e.detail.value.psd2
var b=true
/*if(username==null || username==""){
b=false
wx.showToast({
title: "用户名不能为空!",
icon: "none",
duration: 3000
})
}*/
if(b){
if(phone==null || phone==""){
b=false
wx.showToast({
title: "手机号码不能为空!",
icon: "none",
duration: 3000
})
}
}
if(b){
if(code==null || code==""){
b=false
wx.showToast({
title: "手机验证码不能为空!",
icon: "none",
duration: 3000
})
}
}
if(b){
if(psd==null || psd==""){
b=false
wx.showToast({
title: "新密码不能为空!",
icon: "none",
duration: 3000
})
}
}
if(b){
var patrn =/^(?=.{6,16}$)[0-9a-zA-Z_]+$/;
if(!patrn.exec(psd)) {
b=false
wx.showToast({
title: "新密码由6-16位数字、字母、下划线组成",
icon: "none",
duration: 3000
})
}
}
if(b){
if(psd2==null || psd2==""){
b=false
wx.showToast({
title: "确认密码不能为空!",
icon: "none",
duration: 3000
})
}
}
if(b){
if(psd!=psd2){
b=false
wx.showToast({
title: "两次输入新密码不一致!",
icon: "none",
duration: 3000
})
}
}
if(b){
that.setData({
savebutton:"请稍候..."
})
wx.request({
url: app.globalData.apiurl + "/xapiajax.ashx",
data: {
action:"forgetPassword",
//username:username,
phone:phone,
code:code,
password:psd
},
method:"POST",
dataType:"json",
header: {
"content-type": "application/x-www-form-urlencoded" // 默认值
},
success (res) {
that.setData({
savebutton:"保存"
})
if(res.data.status==1){
wx.showToast({
title: res.data.msg,
icon: "success",
duration: 3000
})
}else{
wx.showToast({
title: res.data.msg,
icon: "none",
duration: 3000
})
}
}
})
}
},getcode:function(e) {
var b=true
if(b){
if(phone==null || phone==""){
b=false
wx.showToast({
title: "手机号码不能为空!",
icon: "none",
duration: 3000
})
}
}
if(b){
wx.request({
url: app.globalData.apiurl + "/xapiajax.ashx",
data: {
action:"sendphonecode0",
username:phone,
phone:phone
},
method:"POST",
dataType:"json",
header: {
"content-type": "application/x-www-form-urlencoded" // 默认值
},
success (res) {
if(res.data.status==1){
wx.showToast({
title: res.data.msg,
icon: "success",
duration: 3000
})
that.gettime()
}else{
wx.showToast({
title: res.data.msg,
icon: "none",
duration: 3000
})
}
}
})
}
},
gettime:function() {
if (wait == 0) {
that.setData({
getcode:"获取验证码"
})
wait = 120;
} else {
that.setData({
getcode: "重新发送(" + wait + ")"
})
wait--;
setTimeout(function() {
that.gettime()
}, 1000)
}
},getusernameValue:function(e) {
username=e.detail.value
},getphoneValue:function(e) {
phone=e.detail.value
}
})