index.vue 8.75 KB
<!-- 系统监控 -->
<template>
  <d2-container class="systemMonitor">
    <div class="echarts">
      <el-row>
        <el-col :span="24">
          <span style="margin-right: 20px;">子系统类型</span>
          <el-radio-group v-model="subSystemRadio" @change="radioChange">
            <el-radio-button
              v-for="(item, index) in systemTypeArr"
              :key="index"
              :label="item.label"
            >
            </el-radio-button>
          </el-radio-group>
        </el-col>
        <el-col :span="24">
          <div id="totalEcharts" style="width: 100%; height: 400px;"></div>
        </el-col>
      </el-row>
    </div>
    <div>
      <el-form
        :inline="true"
        :model="searchForm"
        label-width="100px"
      >
        <el-form-item label="车辆编号">
          <el-input v-model="searchForm.trafficCode" placeholder="请输入车辆编号" clearable></el-input>
        </el-form-item>
        <el-form-item label="归属车辆段">
          <el-select v-model="searchForm.stationCode" placeholder="请选择归属车辆段" filterable clearable>
            <el-option
              v-for="(item,index) in stationCodeArr"
              :key="index"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="车辆状态">
          <el-select v-model="searchForm.openType" placeholder="请选择车辆状态" filterable clearable>
            <el-option value="1" label="是"></el-option>
            <el-option value="2" label="否"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="子系统编号">
          <el-input v-model="searchForm.subsystemCode" placeholder="请输入子系统编号" clearable></el-input>
        </el-form-item>
        <el-form-item label="子系统状态">
          <el-select v-model="searchForm.onlineStatus" placeholder="请选择子系统状态" filterable clearable>
            <el-option value="1" label="在网"></el-option>
            <el-option value="2" label="离网"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleSearch">查询</el-button>
        </el-form-item>
      </el-form>
      <el-row style="height: 40px; line-height: 40px">
        <el-col :span="12">车辆状态列表</el-col>
        <el-col :span="12" style="text-align: right">
            <el-button>导出</el-button>
        </el-col>
    </el-row>
      <el-table
        :data="tableData"
        v-loading="tableLoading"
        border
        style="margin: 20px 0;"
      >
      <el-table-column
        align="center"
        width="60px"
        label="序号"
        type='index'
      ></el-table-column>
      <el-table-column
        v-for="(item, index) in tableColumns"
        :key="index"
        :label="item.label"
        :prop="item.prop"
        :width="item.width"
        align="center"
      >
         <template v-if="item.prop" slot-scope="scope">
           <template v-if="item.prop == 'onlineStatus'">
             <el-tag v-if="tableData[scope.$index][item.prop] == '在网'" type="success" size="medium">{{ tableData[scope.$index][item.prop] }}</el-tag>
             <el-tag v-else type="info" size="medium">{{ tableData[scope.$index][item.prop] }}</el-tag>
           </template>
           <template v-else>
              {{tableData[scope.$index][item.prop]}}
           </template>
         </template>
      </el-table-column>
      </el-table>
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10,20,30,40]"
        :page-size="pageSize"
        :total="total"
        layout="sizes,total,->,prev,pager,next,jumper"
      >
      </el-pagination>
    </div>
  </d2-container>
</template>

