<!-- 人员战果 -->
<template>
  <div>
    <div class="titleBox">
      <div class="title">人员战果</div>
      <div class="btnBox"></div>
    </div>
    <div class="searchBox" ref="searchBox">
      <el-form :model="listQuery" :inline="true">
        <el-form-item label="被盘查人姓名">
          <el-input
            v-model="listQuery.xm"
            placeholder="请输入被盘查人姓名"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="被盘查人电话号码">
          <el-input
            v-model="listQuery.lxdh"
            placeholder="请输入被盘查人电话号码"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="被盘查人身份证号">
          <el-input
            v-model="listQuery.sfzh"
            placeholder="请输入被盘查人身份证号"
            clearable
          ></el-input>
        </el-form-item>
        <!-- <el-form-item label="人员标签">
          <el-select
            v-model="form.jwzLx"
            placeholder="请选择"
            style="width: 100%"
          >
            <el-option
              v-for="(item, index) in D_BZ_RYBQ"
              :key="index"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item>
          <el-button @click="handleFilter"> 查询 </el-button>
          <el-button @click="reset()"> 重置 </el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="tabBox">
      <el-table
        :data="tableData"
        border
        row-key="id"
        :tree-props="{ children: 'itemList', hasChildren: true }"
        style="width: 100%"
        :key="keyCount"
        :height="tableHeight"
        v-loading="loadingTable"
        element-loading-background="rgba(0,0,0,0.3)"
        element-loading-text="数据加载中。。"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="40" align="center" />
        <el-table-column label="序号" type="index" align="center" width="80" />
        <el-table-column label="照片" prop="tp" align="center" width="180">
           <template #default="{ row }">
            <div v-if="row.tpList?.[0]">
              <el-image
                :append-to-body="true"
                :preview-src-list="[
                  `/bagl/mosty-base/minio/image/download/${row.tpList?.[0].fjid}`
                ]"
                style="width: 75px"
                :src="`/bagl/mosty-base/minio/image/download/${row.tpList?.[0].fjid}`"
                fit="cover"
                lazy
              />
            </div>
            <el-image
              style="width: 75px"
              :append-to-body="true"
              v-else
              :src="Person"
              :preview-src-list="[Person]"
              fit="cover"
              lazy
            />
          </template>
        </el-table-column>
        <el-table-column
          label="所属部门"
          prop="ssbm"
          align="center"
          width="180"
        />
        <el-table-column
          label="盘查民警姓名"
          prop="pcmjXm"
          align="center"
          width="180"
        />
        <el-table-column
          label="被盘查人姓名"
          prop="xm"
          align="center"
          width="180"
        />
        <el-table-column
          label="被盘查人身份证号"
          prop="sfzh"
          align="center"
          width="180"
        />
        <el-table-column
          label="被盘查人联系电话"
          prop="lxdh"
          align="center"
          width="180"
        />
        <el-table-column
          label="盘查日期"
          prop="pcrq"
          align="center"
          width="180"
        />
        <el-table-column
          label="盘查时间"
          prop="pcsj"
          align="center"
          width="180"
        />
        <el-table-column
          label="盘查输入类型"
          prop="pcsrlx"
          align="center"
          width="180"
        >
          <template #default="{ row }">
            <dict-tag :options="D_BZ_PCSRLX" :value="row.pcsrlx" :tag="false" />
          </template>
        </el-table-column>
        <el-table-column
          label="人员标签"
          prop="bqxxsj"
          align="center"
          width="180"
        />
        <el-table-column label="盘查处理结果" align="center" width="180">
          <template #default="{ row }">
            <dict-tag :options="D_BZ_PCCLJG" :value="row.pcclJg" :tag="false" />
          </template>
        </el-table-column>

        <el-table-column
          label="操作"
          align="center"
          fixed="right"
          width="250px"
        >
          <template #default="{ row }">
            <el-button @click="detail(row)" size="small">详情</el-button>
            <el-button @click="update(row)" size="small">档案管理</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="fenye" :style="{ top: tableHeight + 'px' }">
        <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 class="dialog" v-if="daglShow">
      <div class="head_box">
        <span class="title">人员档案</span>
        <div>
          <el-button size="small" @click="daglShow = false">关闭</el-button>
        </div>
      </div>
      <el-form :model="ryform" :inline="true" label-position="top" disabled>
        <el-form-item label="人员姓名">
          <el-input v-model="ryform.XM"></el-input>
        </el-form-item>
        <el-form-item label="性别">
          <el-select v-model="ryform.XBDM">
            <el-option
              v-for="(dict, index) in D_BZ_XB"
              :key="index + 'xb'"
              :value="dict.value"
              :label="dict.label"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="身份证">
          <el-input v-model="ryform.ZJHM"></el-input>
        </el-form-item>
        <el-form-item label="民族">
          <el-select v-model="ryform.MZDM">
            <el-option
              v-for="(dict, index) in D_BZ_MZ"
              :key="index + 'mz'"
              :value="dict.value"
              :label="dict.label"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="联系电话">
          <el-input v-model="ryform.LXDH"></el-input>
        </el-form-item>
        <el-form-item style="width: 48%" label="居住地址">
          <el-input v-model="ryform.JZD_DZXZ"></el-input>
        </el-form-item>
        <el-form-item style="width: 48%" label="户籍地址">
          <el-input v-model="ryform.HJD_DZXZ"></el-input>
        </el-form-item>
      </el-form>
    </div>
    <div class="dialog" v-if="dialogFormVisible">
      <div class="head_box">
        <span class="title">{{ title }}</span>
        <div>
          <el-button size="small" @click="close">关闭</el-button>
        </div>
      </div>
      <el-form
        ref="elform"
        :model="form"
        :rules="rules"
        :inline="true"
        label-position="top"
      >
        <el-form-item label="图片" prop="name">
          <img
            :src="
              'http://10.64.201.128:2366/xlpcAdminNew/requestservice/czrk/ryxp.jpg?sfzh=' +
              form.sfzh
            "
            width="75"
          />
        </el-form-item>
        <el-form-item label="所属部门" prop="name">
          <el-input v-model="form.ssbm"></el-input>
        </el-form-item>
        <el-form-item label="盘查民警姓名" prop="name">
          <el-input v-model="form.pcmjXm"></el-input>
        </el-form-item>
        <el-form-item label="盘查民警警号" prop="name">
          <el-input v-model="form.pcmjJh"></el-input>
        </el-form-item>
        <el-form-item label="被盘查人姓名" prop="name">
          <el-input v-model="form.xm"></el-input>
        </el-form-item>
        <el-form-item label="被盘查人身份证号" prop="name">
          <el-input v-model="form.sfzh"></el-input>
        </el-form-item>
        <el-form-item label="被盘查人性别" prop="name">
          <el-input v-model="form.sexmc"></el-input>
        </el-form-item>
        <el-form-item label="被盘查人出生日期" prop="name">
          <el-input v-model="form.csrq"></el-input>
        </el-form-item>
        <el-form-item label="被盘查人民族" prop="name">
          <el-input v-model="form.mzmc"></el-input>
        </el-form-item>
        <el-form-item label="被盘查人学历" prop="name">
          <el-input v-model="form.whcdmc"></el-input>
        </el-form-item>
        <el-form-item label="被盘查人籍贯" prop="name">
          <el-input v-model="form.jgdm"></el-input>
        </el-form-item>
        <el-form-item label="被盘查人住址详址" prop="name">
          <el-input v-model="form.zzxz"></el-input>
        </el-form-item>
        <el-form-item label="被盘查人联系电话" prop="name">
          <el-input v-model="form.lxdh"></el-input>
        </el-form-item>
        <el-form-item label="盘查日期" prop="name">
          <el-input v-model="form.pcrq"></el-input>
        </el-form-item>
        <el-form-item label="盘查时间" prop="name">
          <el-input v-model="form.pcsj"></el-input>
        </el-form-item>
        <el-form-item label="盘查输入类型" prop="name">
          <el-input v-model="form.pcsrlxmc"></el-input>
        </el-form-item>
        <el-form-item label="人员标签" prop="name">
          <el-input v-model="form.bqxxsj"></el-input>
        </el-form-item>
        <el-form-item label="盘查处理结果" prop="name">
          <el-input v-model="form.pcclJgmc"></el-input>
        </el-form-item>
        <el-form-item label="移交单位" prop="name">
          <el-input v-model="form.pcclYjdw"></el-input>
        </el-form-item>
        <el-form-item label="移交原因" prop="name">
          <el-input v-model="form.pcclYjyy"></el-input>
        </el-form-item>
      </el-form>

      <div class="head_box">
        <span class="title">盘查图片</span>
      </div>
      <el-form
        ref="elform"
        :model="form"
        :rules="rules"
        :inline="true"
        label-position="top"
      >
        <div v-if="form.tpList && form.tpList.length > 0">
          <el-image
            v-for="(item, index) in form.tpList"
            :key="index"
            :src="`/bagl/mosty-base/minio/image/download/${item.fjid}`"
            style="
              width: 100px;
              height: 100px;
              margin: 10px 0 10px 20px;
              display: inline-block;
            "
          />
        </div>
      </el-form>
      <div class="head_box">
        <span class="title">盘查物品</span>
      </div>
      <div v-if="form.wpVoList && form.wpVoList.length > 0">
        <el-form
          ref="elform"
          :model="form"
          :rules="rules"
          :inline="true"
          label-position="top"
        >
          <el-form-item label="物品图片" prop="name">
            <div style="height: 120px; display: inline-block">
              <el-image
                v-for="(item, index) in form.wpVoList[0]?.wpTpIdList"
                :key="index"
                :src="`/bagl/mosty-base/minio/image/download/${item}`"
                style="
                  width: 100px;
                  height: 100px;
                  margin: 10px 0 10px 20px;
                  display: inline-block;
                "
              />
            </div>
          </el-form-item>
          <el-form-item label="物品描述" prop="name">
            <el-input v-model="form.wpVoList[0].wpms"></el-input>
          </el-form-item>
          <el-form-item label="物品数量" prop="name">
            <el-input v-model="form.wpVoList[0].wpsl"></el-input>
          </el-form-item>
          <el-form-item label="物品类型" prop="name">
            <el-input v-model="form.wpVoList[0].wplx"></el-input>
          </el-form-item>
        </el-form>
      </div>
    </div>

    <!-- 档案管理 -->
    <DDGL :dialogddglVisible="dialogddglVisible" :ddglList="ddglList"></DDGL>
  </div>
