<template> <app-container> <search-area :need-clear="true" :need-search-more="false" type="seperate" size="small" search-more-type="default" @search="fetchData(false)" @clear="clearInput"> <!--一般查询条件--> <search-item> <el-input v-model.trim="listQuery.keywords" size="small" placeholder="员工号/员工姓名" @change="fetchData(false)" /> </search-item> <search-item> <el-input v-model.trim="listQuery.cardNum" size="small" placeholder="卡编号" @change="fetchData(false)" /> </search-item> <search-item> <el-select v-model="listQuery.staffType" size="small" placeholder="员工类型" clearable @change="fetchData(false)"> <el-option v-for="item in typeList" :key="item.value" :label="item.name" :value="item.value" /> </el-select> </search-item> <search-item> <el-input v-model.trim="listQuery.phone" size="small" placeholder="手机号" @change="fetchData(false)" /> </search-item> </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" size="small" @change="changePage" @selectionChange="handleSelectionChange" > <template slot="btns"> <el-button size="small" class="edit_btn" icon="el-icon-download" @click="exportFile()"> 导出 </el-button> <!-- <el-button size="small" class="edit_btn" icon="el-icon-edit" @click="add()">--> <!-- 添加--> <!-- </el-button>--> <!-- <el-button size="small" class="edit_btn" icon="el-icon-delete" @click="batchDel()">--> <!-- 删除--> <!-- </el-button>--> <!-- <download-template :filename="filename" />--> <!-- <el-upload--> <!-- :limit="1"--> <!-- :show-file-list="false"--> <!-- :http-request="uploadFile"--> <!-- :file-list="fileList"--> <!-- action="string"--> <!-- style="float:right; margin:0 0 0 3px;"--> <!-- accept=".xls,.xlsx"--> <!-- >--> <!-- <el-button slot="trigger" size="small" icon="el-icon-folder-add">--> <!-- 批量导入--> <!-- </el-button>--> <!-- </el-upload>--> </template> <template slot="columns"> <el-table-column label="员工照片" align="center" width="120"> <template slot-scope="scope"> <el-image :src="scope.row.picture ? `${ scope.row.picture}`: defaultPhoto" :preview-src-list="srcList" width="50" height="50" style="width: 50px; height: 50px;margin-top: 10px" @error="errorImg"/> </template> </el-table-column> <el-table-column label="操作" align="center" width="160"> <template slot-scope="scope"> <el-button type="text" size="small" @click.stop="trail(scope.row)"> 轨迹追踪 </el-button> <el-button type="text" size="small" @click.stop="detail(scope.row)"> 详情 </el-button> <!-- <el-button type="text" size="small" @click.stop="edit(scope.row)">--> <!-- 编辑--> <!-- </el-button>--> <!-- <el-button type="text" size="small" @click.stop="del(scope.row)">--> <!-- 删除--> <!-- </el-button>--> </template> </el-table-column> </template> </normal-table> <edit-staff v-show="dialogFormVisible" ref="editStaff" @watchChild="fetchData" /> <trail-dialog v-show="dialogFormVisible1" ref="trailDialog" @watchChild="fetchData" /> </app-container> </template> <script> import NormalTable from '@/components/NormalTable' import AppContainer from '@/components/layout/AppContainer' import SearchArea from '@/components/SearchArea/SearchArea' import SearchItem from '@/components/SearchArea/SearchItem' import { getStaffListPage, delStaff, batchDelStaff, batchImportStaff } from '@/api/person' import { getDictByCode } from '@/api/system/dict' import EditStaff from './editStaff' import { getStaffExport } from '@/api/person' import TrailDialog from '@/views/common/trailDialog' export default { name: 'StaffList', components: { TrailDialog, SearchItem, SearchArea, AppContainer, NormalTable, EditStaff }, data() { return { defaultPhoto: require('@/assets/global_images/photo.png'), errorImg: require('@/assets/global_images/photo_error.png'), srcList: [], listQuery: { keywords: '', cardNum: '', staffType: '', phone: '', offset: 1, limit: 20 }, // 筛选条件 columns: [ { text: '员工编号', value: 'jobNo', align: 'center' }, { text: '员工姓名', value: 'staffName', align: 'center' }, { text: '员工类型', value: 'staffTypeName', align: 'center' }, { text: '所属组织', value: 'deptName', align: 'center' }, { text: '身份证', value: 'staffIdCardM', align: 'center' }, { text: '手机号', value: 'phone', align: 'center' }, // { // text: '工作开始日期', // value: 'onDate', // align: 'center' // }, // { // text: '工作终止日期', // value: 'offDate', // align: 'center' // } ], // 显示列 dialogFormVisible: false, // 是否显示编辑框 dialogFormVisible1: false, // 是否显示编辑框 timeRange: [], // 时间范围 multipleSelection: [], // 多选选中项 list: [], // 列表数据 typeList: [], total: 0, // 数据总数 listLoading: true, // 列表加载动画 filename: 'stafftemp.xlsx', fileList: [], tableOption: { head: { show: true, // 是否需要标题栏, text: '数据列表' // 标题名称 }, options: { needIndex: true // 是否需要序号列 }, toolsOption: { selectColumns: false, // 是否需要筛选列 refresh: false, // 是否需要刷新按钮 needCheckBox: false } } // 表格属性 } }, created() { this.fetchOptions() this.fetchData() }, methods: { fetchOptions() { getDictByCode('staffType').then(response => { if (response.code === 200) { this.typeList = response.data } }) }, // 批量导出 exportFile() { const loading = this.$loading({ lock: true, text: '数据处理中,请稍后...', spinner: 'el-icon-loading', background: 'rgba(0, 0, 0, 0.7)' }) getStaffExport(this.listQuery).then(res => { loading.close() // 关闭加载动画 console.log('download===', res) const blob = new Blob([res.data]) const downloadElement = document.createElement('a') const href = window.URL.createObjectURL(blob) // 创建下载的链接 downloadElement.href = href downloadElement.download = `员工列表.xlsx` // 下载后文件名 document.body.appendChild(downloadElement) downloadElement.click() // 点击下载 document.body.removeChild(downloadElement) // 下载完成移除元素 window.URL.revokeObjectURL(href) // 释放blob对象 }).catch((res) => { loading.close() this.$message.error(res.message) }) }, 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(false) } else { this.$message.error(res.message) } }).catch(() => { loading.close() // 关闭加载动画 }) this.fileList = [] }, encrypIdCardNo(idCard) { if (idCard.length > 6) { return idCard.substr(0, 6) + '********' + idCard.substr(14) } else if (idCard) { return idCard } else { return '' } }, fetchData(isNowPage = true) { this.listLoading = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 this.listQuery.offset = 1 } getStaffListPage(this.listQuery).then(response => { if (response.code === 200) { this.list = response.data.rows.map(item => { item.staffIdCardM = this.encrypIdCardNo(item.staffIdCard) if (item.onDate && item.onDate.length !== 0) { item.onDate = item.onDate.substring(0, 10) } if (item.offDate && item.offDate.length !== 0) { item.offDate = item.offDate.substring(0, 10) } return item }) this.srcList = response.data.rows.map(item => item.picture) this.total = parseInt(response.data.total) this.listLoading = false } }) // const that = this // setTimeout(function() { // that.list = [ // { id: '', staffCode: '0098701', staffName: '张三', staffType: '0', staffTypeName: '物业人员', phone: '132********', picture: '', onDate: '2022-05-06', offDate: '2022-05-16' }, // { id: '', staffCode: '0098701', staffName: '张三', staffType: '0', staffTypeName: '物业人员', phone: '132********', picture: '', onDate: '2022-05-06', offDate: '2022-05-16' }, // { id: '', staffCode: '0098701', staffName: '张三', staffType: '0', staffTypeName: '物业人员', phone: '132********', picture: '', onDate: '2022-05-06', offDate: '2022-05-16' }, // { id: '', staffCode: '0098701', staffName: '张三', staffType: '0', staffTypeName: '物业人员', phone: '132********', picture: '', onDate: '2022-05-06', offDate: '2022-05-16' }, // { id: '', staffCode: '0098701', staffName: '张三', staffType: '0', staffTypeName: '物业人员', phone: '132********', picture: '', onDate: '2022-05-06', offDate: '2022-05-16' }, // { id: '', staffCode: '0098701', staffName: '张三', staffType: '0', staffTypeName: '物业人员', phone: '132********', picture: '', onDate: '2022-05-06', offDate: '2022-05-16' }, // { id: '', staffCode: '0098701', staffName: '张三', staffType: '0', staffTypeName: '物业人员', phone: '132********', picture: '', onDate: '2022-05-06', offDate: '2022-05-16' } // ] // that.total = 200 // that.listLoading = false // }, 100) }, // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 changePage(val) { if (val && val.size) { this.listQuery.limit = val.size } if (val && val.page) { this.listQuery.offset = val.page } this.fetchData() }, batchDel() { const ids = this.multipleSelection.map(item => item.id) const faceIds = this.multipleSelection.map(item => item.faceIds) if (ids.length === 0) { this.$message.warning('请至少选择一行') return } this.$confirm( '确定要删除所选数据吗?', '确认操作', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' } ).then(() => { batchDelStaff(ids,faceIds).then(response => { if (response.code === 200) { this.$message.success('删除成功') this.fetchData() } }) }) }, trail(row) { this.dialogFormVisible1 = true this.$refs.trailDialog.initDialog(row.picture, row.staffName) }, // 打开详情对话框 detail(row) { this.$refs.editStaff.initDialog('detail', row) }, // 新增区域 add() { this.dialogFormVisible = true this.$refs.editStaff.initDialog('create') }, // 编辑区域信息 edit(row) { this.dialogFormVisible = true this.$refs.editStaff.initDialog('update', row) }, del(row) { this.$confirm( '确定要删除该条数据吗?', '确认操作', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' } ).then(() => { delStaff(row.id, row.staffFaceId).then(response => { if (response.code === 200) { this.$message.success('删除成功') this.fetchData() } }) }) }, handleSelectionChange(val) { this.multipleSelection = val }, clearInput() { this.listQuery = { keywords: '', cardNum: '', staffType: '', phone: '', offset: 1, limit: 20 } this.fetchData() } } } </script> <style scoped> </style>