<template>
  <div>
    <Chart :cdata="cdata" v-if="Chartstatus" />
  </div>
</template>

<script>
import Chart from './chart.vue'
import { httpGet } from "../../../../api";
export default {
  data () {
    return {
      // data:{
      //   labels: ["1月", "2月", "三月", "4月", "5月",'6月','7月','8月','9月','10月','11月','12月'],
      //       datasets: [
      //       {
      //       label: "My First dataset",
      //       fillColor: "rgba(220,220,220,0.5)",
      //       strokeColor: "rgba(220,220,220,0.8)",
      //       highlightFill: "rgba(220,220,220,0.75)",
      //       highlightStroke: "rgba(220,220,220,1)",
      //       data: [0,0,0,0,0,0,0,0,0,0,0,0]
      //       }
      //       ]
      // }
      cdata: {
        category: ["1月", "2月", "3月", "4月", "5月",'6月','7月','8月','9月','10月','11月','12月'],
        lineData: [0,0,0,0,0,0,0,0,0,0,0,0],
        barData: [0,0,0,0,0,0,0,0,0,0,0,0],
        rateData: [0,0,0,0,0,0,0,0,0,0,0,0]
      },
      Chartstatus:true,
      roomNum:0
    };
  },
  components: {
    Chart,
  },
  created(){
      var data1={
        type:5
      }
      httpGet(data1,this.$api.getStatisticsTotal).then(res=>{
		  console.log(res)
        this.roomNum=res.data[0].room
      })
     var data={
        level:2, //0-天、1-周、2-月、3-季、4-年
      }
      httpGet(data,this.$api.getTenantCount).then(res=>{
		  console.log(res)
        var option=this.cdata.lineData,option1=this.cdata.barData,option2=this.cdata.rateData
        res.data.map(li=>{
          var index=parseInt(li.order)-1
          option[index]=li.count
          // option1[index]= li.count
          // let rate = option1[index] / this.roomNum || 0
          // option2[index]=(rate*100).toFixed(2)
        })
        this.Chartstatus=false
        this.$nextTick(function(){
          this.cdata.lineData = option
          this.cdata.barData = option
          this.cdata.rateData = option2
          this.Chartstatus=true
        })
      })
  },
  mounted () {
    // this.setData();
  },
  methods: {
    // 根据自己的业务情况修改
    setData () {
      for (let i = 0; i < this.cdata.barData.length -1; i++) {
        let rate = this.cdata.barData[i] / this.cdata.lineData[i];
        this.cdata.rateData.push(rate.toFixed(2));
      }
    },
  }
};
</script>

<style lang="scss" scoped>
</style>