Open treasury document detail/edit in centered modals with pagination.
Register Ant Modal correctly so overlays are not stuck under the table, and add page size controls for the documents list. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -12,7 +12,8 @@ import {
|
||||
FormItem as AFormItem,
|
||||
Image as AImage,
|
||||
Input as AInput,
|
||||
Modal,
|
||||
Modal as AModal,
|
||||
Pagination as APagination,
|
||||
Row as ARow,
|
||||
Select as ASelect,
|
||||
Space as ASpace,
|
||||
@@ -37,8 +38,9 @@ import {
|
||||
import JalaliDateInput from '@/components/JalaliDateInput.vue';
|
||||
import MoneyInput from '@/components/MoneyInput.vue';
|
||||
import { api } from '@/lib/api';
|
||||
import { formatJalaliNumeric, formatLocalDateInput } from '@/lib/jalali';
|
||||
import { formatJalaliNumeric, formatLocalDateInput, toFaDigits } 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 { useTreasuryMobile } from '@/views/treasury/useTreasuryMobile';
|
||||
@@ -98,6 +100,9 @@ const previewUrls = ref<Record<string, string>>({});
|
||||
const editOpen = ref(false);
|
||||
const editSaving = ref(false);
|
||||
const editId = ref<string | null>(null);
|
||||
const page = ref(1);
|
||||
const pageSize = usePageSize('treasury.documents', 10);
|
||||
const pageSizeOptions = PAGE_SIZE_OPTIONS.map(String);
|
||||
const editForm = reactive({
|
||||
title: '',
|
||||
notes: '',
|
||||
@@ -210,12 +215,13 @@ async function saveEdit() {
|
||||
}
|
||||
|
||||
function confirmVoid(row: FinancialDocumentDto) {
|
||||
Modal.confirm({
|
||||
AModal.confirm({
|
||||
title: 'ابطال سند',
|
||||
content: 'این سند و گردش متصل به آن باطل شود؟',
|
||||
okText: 'ابطال',
|
||||
okType: 'danger',
|
||||
cancelText: 'انصراف',
|
||||
centered: true,
|
||||
async onOk() {
|
||||
try {
|
||||
await api.post(`/treasury/documents/${row.id}/void`, { reason: 'ابطال توسط کاربر' });
|
||||
@@ -230,7 +236,7 @@ function confirmVoid(row: FinancialDocumentDto) {
|
||||
}
|
||||
|
||||
function confirmDelete(row: FinancialDocumentDto) {
|
||||
Modal.confirm({
|
||||
AModal.confirm({
|
||||
title: 'حذف سند',
|
||||
content:
|
||||
row.status === 'void'
|
||||
@@ -239,6 +245,7 @@ function confirmDelete(row: FinancialDocumentDto) {
|
||||
okText: 'حذف',
|
||||
okType: 'danger',
|
||||
cancelText: 'انصراف',
|
||||
centered: true,
|
||||
async onOk() {
|
||||
try {
|
||||
await api.delete(`/treasury/documents/${row.id}`);
|
||||
@@ -286,13 +293,42 @@ 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;
|
||||
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;
|
||||
}
|
||||
|
||||
function modalContainer() {
|
||||
return document.body;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -318,7 +354,7 @@ function asDoc(record: unknown): FinancialDocumentDto {
|
||||
<a-table
|
||||
v-else-if="!isMobile"
|
||||
:columns="columns"
|
||||
:data-source="rows"
|
||||
:data-source="pagedRows"
|
||||
:pagination="false"
|
||||
:scroll="{ x: 1100 }"
|
||||
row-key="id"
|
||||
@@ -392,7 +428,7 @@ function asDoc(record: unknown): FinancialDocumentDto {
|
||||
</a-table>
|
||||
|
||||
<a-flex v-else vertical :gap="12">
|
||||
<a-card v-for="item in rows" :key="item.id" :bordered="true">
|
||||
<a-card v-for="item in pagedRows" :key="item.id" :bordered="true">
|
||||
<a-flex vertical :gap="8">
|
||||
<a-flex justify="space-between" align="flex-start" wrap="wrap" :gap="8">
|
||||
<a-typography-text strong>{{ item.title }}</a-typography-text>
|
||||
@@ -459,6 +495,18 @@ function asDoc(record: unknown): FinancialDocumentDto {
|
||||
</a-flex>
|
||||
</a-card>
|
||||
</a-flex>
|
||||
|
||||
<a-flex v-if="rows.length" justify="space-between" align="center" wrap="wrap" :gap="12" style="margin-top: 16px">
|
||||
<a-pagination
|
||||
v-model:current="page"
|
||||
:page-size="pageSize"
|
||||
:total="rows.length"
|
||||
:page-size-options="pageSizeOptions"
|
||||
show-size-changer
|
||||
:show-total="paginationTotal"
|
||||
@update:page-size="onPageSizeChange"
|
||||
/>
|
||||
</a-flex>
|
||||
</a-card>
|
||||
|
||||
<a-modal
|
||||
@@ -466,6 +514,8 @@ function asDoc(record: unknown): FinancialDocumentDto {
|
||||
title="جزئیات سند"
|
||||
:footer="null"
|
||||
:width="isMobile ? '100%' : 720"
|
||||
:get-container="modalContainer"
|
||||
centered
|
||||
destroy-on-close
|
||||
>
|
||||
<a-flex v-if="detailLoading && !detail" justify="center">
|
||||
@@ -536,6 +586,8 @@ function asDoc(record: unknown): FinancialDocumentDto {
|
||||
cancel-text="انصراف"
|
||||
:confirm-loading="editSaving"
|
||||
:width="isMobile ? '100%' : 560"
|
||||
:get-container="modalContainer"
|
||||
centered
|
||||
destroy-on-close
|
||||
@ok="saveEdit"
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user