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

@ -5,7 +5,7 @@ import { useQuasar } from "quasar";
import http from "@/plugins/http"; import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin"; import { useCounterMixin } from "@/stores/mixin";
import { useProfileDataStore } from "@/modules/04_registryPerson/stores/profile"; import { calculateAge } from "@/utils/function";
import type { RequestObject } from "@/modules/04_registryPerson/interface/request/Profile"; import type { RequestObject } from "@/modules/04_registryPerson/interface/request/Profile";
@ -17,8 +17,6 @@ const age = defineModel<string | null>("age", {
}); });
const $q = useQuasar(); const $q = useQuasar();
const storeProfile = useProfileDataStore();
const { filterSelector, calculateAge } = storeProfile;
const { date2Thai, messageError, dialogMessageNotify } = useCounterMixin(); const { date2Thai, messageError, dialogMessageNotify } = useCounterMixin();
const props = defineProps({ const props = defineProps({

View file

@ -9,14 +9,11 @@ import { useCounterMixin } from "@/stores/mixin";
import { useLinkageStore } from "@/stores/linkage"; import { useLinkageStore } from "@/stores/linkage";
import { useDataLinkCenter } from "@/modules/04_registryPerson/stores/LinkCenter"; import { useDataLinkCenter } from "@/modules/04_registryPerson/stores/LinkCenter";
import { useRequestEditStore } from "@/modules/04_registryPerson/stores/RequestEdit"; import { useRequestEditStore } from "@/modules/04_registryPerson/stores/RequestEdit";
import { calculateAge } from "@/utils/function";
import type { DataOption } from "@/modules/04_registryPerson/interface/index/Main"; import type { DataOption } from "@/modules/04_registryPerson/interface/index/Main";
import type { RequestregistrationAddressObject } from "@/modules/04_registryPerson/interface/request/Address"; import type { RequestregistrationAddressObject } from "@/modules/04_registryPerson/interface/request/Address";
import type { RequestObject } from "@/modules/04_registryPerson/interface/request/Profile"; import type { RequestObject } from "@/modules/04_registryPerson/interface/request/Profile";
import type {
FormPerson,
FormChildren,
} from "@/modules/04_registryPerson/interface/index/family";
import Header from "@/components/DialogHeader.vue"; // popup import Header from "@/components/DialogHeader.vue"; // popup
import InformationPage from "@/modules/04_registryPerson/components/Dialog/01_Information.vue"; //form import InformationPage from "@/modules/04_registryPerson/components/Dialog/01_Information.vue"; //form
@ -268,7 +265,7 @@ async function amiRequest() {
formInformations.birthDate = data.value.dateOfBirth formInformations.birthDate = data.value.dateOfBirth
? conventDateOfBirth(`${data.value.dateOfBirth}`) ? conventDateOfBirth(`${data.value.dateOfBirth}`)
: null; : null;
age.value = storeLinkCenter.calculateAge(data.value.age); age.value = calculateAge(data.value.dateOfBirth);
formInformations.gender = data.value.genderDesc; formInformations.gender = data.value.genderDesc;
let registrationAddress = data.value.houseNo ? data.value.houseNo : ""; let registrationAddress = data.value.houseNo ? data.value.houseNo : "";

View file

@ -6,6 +6,7 @@ import { checkPermission } from "@/utils/permissions";
import { useRoute } from "vue-router"; import { useRoute } from "vue-router";
import { useCounterMixin } from "@/stores/mixin"; import { useCounterMixin } from "@/stores/mixin";
import { useProfileDataStore } from "@/modules/04_registryPerson/stores/profile"; import { useProfileDataStore } from "@/modules/04_registryPerson/stores/profile";
import { calculateAge } from "@/utils/function";
import http from "@/plugins/http"; import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
@ -22,7 +23,7 @@ import DialogHistory from "@/modules/04_registryPerson/components/detail/DialogH
const $q = useQuasar(); const $q = useQuasar();
const route = useRoute(); const route = useRoute();
const store = useProfileDataStore(); const store = useProfileDataStore();
const { calculateAge, fetchPerson, filterSelector } = store; const { fetchPerson, filterSelector } = store;
const { const {
success, success,
showLoader, showLoader,

View file

@ -16,7 +16,6 @@ const mixin = useCounterMixin();
const { showLoader, hideLoader } = mixin; const { showLoader, hideLoader } = mixin;
export const useDataLinkCenter = defineStore("DataLinkCenter", () => { export const useDataLinkCenter = defineStore("DataLinkCenter", () => {
const retireDate = ref<Date>();
const optionRelationshipMain = ref<DataOption[]>([]); const optionRelationshipMain = ref<DataOption[]>([]);
const optionRelationship = ref<DataOption[]>([]); const optionRelationship = ref<DataOption[]>([]);
//รายการตัวเลือก //รายการตัวเลือก
@ -70,32 +69,6 @@ export const useDataLinkCenter = defineStore("DataLinkCenter", () => {
subdistrictCOps: [], subdistrictCOps: [],
}); });
/**
*
* @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} วัน`;
}
/** /**
* *
*/ */
@ -351,7 +324,7 @@ export const useDataLinkCenter = defineStore("DataLinkCenter", () => {
OpsPerson, OpsPerson,
OpsAddress, OpsAddress,
OpsAddressFilter, OpsAddressFilter,
calculateAge,
fetchProvince, fetchProvince,
filterSelector, filterSelector,
fetchDistrict, fetchDistrict,

View file

@ -15,8 +15,6 @@ const mixin = useCounterMixin();
const { showLoader, hideLoader } = mixin; const { showLoader, hideLoader } = mixin;
export const useProfileDataStore = defineStore("profile", () => { export const useProfileDataStore = defineStore("profile", () => {
const retireDate = ref<Date>();
//ข้อมูลส่วนตัว //ข้อมูลส่วนตัว
const defaultProfile: RequestObject = { const defaultProfile: RequestObject = {
bloodGroup: null, bloodGroup: null,
@ -69,32 +67,6 @@ export const useProfileDataStore = defineStore("profile", () => {
], ],
}); });
/**
*
* @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} วัน`;
}
/** /**
* *
*/ */
@ -247,11 +219,9 @@ export const useProfileDataStore = defineStore("profile", () => {
return { return {
defaultProfile, defaultProfile,
retireDate,
Ops, Ops,
OpsFilter, OpsFilter,
calculateAge,
fetchPerson, fetchPerson,
filterSelector, filterSelector,
}; };

View file

@ -4,6 +4,7 @@ import { useQuasar } from "quasar";
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
import { useCounterMixin } from "@/stores/mixin"; import { useCounterMixin } from "@/stores/mixin";
import { calculateAge } from "@/utils/function";
import http from "@/plugins/http"; import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
@ -16,7 +17,6 @@ import type {
FormAddPerson, FormAddPerson,
} from "@/modules/05_placement/interface/index/ProfileType"; } from "@/modules/05_placement/interface/index/ProfileType";
const retireDate = ref<Date>();
const router = useRouter(); const router = useRouter();
const $q = useQuasar(); const $q = useQuasar();
const mixin = useCounterMixin(); const mixin = useCounterMixin();
@ -25,14 +25,12 @@ const {
success, success,
dateToISO, dateToISO,
messageError, messageError,
dialogMessageNotify,
showLoader, showLoader,
hideLoader, hideLoader,
dialogConfirm, dialogConfirm,
} = mixin; } = mixin;
const age = ref<string | null>(""); const age = ref<string | null>("");
const defaultCitizenData = ref<string>("");
const informaData = ref<FormAddPerson>({ const informaData = ref<FormAddPerson>({
prefix: "", prefix: "",
firstName: "", firstName: "",
@ -283,32 +281,6 @@ function clickBack() {
router.push("/placement/receive"); 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 นเดอยปเก * @param v นเดอยปเก

View file

@ -5,6 +5,7 @@ import { useQuasar } from "quasar";
import { useRoute, useRouter } from "vue-router"; import { useRoute, useRouter } from "vue-router";
import { useCounterMixin } from "@/stores/mixin"; import { useCounterMixin } from "@/stores/mixin";
import { checkPermission } from "@/utils/permissions"; import { checkPermission } from "@/utils/permissions";
import { calculateAge } from "@/utils/function";
import http from "@/plugins/http"; import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
@ -264,8 +265,6 @@ async function getData() {
salary.value = data.amountOld ?? 0; salary.value = data.amountOld ?? 0;
reason.value = data.reason ?? ""; reason.value = data.reason ?? "";
status.value = data.status ?? ""; status.value = data.status ?? "";
calculateAge(data.dateOfBirth);
}) })
.catch((e) => { .catch((e) => {
messageError($q, e); messageError($q, e);
@ -510,31 +509,6 @@ function calculateMaxDate() {
return today; 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 นเดอยปเก * @param v นเดอยปเก

View file

@ -8,13 +8,13 @@ import config from "@/app.config";
import type { DataOption } from "@/modules/08_registryEmployee/interface/index/Main"; import type { DataOption } from "@/modules/08_registryEmployee/interface/index/Main";
import type { FormDataEmployee } from "@/modules/08_registryEmployee/interface/request/Employee"; import type { FormDataEmployee } from "@/modules/08_registryEmployee/interface/request/Employee";
import type { ResOptionPerson } from "@/modules/08_registryEmployee/interface/response/Employee"; import type { ResOptionPerson } from "@/modules/08_registryEmployee/interface/response/Employee";
import { calculateAge } from "@/utils/function";
/** importComponents*/ /** importComponents*/
import DialogHeader from "@/components/DialogHeader.vue"; import DialogHeader from "@/components/DialogHeader.vue";
/** importStore*/ /** importStore*/
import { useCounterMixin } from "@/stores/mixin"; import { useCounterMixin } from "@/stores/mixin";
import { useRegistryEmp } from "@/modules/08_registryEmployee/stores/registry-employee";
/** use*/ /** use*/
const $q = useQuasar(); const $q = useQuasar();
@ -27,7 +27,6 @@ const {
dialogMessageNotify, dialogMessageNotify,
date2Thai, date2Thai,
} = useCounterMixin(); } = useCounterMixin();
const { calculateAge } = useRegistryEmp();
/** props*/ /** props*/
const modal = defineModel<boolean>("modal", { required: true }); const modal = defineModel<boolean>("modal", { required: true });

View file

@ -1,32 +1,6 @@
import { defineStore } from "pinia"; import { defineStore } from "pinia";
export const useRegistryEmp = defineStore("registryEmployeeTemp", () => { export const useRegistryEmp = defineStore("registryEmployeeTemp", () => {
/**
* function
* @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} วัน`;
}
/** /**
* function convertstatus * function convertstatus
* @param val * @param val
@ -53,7 +27,6 @@ export const useRegistryEmp = defineStore("registryEmployeeTemp", () => {
} }
}; };
return { return {
calculateAge,
statusText, statusText,
}; };
}); });

View file

@ -1,3 +1,5 @@
import moment from "moment";
/** /**
* *
* *
@ -28,3 +30,33 @@ export function calculateFiscalYear(date: Date) {
const month = date.getMonth() + 1; const month = date.getMonth() + 1;
return month >= 10 ? date.getFullYear() + 1 : date.getFullYear(); return month >= 10 ? date.getFullYear() + 1 : date.getFullYear();
} }
/**
*
* @param birthDate
* @returns "อายุเกิน 60 ปี" null null
*/
export function calculateAge(birthDate: Date | null) {
if (!birthDate) return null;
// .startOf('day') จะเซ็ตเวลาเป็น 00:00:00.000 ของวันนั้นๆ
const birth = moment(birthDate).startOf("day");
const now = moment().startOf("day");
if (!birth.isValid()) return "Invalid Date";
// คราวนี้การลบกันจะสนแค่ "วันที่" เท่านั้น
const years = now.diff(birth, "years");
birth.add(years, "years");
const months = now.diff(birth, "months");
birth.add(months, "months");
const days = now.diff(birth, "days");
if (years >= 60) {
return "อายุเกิน 60 ปี";
}
return `${years} ปี ${months} เดือน ${days} วัน`;
}