<script lang="ts" setup>
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
import type { FinVoucherApi } from '#/api/erp/finance/voucher';
|
|
import { ref } from 'vue';
|
|
import { confirm, Page, useVbenModal } from '@vben/common-ui';
|
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
|
|
import { message, Tag } from 'ant-design-vue';
|
|
import {
|
ACTION_ICON,
|
TableAction,
|
useVbenVxeGrid,
|
VxeColumn,
|
VxeTable,
|
} from '#/adapter/vxe-table';
|
import {
|
cancelVoucher,
|
deleteVoucherList,
|
exportVoucher,
|
getVoucherPageWithEntry,
|
postVoucher,
|
} from '#/api/erp/finance/voucher';
|
import { $t } from '#/locales';
|
|
import { useGridColumns, useGridFormSchema } from './data';
|
import Form from './modules/form.vue';
|
|
/** 记账凭证列表 */
|
defineOptions({ name: 'FinVoucher' });
|
|
/** 凭证状态:0未过账 10已过账 20已作废 */
|
const VOUCHER_STATUS_UNPOSTED = 0;
|
const VOUCHER_STATUS_POSTED = 10;
|
const VOUCHER_STATUS_CANCELLED = 20;
|
|
const [FormModal, formModalApi] = useVbenModal({
|
connectedComponent: Form,
|
destroyOnClose: true,
|
});
|
|
/** 刷新表格 */
|
function handleRefresh() {
|
gridApi.query();
|
}
|
|
/** 导出表格 */
|
async function handleExport() {
|
const data = await exportVoucher(await gridApi.formApi.getValues());
|
downloadFileFromBlobPart({ fileName: '记账凭证.xls', source: data });
|
}
|
|
/** 新增记账凭证 */
|
function handleCreate() {
|
formModalApi.setData({ formType: 'create' }).open();
|
}
|
|
/** 编辑记账凭证 */
|
function handleEdit(row: FinVoucherApi.Voucher) {
|
formModalApi.setData({ formType: 'edit', id: row.id }).open();
|
}
|
|
/** 查看详情 */
|
function handleDetail(row: FinVoucherApi.Voucher) {
|
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 deleteVoucherList(ids);
|
checkedIds.value = [];
|
message.success($t('ui.actionMessage.deleteSuccess'));
|
handleRefresh();
|
} finally {
|
hideLoading();
|
}
|
}
|
|
/** 凭证过账 */
|
async function handlePost(row: FinVoucherApi.Voucher) {
|
const hideLoading = message.loading({ content: '过账中...', duration: 0 });
|
try {
|
await postVoucher(row.id!);
|
message.success(`凭证【${row.voucherNo}】过账成功`);
|
handleRefresh();
|
} finally {
|
hideLoading();
|
}
|
}
|
|
/** 凭证作废 */
|
async function handleCancel(row: FinVoucherApi.Voucher) {
|
await confirm(
|
`确认要作废凭证【${row.voucherNo}】吗?作废后该凭证不再计入总账与明细账,且不可恢复。`,
|
);
|
const hideLoading = message.loading({ content: '作废中...', duration: 0 });
|
try {
|
await cancelVoucher(row.id!);
|
message.success(`凭证【${row.voucherNo}】已作废`);
|
handleRefresh();
|
} finally {
|
hideLoading();
|
}
|
}
|
|
const checkedIds = ref<number[]>([]);
|
function handleRowCheckboxChange({
|
records,
|
}: {
|
records: FinVoucherApi.Voucher[];
|
}) {
|
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 getVoucherPageWithEntry({
|
pageNo: page.currentPage,
|
pageSize: page.pageSize,
|
...formValues,
|
});
|
},
|
},
|
},
|
rowConfig: {
|
keyField: 'id',
|
isHover: true,
|
},
|
toolbarConfig: {
|
refresh: true,
|
search: true,
|
},
|
} as VxeTableGridOptions<FinVoucherApi.Voucher>,
|
gridEvents: {
|
checkboxAll: handleRowCheckboxChange,
|
checkboxChange: handleRowCheckboxChange,
|
},
|
});
|
</script>
|
|
<template>
|
<Page auto-content-height><FormModal @success="handleRefresh" />
|
<Grid table-title="记账凭证列表">
|
<template #toolbar-tools>
|
<TableAction
|
:actions="[
|
{
|
label: $t('ui.actionTitle.create', ['记账凭证']),
|
type: 'primary',
|
icon: ACTION_ICON.ADD,
|
auth: ['finance:voucher:create'],
|
onClick: handleCreate,
|
},
|
{
|
label: $t('ui.actionTitle.export'),
|
type: 'primary',
|
icon: ACTION_ICON.DOWNLOAD,
|
auth: ['finance:voucher:export'],
|
onClick: handleExport,
|
},
|
{
|
label: '批量删除',
|
type: 'primary',
|
danger: true,
|
disabled: isEmpty(checkedIds),
|
icon: ACTION_ICON.DELETE,
|
auth: ['finance:voucher:delete'],
|
popConfirm: {
|
title: '是否删除所选中数据?已过账的凭证不允许删除。',
|
confirm: handleDelete.bind(null, checkedIds),
|
},
|
},
|
]"
|
/>
|
</template>
|
|
<template #expand_content="{ row }">
|
<VxeTable
|
:data="row.entries ?? []"
|
border
|
size="small"
|
show-overflow
|
class="mx-2"
|
>
|
<VxeColumn title="序号" width="60">
|
<template #default="{ row: entry }">
|
{{ entry.rowNo ?? '-' }}
|
</template>
|
</VxeColumn>
|
<VxeColumn title="摘要" min-width="180">
|
<template #default="{ row: entry }">
|
{{ entry.summary || '-' }}
|
</template>
|
</VxeColumn>
|
<VxeColumn title="会计科目" min-width="220">
|
<template #default="{ row: entry }">
|
{{ entry.subjectCode }} {{ entry.subjectName }}
|
</template>
|
</VxeColumn>
|
<VxeColumn title="借方金额" align="right" width="140">
|
<template #default="{ row: entry }">
|
{{ entry.debit ? entry.debit.toFixed(2) : '-' }}
|
</template>
|
</VxeColumn>
|
<VxeColumn title="贷方金额" align="right" width="140">
|
<template #default="{ row: entry }">
|
{{ entry.credit ? entry.credit.toFixed(2) : '-' }}
|
</template>
|
</VxeColumn>
|
<VxeColumn title="辅助核算" min-width="150">
|
<template #default="{ row: entry }">
|
{{ entry.auxiliaryName || '-' }}
|
</template>
|
</VxeColumn>
|
</VxeTable>
|
</template>
|
|
<template #attachment="{ row }">
|
<Tag v-if="!row.hasAttachment" color="warning">未上传</Tag>
|
<Tag v-else color="success">已上传</Tag>
|
</template>
|
|
<template #actions="{ row }">
|
<TableAction
|
:actions="[
|
{
|
label: $t('common.detail'),
|
type: 'link',
|
icon: ACTION_ICON.VIEW,
|
auth: ['finance:voucher:query'],
|
onClick: handleDetail.bind(null, row),
|
},
|
{
|
label: $t('common.edit'),
|
type: 'link',
|
icon: ACTION_ICON.EDIT,
|
auth: ['finance:voucher:update'],
|
ifShow: () => row.status === VOUCHER_STATUS_UNPOSTED,
|
onClick: handleEdit.bind(null, row),
|
},
|
{
|
label: '过账',
|
type: 'link',
|
icon: ACTION_ICON.AUDIT,
|
auth: ['finance:voucher:update-status'],
|
ifShow: () => row.status === VOUCHER_STATUS_UNPOSTED,
|
popConfirm: {
|
title: `确认过账凭证【${row.voucherNo}】吗?过账后将计入总账与明细账。`,
|
confirm: handlePost.bind(null, row),
|
},
|
},
|
{
|
label: '作废',
|
type: 'link',
|
danger: true,
|
icon: ACTION_ICON.DELETE,
|
auth: ['finance:voucher:update-status'],
|
ifShow: () =>
|
row.status === VOUCHER_STATUS_UNPOSTED ||
|
row.status === VOUCHER_STATUS_POSTED,
|
onClick: handleCancel.bind(null, row),
|
},
|
{
|
label: $t('common.delete'),
|
type: 'link',
|
danger: true,
|
icon: ACTION_ICON.DELETE,
|
auth: ['finance:voucher:delete'],
|
ifShow: () =>
|
row.status === VOUCHER_STATUS_UNPOSTED ||
|
row.status === VOUCHER_STATUS_CANCELLED,
|
popConfirm: {
|
title: $t('ui.actionMessage.deleteConfirm', [row.voucherNo]),
|
confirm: handleDelete.bind(null, [row.id!]),
|
},
|
},
|
]"
|
/>
|
</template>
|
</Grid>
|
</Page>
|
</template>
|