刘光辉
6 小时以前 cf11e63b659afcc9792ab3e395f1b45d844431a8
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
<script lang="ts" setup>
import type {
  TmsQuizAnswerPaper,
  TmsRecordAttachment,
  TmsRecordDetail,
  TmsRecordIncomplete,
  TmsRecordParticipant,
  TmsRecordProgress,
} from './types';
 
import { computed, onMounted, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
 
import { useMessage } from '@jnpf/hooks';
import {
  Descriptions as ADescriptions,
  DescriptionsItem as ADescriptionsItem,
  Modal as AModal,
} from 'ant-design-vue';
 
import {
  getTmsRecordDetail,
  getTmsRecordIncomplete,
  getTmsRecordProgress,
  getTmsRecordQuizAnswers,
  getTmsRecordQuizCount,
} from '#/api/x/tms/record';
import { TmsAttachmentPreview } from '#/views/x/tms/shared/attachmentPreview';
import QuizPaperView from '#/views/x/tms/shared/QuizPaperView.vue';
import { TMS_BTN } from '#/views/x/tms/shared/ui';
 
import {
  colorOfArchiveStatus,
  labelOfArchiveStatus,
  labelOfCategory,
  labelOfEvalMode,
  labelOfPassFlag,
  labelOfTrainMode,
  loadRecordDics,
} from './constants';
 
import '#/views/x/tms/shared/page.css';
 
defineOptions({ name: 'TmsRecordDetail' });
 
const route = useRoute();
const router = useRouter();
const { createMessage } = useMessage();
 
const loading = ref(false);
const detail = ref<TmsRecordDetail | null>(null);
const progress = ref<TmsRecordProgress | null>(null);
const incompleteList = ref<TmsRecordIncomplete[]>([]);
const quizCount = ref<number | null>(null);
const previewOpen = ref(false);
const previewFileId = ref<string>();
const quizPaperOpen = ref(false);
const quizPaperLoading = ref(false);
const quizPaper = ref<TmsQuizAnswerPaper | null>(null);
 
const participantColumns = computed(() => {
  const cols: Array<{ title: string; dataIndex: string; width?: number }> = [
    { title: '姓名', dataIndex: 'userName', width: 120 },
    { title: '部门', dataIndex: 'deptName', width: 160 },
    { title: '签到日期', dataIndex: 'signDate', width: 160 },
  ];
  if (detail.value?.evalMode === 'quiz') {
    cols.push({ title: '提问成绩', dataIndex: 'quizScore', width: 100 });
  } else if (detail.value?.evalMode === 'exam') {
    cols.push({ title: '考试成绩', dataIndex: 'examScore', width: 100 });
  } else {
    cols.push({ title: '考试成绩', dataIndex: 'examScore', width: 100 });
  }
  cols.push({ title: '是否合格', dataIndex: 'passFlag', width: 90 });
  if (detail.value?.evalMode === 'quiz') {
    cols.push({ title: '操作', dataIndex: 'action', width: 110 });
  }
  return cols;
});
 
const incompleteColumns = [
  { title: '部门', dataIndex: 'deptName', width: 180 },
  { title: '姓名', dataIndex: 'userName', width: 140 },
  { title: '未完成原因', dataIndex: 'reason', width: 160 },
  { title: '签到时间', dataIndex: 'signTime', width: 170 },
  { title: '合格标识', dataIndex: 'passFlag', width: 100 },
];
 
const showQuizHint = computed(() => detail.value?.evalMode === 'quiz');
const showPracticeEntry = computed(() => detail.value?.evalMode === 'practice');
const canRefresh = computed(() => Boolean(detail.value?.id));
 
onMounted(async () => {
  await loadRecordDics();
  await loadData();
});
 
async function loadData() {
  const id = String(route.params.id || '');
  if (!id) {
    router.replace('/tms/record');
    return;
  }
  loading.value = true;
  try {
    detail.value = await getTmsRecordDetail(id);
    await loadProgress(id);
  } catch (e: any) {
    createMessage.error(e?.message || '加载培训记录失败');
    router.replace('/tms/record');
  } finally {
    loading.value = false;
  }
}
 
async function loadProgress(id?: string) {
  const recordId = id || String(detail.value?.id || route.params.id || '');
  if (!recordId) return;
  const [p, incomplete, qc] = await Promise.all([
    getTmsRecordProgress(recordId).catch(() => null),
    getTmsRecordIncomplete(recordId).catch(() => [] as TmsRecordIncomplete[]),
    getTmsRecordQuizCount(recordId).catch(() => null),
  ]);
  progress.value = p;
  incompleteList.value = Array.isArray(incomplete) ? incomplete : [];
  quizCount.value = typeof qc === 'number' ? qc : null;
}
 
function goBack() {
  const from = String(route.query.from || '');
  if (from === 'archived') {
    router.push('/tms/record/archived');
    return;
  }
  if (from === 'ready') {
    router.push('/tms/record/ready');
    return;
  }
  if (from === 'main') {
    router.push('/tms/record');
    return;
  }
  router.back();
}
 
function goPractice() {
  const id = String(detail.value?.id || route.params.id || '');
  if (!id) return;
  router.push(`/tms/record/practice/${id}`);
}
 
function goSign() {
  const id = String(detail.value?.id || route.params.id || '');
  if (!id) return;
  router.push(`/tms/record/sign/${id}`);
}
 
async function handleRefreshProgress() {
  loading.value = true;
  try {
    await loadProgress();
    createMessage.success('进度已刷新');
  } catch (e: any) {
    createMessage.error(e?.message || '刷新失败');
  } finally {
    loading.value = false;
  }
}
 
function passText(row: TmsRecordParticipant | TmsRecordIncomplete) {
  const text = labelOfPassFlag(row.passFlag);
  return text === '-' ? '' : text;
}
 
function rateText(v?: number | null) {
  if (v == null || Number.isNaN(Number(v))) return '-';
  return `${Number(v)}%`;
}
 
function openPreview(file?: TmsRecordAttachment) {
  if (!detail.value?.attachments?.length) {
    createMessage.info('暂无可预览附件');
    return;
  }
  previewFileId.value = file?.id || detail.value.attachments[0]?.id;
  previewOpen.value = true;
}
 
async function openQuizPaper(row: TmsRecordParticipant) {
  const recordId = String(detail.value?.id || route.params.id || '');
  const userId = String(row.userId || '');
  if (!recordId || !userId) {
    createMessage.warning('缺少学员信息');
    return;
  }
  quizPaperLoading.value = true;
  quizPaperOpen.value = true;
  quizPaper.value = null;
  try {
    quizPaper.value = await getTmsRecordQuizAnswers(recordId, userId);
  } catch (e: any) {
    quizPaperOpen.value = false;
    createMessage.error(e?.message || '加载提问答卷失败');
  } finally {
    quizPaperLoading.value = false;
  }
}
</script>
 
<template>
  <div class="jnpf-content-wrapper tms-record-detail-page" v-loading="loading">
    <div class="jnpf-content-wrapper-center">
      <div class="jnpf-content-wrapper-content tms-record-detail-wrap" v-if="detail">
        <a-card title="培训记录详情" :bordered="false">
          <template #extra>
            <a-space>
              <a-button @click="goBack">{{ TMS_BTN.back }}</a-button>
              <a-button v-if="canRefresh" @click="handleRefreshProgress">刷新进度</a-button>
              <a-button
                v-if="detail.archiveStatus !== 'archived'"
                @click="goSign"
              >
                {{ TMS_BTN.signQr }}
              </a-button>
              <a-button v-if="showPracticeEntry" type="primary" @click="goPractice">
                实操打分
              </a-button>
            </a-space>
          </template>
 
          <a-divider orientation="left">参与进度(实时)</a-divider>
          <ADescriptions v-if="progress" :column="4" bordered size="small" class="mb-desc">
            <ADescriptionsItem label="应到人数">{{ progress.totalCount ?? 0 }}</ADescriptionsItem>
            <ADescriptionsItem label="已签到">{{ progress.signedCount ?? 0 }}</ADescriptionsItem>
            <ADescriptionsItem label="合格人数">{{ progress.passedCount ?? 0 }}</ADescriptionsItem>
            <ADescriptionsItem label="未完成人数">{{ progress.incompleteCount ?? 0 }}</ADescriptionsItem>
            <ADescriptionsItem label="签到率">{{ rateText(progress.signRate) }}</ADescriptionsItem>
            <ADescriptionsItem label="合格率">{{ rateText(progress.passRate) }}</ADescriptionsItem>
            <ADescriptionsItem label="未完成率">{{ rateText(progress.incompleteRate) }}</ADescriptionsItem>
            <ADescriptionsItem label="考核方式">{{ labelOfEvalMode(progress.evalMode || detail.evalMode) }}</ADescriptionsItem>
            <ADescriptionsItem v-if="showQuizHint" label="应提问人数" :span="4">
              {{ quizCount == null ? '-' : quizCount }}
            </ADescriptionsItem>
          </ADescriptions>
          <a-empty v-else description="暂无进度数据" />
 
          <a-divider orientation="left">未完成人员(按部门排序)</a-divider>
          <a-table
            size="small"
            bordered
            row-key="personTaskId"
            :pagination="false"
            :columns="incompleteColumns"
            :data-source="incompleteList"
            :locale="{ emptyText: '暂无未完成人员' }"
          >
            <template #bodyCell="{ column, record }">
              <template v-if="column.dataIndex === 'passFlag'">
                {{ passText(record) }}
              </template>
            </template>
          </a-table>
 
          <a-divider orientation="left">基本信息</a-divider>
          <ADescriptions :column="2" bordered size="small">
            <ADescriptionsItem label="培训编号">{{ detail.recordNo }}</ADescriptionsItem>
            <ADescriptionsItem label="归档状态">
              <a-tag :color="colorOfArchiveStatus(detail.archiveStatus)">
                {{ labelOfArchiveStatus(detail.archiveStatus) }}
              </a-tag>
            </ADescriptionsItem>
            <ADescriptionsItem label="任务关闭时间">{{ detail.closeTime || '-' }}</ADescriptionsItem>
            <ADescriptionsItem label="培训主题" :span="2">
              <div class="pre-line">{{ detail.subject }}</div>
            </ADescriptionsItem>
            <ADescriptionsItem label="培训要点" :span="2">
              <div class="pre-line">{{ detail.keyPoints || '-' }}</div>
            </ADescriptionsItem>
            <ADescriptionsItem label="培训开始时间">{{ detail.startTime }}</ADescriptionsItem>
            <ADescriptionsItem label="培训结束时间">{{ detail.endTime || '-' }}</ADescriptionsItem>
            <ADescriptionsItem label="培训地点" :span="2">{{ detail.placeName || '-' }}</ADescriptionsItem>
            <ADescriptionsItem label="培训分类">{{ labelOfCategory(detail.category) }}</ADescriptionsItem>
            <ADescriptionsItem label="培训方式">{{ labelOfTrainMode(detail.trainMode || detail.trainType) }}</ADescriptionsItem>
            <ADescriptionsItem label="培训师">{{ detail.trainerName }}</ADescriptionsItem>
            <ADescriptionsItem label="培训考核方式">{{ labelOfEvalMode(detail.evalMode) }}</ADescriptionsItem>
            <ADescriptionsItem label="培训对象" :span="2">{{ detail.trainees || '-' }}</ADescriptionsItem>
            <ADescriptionsItem label="附件" :span="2">
              <div v-if="detail.attachments?.length" class="attach-list">
                <div v-for="file in detail.attachments" :key="file.id" class="attach-item">
                  <span>{{ file.name }}</span>
                  <a class="attach-link" @click.prevent="openPreview(file)">预览</a>
                </div>
              </div>
              <span v-else>-</span>
            </ADescriptionsItem>
            <ADescriptionsItem label="备注" :span="2">{{ detail.remark || '-' }}</ADescriptionsItem>
          </ADescriptions>
 
          <a-divider orientation="left">参加人员名单</a-divider>
          <a-table
            size="small"
            bordered
            row-key="id"
            :pagination="false"
            :columns="participantColumns"
            :data-source="detail.participants || []"
            :locale="{ emptyText: '暂无参加人员' }"
          >
            <template #bodyCell="{ column, record }">
              <template v-if="column.dataIndex === 'passFlag'">
                {{ passText(record) }}
              </template>
              <template v-else-if="column.dataIndex === 'quizScore'">
                {{ record.quizScore ?? (record.hasQuizAnswer ? '-' : '未作答') }}
              </template>
              <template v-else-if="column.dataIndex === 'action'">
                <a
                  v-if="record.hasQuizAnswer && record.userId"
                  class="attach-link"
                  @click.prevent="openQuizPaper(record)"
                >
                  查看答卷
                </a>
                <span v-else class="text-muted">-</span>
              </template>
            </template>
          </a-table>
        </a-card>
      </div>
    </div>
 
    <AModal
      v-model:open="quizPaperOpen"
      :title="`提问答卷${quizPaper?.userName ? ` · ${quizPaper.userName}` : ''}`"
      width="800px"
      :footer="null"
      :destroy-on-close="true"
      wrap-class-name="tms-quiz-paper-modal"
    >
      <QuizPaperView :paper="quizPaper" :loading="quizPaperLoading" answer-label="学员答案" />
    </AModal>
 
    <AModal
      v-model:open="previewOpen"
      title="附件预览"
      width="90%"
      :footer="null"
      :destroy-on-close="true"
      wrap-class-name="tms-attach-preview-modal"
    >
      <div class="preview-modal-body">
        <TmsAttachmentPreview
          v-model="previewFileId"
          :files="detail?.attachments || []"
          list-title="附件列表"
          empty-preview-text="请选择附件预览"
        />
      </div>
    </AModal>
  </div>
</template>
 
<style scoped>
.tms-record-detail-page {
  height: 100%;
  min-height: 0;
}
 
.tms-record-detail-wrap {
  height: 100%;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto !important;
  background: #fff;
  box-sizing: border-box;
}
 
.mb-desc {
  margin-bottom: 8px;
}
 
.pre-line {
  white-space: pre-wrap;
  line-height: 1.5;
}
 
.attach-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
 
.attach-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
 
.text-muted {
  color: rgba(0, 0, 0, 0.45);
}
 
.attach-link {
  flex-shrink: 0;
  color: var(--primary-color, #1677ff);
  cursor: pointer;
}
 
.attach-link:hover {
  text-decoration: underline;
}
 
.preview-modal-body {
  height: min(72vh, 720px);
  min-height: 420px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
 
.preview-modal-body :deep(.tms-attach-preview) {
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
}
</style>
 
<style>
.tms-attach-preview-modal .ant-modal-body {
  padding: 12px 16px 16px;
}
 
.tms-quiz-paper-modal .ant-modal-body {
  padding: 20px 24px 24px;
}
</style>