liuyu
4 小时以前 82a74ba0402ab546ba524d23ce62198c4d00d2f7
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
<script lang="ts" setup>
import type { ActionItem, BasicColumn } from '@jnpf/ui/vxeTable';
 
import type { ExamScoreDetailRow } from './types';
 
import { onMounted, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
 
import { useMessage } from '@jnpf/hooks';
import { BasicVxeTable, TableAction, useVxeTable } from '@jnpf/ui/vxeTable';
 
import { getExamScoreDetail } from '#/api/x/tms/examScore';
 
defineOptions({ name: 'TmsExamScoreDetail' });
 
const route = useRoute();
const router = useRouter();
const { createMessage } = useMessage();
 
const titleText = ref('考生试卷列表');
const summaryId = String(route.params.id || '');
const loaded = ref(false);
 
const columns: BasicColumn[] = [
  { title: '培训主题', dataIndex: 'taskSubject', minWidth: 220 },
  { title: '培训任务编号', dataIndex: 'taskNo', width: 140 },
  {
    title: '用户ID',
    dataIndex: 'userName',
    width: 120,
    customRender: ({ record }) => {
      const row = record as ExamScoreDetailRow;
      return row.userName || row.userId;
    },
  },
  { title: '考试开始时间', dataIndex: 'examStart', width: 170 },
  { title: '考试结束时间', dataIndex: 'examEnd', width: 170 },
  { title: '成绩', dataIndex: 'score', width: 80, align: 'center' },
  {
    title: '是否合格',
    dataIndex: 'passFlag',
    width: 100,
    align: 'center',
    slots: { default: 'passFlag' },
  },
  { title: '来源IP地址', dataIndex: 'sourceIp', width: 140 },
];
 
const [registerTable, { getSelectRows, reload }] = useVxeTable({
  api: fetchList,
  columns,
  immediate: false,
  rowKey: 'id',
  rowSelection: { type: 'checkbox' },
  useSearchForm: true,
  formConfig: {
    baseColProps: { span: 6 },
    compact: true,
    schemas: [
      {
        field: 'keyword',
        label: '关键词',
        component: 'Input',
        componentProps: { placeholder: '请输入检索关键字', submitOnPressEnter: true },
      },
      {
        field: 'passFlag',
        label: '是否合格',
        component: 'Select',
        componentProps: {
          allowClear: true,
          placeholder: '请选择',
          options: [
            { id: '1', fullName: '是' },
            { id: '0', fullName: '否' },
          ],
        },
      },
    ],
  },
  pagination: false,
  actionColumn: {
    width: 110,
    title: '操作',
    dataIndex: 'action',
    fixed: 'right',
  },
});
 
onMounted(async () => {
  if (!summaryId) {
    router.replace('/tms/examScore');
    return;
  }
  try {
    const detail = await getExamScoreDetail(summaryId);
    titleText.value = `考生试卷列表 · ${detail.taskNo}`;
    loaded.value = true;
    reload();
  } catch (e: any) {
    createMessage.error(e?.message || '加载失败');
    router.replace('/tms/examScore');
  }
});
 
async function fetchList(params: Record<string, any>) {
  if (!loaded.value) {
    return { data: { list: [], pagination: { total: 0 } } };
  }
  const detail = await getExamScoreDetail(summaryId);
  let list = [...(detail.rows || [])];
  if (params.keyword && params.keyword !== 'null') {
    const kw = String(params.keyword).trim().toLowerCase();
    list = list.filter(
      (x) =>
        (x.userName || '').toLowerCase().includes(kw) ||
        (x.userId || '').toLowerCase().includes(kw) ||
        (x.taskSubject || '').toLowerCase().includes(kw),
    );
  }
  if (params.passFlag === '0' || params.passFlag === '1') {
    list = list.filter((x) => x.passFlag === params.passFlag);
  }
  return { data: { list, pagination: { total: list.length, currentPage: 1, pageSize: list.length || 20 } } };
}
 
function goBack() {
  router.push('/tms/examScore');
}
 
function viewPaper(record: ExamScoreDetailRow) {
  router.push(`/tms/examScore/paper/${record.id}`);
}
 
function handleViewSelected() {
  const rows = (getSelectRows?.() || []) as ExamScoreDetailRow[];
  if (!rows.length) {
    createMessage.warning('请先勾选一名考生');
    return;
  }
  if (rows.length > 1) {
    createMessage.warning('一次只能查看一份试卷,请只勾选一条');
    return;
  }
  viewPaper(rows[0]);
}
 
function getTableActions(record: ExamScoreDetailRow): ActionItem[] {
  return [{ label: '查看试卷', onClick: viewPaper.bind(null, record) }];
}
</script>
 
<template>
  <div class="jnpf-content-wrapper">
    <div class="jnpf-content-wrapper-center">
      <div class="jnpf-content-wrapper-content">
        <BasicVxeTable @register="registerTable">
          <template #tableTitle>
            <a-space>
              <a-button @click="goBack">返回</a-button>
              <a-button type="primary" @click="handleViewSelected">查看试卷</a-button>
              <span class="text-gray-400 text-sm">{{ titleText }}</span>
            </a-space>
          </template>
          <template #passFlag="{ record }">
            <span :class="record.passFlag === '1' ? 'text-green-600' : 'text-red-500'">
              {{ record.passFlag === '1' ? '是' : '否' }}
            </span>
          </template>
          <template #action="{ record }">
            <TableAction :actions="getTableActions(record)" />
          </template>
        </BasicVxeTable>
      </div>
    </div>
  </div>
</template>