|
|
@@ -0,0 +1,79 @@
|
|
|
+// components/popup-user-auth/popup-user-auth.ts
|
|
|
+import { openPrivacyContract } from "../../lib/wx/open-api";
|
|
|
+import { usePhoneNumber } from "../../lib/use/use-phone";
|
|
|
+import { createPhoneRegister } from "../../lib/request/common";
|
|
|
+let submitting = false;
|
|
|
+Component({
|
|
|
+ properties: {
|
|
|
+ show: { type: Boolean, value: false },
|
|
|
+ overlay: { type: Boolean, value: true },
|
|
|
+ scene: { type: String, value: '' },
|
|
|
+ },
|
|
|
+ data: {
|
|
|
+ visible: false,
|
|
|
+ title: '完善信息',
|
|
|
+ privacyContract: { agree: false, name: "《隐私政策》", show: false },
|
|
|
+
|
|
|
+ loading: false,
|
|
|
+ submitting: false,
|
|
|
+ model: { } as { phone?: string },
|
|
|
+ },
|
|
|
+ observers: {
|
|
|
+ 'show'(visible) {
|
|
|
+ this.setData({ visible })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ getPhoneNumberHandle(event: WechatMiniprogram.ButtonGetPhoneNumber) {
|
|
|
+ this.setData({ loading: true });
|
|
|
+ const { getPhoneNumber } = usePhoneNumber();
|
|
|
+ getPhoneNumber(event, (value) => {
|
|
|
+ this.setData({ "model.phone": value, loading: false })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ openPrivacyContract: openPrivacyContract,
|
|
|
+ onPrivacySetting({ detail }: { detail: WechatMiniprogram.GetPrivacySettingSuccessCallbackResult; }) {
|
|
|
+ this.setData({
|
|
|
+ "privacyContract.name": detail.privacyContractName,
|
|
|
+ // 'privacyContract.agree': !detail.needAuthorization,
|
|
|
+ });
|
|
|
+ },
|
|
|
+ onAgreeChange(event: any) {
|
|
|
+ const agree = event?.detail?.checked;
|
|
|
+ if (agree) this.setData({ "privacyContract.show": true });
|
|
|
+ else this.setData({ "privacyContract.agree": agree });
|
|
|
+ },
|
|
|
+ onAgree() {
|
|
|
+ this.setData({ "privacyContract.agree": true });
|
|
|
+ },
|
|
|
+
|
|
|
+ async onSubmit(event: WechatMiniprogram.FormSubmit) {
|
|
|
+ if (this.data.submitting || submitting) return;
|
|
|
+ submitting = true;
|
|
|
+ try {
|
|
|
+ const data = { ...this.data.model, ...event.detail.value, scene: this.data.scene };
|
|
|
+
|
|
|
+ if (!data.agemust) data.agemust = this.data.privacyContract.agree ? "Y" : "N";
|
|
|
+ if (data.agemust === "N") {
|
|
|
+ this.setData({ "privacyContract.show": true });
|
|
|
+ throw `请阅读并同意${this.data.privacyContract.name}`;
|
|
|
+ }
|
|
|
+ if (!data.phone) throw `请获取手机号码`;
|
|
|
+
|
|
|
+ this.setData({ "submitting": submitting });
|
|
|
+ const { patientId } = await createPhoneRegister(<any>data);
|
|
|
+ wx.setStorageSync("patientId", patientId);
|
|
|
+ this.setData({ 'visible': false });
|
|
|
+ this.triggerEvent('register', { patientId });
|
|
|
+ } catch (error) {
|
|
|
+ if (typeof error === 'string') this.triggerEvent('message', { type: 'warning', content: error });
|
|
|
+ else if (error.errMsg) {
|
|
|
+ this.triggerEvent('message', { type: 'error', content: error.errMsg });
|
|
|
+ this.setData({ "model.phone": '', loading: false })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ submitting = false;
|
|
|
+ this.setData({ "submitting": submitting });
|
|
|
+ },
|
|
|
+ }
|
|
|
+})
|