<template>
  <div style="position: relative">
    <div v-for="item in selected.y">
      <div style="position: absolute;right: 0;z-index: 100">
        <el-button icon="el-icon-camera-solid" size="mini" @click="handleScreenshot(item, item)">截图</el-button>
      </div>
      <el-tabs v-model="active[item]">
        <el-tab-pane :label="item" :name="item">
          <div :id="item" :style="{ width: width, height: height }"></div>
        </el-tab-pane>
      </el-tabs>
    </div>
  </div>
</template>

<script>
import { chartOption, chartOptionMixins } from "@/views/analyse/custom/mixins";
import { random } from "@/utils";

export default {
  mixins: [chartOption],
  name: "CRadar2",
  data() {
    return {
      active: {},
      max: 0
    }
  },
  mounted() {
    this.selected.y.map(item => {
      this.$set(this.active, item, item)
      this.$nextTick(() => {
        this.initChart(item, this.getOption(item))
      })
    })
  },
  methods: {
    getSum(x) {
      let sum = 0
      for (let i = 0; i < this.selected.y.length; i++) {
        sum += this.getDataCount(x, this.selected.y[i])
      }
      if (this.max < sum) {
        this.max = sum
      }
      return this.max
    },
    getOption(y) {
      return {
        tooltip: {
          trigger: 'item'
        },
        legend: {},
        radar: {
          indicator: this.selected.x.map(x => {
            return {
              name: x,
              max: this.getSum(x)
            }
          }),
          axisName: {
            show: this.form.setting.show,
            fontFamily: this.form.setting.fontFamily,
            fontSize: this.form.setting.fontSize,
            fontWeight: this.form.setting.fontWeight ? 'bold' : 'normal',
            color: this.form.setting.fontColor,
          },
        },
        series: [{
          name: y,
          type: 'radar',
          data: [{
            value: this.selected.x.map(x => this.getDataCount(x, y)),
            name: '',
            lineStyle: {
              color: this.getColor(y)
            },
            label: this.getDataLabel()
          }]
        }]
      }
    },
  }
}
</script>
