From 4a852f580d0efddd4f96263654400470e393457f Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Tue, 24 Dec 2024 11:39:10 +0700 Subject: [PATCH] fix bug --- .../04_SpecialTime/DialogApprove.vue | 135 +++++++----------- .../09_leave/views/04_SpecialTimeMain.vue | 50 +++---- 2 files changed, 71 insertions(+), 114 deletions(-) diff --git a/src/modules/09_leave/components/04_SpecialTime/DialogApprove.vue b/src/modules/09_leave/components/04_SpecialTime/DialogApprove.vue index 64d7256a8..9203da9ce 100644 --- a/src/modules/09_leave/components/04_SpecialTime/DialogApprove.vue +++ b/src/modules/09_leave/components/04_SpecialTime/DialogApprove.vue @@ -7,10 +7,8 @@ import config from "@/app.config"; import { useCounterMixin } from "@/stores/mixin"; import { useSpecialTimeStore } from "@/modules/09_leave/stores/SpecialTimeStore"; -import type { - dataRowRound, - MyObjectRoundRef, -} from "@/modules/09_leave/interface/response/specialTime"; +import type { dataRowRound } from "@/modules/09_leave/interface/response/specialTime"; +import type { DataOption } from "@/modules/09_leave/interface/index/Main"; import DialogHeader from "@/components/DialogHeader.vue"; @@ -19,7 +17,7 @@ const $q = useQuasar(); const SpecialTimeStore = useSpecialTimeStore(); const mixin = useCounterMixin(); const { dialogConfirm, showLoader, success, messageError, hideLoader } = mixin; -const option = ref(SpecialTimeStore.optionStatus); +const option = ref(SpecialTimeStore.optionStatus); /** props*/ const props = defineProps({ @@ -32,14 +30,9 @@ const props = defineProps({ checkOutStatus: { type: String, default: "" }, closeDialog: { type: Function, default: () => {} }, detailData: Object, + fetchData: { type: Function, default: () => {} }, }); -const checkInRef = ref(null); -const checkOutRef = ref(null); -const checkInStatusRef = ref(null); -const checkOutStatusRef = ref(null); -const reasonRef = ref(null); - const formData = reactive({ checkIn: "", checkOut: "", @@ -50,73 +43,35 @@ const formData = reactive({ checkOutEdit: false, }); -const objectRound: MyObjectRoundRef = { - checkIn: checkInRef, - checkOut: checkOutRef, - checkInStatus: checkInStatusRef, - checkOutStatus: checkOutStatusRef, - note: reasonRef, -}; - -/** function validateFom*/ -function validateForm() { - const hasError = []; - for (const key in objectRound) { - if (Object.prototype.hasOwnProperty.call(objectRound, key)) { - const property = objectRound[key]; - if (property.value && typeof property.value.validate === "function") { - const isValid = property.value.validate(); - hasError.push(isValid); - } - } - } - if (hasError.every((result) => result === true)) { - onSubmit(); - } -} - /** function confrim*/ -function onSubmit() { - dialogConfirm( - $q, - async () => { - await approveData(); - props.closeDialog?.(); - }, - "ยืนยันการบันทึกข้อมูล", - "ต้องการยืนยันการบันทึกข้อมูลนี้หรือไม่ ?" - ); -} - -/** function บันทึกข้อมูล*/ -async function approveData() { - showLoader(); - const body = { - checkInTime: formData.checkIn, - checkOutTime: formData.checkOut, - checkInStatus: formData.checkInStatus, - checkOutStatus: formData.checkOutStatus, - reason: formData.note, - }; - await http - .put(config.API.specialTimeApprove(props.id), body) - .then(() => { - success($q, "บันทึกข้อมูลสำเร็จ"); - }) - .catch((e) => { - messageError($q, e); - }) - .finally(async () => { - SpecialTimeStore.fetchData(); - hideLoader(); - }); +async function onSubmit() { + dialogConfirm($q, async () => { + showLoader(); + await http + .put(config.API.specialTimeApprove(props.id), { + checkInTime: formData.checkIn, + checkOutTime: formData.checkOut, + checkInStatus: formData.checkInStatus, + checkOutStatus: formData.checkOutStatus, + reason: formData.note, + }) + .then(async () => { + await props.fetchData(); + success($q, "บันทึกข้อมูลสำเร็จ"); + props.closeDialog?.(); + }) + .catch((e) => { + messageError($q, e); + }) + .finally(async () => { + hideLoader(); + }); + }); } /** function closeDialog*/ function close() { - if (props.closeDialog) { - props.closeDialog(); - } + props.closeDialog(); } /** @@ -127,7 +82,7 @@ function close() { function filterOptionFn(val: string, update: Function) { update(() => { option.value = SpecialTimeStore.optionStatus.filter( - (e: any) => e.name.search(val) !== -1 + (e: DataOption) => e.name.search(val) !== -1 ); }); } @@ -176,7 +131,7 @@ watch(