纸通宝SAAS仓库
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

// pages/home/password/index.js
import { generateCode, postCaptcha } from "../../../api/user"
import { getCustomerInfo, registeCustomer } from "../../../api/saas"
const util = require('../../../utils/util')
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
second: '获取验证码',
codeEnable: false,
form: {
mobile: null,
captcha: null,
accountType: 2
},
loging: false,
customerInfo: null
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
if(options.id){
wx.showLoading({ title: '正在获取', mask: true })
getCustomerInfo(options.id).then(result => {
this.setData({ customerInfo: result.data, ['form.mobile']: result.data.mobile })
const params = { id: 6 }
params.metaData = {
factoryId: app.userInfo.factoryId,
factoryName: app.userInfo.factoryName,
factoryCustomerId: result.data.id,
factoryCustomerName: result.data.name,
factoryCustomerMobile: result.data.mobile
}
generateCode(params).then(result => {
this.setData({ base64: result.data })
wx.hideLoading()
}).catch(err => {
wx.hideLoading()
})
}).catch(err => {
wx.hideLoading()
util.showToast(err)
})
}
},
bindForm: function (e) {
this.data.form[e.target.id] = e.detail.value
},
fetchCode: function () {
if (util.isEmpty(this.data.form.mobile)) {
util.showToast('请输入手机号码')
return
}
if (this.second && this.second.interval) return !1
wx.showLoading({ title: '正在获取', mask: true })
postCaptcha({ verifiableAccount: this.data.form.mobile, verifiableAccountType: 1, purpose: 1 }).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: false })
},
submitForm: function () {
if (this.data.loging || !this.data.customerInfo) {
return
}
if (util.isEmpty(this.data.form.mobile)) {
util.showToast('请输入客户手机号码')
return
}
if (util.isEmpty(this.data.form.captcha)) {
util.showToast('请输入验证码')
return
}
wx.showLoading({ title: '处理中', mask: true })
this.setData({ loging: true })
this.data.form.account = this.data.form.mobile
this.data.form.factorycustomerId = this.data.customerInfo.id
this.data.form.factoryId = app.userInfo.factoryId
registeCustomer(this.data.form).then(result => {
util.showBackToast('客户注册成功')
}).catch(error => {
wx.hideLoading()
util.showToast(error)
this.setData({ loging: false })
})
}
})