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
<script lang="ts" setup>
import type { ActionItem, BasicColumn } from '@jnpf/ui/vxeTable';
 
import type { PersonTaskItem } from './types';
 
import { onMounted } from 'vue';
import { useRouter } from 'vue-router';
 
import { useMessage } from '@jnpf/hooks';
import { BasicVxeTable, TableAction, useVxeTable } from '@jnpf/ui/vxeTable';
 
import { getMyPersonTaskList } from '#/api/x/tms/personTask';
import { TMS_DIC_FIELD_NAMES } from '#/views/x/tms/shared/dic';
import { TMS_BTN } from '#/views/x/tms/shared/ui';
 
import {
  PERSON_STATUS_OPTIONS,
  labelOfEvalMode,
  labelOfPersonStatus,
  labelOfTrainMode,
  loadPersonTaskDics,
} from './constants';
 
import '#/views/x/tms/shared/page.css';
 
defineOptions({ name: 'TmsPersonTask' });
 
const router = useRouter();
const { createMessage } = useMessage();
 
const columns: BasicColumn[] = [
  { title: '培训编号', dataIndex: 'taskNo', width: 140 },
  { title: '培训主题', dataIndex: 'subject', minWidth: 200 },
  {
    title: '培训方式',
    dataIndex: 'trainMode',
    width: 110,
    customRender: ({ record }) => labelOfTrainMode((record as PersonTaskItem).trainMode),
  },
  { title: '开始时间', dataIndex: 'startTime', width: 170 },
  { title: '结束时间', dataIndex: 'endTime', width: 170 },
  {
    title: '状态',
    dataIndex: 'bizStatus',
    width: 100,
    customRender: ({ record }) => labelOfPersonStatus((record as PersonTaskItem).bizStatus),
  },
  { title: '学习进度', dataIndex: 'learnStatus', width: 100 },
  {
    title: '是否可考',
    dataIndex: 'canExam',
    width: 100,
    customRender: ({ record }) => {
      const row = record as PersonTaskItem;
      if (row.canExam) return '是';
      return row.examTip ? '否' : '否';
    },
  },
  {
    title: '考核方式',
    dataIndex: 'evalMode',
    width: 110,
    customRender: ({ record }) => labelOfEvalMode((record as PersonTaskItem).evalMode),
  },
];
 
const [registerTable, { reload, getForm }] = useVxeTable({
  api: fetchList,
  columns,
  immediate: false,
  rowKey: 'id',
  useSearchForm: true,
  formConfig: {
    baseColProps: { span: 6 },
    compact: true,
    showAdvancedButton: true,
    alwaysShowLines: 1,
    autoAdvancedLine: 1,
    schemas: [
      {
        field: 'keyword',
        label: '关键词',
        component: 'Input',
        componentProps: { placeholder: '编号/主题', submitOnPressEnter: true },
      },
      {
        field: 'bizStatus',
        label: '状态',
        component: 'Select',
        componentProps: {
          allowClear: true,
          placeholder: '请选择',
          options: PERSON_STATUS_OPTIONS.value,
          fieldNames: TMS_DIC_FIELD_NAMES,
        },
      },
    ],
  },
  actionColumn: {
    width: 160,
    title: '操作',
    dataIndex: 'action',
    fixed: 'right',
  },
});
 
onMounted(async () => {
  await loadPersonTaskDics();
  getForm()?.updateSchema?.({
    field: 'bizStatus',
    componentProps: {
      allowClear: true,
      placeholder: '请选择',
      options: PERSON_STATUS_OPTIONS.value,
      fieldNames: TMS_DIC_FIELD_NAMES,
    },
  });
  reload();
});
 
async function fetchList(params: Record<string, any>) {
  const page = await getMyPersonTaskList(params);
  return {
    data: {
      list: Array.isArray(page?.list) ? page.list : [],
      pagination: page?.pagination || { total: 0 },
    },
  };
}
 
function isClosedStatus(status?: string) {
  return status === 'cancelled' || status === 'expired';
}
 
function canEnterLearn(record: PersonTaskItem) {
  return !isClosedStatus(record.bizStatus);
}
 
function handleView(record: PersonTaskItem) {
  router.push(`/tms/personTask/detail/${record.id}`);
}
 
function handleLearn(record: PersonTaskItem) {
  if (!canEnterLearn(record)) {
    createMessage.warning(
      record.bizStatus === 'cancelled' ? '任务已取消,无法学习' : '任务已过期,无法学习',
    );
    return;
  }
  router.push(`/tms/personTask/learn/${record.id}`);
}
 
function handleExamHint(record: PersonTaskItem) {
  if (record.canExam) {
    router.push(`/tms/personTask/learn/${record.id}`);
    return;
  }
  createMessage.info(record.examTip || record.signTip || '当前暂不可考试');
}
 
function getTableActions(record: PersonTaskItem): ActionItem[] {
  const actions: ActionItem[] = [{ label: TMS_BTN.detail, onClick: handleView.bind(null, record) }];
  if (canEnterLearn(record)) {
    actions.push({ label: TMS_BTN.learn, onClick: handleLearn.bind(null, record) });
  }
  if (record.canExam) {
    actions.push({
      label: record.passFlag === '0' ? TMS_BTN.retake : TMS_BTN.exam,
      onClick: handleExamHint.bind(null, record),
    });
  } else if (canEnterLearn(record) && record.examTip) {
    actions.push({
      label: TMS_BTN.exam,
      disabled: true,
      tooltip: record.examTip,
    });
  }
  return actions;
}
</script>
 
<template>
  <div class="jnpf-content-wrapper">
    <div class="jnpf-content-wrapper-center">
      <div class="jnpf-content-wrapper-content">
        <BasicVxeTable @register="registerTable">
          <template #tableTitle>
            <div>
              <div class="tms-page-header__title">个人培训任务</div>
              <div class="tms-page-header__sub">学习教材并完成考核;可考时操作列直接进入考试。</div>
            </div>
          </template>
          <template #action="{ record }">
            <TableAction :actions="getTableActions(record)" />
          </template>
        </BasicVxeTable>
      </div>
    </div>
  </div>
</template>