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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<script lang="ts" setup>
import type { TmsRecordDetail } from './types';
 
import { onMounted, reactive, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
 
import { useMessage } from '@jnpf/hooks';
import { Table as ATable } from 'ant-design-vue';
import dayjs from 'dayjs';
 
import { getTmsRecordDetail } from '#/api/x/tms/record';
 
defineOptions({ name: 'TmsRecordSign' });
 
const route = useRoute();
const router = useRouter();
const { createMessage } = useMessage();
 
const loading = ref(false);
const submitting = ref(false);
const detail = ref<TmsRecordDetail | null>(null);
 
const form = reactive({
  userName: '',
  deptName: '',
  signMode: '在线签到',
});
 
const signColumns = [
  { title: '序号', key: 'index', width: 70, align: 'center', customRender: ({ index }: any) => index + 1 },
  { title: '姓名', dataIndex: 'userName', key: 'userName', width: 120 },
  { title: '部门', dataIndex: 'deptName', key: 'deptName', minWidth: 140 },
  { title: '签到时间', dataIndex: 'signTime', key: 'signTime', width: 180 },
  { title: '签到方式', dataIndex: 'signMode', key: 'signMode', width: 120 },
];
 
onMounted(() => {
  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);
    if (detail.value.archiveStatus === 'archived') {
      createMessage.warning('已存档记录不可签到');
      router.replace(`/tms/record/detail/${id}`);
    }
  } catch (e: any) {
    createMessage.error(e?.message || '加载培训记录失败');
    router.replace('/tms/record');
  } finally {
    loading.value = false;
  }
}
 
function handleSubmit() {
  if (!form.userName.trim()) {
    createMessage.warning('请输入签到人姓名');
    return;
  }
  if (!detail.value) return;
  submitting.value = true;
  try {
    detail.value.signList = [
      {
        id: `s-${Date.now()}`,
        userName: form.userName.trim(),
        deptName: form.deptName.trim() || undefined,
        signTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
        signMode: form.signMode,
      },
      ...(detail.value.signList || []),
    ];
    form.userName = '';
    form.deptName = '';
    createMessage.success('签到成功(本地 mock,联调后写入服务端)');
  } finally {
    submitting.value = false;
  }
}
 
function goBack() {
  router.push('/tms/record');
}
</script>
 
<template>
  <div class="jnpf-content-wrapper tms-record-page">
    <div class="jnpf-content-wrapper-center tms-record-center">
      <div class="jnpf-content-wrapper-content tms-record-wrap">
        <a-spin :spinning="loading" class="record-spin">
          <div v-if="detail" class="record-inner">
            <div class="record-header">
              <div>
                <div class="text-base font-medium">培训签到</div>
                <div class="mt-1 text-gray-400 text-sm">
                  {{ detail.recordNo }} · {{ detail.subject }}
                </div>
              </div>
              <a-button @click="goBack">返回</a-button>
            </div>
 
            <a-form layout="inline" class="sign-form mb-4">
              <a-form-item label="姓名">
                <a-input v-model:value="form.userName" placeholder="签到人姓名" class="!w-[140px]" allow-clear />
              </a-form-item>
              <a-form-item label="部门">
                <a-input v-model:value="form.deptName" placeholder="部门(可选)" class="!w-[160px]" allow-clear />
              </a-form-item>
              <a-form-item label="方式">
                <a-select
                  v-model:value="form.signMode"
                  class="!w-[130px]"
                  :options="[
                    { label: '在线签到', value: '在线签到' },
                    { label: 'APP扫码', value: 'APP扫码' },
                    { label: '微信扫码', value: '微信扫码' },
                  ]"
                />
              </a-form-item>
              <a-form-item>
                <a-button type="primary" :loading="submitting" @click="handleSubmit">确认签到</a-button>
              </a-form-item>
            </a-form>
 
            <div class="section-title">已签到人员</div>
            <ATable
              size="middle"
              bordered
              row-key="id"
              :columns="signColumns"
              :data-source="detail.signList || []"
              :pagination="false"
              :locale="{ emptyText: '暂无签到记录' }"
            />
          </div>
        </a-spin>
      </div>
    </div>
  </div>
</template>
 
<style scoped>
.tms-record-page,
.tms-record-center {
  height: 100%;
  min-height: 0;
}
 
.tms-record-wrap {
  display: flex !important;
  flex-direction: column;
  flex: 1 1 0 !important;
  min-height: 0 !important;
  height: 100%;
  overflow: auto !important;
  background: #fff;
}
 
.record-spin {
  display: block;
  min-height: 100%;
  width: 100%;
}
 
.record-inner {
  padding: 16px 20px 24px;
}
 
.record-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
 
.section-title {
  font-size: 15px;
  font-weight: 600;
  margin: 8px 0 12px;
  padding-left: 10px;
  border-left: 3px solid #1677ff;
}
 
.sign-form {
  padding: 12px;
  background: #fafafa;
  border-radius: 6px;
}
</style>