add customer lunar birthdate
This commit is contained in:
@@ -34,11 +34,18 @@
|
||||
borderless
|
||||
/>
|
||||
</t-form-item>
|
||||
<t-form-item label="出生日期">
|
||||
<birthdate-picker
|
||||
v-model="formModel.birthdate"
|
||||
v-model:calendar="formModel.birthdateCalendar"
|
||||
/>
|
||||
</t-form-item>
|
||||
<t-form-item label="年龄">
|
||||
<t-input
|
||||
v-model.trim="formModel.age"
|
||||
type="number"
|
||||
placeholder="年龄"
|
||||
:readonly="!!formModel.birthdate"
|
||||
:placeholder="formModel.birthdate ? '根据出生日期自动计算' : '年龄'"
|
||||
borderless
|
||||
/>
|
||||
</t-form-item>
|
||||
@@ -157,7 +164,7 @@ import CodeScanner from "@/components/CodeScanner.vue";
|
||||
import CustomerSelector from "@/components/CustomerSelector.vue";
|
||||
import PhotoField from "@/components/PhotoField.vue";
|
||||
import { useSettingStore } from "@/store/settingStore";
|
||||
import type { BodyAreaValue, Customer, CustomerGender } from "@/types/Customer";
|
||||
import type { BodyAreaValue, Customer, CustomerBirthdateCalendar, CustomerGender } from "@/types/Customer";
|
||||
import { createBodyAreaValue, getCustomerPhotoURL, normalizeBodyAreaValue } from "@/utils/customer";
|
||||
import { gaoPermissionCodes } from "@/utils/gaoPermission";
|
||||
import { compressUploadImage } from "@/utils/imageCompression";
|
||||
@@ -194,6 +201,8 @@ const formModel = reactive({
|
||||
photoURL: "",
|
||||
telephone: "",
|
||||
age: "",
|
||||
birthdate: "",
|
||||
birthdateCalendar: "SOLAR" as CustomerBirthdateCalendar,
|
||||
address: "",
|
||||
referrer: "",
|
||||
disease: "",
|
||||
@@ -209,6 +218,8 @@ function resetFormModel(): void {
|
||||
photoURL: "",
|
||||
telephone: "",
|
||||
age: "",
|
||||
birthdate: "",
|
||||
birthdateCalendar: "SOLAR",
|
||||
address: "",
|
||||
referrer: "",
|
||||
disease: "",
|
||||
@@ -258,6 +269,8 @@ async function fillForm(): Promise<void> {
|
||||
photoURL: getCustomerPhotoURL(customer),
|
||||
telephone: customer.telephone || "",
|
||||
age: customer.age === undefined || customer.age === null ? "" : String(customer.age),
|
||||
birthdate: customer.birthdate || "",
|
||||
birthdateCalendar: customer.birthdateCalendar || "SOLAR",
|
||||
address: customer.address || "",
|
||||
referrer: customer.introducerCustomer?.name || "",
|
||||
disease: customer.disease || "",
|
||||
@@ -406,6 +419,8 @@ async function saveCustomer(): Promise<void> {
|
||||
name: formModel.name,
|
||||
gender: formModel.gender || undefined,
|
||||
age: Number(formModel.age) || undefined,
|
||||
birthdate: formModel.birthdate || null,
|
||||
birthdateCalendar: formModel.birthdate ? formModel.birthdateCalendar : undefined,
|
||||
telephone: formModel.telephone,
|
||||
address: formModel.address,
|
||||
remark: formModel.note,
|
||||
@@ -463,6 +478,28 @@ watch(() => formModel.referrer, (value) => {
|
||||
}
|
||||
});
|
||||
|
||||
watch(() => formModel.birthdate, (value) => {
|
||||
if (value) {
|
||||
formModel.age = String(calculateAge(value));
|
||||
}
|
||||
});
|
||||
|
||||
function calculateAge(value: string): number {
|
||||
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value);
|
||||
if (!match) {
|
||||
return 0;
|
||||
}
|
||||
const birthYear = Number(match[1]);
|
||||
const birthMonth = Number(match[2]);
|
||||
const birthDay = Number(match[3]);
|
||||
const today = new Date();
|
||||
let age = today.getFullYear() - birthYear;
|
||||
if (today.getMonth() + 1 < birthMonth || (today.getMonth() + 1 === birthMonth && today.getDate() < birthDay)) {
|
||||
age--;
|
||||
}
|
||||
return Math.max(age, 0);
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await fillForm();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user