feat: complete admin panel and backend admin api migration
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
<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">
|
||||
<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="toEdit(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>
|
||||
</a-card>
|
||||
</a-spin>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { message, Modal } from 'ant-design-vue';
|
||||
import {
|
||||
CheckOutlined,
|
||||
CloseOutlined,
|
||||
DeleteOutlined,
|
||||
EditOutlined,
|
||||
} from '@ant-design/icons-vue';
|
||||
import XTable from '../../components/x-table/XTable.vue';
|
||||
import { buildDocumentListModel } from './list_model';
|
||||
import { useUsersStore } from '../../stores/users';
|
||||
import api from '../../api/client';
|
||||
|
||||
const router = useRouter();
|
||||
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);
|
||||
|
||||
/** 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;
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteCash(record: Record<string, any>) {
|
||||
try {
|
||||
await api.delete(`cash/${record.id}`);
|
||||
message.success('سند حذف شد');
|
||||
tbl.value?.fetch();
|
||||
} catch (e: any) {
|
||||
// The backend refuses to delete a confirmed entry — it has already moved the
|
||||
// customer's balance. Surface its Farsi explanation.
|
||||
Modal.error({ title: e?.response?.data?.message ?? 'خطا در حذف سند', okText: 'بستن' });
|
||||
}
|
||||
}
|
||||
|
||||
function toEdit(id: string) {
|
||||
// legacy list.vue:137 opened /admin/edit/findoc/{id}; the route is
|
||||
// /edit/findoc/:id, not /finical/edit/:id.
|
||||
router.push(`/edit/findoc/${id}`);
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user