<template> <div 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" prop="keywords"> <el-input v-model.trim="listQuery.description" placeholder="背负式设备描述" clearable/> </el-form-item> <el-form-item class="selectForm-container-item" prop="keywords"> <el-input v-model.trim="listQuery.backpackCode" placeholder="背负式设备编号" clearable/> </el-form-item> <!-- <el-form-item v-if="showBackpackCode" class="selectForm-container-item" prop="backpackType">--> <!-- <el-select v-model="listQuery.backpackCode" placeholder="背负式设备编号" clearable>--> <!-- <el-option--> <!-- v-for="item in backpackCodeList"--> <!-- :key="item.value"--> <!-- :label="item.name"--> <!-- :value="item.value"/>--> <!-- </el-select>--> <!-- </el-form-item>--> <el-form-item class="selectForm-container-item"> <!-- <dept-select v-model="listQuery.deptid" :need-top="deptShowTop" dept-type="03" placeholder="使用单位"/>--> <dept-select v-model="listQuery.deptId" :dept-show="deptShow" placeholder="使用单位" clearable value=""/> </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="6"><div class="title-header"><i class="el-icon-menu"/>数据列表</div></el-col> <el-col :span="18" class="edit_btns"> <el-button v-if="hasPerm('/backpack/batchExport')" :disabled="total===0" class="edit_btn" size="small" @click="batchExport">导出记录</el-button> <!--<el-button v-if="hasPerm('/template/download')" class="edit_btn" size="small" @click="downloadTemplate">批量导入模板下载</el-button>--> <download-template v-if="hasPerm('/backpack/batchImport')" :filename="filename"/> <el-upload v-if="hasPerm('/backpack/batchImport')" :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('/well/batchBfcf')" class="edit_btn" size="small" @click="batchBf">一键布防</el-button>--> <!--<el-button v-if="hasPerm('/well/batchBfcf')" class="edit_btn" size="small" @click="batchCf">一键撤防</el-button>--> <el-button v-if="hasPerm('/backpack/delete')" class="edit_btn" size="small" @click="del">删除</el-button> <el-button v-if="hasPerm('/backpack/add')" class="edit_btn" size="small" @click="add">新增</el-button> <!--<el-button class="edit_btn" size="small" @click="batchExport">导 出</el-button>--> </el-col> </el-row> <el-table v-loading="listLoading" :data="list" class="table" border @selection-change="handleSelectionChange"> <el-table-column align="center" type="selection" width="55"/> <el-table-column :index="indexMethod" align="center" type="index"/> <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"> <el-button v-if="column.type=='Button' && scope.row.deviceCount>0" type="text" @click="goDeviceList(scope.row)">{{ scope.row[column.value] }}</el-button> <span v-else :class="column.class">{{ scope.row[column.value] }}</span> </template> </el-table-column> <!--<el-table-column v-if="hasPerm('/backpack/bfcf')" label="布撤防" align="center" width="80">--> <!--<template slot-scope="scope">--> <!--<el-button :type="btnStatus[scope.row.bfztName]" size="mini" @click="bfcf(scope.row)">{{ btnNames[scope.row.bfztName] }}</el-button>--> <!--</template>--> <!--</el-table-column>--> <el-table-column label="操作" align="center" width="160"> <template slot-scope="scope"> <el-button type="primary" size="mini" @click="detail(scope.row)">详情</el-button> <el-button v-if="hasPerm('/backpack/update')" type="text" @click="edit(scope.row)">编辑</el-button> <!-- <el-button type="text" @click="goAlarmRecords(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]" :page-size="listQuery.limit" :total="total" align="center" layout="total, sizes, prev, pager, next" @size-change="handleSizeChange" @current-change="handleCurrentChange"/> </div> <!-- <edit-backpack-info v-show="dialogFormVisible" ref="editBackpack" @watchChild="fetchData"/>--> <edit-backpack-info v-show="dialogFormVisible" ref="editBackpack" @watchChild="changeShow"/> <detail-backpack v-show="detailShow" ref="detailbackpack" @watchChild="changeShow"/> </div> </template> <script> import addBackpack from '@/views/backpackManage/addBackpack' import editBackpackInfo from '@/views/backpackManage/editBackpackInfo' import detailBackpack from '@/views/backpackManage/detailBackpack' import SelectTree from '@/components/SelectTree/singleSelect' import { getBackpackList, batchImportBackpack, batchExportBackpack, batchdelBackpack } from '@/api/backpack' import DeptSelect from '@/components/DeptSelect' import DownloadTemplate from '@/components/DownloadTemplate/index' export default { name: 'ListBackpack', components: { DownloadTemplate, SelectTree, addBackpack, detailBackpack, DeptSelect, editBackpackInfo }, data() { return { dialogFormVisible: false, deptShow: true, listQuery: { // keywords: '', description: '', backpackCode: '', deptId: '', offset: 1, limit: 20, sort: 'backpackCode', order: 'asc' }, // 筛选条件 columns: [ { text: '品牌型号', value: 'brandModel', align: 'center' }, { text: '背负式设备编号', value: 'backpackCode', align: 'center' }, { text: '负责人', value: 'chargePerson', align: 'center' }, { text: '负责人电话', value: 'chargePhone', align: 'center' }, { text: '删除标记', value: 'delflag', align: 'center' }, // { // text: '使用单位ID', // value: 'deptId', // align: 'center' // }, { text: '使用单位', value: 'deptName', align: 'center' }, { text: '背负式设备描述', value: 'description', align: 'center' }, // { // text: '设备ID', // value: 'deviceId', // align: 'center' // }, // { // text: '电量编号', // value: 'electricCode', // align: 'center' // }, // { // text: 'id', // value: 'id', // align: 'center' // }, // { // text: 'imei', // value: 'imei', // align: 'center' // }, // { // text: 'iot', // value: 'iot', // align: 'center' // }, { text: '液位编号', value: 'liquidCode', align: 'center' }, { text: '购入日期', value: 'purchaseDate', align: 'center' }, { text: '登记日期', value: 'registerDate', align: 'center' }, { text: '备注', value: 'remarks', align: 'center' }, { text: '使用人', value: 'userPerson', align: 'center' }, { text: '使用人电话', value: 'userPhone', align: 'center' } ], // 显示列 multipleSelection: [], // 多选选中项 list: [], // 列表数据 total: 0, // 数据总数 showBackpackCode: true, BackpackCodeList: null, // 背负式设备类型列表 deptProps: { parent: 'pid', value: 'id', label: 'name', children: 'children' }, // 权属单位树形下拉菜单 deptTreeList: null, // 组织树列表数据 deptShowTop: false, // 权属单位下拉是否显示顶级 listLoading: true, // 加载动画 fullscreenLoading: false, // 全屏加载动画 editShow: false, // 是否显示编辑框 detailShow: false, // 是否显示详情框 filename: 'sluicebackpack_template.xlsx', fileList: [], btnNames: { '布防': '撤防', '撤防': '布防' }, btnStatus: { '撤防': 'success', '布防': 'danger' } } }, created() { this.fetchBackpackList()// 获取背负式设备列表 this.fetchData()// 获取数据 }, activated() { console.log('activated') this.fetchData()// 获取数据 }, methods: { changeShow(){ this.dialogFormVisible =false this.detailShow=false }, // 打开详情对话框 detail(row) { const rowInfo = { data: row } this.detailShow = true this.$refs.detailbackpack.initDialog(true, rowInfo) }, checkSelection() { if (this.multipleSelection.length === 0) { return false } else { return true } }, // 新增背负式设备 add() { console.log('add') // this.$router.push({ path: 'addBackpack', query: { type: 'create' }}) this.dialogStatus = true this.dialogFormVisible = true console.log(this.$refs.editBackpack.initDialog) this.$refs.editBackpack.initDialog('create', this.dialogFormVisible) this.fetchData() }, // 编辑背负式设备信息 edit(row) { console.log('edit') // this.dialogFormVisible = true // this.editShow = true // this.$refs.editbackpack.initDialog(this.dialogFormVisible, row) this.dialogStatus = true this.dialogFormVisible = true this.$refs.editBackpack.initDialog('update', this.dialogFormVisible, row) }, // 删除背负式设备 del() { if (this.checkSelection()) { const backpackInfoIds = [] this.multipleSelection.forEach(function(value, index) { backpackInfoIds.push(value.id) }) this.$confirm( '确定要删除所选背负式设备吗?', '确认操作', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' } ).then(() => { batchdelBackpack(backpackInfoIds).then(response => { if (response.code === 200) { this.$message.success('删除成功') this.fetchData() } }) }) } else { this.$message.error('至少选中一项') } }, // 批量导入背负式设备 uploadFile(param) { console.log('uploadFile') // 判断文件大小是否符合要求 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)' }) // 发起导入请求 batchImportBackpack(_file).then(res => { loading.close() // 关闭加载动画 if (res.code === 200) { this.$message.success('导入成功') this.fileList = [] 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)' }) const _this = this const config = { // 获取下载进度 onDownloadProgress(progressEvent) { console.log(progressEvent) var percent = parseInt(100 * (progressEvent.loaded / progressEvent.total)) console.log('percent:' + percent, 'total:' + progressEvent.total) // 渲染dom _this.$nextTick(() => { _this.percent = percent }) } } batchExportBackpack(this.listQuery, config).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() }) }, // 布防撤防 // bfcf(row) { // if (row.bfzt === '1') { // // 需要撤防 // this.$confirm( // '确定要对该背负式设备进行撤防吗?', // '确认操作', // { // confirmButtonText: '确定', // cancelButtonText: '取消', // type: 'warning' // } // ).then(() => { // bfcf(row.id, '0').then(response => { // if (response.code === 200) { // this.$message.success('撤防成功') // this.fetchData() // } // }) // }) // } else { // // 需要布防 // this.$confirm( // '确定要对该背负式设备进行布防吗?', // '确认操作', // { // confirmButtonText: '确定', // cancelButtonText: '取消', // type: 'warning' // } // ).then(() => { // bfcf(row.id, '1').then(response => { // if (response.code === 200) { // this.$message.success('布防成功') // this.fetchData() // } // }) // }) // } // }, // // 批量布防 // batchBf() { // const listQuery = { // keywords: this.listQuery.keywords, // owner: this.listQuery.owner, // position: this.listQuery.position, // backpackType: this.listQuery.backpackType, // deptid: this.listQuery.deptid, // notes: this.listQuery.notes, // bfzt: '1' // } // this.$confirm( // '确定要对列表中的全部背负式设备进行布防吗?', // '确认操作', // { // confirmButtonText: '确定', // cancelButtonText: '取消', // type: 'warning' // } // ).then(() => { // batchBfcf(listQuery).then(response => { // if (response.code === 200) { // this.$message.success('布防成功') // this.fetchData() // } // }) // }) // }, // // 批量撤防 // batchCf() { // const listQuery = { // keywords: this.listQuery.keywords, // owner: this.listQuery.owner, // position: this.listQuery.position, // backpackType: this.listQuery.backpackType, // deptid: this.listQuery.deptid, // notes: this.listQuery.notes, // bfzt: '0' // } // this.$confirm( // '确定要对列表中的全部背负式设备进行撤防吗?', // '确认操作', // { // confirmButtonText: '确定', // cancelButtonText: '取消', // type: 'warning' // } // ).then(() => { // batchBfcf(listQuery).then(response => { // if (response.code === 200) { // this.$message.success('撤防成功') // this.fetchData() // } // }) // }) // }, // 查询数据 search() { this.fetchData(false) }, // 获取背负式设备数据 fetchData(isNowPage = true) { this.listLoading = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 this.listQuery.offset = 1 } getBackpackList(this.listQuery).then(response => { this.list = response.data.rows this.total = parseInt(response.data.total) this.listLoading = false console.log(this.dialogFormVisible,"====弹框") // this.dialogFormVisible=false }) }, fetchBackpackList() { getBackpackList().then(response => { this.backpackCodeList = [] const backpackCode = this.$store.getters.backpackCode for (const backpackCode of response.data) { if (backpackCode.indexOf(backpackCode.value) !== -1) { this.backpackCodeList.push(backpackCode) } } if (this.backpackCodeList.length <= 1) { this.showBackpackCode = false } }) }, // 去设备列表页 goDeviceList(row) { this.$router.push({ name: 'DeviceList', query: { backpackCode: row.backpackCode }}) }, goAlarmRecords(row) { this.$router.push({ name: 'AlarmRecords', query: { backpackCode: row.backpackCode }}) }, handleSuccess() { console.log('handleSuccess') }, 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 } } } </script> <style rel="stylesheet/scss" lang="scss" scoped> $tableTitleHeight:46px; .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>