<script>
import { request, sysMonitorMethods } from '@api/request'
import notice from '@/common/notice'
export default {
  name: 'systemMonitor',
  data () {
    return {
      subSystemRadio: '全部',
      systemTypeArr: [{
        label: '全部',
        value: '1'
      }, {
        label: '座椅',
        value: '2'
      }],
      // 绘图
      totalECharts: '',
      totalOptions: {
        title: [{
          text: '在网情况',
          x: '25%',
          textAlign: 'center'
        }, {
          text: '故障情况',
          x: '75%',
          textAlign: 'center'
        }],
        tooltip: {},
        series: [{
          name: '在网情况',
          type: 'pie',
          radius: '55%',
          center: ['25%', '50%'],
          label: {
            normal: {
              fontSize: 16
            }
          },
          data: [{
            name: '在网',
            value: 0,
            itemStyle: {
              color: '#18a689'
            }
          }, {
            name: '离网',
            value: 0,
            itemStyle: {
              color: '#999999'
            },
            selected: true
          }]
        }, {
          name: '故障情况',
          type: 'pie',
          radius: ['20%', '55%'],
          center: ['75%', '50%'],
          label: {
            normal: {
              fontSize: 16
            }
          },
          data: [{
            name: '正常',
            value: 0,
            itemStyle: {
              color: '#99cc66'
            }
          }, {
            name: '故障',
            value: 0,
            itemStyle: {
              color: '#ff0000'
            },
            selected: true
          }]
        }]
      },
      // 搜索
      searchForm: {
        trafficCode: '',
        stationCode: '',
        openType: '',
        subsystemCode: '',
        onlineStatus: ''
      },
      stationCodeArr: [{
        label: '归属1',
        value: '1'
      }, {
        label: '归属2',
        value: '2'
      }],
      // 表格
      tableData: [],
      tableLoading: false,
      tableColumns: [{
        label: '子系统编号',
        prop: 'subsystemCode'
      }, {
        label: '子系统类型',
        prop: 'subSystemType'
      }, {
        label: '子系统状态',
        prop: 'onlineStatus'
      }, {
        label: '车辆编号',
        prop: 'trafficCode'
      }, {
        label: '归属车辆段',
        prop: 'stationCode'
      }, {
        label: '故障内容',
        prop: 'downDescription'
      }],
      // 翻页
      currentPage: 1,
      pageSize: 10,
      total: 20
    }
  },

  mounted () {
    // this.drawPie()
    this.loadingGetList()
    this.totalECharts = this.$echarts.init(document.getElementById('totalEcharts'))
    this.getPie()
  },

  methods: {
    loadingGetList() {
      this.tableLoading = true
      this.getList()
    },
    /* 接口请求-start */
    getParams() {
      return {
        pageCount: this.pageSize,
        pageSize: this.currentPage,
        ...this.searchForm
      }
    },
    getList() {
      const params = this.getParams()
      params.method = sysMonitorMethods.Search
      request(params).then(res => {
        this.tableData = res
        this.tableLoading = false
      }).catch(err => {
        notice.errorTips(err)
        this.tableLoading = false
      })
    },
    getPie(systemTypeId = 1) {
      const params = {
        method: sysMonitorMethods.Report,
        systemTypeId: systemTypeId
      }
      // console.log(params)
      request(params).then(res => {
        this.drawPie(res)
      }).catch(err => {
        notice.errorTips(err)
      })
    },
    /* 接口请求-end */
    /* onlineNum	Int	在网数量
       offlineNum	int	离网数量
       normalNum	Int	正常数量
       breakdownNum	Int	故障数量 */
    drawPie (params) {
      this.totalOptions.series[0].data[0].value = params.onlineNum
      this.totalOptions.series[0].data[1].value = params.offlineNum

      this.totalOptions.series[1].data[0].value = params.normalNum
      this.totalOptions.series[1].data[1].value = params.breakdownNum

      this.totalECharts.setOption(this.totalOptions)
    },

    radioChange (label) {
      // console.log(label)
      // 请求后端数据--参数
      var value = ''
      for (var i in this.systemTypeArr) {
        if (this.systemTypeArr[i].label === label) {
          value = this.systemTypeArr[i].value
          break
        }
      }
      // 调接口
      this.getPie(value)
    },

    // 搜索
    handleSearch () {
      console.log(this.searchForm)
      // 调接口
      this.loadingGetList()
    },

    // 页码
    handleSizeChange (value) {
      this.pageSize = value
      // 调接口
      this.loadingGetList()
    },

    handleCurrentChange (value) {
      this.currentPage = value
      // 调接口
      this.loadingGetList()
    }
  }
}

</script>
<style>
</style>