Newer
Older
qd_cnooc_front / src / views / gasDashboard / components / watchGasAlarmBar.vue
yuexiaosheng on 2 Jun 2022 3 KB fix<main>:修改动力管网首页
<template>
  <div class="container">
    <function-area ref="func" select="week" @change="fetchData"/>
    <ve-histogram v-if="isShow" :data="chartData" :grid="grid" :title="title" :extend="extend" :settings="chartSettings"/>
  </div>
</template>

<script>
// 引入视觉映射组件
import 'echarts/lib/component/visualMap'
import { alarmBySecondArea } from '@/api/gasOverview'
import functionArea from './FunctionArea'
export default {
  name: 'WatchGasAlarmBar',
  components: { functionArea },
  data() {
    return {
      title: {
        text: '燃气告警统计'
      },
      chartSettings: {
        itemStyle: {
          barCategoryGap: 0
        },
        labelMap: {
          'areaName': '分区',
          'alarm': '报警数'
        },
        dimension: ['areaName'],
        metrics: ['alarm']
      },
      grid: {
        right: 40,
        top: 80,
        bottom: 5
      },
      extend: {
        legend: {
          show: true
        },
        xAxis: {
          axisLabel: {
            rotate: 30,
            margin: 30,
            textStyle: {
              align: 'center'
            }
          }
        },
        yAxis: {
          name: '报警次数',
          position: 'left',
          max: 10
        },
        series: {
          label: { show: true, position: 'top', formatter: '{c}' },
          barWidth: 20
        }
        // tooltip: { trigger: 'item', formatter: '{b}<br/>报警次数:{c}次' }
      },
      areaId: '',
      areaList: [],
      isShow: true,
      defaultTimeRange: [],
      timeRange: [],
      pickerOptions: {
        disabledDate: function(date) {
          var oDate1 = new Date(date)
          var oDate2 = new Date()
          if (oDate1.getTime() > oDate2.getTime()) {
            return true
          } else {
            return false
          }
        }
      },
      chartData: {
        columns: ['areaName', 'alarm'],
        rows: []
      }
    }
  },
  mounted() {
    this.$refs.func.init()
    // this.setDefaultTime('today')
    // this.fetchArea()
  },
  methods: {
    fetchData(timeRange) {
      const params = {
        areaId: '110000',
        startTime: timeRange[0],
        endTime: timeRange[1]
      }
      this.$emit('change', params)
      alarmBySecondArea(params).then(response => {
        this.isShow = false
        this.chartData.rows = response.data
        const maxValue = Math.max.apply(Math, response.data.map(item => { return item.alarm > item.warning ? item.alarm : item.warning }))
        if (maxValue < 10) {
          this.extend.yAxis.max = 10
        } else {
          this.extend.yAxis.max = maxValue + 1
        }
        this.isShow = true
      })
    }
  }
}
</script>
<style lang="scss" scoped>
  .container{
    position:relative;
    .function{
      width:calc(100% - 120px);
      height: 28px;
      display: flex;
      justify-content: center;
    }
  }
  .statistic-container {

    .el-button{
      padding: 5px 10px;
    }
    margin-bottom: 10px;
    text-align: center;
    .chart-tool-button {
      padding: 5px;
      line-height: 16px;
      margin-top: 5px;
      font-size: 14px;
    }
    .chart-tool-button:hover {
      background-color: #8cc5ff;
      cursor: pointer;
      color: white;
    }
    .chart-tool-button:active {
      background-color: #8cc5ff;
      color: white;
    }
  }
  .selected {
    background-color: #8cc5ff;
    color: white;
  }
</style>