<template>
  <MOSTY.PageTable :table-columns="tableColumns" :tableData="tableData" :heightnum='"77vh"'
   :tableloading="tableloading" page-title="人员检查列表" :search-type="'03'"
    :showolddep="true" @getDeptId="getDeptId">
    <template #serach>
      <el-date-picker v-model="time" type="daterange" range-separator="To" start-placeholder="开始时间" end-placeholder="结束时间" format="YYYY-MM-DD" date-format="YYYY-MM-DD" value-format="YYYY-MM-DD" :size="size" />
      <el-button style="margin-left: 10px" type="primary" @click="search">
        <el-icon>
          <Search />
        </el-icon>
        <span>查询</span>
      </el-button>
    </template>
    <template #actions="{ row }">
      <span class="operesee" @click="configuration(row)">
        <el-icon>
          <EditPen />
        </el-icon>
        详情
      </span>
    </template>

  </MOSTY.PageTable>
  <div v-if="dialogVisible" class="dialog-box">
    <Jcjlxq @close="handleClose" :userid="userid" :time="listQuery.time" :obj="obj" />
  </div>
</template>

<script setup>
// 引入
import { reactive, onMounted, watch, ref, getCurrentInstance } from "vue";
import { getApi, deleteApi, putApi, postApi } from "@/api/tobAcco_api.js";
import { filterYear } from "@/utils/auth.js";
import { dateFormat } from "@/utils/tools";
import { getItem } from "@/utils/storage";
import { ElMessage } from "element-plus";
import Jcjlxq from "./components/jcjlxq.vue";
import * as MOSTY from "@/components/MyComponents/index";
// 数据
//查询条件
const { proxy } = getCurrentInstance();

const dialogVisible = ref(false);
const tableHeight = ref();
const bigHeight = ref(); //整个高度
const userid = ref(null);
const time = ref(
  [dateFormat({ type: "ones", time: new Date() }),
  dateFormat({ type: "day", time: new Date() })]
)
const obj = ref(
  { jcrws: 0, sjjcs: 0 }
)
// const username = ref(localStorage.getItem("USERNAME"))//当前登录用户
const tableColumns = ref([
  {
    title: "姓名",
    prop: "username"
  },
  {
    title: "所属部门",
    prop: "ssbmmc"
  },
  {
    title: "应检查次数",
    prop: "loginCount"
  },
  {
    title: "实际检查次数",
    prop: "useCount"
  },
  {
    title: "操作",
    prop: "actions",
    slot: true
  }
]);
const tableData = ref([
]);
const ssdept = getItem("deptId");
const tableloading = ref(false);
const listQuery = reactive({
  orgcode: "",
  time: `${time.value[0]}至${time.value[1]}`
});

onMounted(() => {
  tabHeightFn();
  bigHeightFn();
  getDataList();
});
//查询
function search () {
  listQuery.time = `${time.value[0]}至${time.value[1]}`
  getDataList()
}
// 配置
const configuration = (row) => {
  userid.value = row.userid;
  obj.value.jcrws = row.loginCount;
  obj.value.sjjcs = row.useCount;
  dialogVisible.value = true;
};
//获取列表数据
function getDataList () {
  tableloading.value = true;
  getApi(listQuery, "/mosty-jcgl/userCheckplan/getJcjlList")
    .then((res) => {
      if (res) {
        tableloading.value = false;
        tableData.value = res;
      }
    })
    .catch((err) => {
      tableData.value = [];
      tableloading.value = false;
    });
}
// 表格高度计算
const tabHeightFn = () => {
  tableHeight.value = window.innerHeight - 210;
};

const getDeptId = (val) => {
  listQuery.orgcode = val;
  getDataList();
};

function handleClose () {
  userid.value = null
  dialogVisible.value = false;
}
const bigHeightFn = () => {
  bigHeight.value = window.innerHeight - 147 + "px";
};
</script>

<style lang="scss" scoped>
.el-table__body-wrapper is-scrolling-left {
  border: none;
}

.el-table__row {
  line-height: 21px;
}

.el-table th,
.el-table td {
  padding: 4px 8px;
}

.el-table__body-wrapper is-scrolling-left .cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.el-dialog__headerbtn {
  margin-top: -6px !important;
}

.el-dialog__headerbtn .el-dialog__close {
  font-size: 27px !important;
}

.bigBox {
  display: flex;
  background-color: #f0f3f4;

  .title {
    height: 45px;
    line-height: 45px;
    font-size: 18px;
    color: #0f3916;
    display: flex;
    justify-content: space-between;
    align-items: center;

    .zzjgxx {
      font-size: 18px;
      font-weight: 400;
      color: #0f3916;
      line-height: 24px;
    }

    .el-icon {
      cursor: pointer;
    }
  }

  .cent {
    width: 100%;
    text-align: center;

    .el-form {
      margin-left: 27%;
    }
  }

  .left {
    width: 300px;
    // height: 1030px;
    background: #ffffff;
    box-shadow: 0px 2px 10px 0px rgba(107, 107, 107, 0.1);
    border-radius: 0px 0px 0px 0px;
    opacity: 1;

    .treeBox {
      overflow: auto;
    }
  }

  .right {
    // width: calc(100% - 300px);
    padding: 0 10px;
    margin: 0px 14px;
    background: #fff;

    .headBox {
      height: 60px;
      display: flex;
      justify-content: space-between;
      position: relative;
      z-index: 2;

      .el-select {
        width: 150px;
      }

      .btnBox {
        display: flex;
        width: 500px;
        justify-content: space-between;
        align-items: center;
      }
    }
  }
}

.xzmb_box {
  display: flex;
  justify-content: space-between;
  padding: 10px;

  > div {
    width: 48%;

    .titles {
      text-align: center;
      font-size: 18px;
      font-weight: 500;
      line-height: 35px;
    }
  }
}

.tabBox {
  height: calc(100% - 70px);
  border-left: 0 !important;

  .el-table {
    height: 91%;
  }

  .fenye {
    top: 95%;
  }
}

.btn {
  padding: 10px;
  float: right;
}
</style>
