attendance-abnormal.vue
4.32 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
<template>
<workbench-card title="考勤异常摘要" :subtitle="monthLabel" icon="el-icon-warning-outline" tone="orange" :loading="loading">
<template #extra>
<el-button type="text" size="mini" @click="goMore">更多</el-button>
</template>
<div class="wb-metric-row wb-metric-row--3">
<div class="wb-metric wb-metric--orange" @click="goMore">
<div class="wb-metric__icon"><i class="el-icon-warning" /></div>
<div class="wb-metric__body">
<div class="wb-metric__num">{{ kpi.late }}</div>
<div class="wb-metric__label">迟到人数</div>
</div>
</div>
<div class="wb-metric wb-metric--red" @click="goMore">
<div class="wb-metric__icon"><i class="el-icon-error" /></div>
<div class="wb-metric__body">
<div class="wb-metric__num">{{ kpi.abnormal }}</div>
<div class="wb-metric__label">异常人数</div>
</div>
</div>
<div class="wb-metric wb-metric--green" @click="goMore">
<div class="wb-metric__icon"><i class="el-icon-success" /></div>
<div class="wb-metric__body">
<div class="wb-metric__num">{{ kpi.normal }}</div>
<div class="wb-metric__label">正常人数</div>
</div>
</div>
</div>
</workbench-card>
</template>
<script>
import { getAttendanceMonthReport } from '@/api/extend/attendanceRecord'
import WorkbenchCard from '../workbench-card.vue'
export default {
name: 'WidgetAttendanceAbnormal',
components: { WorkbenchCard },
data() {
return {
loading: false,
kpi: { late: 0, abnormal: 0, normal: 0 }
}
},
computed: {
month() {
const d = new Date()
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}`
},
monthLabel() {
return `${this.month} · 全员摘要`
}
},
mounted() {
this.load()
},
methods: {
unwrap(res) {
if (!res || typeof res !== 'object') return {}
let inner = res.data != null ? res.data : res
if (inner && typeof inner === 'object' && inner.data != null && (inner.data.list != null || inner.data.List != null || inner.data.summary != null)) {
inner = inner.data
}
return inner && typeof inner === 'object' ? inner : {}
},
pickStats(row) {
const ms = (row && (row.monthStats || row.MonthStats)) || {}
return {
normal: Number(ms.normal != null ? ms.normal : ms.Normal) || 0,
late: Number(ms.late != null ? ms.late : ms.Late) || 0,
abnormal: Number(ms.abnormal != null ? ms.abnormal : ms.Abnormal) || 0
}
},
async load() {
this.loading = true
try {
const res = await getAttendanceMonthReport({
month: this.month,
currentPage: 1,
pageSize: 200
})
const data = this.unwrap(res)
const summary = data.summary || data.Summary
if (summary && typeof summary === 'object') {
this.kpi = {
late: Number(summary.lateCount != null ? summary.lateCount : (summary.LateCount != null ? summary.LateCount : summary.late)) || 0,
abnormal: Number(
summary.leaveAndMissingCount != null ? summary.leaveAndMissingCount
: (summary.LeaveAndMissingCount != null ? summary.LeaveAndMissingCount
: (summary.abnormalCount != null ? summary.abnormalCount
: (summary.AbnormalCount != null ? summary.AbnormalCount : summary.abnormal)))
) || 0,
normal: Number(summary.normalCount != null ? summary.normalCount : (summary.NormalCount != null ? summary.NormalCount : summary.normal)) || 0
}
return
}
const list = data.list || data.List || []
let late = 0
let abnormal = 0
let normal = 0
list.forEach(row => {
const s = this.pickStats(row)
if (s.late > 0) late += 1
if (s.abnormal > 0) abnormal += 1
if (s.late === 0 && s.abnormal === 0 && s.normal > 0) normal += 1
})
this.kpi = { late, abnormal, normal }
} catch (e) {
this.kpi = { late: 0, abnormal: 0, normal: 0 }
} finally {
this.loading = false
}
},
goMore() {
this.$router.push('/attendance-record').catch(() => {})
}
}
}
</script>
<style lang="scss" scoped>
@import '../widget-common.scss';
</style>