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

<script>
  import resize from '../../../../components/Charts/mixins/resize'
  import echarts from 'echarts'
  export default {
    mixins: [resize],
    watch: {
      wsData: {
        handler(newValue, oldValue) {
          this.draw(newValue)
        },
        deep: true
      },
    },

    props: {
      wsData:{
        type: Object
      },
      thFormat:{
        type:Array
      }
    },
    data() {
      return {
        lineColor:'',
        chart: null,
        lineStyle:[
          {
            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: 'rgb(219,50,51)',
                borderColor: 'rgba(219,50,51,0.2)',
                borderWidth: 12
              }
            },
          },
          {
            areaStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                  offset: 0,
                  color: 'rgba(219,196,50,0.3)'
                }, {
                  offset: 0.8,
                  color: 'rgba(219, 50, 51, 0)'
                }], false),
                shadowColor: 'rgba(0, 0, 0, 0.1)',
                shadowBlur: 10
              }
            },
            itemStyle: {
              normal: {
                color: 'rgb(219,196,50)',
                borderColor: 'rgba(219,196,50,0.2)',
                borderWidth: 12
              }
            },
          },
          {
            areaStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                  offset: 0,
                  color: 'rgba(101,219,50,0.3)'
                }, {
                  offset: 0.8,
                  color: 'rgba(219, 50, 51, 0)'
                }], false),
                shadowColor: 'rgba(0, 0, 0, 0.1)',
                shadowBlur: 10
              }
            },
            itemStyle: {
              normal: {
                color: 'rgb(101,219,50)',
                borderColor: 'rgba(101,219,50,0.2)',
                borderWidth: 12
              }
            },
          },
          {
            areaStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                  offset: 0,
                  color: 'rgba(50,219,171,0.3)'
                }, {
                  offset: 0.8,
                  color: 'rgba(219, 50, 51, 0)'
                }], false),
                shadowColor: 'rgba(0, 0, 0, 0.1)',
                shadowBlur: 10
              }
            },
            itemStyle: {
              normal: {
                color: 'rgb(50,219,171)',
                borderColor: 'rgba(50,219,171,0.2)',
                borderWidth: 12
              }
            },
          },
          {
            areaStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                  offset: 0,
                  color: 'rgba(50,118,219,0.3)'
                }, {
                  offset: 0.8,
                  color: 'rgba(219, 50, 51, 0)'
                }], false),
                shadowColor: 'rgba(0, 0, 0, 0.1)',
                shadowBlur: 10
              }
            },
            itemStyle: {
              normal: {
                color: 'rgb(50,118,219)',
                borderColor: 'rgba(50,118,219,0.2)',
                borderWidth: 12
              }
            },
          },
          {
            areaStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                  offset: 0,
                  color: 'rgba(140,50,219,0.3)'
                }, {
                  offset: 0.8,
                  color: 'rgba(219, 50, 51, 0)'
                }], false),
                shadowColor: 'rgba(0, 0, 0, 0.1)',
                shadowBlur: 10
              }
            },
            itemStyle: {
              normal: {
                color: 'rgb(140,50,219)',
                borderColor: 'rgba(140,50,219,0.2)',
                borderWidth: 12
              }
            },
          },
          {
            areaStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                  offset: 0,
                  color: 'rgba(202,50,219,0.3)'
                }, {
                  offset: 0.8,
                  color: 'rgba(219, 50, 51, 0)'
                }], false),
                shadowColor: 'rgba(0, 0, 0, 0.1)',
                shadowBlur: 10
              }
            },
            itemStyle: {
              normal: {
                color: 'rgb(202,50,219)',
                borderColor: 'rgba(202,50,219,0.2)',
                borderWidth: 12
              }
            },
          },
          {
            areaStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                  offset: 0,
                  color: 'rgba(50,199,219,0.3)'
                }, {
                  offset: 0.8,
                  color: 'rgba(219, 50, 51, 0)'
                }], false),
                shadowColor: 'rgba(0, 0, 0, 0.1)',
                shadowBlur: 10
              }
            },
            itemStyle: {
              normal: {
                color: 'rgb(50,199,219)',
                borderColor: 'rgba(50,199,219,0.2)',
                borderWidth: 12
              }
            },
          },
          {
            areaStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                  offset: 0,
                  color: 'rgba(219,143,50,0.3)'
                }, {
                  offset: 0.8,
                  color: 'rgba(219, 50, 51, 0)'
                }], false),
                shadowColor: 'rgba(0, 0, 0, 0.1)',
                shadowBlur: 10
              }
            },
            itemStyle: {
              normal: {
                color: 'rgb(219,143,50)',
                borderColor: 'rgba(219,143,50,0.2)',
                borderWidth: 12
              }
            },
          },
          {
            areaStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                  offset: 0,
                  color: 'rgba(255,102,255,0.3)'
                }, {
                  offset: 0.8,
                  color: 'rgba(219, 50, 51, 0)'
                }], false),
                shadowColor: 'rgba(0, 0, 0, 0.1)',
                shadowBlur: 10
              }
            },
            itemStyle: {
              normal: {
                color: 'rgb(255,102,255)',
                borderColor: 'rgba(255,102,255,0.2)',
                borderWidth: 12
              }
            },
          },// 11
          {
            areaStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                  offset: 0,
                  color: 'rgba(204,0,204,0.3)'
                }, {
                  offset: 0.8,
                  color: 'rgba(219, 50, 51, 0)'
                }], false),
                shadowColor: 'rgba(0, 0, 0, 0.1)',
                shadowBlur: 10
              }
            },
            itemStyle: {
              normal: {
                color: 'rgb(204,0,204)',
                borderColor: 'rgba(204,0,204,0.2)',
                borderWidth: 12
              }
            },
          },
          {
            areaStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                  offset: 0,
                  color: 'rgba(192,255,62,0.3)'
                }, {
                  offset: 0.8,
                  color: 'rgba(219, 50, 51, 0)'
                }], false),
                shadowColor: 'rgba(0, 0, 0, 0.1)',
                shadowBlur: 10
              }
            },
            itemStyle: {
              normal: {
                color: 'rgb(192,255,62)',
                borderColor: 'rgba(192,255,62,0.2)',
                borderWidth: 12
              }
            },
          },
          {
            areaStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                  offset: 0,
                  color: 'rgba(255,0,145,0.3)'
                }, {
                  offset: 0.8,
                  color: 'rgba(219, 50, 51, 0)'
                }], false),
                shadowColor: 'rgba(0, 0, 0, 0.1)',
                shadowBlur: 10
              }
            },
            itemStyle: {
              normal: {
                color: 'rgb(255,0,145)',
                borderColor: 'rgba(255,0,145,0.2)',
                borderWidth: 12
              }
            },
          }
        ]

      }
    },
    mounted() {
      if(sessionStorage.getItem('styleSwitch') === 'blue'){
        this.lineColor = 'white'
      }else{
        this.lineColor = '#3b3b3b'
      }
    /*  this.draw(this.radiationObj.time, this.radiationObj.data)*/
    },
    beforeDestroy() {
      if (!this.chart) {
        return
      }
      this.chart.dispose()
      this.chart = null
    },
    methods: {
      draw(wsData) {

        this.chart = echarts.init(document.getElementById('wscharts'))

        var option = {
          backgroundColor: 'transparent',
          title: {
            top: 20,
            text: '测风塔信息-风速',
            textStyle: {
              fontWeight: 'normal',
              fontSize: 16,
              color: this.lineColor
            },
            left: '1%'
          },
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              lineStyle: {
                color: '#57617B'
              }
            }
          },
          legend: {
            top: 20,
            width:'70%',
            icon: 'rect',
            itemWidth: 14,
            itemHeight: 5,
            itemGap: 13,
            data: [],
            right: '4%',
            textStyle: {
              fontSize: 12,
              color: this.lineColor
            },
            selected:{
            }
          },
          dataZoom: [{
            show: true,
            realtime: true,
            start: 0,
            end: 100,
            left: "15%",
            right: "15%",
            textStyle: {
              color: this.lineColor
            }
          }, {
            type: 'inside'
          }],
          grid: {
            top: 100,
            left: '2%',
            right: '2%',
            bottom: '10%',
            containLabel: true
          },
          xAxis: [{
            type: 'category',
            boundaryGap: false,
            axisLine: {
              lineStyle: {
                color: this.lineColor
              }
            },
            data:[]
          }],
          yAxis: [{
            type: 'value',
            name: 'm/s',
            axisTick: {
              show: false
            },
            axisLine: {
              lineStyle: {
                color: this.lineColor
              }
            },

            axisLabel: {
              margin: 10,
              textStyle: {
                fontSize: 14,
                color: this.lineColor
              },
              formatter: '{value}',
            },
            splitLine: {
              lineStyle: {
                color: '#57617B'
              }
            }
          }],
          series: []
        }
        option.xAxis[0].data = wsData.times
        var index = 0;
        for(var key in wsData.wsCharts){
          var keyName='';
          for(var i = 0 ;i<this.thFormat.length;i++){
            if(key ==this.thFormat[i].key ){
              keyName =this.thFormat[i].value;
            }
          }
          option.legend.data.push(keyName)
          if(index>3){
            option.legend.selected[keyName] = false
          }else{
            option.legend.selected[keyName] = true
          }
          var sValue = {
            name: '',
            type: 'line',
            smooth: false,
            symbol: 'circle',
            symbolSize: 5,
            showSymbol: false,
            lineStyle: {
              normal: {
                width: 2
              }
            },
            // areaStyle: {},
            itemStyle: {},
            data: []
          }
          sValue.name = keyName
          sValue.data = wsData.wsCharts[key]
          // sValue.areaStyle = this.lineStyle[index].areaStyle
          sValue.itemStyle = this.lineStyle[index].itemStyle
          option.series.push(sValue)
          index++;
        }
        this.chart.setOption(option,true)
      },

    }
  }
</script>
<style scoped>
  #wscharts {
    width: 100%;
    height: calc(85vh - 50px);
  }
</style>
