liuyu
21 小时以前 8534025c45b4736975730678b9ccf23570a75f95
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
<script lang="ts" setup>
import type { PersonTaskItem } 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 } from 'ant-design-vue';
 
import { getPersonTaskInfo, signPersonTask } from '#/api/x/tms/personTask';
import { TMS_BTN } from '#/views/x/tms/shared/ui';
 
import {
  labelOfCategory,
  labelOfEvalMode,
  labelOfPersonStatus,
  labelOfTrainMode,
  loadPersonTaskDics,
} from './constants';
 
import '#/views/x/tms/shared/page.css';
 
defineOptions({ name: 'TmsPersonTaskDetail' });
 
const route = useRoute();
const router = useRouter();
const { createMessage } = useMessage();
 
const loading = ref(false);
const signing = ref(false);
const detail = ref<PersonTaskItem | null>(null);
 
const progressText = computed(() => {
  const learned = detail.value?.learnedSeconds || 0;
  const required = detail.value?.requiredSeconds || 0;
  return `${formatDuration(learned)} / ${required > 0 ? formatDuration(required) : '未配置'}`;
});
 
const isClosed = computed(() => detail.value?.bizStatus === 'cancelled' || detail.value?.bizStatus === 'expired');
const canLearn = computed(() => Boolean(detail.value?.id) && !isClosed.value);
const showExam = computed(() => Boolean(detail.value?.canExam && detail.value?.paperId));
const tipMessage = computed(() => {
  if (!detail.value) return '';
  if (detail.value.bizStatus === 'cancelled') return '任务已取消,无法继续学习或考试。';
  if (detail.value.bizStatus === 'expired') return '任务已过期,无法继续学习或考试。';
  if (detail.value.examTip && !detail.value.canExam) return detail.value.examTip;
  if (detail.value.signTip && detail.value.canSign) return detail.value.signTip;
  return '';
});
 
onMounted(async () => {
  await loadPersonTaskDics();
  await loadData();
});
 
async function loadData() {
  const id = String(route.params.id || '');
  if (!id) {
    router.replace('/tms/personTask');
    return;
  }
  loading.value = true;
  try {
    detail.value = await getPersonTaskInfo(id);
  } catch (e: any) {
    createMessage.error(e?.message || '加载失败');
    router.replace('/tms/personTask');
  } finally {
    loading.value = false;
  }
}
 
function goBack() {
  router.push('/tms/personTask');
}
 
function goLearn() {
  if (!detail.value?.id) return;
  if (isClosed.value) {
    createMessage.warning(tipMessage.value || '当前任务不可学习');
    return;
  }
  router.push(`/tms/personTask/learn/${detail.value.id}`);
}
 
function goExam() {
  if (!detail.value?.id || !showExam.value) {
    createMessage.info(detail.value?.examTip || '当前暂不可考试');
    return;
  }
  router.push(`/tms/personTask/learn/${detail.value.id}`);
}
 
async function handleSign() {
  if (!detail.value?.id || !detail.value.canSign || signing.value) return;
  signing.value = true;
  try {
    const result = await signPersonTask(detail.value.id);
    detail.value.signTime = result.signTime;
    detail.value.signed = result.signed ?? true;
    detail.value.canSign = result.canSign ?? false;
    detail.value.signTip = result.signTip || '已签到';
    detail.value.bizStatus = result.bizStatus || detail.value.bizStatus;
    detail.value.canExam = result.canExam;
    detail.value.examTip = result.examTip;
    createMessage.success(result.message || '签到成功');
  } catch (e: any) {
    createMessage.error(e?.message || '签到失败');
  } finally {
    signing.value = false;
  }
}
 
function formatDuration(seconds: number) {
  const h = Math.floor(seconds / 3600);
  const m = Math.floor((seconds % 3600) / 60);
  const s = seconds % 60;
  if (h > 0) return `${h}小时${m}分`;
  if (m > 0) return `${m}分${s}秒`;
  return `${s}秒`;
}
</script>
 
