Files
tehran_taj/apps/admin-panel/src/views/finical/list.vue
T

135 lines
4.8 KiB
Vue
Raw Normal View History

<template>
<!--
Ported from legacy henza_admin/src/views/finical/list.vue — the financial
documents grid. Farsi copy and permission gates preserved, including the fact
that confirm and deny are the SAME endpoint gated on two different rids
(document.list.confirm / document.list.deny).
-->
<div id="page-user-list">
<a-spin :spinning="loading">
<a-card title="لیست اسناد مالی">
<XTable ref="tbl" :model="model">
2026-09-19 12:05:59 +03:30
<template #add>
<ListPageHeader rid="document.create" add-label="ثبت سند مالی" @add="openAdd" />
</template>
<template #confirmed="{ text }">
<a-tag v-if="text === 1" color="green">تایید شده</a-tag>
<a-tag v-else>تایید نشده</a-tag>
</template>
<template #opt="{ record }">
<a-tooltip v-if="!record.confirmed && hasPermission('document.list.confirm')" title="تایید سند">
<a-popconfirm
placement="top"
ok-text="بله"
cancel-text="خیر"
@confirm="changeConfirme(record)"
>
<template #title><p>آیا سند تایید شود ؟</p></template>
<CheckOutlined class="cursor-pointer mx-1 text-success" />
</a-popconfirm>
</a-tooltip>
<a-tooltip v-if="record.confirmed && hasPermission('document.list.deny')" title="رد کردن سند">
<a-popconfirm
placement="top"
ok-text="بله"
cancel-text="خیر"
@confirm="changeConfirme(record)"
>
<template #title><p>آیا سند رد شود ؟</p></template>
<CloseOutlined class="cursor-pointer mx-1 text-danger" />
</a-popconfirm>
</a-tooltip>
<a-tooltip v-if="hasPermission('document.list.edit')" title="ویرایش">
<EditOutlined class="cursor-pointer mx-1 text-primary" @click="openEdit(record.id)" />
</a-tooltip>
<a-tooltip v-if="hasPermission('document.list.remove')" title="حذف">
<a-popconfirm
placement="top"
ok-text="بله"
cancel-text="خیر"
@confirm="deleteCash(record)"
>
<template #title><p>آیا مطمئن به حذف سند مورد نظر هستید ؟</p></template>
<DeleteOutlined class="cursor-pointer mx-1 text-danger" />
</a-popconfirm>
</a-tooltip>
</template>
</XTable>
<AddFinDoc :key="editingId ?? 'new'" :open="modalOpen" :id="editingId" @update:open="modalOpen = $event" @success="tbl?.fetch()" />
</a-card>
</a-spin>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import { message } from 'ant-design-vue';
import {
CheckOutlined,
CloseOutlined,
DeleteOutlined,
EditOutlined,
} from '@ant-design/icons-vue';
import XTable from '../../components/x-table/XTable.vue';
import ListPageHeader from '../../components/common/ListPageHeader.vue';
import AddFinDoc from './addFinDoc.vue';
import { buildDocumentListModel } from './list_model';
import { useUsersStore } from '../../stores/users';
import { useDeleteHandler } from '../../composables/useDeleteHandler';
import api from '../../api/client';
const users = useUsersStore();
const hasPermission = (rid: string) => Boolean(users.hasPermission(rid));
const model = buildDocumentListModel();
const tbl = ref<{ fetch: () => Promise<void> } | null>(null);
const loading = ref(false);
const modalOpen = ref(false);
const editingId = ref<string | undefined>(undefined);
function openAdd() {
editingId.value = undefined;
modalOpen.value = true;
}
function openEdit(id: string) {
editingId.value = id;
modalOpen.value = true;
}
/** legacy changeConfirme(): one toggle endpoint for both confirm and deny */
async function changeConfirme(record: Record<string, any>) {
try {
loading.value = true;
await api.post(`cash/confirem/${record.id}`);
message.success('تغییرات با موفقیت ثبت شد');
tbl.value?.fetch();
} catch (e: any) {
console.log(e);
message.error(e?.response?.data?.message ?? 'خطا در ثبت تغییرات');
} finally {
loading.value = false;
}
}
// The backend refuses to delete a confirmed entry — it has already moved the
// customer's balance. Surface its Farsi explanation.
const { remove: deleteCashById } = useDeleteHandler({
onSuccess: () => tbl.value?.fetch(),
successMessage: 'سند حذف شد',
fallbackErrorMessage: 'خطا در حذف سند',
});
function deleteCash(record: Record<string, any>) {
return deleteCashById(`cash/${record.id}`);
}
</script>