<script lang="ts" setup>
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
import type { ResearchApplicationApi } from '#/api/research/application';
|
import type { ResearchFundRecordApi } from '#/api/research/fund';
|
|
import { computed, ref } from 'vue';
|
|
import { useVbenModal } from '@vben/common-ui';
|
|
import { Alert, message, Tag } from 'ant-design-vue';
|
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
import { getApplication } from '#/api/research/application';
|
import { deleteFundRecord, getFundRecordList } from '#/api/research/fund';
|
|
import { ApplicationStatus, FundStatus, useFundColumns } from '../data';
|
import FundForm from './fund-form.vue';
|
|
defineOptions({ name: 'ResearchFundPanel' });
|
|
const emit = defineEmits(['success']);
|
|
const applicationId = ref<number>();
|
const application = ref<ResearchApplicationApi.Application>();
|
const records = ref<ResearchFundRecordApi.FundRecord[]>([]);
|
|
/** 仅「已立项」的申报单可登记拨款 */
|
const editable = computed(
|
() => application.value?.status === ApplicationStatus.APPROVED,
|
);
|
|
/** 已登记拨付金额合计 */
|
const registeredAmount = computed(() =>
|
records.value.reduce((sum, item) => sum + (Number(item.amount) || 0), 0),
|
);
|
|
/** 申请经费可用余额(负数表示已超额登记) */
|
const remainder = computed(
|
() => (Number(application.value?.budgetAmount) || 0) - registeredAmount.value,
|
);
|
|
/** 各状态记录数量,用于顶部提示(0 条时不提示) */
|
const statusCount = (status: number) =>
|
records.value.filter((item) => item.status === status).length;
|
|
const [FundFormModal, fundFormModalApi] = useVbenModal({
|
connectedComponent: FundForm,
|
destroyOnClose: true,
|
});
|
|
const [Grid, gridApi] = useVbenVxeGrid({
|
gridOptions: {
|
columns: useFundColumns(true),
|
data: [],
|
minHeight: 280,
|
autoResize: true,
|
border: true,
|
rowConfig: {
|
keyField: 'id',
|
isHover: true,
|
},
|
pagerConfig: {
|
enabled: false,
|
},
|
toolbarConfig: {
|
enabled: false,
|
},
|
} as VxeTableGridOptions<ResearchFundRecordApi.FundRecord>,
|
});
|
|
async function refresh() {
|
if (!applicationId.value) {
|
return;
|
}
|
const [recordList, applicationDetail] = await Promise.all([
|
getFundRecordList(applicationId.value),
|
getApplication(applicationId.value),
|
]);
|
records.value = recordList;
|
application.value = applicationDetail;
|
gridApi.setGridOptions({ data: recordList });
|
}
|
|
/** 拨款记录增删改后:本面板重载,同时通知列表页刷新 */
|
async function handleChanged() {
|
await refresh();
|
emit('success');
|
}
|
|
function handleCreate() {
|
fundFormModalApi
|
.setData({ applicationId: applicationId.value!, remainder: remainder.value })
|
.open();
|
}
|
|
function handleEdit(row: ResearchFundRecordApi.FundRecord) {
|
fundFormModalApi
|
.setData({
|
applicationId: applicationId.value!,
|
// 编辑时把当前记录自身金额加回,避免用户看到「余额」偏小产生误解
|
remainder: remainder.value + (Number(row.amount) || 0),
|
record: row,
|
})
|
.open();
|
}
|
|
async function handleDelete(row: ResearchFundRecordApi.FundRecord) {
|
const hideLoading = message.loading({ content: '删除中...', duration: 0 });
|
try {
|
await deleteFundRecord(row.id!);
|
message.success('删除成功');
|
await handleChanged();
|
} finally {
|
hideLoading();
|
}
|
}
|
|
const [Modal, modalApi] = useVbenModal({
|
async onOpenChange(isOpen: boolean) {
|
if (!isOpen) {
|
applicationId.value = undefined;
|
application.value = undefined;
|
records.value = [];
|
return;
|
}
|
const data = modalApi.getData<{ id: number }>();
|
applicationId.value = data.id;
|
modalApi.lock();
|
try {
|
const [recordList, applicationDetail] = await Promise.all([
|
getFundRecordList(data.id),
|
getApplication(data.id),
|
]);
|
records.value = recordList;
|
application.value = applicationDetail;
|
gridApi.setGridOptions({ data: recordList });
|
} finally {
|
modalApi.unlock();
|
}
|
},
|
});
|
</script>
|
|
<template>
|
<Modal title="经费拨付" class="w-4/5" :show-confirm-button="false">
|
<div class="space-y-3">
|
<Alert
|
v-if="!editable"
|
type="info"
|
show-icon
|
message="仅「已立项」的课题申报书可以登记经费拨付记录"
|
/>
|
<div class="flex flex-wrap items-center gap-6 rounded border border-border p-3">
|
<div>
|
<span class="text-gray-500">课题名称:</span>
|
<span class="font-medium">{{ application?.title || '-' }}</span>
|
</div>
|
<div>
|
<span class="text-gray-500">立项编号:</span>
|
<span class="font-medium">{{ application?.researchNo || '未立项' }}</span>
|
</div>
|
<div>
|
<span class="text-gray-500">申请经费:</span>
|
<span class="font-medium">
|
{{ Number(application?.budgetAmount || 0).toFixed(2) }} 元
|
</span>
|
</div>
|
<div>
|
<span class="text-gray-500">已登记拨付:</span>
|
<span class="font-medium">{{ registeredAmount.toFixed(2) }} 元</span>
|
</div>
|
<div>
|
<span class="text-gray-500">可用余额:</span>
|
<span
|
class="font-medium"
|
:class="remainder < 0 ? 'text-red-500' : ''"
|
>
|
{{ remainder.toFixed(2) }} 元
|
</span>
|
</div>
|
</div>
|
|
<Alert
|
v-if="statusCount(FundStatus.APPROVING) > 0"
|
type="info"
|
show-icon
|
:message="`有 ${statusCount(FundStatus.APPROVING)} 条拨付记录正在报销审批中,暂不可修改;财务审批结果将自动回写本记录`"
|
/>
|
<Alert
|
v-if="statusCount(FundStatus.PAID) > 0"
|
type="success"
|
show-icon
|
:message="`有 ${statusCount(FundStatus.PAID)} 条拨付记录财务已通过,拨款完成`"
|
/>
|
<Alert
|
v-if="statusCount(FundStatus.REJECTED) > 0"
|
type="error"
|
show-icon
|
:message="`有 ${statusCount(FundStatus.REJECTED)} 条拨付记录财务已驳回,请修改金额或凭证后点「重新发起报销」`"
|
/>
|
|
<div v-if="editable">
|
<TableAction
|
:actions="[
|
{
|
label: '登记拨款记录',
|
type: 'primary',
|
icon: ACTION_ICON.ADD,
|
auth: ['research:fund:create'],
|
onClick: handleCreate,
|
},
|
]"
|
/>
|
</div>
|
|
<Grid>
|
<template #hasAttachment="{ row }">
|
<Tag :color="row.hasAttachment ? 'success' : 'warning'">
|
{{ row.hasAttachment ? '已上传' : '缺失' }}
|
</Tag>
|
</template>
|
<template #actions="{ row }">
|
<TableAction
|
v-if="editable"
|
:actions="[
|
{
|
label: '编辑',
|
type: 'link',
|
icon: ACTION_ICON.EDIT,
|
auth: ['research:fund:update'],
|
ifShow: () => row.status === FundStatus.PENDING,
|
onClick: handleEdit.bind(null, row),
|
},
|
{
|
label: '重新发起报销',
|
type: 'link',
|
icon: ACTION_ICON.REFRESH,
|
auth: ['research:fund:update'],
|
ifShow: () => row.status === FundStatus.REJECTED,
|
onClick: handleEdit.bind(null, row),
|
},
|
{
|
label: '删除',
|
type: 'link',
|
danger: true,
|
icon: ACTION_ICON.DELETE,
|
auth: ['research:fund:delete'],
|
ifShow: () => row.status === FundStatus.PENDING,
|
popConfirm: {
|
title: `确认删除「${row.batchName || '本条'}」拨款记录吗?`,
|
confirm: handleDelete.bind(null, row),
|
},
|
},
|
]"
|
/>
|
</template>
|
</Grid>
|
</div>
|
</Modal>
|
<FundFormModal @success="handleChanged" />
|
</template>
|