WXL
2025-12-30 ed62678cd16042506bad5e5f75665a822f2d5717
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
<template>
  <div class="attendance-detail">
    <!-- 员工基本信息 -->
    <el-card class="employee-info-card">
      <div class="employee-header">
        <div class="employee-basic">
          <el-avatar
            :size="60"
            :src="employeeInfo.avatar"
            class="employee-avatar"
          >
            {{ employeeInfo.name.charAt(0) }}
          </el-avatar>
          <div class="employee-details">
            <h3>{{ employeeInfo.name }}</h3>
            <p class="employee-department">
              {{ employeeInfo.department }} · {{ employeeInfo.position }}
            </p>
            <p class="employee-contact">
              <span>工号: {{ employeeInfo.employeeId }}</span>
              <span>电话: {{ employeeInfo.phone }}</span>
            </p>
          </div>
        </div>
        <div class="employee-stats">
          <div class="stat-item">
            <div class="stat-value">{{ employeeStats.attendanceRate }}%</div>
            <div class="stat-label">本月出勤率</div>
          </div>
          <div class="stat-item">
            <div class="stat-value">{{ employeeStats.workHours }}h</div>
            <div class="stat-label">总工作时长</div>
          </div>
          <div class="stat-item">
            <div class="stat-value">{{ employeeStats.businessTripDays }}</div>
            <div class="stat-label">出差天数</div>
          </div>
        </div>
      </div>
    </el-card>
 
    <!-- 选项卡 -->
    <el-card>
      <el-tabs v-model="activeTab">
        <el-tab-pane label="出勤记录" name="attendanceList">
          <personal-attendance-table
            :data="attendanceData"
            :loading="loading"
          />
        </el-tab-pane>
 
        <el-tab-pane label="出差记录" name="businessTripList">
          <personal-business-trip-table
            :data="businessTripData"
            :loading="loading"
          />
        </el-tab-pane>
        <el-tab-pane label="日历视图" name="calendar">
          <attendance-calendar
            :attendance-data="attendanceData"
            :business-trip-data="businessTripData"
          />
        </el-tab-pane>
        <el-tab-pane label="统计报表" name="report">
          <personal-attendance-report
            :stats="employeeStats"
            :attendance-data="attendanceData"
          />
        </el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>
 
<script>
import AttendanceCalendar from "./components/AttendanceCalendar.vue";
import PersonalAttendanceTable from "./components/PersonalAttendanceTable.vue";
import PersonBusiness from "./components/PersonBusiness.vue";
import PersonalAttendanceReport from "./components/PersonalAttendanceReport.vue";
 
export default {
  name: "AttendanceDetail",
  components: {
    AttendanceCalendar,
    PersonalAttendanceTable,
    PersonBusiness,
    PersonalAttendanceReport
  },
  data() {
    return {
      activeTab: "calendar",
      loading: false,
      employeeInfo: {
        name: "",
        department: "",
        position: "",
        employeeId: "",
        phone: "",
        avatar: ""
      },
      employeeStats: {
        attendanceRate: 0,
        workHours: 0,
        businessTripDays: 0,
        lateTimes: 0,
        leaveEarlyTimes: 0
      },
      attendanceData: [],
      businessTripData: []
    };
  },
  created() {
    this.getEmployeeInfo();
    this.loadAttendanceData();
  },
  methods: {
    getEmployeeInfo() {
      const { employeeId, employeeName } = this.$route.query;
      // 模拟员工信息
      this.employeeInfo = {
        name: employeeName || "张三",
        department: "OPO项目部",
        position: "项目经理",
        employeeId: employeeId || "OPO001",
        phone: "138****1234",
        avatar: ""
      };
    },
 
    async loadAttendanceData() {
      this.loading = true;
      try {
        await new Promise(resolve => setTimeout(resolve, 500));
 
        // 生成个人考勤模拟数据
        this.attendanceData = this.generatePersonalAttendanceData();
        this.businessTripData = this.generatePersonalBusinessTripData();
        this.calculateStats();
      } catch (error) {
        console.error("加载数据失败:", error);
      } finally {
        this.loading = false;
      }
    },
 
    generatePersonalAttendanceData() {
      const data = [];
      const currentMonth = 12; // 12月
 
      for (let day = 1; day <= 31; day++) {
        if (Math.random() > 0.2) {
          // 80%的出勤率
          data.push({
            id: day,
            date: `2024-${currentMonth
              .toString()
              .padStart(2, "0")}-${day.toString().padStart(2, "0")}`,
            checkIn: `08:${String(Math.floor(Math.random() * 30)).padStart(
              2,
              "0"
            )}`,
            checkOut: `18:${String(Math.floor(Math.random() * 30)).padStart(
              2,
              "0"
            )}`,
            status: Math.random() > 0.1 ? "正常" : "迟到",
            workHours: (8 + Math.random() * 2).toFixed(1)
          });
        }
      }
      return data;
    },
 
    generatePersonalBusinessTripData() {
      return [
        {
          id: 1,
          tripNumber: "BT202412001",
          startCity: "北京",
          endCity: "上海",
          startDate: "2024-12-05",
          endDate: "2024-12-08",
          distance: 1200,
          purpose: "客户会议",
          status: "已完成"
        },
        {
          id: 2,
          tripNumber: "BT202412002",
          startCity: "北京",
          endCity: "广州",
          startDate: "2024-12-15",
          endDate: "2024-12-18",
          distance: 1900,
          purpose: "项目调研",
          status: "已完成"
        }
      ];
    },
 
    calculateStats() {
      const totalDays = 31;
      const attendanceDays = this.attendanceData.length;
 
      this.employeeStats = {
        attendanceRate: Math.round((attendanceDays / totalDays) * 100),
        workHours: this.attendanceData
          .reduce((sum, item) => sum + parseFloat(item.workHours), 0)
          .toFixed(1),
        businessTripDays: this.businessTripData.reduce((sum, item) => {
          const start = new Date(item.startDate);
          const end = new Date(item.endDate);
          return sum + Math.ceil((end - start) / (1000 * 60 * 60 * 24)) + 1;
        }, 0),
        lateTimes: this.attendanceData.filter(item => item.status === "迟到")
          .length,
        leaveEarlyTimes: this.attendanceData.filter(
          item => item.status === "早退"
        ).length
      };
    }
  }
};
</script>
 
<style scoped>
.attendance-detail {
  padding: 20px;
}
 
.employee-info-card {
  margin-bottom: 20px;
}
 
.employee-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
 
.employee-basic {
  display: flex;
  align-items: center;
}
 
.employee-avatar {
  margin-right: 16px;
  background-color: #409eff;
}
 
.employee-details h3 {
  margin: 0 0 8px 0;
  font-size: 24px;
  color: #303133;
}
 
.employee-department {
  margin: 0 0 8px 0;
  color: #606266;
}
 
.employee-contact {
  margin: 0;
  color: #909399;
  font-size: 14px;
}
 
.employee-contact span {
  margin-right: 16px;
}
 
.employee-stats {
  display: flex;
  gap: 30px;
}
 
.stat-item {
  text-align: center;
}
 
.stat-value {
  font-size: 28px;
  font-weight: bold;
  color: #409eff;
  margin-bottom: 4px;
}
 
.stat-label {
  color: #909399;
  font-size: 14px;
}
</style>