<script lang="ts" setup>
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
import type { FinIntangibleAssetApi } from '#/api/erp/finance/intangible-asset';
|
|
import { ref } from 'vue';
|
|
import { Page, useVbenModal } from '@vben/common-ui';
|
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
|
|
import { message } from 'ant-design-vue';
|
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
import {
|
amortizeIntangibleAssetList,
|
deleteIntangibleAsset,
|
deleteIntangibleAssetList,
|
exportIntangibleAsset,
|
getIntangibleAssetPage,
|
} from '#/api/erp/finance/intangible-asset';
|
import { $t } from '#/locales';
|
|
import { INTANGIBLE_STATUS_IN_USE, useGridColumns, useGridFormSchema } from './data';
|
import Form from './modules/form.vue';
|
|
/** 无形资产列表 */
|
defineOptions({ name: 'FinIntangibleAsset' });
|
|
const [FormModal, formModalApi] = useVbenModal({
|
connectedComponent: Form,
|
destroyOnClose: true,
|
});
|
|
/** 刷新表格 */
|
function handleRefresh() {
|
gridApi.query();
|
}
|
|
/** 导出表格 */
|
async function handleExport() {
|
const data = await exportIntangibleAsset(await gridApi.formApi.getValues());
|
downloadFileFromBlobPart({ fileName: '无形资产.xls', source: data });
|
}
|
|
/** 新增无形资产 */
|
function handleCreate() {
|
formModalApi.setData(null).open();
|
}
|
|
/** 编辑无形资产 */
|
function handleEdit(row: FinIntangibleAssetApi.IntangibleAsset) {
|
formModalApi.setData(row).open();
|
}
|
|
/** 删除无形资产 */
|
async function handleDelete(ids: number[]) {
|
const hideLoading = message.loading({
|
content: $t('ui.actionMessage.deleting'),
|
duration: 0,
|
});
|
try {
|
await (ids.length === 1
|
? deleteIntangibleAsset(ids[0]!)
|
: deleteIntangibleAssetList(ids));
|
checkedIds.value = [];
|
message.success($t('ui.actionMessage.deleteSuccess'));
|
handleRefresh();
|
} finally {
|
hideLoading();
|
}
|
}
|
|
/** 计提摊销 */
|
async function handleAmortize(ids: number[]) {
|
const hideLoading = message.loading({
|
content: '计提摊销中...',
|
duration: 0,
|
});
|
try {
|
const result = await amortizeIntangibleAssetList(ids);
|
message.success(
|
`本次计提 ${result.processedCount} 项资产,摊销合计 ${result.totalMonthlyAmortization} 元`,
|
);
|
handleRefresh();
|
} finally {
|
hideLoading();
|
}
|
}
|
|
const checkedIds = ref<number[]>([]);
|
function handleRowCheckboxChange({
|
records,
|
}: {
|
records: FinIntangibleAssetApi.IntangibleAsset[];
|
}) {
|
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 getIntangibleAssetPage({
|
pageNo: page.currentPage,
|
pageSize: page.pageSize,
|
...formValues,
|
});
|
},
|
},
|
},
|
rowConfig: {
|
keyField: 'id',
|
isHover: true,
|
},
|
toolbarConfig: {
|
refresh: true,
|
search: true,
|
},
|
} as VxeTableGridOptions<FinIntangibleAssetApi.IntangibleAsset>,
|
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:intangible-asset:create'],
|
onClick: handleCreate,
|
},
|
{
|
label: '计提摊销',
|
type: 'primary',
|
icon: ACTION_ICON.AUDIT,
|
auth: ['finance:intangible-asset:amortize'],
|
popConfirm: {
|
title: isEmpty(checkedIds)
|
? '未勾选资产,将对全部「在用」且未摊完的无形资产计提一个月摊销,确认继续吗?'
|
: `确认对已勾选的 ${checkedIds.length} 项资产计提一个月摊销吗?`,
|
confirm: handleAmortize.bind(null, checkedIds),
|
},
|
},
|
{
|
label: $t('ui.actionTitle.export'),
|
type: 'primary',
|
icon: ACTION_ICON.DOWNLOAD,
|
auth: ['finance:intangible-asset:export'],
|
onClick: handleExport,
|
},
|
{
|
label: '批量删除',
|
type: 'primary',
|
danger: true,
|
disabled: isEmpty(checkedIds),
|
icon: ACTION_ICON.DELETE,
|
auth: ['finance:intangible-asset:delete'],
|
popConfirm: {
|
title: '是否删除所选中数据?',
|
confirm: handleDelete.bind(null, checkedIds),
|
},
|
},
|
]"
|
/>
|
</template>
|
<template #actions="{ row }">
|
<TableAction
|
:actions="[
|
{
|
label: $t('common.edit'),
|
type: 'link',
|
icon: ACTION_ICON.EDIT,
|
auth: ['finance:intangible-asset:update'],
|
onClick: handleEdit.bind(null, row),
|
},
|
{
|
label: '计提摊销',
|
type: 'link',
|
icon: ACTION_ICON.AUDIT,
|
auth: ['finance:intangible-asset:amortize'],
|
ifShow: () => row.status === INTANGIBLE_STATUS_IN_USE,
|
popConfirm: {
|
title: `确认对资产【${row.assetName}】计提一个月摊销吗?`,
|
confirm: handleAmortize.bind(null, [row.id!]),
|
},
|
},
|
{
|
label: $t('common.delete'),
|
type: 'link',
|
danger: true,
|
icon: ACTION_ICON.DELETE,
|
auth: ['finance:intangible-asset:delete'],
|
popConfirm: {
|
title: $t('ui.actionMessage.deleteConfirm', [row.assetName]),
|
confirm: handleDelete.bind(null, [row.id!]),
|
},
|
},
|
]"
|
/>
|
</template>
|
</Grid>
|
</Page>
|
</template>
|