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

<script>
  import resize from '../../../../components/Charts/mixins/resize'
  import echarts from 'echarts'
  import {mapState} from 'vuex'
  export default {
    mixins: [resize],
    watch: {
      otherObj: {
        handler(newValue, oldValue) {
          this.draw(newValue.time, newValue.data)

        },
        deep: true
      }
    },
    computed: {
      ...mapState({
        otherObj: 'otherObj',
      })
    },
    data() {
      return {
        lineColor:'',
        chart: null,
      }
    },
    mounted() {
      if(sessionStorage.getItem('styleSwitch') === 'blue'){
        this.lineColor = 'white'
      }else{
        this.lineColor = '#3b3b3b'
      }
      this.draw(this.otherObj.time, this.otherObj.data)
    },
    beforeDestroy() {
      if (!this.chart) {
        return
      }
      this.chart.dispose()
      this.chart = null
    },
    methods: {
      draw(timeaxis, otherData) {
        var ws = []
        var wd = []
        if(otherData !=null){
          if(otherData.wss !=null){
            ws = otherData.wss
          }
          if(otherData.wds !=null){
            wd = otherData.wds
          }
        }
        this.chart = echarts.init(document.getElementById('wsAndWd'))

        this.chart.setOption({
          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,
            icon: 'rect',
            itemWidth: 14,
            itemHeight: 5,
            itemGap: 13,
            data: ['风速', '风向'],
            right: '4%',
            textStyle: {
              fontSize: 12,
              color: this.lineColor
            },
            selected:{
              '风速':true,
              '风向':true
            }
          },
          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: timeaxis
          }],
          yAxis: [{
            type: 'value',
            name: 'm/s',
            axisTick: {
              show: false
            },
            axisLine: {
              lineStyle: {
                color: this.lineColor
              }
            },
            axisLabel: {
              margin: 10,
              textStyle: {
                fontSize: 14
              }
            },
            splitLine: {
              lineStyle: {
                color: '#57617B'
              }
            }
          },
            {
              type: 'value',
              name: '°',
              axisTick: {
                show: false
              },
              axisLine: {
                lineStyle: {
                  color: '#57617B'
                }
              },
              axisLabel: {
                margin: 10,
                textStyle: {
                  fontSize: 14
                }
              },
              splitLine: {
                lineStyle: {
                  color: '#57617B'
                }
              }
            }
          ],
          series: [{
            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(113,27,189,0.3)'
            //     }, {
            //       offset: 0.8,
            //       color: 'rgba(137, 189, 27, 0)'
            //     }], false),
            //     shadowColor: 'rgba(0, 0, 0, 0.1)',
            //     shadowBlur: 10
            //   }
            // },
            itemStyle: {
              normal: {
                color: 'rgb(122,27,189)',
                borderColor: 'rgba(74,2,189,0.27)',
                borderWidth: 12

              }
            },
            data: ws
          },

            {
              name: '风向',
              type: 'line',
              yAxisIndex: 1,
              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(137, 189, 27, 0.3)'
              //     }, {
              //       offset: 0.8,
              //       color: 'rgba(137, 189, 27, 0)'
              //     }], false),
              //     shadowColor: 'rgba(0, 0, 0, 0.1)',
              //     shadowBlur: 10
              //   }
              // },
              itemStyle: {
                normal: {
                  color: 'rgb(137,189,27)',
                  borderColor: 'rgba(137,189,2,0.27)',
                  borderWidth: 12

                }
              },
              data: wd
            },




          ]
        })

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

</style>
