<template>
  <div style="padding: 0px;" >
    <el-col :span="24">
      <el-table
        stripe
        :data="descentData"
        :height="vh"
        border
        class="mt10"
        style="width: 100%; height: 100%"
        v-loading="isLoading"
        header-cell-class-name="table_header"
      >
        <template v-for="(item, index) in tableHeaderAera">
          <el-table-column
            :prop="item.prop"
            align="center"
            :label="item.label"
            :key="index"
            :min-width="item.width"
          >
          </el-table-column>
        </template>
      </el-table>
    </el-col>
  </div>
</template>
<script>
import { dicData } from "@/assets/commjs/dictypeData";
import { getStatisticData } from "@/api/statistics";
export default {
  props: {
    item: {
      type: Object,
      default: null,
    },
    item2: {
      type: Object,
      default: null,
    },
    height: {
      type: Number,
      default: null,
    },
    height2: {
      type: Number,
      default: null,
    },
  },
  watch: {
    height2(a, b) {
      if (a == 24) {
        this.vh = document.getElementById("conmentId").offsetHeight-50;
        this.queryData();
      } else {
        return;
      }
    },
    height(a, b) {
      if (a == 6 || a == 8 || a == 9 || a == 16) {
        setTimeout(() => {
          let str = document.getElementById("areaconstyytable").style.height;
          let strsec = str.split("p");
          let height = parseInt(strsec) - 50;
          this.vh = height+10;
          this.queryData();
        }, 200);
      } else {
        return;
      }
    },
    deep: true,
  },
  data() {
    return {
      isLoading: false,
      vh: null,
      h: 0,
      tableHeaderAera: [
        { prop: "name", label: "暂降原因" },
        { prop: "value", label: "暂降次数" },
      ],
      descentData: [],
      time: this.timefamt(),
      formData: {
        deptIndex: JSON.parse(window.sessionStorage.getItem("Info")).deptId,
        monitorFlag: 2,
        powerFlag: 2,
        reportFlag: 3,
        searchBeginTime: "",
        searchEndTime: "",
        statisticalType: {},
      },
      //   classificationData: [],
    };
  },
  created() {
    this.queryData();
  },
  mounted() {
    setTimeout(() => {
      let str = document.getElementById("areaconstyytable").style.height;
      let strsec = str.split("p");
      let height = parseInt(strsec) - 50;
      this.vh = height+10;
    }, 200);
  },
  methods: {
    timefamt() {
      var date = new Date();
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      var day = date.getDate();
      month = month > 9 ? month : "0" + month;
      day = day < 10 ? "0" + day : day;
      var arr = [];
      var time1 = year + "-" + month + "-01";
      arr.push(time1);
      var time2 = year + "-" + month + "-" + day;
      arr.push(time2);
      return arr;
    },
    queryData() {
      this.isLoading = true;
      this.formData.searchBeginTime = this.time[0];
      this.formData.searchEndTime = this.time[1];
      getStatisticData(this.formData).then((res) => {
        if (res.code == "A0000") {
          this.descentData = res.data.type;
          this.isLoading = false;
        }
      });
    },
  },
};
</script>