</template>
<script setup>
import Person from "@/assets/images/default_male.png";
import { getRypcList, getHjyjData } from "@/api/xfzg";
import { ref, getCurrentInstance, onMounted } from "vue";
import * as MOSTY from "@/components/MyComponents/index";
const { proxy } = getCurrentInstance();

const keyCount = ref(0); //tabel组件刷新值
const form = ref({}); //新增表单
const tableData = ref([]); //表格数据
const total = ref(0);
const chackAdd = ref(false); //新增修改切换
const loading = ref(false); //新增保存按钮截流
const ids = ref([]); //表格选中id集合
const searchBox = ref(null); //搜索盒子
const loadingTable = ref(true); //表格加载状态
const tableHeight = ref(); // 表格高度
const dialogFormVisible = ref(false);
const title = ref("详情"); //弹窗标题
const elform = ref(null); //新增表单容器
const ryform = ref({});
const daglShow = ref(false);
// 人员标签
const { D_BZ_RYBQ } = proxy.$dict("D_BZ_RYBQ");
// 盘查处理结果
const { D_BZ_PCCLJG, D_BZ_PCSRLX, D_BZ_MZ, D_BZ_WHCD, D_BZ_XB } = proxy.$dict(
  "D_BZ_PCCLJG",
  "D_BZ_PCSRLX",
  "D_BZ_MZ",
  "D_BZ_WHCD",
  "D_BZ_XB"
);
const listQuery = ref({
  pageCurrent: 1,
  pageSize: 10,
  lxdh: "",
  xm: "",
  isbq: "1",
  sfzh: ""
}); //搜索表单
//表单验证
const rules = ref({
  name: [{ required: true, message: "请输入名称", trigger: "change" }]
});

