Newer
Older
qd_cnooc_front / src / views / dashboard / components / watchAlarmBar.vue
StephanieGitHub on 31 Mar 2022 6 KB fix<all>:更新首页统计功能,待联调
<!--水表告警统计-->
<template>
  <div class="container">
    <div class="statistic-container">
      <el-button round size="mini" @click="setDefaultTime('year')">本年</el-button>
      <el-button round size="mini" @click="setDefaultTime('season')">本季</el-button>
      <el-button round size="mini" @click="setDefaultTime('month')">本月</el-button>
      <el-button round size="mini" @click="setDefaultTime('week')">本周</el-button>
      <el-button round size="mini" @click="setDefaultTime('today')">今日</el-button>
      <el-date-picker
        v-model="timeRange"
        :picker-options="pickerOptions"
        type="daterange"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        value-format="yyyy-MM-dd"
        size="mini"
        style="width:250px;margin-right: 20px"
        @change="fetchData"/>
    </div>
    <ve-histogram v-if="isShow" :data="chartData" :grid="grid" :title="title" :extend="extend" :settings="chartSettings"/>
    <!--<div class="function">-->
      <!--<el-button-->
        <!--v-for="item in areaList"-->
        <!--:key="item.id"-->
        <!--round-->
        <!--size="mini"-->
        <!--@click="areaChange(item.id)">{{ item.name }}</el-button>-->
    <!--</div>-->
  </div>
</template>

<script>
// 引入视觉映射组件
import 'echarts/lib/component/visualMap'
import { alarmBySecondArea } from '@/api/overview'
import { getDayTime } from '@/utils/dateutils'
import { getDoorAreaTree } from '@/api/system/area'
export default {
  name: 'WatchAlarmBar',
  data() {
    return {
      title:{
        text: '水表告警统计'
      },
      chartSettings:{
        itemStyle: {
          barCategoryGap: 0
        },
        labelMap: {
          'areaName': '分区',
          'alarm': '报警数',
          'warning': '预警数'
        },
        dimension: ['areaName'],
        metrics: ['alarm', 'warning']
      },
      grid: {
        right: 40,
        top: 80,
        bottom: 5
      },
      extend: {
        legend: {
          show: false
        },
        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.setDefaultTime('today')
    // this.fetchArea()
  },
  methods: {
    // fetchArea() {
    //   getDoorAreaTree().then(response => {
    //     if (response.code === 200) {
    //       this.areaList = response.data.filter(item => {
    //         return item.pid === '1'
    //       }).map(function(item) {
    //         return {
    //           id: item.id, name: item.name
    //         }
    //       })
    //       if (this.areaList.length !== 0) { this.areaChange(this.areaList[0].id) }
    //     }
    //   })
    // },
    // areaChange(val) {
    //   this.areaId = val
    //   this.fetchData()
    // },
    fetchData() {
      const params = {
        areaId: '110000',
        startTime: this.timeRange[0],
        endTime: this.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 = maxValue+1
        }
        // this.chartData.rows = [
        //   { 'areaName': '科技楼及食堂', 'alarm': 53 },
        //   { 'areaName': 'A\\B\\C\\D\\E座', 'alarm': 78 },
        //   { 'areaName': '厂区', 'alarm': 78 },
        //   { 'areaName': '分段分区', 'alarm': 38 },
        //   { 'areaName': '船坞分区', 'alarm': 48 },
        //   { 'areaName': '刀把码头', 'alarm': 30 },
        //   { 'areaName': '制管作业区', 'alarm': 82 },
        //   { 'areaName': '滑道作业区', 'alarm': 34 },
        //   { 'areaName': '码头作业区', 'alarm': 26 },
        //   { 'areaName': '车间生产区', 'alarm': 45 }
        // ]
        this.isShow = true
      })
    },
    setDefaultTime(val) {
      if (val === 'month') {
        var today = new Date()
        var tYear = today.getFullYear()
        var tMonth = today.getMonth() + 1
        if (tMonth.toString().length === 1) {
          tMonth = '0' + tMonth
        }
        const beginTime = tYear + '-' + tMonth + '-01'
        const endTime = getDayTime(new Date().getTime())
        this.timeRange = [beginTime, endTime.Format('yyyy-MM-dd')]
      } else if (val === 'week') {
        this.timeRange = [getDayTime(new Date().getTime() - 24 * 6 * 60 * 60 * 1000).Format('yyyy-MM-dd'), getDayTime(new Date().getTime()).Format('yyyy-MM-dd')]
      } else if (val === 'yesterday') {
        this.timeRange = [getDayTime(new Date().getTime() - 24 * 60 * 60 * 1000).Format('yyyy-MM-dd'), getDayTime(new Date().getTime() - 24 * 60 * 60 * 1000).Format('yyyy-MM-dd')]
      } else if (val === 'today') {
        this.timeRange = [getDayTime(new Date().getTime()).Format('yyyy-MM-dd'), getDayTime(new Date().getTime()).Format('yyyy-MM-dd')]
      }
      this.fetchData()
    }
  }
}
</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>