index.vue 8.62 KB
<template>
	<div class="NCC-common-layout">
		<div class="NCC-common-layout-center">
			<el-row class="NCC-common-search-box" :gutter="16">
				<el-form @submit.native.prevent>
					<el-col :span="6">
						<el-form-item label="员工姓名">
							<el-input v-model="query.userName" placeholder="员工姓名" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="年份">
							<el-select v-model="query.year" placeholder="年份" clearable>
								<el-option v-for="year in yearOptions" :key="year" :label="year + '年'" :value="year" />
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="月份">
							<el-select v-model="query.month" placeholder="月份" clearable>
								<el-option v-for="month in monthOptions" :key="month" :label="month + '月'" :value="month" />
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="员工状态">
							<el-select v-model="query.employeeStatus" placeholder="员工状态" clearable>
								<el-option label="在职" :value="1" />
								<el-option label="离职" :value="0" />
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item>
							<el-button type="primary" icon="el-icon-search" @click="search()">查询</el-button>
							<el-button icon="el-icon-refresh-right" @click="reset()">重置</el-button>
						</el-form-item>
					</el-col>
				</el-form>
			</el-row>
			<div class="NCC-common-layout-main NCC-flex-main">
				<div class="NCC-common-head">
					<div>
						<el-button type="primary" icon="el-icon-upload2" @click="handleImport()">导入</el-button>
						<el-button type="text" icon="el-icon-download" @click="downloadTemplate()">导入模板</el-button>
						<el-button type="text" icon="el-icon-delete" @click="handleBatchDelete()">批量删除</el-button>
					</div>
					<div class="NCC-common-head-right">
						<el-tooltip effect="dark" content="刷新" placement="top">
							<el-link icon="icon-ym icon-ym-Refresh NCC-common-head-icon" :underline="false" @click="reset()" />
						</el-tooltip>
						<screenfull isContainer />
					</div>
				</div>
                <NCC-table v-loading="listLoading" :data="list" has-c @selection-change="handleSelectionChange">
					<el-table-column prop="userName" label="员工姓名" align="left" />
					<el-table-column prop="year" label="年份" align="left" />
					<el-table-column prop="month" label="月份" align="left" />
					<el-table-column label="员工状态" prop="employeeStatus" align="left">
						<template slot-scope="scope">
							<el-tag :type="scope.row.employeeStatus === 1 ? 'success' : 'danger'" size="small">
								{{ scope.row.employeeStatus === 1 ? '在职' : '离职' }}
							</el-tag>
						</template>
					</el-table-column>
					<el-table-column prop="workDays" label="工作天数" align="left" />
					<el-table-column prop="leaveDays" label="请假天数" align="left" />
					<el-table-column prop="restDays" label="休息天数" align="left" />
					<el-table-column prop="remark" label="备注" align="left" />
					<el-table-column label="创建时间" prop="createTime" align="left" width="150">
						<template slot-scope="scope">
							{{ formatTime(scope.row.createTime) }}
						</template>
					</el-table-column>
					<el-table-column label="更新时间" prop="updateTime" align="left" width="150">
						<template slot-scope="scope">
							{{ formatTime(scope.row.updateTime) }}
						</template>
					</el-table-column>
				</NCC-table>
                <pagination :total="total" :page.sync="listQuery.currentPage" :limit.sync="listQuery.pageSize" @pagination="initData" />
            </div>
        </div>
		
		<!-- 导入弹窗 -->
		<ImportDialog v-if="importVisible" ref="ImportDialog" @refresh="refresh" />
		
		<!-- 批量删除弹窗 -->
		<BatchDeleteDialog v-if="batchDeleteVisible" ref="BatchDeleteDialog" @refresh="refresh" />
	</div>
</template>

<script>
    import request from '@/utils/request'
    import ImportDialog from './ImportDialog'
    import BatchDeleteDialog from './BatchDeleteDialog'
    
	export default {
        components: { ImportDialog, BatchDeleteDialog },
        data() {
            return {
				query: {
                    userName: undefined,
                    year: undefined,
                    month: undefined,
                    employeeStatus: undefined,
				},
                list: [],
                listLoading: true,
                multipleSelection: [], 
                total: 0,
                listQuery: {
                    currentPage: 1,
                    pageSize: 20,
					sort: "desc",
                    sidx: "",
                },
                importVisible: false,
                batchDeleteVisible: false,
                yearOptions: [],
                monthOptions: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
			}
        },
		computed: {},
		created() {
			this.initYearOptions()
			this.initData()
		},
		methods: {
			initYearOptions() {
				const currentYear = new Date().getFullYear()
				for (let i = currentYear - 5; i <= currentYear + 1; i++) {
					this.yearOptions.push(i)
				}
			},
			initData() {
                this.listLoading = true;
                let _query = {
                    ...this.listQuery,
                    ...this.query
                };
                let query = {}
                for (let key in _query) {
                    if (Array.isArray(_query[key])) {
                        query[key] = _query[key].join()
                    } else {
                        query[key] = _query[key]
                    }
                }
                request({
                    url: `/api/Extend/lqattendancesummary`,
                    method: 'GET',
                    data: query
                }).then(res => {
                    this.list = res.data.list
                    this.total = res.data.pagination.total
                    this.listLoading = false
                })
            },
			handleDel(id) {
                this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
                    type: 'warning'
                }).then(() => {
                    request({
                        url: `/api/Extend/lqattendancesummary/${id}`,
                        method: 'DELETE'
                    }).then(res => {
                        this.$message({
                            type: 'success',
                            message: res.msg,
                            onClose: () => {
                                this.initData()
                            }
                        });
                    })
                }).catch(() => {
                });
            },
			handleSelectionChange(val) {
                const res = val.map(item => item.id)
                this.multipleSelection = res
            },
            handleImport() {
                this.importVisible = true
                this.$nextTick(() => {
                    this.$refs.ImportDialog.init()
                })
            },
            handleBatchDelete() {
                this.batchDeleteVisible = true
                this.$nextTick(() => {
                    this.$refs.BatchDeleteDialog.init()
                })
            },
            downloadTemplate() {
                window.open('https://erp.lvqianmeiye.com/FileTemplate/考勤统计导入模板.xlsx', '_blank')
            },
            formatTime(timestamp) {
                if (!timestamp) return '无'
                const date = new Date(timestamp)
                return date.toLocaleString('zh-CN', {
                    year: 'numeric',
                    month: '2-digit',
                    day: '2-digit',
                    hour: '2-digit',
                    minute: '2-digit',
                    second: '2-digit'
                })
            },
			search() {
                this.listQuery = {
                    currentPage: 1,
                    pageSize: 20,
                    sort: "desc",
                    sidx: "",
                }
                this.initData()
            },
            refresh(isrRefresh) {
                this.importVisible = false
                this.batchDeleteVisible = false
                if (isrRefresh) this.reset()
            },
            reset() {
                for (let key in this.query) {
                    this.query[key] = undefined
                }
                this.listQuery = {
                    currentPage: 1,
                    pageSize: 20,
                    sort: "desc",
                    sidx: "",
                }
                this.initData()
            }
		}
    }
</script>