const app = getApp(); let timer: number | null = 0; Page({ data: { show: true, menuButtonInfo: {}, mobile: "", code: "", protool: false, codeText: "发送验证码", }, onLoad() {}, 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=takeda/login/send-verify-code", data: { mobile, }, }).then(() => { 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() { const { mobile, code, protool } = this.data; if (!protool) { this.handleNavProtool(); return; } if (!mobile) { wx.showToast({ title: "请输入手机号", icon: "none", }); return; } if (!code) { wx.showToast({ title: "请输入验证码", icon: "none", }); return; } wx.ajax({ method: "POST", url: "?r=takeda/login/reg-login", data: { mobile, code, }, }).then((res) => { this.submitCallback(res); }); }, handleWxSubmit(e: any) { const { protool } = this.data; const { iv, encryptedData } = e.detail; if (!protool) { return; } if (iv && encryptedData) { wx.ajax({ method: "POST", url: "?r=takeda/login/wx-reg-login", data: { iv: encodeURIComponent(iv), encryptedData: encodeURIComponent(encryptedData), }, }).then((res) => { this.submitCallback(res); }); } }, submitCallback(res) { app.globalData.isLogin = 1; app.globalData.doctorId = res.doctorId; app.waitLogin().then(() => { wx.reLaunch({ url: "/pages/home/index", }); }); }, handleProtool() { if (this.data.protool) { this.setData({ protool: false, }); } else { this.setData({ protool: false, }); wx.navigateTo({ url: "/module1/pages/loginProtool/index" }); } }, handleNavProtool(e) { const phone = e?.currentTarget?.dataset?.phone; wx.navigateTo({ url: `/module1/pages/loginProtool/index?phone=${phone}` }); }, handleTopic() {}, handleCancelTopic() { this.setData({ show: false, }); }, }); export {};