<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.staffKeywords" size="small" placeholder="员工号/员工姓名" @change="fetchData(false)" />
</search-item>
<search-item>
<el-input v-model.trim="listQuery.doorKeywords" size="small" placeholder="门禁编号/名称/区域" @change="fetchData(false)" />
</search-item>
<search-item>
<el-select v-model="listQuery.inoutType" size="small" placeholder="进出方式" style="width: 120px" clearable @change="fetchData(false)">
<el-option
v-for="item in inoutTypeList"
:key="item.value"
:label="item.name"
:value="item.value"
/>
</el-select>
</search-item>
<search-item>
<el-select v-model="listQuery.passWay" size="small" placeholder="通过方式" style="width: 120px" clearable @change="fetchData(false)">
<el-option
v-for="item in passWayList"
:key="item.value"
:label="item.name"
:value="item.value"
/>
</el-select>
</search-item>
<search-item>
<el-date-picker
v-model="timeRange"
type="daterange"
range-separator="至"
value-format="yyyy-MM-dd"
start-placeholder="起始日期"
end-placeholder="终止日期"
size="small"
@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>
</template>
<template slot="columns">
</template>
</normal-table>
<edit-staff v-show="dialogFormVisible" ref="editStaff" @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 { getInoutListPage, delStaff, batchDelStaff, batchImportStaff } from '@/api/person'
import { getDictByCode } from '@/api/system/dict'
import { getInoutExport } from '@/api/person';
export default {
name: 'StaffList',
components: { SearchItem, SearchArea, AppContainer, NormalTable },
data() {
return {
defaultPhoto: require('@/assets/global_images/photo.png'),
errorImg: require('@/assets/global_images/photo_error.png'),
listQuery: {
staffKeywords: '',
doorKeywords: '',
inoutType: '',
passWay: '',
startTime: '',
endTime: '',
offset: 1,
limit: 20
}, // 筛选条件
columns: [
{
text: '员工编号',
value: 'jobNo',
align: 'center'
},
{
text: '员工姓名',
value: 'staffName',
align: 'center'
},
{
text: '卡号',
value: 'cardNum',
align: 'center'
},
// {
// text: '所属组织',
// value: 'deptName',
// align: 'center'
// },
{
text: '门禁区域',
value: 'doorArea',
align: 'center'
},
{
text: '门禁名称',
value: 'doorName',
align: 'center'
},
{
text: '门禁编号',
value: 'doorCode',
align: 'center'
},
{
text: '门禁通道',
value: 'wayName',
align: 'center'
},
{
text: '进出方式',
value: 'inoutTypeName',
width: 80,
align: 'center'
},
{
text: '通过方式',
value: 'passWayName',
width: 80,
align: 'center'
},
{
text: '描述',
value: 'description',
align: 'center'
},
{
text: '通过时间',
value: 'passTime',
align: 'center'
}
], // 显示列
dialogFormVisible: false, // 是否显示编辑框
timeRange: [], // 时间范围
multipleSelection: [], // 多选选中项
list: [], // 列表数据
inoutTypeList: [],
passWayList: [],
total: 0, // 数据总数
listLoading: true, // 列表加载动画
filename: 'stafftemp.xlsx',
fileList: [],
tableOption: {
head: {
show: true, // 是否需要标题栏,
text: '数据列表' // 标题名称
},
options: {
needIndex: true // 是否需要序号列
},
toolsOption: {
selectColumns: false, // 是否需要筛选列
refresh: false, // 是否需要刷新按钮
needCheckBox: true
}
} // 表格属性
}
},
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 = ''
}
}
},
created() {
this.fetchOptions()
this.fetchData()
},
methods: {
fetchOptions() {
getDictByCode('inoutType').then(response => {
if (response.code === 200) {
this.inoutTypeList = response.data
}
})
getDictByCode('passWay').then(response => {
if (response.code === 200) {
this.passWayList = response.data
}
})
},
// 批量导出
exportFile() {
const loading = this.$loading({
lock: true,
text: '数据处理中,请稍后...',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
})
getInoutExport(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
}
getInoutListPage(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.total = parseInt(response.data.total)
this.listLoading = false
}
})
// const that = this
// setTimeout(function() {
// that.list = [
// { id: '', staffCode: '0098701', staffName: '张三', inoutType: '0', inoutTypeName: '物业人员', phone: '132********', picture: '', onDate: '2022-05-06', offDate: '2022-05-16' },
// { id: '', staffCode: '0098701', staffName: '张三', inoutType: '0', inoutTypeName: '物业人员', phone: '132********', picture: '', onDate: '2022-05-06', offDate: '2022-05-16' },
// { id: '', staffCode: '0098701', staffName: '张三', inoutType: '0', inoutTypeName: '物业人员', phone: '132********', picture: '', onDate: '2022-05-06', offDate: '2022-05-16' },
// { id: '', staffCode: '0098701', staffName: '张三', inoutType: '0', inoutTypeName: '物业人员', phone: '132********', picture: '', onDate: '2022-05-06', offDate: '2022-05-16' },
// { id: '', staffCode: '0098701', staffName: '张三', inoutType: '0', inoutTypeName: '物业人员', phone: '132********', picture: '', onDate: '2022-05-06', offDate: '2022-05-16' },
// { id: '', staffCode: '0098701', staffName: '张三', inoutType: '0', inoutTypeName: '物业人员', phone: '132********', picture: '', onDate: '2022-05-06', offDate: '2022-05-16' },
// { id: '', staffCode: '0098701', staffName: '张三', inoutType: '0', inoutTypeName: '物业人员', 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()
}
})
})
},
// 打开详情对话框
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 = {
staffKeywords: '',
doorKeywords: '',
inoutType: '',
passWay: '',
startTime: '',
endTime: '',
offset: 1,
limit: 20
}
this.fetchData()
}
}
}
</script>
<style scoped>
</style>