
<template>
  <el-row style="background:#fff;margin-top:30px;">
    <el-col :xs="24" :sm="24" :lg="24">
      <el-card shadow="always" class="common-card-container common-card-container-body-no-padding">
        <div slot="header">
          <span class="card-title">能量流转</span>
        </div>
        <div style="height: 310px" id="nllzChart"></div>
      </el-card>
    </el-col>
  </el-row>
</template>

<script>
import * as echarts from 'echarts'
import resize from '@/mixins/ems/resize'
import {formatNumber} from "@/filters/ems";

export default {
  mixins: [resize],
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(document.querySelector('#nllzChart'))
    },
    setOption(data) {
      const {siteMonitorDataVo=[],gridNrtPower,loadNrtPower,energyStorageNrtPower,energyStorageAvailElec} = data
      const source = [['日期','充电量','放电量']]
      siteMonitorDataVo.forEach(item=>{
        source.push([item.ammeterDate, item.chargedCap,item.disChargedCap])
      })
      this.chart.setOption({
        title: [
          // 右上角
          {
            text: `电网 实时功率：${formatNumber(gridNrtPower)} kW`,
            top: 10,
            right: 10,
            textStyle:{
              fontSize:12,
              color:'#666666'
            }
          },
          // 右下角
          {
            text: `负载 实时功率：${formatNumber(loadNrtPower)} kW`,
            bottom: 10,
            right: 10,
            textStyle:{
              fontSize:12,
              color:'#666666'
            }
          },
          // 左下角第一行
          {
            text: '储能',
            bottom: 40,
            left: 10,
            textStyle:{
              fontSize:12,
              color:'#666666'
            }
          },
          // 左下角第二行
          {
            text: `实时功率：${formatNumber(energyStorageNrtPower)} kW`,
            bottom: 26,
            left: 10,
            textStyle:{
              fontSize:12,
              color:'#666666'
            }
          },
          // 左下角第三行
          {
            text: `可用电量：${formatNumber(energyStorageAvailElec)} kWh`,
            bottom: 10,
            left: 10,
            textStyle:{
              fontSize:12,
              color:'#666666'
            }
          }
        ],
        grid:{
          left:200
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: { // 坐标轴指示器，坐标轴触发有效
            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
          }
        },
        textStyle:{
          color:"#333333",
        },
        xAxis: {
          type: 'category',
          axisLine: {
            lineStyle:{
              color: '#333333',
            }
          }
        },
        yAxis: {
          type: 'value',
          axisLine: {
            lineStyle:{
              color: '#333333',
            }
          }
        },
        dataset:{
          source
          // source: [['日期','充电量','放电量']]
        },
        series: [
          {
            name:'充电量',
            type: 'line',
          },{
            name:'放电量',
            type: 'line',
          }]
      })
    }
  }
}

</script>

