<template>
  <div>
    <section v-show='isShowTotal' ref="getHeight">
      <section class="box-sjtj">
        <section class="flex">
          <section class="left-tj">
            <Sjtj :info="pageData.countlist" :isShowTip="false" :isShowBottom="false" :width="280" mb="6px" />
          </section>
        </section>
      </section>
    </section>
    <!-- 检查记录查询 -->
    <div class='tabox'>
      <div class="headBox3">
        <el-input placeholder="请输入检查人进行查询" v-model="pageData.listQuery.keywords" clearable
          style='width:400px'></el-input>
        <el-button type="primary" @click="Searchdata">
          <el-icon>
            <Search />
          </el-icon>
          <span>查询</span>
        </el-button>
      </div>
      <MOSTY.Table :table-columns="pageData.tableColumns" :tableData="pageData.tableData" :tableloading="tableloading"
        :tableHeight="'40vh'">
        <template #checkresult="{ row }">
          <span>{{ row.dangercount > 0 ? `发现隐患${row.dangercount}条` : '正常' }}</span>
        </template>
        <template #actions="{ row }">
          <span class="operesee" @click="setFn(row)">
            <el-icon>
              <Compass />
            </el-icon>
            查看
          </span>
        </template>
      </MOSTY.Table>
      <div class="fenye">
        <MOSTY.Pages :pageConfiger="pageData.pageConfiger" @changeNo="handleCurrentChange"
          @changeSize="handleSizeChange" />
      </div>
    </div>
  </div>
  <!--检查记录详情-->
  <div v-if="showdialogjzw" class="dialog-box">
    <Addjcjl :id="id" @saveSuccess="saveSuccess" />
  </div>
</template>
<script setup>
import * as MOSTY from "@/components/MyComponents/index";
import { reactive, ref, onMounted } from "vue"
import Addjcjl from "@/components/dialog/Addjcjl.vue";
import Sjtj from '@/views/dataReportWork/aqjypx/components/sjtj.vue'
import { getApi, postApi } from "@/api/tobAcco_api.js";
const emits = defineEmits(["handleChange", 'searchChange']);
const tableloading = ref(false);
const isShowTotal = ref(true)
const showdialogjzw = ref(false);
const id = ref(null)
const props = defineProps({
  obj: {
    default: () => { },
    type: Object
  },
  type: {
    default: '',
    type: String
  }
});
const pageData = reactive({
  countlist: [
    { title: '总次数', num: 0, icon: 'ccss/icon_01.png' },
    { title: '本年检查次数', num: 0, icon: 'ccss/icon_02.png' },
    { title: '本季度检查次数', num: 0, icon: 'ccss/icon_03.png' },
    { title: '本月检查次数', num: 0, icon: 'ccss/icon_04.png' },
    { title: '本周检查次数', num: 0, icon: 'ccss/icon_05.png' }
  ],
  pageConfiger: {
    pageCurrent: 1,
    pageSize: 10,
    total: 0
  },
  listQuery: {
    pageCurrent: 1,
    pageSize: 10,
    objid: props.obj.objid ? props.obj.objid : props.obj.zbid ? props.obj.zbid : props.obj.id,
    keywords: ''
  },
  tableColumns: [
    {
      title: "检查人",
      prop: "username"
    },
    {
      title: "检查项",
      prop: "objname"
    },
    {
      title: "检查时间",
      prop: "addtime"
    },
    {
      title: "检查结果",
      prop: "checkresult",
      slot: true
    },
    {
      title: "发现隐患数",
      prop: "dangercount"
    },
    {
      title: "操作",
      prop: "actions",
      slot: true
    }
  ],
  tableData: []
})
onMounted(() => {
  getbgsbsscount(props.obj.objid ? props.obj.objid : props.obj.zbid ? props.obj.zbid : props.obj.id)
  getTableData()
})
// 	检查记录统计
function getbgsbsscount(objid) {
  getApi({ objid }, '/mosty-jcgl/dynamic/checkLogStatistics').then(res => {
    if (res) {
      pageData.countlist[0].num = res.count;
      pageData.countlist[1].num = res.yearCount;
      pageData.countlist[2].num = res.quarterCount;
      pageData.countlist[3].num = res.monthCount;
      pageData.countlist[4].num = res.weekCount;
    }
  })
}
const getTableData = () => {
  tableloading.value = true
  getApi(pageData.listQuery, '/mosty-jcgl/dynamic/checkLogList').then(res => {
    tableloading.value = false
    pageData.tableData = res.records
      ? res.records : [];
    pageData.pageConfiger.total = res.total
  })
}
//查询
function Searchdata() {
  getTableData()
}
function setFn(row) {
  id.value = row.id
  showdialogjzw.value = true
}
const saveSuccess = (val) => {
  showdialogjzw.value = false
}
//页码发生变化
const handleCurrentChange = (val) => {
  pageData.listQuery.pageCurrent = val;
  pageData.pageConfiger.pageCurrent = val;
  getTableData()
};
//查询条数发生变化
const handleSizeChange = (val) => {
  pageData.listQuery.pageSize = val;
  pageData.pageConfiger.pageSize = val;
  getTableData()
};
</script>

<style lang="scss" scoped>
.headBox3 {
  display: flex;
  justify-content: end;
  width: 100%;
  margin-bottom: 10px;
}

.top_ul {
  display: flex;
  justify-content: start;
  flex-wrap: wrap;

  >li {
    width: 15%;
    height: 83px;
    margin: 6px 32px;
  }
}
</style>
