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.
104 lines
3.1 KiB
104 lines
3.1 KiB
// pages/home/mobile/index.js
|
|
import Scene from '../../index/scene'
|
|
import { postCaptcha, modifyMobile } from '../../../api/user'
|
|
const util = require('../../../utils/util')
|
|
const app = getApp()
|
|
|
|
Scene({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
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 })
|
|
postCaptcha({ verifiableAccount: this.data.form.mobile, verifiableAccountType: 1, purpose: 3 }).then(result => {
|
|
wx.hideLoading()
|
|
this.setData({ codeEnable: true })
|
|
util.showToast('验证码已经发送')
|
|
this.countDown = this.countDown || this.selectComponent('.count-down')
|
|
this.countDown.reset()
|
|
this.countDown.start()
|
|
}).catch(error => {
|
|
wx.hideLoading()
|
|
util.showToast(error)
|
|
})
|
|
},
|
|
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 })
|
|
this.data.requesting = true
|
|
modifyMobile({ mobile: this.data.form.mobile, captcha: this.data.form.captcha }).then(res => {
|
|
wx.hideLoading()
|
|
app.userInfo.mobile = this.data.form.mobile
|
|
util.showBackToast('修改手机号码成功')
|
|
}).catch(error => {
|
|
wx.hideLoading()
|
|
this.data.requesting = false
|
|
util.showToast(error)
|
|
})
|
|
}
|
|
})
|