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.
189 lines
3.7 KiB
189 lines
3.7 KiB
let common = getApp().globalData.commonFun; |
|
let util = getApp().globalData.utilFun; |
|
Page({ |
|
|
|
/** |
|
* 页面的初始数据 |
|
*/ |
|
data: { |
|
tel: "", // 手机号 |
|
code: "", //验证码 |
|
new_psd: "", //新密码 |
|
again_psd: "", //再次输入 |
|
code_num: 0, //验证码倒计时 |
|
}, |
|
|
|
/** |
|
* 生命周期函数--监听页面加载 |
|
*/ |
|
onLoad: function(options) { |
|
|
|
}, |
|
// 手机号 |
|
tel(e) { |
|
this.setData({ |
|
tel: e.detail.value |
|
}) |
|
}, |
|
// 获取验证码 |
|
obtain() { |
|
wx.showLoading({ |
|
title: '发送中...', |
|
mask: true |
|
}) |
|
let that = this |
|
if (this.data.tel == '' || !(/^1(3|4|5|6|7|8|9)\d{9}$/.test(this.data.tel))) { |
|
wx.showToast({ |
|
title: '请输入正确的手机号码', |
|
icon: 'none', |
|
duration: 2000 |
|
}) |
|
} else { |
|
let url = `api/get-code?phone=${this.data.tel}` |
|
util.httpRequest(url).then((res) => { |
|
wx.hideLoading() |
|
wx.showToast({ |
|
title: '发送成功!', |
|
icon: 'none', |
|
duration: 1500, |
|
mask: true |
|
}) |
|
this.setData({ |
|
code_num: 60, |
|
}) |
|
let setToun = setInterval(() => { |
|
that.setData({ |
|
code_num: that.data.code_num - 1 |
|
}) |
|
if (that.data.code_num <= 0) { |
|
clearInterval('setToun') |
|
} |
|
}, 1000) |
|
}) |
|
} |
|
|
|
}, |
|
// 输入验证码 |
|
code(e) { |
|
this.setData({ |
|
code: e.detail.value |
|
}) |
|
}, |
|
// 输入新密码 |
|
new_psd(e) { |
|
this.setData({ |
|
new_psd: e.detail.value |
|
}) |
|
}, |
|
// 再次输入 |
|
again_psd(e) { |
|
this.setData({ |
|
again_psd: e.detail.value |
|
}) |
|
}, |
|
// 确认修改 |
|
confirm() { |
|
if (this.data.tel == '' || !(/^1(3|4|5|6|7|8|9)\d{9}$/.test(this.data.tel))) { |
|
wx.showToast({ |
|
title: '请输入正确的手机号码', |
|
icon: 'none', |
|
duration: 2000 |
|
}) |
|
} else if (this.data.code == '') { |
|
wx.showToast({ |
|
title: '请输入验证码', |
|
icon: 'none', |
|
duration: 2000 |
|
}) |
|
} else if (this.data.new_psd.length < 6) { |
|
wx.showToast({ |
|
title: '请输入至少6位数密码', |
|
icon: 'none', |
|
duration: 2000 |
|
}) |
|
} else if (this.data.new_psd !== this.data.again_psd) { |
|
wx.showToast({ |
|
title: '确认密码和密码不一致', |
|
icon: 'none', |
|
duration: 2000 |
|
}) |
|
} else { |
|
let url = 'api/forget-password' |
|
let data = { |
|
phone: this.data.tel, |
|
verify_code: this.data.code, |
|
password: this.data.new_psd, |
|
password_rm: this.data.again_psd |
|
} |
|
util.httpRequest(url, data, 'post').then((res) => { |
|
if (res.code == '200') { |
|
wx.showToast({ |
|
title: '修改成功', |
|
icon: 'success', |
|
duration: 2000, |
|
mask: true |
|
}) |
|
setTimeout(() => { |
|
wx.navigateBack({ //返回 |
|
delta: 1 |
|
}) |
|
}, 2000) |
|
} else { |
|
wx.showToast({ |
|
title: res.msg, |
|
icon: 'none', |
|
duration: 2000 |
|
}) |
|
} |
|
}) |
|
} |
|
}, |
|
/** |
|
* 生命周期函数--监听页面初次渲染完成 |
|
*/ |
|
onReady: function() { |
|
|
|
}, |
|
|
|
/** |
|
* 生命周期函数--监听页面显示 |
|
*/ |
|
onShow: function() { |
|
|
|
}, |
|
|
|
/** |
|
* 生命周期函数--监听页面隐藏 |
|
*/ |
|
onHide: function() { |
|
|
|
}, |
|
|
|
/** |
|
* 生命周期函数--监听页面卸载 |
|
*/ |
|
onUnload: function() { |
|
|
|
}, |
|
|
|
/** |
|
* 页面相关事件处理函数--监听用户下拉动作 |
|
*/ |
|
onPullDownRefresh: function() { |
|
|
|
}, |
|
|
|
/** |
|
* 页面上拉触底事件的处理函数 |
|
*/ |
|
onReachBottom: function() { |
|
|
|
}, |
|
|
|
/** |
|
* 用户点击右上角分享 |
|
*/ |
|
onShareAppMessage: function() { |
|
|
|
} |
|
}) |