diff --git a/apps/web/src/components/treasury/TreasuryDocumentsPanel.vue b/apps/web/src/components/treasury/TreasuryDocumentsPanel.vue index b18e266..5a1db5f 100644 --- a/apps/web/src/components/treasury/TreasuryDocumentsPanel.vue +++ b/apps/web/src/components/treasury/TreasuryDocumentsPanel.vue @@ -13,7 +13,6 @@ import { Image as AImage, Input as AInput, Modal as AModal, - Pagination as APagination, Row as ARow, Select as ASelect, Space as ASpace, @@ -38,12 +37,13 @@ import { import JalaliDateInput from '@/components/JalaliDateInput.vue'; import MoneyInput from '@/components/MoneyInput.vue'; import { api } from '@/lib/api'; -import { formatJalaliNumeric, formatLocalDateInput, toFaDigits } from '@/lib/jalali'; +import { formatJalaliNumeric, formatLocalDateInput } from '@/lib/jalali'; import { parseMoneyNumber } from '@/lib/money'; -import { PAGE_SIZE_OPTIONS, usePageSize } from '@/lib/pageSize'; import { useAuthStore } from '@/stores/auth'; import { toman } from '@/views/treasury/treasury-format'; +import { useTreasuryListPaging } from '@/views/treasury/useTreasuryListPaging'; import { useTreasuryMobile } from '@/views/treasury/useTreasuryMobile'; +import TreasuryListPagination from '@/components/treasury/TreasuryListPagination.vue'; const props = defineProps<{ rows: FinancialDocumentDto[]; @@ -100,9 +100,16 @@ const previewUrls = ref>({}); const editOpen = ref(false); const editSaving = ref(false); const editId = ref(null); -const page = ref(1); -const pageSize = usePageSize('treasury.documents', 10); -const pageSizeOptions = PAGE_SIZE_OPTIONS.map(String); +const { + page, + pageSize, + pageSizeOptions, + total, + pagedRows, + resetPage, + onPageSizeChange, + showTotal, +} = useTreasuryListPaging(() => props.rows, 'treasury.documents'); const editForm = reactive({ title: '', notes: '', @@ -293,35 +300,11 @@ const searchModel = computed({ 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() { - page.value = 1; + resetPage(); 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 { return record as FinancialDocumentDto; } @@ -496,17 +479,14 @@ function modalContainer() { - - - + +import { Pagination as APagination } from 'ant-design-vue'; + +const page = defineModel('page', { required: true }); + +defineProps<{ + total: number; + pageSize: number; + pageSizeOptions: string[]; + showTotal: (total: number) => string; +}>(); + +const emit = defineEmits<{ + 'update:pageSize': [size: number]; +}>(); + + + diff --git a/apps/web/src/components/treasury/TreasuryPartyBalanceTable.vue b/apps/web/src/components/treasury/TreasuryPartyBalanceTable.vue index 4afc541..a7599a4 100644 --- a/apps/web/src/components/treasury/TreasuryPartyBalanceTable.vue +++ b/apps/web/src/components/treasury/TreasuryPartyBalanceTable.vue @@ -7,7 +7,9 @@ import { Typography, } from 'ant-design-vue'; import type { TreasuryPartyBalanceDto } from '@mento/shared'; +import TreasuryListPagination from '@/components/treasury/TreasuryListPagination.vue'; import { toman } from '@/views/treasury/treasury-format'; +import { useTreasuryListPaging } from '@/views/treasury/useTreasuryListPaging'; import { useTreasuryMobile } from '@/views/treasury/useTreasuryMobile'; const props = defineProps<{ @@ -19,6 +21,16 @@ const isMobile = useTreasuryMobile(); const { Text: ATypographyText } = Typography; const AListItem = AList.Item; +const { + page, + pageSize, + pageSizeOptions, + total, + pagedRows, + onPageSizeChange, + showTotal, +} = useTreasuryListPaging(() => props.rows, 'treasury.party-balances'); + const kindLabel: Record = { person: 'مشتری', company: 'شرکت', @@ -58,7 +70,7 @@ function kindOf(record: TreasuryPartyBalanceDto) { diff --git a/apps/web/src/views/treasury/TreasuryCategoriesView.vue b/apps/web/src/views/treasury/TreasuryCategoriesView.vue index e2a1340..227468f 100644 --- a/apps/web/src/views/treasury/TreasuryCategoriesView.vue +++ b/apps/web/src/views/treasury/TreasuryCategoriesView.vue @@ -23,6 +23,8 @@ import { } from 'ant-design-vue'; import { api } from '@/lib/api'; import type { FinancialCategoryDto } from '@mento/shared'; +import TreasuryListPagination from '@/components/treasury/TreasuryListPagination.vue'; +import { useTreasuryListPaging } from './useTreasuryListPaging'; import { useTreasuryMobile } from './useTreasuryMobile'; 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 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) { if (!axios.isAxiosError(e)) return 'ذخیره ناموفق بود.'; const msg = (e.response?.data as { message?: string | string[] })?.message; @@ -153,7 +175,11 @@ onMounted(() => { درآمد - +