<template>
  <div>
    <MOSTY.PageTree :pageTitle="'隐患台账统计'" :isShowLeftTree="false">
      <template #serach>
        <el-divider />
        <div class="btnBox">
          <el-button type="primary" @click="CloseEvent">
            <el-icon>
              <Back />
            </el-icon>
            <span>返回</span>
          </el-button>
        </div>
      </template>
      <template #table>
        <section class="eltab3">
          <MOSTY.Table :table-columns="tableColumns" :tableData="tableData" :tableloading="tableloading"
            :tableHeight="'100%'">
          </MOSTY.Table>
        </section>
      </template>
    </MOSTY.PageTree>

  </div>
</template>

<script setup>
// 引入
import {
  reactive,
  onMounted,
  ref,
  getCurrentInstance,
  defineEmits,
  defineProps,
  watch
} from "vue";
import { getApi, deleteApi, postApi } from "@/api/tobAcco_api.js";
import { ElMessage } from "element-plus";
import * as MOSTY from "@/components/MyComponents/index";
import PcflTree from "../../aqfxfjgk/component/pcflTree.vue";
import { getSysDictByCode } from "@/api/sysDict"; //引入封装数字字典接口
const { proxy } = getCurrentInstance();
const emits = defineEmits(["close"]);
const props = defineProps({
  time: {
    type: Array,
    default: []
  }
});
const tableloading = ref(false);
const tableData = ref([]);
const tableColumns = ref([
  {
    title: "单位",
    prop: "orgname"
  },
  // {
  //   title: "应排查次数",
  //   prop: "checkcount"
  // },
  {
    title: "已排查次数",
    prop: "factcount"
  },
  // {
  //   title: "排查次数完成率",
  //   prop: "checkRate"
  // },
  // {
  //   title: "应排查数量",
  //   prop: "totalCount"
  // },
  {
    title: "已排查数量",
    prop: "finishCount"
  },
  {
    title: "数量排查完成率",
    prop: "rate"
  },
  {
    title: "发现隐患数量",
    prop: "yhCount"
  },
  {
    title: "已整改隐患数量",
    prop: "yFinish"
  },
  {
    title: "未完成整改数量",
    prop: "wFinish"
  },
  {
    title: "隐患整改率",
    prop: "zgRate"
  },
  {
    title: "统计时间",
    prop: "time"
  }
]);
const total = ref(0);
onMounted(() => {
  getTableData(props.time)
});

// 获取表格数据
const getTableData = (arr) => {
  tableloading.value = true;
  getApi({ startTime: arr[0], endTime: arr[1] }, "/mosty-jcgl/yhb/yhStatistics")
    .then((res) => {
      if (res) {
        tableloading.value = false;
        tableData.value = res;
        tableData.value.forEach((item) => {
          if (item.controls) {
            item.controls = item.controls.split(",");
          }
        });
        total.value = res.total;
      }
    })
    .catch((err) => {
      tableData.value = [];
      tableloading.value = false;
    });
};

const CloseEvent = () => {
  emits("close");
};
</script>

<style lang="scss" scoped>
.btnBox {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.eltab3 {
  height: calc(100vh - 270px);
}
</style>
