Add 10/20/50/100 page-size pagination across treasury list pages.

EOF

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-17 16:07:13 +03:30
co-authored by Cursor
parent 64280e85c4
commit 634af8a653
13 changed files with 465 additions and 66 deletions
@@ -13,7 +13,6 @@ import {
Image as AImage, Image as AImage,
Input as AInput, Input as AInput,
Modal as AModal, Modal as AModal,
Pagination as APagination,
Row as ARow, Row as ARow,
Select as ASelect, Select as ASelect,
Space as ASpace, Space as ASpace,
@@ -38,12 +37,13 @@ import {
import JalaliDateInput from '@/components/JalaliDateInput.vue'; import JalaliDateInput from '@/components/JalaliDateInput.vue';
import MoneyInput from '@/components/MoneyInput.vue'; import MoneyInput from '@/components/MoneyInput.vue';
import { api } from '@/lib/api'; import { api } from '@/lib/api';
import { formatJalaliNumeric, formatLocalDateInput, toFaDigits } from '@/lib/jalali'; import { formatJalaliNumeric, formatLocalDateInput } from '@/lib/jalali';
import { parseMoneyNumber } from '@/lib/money'; import { parseMoneyNumber } from '@/lib/money';
import { PAGE_SIZE_OPTIONS, usePageSize } from '@/lib/pageSize';
import { useAuthStore } from '@/stores/auth'; import { useAuthStore } from '@/stores/auth';
import { toman } from '@/views/treasury/treasury-format'; import { toman } from '@/views/treasury/treasury-format';
import { useTreasuryListPaging } from '@/views/treasury/useTreasuryListPaging';
import { useTreasuryMobile } from '@/views/treasury/useTreasuryMobile'; import { useTreasuryMobile } from '@/views/treasury/useTreasuryMobile';
import TreasuryListPagination from '@/components/treasury/TreasuryListPagination.vue';
const props = defineProps<{ const props = defineProps<{
rows: FinancialDocumentDto[]; rows: FinancialDocumentDto[];
@@ -100,9 +100,16 @@ const previewUrls = ref<Record<string, string>>({});
const editOpen = ref(false); const editOpen = ref(false);
const editSaving = ref(false); const editSaving = ref(false);
const editId = ref<string | null>(null); const editId = ref<string | null>(null);
const page = ref(1); const {
const pageSize = usePageSize('treasury.documents', 10); page,
const pageSizeOptions = PAGE_SIZE_OPTIONS.map(String); pageSize,
pageSizeOptions,
total,
pagedRows,
resetPage,
onPageSizeChange,
showTotal,
} = useTreasuryListPaging(() => props.rows, 'treasury.documents');
const editForm = reactive({ const editForm = reactive({
title: '', title: '',
notes: '', notes: '',
@@ -293,35 +300,11 @@ const searchModel = computed({
set: (value: string) => emit('update:q', value), set: (value: string) => emit('update:q', value),
}); });
const pageCount = computed(() => Math.max(1, Math.ceil(props.rows.length / pageSize.value)));
const pagedRows = computed(() => {
const start = (page.value - 1) * pageSize.value;
return props.rows.slice(start, start + pageSize.value);
});
watch(
() => [props.rows.length, props.q, pageSize.value] as const,
() => {
if (page.value > pageCount.value) page.value = pageCount.value;
if (page.value < 1) page.value = 1;
},
);
function onSearch() { function onSearch() {
page.value = 1; resetPage();
emit('reload'); emit('reload');
} }
function onPageSizeChange(size: number) {
pageSize.value = size;
page.value = 1;
}
function paginationTotal(total: number) {
return `مجموع: ${toFaDigits(total)} مورد (صفحه ${toFaDigits(page.value)} از ${toFaDigits(pageCount.value)})`;
}
function asDoc(record: unknown): FinancialDocumentDto { function asDoc(record: unknown): FinancialDocumentDto {
return record as FinancialDocumentDto; return record as FinancialDocumentDto;
} }
@@ -496,17 +479,14 @@ function modalContainer() {
</a-card> </a-card>
</a-flex> </a-flex>
<a-flex v-if="rows.length" justify="space-between" align="center" wrap="wrap" :gap="12" style="margin-top: 16px"> <TreasuryListPagination
<a-pagination v-model:page="page"
v-model:current="page" :total="total"
:page-size="pageSize" :page-size="pageSize"
:total="rows.length" :page-size-options="pageSizeOptions"
:page-size-options="pageSizeOptions" :show-total="showTotal"
show-size-changer @update:page-size="onPageSizeChange"
:show-total="paginationTotal" />
@update:page-size="onPageSizeChange"
/>
</a-flex>
</a-card> </a-card>
<a-modal <a-modal
@@ -0,0 +1,30 @@
<script setup lang="ts">
import { Pagination as APagination } from 'ant-design-vue';
const page = defineModel<number>('page', { required: true });
defineProps<{
total: number;
pageSize: number;
pageSizeOptions: string[];
showTotal: (total: number) => string;
}>();
const emit = defineEmits<{
'update:pageSize': [size: number];
}>();
</script>
<template>
<a-pagination
v-if="total > 0"
v-model:current="page"
:page-size="pageSize"
:total="total"
:page-size-options="pageSizeOptions"
show-size-changer
:show-total="showTotal"
style="margin-top: 16px"
@update:page-size="emit('update:pageSize', $event)"
/>
</template>
@@ -7,7 +7,9 @@ import {
Typography, Typography,
} from 'ant-design-vue'; } from 'ant-design-vue';
import type { TreasuryPartyBalanceDto } from '@mento/shared'; import type { TreasuryPartyBalanceDto } from '@mento/shared';
import TreasuryListPagination from '@/components/treasury/TreasuryListPagination.vue';
import { toman } from '@/views/treasury/treasury-format'; import { toman } from '@/views/treasury/treasury-format';
import { useTreasuryListPaging } from '@/views/treasury/useTreasuryListPaging';
import { useTreasuryMobile } from '@/views/treasury/useTreasuryMobile'; import { useTreasuryMobile } from '@/views/treasury/useTreasuryMobile';
const props = defineProps<{ const props = defineProps<{
@@ -19,6 +21,16 @@ const isMobile = useTreasuryMobile();
const { Text: ATypographyText } = Typography; const { Text: ATypographyText } = Typography;
const AListItem = AList.Item; const AListItem = AList.Item;
const {
page,
pageSize,
pageSizeOptions,
total,
pagedRows,
onPageSizeChange,
showTotal,
} = useTreasuryListPaging(() => props.rows, 'treasury.party-balances');
const kindLabel: Record<string, string> = { const kindLabel: Record<string, string> = {
person: 'مشتری', person: 'مشتری',
company: 'شرکت', company: 'شرکت',
@@ -58,7 +70,7 @@ function kindOf(record: TreasuryPartyBalanceDto) {
<template> <template>
<a-list <a-list
v-if="isMobile" v-if="isMobile"
:data-source="rows" :data-source="pagedRows"
:locale="{ emptyText: 'مانده‌ای نیست.' }" :locale="{ emptyText: 'مانده‌ای نیست.' }"
> >
<template #renderItem="{ item }"> <template #renderItem="{ item }">
@@ -87,9 +99,17 @@ function kindOf(record: TreasuryPartyBalanceDto) {
<a-table <a-table
v-else v-else
:columns="columns" :columns="columns"
:data-source="rows" :data-source="pagedRows"
:pagination="false" :pagination="false"
row-key="key" row-key="key"
:locale="{ emptyText: 'مانده‌ای نیست.' }" :locale="{ emptyText: 'مانده‌ای نیست.' }"
/> />
<TreasuryListPagination
v-model:page="page"
:total="total"
:page-size="pageSize"
:page-size-options="pageSizeOptions"
:show-total="showTotal"
@update:page-size="onPageSizeChange"
/>
</template> </template>
@@ -24,7 +24,9 @@ import type { TableColumnsType } from 'ant-design-vue';
import { api } from '@/lib/api'; import { api } from '@/lib/api';
import type { FinancialAccountDto, FinancialMovementDto } from '@mento/shared'; import type { FinancialAccountDto, FinancialMovementDto } from '@mento/shared';
import MoneyInput from '@/components/MoneyInput.vue'; import MoneyInput from '@/components/MoneyInput.vue';
import TreasuryListPagination from '@/components/treasury/TreasuryListPagination.vue';
import { toman } from './treasury-format'; import { toman } from './treasury-format';
import { useTreasuryListPaging } from './useTreasuryListPaging';
import { useTreasuryMobile } from './useTreasuryMobile'; import { useTreasuryMobile } from './useTreasuryMobile';
import { formatJalaliNumeric } from '@/lib/jalali'; import { formatJalaliNumeric } from '@/lib/jalali';
import { parseMoneyNumber } from '@/lib/money'; import { parseMoneyNumber } from '@/lib/money';
@@ -43,6 +45,15 @@ const busy = ref(false);
const isMobile = useTreasuryMobile(); const isMobile = useTreasuryMobile();
const AListItem = AList.Item; const AListItem = AList.Item;
const {
page,
pageSize,
pageSizeOptions,
total,
pagedRows,
onPageSizeChange,
showTotal,
} = useTreasuryListPaging(() => items.value, 'treasury.account-ledger');
const columns: TableColumnsType<FinancialMovementDto> = [ const columns: TableColumnsType<FinancialMovementDto> = [
{ {
title: 'تاریخ', title: 'تاریخ',
@@ -196,7 +207,7 @@ onUnmounted(() => {
<a-divider orientation="right">گردش حساب</a-divider> <a-divider orientation="right">گردش حساب</a-divider>
<a-empty v-if="!items.length" description="گردشی ثبت نشده است." /> <a-empty v-if="!items.length" description="گردشی ثبت نشده است." />
<a-list v-else-if="isMobile" :data-source="items"> <a-list v-else-if="isMobile" :data-source="pagedRows">
<template #renderItem="{ item }"> <template #renderItem="{ item }">
<a-list-item> <a-list-item>
<a-card :title="formatJalaliNumeric(new Date(item.occurredAt))" style="width: 100%"> <a-card :title="formatJalaliNumeric(new Date(item.occurredAt))" style="width: 100%">
@@ -220,11 +231,19 @@ onUnmounted(() => {
<a-table <a-table
v-else-if="items.length" v-else-if="items.length"
:columns="columns" :columns="columns"
:data-source="items" :data-source="pagedRows"
:pagination="false" :pagination="false"
row-key="id" row-key="id"
:scroll="{ x: true }" :scroll="{ x: true }"
/> />
<TreasuryListPagination
v-model:page="page"
:total="total"
:page-size="pageSize"
:page-size-options="pageSizeOptions"
:show-total="showTotal"
@update:page-size="onPageSizeChange"
/>
</a-card> </a-card>
</a-flex> </a-flex>
</template> </template>
@@ -26,7 +26,9 @@ import { api } from '@/lib/api';
import type { FinancialAccountDto, FinancialAccountType, OrgUserDto } from '@mento/shared'; import type { FinancialAccountDto, FinancialAccountType, OrgUserDto } from '@mento/shared';
import MoneyInput from '@/components/MoneyInput.vue'; import MoneyInput from '@/components/MoneyInput.vue';
import JalaliDateInput from '@/components/JalaliDateInput.vue'; import JalaliDateInput from '@/components/JalaliDateInput.vue';
import TreasuryListPagination from '@/components/treasury/TreasuryListPagination.vue';
import { toman } from './treasury-format'; import { toman } from './treasury-format';
import { useTreasuryListPaging } from './useTreasuryListPaging';
import { useTreasuryMobile } from './useTreasuryMobile'; import { useTreasuryMobile } from './useTreasuryMobile';
import { parseMoneyNumber } from '@/lib/money'; import { parseMoneyNumber } from '@/lib/money';
@@ -40,6 +42,15 @@ const accounts = ref<FinancialAccountDto[]>([]);
const users = ref<OrgUserDto[]>([]); const users = ref<OrgUserDto[]>([]);
const error = ref(''); const error = ref('');
const ok = ref(''); const ok = ref('');
const {
page,
pageSize,
pageSizeOptions,
total: listTotal,
pagedRows,
onPageSizeChange,
showTotal,
} = useTreasuryListPaging(() => accounts.value, 'treasury.accounts');
const openForm = ref(false); const openForm = ref(false);
const editingId = ref<string | null>(null); const editingId = ref<string | null>(null);
const responsibleKey = ref<string | undefined>(undefined); const responsibleKey = ref<string | undefined>(undefined);
@@ -422,7 +433,7 @@ onMounted(() => {
<a-divider orientation="right">فهرست حساب‌ها</a-divider> <a-divider orientation="right">فهرست حساب‌ها</a-divider>
<a-empty v-if="!accounts.length" description="حسابی ثبت نشده است." /> <a-empty v-if="!accounts.length" description="حسابی ثبت نشده است." />
<a-list v-else :item-layout="isMobile ? 'vertical' : 'horizontal'" :data-source="accounts"> <a-list v-else :item-layout="isMobile ? 'vertical' : 'horizontal'" :data-source="pagedRows">
<template #renderItem="{ item }"> <template #renderItem="{ item }">
<a-list-item> <a-list-item>
<template #actions> <template #actions>
@@ -444,6 +455,14 @@ onMounted(() => {
</a-list-item> </a-list-item>
</template> </template>
</a-list> </a-list>
<TreasuryListPagination
v-model:page="page"
:total="listTotal"
:page-size="pageSize"
:page-size-options="pageSizeOptions"
:show-total="showTotal"
@update:page-size="onPageSizeChange"
/>
</a-card> </a-card>
</a-flex> </a-flex>
</template> </template>
@@ -9,7 +9,9 @@ import {
Typography, Typography,
} from 'ant-design-vue'; } from 'ant-design-vue';
import { api } from '@/lib/api'; import { api } from '@/lib/api';
import TreasuryListPagination from '@/components/treasury/TreasuryListPagination.vue';
import { formatJalaliNumeric } from '@/lib/jalali'; import { formatJalaliNumeric } from '@/lib/jalali';
import { useTreasuryListPaging } from './useTreasuryListPaging';
const { Paragraph: ATypographyParagraph } = Typography; const { Paragraph: ATypographyParagraph } = Typography;
const AListItem = AList.Item; const AListItem = AList.Item;
@@ -26,6 +28,15 @@ type Row = {
const rows = ref<Row[]>([]); const rows = ref<Row[]>([]);
const error = ref(''); const error = ref('');
const {
page,
pageSize,
pageSizeOptions,
total,
pagedRows,
onPageSizeChange,
showTotal,
} = useTreasuryListPaging(() => rows.value, 'treasury.audit');
const actionLabel: Record<string, string> = { const actionLabel: Record<string, string> = {
settle: 'تسویه سند', settle: 'تسویه سند',
cash_post: 'نشستن وجه در حساب', cash_post: 'نشستن وجه در حساب',
@@ -47,7 +58,7 @@ onMounted(async () => {
<a-card :bordered="false"> <a-card :bordered="false">
<a-empty v-if="!error && !rows.length" description="سابقه‌ای نیست." /> <a-empty v-if="!error && !rows.length" description="سابقه‌ای نیست." />
<a-list v-else item-layout="vertical" :data-source="rows"> <a-list v-else item-layout="vertical" :data-source="pagedRows">
<template #renderItem="{ item }"> <template #renderItem="{ item }">
<a-list-item> <a-list-item>
<a-list-item-meta> <a-list-item-meta>
@@ -67,6 +78,14 @@ onMounted(async () => {
</a-list-item> </a-list-item>
</template> </template>
</a-list> </a-list>
<TreasuryListPagination
v-model:page="page"
:total="total"
:page-size="pageSize"
:page-size-options="pageSizeOptions"
:show-total="showTotal"
@update:page-size="onPageSizeChange"
/>
</a-card> </a-card>
</a-flex> </a-flex>
</template> </template>
@@ -23,6 +23,8 @@ import {
} from 'ant-design-vue'; } from 'ant-design-vue';
import { api } from '@/lib/api'; import { api } from '@/lib/api';
import type { FinancialCategoryDto } from '@mento/shared'; import type { FinancialCategoryDto } from '@mento/shared';
import TreasuryListPagination from '@/components/treasury/TreasuryListPagination.vue';
import { useTreasuryListPaging } from './useTreasuryListPaging';
import { useTreasuryMobile } from './useTreasuryMobile'; import { useTreasuryMobile } from './useTreasuryMobile';
const { Text: ATypographyText } = Typography; const { Text: ATypographyText } = Typography;
@@ -42,6 +44,26 @@ const edit = ref({ id: '', name: '', isActive: true });
const incomeRows = computed(() => rows.value.filter((row) => row.kind === 'income')); const incomeRows = computed(() => rows.value.filter((row) => row.kind === 'income'));
const expenseRows = computed(() => rows.value.filter((row) => row.kind === 'expense')); const expenseRows = computed(() => rows.value.filter((row) => row.kind === 'expense'));
const {
page: incomePage,
pageSize: incomePageSize,
pageSizeOptions: incomePageSizeOptions,
total: incomeTotal,
pagedRows: pagedIncomeRows,
onPageSizeChange: onIncomePageSizeChange,
showTotal: incomeShowTotal,
} = useTreasuryListPaging(() => incomeRows.value, 'treasury.categories-income');
const {
page: expensePage,
pageSize: expensePageSize,
pageSizeOptions: expensePageSizeOptions,
total: expenseTotal,
pagedRows: pagedExpenseRows,
onPageSizeChange: onExpensePageSizeChange,
showTotal: expenseShowTotal,
} = useTreasuryListPaging(() => expenseRows.value, 'treasury.categories-expense');
function apiMessage(e: unknown) { function apiMessage(e: unknown) {
if (!axios.isAxiosError(e)) return 'ذخیره ناموفق بود.'; if (!axios.isAxiosError(e)) return 'ذخیره ناموفق بود.';
const msg = (e.response?.data as { message?: string | string[] })?.message; const msg = (e.response?.data as { message?: string | string[] })?.message;
@@ -153,7 +175,11 @@ onMounted(() => {
<a-divider orientation="right">درآمد</a-divider> <a-divider orientation="right">درآمد</a-divider>
<a-empty v-if="!incomeRows.length" description="دسته درآمدی نیست." /> <a-empty v-if="!incomeRows.length" description="دسته درآمدی نیست." />
<a-list v-else :item-layout="isMobile ? 'vertical' : 'horizontal'" :data-source="incomeRows"> <a-list
v-else
:item-layout="isMobile ? 'vertical' : 'horizontal'"
:data-source="pagedIncomeRows"
>
<template #renderItem="{ item }"> <template #renderItem="{ item }">
<a-list-item> <a-list-item>
<template #actions> <template #actions>
@@ -175,10 +201,22 @@ onMounted(() => {
</a-list-item> </a-list-item>
</template> </template>
</a-list> </a-list>
<TreasuryListPagination
v-model:page="incomePage"
:total="incomeTotal"
:page-size="incomePageSize"
:page-size-options="incomePageSizeOptions"
:show-total="incomeShowTotal"
@update:page-size="onIncomePageSizeChange"
/>
<a-divider orientation="right">هزینه</a-divider> <a-divider orientation="right">هزینه</a-divider>
<a-empty v-if="!expenseRows.length" description="دسته هزینه‌ای نیست." /> <a-empty v-if="!expenseRows.length" description="دسته هزینه‌ای نیست." />
<a-list v-else :item-layout="isMobile ? 'vertical' : 'horizontal'" :data-source="expenseRows"> <a-list
v-else
:item-layout="isMobile ? 'vertical' : 'horizontal'"
:data-source="pagedExpenseRows"
>
<template #renderItem="{ item }"> <template #renderItem="{ item }">
<a-list-item> <a-list-item>
<template #actions> <template #actions>
@@ -200,6 +238,14 @@ onMounted(() => {
</a-list-item> </a-list-item>
</template> </template>
</a-list> </a-list>
<TreasuryListPagination
v-model:page="expensePage"
:total="expenseTotal"
:page-size="expensePageSize"
:page-size-options="expensePageSizeOptions"
:show-total="expenseShowTotal"
@update:page-size="onExpensePageSizeChange"
/>
</a-card> </a-card>
<a-modal <a-modal
@@ -14,7 +14,9 @@ import {
} from 'ant-design-vue'; } from 'ant-design-vue';
import { api } from '@/lib/api'; import { api } from '@/lib/api';
import type { TreasuryDashboardDto } from '@mento/shared'; import type { TreasuryDashboardDto } from '@mento/shared';
import TreasuryListPagination from '@/components/treasury/TreasuryListPagination.vue';
import { toman } from './treasury-format'; import { toman } from './treasury-format';
import { useTreasuryListPaging } from './useTreasuryListPaging';
import { useTreasuryMobile } from './useTreasuryMobile'; import { useTreasuryMobile } from './useTreasuryMobile';
const { Text: ATypographyText } = Typography; const { Text: ATypographyText } = Typography;
@@ -36,6 +38,42 @@ const cards = [
{ key: 'totalBalance', label: 'موجودی حساب‌ها', hint: 'صندوق و بانک' }, { key: 'totalBalance', label: 'موجودی حساب‌ها', hint: 'صندوق و بانک' },
] as const; ] as const;
const {
page: installmentPage,
pageSize: installmentPageSize,
pageSizeOptions: installmentPageSizeOptions,
total: installmentTotal,
pagedRows: pagedInstallments,
onPageSizeChange: onInstallmentPageSizeChange,
showTotal: installmentShowTotal,
} = useTreasuryListPaging(
() => data.value?.upcomingInstallments ?? [],
'treasury.home-installments',
);
const {
page: payablePage,
pageSize: payablePageSize,
pageSizeOptions: payablePageSizeOptions,
total: payableTotal,
pagedRows: pagedPayables,
onPageSizeChange: onPayablePageSizeChange,
showTotal: payableShowTotal,
} = useTreasuryListPaging(
() => data.value?.upcomingPayables ?? [],
'treasury.home-payables',
);
const {
page: recentPage,
pageSize: recentPageSize,
pageSizeOptions: recentPageSizeOptions,
total: recentTotal,
pagedRows: pagedRecent,
onPageSizeChange: onRecentPageSizeChange,
showTotal: recentShowTotal,
} = useTreasuryListPaging(() => data.value?.recent ?? [], 'treasury.home-recent');
onMounted(async () => { onMounted(async () => {
try { try {
const res = await api.get<TreasuryDashboardDto>('/treasury/dashboard'); const res = await api.get<TreasuryDashboardDto>('/treasury/dashboard');
@@ -78,7 +116,7 @@ onMounted(async () => {
<a-list <a-list
v-else v-else
:item-layout="isMobile ? 'vertical' : 'horizontal'" :item-layout="isMobile ? 'vertical' : 'horizontal'"
:data-source="data.upcomingInstallments" :data-source="pagedInstallments"
> >
<template #renderItem="{ item }"> <template #renderItem="{ item }">
<a-list-item> <a-list-item>
@@ -94,6 +132,14 @@ onMounted(async () => {
</a-list-item> </a-list-item>
</template> </template>
</a-list> </a-list>
<TreasuryListPagination
v-model:page="installmentPage"
:total="installmentTotal"
:page-size="installmentPageSize"
:page-size-options="installmentPageSizeOptions"
:show-total="installmentShowTotal"
@update:page-size="onInstallmentPageSizeChange"
/>
</a-col> </a-col>
<a-col :xs="24" :lg="12"> <a-col :xs="24" :lg="12">
@@ -105,7 +151,7 @@ onMounted(async () => {
<a-list <a-list
v-else v-else
:item-layout="isMobile ? 'vertical' : 'horizontal'" :item-layout="isMobile ? 'vertical' : 'horizontal'"
:data-source="data.upcomingPayables" :data-source="pagedPayables"
> >
<template #renderItem="{ item }"> <template #renderItem="{ item }">
<a-list-item> <a-list-item>
@@ -119,6 +165,14 @@ onMounted(async () => {
</a-list-item> </a-list-item>
</template> </template>
</a-list> </a-list>
<TreasuryListPagination
v-model:page="payablePage"
:total="payableTotal"
:page-size="payablePageSize"
:page-size-options="payablePageSizeOptions"
:show-total="payableShowTotal"
@update:page-size="onPayablePageSizeChange"
/>
</a-col> </a-col>
</a-row> </a-row>
@@ -130,7 +184,7 @@ onMounted(async () => {
<a-list <a-list
v-else v-else
:item-layout="isMobile ? 'vertical' : 'horizontal'" :item-layout="isMobile ? 'vertical' : 'horizontal'"
:data-source="data.recent" :data-source="pagedRecent"
> >
<template #renderItem="{ item }"> <template #renderItem="{ item }">
<a-list-item> <a-list-item>
@@ -146,6 +200,14 @@ onMounted(async () => {
</a-list-item> </a-list-item>
</template> </template>
</a-list> </a-list>
<TreasuryListPagination
v-model:page="recentPage"
:total="recentTotal"
:page-size="recentPageSize"
:page-size-options="recentPageSizeOptions"
:show-total="recentShowTotal"
@update:page-size="onRecentPageSizeChange"
/>
</a-card> </a-card>
</template> </template>
</a-flex> </a-flex>
@@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed, onMounted, ref } from 'vue'; import { computed, onMounted, ref, watch } from 'vue';
import axios from 'axios'; import axios from 'axios';
import { import {
Alert as AAlert, Alert as AAlert,
@@ -42,7 +42,9 @@ import {
toFaDigits, toFaDigits,
formatJalaliNumeric, formatJalaliNumeric,
} from '@/lib/jalali'; } from '@/lib/jalali';
import TreasuryListPagination from '@/components/treasury/TreasuryListPagination.vue';
import { toman } from './treasury-format'; import { toman } from './treasury-format';
import { useTreasuryListPaging } from './useTreasuryListPaging';
import { parseMoneyNumber } from '@/lib/money'; import { parseMoneyNumber } from '@/lib/money';
const { Text: ATypographyText } = Typography; const { Text: ATypographyText } = Typography;
@@ -189,6 +191,31 @@ const filtered = computed(() => {
}); });
}); });
const {
page: reportPage,
pageSize: reportPageSize,
pageSizeOptions: reportPageSizeOptions,
total: reportTotal,
pagedRows: pagedReportRows,
onPageSizeChange: onReportPageSizeChange,
showTotal: reportShowTotal,
resetPage: resetReportPage,
} = useTreasuryListPaging(() => filtered.value, 'treasury.payroll-report');
const {
page: paymentPage,
pageSize: paymentPageSize,
pageSizeOptions: paymentPageSizeOptions,
total: paymentTotal,
pagedRows: pagedPayments,
onPageSizeChange: onPaymentPageSizeChange,
showTotal: paymentShowTotal,
resetPage: resetPaymentPage,
} = useTreasuryListPaging(() => selectedPay.value?.payments ?? [], 'treasury.payroll-payments');
watch(selectedPay, () => resetPaymentPage());
watch(filtered, () => resetReportPage());
const moneyKeys = ['baseAmount', 'benefits', 'bonus', 'deductions', 'payable', 'paidAmount', 'remaining'] as const; const moneyKeys = ['baseAmount', 'benefits', 'bonus', 'deductions', 'payable', 'paidAmount', 'remaining'] as const;
const reportColumns: TableColumnsType<PayrollRow> = [ const reportColumns: TableColumnsType<PayrollRow> = [
@@ -653,7 +680,7 @@ onMounted(() => {
</a-space> </a-space>
</a-form> </a-form>
<a-list v-if="isMobile && selectedPay?.payments.length" :data-source="selectedPay.payments"> <a-list v-if="isMobile && selectedPay?.payments.length" :data-source="pagedPayments">
<template #renderItem="{ item }"> <template #renderItem="{ item }">
<a-list-item> <a-list-item>
<a-card style="width: 100%"> <a-card style="width: 100%">
@@ -672,7 +699,7 @@ onMounted(() => {
<a-table <a-table
v-else-if="selectedPay?.payments.length" v-else-if="selectedPay?.payments.length"
:columns="paymentColumns" :columns="paymentColumns"
:data-source="selectedPay.payments" :data-source="pagedPayments"
:pagination="false" :pagination="false"
row-key="id" row-key="id"
> >
@@ -700,6 +727,15 @@ onMounted(() => {
</template> </template>
</template> </template>
</a-table> </a-table>
<TreasuryListPagination
v-if="selectedPay?.payments.length"
v-model:page="paymentPage"
:total="paymentTotal"
:page-size="paymentPageSize"
:page-size-options="paymentPageSizeOptions"
:show-total="paymentShowTotal"
@update:page-size="onPaymentPageSizeChange"
/>
</a-flex> </a-flex>
</a-card> </a-card>
@@ -765,7 +801,7 @@ onMounted(() => {
<a-empty v-if="!filtered.length" description="رکوردی با این فیلتر نیست." /> <a-empty v-if="!filtered.length" description="رکوردی با این فیلتر نیست." />
<a-flex v-else vertical :gap="8"> <a-flex v-else vertical :gap="8">
<a-card <a-card
v-for="row in filtered" v-for="row in pagedReportRows"
:key="row.id" :key="row.id"
hoverable hoverable
@click="detail = row" @click="detail = row"
@@ -851,7 +887,8 @@ onMounted(() => {
<a-col :xs="0" :md="24"> <a-col :xs="0" :md="24">
<a-table <a-table
:columns="reportColumns" :columns="reportColumns"
:data-source="filtered" :data-source="pagedReportRows"
:pagination="false"
row-key="id" row-key="id"
:scroll="{ x: 'max-content' }" :scroll="{ x: 'max-content' }"
:locale="{ emptyText: 'رکوردی با این فیلتر نیست.' }" :locale="{ emptyText: 'رکوردی با این فیلتر نیست.' }"
@@ -907,6 +944,14 @@ onMounted(() => {
</a-table> </a-table>
</a-col> </a-col>
</a-row> </a-row>
<TreasuryListPagination
v-model:page="reportPage"
:total="reportTotal"
:page-size="reportPageSize"
:page-size-options="reportPageSizeOptions"
:show-total="reportShowTotal"
@update:page-size="onReportPageSizeChange"
/>
</a-card> </a-card>
<a-modal <a-modal
@@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, ref } from 'vue'; import { computed, onMounted, ref } from 'vue';
import axios from 'axios'; import axios from 'axios';
import { import {
Alert as AAlert, Alert as AAlert,
@@ -29,10 +29,13 @@ import { api } from '@/lib/api';
import type { FinancialAccountDto, FinancialReceivableDto } from '@mento/shared'; import type { FinancialAccountDto, FinancialReceivableDto } from '@mento/shared';
import MoneyInput from '@/components/MoneyInput.vue'; import MoneyInput from '@/components/MoneyInput.vue';
import JalaliDateInput from '@/components/JalaliDateInput.vue'; import JalaliDateInput from '@/components/JalaliDateInput.vue';
import TreasuryListPagination from '@/components/treasury/TreasuryListPagination.vue';
import { toman } from './treasury-format'; import { toman } from './treasury-format';
import { useTreasuryListPaging } from './useTreasuryListPaging';
import { useTreasuryMobile } from './useTreasuryMobile'; import { useTreasuryMobile } from './useTreasuryMobile';
import { formatJalaliNumeric } from '@/lib/jalali'; import { formatJalaliNumeric } from '@/lib/jalali';
import { parseMoneyNumber } from '@/lib/money'; import { parseMoneyNumber } from '@/lib/money';
import { PAGE_SIZE_OPTIONS, usePageSize } from '@/lib/pageSize';
const { Text: ATypographyText } = Typography; const { Text: ATypographyText } = Typography;
const ASelectOption = ASelect.Option; const ASelectOption = ASelect.Option;
@@ -44,6 +47,25 @@ const accounts = ref<FinancialAccountDto[]>([]);
const error = ref(''); const error = ref('');
const ok = ref(''); const ok = ref('');
const saving = ref(false); const saving = ref(false);
const {
page,
pageSize,
pageSizeOptions,
total,
pagedRows,
onPageSizeChange,
showTotal,
} = useTreasuryListPaging(() => rows.value, 'treasury.receivables');
const installmentPageSize = usePageSize('treasury.receivables-installments', 10);
const installmentPageSizeOptions = PAGE_SIZE_OPTIONS.map(String);
const installmentTablePagination = computed(() => ({
pageSize: installmentPageSize.value,
showSizeChanger: true,
pageSizeOptions: installmentPageSizeOptions,
onShowSizeChange: (_current: number, size: number) => {
installmentPageSize.value = size;
},
}));
const form = ref({ const form = ref({
title: '', title: '',
partyName: '', partyName: '',
@@ -361,7 +383,7 @@ onMounted(() => {
<a-divider orientation="right">قراردادها</a-divider> <a-divider orientation="right">قراردادها</a-divider>
<a-empty v-if="!rows.length" description="قراردادی ثبت نشده است." /> <a-empty v-if="!rows.length" description="قراردادی ثبت نشده است." />
<template v-else> <template v-else>
<div v-for="row in rows" :key="row.id"> <div v-for="row in pagedRows" :key="row.id">
<a-flex justify="space-between" align="flex-start" wrap="wrap" :gap="8"> <a-flex justify="space-between" align="flex-start" wrap="wrap" :gap="8">
<div> <div>
<a-typography-text strong>{{ row.title }}</a-typography-text> <a-typography-text strong>{{ row.title }}</a-typography-text>
@@ -372,7 +394,11 @@ onMounted(() => {
</div> </div>
<a-typography-text strong>{{ toman(row.totalAmount) }}</a-typography-text> <a-typography-text strong>{{ toman(row.totalAmount) }}</a-typography-text>
</a-flex> </a-flex>
<a-list v-if="isMobile" :data-source="row.installments"> <a-list
v-if="isMobile"
:data-source="row.installments"
:pagination="installmentTablePagination"
>
<template #renderItem="{ item }"> <template #renderItem="{ item }">
<a-list-item> <a-list-item>
<a-card :title="`قسط ${item.position}`" style="width: 100%"> <a-card :title="`قسط ${item.position}`" style="width: 100%">
@@ -401,7 +427,7 @@ onMounted(() => {
v-else v-else
:columns="installmentColumns" :columns="installmentColumns"
:data-source="row.installments" :data-source="row.installments"
:pagination="false" :pagination="installmentTablePagination"
row-key="id" row-key="id"
:scroll="{ x: true }" :scroll="{ x: true }"
> >
@@ -422,6 +448,14 @@ onMounted(() => {
</a-table> </a-table>
<a-divider /> <a-divider />
</div> </div>
<TreasuryListPagination
v-model:page="page"
:total="total"
:page-size="pageSize"
:page-size-options="pageSizeOptions"
:show-total="showTotal"
@update:page-size="onPageSizeChange"
/>
</template> </template>
</a-card> </a-card>
</a-flex> </a-flex>
@@ -21,7 +21,9 @@ import {
import { api } from '@/lib/api'; import { api } from '@/lib/api';
import MoneyInput from '@/components/MoneyInput.vue'; import MoneyInput from '@/components/MoneyInput.vue';
import JalaliDateInput from '@/components/JalaliDateInput.vue'; import JalaliDateInput from '@/components/JalaliDateInput.vue';
import TreasuryListPagination from '@/components/treasury/TreasuryListPagination.vue';
import { toman } from './treasury-format'; import { toman } from './treasury-format';
import { useTreasuryListPaging } from './useTreasuryListPaging';
import { useTreasuryMobile } from './useTreasuryMobile'; import { useTreasuryMobile } from './useTreasuryMobile';
import { formatJalaliNumeric } from '@/lib/jalali'; import { formatJalaliNumeric } from '@/lib/jalali';
import { parseMoneyNumber } from '@/lib/money'; import { parseMoneyNumber } from '@/lib/money';
@@ -45,6 +47,15 @@ const rows = ref<Row[]>([]);
const error = ref(''); const error = ref('');
const ok = ref(''); const ok = ref('');
const saving = ref(false); const saving = ref(false);
const {
page,
pageSize,
pageSizeOptions,
total,
pagedRows,
onPageSizeChange,
showTotal,
} = useTreasuryListPaging(() => rows.value, 'treasury.recurring');
const form = ref({ title: '', kind: 'expense', amount: '', interval: 'monthly', startDate: '' }); const form = ref({ title: '', kind: 'expense', amount: '', interval: 'monthly', startDate: '' });
async function load() { async function load() {
@@ -148,7 +159,7 @@ onMounted(() => {
<a-divider orientation="right">فهرست الگوها</a-divider> <a-divider orientation="right">فهرست الگوها</a-divider>
<a-empty v-if="!rows.length" description="الگویی ثبت نشده است." /> <a-empty v-if="!rows.length" description="الگویی ثبت نشده است." />
<a-list v-else :item-layout="isMobile ? 'vertical' : 'horizontal'" :data-source="rows"> <a-list v-else :item-layout="isMobile ? 'vertical' : 'horizontal'" :data-source="pagedRows">
<template #renderItem="{ item }"> <template #renderItem="{ item }">
<a-list-item> <a-list-item>
<template #actions> <template #actions>
@@ -165,6 +176,14 @@ onMounted(() => {
</a-list-item> </a-list-item>
</template> </template>
</a-list> </a-list>
<TreasuryListPagination
v-model:page="page"
:total="total"
:page-size="pageSize"
:page-size-options="pageSizeOptions"
:show-total="showTotal"
@update:page-size="onPageSizeChange"
/>
</a-card> </a-card>
</a-flex> </a-flex>
</template> </template>
@@ -20,8 +20,10 @@ import { DownloadOutlined } from '@ant-design/icons-vue';
import * as XLSX from 'xlsx'; import * as XLSX from 'xlsx';
import type { TreasuryPartyBalanceDto } from '@mento/shared'; import type { TreasuryPartyBalanceDto } from '@mento/shared';
import { api } from '@/lib/api'; import { api } from '@/lib/api';
import TreasuryListPagination from '@/components/treasury/TreasuryListPagination.vue';
import TreasuryPartyBalanceTable from '@/components/treasury/TreasuryPartyBalanceTable.vue'; import TreasuryPartyBalanceTable from '@/components/treasury/TreasuryPartyBalanceTable.vue';
import { toman } from './treasury-format'; import { toman } from './treasury-format';
import { useTreasuryListPaging } from './useTreasuryListPaging';
import { useTreasuryMobile } from './useTreasuryMobile'; import { useTreasuryMobile } from './useTreasuryMobile';
const { Text: ATypographyText } = Typography; const { Text: ATypographyText } = Typography;
@@ -92,6 +94,39 @@ const metricRows = computed<MetricRow[]>(() => {
})); }));
}); });
const {
page: partyPage,
pageSize: partyPageSize,
pageSizeOptions: partyPageSizeOptions,
total: partyTotal,
pagedRows: pagedPartyRows,
onPageSizeChange: onPartyPageSizeChange,
showTotal: partyShowTotal,
} = useTreasuryListPaging(() => receivablesByParty.value, 'treasury.reports-party');
const {
page: monthPage,
pageSize: monthPageSize,
pageSizeOptions: monthPageSizeOptions,
total: monthTotal,
pagedRows: pagedMonthRows,
onPageSizeChange: onMonthPageSizeChange,
showTotal: monthShowTotal,
} = useTreasuryListPaging(() => payablesByMonth.value, 'treasury.reports-month');
const {
page: expenseCatPage,
pageSize: expenseCatPageSize,
pageSizeOptions: expenseCatPageSizeOptions,
total: expenseCatTotal,
pagedRows: pagedExpenseCats,
onPageSizeChange: onExpenseCatPageSizeChange,
showTotal: expenseCatShowTotal,
} = useTreasuryListPaging(
() => current.value?.expenseCategories ?? [],
'treasury.reports-expense-cats',
);
async function load() { async function load() {
const { data } = await api.get<{ const { data } = await api.get<{
current: Period; current: Period;
@@ -213,7 +248,7 @@ onMounted(() => {
<a-divider orientation="right">مطالبات به تفکیک طرف حساب</a-divider> <a-divider orientation="right">مطالبات به تفکیک طرف حساب</a-divider>
<a-empty v-if="!receivablesByParty.length" description="مورد بازی نیست." /> <a-empty v-if="!receivablesByParty.length" description="مورد بازی نیست." />
<a-list v-else :item-layout="isMobile ? 'vertical' : 'horizontal'" :data-source="receivablesByParty"> <a-list v-else :item-layout="isMobile ? 'vertical' : 'horizontal'" :data-source="pagedPartyRows">
<template #renderItem="{ item }"> <template #renderItem="{ item }">
<a-list-item> <a-list-item>
<template #actions> <template #actions>
@@ -225,10 +260,18 @@ onMounted(() => {
</a-list-item> </a-list-item>
</template> </template>
</a-list> </a-list>
<TreasuryListPagination
v-model:page="partyPage"
:total="partyTotal"
:page-size="partyPageSize"
:page-size-options="partyPageSizeOptions"
:show-total="partyShowTotal"
@update:page-size="onPartyPageSizeChange"
/>
<a-divider orientation="right">تعهدات به تفکیک ماه</a-divider> <a-divider orientation="right">تعهدات به تفکیک ماه</a-divider>
<a-empty v-if="!payablesByMonth.length" description="تعهد بازی نیست." /> <a-empty v-if="!payablesByMonth.length" description="تعهد بازی نیست." />
<a-list v-else :item-layout="isMobile ? 'vertical' : 'horizontal'" :data-source="payablesByMonth"> <a-list v-else :item-layout="isMobile ? 'vertical' : 'horizontal'" :data-source="pagedMonthRows">
<template #renderItem="{ item }"> <template #renderItem="{ item }">
<a-list-item> <a-list-item>
<template #actions> <template #actions>
@@ -240,11 +283,19 @@ onMounted(() => {
</a-list-item> </a-list-item>
</template> </template>
</a-list> </a-list>
<TreasuryListPagination
v-model:page="monthPage"
:total="monthTotal"
:page-size="monthPageSize"
:page-size-options="monthPageSizeOptions"
:show-total="monthShowTotal"
@update:page-size="onMonthPageSizeChange"
/>
<template v-if="current"> <template v-if="current">
<a-divider orientation="right">سهم هزینه‌ها</a-divider> <a-divider orientation="right">سهم هزینه‌ها</a-divider>
<a-empty v-if="!current.expenseCategories.length" description="دسته‌ای نیست." /> <a-empty v-if="!current.expenseCategories.length" description="دسته‌ای نیست." />
<a-list v-else :item-layout="isMobile ? 'vertical' : 'horizontal'" :data-source="current.expenseCategories"> <a-list v-else :item-layout="isMobile ? 'vertical' : 'horizontal'" :data-source="pagedExpenseCats">
<template #renderItem="{ item }"> <template #renderItem="{ item }">
<a-list-item> <a-list-item>
<template #actions> <template #actions>
@@ -258,6 +309,14 @@ onMounted(() => {
</a-list-item> </a-list-item>
</template> </template>
</a-list> </a-list>
<TreasuryListPagination
v-model:page="expenseCatPage"
:total="expenseCatTotal"
:page-size="expenseCatPageSize"
:page-size-options="expenseCatPageSizeOptions"
:show-total="expenseCatShowTotal"
@update:page-size="onExpenseCatPageSizeChange"
/>
</template> </template>
</a-flex> </a-flex>
</a-tab-pane> </a-tab-pane>
@@ -0,0 +1,47 @@
import { computed, ref, watch, type Ref } from 'vue';
import { toFaDigits } from '@/lib/jalali';
import { PAGE_SIZE_OPTIONS, usePageSize } from '@/lib/pageSize';
/** صفحه‌بندی مشترک فهرست‌ها و جداول مدیریت مالی (۱۰/۲۰/۵۰/۱۰۰). */
export function useTreasuryListPaging<T>(getRows: () => readonly T[], storageKey: string, fallback = 10) {
const page = ref(1);
const pageSize = usePageSize(storageKey, fallback);
const pageSizeOptions = PAGE_SIZE_OPTIONS.map(String);
const total = computed(() => getRows().length);
const pageCount = computed(() => Math.max(1, Math.ceil(total.value / pageSize.value) || 1));
const pagedRows = computed(() => {
const start = (page.value - 1) * pageSize.value;
return getRows().slice(start, start + pageSize.value) as T[];
});
watch([total, pageSize], () => {
if (page.value > pageCount.value) page.value = pageCount.value;
if (page.value < 1) page.value = 1;
});
function resetPage() {
page.value = 1;
}
function onPageSizeChange(size: number) {
pageSize.value = size;
page.value = 1;
}
function showTotal(count: number) {
return `مجموع: ${toFaDigits(count)} مورد (صفحه ${toFaDigits(page.value)} از ${toFaDigits(pageCount.value)})`;
}
return {
page,
pageSize: pageSize as Ref<number>,
pageSizeOptions,
total,
pageCount,
pagedRows,
resetPage,
onPageSizeChange,
showTotal,
};
}