// 获取列表
function getListData() {
  tableData.value = [];
  loadingTable.value = true;
  getRypcList(listQuery.value)
    .then((res) => {
      tableData.value =  res.records
      total.value = res.total;
      loadingTable.value = false;
    })
    .catch(() => {
      loadingTable.value = false;
    });
}
//打开新增弹窗
function add() {
  chackAdd.value = true;
  dialogFormVisible.value = true;
}
//关闭弹窗
function close() {
  dialogFormVisible.value = false;
  form.value = {};
}

//提交
function submit() {
  elform.value.validate((valid) => {
    if (valid) {
      loading.value = true;
      setTimeout(() => {
        loading.value = false;
      }, 1500);
      if (chackAdd.value) {
        proxy.$message({
          type: "success",
          message: "新增成功"
        });
      } else {
        proxy.$message({
          type: "success",
          message: "修改成功"
        });
      }
    }
  });
}
//修改
function detail(row) {
  chackAdd.value = false;
  form.value = row;
  form.value.sexmc = form.value.xbdm == "1" ? "男" : "女";
  D_BZ_PCSRLX.value.forEach((item) => {
    if (form.value.pcsrlx == item.value) {
      form.value.pcsrlxmc = item.label;
    }
  });
  D_BZ_MZ.value.forEach((item) => {
    if (form.value.mzdm == item.value) {
      form.value.mzmc = item.label;
    }
  });
  D_BZ_WHCD.value.forEach((item) => {
    if (form.value.whcddm == item.value) {
      form.value.whcdmc = item.label;
    }
  });
  title.value = "详情";
  dialogFormVisible.value = true;
}
//批量数据
const handleSelectionChange = (val) => {
  ids.value = [];
  if (val) {
    val.forEach((item) => {
      ids.value.push(item.id);
    });
  }
};
//获取人员档案
function update(row) {
  const data = {
    // api_userid: '511121197206109395',
    // zjhm: '511121197206109395'
    api_userid: row.pcmjSfzh,
    zjhm: row.sfzh
  };
  getHjyjData(data)
    .then((res) => {
      const { rows, msg } = res;
      if (rows && rows.length !== 0) {
        daglShow.value = true;
        ryform.value = rows[0];
      } else if (msg) {
        proxy.$message.error(msg);
      } else {
        proxy.$message.info("非本地人员");
      }
    })
    .catch((error) => {});
}
//删除
function delDictItem(row) {
  proxy
    .$confirm("确定要删除", "警告", {
      type: "warning"
    })
    .then(() => {
      // DELETE([row.id]).then(() => {
      //   proxy.$message({
      //     type: "success",
      //     message: "删除成功"
      //   });
      //   getListData();
      // });
    })
    .catch(() => {
      proxy.$message.info("已取消");
    });
}
//批量删除
function batchDelete() {
  proxy
    .$confirm("确定要删除", "警告", {
      type: "warning"
    })
    .then(() => {
      //       DELETE(ids.value).then((res) => {
      //         proxy.$message({
      //           message: "删除成功",
      //           type: "success"
      //         });
      //         getListData();
      //       });
    })
    .catch(() => {
      proxy.$message.info("已取消");
    });
}
//点击查询
const handleFilter = () => {
  listQuery.value.pageCurrent = 1;
  getListData();
};
//点击重置
const reset = () => {
  listQuery.value = {
    pageCurrent: 1,
    pageSize: 10,
    lxdh: "",
    isbq: "1",
    xm: "",
    sfzh: ""
  };
  getListData();
};
// 表格高度计算
const tabHeightFn = () => {
  tableHeight.value = window.innerHeight - searchBox.value.offsetHeight - 240;
};
/**
 * pageSize 改变触发
 */
const handleSizeChange = (currentSize) => {
  listQuery.value.pageSize = currentSize;
  getListData();
};

/**
 * 页码改变触发
 */
const handleCurrentChange = (currentPage) => {
  listQuery.value.pageCurrent = currentPage;
  getListData();
};
onMounted(() => {
  getListData();
  tabHeightFn();
  window.onresize = function () {
    tabHeightFn();
  };
  proxy.mittBus.on("mittFn", (data) => {
    keyCount.value = data;
  });
});
</script>
<style lang='scss' scoped>
@import "~@/assets/css/layout.scss";
@import "~@/assets/css/element-plus.scss";
::v-deep .el-row {
  margin-bottom: 20px;
}
</style>
