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.0 KiB
142 lines
3.0 KiB
const app = getApp<IAppOption>() |
|
let timer = null as null | number |
|
|
|
Page({ |
|
data: { |
|
showTel: false, |
|
mobile: '', |
|
code: '', |
|
|
|
codeText: '发送验证码', |
|
|
|
check1: false, |
|
check2: false, |
|
}, |
|
onLoad() { |
|
app.waitLogin().then(() => { |
|
app.mpBehavior({ PageName: 'PG_DOCLOG' }) |
|
}) |
|
}, |
|
onUnload() { |
|
if (timer) { |
|
clearInterval(timer as number) |
|
timer = null |
|
} |
|
}, |
|
getCode() { |
|
if (timer) return |
|
const mobile = this.data.mobile |
|
if (!mobile) { |
|
wx.showToast({ |
|
title: '手机号不能为空', |
|
icon: 'none', |
|
}) |
|
return |
|
} |
|
// 验证手机号 |
|
if (!/^1[3-9,]\d{9}$/.test(mobile)) { |
|
wx.showToast({ |
|
title: '手机号格式不正确', |
|
icon: 'none', |
|
}) |
|
return |
|
} |
|
wx.ajax({ |
|
method: 'POST', |
|
url: '?r=wtx/doctor/login/send-verify-code', |
|
data: { |
|
mobile, |
|
}, |
|
}).then((_res) => { |
|
wx.showToast({ |
|
icon: 'none', |
|
title: '验证码已发送~', |
|
}) |
|
let time = 60 |
|
timer = setInterval(() => { |
|
time-- |
|
this.setData({ |
|
codeText: `${time}s后重新发送`, |
|
}) |
|
if (time <= 0) { |
|
clearInterval(timer as number) |
|
timer = null |
|
this.setData({ |
|
codeText: '发送验证码', |
|
}) |
|
} |
|
}, 1000) |
|
}) |
|
}, |
|
handleDocRule() { |
|
const { check1, check2 } = this.data |
|
app.mpBehavior({ PageName: 'BTN_DOCMOBILEONECLICKLOGIN' }) |
|
return new Promise((resolve) => { |
|
if (check1 && check2) { |
|
return resolve(true) |
|
} |
|
wx.showToast({ |
|
title: '请同意相关协议', |
|
icon: 'none', |
|
}) |
|
}) |
|
}, |
|
async handleSubmit() { |
|
await this.handleDocRule() |
|
const { mobile, code } = this.data |
|
app.mpBehavior({ PageName: 'BTN_DOCLOGINCLICK' }) |
|
wx.ajax({ |
|
method: 'POST', |
|
url: '?r=wtx/doctor/login/reg-login', |
|
data: { |
|
mobile, |
|
code, |
|
}, |
|
}).then((_res) => { |
|
this.submitCallback() |
|
}) |
|
}, |
|
handleWxSubmit(e: WechatMiniprogram.CustomEvent) { |
|
app.mpBehavior({ PageName: 'BTN_DOCMOBILEONECLICKLOGIN' }) |
|
const { iv, encryptedData } = e.detail |
|
if (iv && encryptedData) { |
|
wx.ajax({ |
|
method: 'POST', |
|
url: '?r=wtx/doctor/login/wx-reg-login', |
|
data: { |
|
iv: encodeURIComponent(iv), |
|
encryptedData: encodeURIComponent(encryptedData), |
|
}, |
|
}).then((_res) => { |
|
this.submitCallback() |
|
}) |
|
} |
|
}, |
|
submitCallback() { |
|
app.updateLoginInfo(() => { |
|
wx.reLaunch({ |
|
url: `/doctor/pages/index/index`, |
|
}) |
|
}) |
|
}, |
|
handleShowTel() { |
|
this.setData({ |
|
showTel: !this.data.showTel, |
|
}) |
|
}, |
|
handleLink(e: any) { |
|
const { url } = e.currentTarget.dataset |
|
wx.navigateTo({ |
|
url, |
|
}) |
|
}, |
|
handleCheck(e) { |
|
const { name } = e.currentTarget.dataset |
|
app.mpBehavior({ PageName: name }) |
|
}, |
|
handleBack() { |
|
wx.navigateBack() |
|
}, |
|
}) |
|
|
|
export {}
|
|
|