<template>
  <div class="container2">
    <div ref="bar" class="bar" @click="fn(ajjzUrl)"></div>
  </div>
</template>
    
<script>
  import {getAjjz} from '@/api/ddzhxt.js'
export default {
  data() {
    return{
       data:[],
       text:[],
       number:[],
       ajjzUrl:'http://219.147.99.164:8082/servicecity/route/bigdata/list-case-info-7dayajjz.html',

    }
  },
  methods: {
    fn(url) {
      layer.open({
        type: 2,
        content: url, 
        area: ['80%', '80%'],
        title:'' ,
      });
    },
    gr() {
      let myChart = this.$echarts.init(this.$refs.bar);
      var tootipTimer = null;
      let option = {
        xAxis: {
          type: "category",
          data: this.text,
          axisTick: {
            alignWithLabel: true,
          },
          axisLabel: {
            textStyle: {
              color: "#fff",
            },
          },
        },
        yAxis: {
          type: "value",
          axisTick: {
            show: false, //刻度线
          },
          axisLabel: {
            textStyle: {
              color: "#fff",
            },
          },
        },
        grid: {
          left: "2%",
          right: "4%",
          bottom: "2%",
          top: "15%",
          containLabel: true,
        },
        tooltip: {
          show: true,
          borderWidth: 0,
          position: "right",
          // label:{
          //    backgroundColor: "#fff",
          //    width:'120%',
          //    height:'88px'
          // },
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
          formatter: "{b}" + "&nbsp" + ":" + "&nbsp" + "{c}" + "件",
        },
        series: [
          {
            data: this.number,
            type: "bar",
            color: "#f10909",
            // emphasis :{
            //     itemStyle:{
            //     color:"rgba(255,255,255,0.2)"
            //     }
            // },
            label: {
              show: true,
              position: "top",
              formatter: "{c}" + "件",
              textStyle: {
                fontSize: "12",
                color: "#fff",
                fontWeight: 100,
              },
            },
          },
        ],
      };
      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 getAjjz() {
      try {
        const res =await getAjjz ()
        //  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.value)
          })
          this.$nextTick(()=>{
            this.gr();
           })
      } catch (error) {
        console.log('数据获取失败');
      }
    }
  },
  created(){
    this.getAjjz()
  },
  mounted() {
    // setTimeout(() => {
    // this.gr();
      
    // }, 300);
  },
};
</script>
    
<style scoped lang="scss">
.container2 {
  /* border: 1px solid #00ffff; */
  width: 17.0833vw;
  height: 21.5749vh;
  .bar {
  width: 17.0833vw;
  height: 21.5749vh;
}
}


</style>