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,
|
FormItem as AFormItem,
|
||||||
Image as AImage,
|
Image as AImage,
|
||||||
Input as AInput,
|
Input as AInput,
|
||||||
Modal,
|
Modal as AModal,
|
||||||
|
Pagination as APagination,
|
||||||
Row as ARow,
|
Row as ARow,
|
||||||
Select as ASelect,
|
Select as ASelect,
|
||||||
Space as ASpace,
|
Space as ASpace,
|
||||||
@@ -37,8 +38,9 @@ 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 } from '@/lib/jalali';
|
import { formatJalaliNumeric, formatLocalDateInput, toFaDigits } 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 { useTreasuryMobile } from '@/views/treasury/useTreasuryMobile';
|
import { useTreasuryMobile } from '@/views/treasury/useTreasuryMobile';
|
||||||
@@ -98,6 +100,9 @@ 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 pageSize = usePageSize('treasury.documents', 10);
|
||||||
|
const pageSizeOptions = PAGE_SIZE_OPTIONS.map(String);
|
||||||
const editForm = reactive({
|
const editForm = reactive({
|
||||||
title: '',
|
title: '',
|
||||||
notes: '',
|
notes: '',
|
||||||
@@ -210,12 +215,13 @@ async function saveEdit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function confirmVoid(row: FinancialDocumentDto) {
|
function confirmVoid(row: FinancialDocumentDto) {
|
||||||
Modal.confirm({
|
AModal.confirm({
|
||||||
title: 'ابطال سند',
|
title: 'ابطال سند',
|
||||||
content: 'این سند و گردش متصل به آن باطل شود؟',
|
content: 'این سند و گردش متصل به آن باطل شود؟',
|
||||||
okText: 'ابطال',
|
okText: 'ابطال',
|
||||||
okType: 'danger',
|
okType: 'danger',
|
||||||
cancelText: 'انصراف',
|
cancelText: 'انصراف',
|
||||||
|
centered: true,
|
||||||
async onOk() {
|
async onOk() {
|
||||||
try {
|
try {
|
||||||
await api.post(`/treasury/documents/${row.id}/void`, { reason: 'ابطال توسط کاربر' });
|
await api.post(`/treasury/documents/${row.id}/void`, { reason: 'ابطال توسط کاربر' });
|
||||||
@@ -230,7 +236,7 @@ function confirmVoid(row: FinancialDocumentDto) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function confirmDelete(row: FinancialDocumentDto) {
|
function confirmDelete(row: FinancialDocumentDto) {
|
||||||
Modal.confirm({
|
AModal.confirm({
|
||||||
title: 'حذف سند',
|
title: 'حذف سند',
|
||||||
content:
|
content:
|
||||||
row.status === 'void'
|
row.status === 'void'
|
||||||
@@ -239,6 +245,7 @@ function confirmDelete(row: FinancialDocumentDto) {
|
|||||||
okText: 'حذف',
|
okText: 'حذف',
|
||||||
okType: 'danger',
|
okType: 'danger',
|
||||||
cancelText: 'انصراف',
|
cancelText: 'انصراف',
|
||||||
|
centered: true,
|
||||||
async onOk() {
|
async onOk() {
|
||||||
try {
|
try {
|
||||||
await api.delete(`/treasury/documents/${row.id}`);
|
await api.delete(`/treasury/documents/${row.id}`);
|
||||||
@@ -286,13 +293,42 @@ 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;
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function modalContainer() {
|
||||||
|
return document.body;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -318,7 +354,7 @@ function asDoc(record: unknown): FinancialDocumentDto {
|
|||||||
<a-table
|
<a-table
|
||||||
v-else-if="!isMobile"
|
v-else-if="!isMobile"
|
||||||
:columns="columns"
|
:columns="columns"
|
||||||
:data-source="rows"
|
:data-source="pagedRows"
|
||||||
:pagination="false"
|
:pagination="false"
|
||||||
:scroll="{ x: 1100 }"
|
:scroll="{ x: 1100 }"
|
||||||
row-key="id"
|
row-key="id"
|
||||||
@@ -392,7 +428,7 @@ function asDoc(record: unknown): FinancialDocumentDto {
|
|||||||
</a-table>
|
</a-table>
|
||||||
|
|
||||||
<a-flex v-else vertical :gap="12">
|
<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 vertical :gap="8">
|
||||||
<a-flex justify="space-between" align="flex-start" wrap="wrap" :gap="8">
|
<a-flex justify="space-between" align="flex-start" wrap="wrap" :gap="8">
|
||||||
<a-typography-text strong>{{ item.title }}</a-typography-text>
|
<a-typography-text strong>{{ item.title }}</a-typography-text>
|
||||||
@@ -459,6 +495,18 @@ function asDoc(record: unknown): FinancialDocumentDto {
|
|||||||
</a-flex>
|
</a-flex>
|
||||||
</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">
|
||||||
|
<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-card>
|
||||||
|
|
||||||
<a-modal
|
<a-modal
|
||||||
@@ -466,6 +514,8 @@ function asDoc(record: unknown): FinancialDocumentDto {
|
|||||||
title="جزئیات سند"
|
title="جزئیات سند"
|
||||||
:footer="null"
|
:footer="null"
|
||||||
:width="isMobile ? '100%' : 720"
|
:width="isMobile ? '100%' : 720"
|
||||||
|
:get-container="modalContainer"
|
||||||
|
centered
|
||||||
destroy-on-close
|
destroy-on-close
|
||||||
>
|
>
|
||||||
<a-flex v-if="detailLoading && !detail" justify="center">
|
<a-flex v-if="detailLoading && !detail" justify="center">
|
||||||
@@ -536,6 +586,8 @@ function asDoc(record: unknown): FinancialDocumentDto {
|
|||||||
cancel-text="انصراف"
|
cancel-text="انصراف"
|
||||||
:confirm-loading="editSaving"
|
:confirm-loading="editSaving"
|
||||||
:width="isMobile ? '100%' : 560"
|
:width="isMobile ? '100%' : 560"
|
||||||
|
:get-container="modalContainer"
|
||||||
|
centered
|
||||||
destroy-on-close
|
destroy-on-close
|
||||||
@ok="saveEdit"
|
@ok="saveEdit"
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user