<template>
  <div style="width: 100%;height: 100%">
    <div id="rpcharts"></div>
  </div>
</template>

<script>
  import resize from '../../../../components/Charts/mixins/resize'
  import echarts from 'echarts'
  import cc from '../../../curvecolors'

  export default {
    mixins: [resize],
    watch: {
      drawData: {
        handler(newValue, oldValue) {
          console.log(newValue)
          this.draw(newValue.times, newValue.forecast,newValue.iforecast,newValue.cap)
        },
        deep: true
      },
      resizeKey: function (newQuestion, oldQuestion) {
        if (this.chart != null) {
          this.chart.resize();
        }
      }
    },
    props: {
      drawData: {
        type: Object,
      },
      resizeKey: {
        type: Number
      }
    },
    data() {
      return {
        chart: null,
      }
    },
    mounted() {
    },
    beforeDestroy() {
      if (!this.chart) {
        return
      }
      this.chart.dispose()
      this.chart = null
    },
    methods: {
      draw(timeaxis, forecast,iforecast,cap) {


        this.chart = echarts.init(document.getElementById('rpcharts'))
          var option = {
          backgroundColor: 'transparent',
          title: {
            top: 20,
            text: '实际功率实时查询',
            textStyle: {
              fontWeight: 'normal',
              fontSize: 16,
              color: '#F1F1F3'
            },
            left: '1%'
          },
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              lineStyle: {
                color: '#57617B'
              }
            }
          },
          legend: {
            top: 20,
            icon: 'rect',
            itemWidth: 14,
            itemHeight: 5,
            itemGap: 13,
            data: ['修正前','修正后'],
            right: '4%',
            textStyle: {
              fontSize: 12,
              color: '#F1F1F3'
            }
          },
          dataZoom: [{
            show: true,
            realtime: true,
            start: 0,
            end: 100,
            left: "15%",
            right: "15%",
            textStyle: {
              color: "#ffffff"
            }
          }, {
            type: 'inside'
          }],
          grid: {
            top: 100,
            left: '2%',
            right: '2%',
            bottom: '10%',
            containLabel: true
          },
          xAxis: [{
            type: 'category',
            boundaryGap: false,
            axisLine: {
              lineStyle: {
                color: '#ffffff'
              }
            },
            data: timeaxis
          }],
          yAxis: [{
            type: 'value',
            name: '(MW)',
            axisTick: {
              show: false
            },
            axisLine: {
              lineStyle: {
                color: '#ffffff'
              }
            },
            axisLabel: {
              margin: 10,
              textStyle: {
                fontSize: 14
              }
            },
            splitLine: {
              lineStyle: {
                color: '#57617B'
              }
            }
          }],
          series: [{
            name: '修正前',
            type: 'line',
            smooth: false,
            symbol: 'circle',
            symbolSize: 5,
            showSymbol: false,
            lineStyle: {
              normal: {
                width: 2
              }
            },
            itemStyle: {
              normal: {
                color: cc.sj,
                borderColor: 'rgba(219,50,51,0.2)',
                borderWidth: 12
              }
            },
            data: forecast
          },
            {
              name: '修正后',
              type: 'line',
              smooth: true,
              symbol: 'circle',
              symbolSize: 5,
              showSymbol: false,
              lineStyle: {
                normal: {
                  width: 2
                }
              },
              areaStyle: {
                normal: {
                  color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                    offset: 0,
                    color: 'rgba(219, 50, 51, 0.3)'
                  }, {
                    offset: 0.8,
                    color: 'rgba(219, 50, 51, 0)'
                  }], false),
                  shadowColor: 'rgba(0, 0, 0, 0.1)',
                  shadowBlur: 10
                }
              },
              itemStyle: {
                normal: {

                  color: cc.kygl,
                  borderColor: 'rgba(219,50,51,0.2)',
                  borderWidth: 12
                }
              },
              data: iforecast
            },]
        }

        option.yAxis[0].max = cap

        this.chart.setOption(option,true)
      },
    }
  }
</script>
<style scoped>
  #rpcharts {
    width: 100%;
    height: calc(80vh - 50px);
  }
</style>
