刘光辉
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
<script lang="ts" setup>
import type { PracticeForm, PracticeItem } from '#/api/x/tms/practice';
 
import { onMounted, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
 
import { useMessage } from '@jnpf/hooks';
import dayjs from 'dayjs';
 
import { getPracticeByRecord, savePractice } from '#/api/x/tms/practice';
import { TMS_BTN } from '#/views/x/tms/shared/ui';
 
import { labelOfPassFlag, loadRecordDics } from './constants';
 
import '#/views/x/tms/shared/page.css';
 
defineOptions({ name: 'TmsRecordPractice' });
 
const route = useRoute();
const router = useRouter();
const { createMessage } = useMessage();
 
const loading = ref(false);
const saving = ref(false);
const form = ref<PracticeForm>({ items: [] });
 
const columns = [
  { title: '姓名', dataIndex: 'userName', width: 120 },
  { title: '部门', dataIndex: 'deptName', width: 160 },
  { title: '得分', dataIndex: 'score', width: 120 },
  { title: '合格', dataIndex: 'resultFlag', width: 120 },
  { title: '评语', dataIndex: 'content' },
];
 
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 {
    form.value = await getPracticeByRecord(id);
    if (!form.value.practiceTime) {
      form.value.practiceTime = dayjs().format('YYYY-MM-DD HH:mm:ss');
    }
    if (!form.value.items?.length) {
      createMessage.info('暂无已签到学员,可签到后再打分');
    }
  } catch (e: any) {
    createMessage.error(e?.message || '加载实操评分失败');
    router.replace(`/tms/record/detail/${id}`);
  } finally {
    loading.value = false;
  }
}
 
async function handleSave() {
  saving.value = true;
  try {
    await savePractice({
      ...form.value,
      items: (form.value.items || []).map((row) => ({
        ...row,
        score: row.score == null || (row.score as any) === '' ? undefined : Number(row.score),
      })),
    });
    createMessage.success('保存成功');
    await loadData();
  } catch (e: any) {
    createMessage.error(e?.message || '保存失败');
  } finally {
    saving.value = false;
  }
}
 
function goBack() {
  const id = String(route.params.id || form.value.recordId || '');
  router.push(id ? `/tms/record/detail/${id}` : '/tms/record');
}
 
function passLabel(row: PracticeItem) {
  return labelOfPassFlag(row.resultFlag) || '-';
}
</script>
 
<template>
  <div class="jnpf-content-wrapper tms-practice-page" v-loading="loading">
    <div class="jnpf-content-wrapper-center">
      <div class="jnpf-content-wrapper-content tms-practice-wrap">
        <a-card title="实操打分" :bordered="false">
          <template #extra>
            <a-space>
              <a-button @click="goBack">{{ TMS_BTN.back }}</a-button>
              <a-button type="primary" :loading="saving" @click="handleSave">{{ TMS_BTN.save }}</a-button>
            </a-space>
          </template>
 
          <a-form layout="inline" class="practice-meta">
            <a-form-item label="实操时间">
              <a-input v-model:value="form.practiceTime" style="width: 220px" />
            </a-form-item>
            <a-form-item label="备注">
              <a-input v-model:value="form.remark" style="width: 320px" maxlength="200" />
            </a-form-item>
          </a-form>
 
          <a-table
            size="small"
            bordered
            row-key="userId"
            :columns="columns"
            :data-source="form.items || []"
            :pagination="false"
            :locale="{ emptyText: '暂无已签到学员' }"
          >
            <template #bodyCell="{ column, record }">
              <template v-if="column.dataIndex === 'score'">
                <a-input-number
                  v-model:value="record.score"
                  :min="0"
                  :max="100"
                  :precision="1"
                  style="width: 100%"
                />
              </template>
              <template v-else-if="column.dataIndex === 'resultFlag'">
                <a-select
                  v-model:value="record.resultFlag"
                  allow-clear
                  style="width: 100%"
                  :options="[
                    { label: '合格', value: 'pass' },
                    { label: '不合格', value: 'fail' },
                  ]"
                  :placeholder="passLabel(record)"
                />
              </template>
              <template v-else-if="column.dataIndex === 'content'">
                <a-input v-model:value="record.content" maxlength="200" />
              </template>
            </template>
          </a-table>
        </a-card>
      </div>
    </div>
  </div>
</template>
 
<style scoped>
.tms-practice-page {
  height: 100%;
  min-height: 0;
}
 
.tms-practice-wrap {
  height: 100%;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto !important;
  background: #fff;
  box-sizing: border-box;
}
 
.practice-meta {
  margin-bottom: 16px;
}
</style>