Merge pull request #1536 from Frappet/fix/calculateAge
All checks were successful
Build & Deploy on Dev / build (push) Successful in 2m41s
All checks were successful
Build & Deploy on Dev / build (push) Successful in 2m41s
fix:function_calculateAge
This commit is contained in:
commit
b7c33cf25c
10 changed files with 41 additions and 152 deletions
|
|
@ -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({
|
||||
|
|
|
|||
|
|
@ -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 : "";
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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 วันเดือยปีเกิด
|
||||
|
|
|
|||
|
|
@ -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 วันเดือยปีเกิด
|
||||
|
|
|
|||
|
|
@ -8,13 +8,13 @@ import config from "@/app.config";
|
|||
import type { DataOption } from "@/modules/08_registryEmployee/interface/index/Main";
|
||||
import type { FormDataEmployee } from "@/modules/08_registryEmployee/interface/request/Employee";
|
||||
import type { ResOptionPerson } from "@/modules/08_registryEmployee/interface/response/Employee";
|
||||
import { calculateAge } from "@/utils/function";
|
||||
|
||||
/** importComponents*/
|
||||
import DialogHeader from "@/components/DialogHeader.vue";
|
||||
|
||||
/** importStore*/
|
||||
import { useCounterMixin } from "@/stores/mixin";
|
||||
import { useRegistryEmp } from "@/modules/08_registryEmployee/stores/registry-employee";
|
||||
|
||||
/** use*/
|
||||
const $q = useQuasar();
|
||||
|
|
@ -27,7 +27,6 @@ const {
|
|||
dialogMessageNotify,
|
||||
date2Thai,
|
||||
} = useCounterMixin();
|
||||
const { calculateAge } = useRegistryEmp();
|
||||
|
||||
/** props*/
|
||||
const modal = defineModel<boolean>("modal", { required: true });
|
||||
|
|
|
|||
|
|
@ -1,32 +1,6 @@
|
|||
import { defineStore } from "pinia";
|
||||
|
||||
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
|
||||
* @param val ค่าสภานะ
|
||||
|
|
@ -53,7 +27,6 @@ export const useRegistryEmp = defineStore("registryEmployeeTemp", () => {
|
|||
}
|
||||
};
|
||||
return {
|
||||
calculateAge,
|
||||
statusText,
|
||||
};
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import moment from "moment";
|
||||
|
||||
/**
|
||||
* คำนวณหน้าที่จะแสดงหลังจากลบข้อมูล
|
||||
*
|
||||
|
|
@ -28,3 +30,33 @@ export function calculateFiscalYear(date: Date) {
|
|||
const month = date.getMonth() + 1;
|
||||
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} วัน`;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue