| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- import DictionariesBehavior from "../../../../core/behavior/dictionaries.behavior";
- import PageContainerBehavior from "../../../../core/behavior/page-container.behavior";
- import tickleBehavior, {
- getTickleContext,
- } from "../../../../core/behavior/tickle.behavior";
- import { openPrivacyContract } from "../../../../lib/wx/open-api";
- // module/user/pages/user-certification/user-certification.ts
- import {
- createUserInfoMethod,
- verifyCardnoMethod,
- createPhoneRegister,
- } from "../../request";
- import { usePhoneNumber } from "../../../../lib/use/use-phone";
- Component({
- behaviors: [PageContainerBehavior, DictionariesBehavior, tickleBehavior],
- lifetimes: {
- attached() {
- const channel = this.getOpenerEventChannel();
- channel.on("navigateBack", (data) => {
- this.setData(data);
- });
- const { getPhoneNumber, updateStatus, updateValue } = usePhoneNumber();
- this.getPhoneNumber = <any>getPhoneNumber;
- updateStatus((status) => this.setData({ loading: status === "loading" }));
- updateValue((value) => this.setData({ "model.phone": value }));
- },
- },
- properties: {
- hide: { type: Boolean, value: false },
- type: { type: String, value: "" },
- },
- data: {
- loading: false,
- verifying: false,
- submitting: false,
- model: {} as AnyObject,
- name: "",
- cardno: "",
- age: "",
- sex: "",
- privacyContract: { agree: false, name: "《隐私政策》", show: false },
- },
- /**
- * 组件的方法列表
- */
- methods: {
- cancel() {
- wx.navigateBack();
- },
- getPhoneNumber(event: WechatMiniprogram.ButtonGetPhoneNumber) {
- if (wx.getSystemInfoSync().platform === "devtools") {
- wx.showToast({ title: "请在真机上测试", icon: "none" });
- return;
- }
- const { getPhoneNumber, updateValue } = usePhoneNumber();
- getPhoneNumber(event);
- updateValue((value) => this.setData({ "model.phone": value }));
- },
- openPrivacyContract: openPrivacyContract,
- onPrivacySetting({
- detail,
- }: {
- detail: WechatMiniprogram.GetPrivacySettingSuccessCallbackResult;
- }) {
- this.setData({
- "privacyContract.name": detail.privacyContractName,
- // 'privacyContract.agree': !detail.needAuthorization,
- });
- },
- onAgreeChange(event: any) {
- console.log(event);
- const agree = event?.detail?.checked;
- if (agree) this.setData({ "privacyContract.show": true });
- else this.setData({ "privacyContract.agree": agree });
- },
- onAgree() {
- const submitBtn = this.selectComponent("#submitBtn");
- console.log("onAgree-->");
- this.setData({ "privacyContract.agree": true });
- if (submitBtn) submitBtn.resetState();
- },
- async verifyCardno(event: WechatMiniprogram.InputConfirm) {
- const value = event.detail.value;
- if (value.length !== 18) {
- wx.showToast({ title: "请输入正确的身份证号", icon: "none" });
- } else {
- this.setData({ verifying: true });
- try {
- const data = await verifyCardnoMethod(value);
- this.setData({ age: data.age, sex: data.sex });
- } catch (error) {
- this.setData({ cardno: "", age: "", sex: "" });
- wx.showToast({ title: error.errMsg, icon: "error" });
- }
- this.setData({ verifying: false });
- }
- },
- async onSubmit(event: WechatMiniprogram.FormSubmit) {
- if (this.data.submitting) return;
- this.setData({ submitting: true });
- const data = { ...this.data.model, ...event.detail.value };
- data.phone = this.data.model.phone;
- const submitBtn = this.selectComponent("#submitBtn");
- if (!data.phone) {
- if (submitBtn) submitBtn.resetState();
- return getTickleContext.call(this).showWarnMessage("请获取手机号码");
- }
- if (!data.agemust) {
- data.agemust = this.data.privacyContract.agree ? "Y" : "N";
- }
- if (data.agemust === "N") {
- if (submitBtn) submitBtn.resetState();
- this.setData({ "privacyContract.show": true });
- return wx.showToast({
- title: `请阅读并同意${this.data.privacyContract.name}`,
- icon: "none",
- });
- }
- wx.showLoading({ title: "保存中" });
- try {
- const { patientId } = await createPhoneRegister(<any>data);
- wx.setStorageSync("patientId", patientId);
- // 回到相应的页面
- if (this.data.type === "home") {
- wx.navigateTo({
- url: "/pages/home/home",
- });
- } else {
- wx.navigateBack();
- }
- } catch (error) {
- // 请求失败时恢复按钮状态
- if (submitBtn) {
- submitBtn.resetState();
- }
- getTickleContext.call(this).showErrorMessage(error.errMsg);
- } finally {
- this.setData({ submitting: false });
- wx.hideLoading();
- }
- },
- },
- });
|