index.vue 11 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 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="请输入车辆编号" @clear="loadingGetList" clearable></el-input>
        </el-form-item>
        <el-form-item label="归属车辆段">
          <el-select v-model="searchForm.stationCode" placeholder="请选择归属车辆段" @clear="loadingGetList" filterable clearable>
            <!-- <el-option
              v-for="(item,index) in stationCodeArr"
              :key="index"
              :label="item.label"
              :value="item.value"
            ></el-option> -->
            <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-select v-model="searchForm.openType" placeholder="请选择车辆状态" @clear="loadingGetList" 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="请输入子系统编号" @clear="loadingGetList" clearable></el-input>
        </el-form-item>
        <el-form-item label="子系统状态">
          <el-select v-model="searchForm.onlineStatus" placeholder="请选择子系统状态" @clear="loadingGetList" 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" @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">
            <auth-button category="Button"></auth-button>
            <!-- <auth-button label="导出" type="Button" @e-auth-click="exportFile"></auth-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] == '1'" type="success" size="medium">在网</el-tag>
             <el-tag v-else type="info" size="medium">离网</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 { getListApi, reportApi, exportApi } from '@api/systemMonitor'
import notice from '@/common/notice'
import { mapActions } from 'vuex'
import { cloneDeep } from 'lodash'
// import { BaseData } from '@/common/constants'
// require('echarts/lib/chart/pie')
// require('echarts/lib/component/tooltip')

// let echarts = require('echarts/lib/echarts')

export default {
  name: 'index',
  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: ['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: '#479ae8'
            }
          }, {
            name: '故障',
            value: 0,
            itemStyle: {
              color: '#e45b4e'
            }
            // 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: 'errorCode'
      }],
      // 翻页
      currentPage: 1,
      pageSize: 10,
      total: 20,
      baseData: {
        station: [],
        subsys: []
      },
      href: ''
    }
  },

  mounted () {
    this.$echarts = echarts
    this.loadingGetList()
    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: '全部' })
      // console.log(this.baseData)
    },

    loadingGetList () {
      this.tableLoading = true
      this.getList()
    },
    /* 接口请求-start */
    getParams () {
      return {
        pageCount: this.pageSize,
        pageSize: this.currentPage,
        ...this.searchForm
      }
    },
    getList () {
      const params = this.getParams()
      getListApi(params).then(res => {
        this.tableData = res.subsystemList
        this.total = res.pagination.totalCount
        this.tableLoading = false
      }).catch(() => {
        notice.errorTips()
        this.tableLoading = false
      })
    },
    getPie (subsystemTypeCode = '') {
      const params = {
        subsystemTypeCode: subsystemTypeCode
      }
      // console.log(params)
      reportApi(params).then(res => {
        this.drawPie(res)
      }).catch(() => {
        notice.errorTips()
      })
    },
    exportFile () {
      const params = this.getParams()
      exportApi(params).then(res => {
        // console.log(res)
        // this.href = 'https://web.stanford.edu/~xgzhou/zhou_book2017.pdf'
        // window.location.href = res.url
        this.$open(res.url)
        notice.okTips()
        // window.open(res.url, '_black')
        // window.location.href = 'https://web.stanford.edu/~xgzhou/zhou_book2017.pdf'
        // let url = window.URL.createObjectURL(new Blob(['https://web.stanford.edu/~xgzhou/zhou_book2017.pdf']))
        // let link = document.createElement('a')
        // link.style.display = 'none'
        // link.href = url
        // link.setAttribute('download', 'excel.xlsx')

        // document.body.appendChild(link)
        // link.click()
      }).catch(() => {
        notice.errorTips()
      })
    },
    /* 接口请求-end */
    // onlineNum 在网数量
    // offlineNum 离网数量
    // normalNum 正常数量
    // breakdownNum 故障数量
    drawPie (params) {
      this.totalOptions.series[0].data[0].value = params.onlineNum ? params.onlineNum : 0
      this.totalOptions.series[0].data[1].value = params.offlineNum ? params.offlineNum : 0

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

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

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

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

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

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

</script>
<style>
</style>