<script lang="ts" setup>
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
import type { FinanceReimbursementApi } from '#/api/finance/reimbursement';
|
|
import { ref } from 'vue';
|
import { useRouter } from 'vue-router';
|
|
import { Page, useVbenModal } from '@vben/common-ui';
|
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
|
|
import { message, Tag } from 'ant-design-vue';
|
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
import {
|
archiveReimbursement,
|
deleteReimbursement,
|
exportReimbursement,
|
getReimbursementApproveProcessList,
|
getReimbursementPage,
|
} from '#/api/finance/reimbursement';
|
import { $t } from '#/locales';
|
|
import {
|
ReimbursementStatus,
|
useGridColumns,
|
useGridFormSchema,
|
} from './data';
|
import Form from './modules/form.vue';
|
import ProcessSelectModal from './modules/process-select-modal.vue';
|
|
/** 财务报销单列表 */
|
defineOptions({ name: 'FinanceReimbursement' });
|
|
const router = useRouter();
|
|
const [FormModal, formModalApi] = useVbenModal({
|
connectedComponent: Form,
|
destroyOnClose: true,
|
});
|
|
const [ProcessModal, processModalApi] = useVbenModal({
|
connectedComponent: ProcessSelectModal,
|
destroyOnClose: true,
|
});
|
|
/** 刷新表格 */
|
function handleRefresh() {
|
gridApi.query();
|
}
|
|
/** 导出表格 */
|
async function handleExport() {
|
const data = await exportReimbursement(await gridApi.formApi.getValues());
|
downloadFileFromBlobPart({ fileName: '报销单.xls', source: data });
|
}
|
|
/** 新增报销单 */
|
function handleCreate() {
|
formModalApi.setData({ formType: 'create' }).open();
|
}
|
|
/** 编辑报销单(仅草稿、已驳回可编辑) */
|
function handleEdit(row: FinanceReimbursementApi.Reimbursement) {
|
formModalApi.setData({ formType: 'edit', id: row.id }).open();
|
}
|
|
/** 查看报销单详情 */
|
function handleDetail(row: FinanceReimbursementApi.Reimbursement) {
|
formModalApi.setData({ formType: 'detail', id: row.id }).open();
|
}
|
|
/** 删除报销单(仅草稿可删) */
|
async function handleDelete(ids: number[]) {
|
const hideLoading = message.loading({
|
content: $t('ui.actionMessage.deleting'),
|
duration: 0,
|
});
|
try {
|
await Promise.all(ids.map((id) => deleteReimbursement(id)));
|
message.success($t('ui.actionMessage.deleteSuccess'));
|
handleRefresh();
|
} finally {
|
hideLoading();
|
}
|
}
|
|
/** 提交审批 - 先获取流程列表,流程 key 不写死 */
|
async function handleSubmit(row: FinanceReimbursementApi.Reimbursement) {
|
const hideLoading = message.loading({
|
content: '获取审批流程...',
|
duration: 0,
|
});
|
try {
|
const processList = await getReimbursementApproveProcessList();
|
hideLoading();
|
if (!processList || processList.length === 0) {
|
message.warning('暂无可用审批流程,请先到 BPM 流程设计器发布报销审批流程');
|
return;
|
}
|
processModalApi.setData({ id: row.id, processList }).open();
|
} catch {
|
hideLoading();
|
}
|
}
|
|
/** 归档报销单 */
|
async function handleArchive(row: FinanceReimbursementApi.Reimbursement) {
|
const hideLoading = message.loading({
|
content: '归档中...',
|
duration: 0,
|
});
|
try {
|
const archiveNo = await archiveReimbursement(row.id!);
|
message.success(`已归档并生成档案 ${archiveNo}`);
|
handleRefresh();
|
} finally {
|
hideLoading();
|
}
|
}
|
|
/** 查看审批详情 */
|
function handleProcessDetail(row: FinanceReimbursementApi.Reimbursement) {
|
if (!row.processInstanceId) {
|
message.warning('该报销单尚未提交审批');
|
return;
|
}
|
router.push({
|
name: 'BpmProcessInstanceDetail',
|
query: { id: row.processInstanceId },
|
});
|
}
|
|
const checkedIds = ref<number[]>([]);
|
function handleRowCheckboxChange({
|
records,
|
}: {
|
records: FinanceReimbursementApi.Reimbursement[];
|
}) {
|
checkedIds.value = records.map((item) => item.id!);
|
}
|
|
const [Grid, gridApi] = useVbenVxeGrid({
|
formOptions: {
|
schema: useGridFormSchema(),
|
},
|
gridOptions: {
|
columns: useGridColumns(),
|
height: 'auto',
|
keepSource: true,
|
proxyConfig: {
|
ajax: {
|
query: async ({ page }, formValues) => {
|
return await getReimbursementPage({
|
pageNo: page.currentPage,
|
pageSize: page.pageSize,
|
...formValues,
|
});
|
},
|
},
|
},
|
rowConfig: {
|
keyField: 'id',
|
isHover: true,
|
},
|
toolbarConfig: {
|
refresh: true,
|
search: true,
|
},
|
} as VxeTableGridOptions<FinanceReimbursementApi.Reimbursement>,
|
gridEvents: {
|
checkboxAll: handleRowCheckboxChange,
|
checkboxChange: handleRowCheckboxChange,
|
},
|
});
|
</script>
|
|
<template>
|
<Page auto-content-height>
|
<FormModal @success="handleRefresh" />
|
<ProcessModal @success="handleRefresh" />
|
<Grid table-title="报销单列表">
|
<template #toolbar-tools>
|
<TableAction
|
:actions="[
|
{
|
label: $t('ui.actionTitle.create', ['报销单']),
|
type: 'primary',
|
icon: ACTION_ICON.ADD,
|
auth: ['finance:reimbursement:create'],
|
onClick: handleCreate,
|
},
|
{
|
label: $t('ui.actionTitle.export'),
|
type: 'primary',
|
icon: ACTION_ICON.DOWNLOAD,
|
auth: ['finance:reimbursement:export'],
|
onClick: handleExport,
|
},
|
{
|
label: '批量删除',
|
type: 'primary',
|
danger: true,
|
disabled: isEmpty(checkedIds),
|
icon: ACTION_ICON.DELETE,
|
auth: ['finance:reimbursement:delete'],
|
popConfirm: {
|
title: `是否删除所选中数据?(仅草稿状态可删除)`,
|
confirm: handleDelete.bind(null, checkedIds),
|
},
|
},
|
]"
|
/>
|
</template>
|
<template #hasAttachment="{ row }">
|
<Tag :color="row.hasAttachment ? 'success' : 'default'">
|
{{ row.hasAttachment ? '有' : '无' }}
|
</Tag>
|
</template>
|
<template #actions="{ row }">
|
<TableAction
|
:actions="[
|
{
|
label: $t('common.detail'),
|
type: 'link',
|
icon: ACTION_ICON.VIEW,
|
auth: ['finance:reimbursement:query'],
|
onClick: handleDetail.bind(null, row),
|
},
|
{
|
label: $t('common.edit'),
|
type: 'link',
|
icon: ACTION_ICON.EDIT,
|
auth: ['finance:reimbursement:update'],
|
ifShow: () =>
|
row.status === ReimbursementStatus.DRAFT ||
|
row.status === ReimbursementStatus.REJECTED,
|
onClick: handleEdit.bind(null, row),
|
},
|
{
|
label: '提交审批',
|
type: 'link',
|
icon: ACTION_ICON.AUDIT,
|
auth: ['finance:reimbursement:update-status'],
|
ifShow: () =>
|
row.status === ReimbursementStatus.DRAFT ||
|
row.status === ReimbursementStatus.REJECTED,
|
onClick: handleSubmit.bind(null, row),
|
},
|
{
|
label: '归档',
|
type: 'link',
|
icon: ACTION_ICON.VIEW,
|
auth: ['finance:reimbursement:archive'],
|
ifShow: () => row.status === ReimbursementStatus.APPROVED,
|
popConfirm: {
|
title: `确认归档报销单 ${row.no} 吗?归档后不可再修改`,
|
confirm: handleArchive.bind(null, row),
|
},
|
},
|
{
|
label: '查看审批',
|
type: 'link',
|
icon: ACTION_ICON.VIEW,
|
auth: ['finance:reimbursement:query'],
|
ifShow: () => !!row.processInstanceId,
|
onClick: handleProcessDetail.bind(null, row),
|
},
|
{
|
label: $t('common.delete'),
|
type: 'link',
|
danger: true,
|
icon: ACTION_ICON.DELETE,
|
auth: ['finance:reimbursement:delete'],
|
ifShow: () => row.status === ReimbursementStatus.DRAFT,
|
popConfirm: {
|
title: $t('ui.actionMessage.deleteConfirm', [row.no]),
|
confirm: handleDelete.bind(null, [row.id!]),
|
},
|
},
|
]"
|
/>
|
</template>
|
</Grid>
|
</Page>
|
</template>
|