AStaffDetailAttendance.vue
5 KB
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
<template>
<div class="staff-attendance-container">
<el-row :gutter="20">
<el-col :span="4">
<el-input
v-model="aStaffDetailAttendanceInfo.curDate"
:placeholder="$t('staffDetailAttendance.enterDate')"
@change="loadStaffAttendances"
/>
</el-col>
<el-col :span="4">
<el-button type="primary" size="small" @click="loadStaffAttendances">
<i class="el-icon-search"></i> {{ $t('common.search') }}
</el-button>
</el-col>
</el-row>
<el-row :gutter="20" class="attendance-wrapper">
<el-col
v-for="index in aStaffDetailAttendanceInfo.maxDay"
:key="index"
:span="4"
class="attendance-card"
:style="{ 'background-color': getBgColor(index) }"
>
<el-card>
<div>{{ `${aStaffDetailAttendanceInfo.curYear}-${aStaffDetailAttendanceInfo.curMonth}-${index}` }}</div>
<div v-for="(item, detailIndex) in getAttendanceDetail(index)" :key="detailIndex">
<div v-if="item.rest">{{ item.rest }}</div>
<div v-else>
{{ item.specCd === '1001' ? $t('staffDetailAttendance.checkIn') : $t('staffDetailAttendance.checkOut') }}:
<span v-if="item.state !== '10000'">{{ formatTime(item.checkTime) }}</span>
<span v-else>-</span>
<span>({{ item.stateName }})</span>
</div>
</div>
<div>
<el-link @click="checkInLog(index)">{{ $t('staffDetailAttendance.attendanceLog') }}</el-link>
</div>
</el-card>
</el-col>
</el-row>
<staff-attendance-detail ref="staffAttendanceDetail" />
</div>
</template>
<script>
import { queryAdminAttendanceClasses } from '@/api/staff/adminStaffDetailApi'
import StaffAttendanceDetail from '@/components/staff/StaffAttendanceDetail.vue'
export default {
name: 'AStaffDetailAttendance',
components: { StaffAttendanceDetail },
data() {
return {
aStaffDetailAttendanceInfo: {
staffId: '',
attendances: [],
curDate: '',
maxDay: '',
curYear: '',
curMonth: ''
}
}
},
created() {
const date = new Date()
this.aStaffDetailAttendanceInfo.curMonth = date.getMonth() + 1
this.aStaffDetailAttendanceInfo.curYear = date.getFullYear()
this.aStaffDetailAttendanceInfo.curDate = `${date.getFullYear()}-${date.getMonth() + 1}`
this.aStaffDetailAttendanceInfo.maxDay = new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate()
},
methods: {
switchTab(data) {
this.aStaffDetailAttendanceInfo.staffId = data.staffId
this.loadStaffAttendances()
},
async loadStaffAttendances() {
if (!this.aStaffDetailAttendanceInfo.staffId || !this.aStaffDetailAttendanceInfo.curDate) return
try {
const { data } = await queryAdminAttendanceClasses({
staffId: this.aStaffDetailAttendanceInfo.staffId,
date: this.aStaffDetailAttendanceInfo.curDate,
page: 1,
row: 1000
})
this.aStaffDetailAttendanceInfo.attendances = data
} catch (error) {
this.$message.error(this.$t('staffDetailAttendance.fetchError'))
}
},
getAttendanceDetail(day) {
const attendance = this.getDayAttendance(day)
if (!attendance) {
const date = new Date()
const taskYear = this.aStaffDetailAttendanceInfo.curYear
const taskMonth = this.aStaffDetailAttendanceInfo.curMonth
if (taskYear == date.getFullYear() && parseInt(taskMonth) == date.getMonth() + 1 && day > date.getDate()) {
return [{ rest: this.$t('staffDetailAttendance.notYet') }]
}
return [{ rest: this.$t('staffDetailAttendance.noAttendance') }]
}
return attendance.attendanceClassesTaskDetails
},
getDayAttendance(day) {
return this.aStaffDetailAttendanceInfo.attendances.find(item => item.taskDay == day) || null
},
getBgColor() {
return '#fff'
},
formatTime(time) {
return time // Implement time formatting if needed
},
checkInLog(day) {
const curMonth = this.aStaffDetailAttendanceInfo.curMonth < 10 ? `0${this.aStaffDetailAttendanceInfo.curMonth}` : this.aStaffDetailAttendanceInfo.curMonth
const formattedDay = day < 10 ? `0${day}` : day
this.$refs.staffAttendanceDetail.open({
staffId: this.aStaffDetailAttendanceInfo.staffId,
date: `${this.aStaffDetailAttendanceInfo.curYear}-${curMonth}-${formattedDay}`
})
}
}
}
</script>
<style lang="scss" scoped>
.staff-attendance-container {
padding: 20px;
.attendance-wrapper {
margin-top: 20px;
.attendance-card {
border-radius: 5px;
cursor: pointer;
.el-card {
text-align: center;
}
}
}
}
</style>