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

<script>
  import resize from '../../../../components/Charts/mixins/resize'
  import echarts from 'echarts'
  import {mapState} from 'vuex'

  export default {
    mixins: [resize],
    watch: {
      wdData: {
        handler(newValue, oldValue) {
          this.draw(newValue)
        },
        deep: true
      }
    },
    props: {
      wdData:{
        type: Object
      },
      wd70:{
        type: String
      },
      wd50:{
        type: String
      },
      thFormat:{
        type:Array
      }
    },
    data() {
      return {
        chart: null,
        lineColor:'',
        itemStyle:[
          {
            itemStyle: {
              normal: {
                lineStyle: {
                  color: '#4A99FF',
                  // shadowColor: '#4A99FF',
                  // shadowBlur: 10,
                },
                shadowColor: '#4A99FF',
                shadowBlur: 10,
              },
            },
            areaStyle: {
              normal: { // 单项区域填充样式
                color: {
                  type: 'linear',
                  x: 0, //右
                  y: 0, //下
                  x2: 1, //左
                  y2: 1, //上
                  colorStops: [{
                    offset: 0,
                    color: '#4A99FF'
                  }, {
                    offset: 0.5,
                    color: 'rgba(0,0,0,0)'
                  }, {
                    offset: 1,
                    color: '#4A99FF'
                  }],
                  globalCoord: false
                },
                opacity: 1 // 区域透明度
              }
            }
            },
          {
            itemStyle: {
              normal: {
                lineStyle: {
                  color: '#4BFFFC',
                  // shadowColor: '#4BFFFC',
                  // shadowBlur: 10,
                },
                shadowColor: '#4BFFFC',
                shadowBlur: 10,
              },
            },
            areaStyle: {
              normal: { // 单项区域填充样式
                color: {
                  type: 'linear',
                  x: 0, //右
                  y: 0, //下
                  x2: 1, //左
                  y2: 1, //上
                  colorStops: [{
                    offset: 0,
                    color: '#4BFFFC'
                  }, {
                    offset: 0.5,
                    color: 'rgba(0,0,0,0)'
                  }, {
                    offset: 1,
                    color: '#4BFFFC'
                  }],
                  globalCoord: false
                },
                opacity: 1 // 区域透明度
              }
            }
          },
          {
            itemStyle: {
              normal: {
                lineStyle: {
                  color: '#ff654a',
                  // shadowColor: '#4A99FF',
                  // shadowBlur: 10,
                },
                shadowColor: '#ff654a',
                shadowBlur: 10,
              },
            },
            areaStyle: {
              normal: { // 单项区域填充样式
                color: {
                  type: 'linear',
                  x: 0, //右
                  y: 0, //下
                  x2: 1, //左
                  y2: 1, //上
                  colorStops: [{
                    offset: 0,
                    color: '#ff654a'
                  }, {
                    offset: 0.5,
                    color: 'rgba(0,0,0,0)'
                  }, {
                    offset: 1,
                    color: '#ff654a'
                  }],
                  globalCoord: false
                },
                opacity: 1 // 区域透明度
              }
            }
          },
          {
            itemStyle: {
              normal: {
                lineStyle: {
                  color: '#edff4a',
                  // shadowColor: '#4A99FF',
                  // shadowBlur: 10,
                },
                shadowColor: '#edff4a',
                shadowBlur: 10,
              },
            },
            areaStyle: {
              normal: { // 单项区域填充样式
                color: {
                  type: 'linear',
                  x: 0, //右
                  y: 0, //下
                  x2: 1, //左
                  y2: 1, //上
                  colorStops: [{
                    offset: 0,
                    color: '#edff4a'
                  }, {
                    offset: 0.5,
                    color: 'rgba(0,0,0,0)'
                  }, {
                    offset: 1,
                    color: '#edff4a'
                  }],
                  globalCoord: false
                },
                opacity: 1 // 区域透明度
              }
            }
          },
          {
            itemStyle: {
              normal: {
                lineStyle: {
                  color: '#65ff4a',
                  // shadowColor: '#4A99FF',
                  // shadowBlur: 10,
                },
                shadowColor: '#65ff4a',
                shadowBlur: 10,
              },
            },
            areaStyle: {
              normal: { // 单项区域填充样式
                color: {
                  type: 'linear',
                  x: 0, //右
                  y: 0, //下
                  x2: 1, //左
                  y2: 1, //上
                  colorStops: [{
                    offset: 0,
                    color: '#65ff4a'
                  }, {
                    offset: 0.5,
                    color: 'rgba(0,0,0,0)'
                  }, {
                    offset: 1,
                    color: '#65ff4a'
                  }],
                  globalCoord: false
                },
                opacity: 1 // 区域透明度
              }
            }
          },
          {
            itemStyle: {
              normal: {
                lineStyle: {
                  color: '#4affea',
                  // shadowColor: '#4A99FF',
                  // shadowBlur: 10,
                },
                shadowColor: '#4affea',
                shadowBlur: 10,
              },
            },
            areaStyle: {
              normal: { // 单项区域填充样式
                color: {
                  type: 'linear',
                  x: 0, //右
                  y: 0, //下
                  x2: 1, //左
                  y2: 1, //上
                  colorStops: [{
                    offset: 0,
                    color: '#4affea'
                  }, {
                    offset: 0.5,
                    color: 'rgba(0,0,0,0)'
                  }, {
                    offset: 1,
                    color: '#4affea'
                  }],
                  globalCoord: false
                },
                opacity: 1 // 区域透明度
              }
            }
          },
          {
            itemStyle: {
              normal: {
                lineStyle: {
                  color: '#894aff',
                  // shadowColor: '#4A99FF',
                  // shadowBlur: 10,
                },
                shadowColor: '#894aff',
                shadowBlur: 10,
              },
            },
            areaStyle: {
              normal: { // 单项区域填充样式
                color: {
                  type: 'linear',
                  x: 0, //右
                  y: 0, //下
                  x2: 1, //左
                  y2: 1, //上
                  colorStops: [{
                    offset: 0,
                    color: '#894aff'
                  }, {
                    offset: 0.5,
                    color: 'rgba(0,0,0,0)'
                  }, {
                    offset: 1,
                    color: '#894aff'
                  }],
                  globalCoord: false
                },
                opacity: 1 // 区域透明度
              }
            }
          },
          {
            itemStyle: {
              normal: {
                lineStyle: {
                  color: '#d84aff',
                  // shadowColor: '#4A99FF',
                  // shadowBlur: 10,
                },
                shadowColor: '#d84aff',
                shadowBlur: 10,
              },
            },
            areaStyle: {
              normal: { // 单项区域填充样式
                color: {
                  type: 'linear',
                  x: 0, //右
                  y: 0, //下
                  x2: 1, //左
                  y2: 1, //上
                  colorStops: [{
                    offset: 0,
                    color: '#d84aff'
                  }, {
                    offset: 0.5,
                    color: 'rgba(0,0,0,0)'
                  }, {
                    offset: 1,
                    color: '#d84aff'
                  }],
                  globalCoord: false
                },
                opacity: 1 // 区域透明度
              }
            }
          },
          {
            itemStyle: {
              normal: {
                lineStyle: {
                  color: '#ff4aae',
                  // shadowColor: '#4A99FF',
                  // shadowBlur: 10,
                },
                shadowColor: '#ff4aae',
                shadowBlur: 10,
              },
            },
            areaStyle: {
              normal: { // 单项区域填充样式
                color: {
                  type: 'linear',
                  x: 0, //右
                  y: 0, //下
                  x2: 1, //左
                  y2: 1, //上
                  colorStops: [{
                    offset: 0,
                    color: '#ef82ff'
                  }, {
                    offset: 0.5,
                    color: 'rgba(0,0,0,0)'
                  }, {
                    offset: 1,
                    color: '#d778ff'
                  }],
                  globalCoord: false
                },
                opacity: 1 // 区域透明度
              }
            }
          },
          {
            itemStyle: {
              normal: {
                lineStyle: {
                  color: '#e496ff',
                  // shadowColor: '#4A99FF',
                  // shadowBlur: 10,
                },
                shadowColor: '#e496ff',
                shadowBlur: 10,
              },
            },
            areaStyle: {
              normal: { // 单项区域填充样式
                color: {
                  type: 'linear',
                  x: 0, //右
                  y: 0, //下
                  x2: 1, //左
                  y2: 1, //上
                  colorStops: [{
                    offset: 0,
                    color: '#e496ff'
                  }, {
                    offset: 0.5,
                    color: 'rgba(0,0,0,0)'
                  }, {
                    offset: 1,
                    color: '#e496ff'
                  }],
                  globalCoord: false
                },
                opacity: 1 // 区域透明度
              }
            }
          },// 11
          {
            itemStyle: {
              normal: {
                lineStyle: {
                  color: '#cc00cc',
                  // shadowColor: '#4A99FF',
                  // shadowBlur: 10,
                },
                shadowColor: '#81b4ff',
                shadowBlur: 10,
              },
            },
            areaStyle: {
              normal: { // 单项区域填充样式
                color: {
                  type: 'linear',
                  x: 0, //右
                  y: 0, //下
                  x2: 1, //左
                  y2: 1, //上
                  colorStops: [{
                    offset: 0,
                    color: '#ff4aae'
                  }, {
                    offset: 0.5,
                    color: 'rgba(0,0,0,0)'
                  }, {
                    offset: 1,
                    color: '#ff4aae'
                  }],
                  globalCoord: false
                },
                opacity: 1 // 区域透明度
              }
            }
          },
          {
            itemStyle: {
              normal: {
                lineStyle: {
                  color: '#c0ff3e',
                  // shadowColor: '#4A99FF',
                  // shadowBlur: 10,
                },
                shadowColor: '#c0ff3e',
                shadowBlur: 10,
              },
            },
            areaStyle: {
              normal: { // 单项区域填充样式
                color: {
                  type: 'linear',
                  x: 0, //右
                  y: 0, //下
                  x2: 1, //左
                  y2: 1, //上
                  colorStops: [{
                    offset: 0,
                    color: '#c0ff3e'
                  }, {
                    offset: 0.5,
                    color: 'rgba(0,0,0,0)'
                  }, {
                    offset: 1,
                    color: '#c0ff3e'
                  }],
                  globalCoord: false
                },
                opacity: 1 // 区域透明度
              }
            }
          },{
            itemStyle: {
              normal: {
                lineStyle: {
                  color: '#ff0091',
                  // shadowColor: '#4A99FF',
                  // shadowBlur: 10,
                },
                shadowColor: '#ff0091',
                shadowBlur: 10,
              },
            },
            areaStyle: {
              normal: { // 单项区域填充样式
                color: {
                  type: 'linear',
                  x: 0, //右
                  y: 0, //下
                  x2: 1, //左
                  y2: 1, //上
                  colorStops: [{
                    offset: 0,
                    color: '#ff0091'
                  }, {
                    offset: 0.5,
                    color: 'rgba(0,0,0,0)'
                  }, {
                    offset: 1,
                    color: '#ff0091'
                  }],
                  globalCoord: false
                },
                opacity: 1 // 区域透明度
              }
            }
          },
        ]
      }
    },
    mounted() {
      if(sessionStorage.getItem('styleSwitch') === 'blue'){
        this.lineColor = 'white'
      }else{
        this.lineColor = '#3b3b3b'
      }
    },
    beforeDestroy() {
      if (!this.chart) {
        return
      }
      this.chart.dispose()
      this.chart = null
    },
    methods: {
      draw(wdData) {

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

        var option = {
          backgroundColor: 'transparent',
          color:['#4A99FF','#4BFFFC','#ff654a','#edff4a','#65ff4a','#4affea','#894aff','#d84aff','#ff4aae','#e496ff','#ff4aae','#c0ff3e','#ff0091'],
          title: {
            top: 20,
            text: '测风塔信息-风向玫瑰图\n\n50米主风向：'+this.wd50+'\n70米主风向：'+this.wd70,
            textStyle: {
              fontWeight: 'normal',
              fontSize: 16,
              color: this.lineColor
            },
            left: '1%'
          },
          legend: {
            top: 20,
            width:50,
            icon: 'rect',
            itemWidth: 14,
            itemHeight: 5,
            itemGap: 13,
            data: [],
            right: '4%',
            textStyle: {
              fontSize: 12,
              color: this.lineColor
            },
            selected:{
            }
          },
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              lineStyle: {
                color: '#57617B'
              }
            }
          },
          radar: [

            {

              name: {
                textStyle: {
                  color: this.lineColor,
                  fontSize: 16
                },
              },
              splitArea: { // 坐标轴在 grid 区域中的分隔区域，默认不显示。
                show: true,
                areaStyle: { // 分隔区域的样式设置。
                  color: ['rgba(255,255,255,0)', 'rgba(255,255,255,0)'], // 分隔区域颜色。分隔区域会按数组中颜色的顺序依次循环设置颜色。默认是一个深浅的间隔色。
                }
              },
              axisLine: { //指向外圈文本的分隔线样式
                lineStyle: {
                  color: this.lineColor
                }
              },
              splitLine: {
                lineStyle: {
                  color: this.lineColor, // 分隔线颜色
                  width: 1, // 分隔线线宽
                }
              },
              indicator: [
                {text: 'N', max: 1},
                {text: 'NNW', max: 1},
                {text: 'NW', max: 1},
                {text: 'WNW', max: 1},
                {text: 'W', max: 1},
                {text: 'WSW', max: 1},
                {text: 'SW', max: 1},
                {text: 'SSW', max: 1},
                {text: 'S', max: 1},
                {text: 'SSE', max: 1},
                {text: 'SE', max: 1},
                {text: 'ESE', max: 1},
                {text: 'E', max: 1},
                {text: 'ENE', max: 1},
                {text: 'NE', max: 1},
                {text: 'NNE', max: 1},
              ],
              center: ['50%', '50%'],
              radius: '70%'
            },
          ],
          series: [
            {
              type: 'radar',
              tooltip: {
                trigger: 'item',
              },
              areaStyle: {},
              data: []
            }
          ]
        }
        var index = 0;
        for(var key in wdData){
          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 wd = new Object
          wd.name=keyName
          wd.value=wdData[key]
          wd.itemStyle = this.itemStyle[index].itemStyle
          wd.areaStyle = this.itemStyle[index].areaStyle
          option.series[0].data.push(wd)
          index++;
        }
        this.chart.setOption(option,true)

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