<template>
  <div class="jnpf-content-wrapper tms-person-task-page" v-loading="loading">
    <div class="jnpf-content-wrapper-center">
      <div class="jnpf-content-wrapper-content tms-person-task-wrap" v-if="detail">
        <div class="tms-page-header">
          <div>
            <div class="tms-page-header__title">个人培训任务</div>
            <div class="tms-page-header__sub">{{ detail.taskNo || '-' }} · {{ detail.subject || '-' }}</div>
          </div>
          <div class="tms-page-header__actions">
            <a-button @click="goBack">{{ TMS_BTN.back }}</a-button>
            <a-button
              v-if="detail.canSign"
              type="primary"
              :ghost="showExam"
              :loading="signing"
              @click="handleSign"
            >
              {{ TMS_BTN.sign }}
            </a-button>
            <a-button v-if="canLearn" type="primary" ghost @click="goLearn">{{ TMS_BTN.enterLearn }}</a-button>
            <a-button v-if="showExam" type="primary" @click="goExam">
              {{ detail.passFlag === '0' ? TMS_BTN.retake : TMS_BTN.enterExam }}
            </a-button>
          </div>
        </div>
 
        <a-alert v-if="tipMessage" class="tms-page-tip" type="warning" show-icon :message="tipMessage" />
 
        <ADescriptions bordered :column="2" size="small">
          <ADescriptionsItem label="培训编号">{{ detail.taskNo || '-' }}</ADescriptionsItem>
          <ADescriptionsItem label="状态">{{ labelOfPersonStatus(detail.bizStatus) }}</ADescriptionsItem>
          <ADescriptionsItem label="培训主题" :span="2">{{ detail.subject || '-' }}</ADescriptionsItem>
          <ADescriptionsItem label="培训分类">{{ labelOfCategory(detail.category) }}</ADescriptionsItem>
          <ADescriptionsItem label="培训方式">{{ labelOfTrainMode(detail.trainMode) }}</ADescriptionsItem>
          <ADescriptionsItem label="考核方式">{{ labelOfEvalMode(detail.evalMode) }}</ADescriptionsItem>
          <ADescriptionsItem label="签到状态">
            {{
              detail.signed || detail.signTime
                ? `已签到${detail.signTime ? `(${detail.signTime})` : ''}`
                : detail.signTip || '未签到'
            }}
          </ADescriptionsItem>
          <ADescriptionsItem label="是否可考">
            {{ detail.canExam ? '是' : '否' }}
            <span v-if="!detail.canExam && detail.examTip" class="tip-inline">({{ detail.examTip }})</span>
          </ADescriptionsItem>
          <ADescriptionsItem label="学习进度">{{ detail.learnStatus || '-' }}</ADescriptionsItem>
          <ADescriptionsItem label="要求课时">{{ detail.requiredHours ?? '-' }} 小时</ADescriptionsItem>
          <ADescriptionsItem label="已学/需学">{{ progressText }}</ADescriptionsItem>
          <ADescriptionsItem label="开始时间">{{ detail.startTime || '-' }}</ADescriptionsItem>
          <ADescriptionsItem label="结束时间">{{ detail.endTime || '-' }}</ADescriptionsItem>
          <ADescriptionsItem label="关闭时间">{{ detail.closeTime || '-' }}</ADescriptionsItem>
          <ADescriptionsItem label="地点">{{ detail.placeName || '-' }}</ADescriptionsItem>
          <ADescriptionsItem label="试卷">{{ detail.paperName || '-' }}</ADescriptionsItem>
          <ADescriptionsItem label="成绩">{{ detail.examScore ?? '-' }}</ADescriptionsItem>
          <ADescriptionsItem label="培训要点" :span="2">{{ detail.keyPoints || '-' }}</ADescriptionsItem>
        </ADescriptions>
      </div>
    </div>
  </div>
</template>
 
<style scoped>
.tms-person-task-page,
.tms-person-task-wrap {
  height: 100%;
  min-height: 0;
}
 
.tms-person-task-wrap {
  overflow: auto;
  background: #fff;
  padding: 16px 20px 24px;
  box-sizing: border-box;
}
 
.tip-inline {
  color: #fa8c16;
  margin-left: 4px;
}
</style>