WXL
2025-12-28 1b736033f6d01b774d58b4c2d7cd2ce8607a44fa
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
<template>
  <div class="personal-attendance-table">
    <div class="table-header">
      <h4>出勤记录详情</h4>
      <div class="header-actions">
        <el-button size="small" @click="exportToCSV" icon="el-icon-download">
          导出CSV
        </el-button>
        <el-tooltip content="刷新数据" placement="top">
          <el-button size="small" @click="refreshData" icon="el-icon-refresh">
            刷新
          </el-button>
        </el-tooltip>
      </div>
    </div>
 
    <el-table
      :data="filteredData"
      border
      style="width: 100%"
      v-loading="loading"
      class="attendance-table"
    >
      <el-table-column prop="date" label="日期"  sortable>
        <template #default="scope">
          <span class="date-cell">{{ scope.row.date }}</span>
        </template>
      </el-table-column>
 
      <el-table-column prop="checkIn" label="签到时间" >
        <template #default="scope">
          <span :class="getTimeClass(scope.row.checkIn, 'checkIn')">
            {{ scope.row.checkIn || '-' }}
          </span>
        </template>
      </el-table-column>
 
      <el-table-column prop="checkOut" label="签退时间" >
        <template #default="scope">
          <span :class="getTimeClass(scope.row.checkOut, 'checkOut')">
            {{ scope.row.checkOut || '-' }}
          </span>
        </template>
      </el-table-column>
 
      <el-table-column prop="workHours" label="工作时长"  sortable>
        <template #default="scope">
          <el-tag
            :type="getWorkHoursType(scope.row.workHours)"
            size="small"
          >
            {{ scope.row.workHours }}h
          </el-tag>
        </template>
      </el-table-column>
 
      <el-table-column prop="status" label="状态" >
        <template #default="scope">
          <el-tag
            :type="getStatusType(scope.row.status)"
            effect="plain"
          >
            {{ scope.row.status }}
          </el-tag>
        </template>
      </el-table-column>
 
      <el-table-column prop="remarks" label="备注" min-width="150" show-overflow-tooltip>
        <template #default="scope">
          <span class="remarks-cell">{{ scope.row.remarks || '无' }}</span>
        </template>
      </el-table-column>
 
      <el-table-column label="操作"  fixed="right">
        <template #default="scope">
          <el-button
            size="mini"
            type="text"
            @click="viewDetails(scope.row)"
            icon="el-icon-view"
          >
            详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>
 
    <!-- 分页 -->
    <div class="pagination-container">
      <el-pagination
        :current-page="currentPage"
        :page-size="pageSize"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
 
    <!-- 详情对话框 -->
    <el-dialog
      title="出勤记录详情"
      :visible.sync="detailDialogVisible"
      width="500px"
    >
      <div v-if="currentRecord" class="record-details">
        <el-descriptions :column="1" border>
          <el-descriptions-item label="日期">
            {{ currentRecord.date }}
          </el-descriptions-item>
          <el-descriptions-item label="签到时间">
            <el-tag :type="getTimeClass(currentRecord.checkIn, 'checkIn')">
              {{ currentRecord.checkIn }}
            </el-tag>
          </el-descriptions-item>
          <el-descriptions-item label="签退时间">
            <el-tag :type="getTimeClass(currentRecord.checkOut, 'checkOut')">
              {{ currentRecord.checkOut }}
            </el-tag>
          </el-descriptions-item>
          <el-descriptions-item label="工作时长">
            <el-tag :type="getWorkHoursType(currentRecord.workHours)">
              {{ currentRecord.workHours }} 小时
            </el-tag>
          </el-descriptions-item>
          <el-descriptions-item label="状态">
            <el-tag :type="getStatusType(currentRecord.status)">
              {{ currentRecord.status }}
            </el-tag>
          </el-descriptions-item>
          <el-descriptions-item label="备注">
            {{ currentRecord.remarks || '无' }}
          </el-descriptions-item>
        </el-descriptions>
      </div>
    </el-dialog>
  </div>
