diff --git a/src/modules/05_leave/components/FormLeave/01_SickForm.vue b/src/modules/05_leave/components/FormLeave/01_SickForm.vue index 42ebfc1..5f3759a 100644 --- a/src/modules/05_leave/components/FormLeave/01_SickForm.vue +++ b/src/modules/05_leave/components/FormLeave/01_SickForm.vue @@ -15,8 +15,7 @@ const typeForm = defineModel("type", { required: true }); const $q = useQuasar(); const dataStore = useLeaveStore(); const mixin = useCounterMixin(); -const { date2Thai, messageError, convertDateToAPI, showLoader, hideLoader } = - mixin; +const { date2Thai, messageError, convertDateToAPI } = mixin; const edit = ref(true); const leaveDocumentRef = ref(null); @@ -66,6 +65,8 @@ const leaveNumberRef = ref(null); const leaveAddressRef = ref(null); const leaveDetailRef = ref(null); +const isLoadLeaveDate = ref(false); + /** maping ref เข้าตัวแปรเพื่อเตรียมตรวจสอบ */ const FormRef: FormRef = { leaveWrote: leaveWroteRef, @@ -149,7 +150,7 @@ const checkDate = computed(() => { // const totalCheck = ref(null); async function fetchCheck() { if (formDataSick.leaveStartDate && formDataSick.leaveEndDate) { - showLoader(); + isLoadLeaveDate.value = true; await http .post(config.API.leaveCheck(), { type: dataStore.typeId ?? null, @@ -177,11 +178,10 @@ async function fetchCheck() { .catch((e: any) => { messageError($q, e); // totalCheck.value = null; - hideLoader(); }) .finally(() => { - hideLoader(); leaveDocumentRef.value.resetValidation(); + isLoadLeaveDate.value = false; }); } } @@ -425,6 +425,7 @@ onMounted(() => { v-model="formDataSick.leaveTotal" label="จำนวนวันที่ลา (วัน)" readonly + :loading="isLoadLeaveDate" > diff --git a/src/modules/05_leave/components/FormLeave/03_Birth.vue b/src/modules/05_leave/components/FormLeave/03_Birth.vue index ce3533b..5b11938 100644 --- a/src/modules/05_leave/components/FormLeave/03_Birth.vue +++ b/src/modules/05_leave/components/FormLeave/03_Birth.vue @@ -13,14 +13,7 @@ import type { FormRef } from "@/modules/05_leave/interface/request/BirthForm"; const $q = useQuasar(); const dataStore = useLeaveStore(); const mixin = useCounterMixin(); -const { - date2Thai, - dateToISO, - messageError, - convertDateToAPI, - showLoader, - hideLoader, -} = mixin; +const { date2Thai, messageError, convertDateToAPI } = mixin; const edit = ref(true); const leaveId = ref(""); @@ -45,6 +38,8 @@ const props = defineProps({ }, }); +const isLoadCheck = ref(false); + /** ข้อมูล v-model ของฟอร์ม */ const formDataBirth = reactive({ type: dataStore.typeId, @@ -145,14 +140,10 @@ const checkDate = computed(() => { } }); -/** - * check ว่าลาได้ไหม จาก api - * @param formData - */ -// const totalCheck = ref(null); +/** ตรวจสอบวันลา */ async function fetchCheck() { if (formDataBirth.leaveStartDate && formDataBirth.leaveEndDate) { - showLoader(); + isLoadCheck.value = true; const checkDate = computed(() => { if ( convertDateToAPI(formDataBirth.leaveEndDate) == @@ -163,9 +154,7 @@ async function fetchCheck() { return false; } }); - // console.log("checkDate.value", checkDate.value); - // console.log("formDataBirth.leaveRangeEnd", formDataBirth.leaveRangeEnd); - // console.log("formDataBirth.leaveRange", formDataBirth.leaveRange); + await http .post(config.API.leaveCheck(), { type: dataStore.typeId ?? null, @@ -176,11 +165,9 @@ async function fetchCheck() { ? formDataBirth.leaveRange : formDataBirth.leaveRangeEnd, }) - .then((res: any) => { - hideLoader(); + .then((res) => { const data = res.data.result; formDataBirth.leaveTotal = data.totalDate; - // totalCheck.value = data.totalDate; reasonLeave.value = data.message != "" ? data.message @@ -189,10 +176,11 @@ async function fetchCheck() { : "ช่วงวันลาที่ระบุไม่ถูกต้อง"; isLeave.value = formDataBirth.leaveTotal > 0 ? data.isLeave : false; }) - .catch((e: any) => { - hideLoader(); - // totalCheck.value = null; + .catch((e) => { messageError($q, e); + }) + .finally(() => { + isLoadCheck.value = false; }); } } @@ -433,6 +421,7 @@ onMounted(() => { v-model="formDataBirth.leaveTotal" label="จำนวนวันที่ลา (วัน)" readonly + :loading="isLoadCheck" > diff --git a/src/modules/05_leave/components/FormLeave/04_HelpWifeBirthForm.vue b/src/modules/05_leave/components/FormLeave/04_HelpWifeBirthForm.vue index e3e29fe..9f8739c 100644 --- a/src/modules/05_leave/components/FormLeave/04_HelpWifeBirthForm.vue +++ b/src/modules/05_leave/components/FormLeave/04_HelpWifeBirthForm.vue @@ -1,7 +1,6 @@