<template>
  <div class="titleBox">
    <PageTitle title="街面状况"></PageTitle>
  </div>
  <!-- 搜索 -->
  <div ref="searchBox">
    <Search :searchArr="searchConfiger" @submit="onSearch" :key="pageData.keyCount" />
  </div>
  <!-- 表格 -->
  <div class="tabBox">
    <MyTable :tableData="pageData.tableData" :tableColumn="pageData.tableColumn" :tableHeight="pageData.tableHeight"
      :key="pageData.keyCount" :tableConfiger="pageData.tableConfiger" :controlsWidth="pageData.controlsWidth">
      <template #ddmjList="{ row }">
        <span>{{ row.ddmjList.length }}</span>
      </template>
      <template #controls="{ row }">
        <el-link type="primary" link @click="addEdit(row)">详情</el-link>
      </template>
    </MyTable>
    <Pages @changeNo="changeNo" @changeSize="changeSize" :tableHeight="pageData.tableHeight" :pageConfiger="{
      ...pageData.pageConfiger,
      total: pageData.total
    }"></Pages>
  </div>
  <!-- 详情 -->
  <DetailForm ref="detailDiloag" />
</template>

<script setup>
import Pages from "@/components/aboutTable/Pages.vue";
import MyTable from "@/components/aboutTable/MyTable.vue";
import Search from "@/components/aboutTable/Search.vue";
import DetailForm from "./components/detailForm.vue";
import PageTitle from "@/components/aboutTable/PageTitle.vue";
import { qcckGet } from "@/api/qcckApi.js";
import { reactive, ref, onMounted, getCurrentInstance } from "vue";
const searchBox = ref(); //搜索框
const detailDiloag = ref();
const searchConfiger = ref([
  {
    label: "勤务名称",
    prop: "qwmc",
    placeholder: "请输入勤务名称",
    showType: "input"
  }
]);

const queryFrom = ref({});
const pageData = reactive({
  tableData: [],
  keyCount: 0,
  tableConfiger: {
    rowHieght: 61,
    showSelectType: "null",
    loading: false,
    showIndex: true
  },
  total: 5,
  pageConfiger: {
    pageSize: 20,
    pageCurrent: 1
  },
  controlsWidth: 100,
  tableColumn: [
    { label: "辖区", prop: "ssxq" },
    { label: "日期", prop: "sbrq" },
    { label: "巡逻路线", prop: "xllx" },
    { label: "上报人", prop: "sbrxm" },
  ]
});
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 = (val) => {
  pageData.tableConfiger.loading = true;
  let data = { ...pageData.pageConfiger, ...queryFrom.value };
  qcckGet(data, "/mosty-jbld/jbjmzk/selelctPage")
    .then((res) => {
      pageData.tableData = res.records || [];
      pageData.total=res.total
      pageData.tableConfiger.loading = false;
    })
    .catch(() => {
      pageData.tableConfiger.loading = false;
    });
};

const addEdit = (row) => {
  detailDiloag.value.init(row);
};

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

<style></style>