fix(finance): shared treasury layout so tab switches stop jumping

Keep title and nav mounted in TreasuryLayout with stable header height, and finish Ant form chrome (MoneyInput, Jalali) on finance pages.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-21 21:47:00 +03:30
co-authored by Cursor
parent 23ae273232
commit cb5944e767
15 changed files with 907 additions and 476 deletions
@@ -1,121 +1,203 @@
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { useRoute } from 'vue-router';
import { onMounted, onUnmounted, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import {
Alert as AAlert,
Button as AButton,
Card as ACard,
Col as ACol,
Divider as ADivider,
Empty as AEmpty,
Flex as AFlex,
Form as AForm,
FormItem as AFormItem,
Input as AInput,
Row as ARow,
Space as ASpace,
Statistic as AStatistic,
Table as ATable,
} from 'ant-design-vue';
import type { TableColumnsType } from 'ant-design-vue';
import { api } from '@/lib/api';
import type { FinancialAccountDto, FinancialMovementDto } from '@mento/shared';
import { UiButton, UiField, UiInput, UiPageHeader } from '@/components/ui';
import MoneyInput from '@/components/MoneyInput.vue';
import TreasuryNav from '@/components/treasury/TreasuryNav.vue';
import { toman } from './treasury-format';
import { formatJalaliNumeric } from '@/lib/jalali';
import { parseMoneyNumber } from '@/lib/money';
import { useTreasuryPageChrome } from './treasuryPageChrome';
const route = useRoute();
const router = useRouter();
const pageChrome = useTreasuryPageChrome();
const account = ref<FinancialAccountDto | null>(null);
const items = ref<FinancialMovementDto[]>([]);
const error = ref('');
const stated = ref('');
const stated = ref<string | number | null>('');
const reason = ref('');
const note = ref('');
const busy = ref(false);
const columns: TableColumnsType<FinancialMovementDto> = [
{
title: 'تاریخ',
key: 'occurredAt',
customRender: ({ record }) => formatJalaliNumeric(new Date(record.occurredAt)),
},
{
title: 'شرح',
key: 'memo',
customRender: ({ record }) => record.memo || '—',
},
{ title: 'نوع', dataIndex: 'kindLabel', key: 'kindLabel' },
{
title: 'ورودی',
key: 'in',
customRender: ({ record }) => (record.direction === 'in' ? toman(record.amount) : '—'),
},
{
title: 'خروجی',
key: 'out',
customRender: ({ record }) => (record.direction === 'out' ? toman(record.amount) : '—'),
},
{
title: 'مانده',
key: 'balanceAfter',
customRender: ({ record }) => (record.balanceAfter ? toman(record.balanceAfter) : '—'),
},
];
async function load() {
const { data } = await api.get<{ account: FinancialAccountDto; items: FinancialMovementDto[] }>(
`/treasury/accounts/${route.params.id}/ledger`,
);
account.value = data.account;
items.value = data.items;
pageChrome?.set({
title: data.account.name || 'جزئیات حساب',
description: 'گردش قطعی این حساب',
});
}
async function reconcile() {
error.value = '';
note.value = '';
busy.value = true;
try {
const { data } = await api.post<{ difference: string; systemBalance: string }>('/treasury/reconciliations', {
accountId: route.params.id,
statedBalance: stated.value,
});
const amount = parseMoneyNumber(String(stated.value ?? ''), 0);
const { data } = await api.post<{ difference: string; systemBalance: string }>(
'/treasury/reconciliations',
{
accountId: route.params.id,
statedBalance: amount ?? 0,
},
);
note.value = `اختلاف ${toman(data.difference)} نسبت به موجودی سیستم ${toman(data.systemBalance)}. موجودی خودکار عوض نشد.`;
} catch {
error.value = 'ثبت مغایرت ناموفق بود.';
} finally {
busy.value = false;
}
}
async function adjust(direction: 'in' | 'out') {
error.value = '';
busy.value = true;
try {
const amount = parseMoneyNumber(String(stated.value ?? ''), 0);
await api.post('/treasury/adjustments', {
accountId: route.params.id,
amount: stated.value,
amount: amount ?? 0,
direction,
reason: reason.value,
});
window.location.reload();
await load();
note.value = 'اصلاح موجودی ثبت شد.';
} catch {
error.value = 'اصلاح موجودی ناموفق بود.';
} finally {
busy.value = false;
}
}
onMounted(async () => {
try {
const { data } = await api.get<{ account: FinancialAccountDto; items: FinancialMovementDto[] }>(
`/treasury/accounts/${route.params.id}/ledger`,
);
account.value = data.account;
items.value = data.items;
} catch {
onMounted(() => {
void load().catch(() => {
error.value = 'گردش حساب بارگذاری نشد.';
}
});
});
onUnmounted(() => {
pageChrome?.clear();
});
</script>
<template>
<section class="page">
<UiPageHeader :title="account?.name || 'حساب'" description="گردش قطعی این حساب" />
<TreasuryNav />
<p v-if="error" class="err">{{ error }}</p>
<div v-if="account" class="stats">
<article><span>موجودی فعلی</span><strong>{{ toman(account.balance) }}</strong></article>
<article><span>مانده افتتاحیه</span><strong>{{ toman(account.openingBalance) }}</strong></article>
<article><span>ورودی</span><strong>{{ toman(account.periodIn) }}</strong></article>
<article><span>خروجی</span><strong>{{ toman(account.periodOut) }}</strong></article>
</div>
<div v-if="account" class="reconcile">
<UiField label="موجودی واقعی"><MoneyInput v-model="stated" :decimals="0" /></UiField>
<UiField label="علت اصلاح"><UiInput v-model="reason" /></UiField>
<UiButton variant="secondary" @click="reconcile">ثبت مغایرت</UiButton>
<UiButton variant="secondary" @click="adjust('in')">اصلاح ورود</UiButton>
<UiButton variant="secondary" @click="adjust('out')">اصلاح خروج</UiButton>
<p v-if="note" class="note">{{ note }}</p>
</div>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>تاریخ</th>
<th>شرح</th>
<th>نوع</th>
<th>ورودی</th>
<th>خروجی</th>
<th>مانده</th>
</tr>
</thead>
<tbody>
<tr v-for="row in items" :key="row.id">
<td>{{ formatJalaliNumeric(new Date(row.occurredAt)) }}</td>
<td>{{ row.memo || '—' }}</td>
<td>{{ row.kindLabel }}</td>
<td>{{ row.direction === 'in' ? toman(row.amount) : '—' }}</td>
<td>{{ row.direction === 'out' ? toman(row.amount) : '—' }}</td>
<td>{{ row.balanceAfter ? toman(row.balanceAfter) : '—' }}</td>
</tr>
<tr v-if="!items.length"><td colspan="6">گردشی ثبت نشده است.</td></tr>
</tbody>
</table>
</div>
</section>
</template>
<a-flex vertical :gap="16">
<a-space>
<a-button type="link" @click="router.push('/finance/accounts')">بازگشت به حساب‌ها</a-button>
</a-space>
<style scoped>
.page { display: grid; gap: 1rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0.7rem; }
.stats article { background: #fff; border: 1px solid #e7eef2; border-radius: 14px; padding: 0.8rem; }
.stats span { color: #64748b; display: block; }
.table-wrap { overflow: auto; background: #fff; border: 1px solid #e7eef2; border-radius: 16px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.7rem; text-align: right; border-bottom: 1px solid #f1f5f9; white-space: nowrap; }
.reconcile { display: grid; grid-template-columns: 1fr 1fr auto auto auto; gap: 0.6rem; align-items: end; }
.note { grid-column: 1 / -1; color: #0f766e; font-weight: 700; }
.err { color: #b91c1c; font-weight: 700; }
@media (max-width: 800px) { .reconcile { grid-template-columns: 1fr; } }
</style>
<a-alert v-if="error" type="error" show-icon :message="error" />
<a-alert v-if="note" type="success" show-icon :message="note" />
<a-row v-if="account" :gutter="[16, 16]">
<a-col :xs="24" :sm="12" :md="6">
<a-card :bordered="false">
<a-statistic title="موجودی فعلی" :value="toman(account.balance)" />
</a-card>
</a-col>
<a-col :xs="24" :sm="12" :md="6">
<a-card :bordered="false">
<a-statistic title="مانده افتتاحیه" :value="toman(account.openingBalance)" />
</a-card>
</a-col>
<a-col :xs="24" :sm="12" :md="6">
<a-card :bordered="false">
<a-statistic title="ورودی" :value="toman(account.periodIn)" />
</a-card>
</a-col>
<a-col :xs="24" :sm="12" :md="6">
<a-card :bordered="false">
<a-statistic title="خروجی" :value="toman(account.periodOut)" />
</a-card>
</a-col>
</a-row>
<a-card v-if="account" :bordered="false">
<a-divider orientation="right">مغایرت و اصلاح</a-divider>
<a-form layout="vertical">
<a-row :gutter="[16, 0]">
<a-col :xs="24" :md="8">
<a-form-item label="موجودی واقعی">
<MoneyInput v-model="stated" :decimals="0" />
</a-form-item>
</a-col>
<a-col :xs="24" :md="8">
<a-form-item label="علت اصلاح">
<a-input v-model:value="reason" />
</a-form-item>
</a-col>
<a-col :xs="24" :md="8">
<a-form-item label=" ">
<a-space wrap>
<a-button :loading="busy" @click="reconcile">ثبت مغایرت</a-button>
<a-button :loading="busy" @click="adjust('in')">اصلاح ورود</a-button>
<a-button :loading="busy" @click="adjust('out')">اصلاح خروج</a-button>
</a-space>
</a-form-item>
</a-col>
</a-row>
</a-form>
<a-divider orientation="right">گردش حساب</a-divider>
<a-empty v-if="!items.length" description="گردشی ثبت نشده است." />
<a-table
v-else
:columns="columns"
:data-source="items"
:pagination="false"
row-key="id"
:scroll="{ x: true }"
/>
</a-card>
</a-flex>
</template>