"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
|