<template> <app-container> <search-area :need-clear="true" :need-search-more="true" type="seperate" search-more-type="default" @search="fetchData" @clear="clearInput"> <!--一般查询条件--> <search-item> <el-input v-model.trim="listQuery.keywords" size="small" placeholder="姓名/身份证号/手机号" clearable/> </search-item> <search-item/> <search-item> <el-select v-model="listQuery.type" size="small" placeholder="人员类型" clearable> <el-option v-for="item in typeList" :key="item.value" :label="item.name" :value="item.value"/> </el-select> </search-item> <search-item> <el-select v-model="listQuery.post" size="small" placeholder="岗位" clearable> <el-option v-for="item in postList" :key="item.value" :label="item.name" :value="item.value"/> </el-select> </search-item> <!--高级检索--> <div slot="searchMore"> <search-item> <el-input v-model.trim="listQuery.responseArea" size="small" placeholder="负责片区" clearable/> </search-item> <search-item> <el-select v-model="listQuery.jobCode" size="small" placeholder="作业内容" clearable> <el-option v-for="item in jobList" :key="item.value" :label="item.name" :value="item.value"/> </el-select> </search-item> <search-item> <el-date-picker v-model="listQuery.hireDate" size="small" type="month" value-format="yyyy-MM" placeholder="入职年月" clearable/> </search-item> </div> </search-area> <normal-table :data="list" :head="tableOption.head" :query="listQuery" :total="total" :columns="columns" :list-loading="listLoading" :options="tableOption.options" :tools-option="tableOption.toolsOption" @change="changePage"> <template slot="btns"> <el-button v-if="hasPerm('/sanitation/staff/add')" size="small" class="edit_btn" @click.stop="add">新增</el-button> <!--<el-button size="small" class="edit_btn">删除</el-button>--> <el-upload v-if="hasPerm('/sanitation/staff/import')" :limit="1" :show-file-list="false" :http-request="uploadFile" :file-list="fileList" action="string" accept=".xls,.xlsx" class="edit_btn"> <el-button slot="trigger" size="small">批量导入</el-button> </el-upload> <el-button v-if="hasPerm('/sanitation/staff/export')" size="small" class="edit_btn" @click="batchExport">花名册导出</el-button> </template> <template slot="columns"> <el-table-column label="操作" align="center" width="160"> <template slot-scope="scope"> <el-button type="text" size="small" @click.stop="goDetail(scope.row)">详情</el-button> <el-button v-if="hasPerm('/sanitation/staff/update')" type="text" size="small" @click.stop="edit(scope.row)">编辑</el-button> <el-button v-if="hasPerm('/sanitation/staff/delete')" type="text" size="small" @click.stop="del(scope.row)">删除</el-button> <!--<el-button type="text" size="small" @click.stop="registerIris(scope.row)">岗位调整</el-button>--> </template> </el-table-column> </template> </normal-table> <edit-staff v-show="editShow" ref="editstaff" @watchChild="fetchData"/> </app-container> </template> <script> import EditStaff from './editStaff' import { getDictByType } from '@/api/common' import { getStaffListPage, delStaff, batchImportStaff, batchExportStaff } from '@/api/sanitation/staff' import { exportFile } from '@/utils/exportutils' export default { name: 'StaffList', components: { EditStaff }, data() { return { listQuery: { keywords: '', // 关键字 type: '', // 人员类型 post: '', // 岗位 hireDate: '', // 入职年月时间 jobCode: '', // 作业内容 responseArea: '', // 负责片区 offset: 1, limit: 20, sort: '', order: 'desc' }, // 筛选条件 columns: [ { text: '姓名', value: 'name', align: 'center' }, { text: '性别', value: 'sexName', align: 'center', width: 60 }, { text: '身份证号', value: 'idCard', width: 165, align: 'center' }, { text: '手机号', value: 'tel', align: 'center' }, { text: '类型', value: 'typeName', align: 'center', width: 80 }, { text: '岗位', value: 'postName', align: 'center' }, { text: '入职年月', value: 'hireDate', align: 'center' }, { text: '负责片区', value: 'responseArea', align: 'center' } ], // 显示列 timeRange: [], // 时间范围 list: [], // 列表数据 total: 0, // 数据总数 listLoading: true, // 列表加载动画 typeList: [ { name: '正式职工', value: '0' }, { name: '外聘', value: '1' } ], postList: [ { name: '保洁员', value: '0' }, { name: '司机', value: '1' } ], // 岗位 jobList: [ { name: '清扫', value: '0' }, { name: '保洁', value: '1' } ], // 作业内容 tableOption: { head: { show: true, // 是否需要标题栏, text: '数据列表' // 标题名称 }, options: { needIndex: true // 是否需要序号列 }, toolsOption: { selectColumns: false, // 是否需要筛选列 refresh: false // 是否需要刷新按钮 } }, // 表格属性 editShow: false, // 编辑页面是否显示 fileList: [] // 文件列表,上传用 } }, created() { this.fetchData() this.fetchPersonType() this.fetchPost() this.fetchJob() }, methods: { fetchData() { this.listLoading = true const that = this getStaffListPage(this.listQuery).then(response => { that.list = response.data.rows that.total = response.data.total that.listLoading = false }) }, // 点击编辑 edit(row) { this.editShow = true this.$refs.editstaff.initDialog('update', true, row) }, // 点击详情 goDetail(row) { this.editShow = true this.$refs.editstaff.initDialog('detail', true, row) }, // 点击新增 add() { this.editShow = true this.$refs.editstaff.initDialog('create', true) }, // 删除单个人员 del(row) { const staffIds = [row.id] this.$confirm( '确定要删除该人员吗?', '确认操作', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' } ).then(() => { delStaff(staffIds).then(response => { if (response.code === 200) { this.$message.success('删除成功') this.fetchData() } }) }) }, // 删除多个人员 batchDel() { if (this.checkSelection()) { const staffIds = [] this.multipleSelection.forEach(function(value, index) { staffIds.push(value.id) }) this.$confirm( '确定要删除所选人员吗?', '确认操作', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' } ).then(() => { delStaff(staffIds).then(response => { if (response.code === 200) { this.$message.success('删除成功') this.fetchData() } }) }) } else { this.$message.error('至少选中一项') } }, // 批量导入 uploadFile(param) { // 判断文件大小是否符合要求 const _file = param.file const isLt5M = _file.size / 1024 / 1024 < 5 if (!isLt5M) { this.$message.error('请上传5M以下的excel文件') return false } // 全屏加载动画 const loading = this.$loading({ lock: true, text: '导入中,请稍后...', spinner: 'el-icon-loading', background: 'rgba(0, 0, 0, 0.7)' }) // 发起导入请求 batchImportStaff(_file).then(res => { loading.close() // 关闭加载动画 if (res.code === 200) { this.$message.success('导入成功') this.fetchData() } else { this.$message.error(res.message) } }).catch(() => { loading.close() // 关闭加载动画 }) this.fileList = [] }, // 批量导出 batchExport() { // 全屏加载动画 const loading = this.$loading({ lock: true, text: '数据处理中,请稍后...', spinner: 'el-icon-loading', background: 'rgba(0, 0, 0, 0.7)' }) batchExportStaff(this.listQuery).then(res => { loading.close() // 关闭加载动画 const blob = new Blob([res.data]) const fileName = `人员列表.xlsx` // 下载后文件名 exportFile(blob, fileName) }).catch((res) => { loading.close() }) }, // 获取人员类别 fetchPersonType(val) { getDictByType('staffType').then(response => { this.typeList = response.data }) }, // 获取岗位 fetchPost(val) { getDictByType('postType').then(response => { this.postList = response.data }) }, // 获取岗位 fetchJob(val) { getDictByType('jobType').then(response => { this.jobList = response.data }) }, // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 changePage(val) { if (val && val.size) { this.listQuery.limit = val.size } if (val && val.page) { this.listQuery.offset = val.page } this.fetchData() }, // 重置后的操作, 若不需要显示重置按钮则不需要写 clearInput() { this.listQuery = { keywords: '', // 关键字 type: '', // 人员类型 post: '', // 岗位 hiredate: '', // 入职年月时间 jobCode: '', // 作业内容 responseArea: '', // 负责片区 offset: 1, limit: 20, sort: '', order: 'desc' } } } } </script> <style rel="stylesheet/scss" lang="scss" scoped> .edit_btns{ .edit_btn{ float:right; margin-left:5px; } } </style>