<template>
  <div>
    <div class="titleBox">
      <PageTitle title="人员盘查">
        <!-- <el-link type="primary" @click="addEdit('detail', row)">详情</el-link> -->
      </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"
        @chooseData="chooseData"
      >
        <template #yjTp="{ row }">
          <div class="phone">
            <el-image v-if="row.tp" :src="urlImg + row.yjTp" fit="cover" lazy />
            <el-image v-else :src="Person" fit="cover" lazy />
          </div>
        </template>
        <template #yjLx="{ row }">
          <dict-tag :options="D_BZ_YJLX" :value="row.yjLx" :tag="false" />
        </template>

        <!-- 操作 -->
        <template #controls="{ row }">
          <el-link type="primary" @click="addEdit('detail', row)">详情</el-link>
        </template>
      </MyTable>
      <Pages
        @changeNo="changeNo"
        @changeSize="changeSize"
        :tableHeight="pageData.tableHeight"
        :pageConfiger="{
          ...pageData.pageConfiger,
          total: pageData.total
        }"
      ></Pages>
    </div>
    <!-- 编辑详情 -->
    <!-- 编辑详情 -->
    <EditAddForm ref="detailDiloag" :dict="{ D_BZ_YJLX, D_BZ_YJJB }" />
  </div>
</template>

<script setup>
import PageTitle from "@/components/aboutTable/PageTitle.vue";
import MyTable from "@/components/aboutTable/MyTable.vue";
import Pages from "@/components/aboutTable/Pages.vue";
import EditAddForm from "./components/editAddForm.vue";
import Search from "@/components/aboutTable/Search.vue";
import { BpcryselectCrewList } from "@/api/mosty-jcz.js";
import { reactive, ref, onMounted, getCurrentInstance, watch } from "vue";
const { proxy } = getCurrentInstance();
const urlImg = "/mosty-api/mosty-base/minio/image/download/";
const { D_BZ_YJLX, D_BZ_YJJB } = proxy.$dict("D_BZ_YJLX", "D_BZ_YJJB");
const searchConfiger = ref([
  {
    label: "姓名",
    prop: "xm",
    placeholder: "请输入姓名",
    showType: "input"
  },
  {
    label: "身份证号",
    prop: "sfzh",
    placeholder: "请输入预警对象",
    showType: "input"
  },
  {
    label: "日期",
    prop: "startTime",
    placeholder: "日期",
    showType: "datetimerange"
  }
]);

const detailDiloag = ref();
const pageData = reactive({
  tableData: [], //表格数据
  keyCount: 0,
  tableConfiger: {
    rowHieght: 61,
    showSelectType: "null",
    loading: false
  },
  total: 0,
  pageConfiger: {
    pageSize: 20,
    pageCurrent: 1
  }, //分页
  controlsWidth: 250, //操作栏宽度
  tableColumn: [
    { label: "照片", prop: "xm" },
    { label: "所属部门", prop: "ssbm" },
    { label: "盘查民警", prop: "pcmjXm" },
    { label: "被盘查人", prop: "xm" },
    { label: "被盘查人身份证", prop: "sfzh" },
    { label: "被盘查人电话", prop: "lxdh" },
    { label: "盘查日期", prop: "pcrq", showSolt: true },
    { label: "盘查时间", prop: "pcsj", showSolt: true },
    { label: "被盘输入类型", prop: "yjLx", showSolt: true },
    { label: "人员标签名称", prop: "bqmc", showSolt: true },
    { label: "盘查结果", prop: "pcclJgmc", showSolt: true }
  ]
});
onMounted(() => {
  tabHeightFn();
});

//查询条件
const queryCondition = ref({});
// 获取数据
const getjczgetXfllList = () => {
  pageData.tableConfiger.loading = true;
  const promes = { ...queryCondition.value, ...pageData.pageConfiger };
  BpcryselectCrewList(promes)
    .then((res) => {
      pageData.tableData = res.records;
      pageData.total = res.total;
    })
    .finally(() => {
      pageData.tableConfiger.loading = false;
    });
};
getjczgetXfllList();
// 搜索
const onSearch = (val) => {
  const promes = {
    startTime: "",
    endTime: ""
  };
  if (val.startTime) {
    promes.startTime = val.startTime[0];
    promes.endTime = val.startTime[1];
  } else {
    promes.startTime = "";
    promes.endTime = "";
  }
  queryCondition.value = { ...queryCondition.value, ...val, ...promes };
  getjczgetXfllList();
};

const changeNo = (val) => {
  pageData.pageConfiger.pageNum = val;
};
const changeSize = (val) => {
  pageData.pageConfiger.pageSize = val;
};
// 新增
const addEdit = (type, row) => {
  detailDiloag.value.init(type, row);
};
const searchBox = ref(null);
// 表格高度计算
const tabHeightFn = () => {
  pageData.tableHeight =
    window.innerHeight - searchBox.value.offsetHeight - 280;
  window.onresize = function () {
    tabHeightFn();
  };
};
</script>

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