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 config from "@/app.config";
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";
@ -17,8 +17,6 @@ const age = defineModel<string | null>("age", {
});
const $q = useQuasar();
const storeProfile = useProfileDataStore();
const { filterSelector, calculateAge } = storeProfile;
const { date2Thai, messageError, dialogMessageNotify } = useCounterMixin();
const props = defineProps({

View file

@ -9,14 +9,11 @@ import { useCounterMixin } from "@/stores/mixin";
import { useLinkageStore } from "@/stores/linkage";
import { useDataLinkCenter } from "@/modules/04_registryPerson/stores/LinkCenter";
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 { RequestregistrationAddressObject } from "@/modules/04_registryPerson/interface/request/Address";
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 InformationPage from "@/modules/04_registryPerson/components/Dialog/01_Information.vue"; //form
@ -268,7 +265,7 @@ async function amiRequest() {
formInformations.birthDate = data.value.dateOfBirth
? conventDateOfBirth(`${data.value.dateOfBirth}`)
: null;
age.value = storeLinkCenter.calculateAge(data.value.age);
age.value = calculateAge(data.value.dateOfBirth);
formInformations.gender = data.value.genderDesc;
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 { useCounterMixin } from "@/stores/mixin";
import { useProfileDataStore } from "@/modules/04_registryPerson/stores/profile";
import { calculateAge } from "@/utils/function";
import http from "@/plugins/http";
import config from "@/app.config";
@ -22,7 +23,7 @@ import DialogHistory from "@/modules/04_registryPerson/components/detail/DialogH
const $q = useQuasar();
const route = useRoute();
const store = useProfileDataStore();
const { calculateAge, fetchPerson, filterSelector } = store;
const { fetchPerson, filterSelector } = store;
const {
success,
showLoader,

View file

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

View file

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