<!-- 车辆比中日志 -->
<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="所属部门">
          <MOSTY.Department
            width="100%"
            clearable
            v-model="listQuery.ssbmdm"
          />
        </el-form-item>

        <el-form-item label="号牌号码">
          <el-input
            v-model="listQuery.hphm"
            placeholder="请输入号牌号码"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="盘查日期">
          <el-date-picker
            v-model="dataRange"
            type="daterange"
            unlink-panels
            placeholder="请选择盘查日期"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :size="size"
            format="YYYY-MM-DD"
            value-format="YYYY-MM-DD"
          />
        </el-form-item>
        <!-- <el-form-item label="盘查时间">
          <el-time-picker v-model="value1" placeholder="请选择盘查时间" />
        </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_CLBQ"
              :key="index"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item label="盘查处理结果">
          <el-select
            v-model="listQuery.pcclJg"
            placeholder="请选择"
            style="width: 100%"
          >
            <el-option
              v-for="(item, index) in D_BZ_PCCLJG"
              :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"
        ref="dataTreeList"
        :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 }">
            <img
              :src="
                'http://10.64.201.128:2366/xlpcAdminNew/requestservice/czrk/ryxp.jpg?sfzh=' +
                row.jdcsyrsfzh
              "
              width="75"
            />
          </template>
        </el-table-column>
        <el-table-column
          label="所属部门"
          prop="ssbm"
          align="center"
          width="180"
        />
        <el-table-column
          label="盘查民警姓名"
          prop="xtCjr"
          align="center"
          width="180"
        />
        <el-table-column
          label="号牌号码"
          prop="hphm"
          align="center"
          width="180"
        />
        <el-table-column
          label="号牌种类"
          prop="hpzl"
          align="center"
          width="180"
        >
          <template #default="{ row }">
            <dict-tag :options="D_BZ_HPZL" :value="row.hpzl" :tag="false" />
          </template>
        </el-table-column>
        <el-table-column
          label="机动车所有人"
          prop="jdcsyr"
          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="bqmc"
          align="center"
          width="180"
        >
          <!-- <template #default="{ row }">
            <dict-tag
                :options="D_BZ_CLBQ"
                :value="row.bqmc"
                :tag="false"
              />
          </template> -->
        </el-table-column>
        <el-table-column
          label="盘查处理结果"
          prop="pcclJgmc"
          align="center"
          width="180"
        />

        <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
            :loading="loading"
            type="primary"
            size="small"
            @click="submit"
            >保存</el-button
          > -->
          <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.jdcsyrsfzh" width="75"/>
        </el-form-item>
        <el-form-item label="所属部门" prop="name">
          <el-input v-model="detailList.ssbm"></el-input>
        </el-form-item>
        <el-form-item label="号牌号码" prop="name">
          <el-input v-model="detailList.hphm"></el-input>
        </el-form-item>
        <el-form-item label="号牌种类" prop="name">
          <el-input v-model="detailList.hpzlmc"></el-input>
        </el-form-item>
        <el-form-item label="车架号" prop="name">
          <el-input v-model="detailList.clsbdh"></el-input>
        </el-form-item>
        <el-form-item label="机动车所有人" prop="name">
          <el-input v-model="detailList.jdcsyr"></el-input>
        </el-form-item>
        <el-form-item label="机动车所有人身份证号" prop="name">
          <el-input v-model="detailList.jdcsyrsfzh"></el-input>
        </el-form-item>
        <el-form-item label="盘查日期" prop="name">
          <el-input v-model="detailList.pcrq"></el-input>
        </el-form-item>
        <el-form-item label="盘查时间" prop="name">
          <el-input v-model="detailList.pcsj"></el-input>
        </el-form-item>
        <el-form-item label="盘查输入类型" prop="name">
          <el-input v-model="detailList.pcsrlxmc"></el-input>
        </el-form-item>
        <el-form-item label="车辆标签" prop="name">
          <el-input v-model="detailList.bqmc"></el-input>
        </el-form-item>
        <el-form-item label="盘查处理结果" prop="name">
          <el-input v-model="detailList.pcclJgmc"></el-input>
        </el-form-item>
        <el-form-item label="盘查民警姓名" prop="name">
          <el-input v-model="detailList.xtCjr"></el-input>
        </el-form-item>
        <el-form-item label="盘查民警警号" prop="name">
          <el-input v-model="detailList.pcmjJh"></el-input>
        </el-form-item>
        <el-form-item label="移交单位" prop="name">
          <el-input v-model="detailList.pcclYjdw"></el-input>
        </el-form-item>
        <el-form-item label="移交原因" prop="name">
          <el-input v-model="detailList.pcclYjyy"></el-input>
        </el-form-item>
   
      </el-form>
      
        <div class="head_box">
          <span class="title">盘查图片</span>
        </div>
      <div v-if="detailList.tpList && detailList.tpList.length > 0">
        <el-form
          ref="elform"
          :model="detailList"
          :rules="rules"
          :inline="true"
          label-position="top"
        >
          <el-image
            v-for="(item, index) in detailList.tpList"
            :key="index"
            :src="`/mosty-api/mosty-base/minio/image/download/${item.fjid}`"
            style="
              width: 100px;
              height: 100px;
              margin: 10px 0 10px 20px;
              display: inline-block;
            "
          />
        </el-form>
      </div>

      
        <div class="head_box">
          <span class="title">盘查物品</span>
        </div>
      <div v-if="detailList.wpVoList && detailList.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 detailList.wpVoList[0]?.wpTpIdList"
                :key="index"
                :src="`/mosty-api/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="detailList.wpVoList[0].wpms"></el-input>
          </el-form-item>
          <el-form-item label="物品数量" prop="name">
            <el-input v-model="detailList.wpVoList[0].wpsl"></el-input>
          </el-form-item>
          <el-form-item label="物品类型" prop="name">
            <el-input v-model="detailList.wpVoList[0].wplx"></el-input>
          </el-form-item>
        </el-form>
      </div>

      <div v-if="detailList.ryList && detailList.ryList.length > 0">
        <div class="head_box">
          <span class="title">同乘人员</span>
        </div>
        <div v-for="(item, index) in detailList.ryList" :key="index">
        <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=' +
                  item.sfzh
                "
                width="75"
              />
            </el-form-item>
            <el-form-item label="姓名" prop="name">
              <el-input v-model="item.xm"></el-input>
            </el-form-item>
            <el-form-item label="出生日期" prop="name">
              <el-input v-model="item.csrq"></el-input>
            </el-form-item>
            <el-form-item label="标签名称" prop="name">
              <el-input v-model="item.bqxxsj"></el-input>
            </el-form-item>
            <el-form-item label="居住详址" prop="name">
              <el-input v-model="item.zzxz"></el-input>
            </el-form-item>
            <el-form-item label="盘查结果" prop="name">
              <el-input v-model="item.pcclJgmc"></el-input>
            </el-form-item>
            <el-form-item label="盘查民警姓名" prop="name">
              <el-input v-model="item.pcmjXm"></el-input>
            </el-form-item>
            <el-form-item label="盘查民警所属部门" prop="name">
              <el-input v-model="item.ssbm"></el-input>
            </el-form-item>
          
        </el-form>
        </div>
      </div>
    </div>

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

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 dataRange = ref([]);
const ryform = ref({})
const daglShow = ref(false)
// 车辆标签 盘查处理结果 机动车号牌种类代码 盘查输入类型
const { D_BZ_CLBQ, D_BZ_PCCLJG, D_BZ_HPZL, D_BZ_PCSRLX,D_BZ_XB } = proxy.$dict(
  "D_BZ_CLBQ",
  "D_BZ_PCCLJG",
  "D_BZ_HPZL",
  "D_BZ_PCSRLX",
  'D_BZ_XB'
);
const listQuery = ref({
  pageCurrent: 1,
  pageSize: 10,
  kssj: "",
  jssj: "",
  hphm: "",
  ssbmdm: "",
  pcclJg: ""
}); //搜索表单

