<!--员工管理--> <template> <div v-if="!$root.isOcxShow" class="app-container"> <!--筛选条件--> <div class="search-div"> <el-form ref="selectForm" :inline="true" :model="listQuery" class="form-container"> <el-row> <el-form-item class="selectForm-container-item"> <el-input v-model.trim="listQuery.keywords" placeholder="姓名/员工编号" clearable/> </el-form-item> <el-form-item class="selectForm-container-item"> <el-input v-model.trim="listQuery.cardCode" placeholder="卡编号" clearable/> </el-form-item> <el-form-item class="selectForm-container-item"> <dept-select v-model="listQuery.deptid" :need-top="false" :dept-show="true" placeholder="单位/部门"/> </el-form-item> <el-form-item class="selectForm-container-item"> <el-select v-model="listQuery.groupId" placeholder="人员组别" clearable> <el-option v-for="item in groupList" :key="item.id" :label="item.groupName" :value="item.id"/> </el-select> </el-form-item> <el-form-item class="selectForm-container-item"> <el-select v-model="listQuery.cardType" placeholder="卡类型" clearable> <el-option label="A" value="A"/> <el-option label="B" value="B"/> <el-option label="C" value="C"/> <el-option label="D" value="D"/> </el-select> </el-form-item> <el-form-item class="selectForm-container-item" > <el-date-picker v-model="timeRange" type="datetimerange" range-separator="至" value-format="yyyy-MM-dd HH:mm:ss" start-placeholder="创建开始时间" end-placeholder="创建结束时间"/> </el-form-item> <el-form-item class="selectForm-container-item"> <el-date-picker v-model="updateTimeRange" type="datetimerange" range-separator="至" value-format="yyyy-MM-dd HH:mm:ss" start-placeholder="建卡开始时间" end-placeholder="建卡结束时间"/> </el-form-item> <el-button class="filter-item" type="primary" icon="el-icon-search" @click="search">搜索</el-button> </el-row> </el-form> </div> <!--查询结果Table显示--> <div> <el-row class="table-title"> <el-col :span="4"><div class="title-header"><i class="el-icon-menu"/>数据列表</div></el-col> <el-col :span="20" class="edit_btns"> <div class="clearfix"> <el-button v-if="hasPerm('/person/synchronizeDelPerson')" class="edit_btn" size="small" @click="delSynchronizePerson">删除闸机数据</el-button> <el-dropdown v-if="hasPerm('/person/synchronizePerson')" class="edit_btn"> <el-button size="small">下发闸机数据</el-button> <el-dropdown-menu slot="dropdown"> <el-dropdown-item @click.native="synchronizePerson(1)">院本部授权</el-dropdown-item> <el-dropdown-item @click.native="synchronizePerson(2)">公共区域授权</el-dropdown-item> </el-dropdown-menu> </el-dropdown> <el-button v-if="attendanceEnable" class="edit_btn" size="small" @click="initAnnualLeave">初始化剩余年假</el-button> <el-upload :limit="1" :show-file-list="false" :http-request="importPersonNewUpload" :file-list="personNewList" action="string" accept=".xls,.xlsx" class="edit_btn" style="margin-top: 0"> <el-button slot="trigger" class="edit_btn" size="small">更换卡</el-button> </el-upload> <download-template ref="downloadTemplate" filename="personNewInfoTemp.xlsx" label="换卡模板下载"/> <!--批量导入删除--> <el-upload :limit="1" :show-file-list="false" :before-upload="beforeUpload" :http-request="batchPhotoUpload" :file-list="photoFileList" action="string" accept=".zip" class="edit_btn" style="margin-top: 0"> <el-button slot="trigger" class="edit_btn" size="small">照片批量导入</el-button> </el-upload> <el-upload :limit="1" :show-file-list="false" :http-request="deletePersonUpload" :file-list="deleteFileList" action="string" accept=".xls,.xlsx" class="edit_btn" style="margin-top: 0"> <el-button slot="trigger" class="edit_btn" size="small">批量导入删除</el-button> </el-upload> <!--批量导入--> <el-upload :limit="1" :show-file-list="false" :http-request="importPersonUpload" :file-list="personFileList" action="string" accept=".xls,.xlsx" class="edit_btn" style="margin-top: 0"> <el-button slot="trigger" class="edit_btn" size="small">批量导入</el-button> </el-upload> <download-template ref="downloadTemplate" :filename="filename" /> <el-button :disabled="total===0" class="edit_btn" size="small" @click="batchExport">导出记录</el-button> <el-button v-if="hasPerm('/staff/delete')" class="edit_btn" size="small" @click="del">删除</el-button> <el-button v-if="hasPerm('/staff/add')" class="edit_btn" size="small" @click="add">新增</el-button> </div> </el-col> </el-row> <el-table v-loading="listLoading" ref="dataTable" :data="list" class="table" border @selection-change="handleSelectionChange"> <el-table-column v-if="hasPerm('/staff/delete')" align="center" type="selection" width="55"/> <el-table-column :index="indexMethod" align="center" label="序号" type="index" width="55"/> <el-table-column v-for="column in columns" :key="column.value" :label="column.text" :width="column.width" :align="column.align" show-overflow-tooltip> <template slot-scope="scope"> <span v-if="column.value === 'idCardNo'">{{ encrypIdCardNo(scope.row[column.value]) }}</span> <span v-else>{{ scope.row[column.value] ? scope.row[column.value] : scope.row.ext[column.value] }}</span> </template> </el-table-column> <el-table-column label="照片" width="60"> <template slot-scope="scope"> <img :src="scope.row.photo ? `${base_url}${scope.row.photo}`: defaultPhoto" width="40" height="40" @error="errorImg" > </template> </el-table-column> <el-table-column label="操作" align="center" width="100"> <template slot-scope="scope"> <el-button v-if="hasPerm('/staff/update')" type="text" @click="edit(scope.row)">编辑</el-button> <!--<el-button v-if="hasPerm('/iris')&& scope.row['isRegist']=='0'" type="text" @click="registerIris(scope.row)">注册虹膜</el-button>--> <!--<el-button v-if="hasPerm('/iris')&& scope.row['isRegist']=='1'" type="text" @click="registerIris(scope.row)">重新注册</el-button>--> </template> </el-table-column> </el-table> </div> <!--分页--> <div class="pagination-container"> <el-pagination v-show="total>listQuery.limit" :current-page="listQuery.offset" :page-sizes="[20,30,50,100,200]" :page-size="listQuery.limit" :total="total" align="center" layout="total, sizes, prev, pager, next" @size-change="handleSizeChange" @current-change="handleCurrentChange"/> </div> <capture-iris ref="captureIris" :v-if.sync="dialogFormVisible"/> <update-data ref="updateData" @finishUpdate="finishUpdate"/> </div> </template> <script> import DeptSelect from '@/components/DeptSelect' import { getPersonList, getSexType, getDutyType, delPerson, batchImportPhoto, sendPanelPersons, batchExportPerson, batchImportPerson, batchDeletePerson, batchImportPersonNew, syncPerson, delSyncPerson } from '@/api/person' import DownloadTemplate from '@/components/DownloadTemplate/index' // import { getToken } from '@/utils/auth' // getToken from cookie // import { getProject } from '@/utils/baseConfig' // import { isIE } from '@/utils/browser' import { downloadFile } from '@/utils/downloadUtils' import { attendanceEnable } from '@/main.js' import { initAnnualLeave } from '@/api/attendance' import CaptureIris from './captureIris' import UpdateData from './updateData' import { getPersonGroupList } from '@/api/person' export default { name: 'ListStaff', components: { CaptureIris, DeptSelect, DownloadTemplate, UpdateData }, data() { return { listQuery: { keywords: '', // 关键字(姓名/身份证号) groupId: '', // 人员分组 deptid: '', // 部门 personType: '1', // 人员类 offset: 1, limit: 200, cardCode: '', // 卡编号 cardType: '', // 卡类别 startTime: '', // 创建开始时间 endTime: '', // 创建结束时间 updateStartTime: '', // 建卡开始时间 updateEndTime: '', // 建卡结束时间 sort: '', // 排序 order: '' }, // 筛选条件 dialogFormVisible: false, columns: [], // 显示列 multipleSelection: [], // 多选选中项 list: [], // 列表数据 total: 0, // 数据总数 sexList: [], // 性别列表 dutyList: [], // 职务列表 listLoading: false, // 加载动画 fullscreenLoading: false, // 全屏加载动画 filename: 'personAtdTempDownload.xlsx', attendanceEnable: attendanceEnable, photoFileList: [], personFileList: [], deleteFileList: [], personNewList: [], groupList: [], timeRange: [], // 时间范围 updateTimeRange: [], // 时间范围 base_url: process.env.BASE_API + '/static/', defaultPhoto: require('@/assets/global_images/photo.png'), defaultPhotoError: require('@/assets/global_images/photo_error.png') } }, computed: { // 检查选择情况 hasSelection: function() { return this.multipleSelection.length !== 0 } }, watch: { timeRange(val) { if (val && val.length > 0) { this.listQuery.startTime = val[0] this.listQuery.endTime = val[1] } else { this.listQuery.startTime = '' this.listQuery.endTime = '' } }, updateTimeRange(val) { if (val && val.length > 0) { this.listQuery.updateStartTime = val[0] this.listQuery.updateEndTime = val[1] } else { this.listQuery.updateStartTime = '' this.listQuery.updateEndTime = '' } } }, mounted() { this.columns = [ { text: '员工编号', value: 'personCode', align: 'center' }, { text: '姓名', value: 'name', align: 'center', width: 100 }, { text: '性别', value: 'sexName', align: 'center', width: 80 }, { text: '身份证号', value: 'idCardNo', align: 'center', width: 180 }, { text: '卡编号', value: 'cardCode', align: 'center' }, { text: '卡类型', value: 'cardType', align: 'center', width: 80 }, { text: '创建时间', value: 'createtime', align: 'center' }, { text: '建卡时间', value: 'updatetime', align: 'center' }, { text: '单位/部门', value: 'deptName', align: 'center' }, { text: '职务', value: 'dutyName', align: 'center' } ] if (attendanceEnable) { this.columns = this.columns.concat([ { text: '考勤', value: 'isKaoqinName', align: 'center' }, { text: '统计加班', value: 'isOtName', align: 'center' }, { text: '专务', value: 'isZhuanwuName', align: 'center' }, { text: '部门正职领导', value: 'isLeaderName', align: 'center' }, { text: '年假/天', value: 'initAnnualLeave', align: 'center' }, { text: '剩余年假/天', value: 'annualLeave', align: 'center' }, { text: '是否实习生', value: 'personTypeName', align: 'center' } ]) } this.fetchSexType()// 获取性别列表 this.fetchGroup()// 获取性别列表 this.fetchDutyType() // 获取职务列表 this.fetchData()// 获取数据 }, activated() { this.fetchData(false) }, methods: { receiveParamsFromHtml(res) {}, // 新增设备 add() { this.$router.push({ path: '/addStaff', query: { type: 'create', personType: '1' }}) }, // 编辑设备信息 edit(row) { this.$router.push({ path: '/updateStaff', query: { type: 'update', personType: '1', id: row.id }}) }, // 删除人员 del() { if (!this.hasSelection) { this.$message.error('至少选中一项') return } const staffIds = this.multipleSelection.map(v => v.id) this.$confirm( '确定要删除所选员工吗?', '确认操作', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' } ).then(() => { this.listLoading = true delPerson(staffIds).then(response => { if (response.code === 200) { this.$message.success(response.message) this.fetchData(false) this.listLoading = false } }).catch(() => { this.fetchData(false) this.listLoading = false }) }) }, // 下发闸机数据 synchronizePerson(type) { const params = { keywords: this.listQuery.keywords, // 关键字(姓名/身份证号) groupId: this.listQuery.groupId, // 部门 deptid: this.listQuery.deptid, // 部门 personType: this.listQuery.personType, // 人员类 cardCode: this.listQuery.cardCode, // 卡编号 cardType: this.listQuery.cardType, // 卡类别 startTime: this.listQuery.startTime, // 创建开始时间 endTime: this.listQuery.endTime, // 创建结束时间 updateStartTime: this.listQuery.updateStartTime, // 建卡开始时间 updateEndTime: this.listQuery.updateEndTime, // 建卡结束时间 personIds: this.hasSelection ? this.multipleSelection.map(v => v.id) : [], auth: type } const hint = this.hasSelection ? '确定要下发所选人员数据至闸机吗?' : '未选中人员,确定要下发列表中全部数据至闸机吗?' this.$confirm( `${hint}`, '确认操作', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' } ).then(() => { this.listLoading = true syncPerson(params).then(response => { if (response.code === 200) { this.$message.success(response.message) this.fetchData(false) this.listLoading = false } }).catch(() => { this.fetchData(false) this.listLoading = false }) }) }, // 删除闸机数据 delSynchronizePerson() { const params = { keywords: this.listQuery.keywords, // 关键字(姓名/身份证号) groupId: this.listQuery.groupId, // 部门 deptid: this.listQuery.deptid, // 部门 personType: this.listQuery.personType, // 人员类 cardCode: this.listQuery.cardCode, // 卡编号 cardType: this.listQuery.cardType, // 卡类别 startTime: this.listQuery.startTime, // 创建开始时间 endTime: this.listQuery.endTime, // 创建结束时间 updateStartTime: this.listQuery.updateStartTime, // 建卡开始时间 updateEndTime: this.listQuery.updateEndTime // 建卡结束时间 // personIds: this.hasSelection ? this.multipleSelection.map(v => v.id) : [] } if (!this.hasSelection) { this.$message.warning('未选中任何人员') // this.$confirm( // '未选中人员,确定要删除全部闸机数据吗?', // '确认操作', // { // confirmButtonText: '确定', // cancelButtonText: '取消', // type: 'warning' // } // ).then(() => { // this.listLoading = true // delSyncPerson(params).then(response => { // if (response.code === 200) { // this.$message.success(response.message) // this.fetchData(false) // this.listLoading = false // } // }).catch(() => { // this.fetchData(false) // this.listLoading = false // }) // }) } else { const staffIds = this.multipleSelection.map(v => v.id) this.$confirm( '确定要删除闸机中所选人员数据吗?', '确认操作', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' } ).then(() => { this.listLoading = true delSyncPerson({ personIds: staffIds }).then(response => { if (response.code === 200) { this.$message.success(response.message) this.fetchData(false) this.listLoading = false } }).catch(() => { this.fetchData(false) this.listLoading = false }) }) } }, registerIris(row) { this.dialogFormVisible = true this.$refs.captureIris.initDialog(this.dialogFormVisible, row, '0') }, // 图片加载失败 errorImg(e) { const img = e.srcElement img.src = this.defaultPhotoError img.onerror = null // 防止闪图 }, initAnnualLeave() { this.$confirm( '此操作不可撤销!仍要将所有员工的剩余年假设置为初始值吗?', '确认操作', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' } ).then(() => { initAnnualLeave().then(response => { if (response.code === 200) { this.$message.success('重置成功') this.fetchData() } }) }) }, // 照片批量上传导入格式大小限制 beforeUpload(file) { const isZip = file.name.split('.')[1] === 'zip' // const isLt5M = file.size / 1024 / 1024 < 5; if (!isZip) { this.$message({ message: '只能上传zip文件', type: 'error' }) return false } // if (!isLt5M) { // this.$message({ // message: "上传文件大小不能超过 5MB!", // type: "error" // }); // return false // } return isZip }, // 照片批量导入 batchPhotoUpload(param) { // 判断文件大小是否符合要求 const _file = param.file // let isZipExt = (_file.name && _file.name.split('.')[1]) === 'zip' // const isLt5M = _file.size / 1024 / 1024 < 5 // if (!isZipExt) { // this.$message.error('请上传zip格式文件') // return false // } // if (!isLt5M) { // this.$message.error('请上传5M以下zip格式文件') // return false // } // 全屏加载动画 const loading = this.$loading({ lock: true, text: '导入中,请稍后...', spinner: 'el-icon-loading', background: 'rgba(0, 0, 0, 0.7)' }) // 发起导入请求 batchImportPhoto(_file).then(res => { loading.close() // 关闭加载动画 if (res.code === 200) { this.$message.success(`${res.message}`) this.photoFileList = [] this.fetchData(false) } }).catch(() => { loading.close() this.$message.error('导入失败') this.photoFileList = [] }) this.photoFileList = [] }, // 人员同步至面板机 sendPanelPersons() { const staffIds = this.multipleSelection.map(v => v.id) const hasStaffLen = staffIds.length !== 0 this.$confirm( `确定要将${hasStaffLen ? '所选' : '全部'}人员同步至面板机吗?`, '确认操作', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' } ).then(() => { this.listLoading = true sendPanelPersons(hasStaffLen ? staffIds : null).then(response => { if (response.code === 200) { this.$message.success('同步成功') this.fetchData(false) this.listLoading = false } }).catch(() => { this.fetchData(false) this.listLoading = false }) }) }, // 批量导出 batchExport() { // 全屏加载动画 const loading = this.$loading({ lock: true, text: '数据处理中,请稍后...', spinner: 'el-icon-loading', background: 'rgba(0, 0, 0, 0.7)' }) batchExportPerson(this.listQuery).then(res => { loading.close() // 关闭加载动画 downloadFile(res.data, '员工列表') }).catch((res) => { loading.close() }) }, // 批量导入 importPersonUpload(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)' }) // 发起导入请求 batchImportPerson(_file).then(res => { loading.close() // 关闭加载动画 if (res.code === 200) { this.$message.success(`${res.message}`) this.personFileList = [] this.fetchData(false) } }).catch(() => { loading.close() }) this.personFileList = [] }, // 批量导入删除 deletePersonUpload(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)' }) // 发起导入请求 batchDeletePerson(_file).then(res => { loading.close() // 关闭加载动画 if (res.code === 200) { this.$message.success(`${res.message}`) this.deleteFileList = [] this.fetchData(false) } }).catch(() => { loading.close() this.deleteFileList = [] }) this.deleteFileList = [] }, // 更换卡 importPersonNewUpload(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)' }) // 发起导入请求 batchImportPersonNew(_file).then(res => { loading.close() // 关闭加载动画 if (res.code === 200) { this.$message.success(`${res.message}`) this.personNewList = [] this.fetchData(false) } }).catch(() => { loading.close() this.personNewList = [] }) this.personNewList = [] }, // 查询数据 search() { this.fetchData(false) }, // 获取数据 fetchData(isNowPage = true) { this.listLoading = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 this.listQuery.offset = 1 } getPersonList(this.listQuery).then(response => { if (response.data.rows) { for (var i = 0; i < response.data.rows.length; i++) { if (response.data.rows[i].personType === '0') { response.data.rows[i].personTypeName = '是' } else { response.data.rows[i].personTypeName = '否' } } } this.list = response.data.rows this.total = parseInt(response.data.total) this.listLoading = false }) }, fetchGroup() { getPersonGroupList().then(response => { this.groupList = response.data }) }, // 获取性别 fetchSexType() { getSexType().then(response => { this.sexList = response.data }) }, // 获取职务 fetchDutyType() { getDutyType().then(response => { this.dutyList = response.data }) }, indexMethod(index) { return this.listQuery.limit * (this.listQuery.offset - 1) + index + 1 }, // 改变页容量 handleSizeChange(val) { this.listQuery.limit = val this.fetchData() }, // 改变当前页 handleCurrentChange(val) { this.listQuery.offset = val this.fetchData() }, // 多选触发方法 handleSelectionChange(val) { this.multipleSelection = val }, // 身份证号加密 encrypIdCardNo(idCardNo) { if (idCardNo) { return idCardNo.substr(0, 6) + '********' + idCardNo.substr(14, 18) } else { return '' } }, // 人员数据下发 updateData() { if (!this.hasSelection) { this.$message.error('至少选中一项') return } this.$refs.updateData.initDialog(true, this.multipleSelection) }, finishUpdate() { this.$refs.dataTable.clearSelection() } } } </script> <style rel="stylesheet/scss" lang="scss" scoped> $tableTitleHeight:46px; .app-container{ margin-bottom:20px } .table{ margin-bottom: 20px; } .pagination-container{ margin-bottom: 50px; } .table-title{ background-color:rgba(243, 243, 243, 1); height: $tableTitleHeight; .title-header{ line-height:$tableTitleHeight; color: #606266; font-size: 15px; i{ margin-left: 5px; margin-right: 5px; } } } .edit_btns{ .edit_btn{ float:right; margin:7px 3px;//为了需要居中显示margin-top和bottom要用$tableTitleHeight减去按钮原高度除以2 } } </style>