ปรับปฏิทินทะเบียนประวัติ ส่วนการเพิ่มข้อมูลและแก้ไขวันเกิด

This commit is contained in:
Warunee Tamkoo 2024-02-12 21:32:17 +07:00
parent cba0f206c2
commit b5b3ff2ea5
3 changed files with 122 additions and 44 deletions

View file

@ -21,6 +21,7 @@ const {
dateToISO, dateToISO,
dialogConfirm, dialogConfirm,
success, success,
convertDate,
} = useCounterMixin(); } = useCounterMixin();
const $q = useQuasar(); const $q = useQuasar();
@ -33,7 +34,7 @@ const informaData = ref<any>({
prefixId: null, prefixId: null,
firstname: null, firstname: null,
lastname: null, lastname: null,
birthDate: null, birthDate: "",
genderId: null, genderId: null,
bloodId: null, bloodId: null,
nationality: "ไทย", nationality: "ไทย",
@ -173,7 +174,6 @@ const calRetire = async (birth: Date) => {
birthDate: dateToISO(birth), birthDate: dateToISO(birth),
}; };
if (dateToISO(dateBefore.value) != dateToISO(birth)) { if (dateToISO(dateBefore.value) != dateToISO(birth)) {
console.log(birth);
showLoader(); showLoader();
await http await http
.post(config.API.profileCalRetire, body) .post(config.API.profileCalRetire, body)
@ -186,7 +186,8 @@ const calRetire = async (birth: Date) => {
}) })
.catch((e: any) => { .catch((e: any) => {
messageError($q, e); messageError($q, e);
informaData.value.birthDate = null; inputBirthDate.value = "";
informaData.value.birthDate = "";
informaData.value.age = ""; informaData.value.age = "";
}) })
.finally(() => { .finally(() => {
@ -201,7 +202,8 @@ const saveData = async () => {
if (myform.value != null) { if (myform.value != null) {
await myform.value.validate().then(async (saveDataTest: Boolean) => { await myform.value.validate().then(async (saveDataTest: Boolean) => {
if (saveDataTest) { 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); formData.append("race", informaData.value.ethnicity);
if (informaData.value.religionId != undefined) if (informaData.value.religionId != undefined)
formData.append("religionId", informaData.value.religionId); formData.append("religionId", informaData.value.religionId);
if (informaData.value.birthDate != undefined) if (informaData.value.birthDate != "")
formData.append( formData.append("birthDate", dateToISO(informaData.value.birthDate));
"birthDate",
dateToISO(informaData.value.birthDate) ?? dateToISO(new Date())
);
if (informaData.value.bloodId != undefined) if (informaData.value.bloodId != undefined)
formData.append("bloodGroupId", informaData.value.bloodId); formData.append("bloodGroupId", informaData.value.bloodId);
if (informaData.value.statusId != undefined) if (informaData.value.statusId != undefined)
@ -248,6 +247,7 @@ const addData = async () => {
.post(config.API.createProfileOfficer(), formData) .post(config.API.createProfileOfficer(), formData)
.then((res) => { .then((res) => {
success($q, "บันทึกข้อมูลสำเร็จ"); success($q, "บันทึกข้อมูลสำเร็จ");
clearForm();
}) })
.catch((e) => { .catch((e) => {
messageError($q, 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) */ /*** get รายการข้อมูลเกี่ยวกับบุคคล (dropdown list) */
const fetchPerson = async () => { const fetchPerson = async () => {
showLoader(); showLoader();
@ -322,39 +344,31 @@ const fetchPerson = async () => {
}); });
}; };
const id = ref<string>(""); // change date input
const inputBirthDate = ref<string>("");
const dayChecked = ref<boolean>(false); const dayChecked = ref<boolean>(false);
watch( watch(
() => id.value, () => inputBirthDate.value,
() => { (value: string) => {
if (id.value.length === 10) { if (value.length === 10) {
const test = ref<string[]>([]); const dateVal = convertDate(value);
test.value = id.value.split("/");
const test3: number = parseInt(test.value[2]) - 543;
const test2: string = `${test3}-${test.value[1]}-${test.value[0]}`;
const checked = moment(test2).isValid(); if (dateVal.isValid) {
if (checked) {
dayChecked.value = false; dayChecked.value = false;
calRetire(new Date(test2)); calRetire(new Date(dateVal.value));
} else { } else {
dayChecked.value = true; dayChecked.value = true;
id.value = ""; inputBirthDate.value = "";
informaData.value.age = "";
} }
// console.log(numDays);
// if (day <= numDays) {
// console.log(test2);
// } else {
// console.log("");
// }
} }
} }
); );
</script> </script>
<template> <template>
<q-dialog v-model="modal"> <q-dialog v-model="modal">
<q-card style="min-width: 60vw"> <q-card style="min-width: 75vw">
<Header <Header
tittle="เพิ่มข้อมูลทะเบียนประวัติข้าราชการ กทม.สามัญ" tittle="เพิ่มข้อมูลทะเบียนประวัติข้าราชการ กทม.สามัญ"
:close="() => (modal = false)" :close="() => (modal = false)"
@ -477,13 +491,12 @@ watch(
</datepicker> --> </datepicker> -->
<q-input <q-input
outlined outlined
v-model="id" v-model="inputBirthDate"
label="วัน/เดือน/ปี" label="วัน/เดือน/ปี เกิด"
mask="##/##/####" mask="##/##/####"
dense dense
hint="Mask: ##/##/####"
:error="dayChecked" :error="dayChecked"
error-message="ทดสอบ" error-message="กรุณากรอกวัน/เดือน/ปี เกิด"
/> />
</div> </div>
<div class="col-xs-6 col-sm-2 col-md-2"> <div class="col-xs-6 col-sm-2 col-md-2">

View file

@ -91,7 +91,19 @@
/> />
</div> </div>
<div class="col-xs-6 col-sm-2 col-md-2"> <div class="col-xs-6 col-sm-2 col-md-2">
<!-- change date input -->
<q-input
v-if="edit"
outlined
v-model="inputBirthDate"
label="วัน/เดือน/ปี เกิด"
mask="##/##/####"
dense
:error="dayChecked"
error-message="กรุณากรอกวัน/เดือน/ปี เกิด"
/>
<datepicker <datepicker
v-else
v-model="informaData.birthDate" v-model="informaData.birthDate"
:locale="'th'" :locale="'th'"
autoApply autoApply
@ -416,8 +428,9 @@
</template> </template>
</HistoryTable> </HistoryTable>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, onMounted } from "vue"; import { ref, onMounted, watch } from "vue";
import { useCounterMixin } from "@/stores/mixin"; import { useCounterMixin } from "@/stores/mixin";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
@ -468,6 +481,8 @@ const {
dialogMessage, dialogMessage,
showLoader, showLoader,
hideLoader, hideLoader,
convertDate, // change date input
convertDateDisplay, // change date input
} = mixin; } = mixin;
const profileStore = useProfileDataStore(); const profileStore = useProfileDataStore();
@ -730,7 +745,7 @@ const defaultAdd = () => {
prefixId: null, prefixId: null,
firstname: null, firstname: null,
lastname: null, lastname: null,
birthDate: new Date(), birthDate: null,
genderId: null, genderId: null,
bloodId: null, bloodId: null,
nationality: null, nationality: null,
@ -997,6 +1012,7 @@ const calRetire = async (birth: Date) => {
.then((res: any) => { .then((res: any) => {
const data = res.data.result; const data = res.data.result;
informaData.value.age = data.age; informaData.value.age = data.age;
informaData.value.birthDate = birth;
changeRetireText(data.retireDate); changeRetireText(data.retireDate);
dateBefore.value = birth; dateBefore.value = birth;
}) })
@ -1004,6 +1020,7 @@ const calRetire = async (birth: Date) => {
messageError($q, e); messageError($q, e);
const retire = new Date(`${birth.getFullYear() + 60}-09-30`); const retire = new Date(`${birth.getFullYear() + 60}-09-30`);
informaData.value.birthDate = dateBefore.value; informaData.value.birthDate = dateBefore.value;
inputBirthDate.value = dateBefore.value;
changeRetireText(date2Thai(retire)); changeRetireText(date2Thai(retire));
}) })
.finally(() => { .finally(() => {
@ -1029,6 +1046,7 @@ const fetchData = async () => {
informaData.value.firstname = data.firstName; informaData.value.firstname = data.firstName;
informaData.value.lastname = data.lastName; informaData.value.lastname = data.lastName;
informaData.value.birthDate = new Date(data.birthDate); informaData.value.birthDate = new Date(data.birthDate);
inputBirthDate.value = convertDateDisplay(data.birthDate);
informaData.value.genderId = informaData.value.genderId =
data.genderId !== "00000000-0000-0000-0000-000000000000" data.genderId !== "00000000-0000-0000-0000-000000000000"
? data.genderId ? data.genderId
@ -1137,9 +1155,11 @@ const saveData = async () => {
await myform.value.validate().then(async (success: boolean) => { await myform.value.validate().then(async (success: boolean) => {
if (success) { if (success) {
if (props.statusAdd) { if (props.statusAdd) {
await addData(); if (inputBirthDate.value === "") dayChecked.value = true;
else await addData();
} else { } else {
await editData(); if (inputBirthDate.value === "") dayChecked.value = true;
else await editData();
} }
} else { } else {
} }
@ -1165,4 +1185,25 @@ const getClass = (val: boolean) => {
"full-width cursor-pointer": !val, "full-width cursor-pointer": !val,
}; };
}; };
// change date input
const inputBirthDate = ref<string>("");
const dayChecked = ref<boolean>(false);
watch(
() => inputBirthDate.value,
(value: string) => {
if (value.length === 10) {
const dateVal = convertDate(value);
if (dateVal.isValid) {
dayChecked.value = false;
calRetire(new Date(dateVal.value));
} else {
dayChecked.value = true;
inputBirthDate.value = "";
informaData.value.age = "";
}
}
}
);
</script> </script>

View file

@ -304,21 +304,44 @@ export const useCounterMixin = defineStore("mixin", () => {
} }
} }
function convertDate(date: string) { const convertDate = (date: string) => {
if (date != null && date.length == 10) { if (date != null && date.length == 10) {
const srcDate = date.split("/"); const srcDate = date.toString().split("/");
const dateVal = const dateVal =
Number(srcDate[2]) - 543 + "-" + srcDate[1] + "-" + srcDate[0]; Number(srcDate[2]) - 543 + "-" + srcDate[1] + "-" + srcDate[0];
const check = moment(dateVal).isValid();
if (moment(dateVal).isValid()) { if (check) {
return dateVal; return {
isValid: check,
value: dateVal,
};
} else { } else {
return "" return {
isValid: check,
value: "",
};
} }
} else { } 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) { function appendLeadingZeroes(n: number) {
if (n <= 9) return "0" + n; if (n <= 9) return "0" + n;
@ -973,5 +996,6 @@ export const useCounterMixin = defineStore("mixin", () => {
dialogMessageNotify, dialogMessageNotify,
fails, fails,
convertDate, convertDate,
convertDateDisplay,
}; };
}); });