From b5b3ff2ea51fecd6623c98d446733c2a4ea73cfa Mon Sep 17 00:00:00 2001 From: waruneeta Date: Mon, 12 Feb 2024 21:32:17 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=9B=E0=B8=A3=E0=B8=B1=E0=B8=9A=E0=B8=9B?= =?UTF-8?q?=E0=B8=8F=E0=B8=B4=E0=B8=97=E0=B8=B4=E0=B8=99=E0=B8=97=E0=B8=B0?= =?UTF-8?q?=E0=B9=80=E0=B8=9A=E0=B8=B5=E0=B8=A2=E0=B8=99=E0=B8=9B=E0=B8=A3?= =?UTF-8?q?=E0=B8=B0=E0=B8=A7=E0=B8=B1=E0=B8=95=E0=B8=B4=20=E0=B8=AA?= =?UTF-8?q?=E0=B9=88=E0=B8=A7=E0=B8=99=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B9=80?= =?UTF-8?q?=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1=E0=B8=82=E0=B9=89=E0=B8=AD?= =?UTF-8?q?=E0=B8=A1=E0=B8=B9=E0=B8=A5=E0=B9=81=E0=B8=A5=E0=B8=B0=E0=B9=81?= =?UTF-8?q?=E0=B8=81=E0=B9=89=E0=B9=84=E0=B8=82=E0=B8=A7=E0=B8=B1=E0=B8=99?= =?UTF-8?q?=E0=B9=80=E0=B8=81=E0=B8=B4=E0=B8=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/DialogAddEmployee.vue | 79 +++++++++++-------- .../components/Information/Information.vue | 49 +++++++++++- src/stores/mixin.ts | 38 +++++++-- 3 files changed, 122 insertions(+), 44 deletions(-) diff --git a/src/components/DialogAddEmployee.vue b/src/components/DialogAddEmployee.vue index c72424b69..f161a8a7f 100644 --- a/src/components/DialogAddEmployee.vue +++ b/src/components/DialogAddEmployee.vue @@ -21,6 +21,7 @@ const { dateToISO, dialogConfirm, success, + convertDate, } = useCounterMixin(); const $q = useQuasar(); @@ -33,7 +34,7 @@ const informaData = ref({ prefixId: null, firstname: null, lastname: null, - birthDate: null, + birthDate: "", genderId: null, bloodId: null, nationality: "ไทย", @@ -173,7 +174,6 @@ const calRetire = async (birth: Date) => { birthDate: dateToISO(birth), }; if (dateToISO(dateBefore.value) != dateToISO(birth)) { - console.log(birth); showLoader(); await http .post(config.API.profileCalRetire, body) @@ -186,7 +186,8 @@ const calRetire = async (birth: Date) => { }) .catch((e: any) => { messageError($q, e); - informaData.value.birthDate = null; + inputBirthDate.value = ""; + informaData.value.birthDate = ""; informaData.value.age = ""; }) .finally(() => { @@ -201,7 +202,8 @@ const saveData = async () => { if (myform.value != null) { await myform.value.validate().then(async (saveDataTest: Boolean) => { if (saveDataTest) { - dialogConfirm($q, () => addData()); // validate ผ่านส่งไปบันทึกที่ api + if (inputBirthDate.value === "") dayChecked.value = true; + else dialogConfirm($q, () => addData()); // validate ผ่านส่งไปบันทึกที่ api } }); } @@ -227,11 +229,8 @@ const addData = async () => { formData.append("race", informaData.value.ethnicity); if (informaData.value.religionId != undefined) formData.append("religionId", informaData.value.religionId); - if (informaData.value.birthDate != undefined) - formData.append( - "birthDate", - dateToISO(informaData.value.birthDate) ?? dateToISO(new Date()) - ); + if (informaData.value.birthDate != "") + formData.append("birthDate", dateToISO(informaData.value.birthDate)); if (informaData.value.bloodId != undefined) formData.append("bloodGroupId", informaData.value.bloodId); if (informaData.value.statusId != undefined) @@ -248,6 +247,7 @@ const addData = async () => { .post(config.API.createProfileOfficer(), formData) .then((res) => { success($q, "บันทึกข้อมูลสำเร็จ"); + clearForm(); }) .catch((e) => { messageError($q, e); @@ -259,6 +259,28 @@ const addData = async () => { }); }; +function clearForm() { + informaData.value = { + cardid: null, + age: null, + prefix: null, + prefixId: null, + firstname: null, + lastname: null, + birthDate: null, + genderId: null, + bloodId: null, + nationality: "ไทย", + ethnicity: "ไทย", + statusId: null, + religionId: "ceaec498-71b4-4f82-b5a2-7d6ec988b753", + tel: null, + employeeType: null, + employeeClass: null, + profileType: null, + }; +} + /*** get รายการข้อมูลเกี่ยวกับบุคคล (dropdown list) */ const fetchPerson = async () => { showLoader(); @@ -322,39 +344,31 @@ const fetchPerson = async () => { }); }; -const id = ref(""); +// change date input +const inputBirthDate = ref(""); const dayChecked = ref(false); watch( - () => id.value, - () => { - if (id.value.length === 10) { - const test = ref([]); - test.value = id.value.split("/"); - const test3: number = parseInt(test.value[2]) - 543; - const test2: string = `${test3}-${test.value[1]}-${test.value[0]}`; + () => inputBirthDate.value, + (value: string) => { + if (value.length === 10) { + const dateVal = convertDate(value); - const checked = moment(test2).isValid(); - - if (checked) { + if (dateVal.isValid) { dayChecked.value = false; - calRetire(new Date(test2)); + calRetire(new Date(dateVal.value)); } else { dayChecked.value = true; - id.value = ""; + inputBirthDate.value = ""; + informaData.value.age = ""; } - // console.log(numDays); - // if (day <= numDays) { - // console.log(test2); - // } else { - // console.log("ผิดพลาด"); - // } } } ); + + diff --git a/src/stores/mixin.ts b/src/stores/mixin.ts index 71fad33cd..cd172e3e9 100644 --- a/src/stores/mixin.ts +++ b/src/stores/mixin.ts @@ -304,21 +304,44 @@ export const useCounterMixin = defineStore("mixin", () => { } } - function convertDate(date: string) { + const convertDate = (date: string) => { if (date != null && date.length == 10) { - const srcDate = date.split("/"); + const srcDate = date.toString().split("/"); const dateVal = Number(srcDate[2]) - 543 + "-" + srcDate[1] + "-" + srcDate[0]; + const check = moment(dateVal).isValid(); - if (moment(dateVal).isValid()) { - return dateVal; + if (check) { + return { + isValid: check, + value: dateVal, + }; } else { - return "" + return { + isValid: check, + value: "", + }; } } else { - return ""; + return { + isValid: false, + value: "", + }; } - } + }; + + const convertDateDisplay = (dateVal: Date) => { + const date = new Date(dateVal); + let dstYear = date.getFullYear() + 543; + let dstMonth = date.getMonth() + 1; + return ( + date.getDate().toString().padStart(2, "0") + + "/" + + dstMonth.toString().padStart(2, "0") + + "/" + + dstYear + ); + }; function appendLeadingZeroes(n: number) { if (n <= 9) return "0" + n; @@ -973,5 +996,6 @@ export const useCounterMixin = defineStore("mixin", () => { dialogMessageNotify, fails, convertDate, + convertDateDisplay, }; });