// pages/forget/forget.js Page({ /** * 页面的初始数据 */ data: { userName: null, phone: null, email: null, checkPass: false, errorMsg: '' }, goNext(e){ let that = this; let { userName: loginName, phone, email } = this.data; wx.request({ url: getApp().globalData.postHeadAgreement + '/restapi/wechat/forget', data: { loginName, phonenumber: phone, email }, method: 'POST', success(res) { //console.log(res); //console.log(res.data.code == 1); if (res.data.code == 1) { that.setData({ errorMsg: res.data.msg }); } else { //跳转到下一步 let url = `/pages/reset_password/reset_password?loginName=${loginName}`; wx.redirectTo({ url }); } } }); }, inputAccount(e) { this.setData({ userName: e.detail.value }); this.checkAll(); }, inputPhone(e) { this.setData({ phone: e.detail.value }); this.checkAll(); }, inputEmail(e) { this.setData({ email: e.detail.value }); this.checkAll(); }, checkPhone() { if (!(/^1[3456789]\d{9}$/.test(this.data.phone))) { return false; } return true; }, checkMail() { if (!(/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/.test(this.data.email))) { return false; } return true; }, checkAll() { if (!this.data.userName || !this.data.userName.replace(/(^\s*)|(\s*$)/g, "")) { this.setData({ errorMsg: '账号不能为空' }); this.setData({ checkPass: false }); return; } else { this.setData({ errorMsg: '' }); } if (!this.checkPhone()) { this.setData({ errorMsg: '手机号输入有误,请重新输入' }); this.setData({ checkPass: false }); return; } else { this.setData({ errorMsg: '' }); } if (!this.checkMail()) { this.setData({ errorMsg: '邮箱输入有误,请重新输入' }); this.setData({ checkPass: false }); return; } else { this.setData({ errorMsg: '' }); } this.setData({ checkPass: true }); }, /** * 生命周期函数--监听页面加载 */ onLoad: function(options) { }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function() { }, /** * 生命周期函数--监听页面显示 */ onShow: function() { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function() { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function() { }, /** * 用户点击右上角分享 */ onShareAppMessage: function() { } })