<script setup>
import { computed, getCurrentInstance, onMounted, reactive, ref } from "vue";
const { proxy } = getCurrentInstance();
import PageTitle from "@/components/aboutTable/PageTitle.vue";
import Search from "@/components/aboutTable/Search.vue";
import MyTable from "@/components/aboutTable/MyTable.vue";
import Pages from "@/components/aboutTable/Pages.vue";
import { qcckPost, qcckGet } from "@/api/qcckApi.js";

const searchConfiger = reactive([
  {
    showType: "input",
    prop: "dkrXm",
    placeholder: "请输入打卡人姓名",
    label: "打卡人姓名"
  }
]);
const searchBox = ref(); //搜索框
const pageData = reactive({
  visible: true,
  tableData: [], //表格数据
  keyCount: 0,
  tableConfiger: {
    rowHieght: 61,
    loading: false,
    haveControls:false,
  },
  total: 0,
  pageConfiger: {
    pageSize: 10,
    pageCurrent: 1
  }, //分页
  controlsWidth: 210, //操作栏宽度
  tableColumn: [
    {
      label: "打卡人姓名",
      prop: "dkrXm"
    },
    {
      label: "必到点位置",
      prop: "bddMc"
    },
    {
      label: "开始时间",
      prop: "dkKsSj"
    },
    {
      label: "打卡开始附件",
      prop: "dkKsFj",
      showSolt: true
    },
    {
      label: "结束时间",
      prop: "dkJsSj"
    },
    {
      label: "打卡结束附件",
      prop: "dkJsFj",
      showSolt: true
    }
  ]
});
const onSearch = (val) => {
  const { cz, ...ret } = val;
  pageData.pageConfiger.pageCurrent = 1;
  getListData(ret);
};

// 表格高度计算
const tabHeightFn = () => {
  pageData.tableHeight =
    window.innerHeight - searchBox.value.offsetHeight - 244;
  window.onresize = function () {
    tabHeightFn();
  };
};

const getListData = async (params = {}) => {
  pageData.tableConfiger.loading = true;
  qcckGet({...pageData.pageConfiger,...params}, "/mosty-yjzl/tbZdxlFgdwBddxlrwJl/getPageList")
    .then((res) => {
      pageData.tableData = res.records || [];
      pageData.tableConfiger.loading = false;
      pageData.total = res.total;
    })
    .catch(() => {
      pageData.tableConfiger.loading = false;
    });
};

const changeNo = (val) => {
  pageData.pageConfiger.pageCurrent = val;
  getListData();
};

const changeSize = (val) => {
  pageData.pageConfiger.pageSize = val;
  getListData();
};


onMounted(() => {
  proxy.mittBus.on("mittFn", (data) => {
    pageData.keyCount = data;
  });
  tabHeightFn();
  getListData();
});
</script>

<template>
  <div class="container">
    <div class="titleBox">
      <PageTitle title="打卡记录">
      </PageTitle>
    </div>
    <div ref="searchBox">
      <Search :searchArr="searchConfiger" @submit="onSearch" />
    </div>

    <div class="tabBox">
      <MyTable
        :tableData="pageData.tableData"
        :tableColumn="pageData.tableColumn"
        :tableHeight="pageData.tableHeight"
        :key="pageData.keyCount"
        :tableConfiger="pageData.tableConfiger"
        :controlsWidth="pageData.controlsWidth"
      >
        <template #dkKsFj="{ row }">
          <el-image
            :append-to-body="true"
            :preview-src-list="[
              `/mosty-api/mosty-base/minio/image/download/${row.dkKsFj}`
            ]"
            style="width: 75px; height: 75px"
            :src="`/mosty-api/mosty-base/minio/image/download/${row.dkKsFj}`"
            fit="cover"
            lazy
          />
        </template>
        <template #dkJsFj="{ row }">
          <el-image
            :append-to-body="true"
            :preview-src-list="[
              `/mosty-api/mosty-base/minio/image/download/${row.dkJsFj}`
            ]"
            style="width: 75px; height: 75px"
            :src="`/mosty-api/mosty-base/minio/image/download/${row.dkJsFj}`"
            fit="cover"
            lazy
          />
        </template>
        <!-- 操作 -->
        <template #controls="{ row }">
        </template>
      </MyTable>

      <Pages
        @changeNo="changeNo"
        @changeSize="changeSize"
        :tableHeight="pageData.tableHeight"
        :pageConfiger="{
          ...pageData.pageConfiger,
          total: pageData.total
        }"
      />
    </div>
  </div>
</template>

<style scoped lang="scss">
.container {
  ::v-deep {
    .check,
    .el-upload-text {
      display: none;
    }

    .el-descriptions__body {
      background-color: transparent !important;
      color: #fff;
    }
  }
}
</style>