</template>
 
<script>
export default {
  name: 'PersonalAttendanceTable',
  props: {
    data: {
      type: Array,
      default: () => []
    },
    loading: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      currentPage: 1,
      pageSize: 10,
      detailDialogVisible: false,
      currentRecord: null,
      filterForm: {
        dateRange: [],
        status: ''
      }
    }
  },
  computed: {
    total() {
      return this.data.length
    },
    filteredData() {
      let filtered = this.data
 
      // 按日期范围过滤
      if (this.filterForm.dateRange && this.filterForm.dateRange.length === 2) {
        const [start, end] = this.filterForm.dateRange
        filtered = filtered.filter(item => {
          const itemDate = new Date(item.date)
          return itemDate >= new Date(start) && itemDate <= new Date(end)
        })
      }
 
      // 按状态过滤
      if (this.filterForm.status) {
        filtered = filtered.filter(item => item.status === this.filterForm.status)
      }
 
      // 分页
      const start = (this.currentPage - 1) * this.pageSize
      const end = start + this.pageSize
      return filtered.slice(start, end)
    }
  },
  methods: {
    getTimeClass(time, type) {
      if (!time) return 'text-muted'
 
      const hour = parseInt(time.split(':')[0])
      if (type === 'checkIn') {
        return hour > 9 ? 'text-danger' : 'text-success'
      } else {
        return hour < 18 ? 'text-warning' : 'text-success'
      }
    },
 
    getWorkHoursType(hours) {
      const numHours = parseFloat(hours)
      if (numHours >= 8) return 'success'
      if (numHours >= 6) return 'warning'
      return 'danger'
    },
 
    getStatusType(status) {
      const typeMap = {
        '正常': 'success',
        '迟到': 'warning',
        '早退': 'warning',
        '缺勤': 'danger',
        '出差': 'primary'
      }
      return typeMap[status] || 'info'
    },
 
    viewDetails(record) {
      this.currentRecord = record
      this.detailDialogVisible = true
    },
 
    exportToCSV() {
      // 简化版CSV导出逻辑
      const headers = ['日期', '签到时间', '签退时间', '工作时长', '状态', '备注']
      const csvData = this.data.map(item => [
        item.date,
        item.checkIn,
        item.checkOut,
        item.workHours,
        item.status,
        item.remarks || ''
      ])
 
      const csvContent = [headers, ...csvData]
        .map(row => row.map(field => `"${field}"`).join(','))
        .join('\n')
 
      const blob = new Blob([`\uFEFF${csvContent}`], { type: 'text/csv;charset=utf-8;' })
      const link = document.createElement('a')
      link.href = URL.createObjectURL(blob)
      link.download = `出勤记录_${new Date().toISOString().split('T')[0]}.csv`
      link.click()
    },
 
    refreshData() {
      this.$emit('refresh')
    },
 
    handleSizeChange(size) {
      this.pageSize = size
      this.currentPage = 1
    },
 
    handleCurrentChange(page) {
      this.currentPage = page
    }
  }
}
</script>
 
<style scoped>
.personal-attendance-table {
  padding: 20px;
}
 
.table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
 
.table-header h4 {
  margin: 0;
  color: #303133;
  font-size: 16px;
}
 
.header-actions {
  display: flex;
  gap: 10px;
}
 
.attendance-table {
  margin-bottom: 20px;
}
 
.date-cell {
  font-weight: 500;
}
 
.text-success { color: #67c23a; }
.text-warning { color: #e6a23c; }
.text-danger { color: #f56c6c; }
.text-muted { color: #909399; }
.text-primary { color: #409eff; }
 
.remarks-cell {
  color: #606266;
  font-size: 13px;
}
 
.pagination-container {
  display: flex;
  justify-content: flex-end;
  margin-top: 20px;
}
 
.record-details {
  padding: 10px;
}
 
/* 响应式设计 */
@media (max-width: 768px) {
  .table-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
 
  .header-actions {
    width: 100%;
    justify-content: flex-end;
  }
}
</style>