WXL
21 小时以前 05c363fdd7ab04e3bd9a753e2c5d5bfff04d681c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
"use strict";
const common_vendor = require("../../common/vendor.js");
const _sfc_main = {
  __name: "add",
  setup(__props) {
    const idTypes = [
      { value: "macauId", label: "青岛居民身份证" },
      { value: "mainlandId", label: "内地居民身份证" },
      { value: "hkId", label: "香港居民身份证" },
      { value: "passport", label: "护照" },
      { value: "other", label: "其他证件" }
    ];
    const idTypeIndex = common_vendor.ref(0);
    const relationIndex = common_vendor.ref(-1);
    const idTypeLabels = common_vendor.computed(() => idTypes.map((item) => item.label));
    const relations = [
      { value: "self", label: "本人" },
      { value: "parent", label: "父母" },
      { value: "spouse", label: "配偶" },
      { value: "child", label: "子女" },
      { value: "grandparent", label: "祖父母" },
      { value: "sibling", label: "兄弟姐妹" },
      { value: "other", label: "其他" }
    ];
    const relationLabels = common_vendor.computed(() => relations.map((item) => item.label));
    const form = common_vendor.ref({
      name: "",
      idType: "macauId",
      // 默认选中青岛居民身份证
      idNumber: "",
      relation: "",
      cardNo: "",
      phone: "",
      verifyCode: "",
      isDefault: false
    });
    const cardOption = common_vendor.ref("bind");
    const countdown = common_vendor.ref(0);
    let timer = null;
    const idNumberError = common_vendor.ref("");
    const idNumberMaxLength = common_vendor.computed(() => {
      const type = idTypes[idTypeIndex.value].value;
      return type === "mainlandId" ? 18 : 20;
    });
    const idNumberPlaceholder = common_vendor.computed(() => {
      const type = idTypes[idTypeIndex.value].value;
      switch (type) {
        case "macauId":
          return "请输入8位青岛居民身份证号码";
        case "mainlandId":
          return "请输入18位内地居民身份证号码";
        case "hkId":
          return "请输入香港居民身份证号码";
        case "passport":
          return "请输入护照号码";
        default:
          return "请输入证件号码";
      }
    });
    const idNumberRules = {
      macauId: {
        pattern: /^[1-9]\d{7}$/,
        message: "请输入8位数字的青岛居民身份证号码"
      },
      mainlandId: {
        pattern: /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/,
        message: "请输入正确的内地居民身份证号码"
      },
      hkId: {
        pattern: /^[A-Z]{1,2}[0-9]{6}\([0-9A]\)$/,
        message: "请输入正确的香港居民身份证号码"
      }
    };
    const validateIdNumber = () => {
      if (!form.value.idNumber) {
        idNumberError.value = "请输入证件号码";
        return false;
      }
      const type = idTypes[idTypeIndex.value].value;
      const rule = idNumberRules[type];
      if (rule) {
        const reg = rule.pattern;
        if (!reg.test(form.value.idNumber)) {
          idNumberError.value = rule.message;
          return false;
        }
      }
      idNumberError.value = "";
      return true;
    };
    const validatePhone = (phone) => {
      const macauMobile = /^6\d{7}$/;
      const mainlandMobile = /^1[3-9]\d{9}$/;
      const hkMobile = /^[569]\d{7}$/;
      return macauMobile.test(phone) || mainlandMobile.test(phone) || hkMobile.test(phone);
    };
    const sendVerifyCode = () => {
      if (countdown.value > 0)
        return;
      if (!form.value.phone) {
        common_vendor.index.showToast({
          title: "请输入手机号码",
          icon: "none"
        });
        return;
      }
      if (!validatePhone(form.value.phone)) {
        common_vendor.index.showToast({
          title: "请输入正确的手机号码",
          icon: "none"
        });
        return;
      }
      countdown.value = 60;
      timer = setInterval(() => {
        countdown.value--;
        if (countdown.value <= 0) {
          clearInterval(timer);
          timer = null;
        }
      }, 1e3);
    };
    const validateCardNo = (cardNo) => {
      const kiangWuCard = /^KW\d{8}$/;
      const mustCard = /^MUST\d{6}$/;
      return kiangWuCard.test(cardNo) || mustCard.test(cardNo);
    };
    const onIdTypeChange = (e) => {
      const index = parseInt(e.detail.value);
      idTypeIndex.value = index;
      form.value.idType = idTypes[index].value;
      form.value.idNumber = "";
      idNumberError.value = "";
    };
    const onRelationChange = (e) => {
      const index = parseInt(e.detail.value);
      relationIndex.value = index;
      form.value.relation = relations[index].value;
    };
    const canSubmit = common_vendor.computed(() => {
      const { name, idNumber, relation, phone } = form.value;
      if (!name || !idNumber || !relation || !phone)
        return false;
      if (idNumberError.value)
        return false;
      if (cardOption.value === "bind" && !form.value.cardNo)
        return false;
      return true;
    });
    const submitForm = () => {
      if (!canSubmit.value)
        return;
      if (!validateIdNumber())
        return;
      if (cardOption.value === "bind") {
        if (!validateCardNo(form.value.cardNo)) {
          common_vendor.index.showToast({
            title: "请输入正确的就诊卡号",
            icon: "none"
          });
          return;
        }
      }
      if (!validatePhone(form.value.phone)) {
        common_vendor.index.showToast({
          title: "请输入正确的手机号码",
          icon: "none"
        });
        return;
      }
      common_vendor.index.showLoading({
        title: "保存中..."
      });
      common_vendor.index.__f__("log", "at pages/patient/add.vue:372", "提交表单:", form.value);
      setTimeout(() => {
        common_vendor.index.hideLoading();
        common_vendor.index.showToast({
          title: "保存成功",
          icon: "success"
        });
        setTimeout(() => {
          common_vendor.index.navigateBack();
        }, 1500);
      }, 1e3);
    };
    onUnmounted(() => {
      if (timer) {
        clearInterval(timer);
        timer = null;
      }
    });
    const currentIdType = common_vendor.computed(() => {
      if (idTypeIndex.value >= 0 && idTypes[idTypeIndex.value]) {
        return idTypes[idTypeIndex.value].label;
      }
      return "请选择证件类型";
    });
    const currentRelation = common_vendor.computed(() => {
      if (relationIndex.value >= 0 && relations[relationIndex.value]) {
        return relations[relationIndex.value].label;
      }
      return "请选择关系";
    });
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: form.value.name,
        b: common_vendor.o(($event) => form.value.name = $event.detail.value),
        c: common_vendor.t(currentIdType.value),
        d: idTypeLabels.value,
        e: idTypeIndex.value,
        f: common_vendor.o(onIdTypeChange),
        g: idNumberPlaceholder.value,
        h: idNumberMaxLength.value,
        i: common_vendor.o(validateIdNumber),
        j: form.value.idNumber,
        k: common_vendor.o(($event) => form.value.idNumber = $event.detail.value),
        l: idNumberError.value
      }, idNumberError.value ? {
        m: common_vendor.t(idNumberError.value)
      } : {}, {
        n: common_vendor.t(currentRelation.value),
        o: relationLabels.value,
        p: relationIndex.value,
        q: common_vendor.o(onRelationChange),
        r: cardOption.value === "bind" ? 1 : "",
        s: common_vendor.o(($event) => cardOption.value = "bind"),
        t: cardOption.value === "new" ? 1 : "",
        v: common_vendor.o(($event) => cardOption.value = "new"),
        w: cardOption.value === "bind"
      }, cardOption.value === "bind" ? {
        x: form.value.cardNo,
        y: common_vendor.o(($event) => form.value.cardNo = $event.detail.value),
        z: form.value.phone,
        A: common_vendor.o(($event) => form.value.phone = $event.detail.value),
        B: form.value.verifyCode,
        C: common_vendor.o(($event) => form.value.verifyCode = $event.detail.value),
        D: common_vendor.t(countdown.value ? `${countdown.value}s` : "获取验证码"),
        E: !!countdown.value,
        F: common_vendor.o(sendVerifyCode)
      } : {
        G: form.value.phone,
        H: common_vendor.o(($event) => form.value.phone = $event.detail.value)
      }, {
        I: form.value.isDefault,
        J: common_vendor.o((e) => form.value.isDefault = e.detail.value),
        K: !canSubmit.value,
        L: common_vendor.o(submitForm),
        M: common_vendor.gei(_ctx, "")
      });
    };
  }
};
wx.createPage(_sfc_main);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/patient/add.js.map