<template>
  <div class="app-container home">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>{{ title }}数据统计</span>
        <!-- <el-button style="float: right; padding: 3px 0" type="text">操作按钮</el-button> -->
      </div>
      <el-row :gutter="20">
        <el-col :span="8" v-for="row in rows" :key="row">
          <div :id="row" style="width: 500px;height: 500px;"></div>
        </el-col>
        <!-- <el-col :span="8">
          <div id="orderSources" style="width: 500px;height: 500px;"></div>
        </el-col>
        <el-col :span="8">
          <div id="car" style="width: 500px;height: 500px;"></div>
        </el-col> -->
      </el-row>
      <div class="text item">
        <!-- <v-chart v-if="isShow" :options="option" theme="th" /> -->


      </div>
    </el-card>

  </div>
</template>

<script>
import { countGroup } from "@/api/business/templatePropValue";

import * as echarts from 'echarts';
export default {
  name: "Index",
  data() {
    return {
      surveyId: null,
      title: null,
      rows:[]
    };
  },
  beforeCreate(){
    console.log( this.$route.query.id);
    countGroup(this.$route.query.id).then(response => {
        this.rows = [];
        for (let key in response.data) {
          this.rows.push(key);
        }
      });
  },
  created() {

    this.surveyId = this.$route.query.id
    this.title = this.$route.query.title
    setTimeout(() => {
    this.ininChat(this.$route.query.id);
    }, 500); // 5000毫秒后执行
  },
  methods: {
    goTarget(href) {
      window.open(href, "_blank");
    },
    ininChat(surveyId) {
      countGroup(surveyId).then(response => {
        console.log("response", response);
        this.rows = [];
        for (let key in response.data) {
          this.rows.push(key);
        }
        console.log(this.rows);
        for (let key in response.data) {
          console.log(key);
          var option = {
            title: {
              text: key,
              left: 'center',
              top: 'center'
            },
            series: [
              {
                type: 'pie',
                data: response.data[key],
                // {"name":"待处理","value":99},{"name":"已送达","value":1}
                radius: ['40%', '70%']
              }
            ]
          };
          // 绘制图表
         var dom =  document.getElementById(key);
         console.log("dom",dom);
         if(dom == null){
          this.$modal.msgError("未获取到dom");
         }else{
          this.orderRound = echarts.init(dom);
          this.orderRound.setOption(option);
         }
         
        }
      });


    }
  }
};
</script>

<style scoped lang="scss">
.home {
  blockquote {
    padding: 10px 20px;
    margin: 0 0 20px;
    font-size: 17.5px;
    border-left: 5px solid #eee;
  }

  hr {
    margin-top: 20px;
    margin-bottom: 20px;
    border: 0;
    border-top: 1px solid #eee;
  }

  .col-item {
    margin-bottom: 20px;
  }

  ul {
    padding: 0;
    margin: 0;
  }

  font-family: "open sans",
  "Helvetica Neue",
  Helvetica,
  Arial,
  sans-serif;
  font-size: 13px;
  color: #676a6c;
  overflow-x: hidden;

  ul {
    list-style-type: none;
  }

  h4 {
    margin-top: 0px;
  }

  h2 {
    margin-top: 10px;
    font-size: 26px;
    font-weight: 100;
  }

  p {
    margin-top: 10px;

    b {
      font-weight: 700;
    }
  }

  .update-log {
    ol {
      display: block;
      list-style-type: decimal;
      margin-block-start: 1em;
      margin-block-end: 1em;
      margin-inline-start: 0;
      margin-inline-end: 0;
      padding-inline-start: 40px;
    }
  }
}
</style>
