<template> <div class="app-container"> <!--筛选条件--> <div class="search-div"> <div class="search-left"> <el-form ref="selectForm" :inline="true" :model="listQuery" class="form-container"> <el-row> <el-form-item class="selectForm-container-item"> <el-input v-model.trim="listQuery.keyword" placeholder="路灯编号/路灯名称" clearable/> </el-form-item> <el-form-item class="selectForm-container-item"> <el-input v-model.trim="listQuery.controllerCode" placeholder="控制器编号" clearable/> </el-form-item> <el-form-item class="selectForm-container-item"> <el-select v-model="listQuery.groupId" placeholder="设备组" clearable> <el-option v-for="item in groupList" :key="item.id" :label="item.groupName" :value="item.id"/> </el-select> </el-form-item> <el-button class="filter-item" type="primary" icon="el-icon-search" @click="search">搜索</el-button> <el-button class="filter-item" type="warning" icon="el-icon-delete" @click="clearInput">重置</el-button> </el-row> </el-form> </div> <div class="clearfloat"/> </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-row> <el-table v-loading="listLoading" :data="list" class="table" border> <el-table-column :index="indexMethod" label="序号" width="55" 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>{{ scope.row[column.value] }}</span> </template> </el-table-column> <el-table-column label="操作" align="center" width="130"> <template slot-scope="scope"> <!--<el-button type="text" size="small" @click="showCompare(scope.row)">生成工单</el-button>--> <el-button type="text" size="small" @click="showHistory(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> <history-data v-show="dialogFormVisible" ref="historydata"/> </div> </template> <script> import { getGroupList, getControllerData } from '@/api/report' import HistoryData from './historyData' export default { name: 'ControllerData', components: { HistoryData }, data() { return { listQuery: { keyword: '', controllerCode: '', groupId: '', offset: 1, limit: 20, sort: 'lampCode', order: 'asc' }, // 筛选条件 columns: [ { text: '路灯编号', value: 'lampCode', align: 'center' }, { text: '路灯名称', value: 'lampName', align: 'center' }, { text: '控制器编号', value: 'controllerCode', align: 'center' }, { text: '电流', value: 'latestElec', align: 'center' }, { text: '电压', value: 'latestVol', align: 'center' }, { text: '有功功率(W)', value: 'latestActivePower', align: 'center' }, { text: '无功功率(VAR)', value: 'latestReactivePower', align: 'center' }, { text: '状态', value: 'latestStatusName', align: 'center' }, { text: '最新时间', value: 'latestTime', align: 'center' } ], groupList: [], total: 0, // 数据总数 list: [], // 报警列表 listLoading: true, // 列表加载 dialogFormVisible: false, alarmReasonList: [], // 报警原因列表 timeRange: [] // 时间范围 } }, created() { this.fetchGroupList() // 获取人员标签列表 this.fetchData()// 获取数据 }, activated() { this.fetchData() }, methods: { fetchData(isNowPage = true) { this.listLoading = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 this.listQuery.offset = 1 } getControllerData(this.listQuery).then(response => { if (response.code === 200) { this.list = response.data.rows this.total = parseInt(response.data.total) } else { this.$message.error(response.message) } this.listLoading = false }) }, // 查询数据 search() { this.fetchData(false) }, showHistory(row) { this.dialogFormVisible = true this.$refs.historydata.initDialog(this.dialogFormVisible, row) }, clearInput() { this.listQuery = { keyword: '', controllerCode: '', groupId: '', offset: 1, limit: 20, sort: '', order: '' } this.timeRange = [] this.fetchData(false) }, // 获取类型列表 fetchGroupList() { getGroupList('3').then(response => { this.groupList = response.data }) }, // 序号计算 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() } } } </script> <style rel="stylesheet/scss" lang="scss" scoped> $tableTitleHeight:46px; .app-container{ margin-bottom:20px } .table{ margin-bottom: 20px; } .small-row-class{ height: 15px; } .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> <style rel="stylesheet/scss" lang="scss"> .small-row-class td{ padding:2px 0px; } </style>