liu
2026-09-29 982c97ab82f3beb1b4febcf014562eda34b9fc05
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<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>