<template>
  <div>
    <div class="titleBox">
      <PageTitle title="重点人管理">
        <el-popover placement="bottom" :visible="visible" :width="400" trigger="click">
            <template #reference>
              <el-button type="primary" @click="visible =!visible" size="small">布控申请
            </el-button>
            </template>
            <div class="flex just-center">
              <el-button size="small" type="primary">列控申请</el-button>
              <el-button size="small" type="primary">变更申请</el-button>
              <el-button size="small" type="primary">管控申请</el-button>
              <el-button size="small" type="primary">协控申请</el-button>
            </div>
          </el-popover>
          <el-button size="small" type="primary">指定分配</el-button>
          <el-button size="small" type="primary">转线索</el-button>
          <el-button size="small" type="primary">移交管控</el-button>
        <el-button type="primary" size="small" @click="addEdit('add', '')">
          <el-icon style="vertical-align: middle"><CirclePlus /></el-icon>
          <span style="vertical-align: middle">新增</span>
        </el-button>
      </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 #ryxx="{ row }">
          <div>
            <img src="" alt="" />
            <ul>
              <li>姓名：{{ row.ryXm }}</li>
              <li class="rowClass"> 性别：<DictTag :tag="false" :value="row.ryXb" :options="D_BZ_XB" /></li>
              <li class="rowClass">籍贯：<DictTag :tag="false" :value="row.ryJg" :options="D_BZ_XZQHDM"/> </li>
              <li>身份证：{{ row.rySfzh }}</li>
              <li>出生日期：{{ row.ryCsrq }}</li>
              <li class="rowClass">民族：<DictTag :tag="false" :value="row.ryMz" :options="D_BZ_MZ" /></li>
            </ul>
          </div>
          <div class="flex">
            <el-button :key="index" type="primary" size="small" v-for="(item, index) in row.bqList">{{ item.bqMc }}</el-button>
          </div>
        </template>
        <template #jzxx="{ row }">
          <div class="rowClass">户籍地区划：<DictTag :tag="false" :value="row.hjdQh" :options="D_BZ_XZQHDM" /></div>
          <div>户籍派出所：{{ row.hjdPcsmc }}</div>
          <div>户籍地详址：{{ row.hjdXz }}</div>
        </template>
        <template #gxdw="{ row }">
          <div>管辖单位：{{ row.gxSsbmmc }}</div>
          <div class="rowClass">人员级别： <DictTag :tag="false" :value="row.zdrRyjb" :options="D_GS_ZDR_RYJB"/> </div>
          <div>管控原因：{{ zdrLkyy }}</div>
          <div class="rowClass">管控状态：<DictTag :tag="false" :value="row.zdrBkZt" :options="D_GS_ZDR_BK_ZT"/></div>
        </template>
        <template #zdrCzzt="{ row }">
          <DictTag :tag="false" :value="row.zdrCzzt" :options="D_GS_ZDR_CZZT" />
        </template>
        <template #xtSjzt="{ row }">
          <div>{{ row.xtSjzt == 0 ? "注销" : row.xtSjzt == 1 ? "正常" : "封存" }}</div>
        </template>

        <!-- 操作 -->
        <template #controls="{ row }">
          <el-link size="small" type="success" @click="addEdit('edit', row)">编辑</el-link >
          <el-link size="small" type="danger" @click="deleteRow(row)" >删除</el-link>
        </template>
      </MyTable>
      <Pages
        @changeNo="changeNo"
        @changeSize="changeSize"
        :tableHeight="pageData.tableHeight"
        :pageConfiger="{
          ...pageData.pageConfiger,
          total: pageData.total
        }"
      ></Pages>
    </div>
    <!-- 详情 -->
    <AddForm ref="addFormDiloag" v-if="show" :dic="{D_GS_ZDR_RYJB,D_BZ_XB,D_BZ_MZ,D_BZ_XZQHDM,D_GS_ZDR_BK_ZT,D_GS_ZDR_CZZT,D_GS_BQ_ZL,D_GS_BQ_LB,D_GS_BQ_LX,D_GS_ZDR_YJDJ,D_GS_BK_SSJZ}" />
  </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 Search from "@/components/aboutTable/Search.vue";
import AddForm from "./components/addForm.vue";
import { qcckGet } from "@/api/qcckApi.js";
import { reactive, ref, onMounted, getCurrentInstance } from "vue";
const { proxy } = getCurrentInstance();
const {D_GS_ZDR_RYJB,D_BZ_XB,D_BZ_MZ,D_BZ_XZQHDM,D_GS_ZDR_BK_ZT,D_GS_ZDR_CZZT,D_GS_BQ_ZL,D_GS_BQ_LB,D_GS_BQ_LX,D_GS_ZDR_YJDJ,D_GS_BK_SSJZ } = proxy.$dict("D_GS_ZDR_RYJB","D_BZ_XB","D_BZ_MZ","D_BZ_XZQHDM","D_GS_ZDR_BK_ZT","D_GS_ZDR_CZZT","D_GS_BQ_ZL","D_GS_BQ_LB","D_GS_BQ_LX","D_GS_ZDR_YJDJ","D_GS_BK_SSJZ"); 
const show = ref(false);
const addFormDiloag = ref();
const searchBox = ref(); //搜索框
const searchConfiger = ref([
  {
    label: "姓名",
    prop: "ryXm",
    placeholder: "请输入姓名",
    showType: "input"
  },
  {
    label: "身份证",
    prop: "rySfzh",
    placeholder: "请输入身份证",
    showType: "input"
  },
  {
    label: "户籍地",
    prop: "hjdXz",
    placeholder: "请输入户籍地",
    showType: "input"
  },
  {
    label: "人员级别",
    prop: "zdrRyjb",
    placeholder: "请输入人员级别",
    showType: "select",
    options: D_GS_ZDR_RYJB
  },
]);

const pageData = reactive({
  tableData: [],
  keyCount: 0,
  tableConfiger: {
    rowHieght: 61,
    showSelectType: "null",
    loading: false
  },
  total: 0,
  pageConfiger: {
    pageSize: 20,
    pageCurrent: 1
  },
  controlsWidth: 220,
  tableColumn: [
    { label: "重点人员信息", prop: "ryxx", showSolt: true },
    { label: "户籍居住信息", prop: "jzxx", showSolt: true },
    { label: "管辖单位", prop: "gxdw", showSolt: true },
    { label: "处置状态", prop: "zdrCzzt", showSolt: true },
    { label: "状态", prop: "xtSjzt", showSolt: true }
  ]
});

const queryFrom = ref({});

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

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

const changeNo = (val) => {
  pageData.pageConfiger.pageNum = 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-gsxt/tbGsxtZdry/selectPage").then((res) => {
    pageData.tableData = res.records || [];
    pageData.total = res.total;
    pageData.tableConfiger.loading = false;
  }).catch(() => {
    pageData.tableConfiger.loading = false;
  });
};

//新增编辑
const addEdit = (type, row) => {
  show.value = true;
  setTimeout(() => {
    addFormDiloag.value.init(type, row);
  },400);
};

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

<style>
.el-loading-mask {
  background: rgba(0, 0, 0, 0.5) !important;
}
.rowClass {
  display: flex;
  align-items: center;
  justify-content: center;
}
</style>
