// pages/home/mobile/index.js const util = require('../../../utils/util') const app = getApp() Page({ /** * 页面的初始数据 */ data: { mobileEnable: false, codeEnable: true, loginEnable: true, second: '获取验证码', form: { accountType: 'MOBILE', mobile: null, captcha: null }, mobile: null }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ mobile: app.userInfo.mobile }) }, bindInput: function (e) { this.data.form[e.target.id] = e.detail.value if ('mobile' == e.target.id) { if ((/^1\d{10}$/.test(e.detail.value)) && e.detail.value.length == 11) { this.setData({ mobileEnable: true }) } } if ((/^1\d{10}$/.test(this.data.form.mobile)) && this.data.form.mobile.length == 11) { if (!util.isEmpty(this.data.form.captcha)) { this.setData({ loginEnable: false }) } else { this.setData({ loginEnable: true }) } } else { this.setData({ loginEnable: true }) } }, fetchCode: function () { if (!(/^1\d{10}$/.test(this.data.form.mobile)) || this.data.form.mobile.length < 11) { utill.showToast('请输入11位手机号码') return } if (this.data.form.mobile == this.data.mobile) { util.showToast('新手机号码不能和当前号码一致!') return } wx.showLoading({ title: '正在获取', mask: true }) var form = {account: this.data.form.mobile, accountType: 'MOBILE', purpose: 'RECYCLE_CLIENT_UPDATE_MOBILE' } }, onChange: function(e) { this.setData({ second: e.detail.seconds + ' 秒 ' }) }, onFinished: function(){ this.setData({ second: '重新获取验证码', codeEnable: true }) }, submitForm: function () { if (this.data.requesting) { return } if (!(/^1\d{10}$/.test(this.data.form.mobile)) || this.data.form.mobile.length < 11) { utill.showToast('请输入11位手机号码') return } if (this.data.form.mobile == this.data.mobile) { util.showToast('新手机号码不能和当前号码一致!') return } if (util.isEmpty(this.data.form.captcha)) { util.showToast('请输入验证码') return } wx.showLoading({ title: '处理中', mask: true }) var data = { mobile: this.data.form.mobile, captcha: this.data.form.captcha } this.data.requesting = true // /front/customer/mobile修改手机号码 // request.post('/cloud-print-user-center/user/modify/mobile', data).then(res => { // wx.hideLoading() // app.accountInfo.mobile = this.data.form.mobile // util.showBackToast('修改成功') // }).catch(error => { // wx.hideLoading() // this.data.requesting = false // util.showToast(error) // }) } })