<template>
  <div class="bigBox" v-if="modelValue">
    <div class="container">
      <div class="header">
        <span class="title">{{ title }}</span>
        <span class="close" @click="closeDialog">
          <el-icon :size="22"><CircleClose /></el-icon>
        </span>
      </div>
      <div class="search">
        <el-form ref="formRef" :model="listQuery">
          <el-form-item label="所属部门">
            <MOSTY.Department width="200px" clearable v-model="listQuery.ssbmdm" />
          </el-form-item>
          &nbsp;<el-form-item label=" 姓名">
            <el-input v-model="listQuery.jlxm" placeholder="请输入姓名"/>
          </el-form-item>
          &nbsp;<el-form-item label=" 警号">
            <el-input v-model="listQuery.jh" placeholder="请输入警号"/>
          </el-form-item>
          <el-form-item>
            <el-button class="serchBtn" @click="handleFilter"> 查询 </el-button>
            <el-button @click="reset()"> 重置 </el-button>
          </el-form-item>
        </el-form>
      </div>
      <div class="datalist">
        <el-table ref="multipleUserRef" :data="list.tableData" border width="100%" height="100%">
          <el-table-column label="序号"  type="index" align="center" width="80"/>
          <el-table-column prop="jlxm" show-overflow-tooltip align="center" label="姓名" />
          <el-table-column prop="xbdm" align="center" label="性别">
            <template #default="{ row }">
              <dict-tag :options="D_BZ_XB" :value="row.xbdm" :tag="false" />
            </template>
          </el-table-column>
          <el-table-column prop="sfzh" show-overflow-tooltip align="center" label="身份证号码" />
          <el-table-column prop="ssbm" label="所属部门" align="center" />
          <el-table-column prop="jh" label="警号" align="center" />
        </el-table>
      </div>
      <div class="fenye">
        <el-pagination
          class="pagination"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="listQuery.pageCurrent"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="listQuery.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>

<script setup>
import * as MOSTY from "@/components/MyComponents/index";
import emitter from "@/utils/eventBus.js";
import { getItem } from "@/utils/storage";
import { timeValidate } from "@/utils/time.js";
import { http } from "@/api/service";
import { ref, onMounted, onUnmounted, getCurrentInstance, reactive } from "vue";

const { proxy } = getCurrentInstance();
const { D_BZ_XB } = proxy.$dict("D_BZ_XB");
const list = reactive({
  tableData: []
});
const title = ref("");
const modelValue = ref(false);
const total = ref(0);
const listQueryDefault = ref({})
const listQuery = ref({
  pageCurrent: 1,
  pageSize: 20,
  ssbmdm: "",
  jlxm: "",
  jh: ""
});

onMounted(() => {
  listQueryDefault.value = JSON.parse(JSON.stringify(listQuery.value))
  emitter.on("showJLWindow", (res) => {
    title.value = res == "mj" ? "在岗警力-民警":"在岗警力-辅警"
    getList_Mj();
    modelValue.value = true;
  });
});
onUnmounted(() => {
  emitter.off("showJLWindow");
});
const handleCurrentChange = (currentPage) => {
  listQuery.value.pageCurrent = currentPage;
  getList_Mj();
};
// pageSize 改变触发
const handleSizeChange = (currentSize) => {
  listQuery.value.pageSize = currentSize;
  getList_Mj();
};
// 关闭弹窗
function closeDialog() {
  modelValue.value = false;
  listQuery.value = JSON.parse(JSON.stringify(listQueryDefault.value))
  list.tableData = [];
}
// 搜索
function handleFilter() {
  listQuery.value.pageCurrent = 1;
  getList_Mj();
}
//重置
function reset() {
  listQuery.value = JSON.parse(JSON.stringify(listQueryDefault.value))
  handleFilter();
}
// 警力情况 - 民警 - 全部
function getList_Mj() {
  let pramas = {
    pageCurrent: listQuery.value.pageCurrent,
    pageSize: listQuery.value.pageSize,
    ssbmdm: listQuery.value.ssbmdm,
    jlxm: listQuery.value.jlxm,
    jh: listQuery.value.jh,
    bbrq: timeValidate(new Date(), 'ymd')
  };

  if (title.value == "在岗警力-民警") {
    pramas.jllx = "01";
    http.getJlmj(pramas).then((res) => {
      list.tableData = res.records;
      total.value = res.total;
      listQuery.value.pageCurrent = res.current;
    });
  } else {
    pramas.jllx = "02";
    http.getJlfj(pramas).then((res) => {
      list.tableData = res.records;
      total.value = res.total;
      listQuery.value.pageCurrent = res.current;
    });
  }
}
</script>

<style lang="scss" scoped>
.bigBox {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 99;
  .container {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    margin: auto;
    width: 80%;
    height: 80vh;
    background: #052342;
    padding: 0 20px;
    .header {
      width: 100%;
      height: 60px;
      line-height: 60px;
      .title {
        float: left;
        font-size: 16px;
      }
      .close {
        float: right;
        font-size: 16px;
        cursor: pointer;
      }
    }
    .datalist {
      height: 60vh;
    }
    .fenye {
      height: 60px;
    }
  }
}
.el-form {
  display: flex;
}
.serchBtn {
  margin-left: 20px;
}
@import "~@/assets/css/layout.scss";
@import "~@/assets/css/element-plus.scss";
</style>
