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.
175 lines
4.3 KiB
175 lines
4.3 KiB
const app = getApp<IAppOption>(); |
|
let timer = null as null | number; |
|
|
|
Page({ |
|
data: { |
|
mobile: '', |
|
code: '', |
|
|
|
check1: false, |
|
check2: false, |
|
|
|
codeText: '发送验证码', |
|
page: '', |
|
}, |
|
onLoad(options: any) { |
|
this.setData({ |
|
page: options.page, |
|
}); |
|
app.zdWaitLogin({ isReg: false, loginPage: true }).then(() => { |
|
app.zdMpBehavior({ PageName: 'PG_PATIENTLOGIN' }); |
|
}); |
|
}, |
|
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=xd/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); |
|
}); |
|
}, |
|
handleSubmit() { |
|
app.zdMpBehavior({ PageName: 'BTN_PATIENTLOGIN' }); |
|
const { mobile, code } = this.data; |
|
const { registrationSource, registChannel, regBusinessId } = app.globalData; |
|
wx.ajax({ |
|
method: 'POST', |
|
url: '?r=xd/login/reg-login', |
|
data: { |
|
mobile, |
|
code, |
|
registrationSource, |
|
registChannel, |
|
regBusinessId, |
|
}, |
|
}).then((_res) => { |
|
this.submitCallback(); |
|
}); |
|
}, |
|
handleWxSubmit(e: WechatMiniprogram.CustomEvent) { |
|
app.zdMpBehavior({ PageName: 'BTN_PATIENTQUICKPATIENTLOGIN' }); |
|
const { iv, encryptedData } = e.detail; |
|
const { registrationSource, registChannel, regBusinessId } = app.globalData; |
|
if (iv && encryptedData) { |
|
wx.ajax({ |
|
method: 'POST', |
|
url: '?r=xd/login/wx-reg-login', |
|
data: { |
|
iv: encodeURIComponent(iv), |
|
encryptedData: encodeURIComponent(encryptedData), |
|
registrationSource, |
|
registChannel, |
|
regBusinessId, |
|
}, |
|
}).then((_res) => { |
|
this.submitCallback(); |
|
}); |
|
} |
|
}, |
|
handleWxCheck() { |
|
wx.showToast({ |
|
icon: 'none', |
|
title: '请先同意隐私政策', |
|
}); |
|
}, |
|
submitCallback() { |
|
const { page } = this.data; |
|
app.globalData.loginType = 1; |
|
app.globalData.isLogin = 1; |
|
app.getZdUserInfo(this, true, (zdUserInfo) => { |
|
// 1-空白用户,2-注册用户,3-疾病患者,4-用药患者 |
|
const { PatientId, AuditStatus, UserType } = zdUserInfo; |
|
const backPage = app.globalData.backPage; |
|
let urlKey = ''; |
|
if (UserType >= 3) { |
|
urlKey = 'home'; |
|
} else if (!PatientId) { |
|
urlKey = 'agreement'; |
|
} else if (AuditStatus == 1 && typeof backPage === 'string' && backPage.includes('liveResult')) { |
|
urlKey = 'home'; |
|
} else if ([0, 2].includes(AuditStatus)) { |
|
urlKey = 'enterInfo'; |
|
} |
|
const navUrl = { |
|
home: backPage || '/patient/pages/index/index', |
|
agreement: `/patient/pages/enterInfo/index`, |
|
enterInfo: '/patient/pages/enterInfo/index', |
|
}[urlKey]; |
|
|
|
if (['agreement', 'enterInfo'].includes(urlKey)) { |
|
wx.navigateTo({ |
|
url: navUrl, |
|
}); |
|
} else { |
|
wx.reLaunch({ |
|
url: navUrl, |
|
}); |
|
} |
|
}); |
|
}, |
|
handleVisitors() { |
|
app.zdMpBehavior({ PageName: 'BTN_PATIENTLOOKAROUND' }); |
|
app.globalData.anyWhere = true; |
|
app.globalData.first = true; |
|
app.globalData.loginType = 1; |
|
wx.reLaunch({ |
|
url: '/patient/pages/index/index', |
|
}); |
|
}, |
|
handleDoctor() { |
|
wx.reLaunch({ |
|
url: '/doctor/patient/pages/d_login/index', |
|
}); |
|
}, |
|
handleLink(e: any) { |
|
const { url } = e.currentTarget.dataset; |
|
wx.navigateTo({ |
|
url, |
|
}); |
|
}, |
|
handleCheck(e: any) { |
|
const { key } = e.currentTarget.dataset; |
|
this.setData({ |
|
[key]: !this.data[key], |
|
}); |
|
}, |
|
}); |
|
|
|
export {};
|
|
|