//表单验证
const rules = ref({
  name: [{ required: true, message: "请输入名称", trigger: "change" }]
});

// 获取列表
function getListData() {
  tableData.value = [];
  loadingTable.value = true;
  if (dataRange.value.length > 0) {
    listQuery.value.kssj = dataRange.value[0];
    listQuery.value.jssj = dataRange.value[1];
  }
  getClpcList(listQuery.value).then((res) => {
    res.records.forEach(item => {
      if(item.bqmc && item.bqmc != ""){
        tableData.value.push(item);
      }
    })
    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: "修改成功"
        });
      }
    }
  });
}
const detailList = ref({});
//修改
function detail(row) {
  detailList.value = row;
  D_BZ_PCCLJG.value.forEach((item) => {
    if (detailList.value.pcclJg == item.value) {
      detailList.value.pcclJgmc = item.label;
    }
  });
  D_BZ_HPZL.value.forEach((item) => {
    if (detailList.value.hpzl == item.value) {
      detailList.value.hpzlmc = item.label;
    }
  });
  D_BZ_PCSRLX.value.forEach((item) => {
    if (detailList.value.pcsrlx == item.value) {
      detailList.value.pcsrlxmc = item.label;
    }
  });
  chackAdd.value = false;
  form.value = row;
  title.value = "详情";
  dialogFormVisible.value = true;
}
//批量数据
const handleSelectionChange = (val) => {
  ids.value = [];
  if (val) {
    val.forEach((item) => {
      ids.value.push(item.id);
    });
  }
};
//删除
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();
};
//获取人员档案
function update(row) {
  const data = {
    // api_userid: '511121197206109395',
    // zjhm: '511121197206109395'
    api_userid: row.pcmjSfzh,
    zjhm: row.jdcsyrsfzh
  };
  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) => {});
}
//点击重置
const reset = () => {
  listQuery.value = {
    pageCurrent: 1,
    pageSize: 10,
    kssj: "",
    jssj: "",
    hphm: "",
    ssbmdm: "",
    pcclJg: ""
  };
  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: 10px 0px;
  border-radius: 5px;
}
::v-deep .content.el-col {
  border-radius: 4px;
  border: 1px solid rgb(216, 32, 32);
  padding: 10px 0;
}
</style>
