<template>
  <div class="container3" @click="fn(ajlxUrl)">
    <div ref="bar" class="bar"></div>
  </div>
</template>
    
<script>
import {getAjlx} from "@/api/ddzhxt.js"
export default {
  computed: {
    randomRgbColor() {
      //随机生成RGB颜色
      var r = Math.floor(Math.random() * 256); //随机生成256以内r值
      var g = Math.floor(Math.random() * 256); //随机生成256以内g值
      var b = Math.floor(Math.random() * 256); //随机生成256以内b值
      return `rgb(${r},${g},${b})`; //返回rgb(r,g,b)格式颜色
    },
  },
  data() {
    return{
       text:[],
       number:[],
       data:[],
       ajlxUrl:'http://219.147.99.164:8082/servicecity/route/bigdata/list-case-info-ajlxtop10.html',
    }
  },
created () {
  this.getAjlx()
},
  methods: {
    fn(url) {
      layer.open({
        type: 2,
        content: url, 
        area: ['90%', '80%'],
        title:'' ,
      });
    },
    gr() {
      let myChart = this.$echarts.init(this.$refs.bar);
      var tootipTimer = null;
      let option = {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
        },
        grid: {
          left: "2%",
          right: "15%",
          bottom: "10%",
          top: "5%",
          containLabel: true,
        },
        xAxis: {
          type: "value",
          boundaryGap: [0, 0.01],
          axisLine: {
            show: false,
          },
          axisTick: {
            show: false, //刻度线
          },
          axisLabel: {
            show: false, //隐藏刻度值
          },
          splitLine: {
            //网格线
            show: false,
          },
        },
        yAxis: {
          axisLabel: {
            textStyle: {
              show: true,
              color: "#fff",
              fontSize: "12",
            },
          },
          type: "category",
          data: this.text,
        },
        series: [
          {
            name: "案件",
            type: "bar",
            barWidth: "20%",
            color: this.randomRgbColor,
            label: {
              formatter: "{c}" + "个",
              show: true,
              position: "right",
              textStyle: {
                fontSize: "12",
                color: "#fff",
              },
            },
            data:this.number,
          },
        ],
      };
      myChart.setOption(option);
      let sizeFun = function () {
        myChart.resize();
      };
      window.addEventListener("resize", sizeFun);
      tootipTimer && tootipTimer.clearLoop();
            tootipTimer = null;
            // 调用轮播的方法
            tootipTimer = window.loopShowTooltip(myChart, option, {
                interval: 2000, // 轮播间隔时间
                loopSeries: true, // 是否开启轮播循环
            });
    },
    async getAjlx () {
      try {
        const res = await getAjlx()
        // console.log(res);
        this.data = res.data.list
        //  console.log(this.data);
         this.data.forEach(item => {
          this.text.push(item.name) 
          this.number.push(...item.columns)
         })
         this.$nextTick(()=>{
            this.gr();
           })
      } catch (error) {
        console.log('数据获取失败');
      }
    }
  },
  mounted() {
    // setTimeout(() => {
    // this.gr();   
    // }, 300);
  },
};
</script>
    
<style scoped lang="scss">
.container3 {
  /* border: 1px solid #00ffff;  */
  width: 17.0833vw;
  height: 31.823vh;
  text-align: left;
  .bar {
  width: 17.0833vw;
  height: 31.823vh;
}
}


</style>