// pages/accountSettings/accountSettings.js var http = require("../../utils/http.js"); var util = require('../../utils/util.js'); Page({ /** * 页面的初始数据 */ data: { // username: '', password: '', phoneNumber: '', countryCode: '', //区号 confirmPassword: '', //确认密码 // 验证码相关 show: true, count: '', timer: null, hadGotCode: false, //是否已经点击了获取验证码 validCode: '', }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { }, /** * 获取用户手机号码 */ // getPhoneNumber: function (e) { // wx.showLoading(); // // 参数e是绑定的授权方法自动传入过来的, 主要是为了拿到vi和encryptedData值从后台换取用户联系方式 // var iv = e.detail.iv; // var encryptedData = e.detail.encryptedData; // //调用后台接口获取用户手机号码 // var params = { // url: "/p/user/getPhoneNumber", // method: "GET", // data: { // encryptedData: encryptedData, // ivStr: iv, // }, // callBack: (res) => { // wx.hideLoading(); // this.setData({ // phoneNumber: res.phoneNumber, // countryCode: res.countryCode // }) // console.log(this.data.phoneNumber) // } // }; // http.request(params); // }, /** * 获取验证码 */ getValidCode: function () { if (!util.checkPhoneNumber(this.data.phoneNumber) || this.data.phoneNumber.length != 11) { wx.showToast({ title: '请输入正确的手机号', icon: 'none' }); return } if (this.data.hadGotCode) { return } this.setData({ hadGotCode: true, }) console.log('获取验证码') var params = { url: "/p/shop/sendCode", method: "POST", data: { mobile: this.data.phoneNumber, }, callBack: res => { this.setData({ hadGotCode: true }) const timeCount = 60; if (!this.data.timer) { let count = timeCount let timer = this.data.timer setTimeout(() => { this.setData({ count: count, show: false }) }, 1000) timer = setInterval(() => { if (count > 0 && count <= timeCount) { this.setData({ count: count-- }) } else { clearInterval(timer); this.setData({ timer: null, show: true, hadGotCode: false }) } }, 1000) } } }; http.request(params); }, /** * 获取输入的手机号 */ bindMobileInt(e){ this.setData({ phoneNumber: e.detail.value }) }, /** * 获取输入的验证码的值 */ bindValidCodeInt: function (e) { this.setData({ validCode: e.detail.value }); }, /** * 获取登录密码数据 */ bindPasswordInt: function(e) { this.setData({ password: e.detail.value }) }, /** * 获取确认密码数据 */ bindConfirmPasswordInt: function (e) { this.setData({ confirmPassword: e.detail.value }) }, /** * 请求接口 */ accountSettingsSubmit:function() { if (!util.checkPhoneNumber(this.data.phoneNumber) || this.data.phoneNumber.length == 0){ wx.showToast({ title: '请输入正确的手机号', icon: 'none' }) } else if (this.data.validCode.length == 0) { wx.showToast({ title: '请输入验证码', icon: 'none' }); } else if (this.data.password.trim().length < 6 || this.data.password.trim().length > 12) { wx.showToast({ title: '登录密码格式不对', icon: 'none' }) } else if (this.data.confirmPassword.length == 0) { wx.showToast({ title: '请再次输入密码', icon: 'none' }) } else if (this.data.confirmPassword != this.data.password) { wx.showToast({ title: '两次密码输入不一致', icon: 'none' }) } else { wx.showLoading(); var params = { url: "/p/shop/saveUsernameAndPassword", method: "POST", data: { username: this.data.phoneNumber.trim(), password: this.data.password.trim(), code: this.data.validCode.trim() }, callBack: (res) => { wx.hideLoading(); wx.showToast({ icon: 'success', title: '设置成功!', duration: 2000, success: function () { wx.switchTab({ url: '/pages/user/user' }) } }) } }; http.request(params); } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })