<script>
import apiSecurityAlarmMgr from "@/api/security/apiSecurityAlarmMgr";

export default {
  data() {
    return {
      option: {
        legend: {
          data: [
            '摄像头',
            '水浸设备',
          ]
        },
        grid: {
          left: '0%', //默认10%
          right: '1%', //默认10%
          bottom: '18%', //默认60
          top: '15%',
          containLabel: true
          //grid区域是否包含坐标轴的刻度标签
        },
        xAxis: {
          data: []
        },
        yAxis: [
          {
            type: 'value',
            min: 0,
            max: 100,
            nameTextStyle: {
              padding: [10, 0, 10, -12]
            },
            axisLabel: {
              show: true,
              formatter: '{value}%'
            }
          },
        ],
        dataZoom: [
          {
            type: 'slider',
            start: 0,
            end: 100,
            height: 12,
          },
          {
            type: 'inside',
            start: 0,
            end: 100,
          }
        ],
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          },
          textStyle: {
            color: '#fff',
            align: 'left',
            fontSize: 14
          },
          axisLine: {//x坐标轴轴线
            show: true,
            lineStyle: {//x坐标轴轴线样式
              color: '#000',//'#ccc' | 'rgb(128, 128, 128)' | 'rgba(128, 128, 128, 0.5)'，设置标签颜色
            }
          },
          backgroundColor: 'rgba(0,0,0,0.8)',
        },
        series: [
          {
            name: '摄像头',
            data: [],
            type: 'line',
            smooth: true,
            //areaStyle: {
            //  color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [{
            //    offset: 0,
            //    color: '#A6C9FF' // 0% 处的颜色
            //  }, {
            //    offset: 0.8,
            //    color: '#ffffff' // 100% 处的颜色
            //  }], false),
            //},
            lineStyle: {
              color: "#5A9BFE",
              width: 1,
            },
            emphasis: {
              scale:1.5
            }
          },
          {
            name: '水浸设备',
            data: [],
            type: 'line',
            smooth: true,
            //areaStyle: {
            //  color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [{
            //    offset: 0,
            //    color: '#B0E5CB' // 0% 处的颜色
            //  }, {
            //    offset: 0.8,
            //    color: '#ffffff' // 100% 处的颜色
            //  }], false),
            //},
            lineStyle: {
              color: "#62CC97",
              width: 1,
            },
            emphasis: {
              scale:1.5
            },
          }
        ]
      },
    }
  },
  props: {
    height: Number,
    queryData: Object
  },
  mounted() {
    this.$nextTick(()=>{
      this.init()
    })
  },
  methods: {
    init() {
      let chart = this.$echarts.init(this.$refs.myChart)
      this.chart = chart;
      this.$util.chartsResize(this.chart);
      chart.setOption(this.option)
      this.getData()
    },
    getData() {
      return apiSecurityAlarmMgr.getEquipmentOnline(this.queryData).then(res=>{
        let data = this.$util.dataUtil.covertDataToEcharts(res, ['camera','waterImmersion'])
        this.$util.dataUtil.refreshEchartsData(this.chart, this.option, data)
      })
    }
  }
}
</script>

<template>
  <div style="width: 100%" :style="{height: height+'px'}" ref="myChart"></div>
</template>

<style lang="less" scoped>

</style>