<template>
  <div id="two">
    <el-row>
      <el-col :span="24" class="main">
        <el-col :span="24" class="title"> e专利 </el-col>
        <el-col :span="24" class="canvas">
          <div id="twoChart" style="height: 425px"></div>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import * as echarts from 'echarts';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: statistics } = createNamespacedHelpers('statistics');

export default {
  name: 'one',
  props: {},
  components: {},
  data: function () {
    return {};
  },
  created() {},
  mounted() {
    this.init();
  },
  methods: {
    ...statistics(['query']),
    async init() {
      let res = await this.query({ type: 'patent' });
      if (this.$checkRes(res)) {
        let viewData = res.data.map((i) => i.name);
        var chartDom = document.getElementById('twoChart');
        var myChart = echarts.init(chartDom);
        var option = {
          tooltip: {
            trigger: 'item',
            formatter: '{a} <br/>{b} : {c} ({d}%)',
          },
          legend: {
            type: 'scroll',
            orient: 'vertical',
            right: 10,
            top: 20,
            bottom: 20,
            data: viewData,
            selected: res.data,
          },
          series: [
            {
              name: '姓名',
              type: 'pie',
              radius: '50%',
              center: ['35%', '50%'],
              data: res.data,
              emphasis: {
                itemStyle: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: 'rgba(0, 0, 0, 0.5)',
                },
              },
            },
          ],
        };
        option && myChart.setOption(option);
      }
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  .title {
    text-align: center;
    font-size: 16px;
    font-weight: bold;
    padding: 15px 0;
  }
}
</style>
