From b25d6758dece6e025aa0ea204d66896cf7e692e0 Mon Sep 17 00:00:00 2001 From: dyhj625 Date: Thu, 27 Mar 2025 10:30:15 +0900 Subject: [PATCH] =?UTF-8?q?=ED=9C=B4=EA=B0=80=20-3=EA=B0=9C=EC=9D=B4?= =?UTF-8?q?=EC=83=81=20=EC=82=AC=EC=9A=A9=20=20x?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/modal/VacationGrantModal.vue | 1 - src/views/vacation/VacationManagement.vue | 56 +++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/components/modal/VacationGrantModal.vue b/src/components/modal/VacationGrantModal.vue index 9212ebe..2a492b9 100644 --- a/src/components/modal/VacationGrantModal.vue +++ b/src/components/modal/VacationGrantModal.vue @@ -48,7 +48,6 @@ const myRemainingQuota = computed(() => { const isGiftButtonDisabled = computed(() => { return myRemainingQuota.value <= 0; }); -console.log(myRemainingQuota.value) // 사원 별 남은 보내기 개수 const fetchSentVacationCount = async () => { try { diff --git a/src/views/vacation/VacationManagement.vue b/src/views/vacation/VacationManagement.vue index d6ce836..a618e19 100644 --- a/src/views/vacation/VacationManagement.vue +++ b/src/views/vacation/VacationManagement.vue @@ -179,6 +179,46 @@ function handleMonthChange(viewInfo) { const month = String(currentDate.getMonth() + 1).padStart(2, "0"); loadCalendarData(year, month); } + +// 반차/연차 가중치 계산 함수 +const getVacationWeight = (type) => { + if (type === "700101" || type === "700102") return 0.5; + if (type === "700103") return 1; + return 0; +}; + +// 연차 계산 결과 +const vacationUsageInfo = computed(() => { + const myId = userStore.user.id; + const myRemaining = remainingVacationData.value[myId] ?? 0; + + let addAmount = 0; + let deleteAmount = 0; + + for (const [date, type] of selectedDates.value.entries()) { + if (type === "delete") { + // 과거 휴가에서 삭제되는 항목은 복구 대상 + const matched = myVacations.value.find( + (v) => v.date.split("T")[0] === date && !v.receiverId + ); + if (matched) { + deleteAmount += getVacationWeight(matched.type); + } + } else { + addAmount += getVacationWeight(type); + } + } + + const netQuota = myRemaining - addAmount + deleteAmount; + + return { + myRemaining, + addAmount, + deleteAmount, + netQuota + }; +}); + // 캘린더 클릭 function handleDateClick(info) { if (!info.date || !info.dateStr) { @@ -221,6 +261,22 @@ function handleDateClick(info) { } } + // 새로 클릭 시 연차 초과 여부 검사 + const upcomingType = halfDayType.value === "AM" ? "700101" + : halfDayType.value === "PM" ? "700102" + : "700103"; + const upcomingWeight = getVacationWeight(upcomingType); + const isAddingNew = !selectedDates.value.has(clickedDateStr) && !isMyVacation; + + if (isAddingNew) { + const projectedQuota = vacationUsageInfo.value.netQuota - upcomingWeight; + + if (projectedQuota < -3) { + toastStore.onToast("연차를 더 이상 선택할 수 없습니다.", "e"); + return; + } + } + // 이미 활성화된 날짜를 한 번 더 클릭하면 비활성화 if (currentValue && currentValue !== "delete") { selectedDates.value.delete(clickedDateStr);