<script lang="ts" setup>
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
import type { ResearchApplicationApi } from '#/api/research/application';
|
|
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 {
|
deleteTopicReview,
|
getApplication,
|
getTopicReviewList,
|
} from '#/api/research/application';
|
|
import { ApplicationStatus, useReviewColumns } from '../data';
|
import ReviewForm from './review-form.vue';
|
|
defineOptions({ name: 'ResearchTopicReviewPanel' });
|
|
const emit = defineEmits(['success']);
|
|
const applicationId = ref<number>();
|
const application = ref<ResearchApplicationApi.Application>();
|
const reviews = ref<ResearchApplicationApi.TopicReview[]>([]);
|
|
/** 仅「审批中」的申报单可增删改专家评分 */
|
const editable = computed(
|
() => application.value?.status === ApplicationStatus.APPROVING,
|
);
|
|
const STATUS_LABELS: Record<number, string> = {
|
[ApplicationStatus.DRAFT]: '草稿',
|
[ApplicationStatus.APPROVING]: '审批中',
|
[ApplicationStatus.APPROVED]: '已立项',
|
[ApplicationStatus.REJECTED]: '已驳回',
|
};
|
|
const statusLabel = computed(() =>
|
application.value?.status === undefined ||
|
application.value?.status === null
|
? '未知'
|
: (STATUS_LABELS[application.value.status] ?? '未知'),
|
);
|
|
const [ReviewFormModal, reviewFormModalApi] = useVbenModal({
|
connectedComponent: ReviewForm,
|
destroyOnClose: true,
|
});
|
|
const [Grid, gridApi] = useVbenVxeGrid({
|
gridOptions: {
|
columns: useReviewColumns(true),
|
data: [],
|
minHeight: 300,
|
autoResize: true,
|
border: true,
|
rowConfig: {
|
keyField: 'id',
|
isHover: true,
|
},
|
pagerConfig: {
|
enabled: false,
|
},
|
toolbarConfig: {
|
enabled: false,
|
},
|
} as VxeTableGridOptions<ResearchApplicationApi.TopicReview>,
|
});
|
|
/** 拉取评审明细并同步主单汇总值(后端在增删改后已重算均分与结论) */
|
async function refresh() {
|
if (!applicationId.value) {
|
return;
|
}
|
const [reviewList, applicationDetail] = await Promise.all([
|
getTopicReviewList(applicationId.value),
|
getApplication(applicationId.value),
|
]);
|
reviews.value = reviewList;
|
application.value = applicationDetail;
|
gridApi.setGridOptions({ data: reviewList });
|
}
|
|
/** 评审明细变化后:本面板重载,同时通知列表页刷新(均分会展示在列表) */
|
async function handleChanged() {
|
await refresh();
|
emit('success');
|
}
|
|
function handleCreate() {
|
reviewFormModalApi
|
.setData({ applicationId: applicationId.value! })
|
.open();
|
}
|
|
function handleEdit(row: ResearchApplicationApi.TopicReview) {
|
reviewFormModalApi
|
.setData({ applicationId: applicationId.value!, review: row })
|
.open();
|
}
|
|
async function handleDelete(row: ResearchApplicationApi.TopicReview) {
|
const hideLoading = message.loading({ content: '删除中...', duration: 0 });
|
try {
|
await deleteTopicReview(row.id!);
|
message.success('删除成功,均分与排名已重新汇总');
|
await handleChanged();
|
} finally {
|
hideLoading();
|
}
|
}
|
|
const [Modal, modalApi] = useVbenModal({
|
async onOpenChange(isOpen: boolean) {
|
if (!isOpen) {
|
applicationId.value = undefined;
|
application.value = undefined;
|
reviews.value = [];
|
return;
|
}
|
const data = modalApi.getData<{ id: number }>();
|
applicationId.value = data.id;
|
modalApi.lock();
|
try {
|
await refresh();
|
} 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="`当前申报单状态为「${statusLabel}」,仅「审批中」状态可录入或修改专家评分`"
|
/>
|
<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?.reviewAvgScore === null ||
|
application?.reviewAvgScore === undefined
|
? '未汇总'
|
: Number(application.reviewAvgScore).toFixed(2)
|
}}
|
</span>
|
</div>
|
<div>
|
<span class="text-gray-500">评审结论:</span>
|
<Tag
|
v-if="application?.reviewPass !== null && application?.reviewPass !== undefined"
|
:color="application.reviewPass === 1 ? 'success' : 'error'"
|
>
|
{{ application.reviewPass === 1 ? '推荐立项' : '不推荐立项' }}
|
</Tag>
|
<span v-else>未汇总</span>
|
</div>
|
<div>
|
<span class="text-gray-500">已录入专家数:</span>
|
<span class="font-medium">{{ reviews.length }}</span>
|
</div>
|
</div>
|
|
<div v-if="editable">
|
<TableAction
|
:actions="[
|
{
|
label: '录入专家评分',
|
type: 'primary',
|
icon: ACTION_ICON.ADD,
|
auth: ['research:review:create'],
|
onClick: handleCreate,
|
},
|
]"
|
/>
|
</div>
|
|
<Grid>
|
<template #actions="{ row }">
|
<TableAction
|
v-if="editable"
|
:actions="[
|
{
|
label: '编辑',
|
type: 'link',
|
icon: ACTION_ICON.EDIT,
|
auth: ['research:review:update'],
|
onClick: handleEdit.bind(null, row),
|
},
|
{
|
label: '删除',
|
type: 'link',
|
danger: true,
|
icon: ACTION_ICON.DELETE,
|
auth: ['research:review:delete'],
|
popConfirm: {
|
title: `确认删除专家「${row.evaluatorName}」的评分记录吗?删除后均分与排名将重新汇总`,
|
confirm: handleDelete.bind(null, row),
|
},
|
},
|
]"
|
/>
|
</template>
|
</Grid>
|
</div>
|
</Modal>
|
<ReviewFormModal @success="handleChanged" />
|
</template>
|