<template>
  <ve-histogram
    :data="chartData"
    :grid="grid"
    :extend="extend"
    :settings="chartSettings"
  />
</template>

<script>
import { alarmStaticsByContent } from '@/api/data/dataStatics'
export default {
  name: 'AlarmStaticsByType',
  props: {
    timeRange: {
      type: Array,
      default: () => []
    } // 查询时间范围
  },
  data() {
    return {
      listQuery: {
        beginTime: '',
        endTime: '',
        alarmType: '1'
      },
      // 柱状图
      extend: {
        xAxis: {
          axisLabel: {
            rotate: 30,
            margin: 30,
            textStyle: {
              align: 'center'
            }
          }
        },
        series: {
          label: { show: true, position: 'top' },
          barMaxWidth: 35 // 最大柱宽度
        }
      },
      grid: {
        right: 60
      },
      chartSettings: {
        itemStyle: {
          'barCategoryGap': 5
        },
        barWidth: 15,
        labelMap: {
          'alarmContent': '报警内容',
          'alarmCount': '报警数量'
        },
        dimension: ['alarmContent'],
        metrics: ['alarmCount']
      },
      chartData: {
        columns: ['alarmContent', 'alarmCount'],
        rows: []
      }
    }
  },
  watch: {
    timeRange() {
      this.fetchData()
    }
  },
  methods: {
    fetchData() {
      this.handleDateTime()
      alarmStaticsByContent(this.listQuery).then(response => {
        this.chartData.rows = response.data
      })
    },
    // 处理时间
    handleDateTime() {
      if (this.timeRange && this.timeRange.length > 0) {
        this.listQuery.beginTime = this.timeRange[0]
        this.listQuery.endTime = this.timeRange[1]
      } else {
        this.listQuery.beginTime = ''
        this.listQuery.endTime = ''
      }
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.flagBoxStyle {
  display: flex;
  margin-bottom: 20px;
}
.flagBoxStyle div:nth-child(2){
  line-height: 30px;
  font-weight: 600;
}
.flagStyle {
  width: 4px;
  height: 30px;
  margin-right: 6px;
  background: rgb(64 121 242);
}
.cardStyle {
  display:flex;
  margin-bottom: 60px;
  justify-content: space-around;
}
.ttileStyle {
  font-size: 12px;
}
.countStyle {
  font-size: 20px;
  margin: 0 10px;
}
.el-date-editor--datetimerange.el-input,
.el-date-editor--datetimerange.el-input__inner{
  width: 340px;
}
</style>
