<template> <app-container> <!--筛选条件--> <search-area size="small" @search="search"> <search-item> <el-input v-model.trim="listQuery.keywords" size="small" placeholder="设备编号/井编号" clearable /> </search-item> <search-item> <el-select v-model="listQuery.deviceType" size="small" placeholder="设备类型" clearable> <el-option v-for="item in deviceTypeList" :key="item.value" :label="item.name" :value="item.value" /> </el-select> </search-item> <search-item> <dept-select v-model="listQuery.deptid" :need-top="deptShowTop" dept-type="03" placeholder="选择权属单位" /> </search-item> <search-item v-if="isAdmin"> <el-select v-model="listQuery.isOnline" size="small" placeholder="在线情况" clearable> <el-option v-for="item in onlineStates" :key="item.value" :label="item.name" :value="item.value" /> </el-select> </search-item> </search-area> <!--查询结果Table显示--> <normal-table ref="normalTable" :data="list" :total="total" :query="listQuery" :list-loading="listLoading" :options="options" size="small" @change="changePage" @selectionChange="handleSelectionChange" > <template slot="btns"> <el-button v-if="hasPerm('/device/add')" size="small" @click="add"> 新增 </el-button> <el-button v-if="hasPerm('/device/delete')" size="small" @click="del"> 删除 </el-button> <el-upload v-if="hasPerm('/device/batchImport')" :limit="1" :show-file-list="false" :http-request="uploadFile" :file-list="fileList" action="string" accept=".xls,.xlsx" class="upload-btn" > <el-button slot="trigger" size="small"> 批量导入 </el-button> </el-upload> <download-template v-if="hasPerm('/device/batchImport')" :filename="filename" /> <el-button v-if="hasPerm('/device/batchExport')" :disabled="total===0" size="small" @click="batchExport"> 导出记录 </el-button> </template> <template slot="preColumns"> <el-table-column v-if="hasPerm('/device/delete')" align="center" type="selection" width="55" /> </template> <template slot="columns"> <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.type!='Button'" :class="column.class">{{ scope.row[column.value] }}</span> <el-button v-if="column.type=='Button'" type="text" @click="showWellDetail(scope.row)"> {{ scope.row[column.value] }} </el-button> </template> </el-table-column> <el-table-column label="操作" align="center" width="160"> <template slot-scope="scope"> <el-button type="text" size="small" @click="datalist(scope.row)"> 历史数据 </el-button> <el-button v-if="hasPerm('/device/update')" type="text" size="small" @click="edit(scope.row)"> 编辑 </el-button> <el-button type="text" size="small" @click="detail(scope.row)"> 详情 </el-button> </template> </el-table-column> </template> </normal-table> <edit-device v-show="editShow" ref="editdevice" @watchChild="fetchData" /> <detail-device v-show="detailShow" ref="detaildevice" /> <info-well v-show="wellShow" ref="wellInfo" mapid="device-map" /> </app-container> </template> <script> import editDevice from '@/views/deviceManage/editDevice' import detailDevice from '@/views/deviceManage/detailDevice' import { getDeviceList, getDeviceType, delDevice, batchImportDevice, batchExportDevice } from '@/api/device/device' import DownloadTemplate from '@/components/DownloadTemplate' import DeptSelect from '@/components/DeptSelect/index' import InfoWell from '@/views/wellManage/infoWell' import { isAdministrator, notContainConcentrator } from '@/utils/permission' export default { name: 'ListDevice', components: { DeptSelect, DownloadTemplate, editDevice, detailDevice, InfoWell }, data() { return { listQuery: { keywords: '', deviceType: '', isOnline: '', offset: 1, limit: 20, sort: 'id', order: 'asc' }, // 筛选条件 columns: [ { text: '设备编号', value: 'devcode', align: 'center' }, { text: '设备名称', value: 'deviceName', align: 'center' }, { text: '设备类型', value: 'deviceTypeName', align: 'center' }, { text: '设备位置', value: 'position', width: 140, align: 'center' }, { text: '权属单位', value: 'deptName', align: 'center' }, { text: '安装高度(m)', value: 'installHeight', width: 110, align: 'center' }, { text: '设备安装日期', value: 'installDate', width: 110, align: 'center' }, { text: '点位编号', value: 'wellCode', align: 'center', type: 'Button' }, { text: '在线状态', value: 'onlineStateName', width: 80, align: 'center' }, { text: '关联集中器编号', value: 'concenCode', width: 100, align: 'center' } ], // 显示列 multipleSelection: [], // 多选选中项 list: [], // 列表数据 total: 0, // 数据总数 deviceTypeList: [], // 设备类型列表 deptProps: { parent: 'pid', value: 'id', label: 'name', children: 'children' }, // 权属单位树形下拉菜单 deptTreeList: null, // 组织树列表数据 showDeptTree: 0, // 是否显示权属单位下拉 showDeviceType: true, // 是否显示设备类型下拉 fileList: [], listLoading: true, // 加载动画 fullscreenLoading: false, // 全屏加载动画 editShow: false, // 是否显示编辑框 detailShow: false, // 是否显示编辑框 filename: 'device_template.xlsx', deptShowTop: false, // 是否显示顶级 onlineStates: [ { value: '1', name: '在线' }, { value: '0', name: '离线' } ], // 在线情况 options: { needIndex: true, // 是否需要序号列 border: true // 是否需要上方边框 }, wellShow: false } }, computed: { isAdmin() { return isAdministrator() } }, mounted() { this.fetchDeviceType()// 获取设备列表 if (!notContainConcentrator()) { this.columns.splice(-1, 1) } if(this.$route.query.status === 'offline') { this.listQuery.isOnline = '0' } // 如果参数中有井编号,则将查询条件填入,否则正常 if (this.$route.query && this.$route.query.wellCode && this.$route.query.wellCode !== '') { this.listQuery.keywords = this.$route.query.wellCode this.fetchData(true) } else { this.fetchData()// 获取数据 } }, methods: { // 检查选择情况 checkSelection() { if (this.multipleSelection.length === 0) { return false } else { return true } }, // 新增设备 add() { this.dialogFormVisible = true this.editShow = true this.$refs.editdevice.initDialog('create') }, // 编辑设备信息 edit(row) { this.dialogFormVisible = true this.editShow = true this.$refs.editdevice.initDialog('update', row) }, detail(row) { this.$refs.detaildevice.initDialog('detail', row) }, // 删除设备 del() { if (this.checkSelection()) { const deviceIds = [] this.multipleSelection.forEach(function(value, index) { deviceIds.push(value.id) }) let minusOnePage = false if (deviceIds.length === this.list.length) { minusOnePage = true } this.$confirm( '确定要删除所选设备吗?', '确认操作', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' } ).then(() => { delDevice(deviceIds).then(response => { if (response.code === 200) { this.$message.success('删除成功') if (minusOnePage) { this.listQuery.offset = this.listQuery.offset > 1 ? this.listQuery.offset - 1 : 1 } 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)' }) // 发起导入请求 batchImportDevice(_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)' }) batchExportDevice(this.listQuery).then(res => { loading.close() // 关闭加载动画 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() }) }, // 查询数据 search() { this.fetchData(false) }, // 获取集中器数据 fetchData(isNowPage = true) { this.listLoading = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 this.listQuery.offset = 1 } getDeviceList(this.listQuery).then(response => { this.list = response.data.rows this.total = parseInt(response.data.total) this.listLoading = false }) }, // 获取设备类型 fetchDeviceType() { getDeviceType(this.listQuery).then(response => { this.deviceTypeList = [] // 过滤掉该单位不支持的设备类型 const deviceTypes = this.$store.getters.deviceTypes for (const deviceType of response.data) { if (deviceTypes.indexOf(deviceType.value) !== -1) { this.deviceTypeList.push(deviceType) } } if (deviceTypes.indexOf('2') === -1) { // 如果包含不包含 const index = this.columns.findIndex(item => item.value === 'installHeight') this.columns.splice(index, 1) } if (this.deviceTypeList.length <= 1) { this.showDeviceType = false } }) }, datalist(row) { const params = { devcode: row.devcode, deviceType: row.deviceType } this.$router.push({ name: 'DataManage', query: params }) }, showWellDetail(row) { this.wellShow = true this.$refs.wellInfo.initDialog(row.wellId) }, // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 changePage(val) { if (val && val.size) { this.listQuery.limit = val.size } if (val && val.page) { this.listQuery.offset = val.page } this.fetchData() }, // 多选触发方法 handleSelectionChange(val) { this.multipleSelection = val } } } </script> <style rel="stylesheet/scss" lang="scss" scoped> </style>