diff --git a/src/views/account/BudgetView.vue b/src/views/account/BudgetView.vue index 79e1c00..52b0213 100644 --- a/src/views/account/BudgetView.vue +++ b/src/views/account/BudgetView.vue @@ -21,13 +21,7 @@ const formOpen = ref(false) const editId = ref(null) const form = reactive({ category: '', - fixed: false, - baseUnit: 'DAY', - baseAmount: null, - daily: null, - weekly: null, monthly: null, - yearly: null, }) const submitting = ref(false) const formError = ref(null) @@ -46,28 +40,6 @@ const periodLabel = computed(() => `${year.value}년 ${String(month.value).padSt function won(n) { return (n ?? 0).toLocaleString('ko-KR') } -function daysInMonth(y, m) { - return new Date(y, m, 0).getDate() -} -function daysInYear(y) { - return (y % 4 === 0 && y % 100 !== 0) || y % 400 === 0 ? 366 : 365 -} -function baseDays(unit) { - return unit === 'WEEK' ? 7 : unit === 'MONTH' ? 30 : 1 -} - -// 고정 모드 자동 환산 미리보기 (현재 월/년 실제 일수 기준) -const fixedPreview = computed(() => { - if (!form.fixed) return null - const amount = Number(form.baseAmount) || 0 - const daily = amount / baseDays(form.baseUnit) - return { - weekly: Math.round(daily * 7), - monthly: Math.round(daily * daysInMonth(year.value, month.value)), - yearly: Math.round(daily * daysInYear(year.value)), - } -}) - function ratio(s) { if (!s.monthlyBudget) return 0 return Math.min(Math.round((s.spent / s.monthlyBudget) * 100), 999) @@ -178,16 +150,7 @@ async function copyFromPrevMonth() { function openCreate() { editId.value = null - Object.assign(form, { - category: '', - fixed: false, - baseUnit: 'DAY', - baseAmount: null, - daily: null, - weekly: null, - monthly: null, - yearly: null, - }) + Object.assign(form, { category: '', monthly: null }) formError.value = null formOpen.value = true } @@ -195,16 +158,7 @@ function openEdit(s) { const b = budgetsRaw.value.find((x) => x.id === s.id) if (!b) return editId.value = b.id - Object.assign(form, { - category: b.category, - fixed: b.fixed, - baseUnit: b.baseUnit || 'DAY', - baseAmount: b.baseAmount, - daily: b.daily, - weekly: b.weekly, - monthly: b.monthly, - yearly: b.yearly, - }) + Object.assign(form, { category: b.category, monthly: b.monthly }) formError.value = null formOpen.value = true } @@ -215,22 +169,17 @@ async function submit() { formError.value = '카테고리를 입력하세요.' return } - let payload - if (form.fixed) { - if (!form.baseAmount || form.baseAmount <= 0) { - formError.value = '기준 금액을 입력하세요.' - return - } - payload = { category: form.category.trim(), fixed: true, baseUnit: form.baseUnit, baseAmount: Number(form.baseAmount) } - } else { - payload = { - category: form.category.trim(), - fixed: false, - daily: form.daily != null ? Number(form.daily) : null, - weekly: form.weekly != null ? Number(form.weekly) : null, - monthly: form.monthly != null ? Number(form.monthly) : null, - yearly: form.yearly != null ? Number(form.yearly) : null, - } + if (!form.monthly || form.monthly <= 0) { + formError.value = '월 예산 금액을 입력하세요.' + return + } + const payload = { + category: form.category.trim(), + fixed: false, + daily: null, + weekly: null, + monthly: Number(form.monthly), + yearly: null, } submitting.value = true try { @@ -255,97 +204,10 @@ async function remove(s) { } } -// ===== 1회성 예산 ===== -const onetimes = ref([]) -const onetimeFormOpen = ref(false) -const onetimeEditId = ref(null) -const onetimeForm = reactive({ title: '', category: '', amount: null, startDate: '', endDate: '' }) -const onetimeSubmitting = ref(false) -const onetimeFormError = ref(null) - -function todayStr() { - const d = new Date() - return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}` -} - -async function loadOnetime() { - try { onetimes.value = await accountApi.onetimeBudgets() } - catch { onetimes.value = [] } -} - -function statusLabel(s) { - return s === 'UPCOMING' ? '예정' : s === 'ACTIVE' ? '진행' : '종료' -} -function onetimeRatio(o) { - if (!o.amount) return 0 - return Math.min(Math.round((o.spent / o.amount) * 100), 999) -} -function onetimeBarClass(o) { - const r = o.amount ? o.spent / o.amount : 0 - return r >= 1 ? 'over' : r >= 0.8 ? 'warn' : 'ok' -} - -function openOnetimeCreate() { - onetimeEditId.value = null - Object.assign(onetimeForm, { title: '', category: '', amount: null, startDate: todayStr(), endDate: '' }) - onetimeFormError.value = null - onetimeFormOpen.value = true -} -function openOnetimeEdit(o) { - onetimeEditId.value = o.id - Object.assign(onetimeForm, { - title: o.title, - category: o.category || '', - amount: o.amount, - startDate: o.startDate, - endDate: o.endDate, - }) - onetimeFormError.value = null - onetimeFormOpen.value = true -} - -async function submitOnetime() { - onetimeFormError.value = null - if (!onetimeForm.title.trim()) { onetimeFormError.value = '제목을 입력하세요.'; return } - if (!onetimeForm.amount || onetimeForm.amount <= 0) { onetimeFormError.value = '금액을 입력하세요.'; return } - if (!onetimeForm.startDate) { onetimeFormError.value = '시작일을 입력하세요.'; return } - if (!onetimeForm.endDate) { onetimeFormError.value = '종료일을 입력하세요.'; return } - if (onetimeForm.startDate > onetimeForm.endDate) { onetimeFormError.value = '종료일이 시작일보다 빠를 수 없습니다.'; return } - const payload = { - title: onetimeForm.title.trim(), - category: onetimeForm.category || null, - amount: Number(onetimeForm.amount), - startDate: onetimeForm.startDate, - endDate: onetimeForm.endDate, - } - onetimeSubmitting.value = true - try { - if (onetimeEditId.value) await accountApi.updateOnetimeBudget(onetimeEditId.value, payload) - else await accountApi.createOnetimeBudget(payload) - onetimeFormOpen.value = false - await loadOnetime() - } catch (e) { - onetimeFormError.value = e.response?.data?.message || '저장에 실패했습니다.' - } finally { - onetimeSubmitting.value = false - } -} - -async function removeOnetime(o) { - if (!(await dialog.confirm(`'${o.title}' 1회성 예산을 삭제할까요?`, { title: '삭제', danger: true }))) return - try { - await accountApi.removeOnetimeBudget(o.id) - await loadOnetime() - } catch (e) { - alert(e.response?.data?.message || '삭제에 실패했습니다.') - } -} - onMounted(() => { load() loadCategories() loadIncome() - loadOnetime() }) @@ -418,71 +280,6 @@ onMounted(() => {
설정된 예산이 없습니다. "예산 추가"로 시작하세요.
- -등록된 1회성 예산이 없습니다.
-