信达小程序
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.

124 lines
2.5 KiB

2 weeks ago
const app = getApp<IAppOption>()
let timer = null as null | number
3 weeks ago
Page({
data: {
2 weeks ago
showTel: false,
3 weeks ago
mobile: '',
code: '',
2 weeks ago
codeText: '发送验证码',
3 weeks ago
2 weeks ago
check1: false,
check2: false,
check3: false,
3 weeks ago
},
2 weeks ago
onLoad() {},
3 weeks ago
getCode() {
2 weeks ago
if (timer) return
const mobile = this.data.mobile
3 weeks ago
if (!mobile) {
wx.showToast({
title: '手机号不能为空',
icon: 'none',
2 weeks ago
})
return
3 weeks ago
}
// 验证手机号
if (!/^1[3-9,]\d{9}$/.test(mobile)) {
wx.showToast({
title: '手机号格式不正确',
icon: 'none',
2 weeks ago
})
return
3 weeks ago
}
wx.ajax({
method: 'POST',
2 weeks ago
url: '?r=wtx/login/send-verify-code',
3 weeks ago
data: {
mobile,
},
2 weeks ago
}).then((_res) => {
3 weeks ago
wx.showToast({
icon: 'none',
title: '验证码已发送~',
2 weeks ago
})
let time = 60
3 weeks ago
timer = setInterval(() => {
2 weeks ago
time--
3 weeks ago
this.setData({
codeText: `${time}s后重新发送`,
2 weeks ago
})
3 weeks ago
if (time <= 0) {
2 weeks ago
clearInterval(timer as number)
timer = null
3 weeks ago
this.setData({
codeText: '发送验证码',
2 weeks ago
})
3 weeks ago
}
2 weeks ago
}, 1000)
})
3 weeks ago
},
2 weeks ago
handleDocRule() {
const { check1, check2, check3 } = this.data
return new Promise((resolve) => {
if (check1 && check2 && check3) {
return resolve(true)
}
3 weeks ago
wx.showToast({
2 weeks ago
title: '请同意相关协议',
3 weeks ago
icon: 'none',
2 weeks ago
})
})
},
async handleSubmit() {
await this.handleDocRule()
const { mobile, code } = this.data
3 weeks ago
wx.ajax({
method: 'POST',
2 weeks ago
url: '?r=wtx/login/reg-login',
3 weeks ago
data: {
mobile,
code,
},
2 weeks ago
}).then((_res) => {
this.submitCallback()
})
3 weeks ago
},
2 weeks ago
handleWxSubmit(e: WechatMiniprogram.CustomEvent) {
const { iv, encryptedData } = e.detail
3 weeks ago
if (iv && encryptedData) {
wx.ajax({
method: 'POST',
2 weeks ago
url: '?r=wtx/login/wx-reg-login',
3 weeks ago
data: {
iv: encodeURIComponent(iv),
encryptedData: encodeURIComponent(encryptedData),
},
2 weeks ago
}).then((_res) => {
this.submitCallback()
})
3 weeks ago
}
},
submitCallback() {
2 weeks ago
app.getUserInfo(2).then((res) => {
if (res.PatientId) {
wx.reLaunch({
url: `/patient/pages/index/index`,
})
} else {
wx.navigateTo({
url: `/patient/pages/entryInfo/index?aid=${res.applyIntentionId}`,
})
}
})
3 weeks ago
},
2 weeks ago
handleShowTel() {
3 weeks ago
this.setData({
2 weeks ago
showTel: !this.data.showTel,
})
3 weeks ago
},
2 weeks ago
})
3 weeks ago
2 weeks ago
export {}