index.vue 6.92 KB
<!-- 系统监控 -->
<template>
  <d2-container class="systemMonitor">
    <div class="echarts">
      <el-row>
        <el-col :span="24">
          <span style="margin-right: 20px;color:#909399"><d2-el-icon name="s-data"/> 子系统类型</span>
          <el-radio-group v-model="subSystemRadio" @change="getPie">
            <el-radio-button
              v-for="(item, index) in baseData.subsys"
              :key="index"
              :value="item.confCode"
              :label="item.confValue"
            >
            </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 baseData.station"
              :key="index"
              :value="item.confCode"
              :label="item.confValue"
            ></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"  icon="el-icon-search" :id="tableParams.btnId">查询</el-button>
        </el-form-item>
      </el-form>
      <d2-table-header title="子系统状态列表"><auth-button category="Button"></auth-button></d2-table-header>
      <d2-table
        :searchForm="searchForm"
        :tableParams="tableParams"
        :getListApi="getListApi"
      ></d2-table>
    </div>
  </d2-container>
</template>

<script>
import { getListApi, reportApi, exportApi } from '@api/systemMonitor'
import notice from '@/common/notice'
import { mapActions } from 'vuex'
export default {
  name: 'index',
  data() {
    return {
      subSystemRadio: '全部',
      // 绘图
      totalECharts: '',
      totalOptions: {
        title: [{
          text: '在网情况',
          x: '24.5%',
          y: '8%',
          textAlign: 'center'
        }, {
          text: '故障情况',
          x: '74.5%',
          y: '8%',
          textAlign: 'center'
        }],
        tooltip: {},
        series: [{
          name: '在网情况',
          type: 'pie',
          radius: ['35%', '55%'],
          center: ['25%', '50%'],
          label: {
            normal: {
              fontSize: 16,
              formatter: '{b}: {c}'
            }
          },
          data: [{
            name: '在网',
            value: 0,
            itemStyle: {
              color: '#00b639'
            }
          }, {
            name: '离网',
            value: 0,
            itemStyle: {
              color: '#999999'
            }
            // selected: true
          }]
        }, {
          name: '故障情况',
          type: 'pie',
          radius: ['35%', '55%'],
          center: ['75%', '50%'],
          label: {
            normal: {
              fontSize: 16,
              formatter: '{b}: {c}'
            }
          },
          data: [{
            name: '故障',
            value: 0,
            itemStyle: {
              color: '#e45b4e'
            }
            // selected: true
          }, {
            name: '正常',
            value: 0,
            itemStyle: {
              color: '#479ae8'
            }
          }]
        }]
      },
      // 搜索
      searchForm: {
        trafficCode: '',
        stationCode: '',
        subsystemCode: '',
        onlineStatus: ''
      },
      // 表格
      // tableData: [],
      // 表格参数
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'subsystemList',
        tag: Object.freeze({
          type: ['', 'success', 'info'],
          label: ['', '在网', '离网']
        }),
        tableColumns: [{
          label: '子系统编号',
          prop: 'subsystemCode',
          width: '160'
        }, {
          label: '子系统类型',
          prop: 'subsystemType',
          width: '120'
        }, {
          label: '子系统状态',
          prop: 'onlineStatus',
          width: '160',
          tagLabel: true
        }, {
          label: '车辆编号',
          prop: 'trafficCode',
          width: '120'
        }, {
          label: '归属车辆段',
          prop: 'stationName'
        }, {
          label: '故障内容',
          prop: 'errorCode'
        }]
      },
      baseData: {
        station: [],
        subsys: []
      },
      getListApi: getListApi
    }
  },

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

  methods: {
    ...mapActions('d2admin/base', ['load']),

    async loadBaseData() {
      // this.baseData.station = await this.$store.dispatch('d2admin/base/get', BaseData.STATION.KEY)
      const { station, subsys } = await this.load()
      this.baseData.station = _.cloneDeep(station)
      this.baseData.subsys = _.cloneDeep(subsys)
      this.baseData.subsys.unshift({ confCode: '', confValue: '全部' })
    },

    getPie(label = '') {
      const params = {
        subsystemTypeCode: label ? this.baseData.subsys.find(item => item.confValue === label).confCode : ''
      }
      reportApi(params).then(res => {
        this.drawPie(res)
      }).catch(() => {
        notice.errorTips()
      })
    },
    exportFile() {
      exportApi(this.searchForm).then(res => {
        this.$open(res.url)
        notice.okTips()
      }).catch(() => {
        notice.errorTips()
      })
    },
    /* 接口请求-end */
    // onlineNum 在网数量
    // offlineNum 离网数量
    // normalNum 正常数量
    // breakdownNum 故障数量
    drawPie(params) {
      let item = this.totalOptions.series[0]
      item.data[0].value = params.onlineNum ? params.onlineNum : 0
      item.data[1].value = params.offlineNum ? params.offlineNum : 0

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

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

</script>
<style>
</style>