Compare commits
6 Commits
37b4a9f4cf
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| 1b53af525e | |||
| f8e6c6b0ee | |||
| e1c077dccd | |||
| 1e9ff0408c | |||
| b2f3b156b2 | |||
| 28ebe06767 |
@@ -1,4 +1,4 @@
|
||||
<script setup>
|
||||
1<script setup>
|
||||
import { computed, nextTick, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { accountApi } from '@/api/accountApi'
|
||||
import { reminders } from '@/native/reminders'
|
||||
@@ -127,6 +127,56 @@ const repayTargetIsCard = computed(() => {
|
||||
const w = wallets.value.find((x) => x.id === form.toWalletId)
|
||||
return !!w && w.type === 'CARD'
|
||||
})
|
||||
// 금리가 설정된 대출 계좌를 선택한 경우 자동계산 활성
|
||||
const repayTargetLoanWallet = computed(() => {
|
||||
const w = wallets.value.find((x) => x.id === form.toWalletId)
|
||||
return w?.type === 'LOAN' && w.loanRate ? w : null
|
||||
})
|
||||
// 납입금액 입력용 (원리금균등만 사용)
|
||||
const loanPaymentAmount = ref(null)
|
||||
|
||||
function monthlyInterestOf(loan) {
|
||||
return Math.round(Math.abs(loan.balance || 0) * (Number(loan.loanRate) / 100 / 12))
|
||||
}
|
||||
|
||||
// 상환방식별 자동계산: 원금균등·만기일시는 납입금액 입력 불필요
|
||||
const loanAutoResult = computed(() => {
|
||||
const loan = repayTargetLoanWallet.value
|
||||
if (!loan) return null
|
||||
const interest = monthlyInterestOf(loan)
|
||||
if (loan.loanMethod === 'BULLET') {
|
||||
return { interest, principal: 0, total: interest, needsInput: false }
|
||||
}
|
||||
if (loan.loanMethod === 'EQUAL_PRINCIPAL' && loan.loanAmount && loan.loanMonths) {
|
||||
const principal = Math.round(Number(loan.loanAmount) / loan.loanMonths)
|
||||
return { interest, principal, total: principal + interest, needsInput: false }
|
||||
}
|
||||
return { interest: null, principal: null, total: null, needsInput: true }
|
||||
})
|
||||
|
||||
watch(loanAutoResult, (r) => {
|
||||
if (r && !r.needsInput) {
|
||||
form.interest = r.interest
|
||||
form.principal = r.principal
|
||||
loanPaymentAmount.value = r.total
|
||||
}
|
||||
})
|
||||
|
||||
function calcLoanRepayment(payment) {
|
||||
const loan = repayTargetLoanWallet.value
|
||||
if (!loan || !payment || payment <= 0) return
|
||||
const interest = monthlyInterestOf(loan)
|
||||
form.interest = Math.min(interest, payment)
|
||||
form.principal = Math.max(0, payment - form.interest)
|
||||
}
|
||||
watch(loanPaymentAmount, (val) => {
|
||||
if (loanAutoResult.value?.needsInput && val) calcLoanRepayment(Number(val))
|
||||
})
|
||||
watch(() => form.toWalletId, () => {
|
||||
loanPaymentAmount.value = null
|
||||
form.principal = null
|
||||
form.interest = null
|
||||
})
|
||||
// 카드 지출일 때만 할부 입력 노출 (2~24개월, 일시불은 빈값)
|
||||
const showInstallment = computed(() => form.type === 'EXPENSE' && form.walletKind === 'CARD')
|
||||
const installmentMonthly = computed(() => {
|
||||
@@ -282,7 +332,19 @@ const categoryMajor = ref('') // 펼쳐진 대분류 이름
|
||||
const majorOptionsData = computed(() =>
|
||||
categories.value.filter((c) => c.type === form.type && c.parentId == null)
|
||||
)
|
||||
// 특정 대분류의 소분류 객체 목록
|
||||
// 대분류를 4개씩 행으로 묶음
|
||||
const majorRows = computed(() => {
|
||||
const items = majorOptionsData.value
|
||||
const rows = []
|
||||
for (let i = 0; i < items.length; i += 4) rows.push(items.slice(i, i + 4))
|
||||
return rows
|
||||
})
|
||||
// 현재 펼쳐진 대분류 객체
|
||||
const selectedMajorObj = computed(() =>
|
||||
majorOptionsData.value.find((m) => m.name === categoryMajor.value) ?? null
|
||||
)
|
||||
|
||||
// 특정 대분류의 소분류 목록
|
||||
function subsByMajor(majorId) {
|
||||
return categories.value.filter((c) => c.parentId === majorId)
|
||||
}
|
||||
@@ -318,10 +380,19 @@ const allCategoryNames = computed(() => [...new Set(categories.value.map((c) =>
|
||||
|
||||
// 모달 내 분류 인라인 추가
|
||||
const addingCategory = ref(false)
|
||||
const addingAsMajor = ref(true) // true=대분류 추가, false=소분류 추가
|
||||
const newCategoryName = ref('')
|
||||
const catSubmitting = ref(false)
|
||||
function startAddCategory() {
|
||||
function startAddMajorCategory() {
|
||||
categoryMajor.value = ''
|
||||
form.category = ''
|
||||
newCategoryName.value = ''
|
||||
addingAsMajor.value = true
|
||||
addingCategory.value = true
|
||||
}
|
||||
function startAddSubCategory() {
|
||||
newCategoryName.value = ''
|
||||
addingAsMajor.value = false
|
||||
addingCategory.value = true
|
||||
}
|
||||
function cancelAddCategory() {
|
||||
@@ -1114,39 +1185,67 @@ onMounted(async () => {
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
<!-- 금리 설정된 대출 계좌: 방식별 자동계산 -->
|
||||
<template v-if="repayTargetLoanWallet">
|
||||
<!-- 원리금균등: 납입금액 직접 입력 -->
|
||||
<template v-if="loanAutoResult?.needsInput">
|
||||
<label>납입금액(원리금균등)
|
||||
<input v-model.number="loanPaymentAmount" type="number" min="0"
|
||||
placeholder="이번 달 납입할 총금액" :disabled="submitting" />
|
||||
</label>
|
||||
</template>
|
||||
<!-- 원금균등·만기일시: 자동계산 결과 표시 -->
|
||||
<template v-else>
|
||||
<div class="loan-breakdown">
|
||||
<span class="bd-label">{{ repayTargetLoanWallet.loanMethod === 'BULLET' ? '만기일시' : '원금균등' }} 자동계산</span>
|
||||
<span>납입 <b>{{ (loanAutoResult?.total || 0).toLocaleString('ko-KR') }}원</b></span>
|
||||
</div>
|
||||
</template>
|
||||
<!-- 계산 결과 표시 + 수동 조정 -->
|
||||
<div v-if="(form.interest ?? null) !== null || (form.principal ?? null) !== null" class="loan-breakdown">
|
||||
<span>이자 <b>{{ (form.interest || 0).toLocaleString('ko-KR') }}원</b></span>
|
||||
<span>원금 <b>{{ (form.principal || 0).toLocaleString('ko-KR') }}원</b></span>
|
||||
</div>
|
||||
<label>이자(조정)<input v-model.number="form.interest" type="number" min="0" :disabled="submitting" /></label>
|
||||
<label>원금(조정)<input v-model.number="form.principal" type="number" min="0" :disabled="submitting" /></label>
|
||||
</template>
|
||||
<template v-else>
|
||||
<label>원금<input v-model.number="form.principal" type="number" min="0" placeholder="원 (이체로 기록)" :disabled="submitting" /></label>
|
||||
<label>이자<input v-model.number="form.interest" type="number" min="0" placeholder="원 (지출·분류 이자)" :disabled="submitting" /></label>
|
||||
</template>
|
||||
<label v-if="repayTargetIsCard">연회비<input v-model.number="form.annualFee" type="number" min="0" placeholder="원 (지출·분류 연회비)" :disabled="submitting" /></label>
|
||||
</template>
|
||||
|
||||
<label v-if="form.type === 'INCOME' || form.type === 'EXPENSE'">분류
|
||||
<div v-if="!addingCategory" class="cat-accordion">
|
||||
<div v-for="m in majorOptionsData" :key="m.id" class="acc-major">
|
||||
<div v-if="!addingCategory" class="cat-picker">
|
||||
<!-- 대분류 행별 렌더링: 선택된 대분류가 속한 행 바로 아래 소분류 삽입 -->
|
||||
<template v-for="(row, rowIdx) in majorRows" :key="rowIdx">
|
||||
<div class="acc-major-grid">
|
||||
<button
|
||||
type="button" class="acc-major-btn"
|
||||
:class="{ active: form.category === m.name && !subsByMajor(m.id).length, expanded: categoryMajor === m.name && subsByMajor(m.id).length }"
|
||||
v-for="m in row" :key="m.id"
|
||||
type="button" class="acc-chip major"
|
||||
:class="{ active: categoryMajor === m.name }"
|
||||
:disabled="submitting"
|
||||
@click="onMajorClick(m)"
|
||||
>
|
||||
<span class="acc-arrow">{{ subsByMajor(m.id).length ? (categoryMajor === m.name ? '▼' : '▶') : '' }}</span>
|
||||
{{ m.name }}
|
||||
</button>
|
||||
<div v-if="categoryMajor === m.name && subsByMajor(m.id).length" class="acc-subs">
|
||||
>{{ m.name }}</button>
|
||||
</div>
|
||||
<div v-if="selectedMajorObj && row.some(m => m.id === selectedMajorObj.id) && subsByMajor(selectedMajorObj.id).length" class="acc-sub-grid">
|
||||
<button
|
||||
v-for="s in subsByMajor(m.id)" :key="s.id"
|
||||
type="button" class="acc-sub-btn"
|
||||
v-for="s in subsByMajor(selectedMajorObj.id)" :key="s.id"
|
||||
type="button" class="acc-chip sub"
|
||||
:class="{ active: form.category === s.name }"
|
||||
:disabled="submitting"
|
||||
@click="form.category = s.name"
|
||||
>{{ s.name }}</button>
|
||||
<button type="button" class="acc-chip add-chip sub-add" :disabled="submitting" @click="startAddSubCategory">+ 소분류</button>
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" class="cat-add-btn acc-add" :disabled="submitting" @click="startAddCategory">+ 추가</button>
|
||||
</template>
|
||||
<button type="button" class="acc-chip add-chip" :disabled="submitting" @click="startAddMajorCategory">+ 대분류</button>
|
||||
</div>
|
||||
<div v-else class="cat-input">
|
||||
<input
|
||||
v-model="newCategoryName" type="text"
|
||||
:placeholder="form.type === 'EXPENSE' ? '새 지출 분류' : '새 수입 분류'"
|
||||
:placeholder="addingAsMajor ? (form.type === 'EXPENSE' ? '새 지출 대분류' : '새 수입 대분류') : `${categoryMajor} > 새 소분류`"
|
||||
:disabled="catSubmitting" @keyup.enter.prevent="confirmAddCategory"
|
||||
/>
|
||||
<button type="button" class="cat-add-btn primary" :disabled="catSubmitting" @click="confirmAddCategory">확인</button>
|
||||
@@ -1896,78 +1995,77 @@ button.primary {
|
||||
border-color: hsla(160, 100%, 37%, 1);
|
||||
color: hsla(160, 100%, 37%, 1);
|
||||
}
|
||||
/* 분류 아코디언 */
|
||||
.cat-accordion {
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 6px;
|
||||
overflow: hidden;
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
.acc-major-btn {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
padding: 0.45rem 0.7rem;
|
||||
border: 0;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
text-align: left;
|
||||
font-size: 0.88rem;
|
||||
color: var(--color-text);
|
||||
}
|
||||
.acc-major-btn:last-child {
|
||||
border-bottom: 0;
|
||||
}
|
||||
.acc-major-btn.active,
|
||||
.acc-major-btn.expanded {
|
||||
background: var(--color-background-soft);
|
||||
font-weight: 600;
|
||||
}
|
||||
.acc-major-btn.active {
|
||||
color: hsla(160, 100%, 37%, 1);
|
||||
}
|
||||
.acc-arrow {
|
||||
font-size: 0.6rem;
|
||||
flex: none;
|
||||
width: 0.9rem;
|
||||
text-align: center;
|
||||
opacity: 0.6;
|
||||
}
|
||||
.acc-subs {
|
||||
/* 분류 칩 그리드 */
|
||||
.cat-picker {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
.acc-sub-btn {
|
||||
padding: 0.38rem 0.7rem 0.38rem 2rem;
|
||||
border: 0;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
.acc-major-grid,
|
||||
.acc-sub-grid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.35rem;
|
||||
}
|
||||
.acc-sub-grid {
|
||||
padding: 0.4rem;
|
||||
border-radius: 6px;
|
||||
background: var(--color-background-soft);
|
||||
}
|
||||
.acc-chip {
|
||||
flex: 1 1 calc(25% - 0.35rem);
|
||||
min-width: 0;
|
||||
padding: 0.38rem 0.4rem;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 6px;
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
text-align: left;
|
||||
font-size: 0.84rem;
|
||||
font-size: 0.82rem;
|
||||
color: var(--color-text);
|
||||
text-align: center;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.acc-sub-btn:last-child {
|
||||
border-bottom: 0;
|
||||
}
|
||||
.acc-sub-btn.active {
|
||||
.acc-chip.major.active {
|
||||
border-color: hsla(160, 100%, 37%, 1);
|
||||
background: hsla(160, 100%, 37%, 0.1);
|
||||
color: hsla(160, 100%, 37%, 1);
|
||||
font-weight: 600;
|
||||
}
|
||||
.acc-add {
|
||||
display: block;
|
||||
width: 100%;
|
||||
border: 0;
|
||||
border-top: 1px dashed var(--color-border);
|
||||
border-radius: 0;
|
||||
background: transparent;
|
||||
text-align: center;
|
||||
.acc-chip.sub {
|
||||
background: var(--color-background);
|
||||
}
|
||||
.acc-chip.sub.active {
|
||||
border-color: hsla(160, 100%, 37%, 1);
|
||||
background: hsla(160, 100%, 37%, 0.1);
|
||||
color: hsla(160, 100%, 37%, 1);
|
||||
font-weight: 600;
|
||||
}
|
||||
.acc-chip.add-chip {
|
||||
opacity: 0.55;
|
||||
border-style: dashed;
|
||||
}
|
||||
.acc-chip.add-chip.sub-add {
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
.loan-breakdown {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
padding: 0.45rem 0.6rem;
|
||||
border-radius: 6px;
|
||||
background: var(--color-background-soft);
|
||||
font-size: 0.85rem;
|
||||
color: var(--color-text);
|
||||
}
|
||||
.loan-breakdown b {
|
||||
color: hsla(160, 100%, 37%, 1);
|
||||
}
|
||||
.loan-breakdown .bd-label {
|
||||
width: 100%;
|
||||
font-size: 0.78rem;
|
||||
opacity: 0.6;
|
||||
font-size: 0.82rem;
|
||||
margin-bottom: 0.1rem;
|
||||
}
|
||||
.tag-field {
|
||||
display: flex;
|
||||
|
||||
@@ -33,6 +33,12 @@ const form = reactive({
|
||||
openingBalance: 0,
|
||||
openingDate: '',
|
||||
currentValue: null,
|
||||
// 대출(LOAN) 전용
|
||||
loanAmount: null,
|
||||
loanRate: null,
|
||||
loanMethod: '',
|
||||
loanMonths: null,
|
||||
loanStart: '',
|
||||
})
|
||||
const submitting = ref(false)
|
||||
const formError = ref(null)
|
||||
@@ -196,7 +202,7 @@ function issuerLabel(t) {
|
||||
return t === 'BANK' ? '은행명' : t === 'CARD' ? '카드사' : t === 'INVEST' ? '증권사' : '대출기관'
|
||||
}
|
||||
function openingLabel(t) {
|
||||
return t === 'BANK' || t === 'CASH' ? '초기 잔액' : t === 'CARD' ? '초기 미결제 금액' : t === 'INVEST' ? '투자금(투입원금)' : '대출 잔액(원금)'
|
||||
return t === 'BANK' || t === 'CASH' ? '초기 잔액' : t === 'CARD' ? '초기 미결제 금액' : t === 'INVEST' ? '투자금(투입원금)' : '기록 시작 시 잔액'
|
||||
}
|
||||
// 투자 수익률(%) — 투입원금 대비 평가손익
|
||||
function returnPct(w) {
|
||||
@@ -229,6 +235,11 @@ function openCreate() {
|
||||
openingBalance: 0,
|
||||
openingDate: '',
|
||||
currentValue: null,
|
||||
loanAmount: null,
|
||||
loanRate: null,
|
||||
loanMethod: '',
|
||||
loanMonths: null,
|
||||
loanStart: '',
|
||||
})
|
||||
formError.value = null
|
||||
formOpen.value = true
|
||||
@@ -245,6 +256,11 @@ function openEdit(w) {
|
||||
openingBalance: isLiability(w.type) ? -(w.openingBalance || 0) : w.openingBalance || 0,
|
||||
openingDate: w.openingDate || '',
|
||||
currentValue: w.currentValue ?? null,
|
||||
loanAmount: w.loanAmount ?? null,
|
||||
loanRate: w.loanRate ?? null,
|
||||
loanMethod: w.loanMethod || '',
|
||||
loanMonths: w.loanMonths ?? null,
|
||||
loanStart: w.loanStart || '',
|
||||
})
|
||||
formError.value = null
|
||||
formOpen.value = true
|
||||
@@ -258,6 +274,7 @@ async function submit() {
|
||||
}
|
||||
submitting.value = true
|
||||
const magnitude = Number(form.openingBalance) || 0
|
||||
const isLoan = form.type === 'LOAN'
|
||||
const payload = {
|
||||
type: form.type,
|
||||
name: form.name.trim(),
|
||||
@@ -271,6 +288,11 @@ async function submit() {
|
||||
form.type === 'INVEST' && form.currentValue !== '' && form.currentValue != null
|
||||
? Number(form.currentValue)
|
||||
: null,
|
||||
loanAmount: isLoan && form.loanAmount ? Number(form.loanAmount) : null,
|
||||
loanRate: isLoan && form.loanRate !== null && form.loanRate !== '' ? Number(form.loanRate) : null,
|
||||
loanMethod: isLoan && form.loanMethod ? form.loanMethod : null,
|
||||
loanMonths: isLoan && form.loanMonths ? Number(form.loanMonths) : null,
|
||||
loanStart: isLoan && form.loanStart ? form.loanStart : null,
|
||||
}
|
||||
try {
|
||||
if (editId.value) await accountApi.updateWallet(editId.value, payload)
|
||||
@@ -297,6 +319,9 @@ async function remove(w) {
|
||||
function cardTypeLabel(v) {
|
||||
return v === 'CHECK' ? '체크' : v === 'CREDIT' ? '신용' : ''
|
||||
}
|
||||
function loanMethodLabel(v) {
|
||||
return v === 'EQUAL_PAYMENT' ? '원리금균등' : v === 'EQUAL_PRINCIPAL' ? '원금균등' : v === 'BULLET' ? '만기일시' : ''
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await load()
|
||||
@@ -362,6 +387,10 @@ onBeforeUnmount(() => sortable?.destroy())
|
||||
>{{ revealedAccts.has(w.id) ? '🙈' : '👁' }}</button>
|
||||
</template>
|
||||
<template v-if="w.type === 'INVEST'"> · 투자금 {{ won(w.investedAmount) }}</template>
|
||||
<template v-if="w.type === 'LOAN'">
|
||||
<span v-if="w.loanAmount"> · 실행 {{ won(w.loanAmount) }}원</span>
|
||||
<span v-if="w.loanRate"> · {{ w.loanRate }}%<span v-if="w.loanMethod"> / {{ loanMethodLabel(w.loanMethod) }}</span></span>
|
||||
</template>
|
||||
</span>
|
||||
</div>
|
||||
<div class="balance-wrap">
|
||||
@@ -458,6 +487,33 @@ onBeforeUnmount(() => sortable?.destroy())
|
||||
</template>
|
||||
<label>기준일<input v-model="form.openingDate" type="date" :disabled="submitting" /></label>
|
||||
|
||||
<!-- 대출 전용 -->
|
||||
<template v-if="form.type === 'LOAN'">
|
||||
<label>대출 실행 금액(원금)
|
||||
<input v-model.number="form.loanAmount" type="number" min="0"
|
||||
placeholder="처음 빌린 금액 (예: 10000000)" :disabled="submitting" />
|
||||
</label>
|
||||
<label>연이자율(%)
|
||||
<input v-model.number="form.loanRate" type="number" min="0" max="100" step="0.01"
|
||||
placeholder="예: 5.25" :disabled="submitting" />
|
||||
</label>
|
||||
<label>상환방식
|
||||
<select v-model="form.loanMethod" :disabled="submitting">
|
||||
<option value="">(선택 안 함)</option>
|
||||
<option value="EQUAL_PAYMENT">원리금균등상환</option>
|
||||
<option value="EQUAL_PRINCIPAL">원금균등상환</option>
|
||||
<option value="BULLET">만기일시상환</option>
|
||||
</select>
|
||||
</label>
|
||||
<label>대출기간(개월)
|
||||
<input v-model.number="form.loanMonths" type="number" min="1"
|
||||
placeholder="예: 120 (10년)" :disabled="submitting" />
|
||||
</label>
|
||||
<label>대출시작일
|
||||
<input v-model="form.loanStart" type="date" :disabled="submitting" />
|
||||
</label>
|
||||
</template>
|
||||
|
||||
<p v-if="formError" class="msg error">{{ formError }}</p>
|
||||
|
||||
<div class="buttons">
|
||||
|
||||
Reference in New Issue
Block a user