<template>
  <div>
    <!-- 搜索 -->
    <div ref="searchBox" class="mt10">
      <Search :searchArr="searchConfiger" @submit="onSearch" />
    </div>
    <!-- 表格 -->
    <div class="tabBox mt10" :style="{height: pageData.tableHeight +30+ 'px'}">
      <MyTable
        :tableData="pageData.tableData"
        :tableColumn="pageData.tableColumn"
        :tableHeight="pageData.tableHeight"
        :key="pageData.keyCount"
        :tableConfiger="pageData.tableConfiger"
        :controlsWidth="pageData.controlsWidth"
      >
      </MyTable>
      <Pages
        @changeNo="changeNo"
        @changeSize="changeSize"
        :tableHeight="pageData.tableHeight"
        :pageConfiger="{
          ...pageData.pageConfiger,
          total: pageData.total
        }"
      />
    </div>
    />
  </div>
</template>

<script setup>
import MyTable from "@/components/aboutTable/MyTable.vue";
import Pages from "@/components/aboutTable/Pages.vue";
import Search from "@/components/aboutTable/Search.vue";
import { qcckGet } from "@/api/qcckApi.js";
import { reactive, ref, onMounted } from "vue";
const searchBox = ref(); //搜索框
const searchConfiger = ref([
  { label: "申请人姓名", prop: "xm", placeholder: "请输入申请人姓名", showType: "input" },
  { label: "申请人身份证", prop: "sfzh", placeholder: "请输入申请人身份证号", showType: "input"},
  { label: "申请人联系电话", prop: "lxdh", placeholder: "请输入申请人联系电话", showType: "input"}
]);

const pageData = reactive({
  tableData: [],
  keyCount: 0,
  tableConfiger: {
    rowHieght: 61,
    showSelectType: "null",
    loading: false,
    haveControls: false
  },
  total: 0,
  pageConfiger: {
    pageSize: 20,
    pageCurrent: 1
  },
  controlsWidth: 200,
  tableColumn: [
    { label: "申请人姓名", prop: "xm" },
    { label: "申请人身份证", prop: "sfzh"},
    { label: "申请人联系电话", prop: "lxdh" },
     { label: "提交人姓名", prop: "tjrxm"},
    { label: "提交人身份证号", prop: "tjrsfzh"},
    { label: "权限说明", prop: "qxsm", showOverflowTooltip: true },
  ]
});

const queryFrom = ref({});

onMounted(() => {
  getList();
  tabHeightFn();
});

// 搜索
const onSearch = (val) => {
  queryFrom.value = { ...val };
  pageData.pageConfiger.pageCurrent = 1;
  getList();
};

const changeNo = (val) => {
  pageData.pageConfiger.pageCurrent = val;
  getList();
};
const changeSize = (val) => {
  pageData.pageConfiger.pageSize = val;
  getList();
};

// 获取列表
const getList = () => {
    pageData.tableConfiger.loading = true;
    let data = { ...pageData.pageConfiger, ...queryFrom.value };
    qcckGet(data, "/mosty-gsxt/gsxt/qxsq/getPageList").then((res) => {
      pageData.tableData = res.records || [];
      pageData.total = res.total;
      pageData.tableConfiger.loading = false;
    }).catch(() => {
      pageData.tableConfiger.loading = false;
    });
};

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

<style>
.el-loading-mask {
  background: rgba(0, 0, 0, 0.5) !important;
}
</style>
