<template> <div class="app-container"> <!--筛选条件--> <search-area :need-clear="false" :need-search-more="false" size="small" search-more-type="default" @search="search" > <!--一般查询条件--> <search-item> <el-input v-model.trim="listQuery.keywords" placeholder="设备编号" size="small" clearable /> </search-item> <search-item> <area-select-tree v-model="listQuery.areaId" :need-top="false" :dept-show="true" size="small" placeholder="区域" /> </search-item> <!--<search-item>--> <!--<el-date-picker--> <!--v-model="timeRange"--> <!--type="datetimerange"--> <!--range-separator="至"--> <!--value-format="yyyy-MM-dd HH:mm:ss"--> <!--start-placeholder="开始时间"--> <!--end-placeholder="结束时间"--> <!--size="small"/>--> <!--</search-item>--> </search-area> <!--查询结果Table显示--> <div style="box-sizing: border-box; padding: 0px 10px"> <el-row class="table-title"> <el-col :span="6"> <div class="title-header"> <i class="el-icon-menu" />数据列表 </div> </el-col> <el-col :span="12" :offset="6" class="edit_btns"> <el-button v-if="hasPerm('/waterMeterData/export')" 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"> <span v-if="column.checkCell" :class="checkCell(scope.row.cell)">{{ scope.row[column.value] }}</span> <span v-else-if="column.text === '设备位置'">{{ scope.row["areaFullName"] +'/' + scope.row[column.value] }}</span> <span v-else>{{ scope.row[column.value] }}</span> </template> </el-table-column> <el-table-column label="操作" align="center"> <template slot-scope="scope"> <el-button type="text" @click="line(scope.row)"> 7日曲线 </el-button> <el-button type="text" @click="openData(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="[10, 20, 30]" :page-size="listQuery.limit" :total="total" align="center" layout="total, sizes, prev, pager, next" @size-change="handleSizeChange" @current-change="handleCurrentChange" /> </div> <watch-seven-day v-show="dialogFormVisible" ref="watchsevenday" /> <water-history v-show="waterHistoryShow" ref="waterHistory"/> </div> </template> <script> import selectTree from '@/components/SelectTree/singleSelect' import { getWatchData, batchExportWaterData } from '@/api/data' import DeptSelect from '@/components/DeptSelect/index' import { parseUrl } from '@/utils/parseutils' import WatchSevenDay from './watchSevenDay' import AreaSelectTree from '@/components/AreaSelect/areaSelectTree' import WaterHistory from './waterHistory' export default { name: 'ListWaterData', components: {WaterHistory, AreaSelectTree, WatchSevenDay, DeptSelect, selectTree }, data() { return { listQuery: { areaId: '', // 关键字 keywords: '', // 关键字 // deptid: '', // 部门id // beginTime: '', // 开始时间 // endTime: '', // 结束时间 offset: 1, limit: 10, sort: '', order: '' }, // 筛选条件 timeRange: [], // 时间范围 columns: [ { text: '设备编号', value: 'devcode', align: 'center', width: 120 }, { text: '井编号', value: 'wellCode', align: 'center', width: 100 }, { text: '设备类型', value: 'deviceTypeName', align: 'center', width: 80 }, { text: '设备位置', value: 'position', align: 'center' }, { text: '抄表读数', value: 'watchNum', align: 'center', width: 80 }, { text: '采集时间', value: 'uptime', width: 170, align: 'center' }, { text: '今日用水量(立方米)', value: 'dayCount', align: 'center', width: 100 }, { text: '本月用水量(立方米)', value: 'monthCount', align: 'center', width: 100 }, { text: '总用水量(立方米)', value: 'totalCount', align: 'center', width: 80 }, { text: '状态描述', value: 'statusName', align: 'center', width: 80 } // { // text: '分区', // value: 'deptName', // align: 'center' // }, ], // 显示列 multipleSelection: [], // 多选选中项 list: [], // 列表数据 total: 0, // 数据总数 deviceTypeList: [], // 液位配置类型列表 deptProps: { parent: 'pid', value: 'id', label: 'name', children: 'children' }, // 分区树形下拉菜单 deptTreeList: null, // 组织树列表数据 showDeptTree: 0, // 是否显示分区下拉 showDeviceType: true, // 是否显示设备类型下拉 listLoading: true, // 加载动画 fullscreenLoading: false, // 全屏加载动画 dialogFormVisible: false, waterHistoryShow: false, editShow: false, // 是否显示编辑框 detailShow: false, // 是否显示编辑框 deptShowTop: false } }, watch: { timeRange(val) { if (val && val.length > 0) { this.listQuery.beginTime = val[0] this.listQuery.endTime = val[1] } else { this.listQuery.beginTime = '' this.listQuery.endTime = '' } } }, created() { // 如果路径里带参数,解析devcode参数 if (window.location.href) { const params = parseUrl(window.location.href) if (params && params.deviceType === '2' && params.devcode) { this.listQuery.keywords = params.devcode } this.fetchData() } }, activated() { // 要是路由里有参数 if (this.$route.query && this.$route.query.devcode) { this.listQuery.keywords = this.$route.query.devcode this.fetchData(false) // 获取数据 } else { this.fetchData() } }, methods: { // 批量导出 batchExport() { console.log('批量导出液位配置') // 全屏加载动画 const loading = this.$loading({ lock: true, text: '数据处理中,请稍后...', spinner: 'el-icon-loading', background: 'rgba(0, 0, 0, 0.7)' }) batchExportWaterData(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() }) }, selectnode(node) { this.listQuery.areaId = node.id this.search() }, // 查询数据 search() { this.fetchData(false) }, line(row) { this.dialogFormVisible = true this.$refs.watchsevenday.initDialog(this.dialogFormVisible, row) }, openData(row){ this.waterHistoryShow = true this.$refs.waterHistory.initDialog(this.waterHistoryShow, row) }, // 获取液位配置数据 fetchData(isNowPage = true) { this.listLoading = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 this.listQuery.offset = 1 } getWatchData(this.listQuery).then((response) => { this.list = response.data.rows.map(function(item) { item.areaFullName = item.areaFullName .replace('/', '') .replace('顶层', '') return item }) this.total = parseInt(response.data.total) this.listLoading = false }) }, checkCell(value) { var cell = parseFloat(value) if (cell < 10) { return 'warning-state' } }, 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> .app-container { padding: 0px 0px; } $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 } } .warning-state { color: red; } </style>