fix:function_calculateAge

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2026-01-21 16:16:00 +07:00
parent 8867829211
commit 6f40ee330c
10 changed files with 41 additions and 152 deletions

View file

@ -4,6 +4,7 @@ import { useQuasar } from "quasar";
import { useRouter } from "vue-router";
import { useCounterMixin } from "@/stores/mixin";
import { calculateAge } from "@/utils/function";
import http from "@/plugins/http";
import config from "@/app.config";
@ -16,7 +17,6 @@ import type {
FormAddPerson,
} from "@/modules/05_placement/interface/index/ProfileType";
const retireDate = ref<Date>();
const router = useRouter();
const $q = useQuasar();
const mixin = useCounterMixin();
@ -25,14 +25,12 @@ const {
success,
dateToISO,
messageError,
dialogMessageNotify,
showLoader,
hideLoader,
dialogConfirm,
} = mixin;
const age = ref<string | null>("");
const defaultCitizenData = ref<string>("");
const informaData = ref<FormAddPerson>({
prefix: "",
firstName: "",
@ -283,32 +281,6 @@ function clickBack() {
router.push("/placement/receive");
}
/**
* งกนคำนวนอาย
* @param birthDate นเดอยปเก
* @returns อาย แบบ เดอน
*/
function calculateAge(birthDate: Date | null) {
if (!birthDate) return null;
const birthDateTimeStamp = new Date(birthDate).getTime();
const now = new Date();
const diff = now.getTime() - birthDateTimeStamp;
const ageDate = new Date(diff);
const years = ageDate.getUTCFullYear() - 1970;
const months = ageDate.getUTCMonth();
const days = ageDate.getUTCDate() - 1;
const retire = new Date(birthDate);
retire.setFullYear(retire.getFullYear() + 60);
retireDate.value = retire;
if (years > 60) {
return "อายุเกิน 60 ปี";
}
return `${years} ปี ${months} เดือน ${days} วัน`;
}
/**
* งกนอปเดทวนเดอนปเก
* @param v นเดอยปเก

View file

@ -5,6 +5,7 @@ import { useQuasar } from "quasar";
import { useRoute, useRouter } from "vue-router";
import { useCounterMixin } from "@/stores/mixin";
import { checkPermission } from "@/utils/permissions";
import { calculateAge } from "@/utils/function";
import http from "@/plugins/http";
import config from "@/app.config";
@ -264,8 +265,6 @@ async function getData() {
salary.value = data.amountOld ?? 0;
reason.value = data.reason ?? "";
status.value = data.status ?? "";
calculateAge(data.dateOfBirth);
})
.catch((e) => {
messageError($q, e);
@ -510,31 +509,6 @@ function calculateMaxDate() {
return today;
}
/**
* งกนคำนวนอาย
* @param birthDate นเดอยปเก
* @returns อาย แบบ เดอน
*/
function calculateAge(birthDate: Date | null) {
if (!birthDate) return null;
const birthDateTimeStamp = new Date(birthDate).getTime();
const now = new Date();
const diff = now.getTime() - birthDateTimeStamp;
const ageDate = new Date(diff);
const years = ageDate.getUTCFullYear() - 1970;
const months = ageDate.getUTCMonth();
const days = ageDate.getUTCDate() - 1;
const retire = new Date(birthDate);
retire.setFullYear(retire.getFullYear() + 60);
if (years > 60) {
return "อายุเกิน 60 ปี";
}
return `${years} ปี ${months} เดือน ${days} วัน`;
}
/**
* งกนอปเดทวนเดอนปเก
* @param v นเดอยปเก