WXL
13 小时以前 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
"use strict";
const common_vendor = require("../../common/vendor.js");
const _sfc_main = {
  __name: "add-bank-card",
  setup(__props) {
    const banks = [
      {
        id: 1,
        name: "中国银行(青岛)",
        code: "bocm",
        logo: "/static/payment/bocm.png"
      },
      {
        id: 2,
        name: "工商银行(青岛)",
        code: "icbcm",
        logo: "/static/payment/icbcm.png"
      },
      {
        id: 3,
        name: "大西洋银行",
        code: "bem",
        logo: "/static/payment/bem.png"
      },
      {
        id: 4,
        name: "青岛商业银行",
        code: "bcm",
        logo: "/static/payment/bcm.png"
      }
    ];
    const bankIndex = common_vendor.ref(-1);
    const cardTypes = [
      { value: "debit", label: "储蓄卡" },
      { value: "credit", label: "信用卡" }
    ];
    const selectedCardType = common_vendor.ref("debit");
    const form = common_vendor.ref({
      bankId: "",
      cardType: "debit",
      cardNumber: "",
      holderName: "",
      phone: "",
      verifyCode: "",
      isDefault: false
    });
    const countdown = common_vendor.ref(0);
    let timer = null;
    const onBankChange = (e) => {
      const index = parseInt(e.detail.value);
      bankIndex.value = index;
      form.value.bankId = banks[index].id;
    };
    const formatCardNumber = (e) => {
      let value = e.detail.value.replace(/\D/g, "");
      value = value.replace(/(\d{4})(?=\d)/g, "$1 ");
      form.value.cardNumber = value;
    };
    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 canSubmit = common_vendor.computed(() => {
      const { bankId, cardNumber, holderName, phone, verifyCode } = form.value;
      return bankId && cardNumber && holderName && phone && verifyCode && validatePhone(phone);
    });
    const submitForm = () => {
      if (!canSubmit.value)
        return;
      common_vendor.index.showLoading({
        title: "添加中..."
      });
      common_vendor.index.__f__("log", "at pages/my/add-bank-card.vue:264", "提交表单:", 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;
      }
    });
    return (_ctx, _cache) => {
      return {
        a: common_vendor.t(bankIndex.value > -1 ? banks[bankIndex.value].name : "请选择发卡银行"),
        b: banks,
        c: bankIndex.value,
        d: common_vendor.o(onBankChange),
        e: common_vendor.f(cardTypes, (type, index, i0) => {
          return {
            a: common_vendor.t(type.label),
            b: index,
            c: selectedCardType.value === type.value ? 1 : "",
            d: common_vendor.o(($event) => selectedCardType.value = type.value, index)
          };
        }),
        f: common_vendor.o([($event) => form.value.cardNumber = $event.detail.value, formatCardNumber]),
        g: form.value.cardNumber,
        h: form.value.holderName,
        i: common_vendor.o(($event) => form.value.holderName = $event.detail.value),
        j: form.value.phone,
        k: common_vendor.o(($event) => form.value.phone = $event.detail.value),
        l: form.value.verifyCode,
        m: common_vendor.o(($event) => form.value.verifyCode = $event.detail.value),
        n: common_vendor.t(countdown.value ? `${countdown.value}s` : "获取验证码"),
        o: !!countdown.value,
        p: common_vendor.o(sendVerifyCode),
        q: form.value.isDefault,
        r: common_vendor.o((e) => form.value.isDefault = e.detail.value),
        s: !canSubmit.value,
        t: common_vendor.o(submitForm),
        v: common_vendor.gei(_ctx, "")
      };
    };
  }
};
wx.createPage(_sfc_main);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/my/add-bank-card.js.map