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

197 lines
3.9 KiB

const app = getApp<IAppOption>()
let timer = null as null | number
2 months ago
Page({
data: {
2 months ago
popupShow: false,
popupType: 'popup4', // 登录失败弹窗
popupParams: {
close: true,
} as any,
2 months ago
showTel: false,
2 months ago
mobile: '',
code: '',
2 months ago
codeText: '发送验证码',
2 months ago
2 months ago
check1: false,
2 months ago
},
2 months ago
onLoad() {},
2 months ago
getCode() {
if (timer) return
const mobile = this.data.mobile
2 months ago
if (!mobile) {
wx.showToast({
title: '手机号不能为空',
icon: 'none',
})
return
2 months ago
}
// 验证手机号
if (!/^1[3-9,]\d{9}$/.test(mobile)) {
wx.showToast({
title: '手机号格式不正确',
icon: 'none',
})
return
2 months ago
}
wx.ajax({
method: 'POST',
2 months ago
url: '?r=xd/login/send-verify-code',
2 months ago
data: {
mobile,
},
2 months ago
}).then((_res) => {
2 months ago
wx.showToast({
icon: 'none',
title: '验证码已发送~',
})
let time = 60
2 months ago
timer = setInterval(() => {
time--
2 months ago
this.setData({
codeText: `${time}s后重新发送`,
})
2 months ago
if (time <= 0) {
clearInterval(timer as number)
timer = null
2 months ago
this.setData({
codeText: '发送验证码',
})
2 months ago
}
}, 1000)
})
2 months ago
},
handleCheck() {
this.setData({
check1: !this.data.check1,
})
2 months ago
},
2 months ago
handleDocRule() {
const { check1 } = this.data
2 months ago
return new Promise((resolve) => {
2 months ago
if (check1) {
return resolve(true)
2 months ago
}
2 months ago
wx.showToast({
2 months ago
title: '请同意相关协议',
2 months ago
icon: 'none',
})
})
2 months ago
},
async handleSubmit() {
await this.handleDocRule()
const { mobile, code } = this.data
2 months ago
if (!mobile) {
wx.showToast({
title: '请输入手机号',
icon: 'none',
})
return
2 months ago
}
if (!code) {
wx.showToast({
title: '请输入验证码',
icon: 'none',
})
return
2 months ago
}
2 months ago
wx.ajax({
method: 'POST',
2 months ago
url: '?r=xd/login/reg-login',
2 months ago
data: {
mobile,
code,
},
2 months ago
showMsg: false,
})
.then(() => {
this.submitCallback()
2 months ago
})
2 months ago
.catch((err) => {
if (err.data.code == 100) {
this.handleShowPopup()
2 months ago
} else if (err.data.msg) {
wx.showToast({
title: err.data.msg,
icon: 'none',
})
2 months ago
}
})
2 months ago
},
2 months ago
handleWxSubmit(e: WechatMiniprogram.CustomEvent) {
const { iv, encryptedData } = e.detail
2 months ago
if (iv && encryptedData) {
wx.ajax({
method: 'POST',
2 months ago
url: '?r=xd/login/wx-reg-login',
2 months ago
data: {
iv: encodeURIComponent(iv),
encryptedData: encodeURIComponent(encryptedData),
},
2 months ago
showMsg: false,
})
.then(() => {
this.submitCallback()
2 months ago
})
2 months ago
.catch((err) => {
if (err.data.code == 100) {
this.handleShowPopup()
2 months ago
} else if (err.data.msg) {
wx.showToast({
title: err.data.msg,
icon: 'none',
})
2 months ago
}
})
2 months ago
}
},
submitCallback() {
app.updateLoginInfo((res) => {
if (res.isLogin == 1) {
if (res.loginType == 2) {
wx.reLaunch({
url: '/pages/home/index',
})
} else {
this.handleShowPopup()
}
2 months ago
} else {
this.handleShowPopup()
2 months ago
}
})
2 months ago
},
handlePatient() {
wx.reLaunch({
url: '/patient/pages/login/index',
})
},
2 months ago
handleShowPopup() {
this.setData({
popupShow: true,
popupType: 'popup4',
popupParams: {
close: true,
},
})
2 months ago
},
2 months ago
handleShowTel() {
2 months ago
this.setData({
2 months ago
showTel: !this.data.showTel,
})
2 months ago
},
handleLink() {
wx.navigateTo({
url: '/doc/pages/doc1/index',
})
2 months ago
},
2 months ago
handlePopupCancel() {
this.setData({
popupShow: false,
})
2 months ago
},
})
2 months ago
export {}