纸通宝小程序
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.
 

142 lines
3.4 KiB

// pages/home/password/index.js
import { $wuxCountDown } from '../../../components/index'
const request = require('../../../utils/request'); //导入模块
const util = require('../../../utils/util');
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
second: null,
codeEnable: true,
pwdType: 'password',
pwd_icon: 'attention',
form: {
mobile: null,
password: null,
verifyCode: null
},
requesting: false,
mobile: ''
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({
mobile: app.globalData.userInfo.mobile
})
},
bindForm: function (e) {
this.data.form[e.target.id] = e.detail.value
},
changePwd: function (e) {
if (this.data.pwdType === 'password') {
this.setData({
pwdType: 'text'
})
this.setData({
pwd_icon: 'attentionforbid'
})
} else {
this.setData({
pwdType: 'password'
})
this.setData({
pwd_icon: 'attention'
})
}
},
fetchCode: function () {
if (util.isEmpty(this.data.form.newMobile)) {
util.showToast('请输入新手机号码!')
return
}
if (this.data.form.newMobile == this.data.mobile) {
util.showToast('新手机号码不能和当前号码一致!')
return
}
if (this.second && this.second.interval) return !1
wx.showLoading({
title: '正在获取',
mask: true
})
// /login/h5/mobile/send_sms_code 发送验证码
request.post('/recycle-service/send/captcha', {
account: this.data.form.newMobile,
accountType: 'MOBILE',
purpose: 'RECYCLE_CLIENT_UPDATE_MOBILE'
}).then(result => {
wx.hideLoading()
this.setData({
codeEnable: false
})
util.showToast('验证码已经发送')
this.wuxCountDown = new $wuxCountDown({
date: +(new Date) + 60000,
onEnd() {
this.setData({
second: '重新获取验证码',
codeEnable: true
})
},
render(date) {
const sec = this.leadingZeros(date.sec, 2) + ' 秒 '
date.sec !== 0 && this.setData({
second: sec,
})
},
})
}).catch(error => {
wx.hideLoading()
util.showToast(error)
})
},
submitForm: function () {
if (this.data.requesting) {
return
}
if (util.isEmpty(this.data.form.newMobile)) {
util.showToast('请输入新手机号码')
return
}
if (this.data.form.newMobile == this.data.mobile) {
util.showToast('新手机号码不能和当前号码一致!')
return
}
if (util.isEmpty(this.data.form.verifyCode)) {
util.showToast('请输入验证码')
return
}
wx.showLoading({
title: '处理中',
mask: true
})
var data = {
mobile: this.data.form.newMobile,
captcha: this.data.form.verifyCode
}
this.data.requesting = true
// /front/customer/mobile修改手机号码
request.post('/recycle-service/user/modify/mobile', data).then(res => {
wx.hideLoading()
app.globalData.userInfo.mobile = this.data.form.newMobile
util.showBackToast('更换成功')
}).catch(error => {
wx.hideLoading()
this.data.requesting = false
util.showToast(error)
})
},
onUnload: function(){
if(this.wuxCountDown){
this.wuxCountDown.stop()
this.wuxCountDown = null
}
}
})