You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
5.8 KiB

1 year ago
<template>
<div>
<card-container>
1 year ago
<vxe-toolbar export print ref="toolbar">
1 year ago
<template #buttons>
<el-date-picker v-model="select.month" type="month" size="small" value-format="yyyy-MM"></el-date-picker>
<el-button icon="el-icon-search" type="primary" plain size="small" style="margin-left: 6px;" @click="getStatistics"></el-button>
</template>
</vxe-toolbar>
<vxe-table
ref="table"
stripe
style="margin-top: 10px;"
round
:max-height="600"
keep-source
show-header-overflow
show-footer-overflow
show-overflow
:row-config="{ isHover: true }"
:header-cell-style="{ 'white-space': 'wrap' }"
1 year ago
:print-config="{}"
1 year ago
:export-config="{}"
1 year ago
:column-config="{ resizable: true }"
:data="tableData.admins">
<vxe-column type="seq" width="50" align="center" fixed="left"></vxe-column>
<vxe-column field="name" title="姓名" fixed="left" align="center" width="120"></vxe-column>
<vxe-column field="department.name" title="所在部门" align="center" width="150"></vxe-column>
<vxe-colgroup v-for="item in dateTableColumns" align="center" :title="item.title">
<vxe-column title="上午" width="160" align="center">
<template #default="{ row }">
1 year ago
<div v-if="row.attendance[item.date]['qingxiujia'] && row.attendance[item.date]['qingxiujia'][0]">
{{ row.attendance[item.date]['qingxiujia'][0].qingjialeibie }}
</div>
<div v-else-if="row.attendance[item.date]['chuchai'] && row.attendance[item.date]['chuchai'][0]">
出差
</div>
<div v-else-if="(row.attendance[item.date].hasOwnProperty('0')) && row.attendance[item.date]['0'].sign_in_at">
1 year ago
</div>
<div v-else>
</div>
1 year ago
</template>
</vxe-column>
<vxe-column title="下午" width="160" align="center">
<template #default="{ row }">
1 year ago
<div v-if="row.attendance[item.date]['qingxiujia'] && row.attendance[item.date]['qingxiujia'][1]">
{{ row.attendance[item.date]['qingxiujia'][1].qingjialeibie }}
</div>
<div v-else-if="row.attendance[item.date]['chuchai'] && row.attendance[item.date]['chuchai'][1]">
出差
</div>
<div v-else-if="(row.attendance[item.date].hasOwnProperty('0')) && row.attendance[item.date]['0'].sign_out_at">
1 year ago
</div>
<div v-else>
</div>
1 year ago
</template>
</vxe-column>
</vxe-colgroup>
1 year ago
<vxe-column title="备注" min-width="200" header-align="center" align="left">
<template #default="{ row }">
<span>{{ getRemark(row) }}</span>
</template>
</vxe-column>
1 year ago
</vxe-table>
</card-container>
</div>
</template>
<script>
1 year ago
import { throttle } from '@/utils'
1 year ago
import { statistics } from '@/api/attendance'
export default {
data() {
return {
select: {
month: this.$moment().format('YYYY-MM')
},
tableData: {
admins: [],
1 year ago
dates: [],
leave_types: []
1 year ago
}
}
},
methods: {
1 year ago
bindToolbar: throttle(function () {
this.$nextTick(() => {
if (this.$refs["table"] && this.$refs["toolbar"]) {
this.$refs["table"].connect(this.$refs["toolbar"]);
}
});
}, 1000, true),
1 year ago
async getStatistics() {
try {
const res = await statistics(this.select)
this.tableData = res
} catch (err) {
console.error(err)
}
1 year ago
},
getRemark(row) {
let result = ''
let overtimeDay = 0
let leave = new Map(this.tableData.leave_types.map(i => [i, 0]))
let signDay = Object.entries(row.attendance).reduce((pre, [key, value]) => {
if (value['qingxiujia'][0]) {
console.log(value['qingxiujia'][0])
leave.set(value['qingxiujia'][0]['qingjialeibie'], Number(leave.get(value['qingxiujia'][0]['qingjialeibie']) ?? 0) + Number(value['qingxiujia'][0]['day'] ?? 0))
}
if (value['qingxiujia'][1]) {
leave.set(value['qingxiujia'][1]['qingjialeibie'], Number(leave.get(value['qingxiujia'][1]['qingjialeibie']) ?? 0) + Number(value['qingxiujia'][1]['day'] ?? 0))
}
return pre + (!value.hasOwnProperty('0') ? 0 : (
this.workDates.indexOf(key) !== -1 ? (
(() => {
let temp = 0
temp += value['0'].sign_in_at ? 0.5 : 0
temp += value['0'].sign_out_at ? 0.5 : 0
return temp
})()
) : ((
(() => {
overtimeDay += value['0'].sign_in_at ? 0.5 : 0
overtimeDay += value['0'].sign_out_at ? 0.5 : 0
return 0
})()
)??0)
))
}, 0)
result += signDay === this.workDates.length ? '全勤' : `缺勤${this.workDates.length-signDay}`
result += overtimeDay ? `,加班${overtimeDay}` : ''
Array.from(leave).forEach(([name, day]) => {
if (day) {
result += `,${name}${day}`
}
})
return result
1 year ago
}
},
computed: {
dateTableColumns() {
1 year ago
let columns = this.tableData.dates.map(i => ({
1 year ago
title: `${this.$moment(i.day).format('YYYY年MM月DD日')} ${i.is_workday ? '工作日' : '公休'}`,
field: i.day,
date: i.date
}))
1 year ago
return columns
1 year ago
},
workDates() {
return this.tableData.dates.filter(i => i.is_workday).map(i => i.date)
1 year ago
}
},
created() {
this.getStatistics()
1 year ago
},
mounted() {
this.bindToolbar()
},
1 year ago
}
</script>
<style scoped lang="scss">
</style>