From 492577c34cc55910d2dcedd720b58c15b32be473 Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Thu, 4 Apr 2024 17:25:34 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84=E0=B8=82?= =?UTF-8?q?=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B9=82?= =?UTF-8?q?=E0=B8=84=E0=B8=A3=E0=B8=87=E0=B8=81=E0=B8=B2=E0=B8=A3=20=3D>?= =?UTF-8?q?=20=E0=B8=84=E0=B8=B3=E0=B8=99=E0=B8=A7=E0=B8=99=E0=B8=A7?= =?UTF-8?q?=E0=B8=B1=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../15_development/components/Other.vue | 46 ++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/src/modules/15_development/components/Other.vue b/src/modules/15_development/components/Other.vue index 7cc19ccc3..2829f0ff2 100644 --- a/src/modules/15_development/components/Other.vue +++ b/src/modules/15_development/components/Other.vue @@ -13,8 +13,13 @@ import { useDevelopmentDataStore } from "@/modules/15_development/store/developm const $q = useQuasar(); const store = useDevelopmentDataStore(); -const { showLoader, hideLoader, dialogConfirm, date2Thai, messageError } = - useCounterMixin(); +const { + showLoader, + hideLoader, + calculateDurationYmd, + date2Thai, + messageError, +} = useCounterMixin(); const provinceOp = ref([]); const provinceOpMain = ref([]); @@ -63,10 +68,46 @@ function changeDateStart() { const endDate = new Date(store.formAddProject.dateEnd); if (startDate > endDate) { store.formAddProject.dateEnd = null; + store.formAddProject.totalDate = null; + } else { + daysBetweenDates( + store.formAddProject.dateStart, + store.formAddProject.dateEnd + ); } } } +function changeDateEnd() { + daysBetweenDates( + store.formAddProject.dateStart, + store.formAddProject.dateEnd + ); +} + +async function daysBetweenDates(date1: any, date2: any) { + const newStartDate = resetTimeToMidnight(new Date(date1)); + const newEndDate = resetTimeToMidnight(new Date(date2)); + + const differenceInMilliseconds = + newEndDate.getTime() - newStartDate.getTime(); + + const differenceInDays = Math.floor( + differenceInMilliseconds / (1000 * 60 * 60 * 24) + ); + + store.formAddProject.totalDate = differenceInDays + 1; +} + +function resetTimeToMidnight(date: Date): Date { + const newDate = new Date(date); + newDate.setHours(0); + newDate.setMinutes(0); + newDate.setSeconds(0); + newDate.setMilliseconds(0); + return newDate; +} + /** * Fuction Filter จังหวัด * @param val ค่าตัวพิมพ์ค้นหา @@ -136,6 +177,7 @@ onMounted(() => { :enableTimePicker="false" week-start="0" :min-date="store.formAddProject.dateStart" + @update:model-value="changeDateEnd()" >