<template>
  <div>
    <div class="titleBox">
      <div class="title">执勤警组管理</div>
      <div class="btnBox">
        <el-button type="primary" @click="add">
          <el-icon style="vertical-align: middle">
            <CirclePlus />
          </el-icon>
          <span style="vertical-align: middle">新增</span>
        </el-button>
        <el-button @click="batchDelete" :disabled="ids.length == 0" typeof="danger">
          <el-icon style="vertical-align: middle">
            <Delete />
          </el-icon>
          <span style="vertical-align: middle">批量删除</span>
        </el-button>
      </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.jzMc" placeholder="请输入警组名称" clearable />
        </el-form-item>

        <el-form-item label="负责人">
          <el-input v-model="listQuery.ddMjxm" placeholder="请输入负责人" clearable />
        </el-form-item>
        <el-form-item prop="qwdj" label="是否包含下级">
          <el-select v-model="listQuery.isChild">
            <el-option v-for="item in D_BZ_SF" :key="item" :label="item.label" :value="item.value">{{ item.label
              }}</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" style="width: 100%" :key="keyCount"
        @selection-change="handleSelectionChange" :height="tableHeight" v-loading="loadingTable"
        element-loading-background="rgba(0,0,0,0.3)" element-loading-text="数据加载中。。">
        <el-table-column type="selection" width="40" align="center" />
        <el-table-column type="index" show-overflow-tooltip align="center" width="60px" label="序号">
        </el-table-column>
        <el-table-column prop="ssbm" label="所属部门" show-overflow-tooltip></el-table-column>
        <el-table-column prop="jzMc" show-overflow-tooltip align="center" label="警组名称">
        </el-table-column>
        <el-table-column prop="ddMjxm" show-overflow-tooltip label="警组负责人" align="center">
        </el-table-column>
        <el-table-column prop="jzryList" show-overflow-tooltip align="center" label="警组成员">
          <template #default="{ row }">
            <el-tag v-for="(item, index) in row.jzryList" :key="index + 'jz'" class="mx-1">
              {{ item.jlxm }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="txzbList" show-overflow-tooltip label="智能装备">
          <template #default="{ row }">
            <el-tag v-for="(item, index) in row.txzbList" :key="index + 'zb'" class="mx-1">
              {{ item.sbmc }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="jyqxList" show-overflow-tooltip label="警用器械">
          <template #default="{ row }">
            <el-tag v-for="(item, index) in row.jyqxList" :key="index + 'qx'" class="mx-1">
              {{ item.qxmc }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="clList" show-overflow-tooltip label="警组车辆">
          <template #default="{ row }">
            <el-tag v-for="(item, index) in row.clList" :key="index + 'cl'" class="mx-1">
              {{ item.jdchphm }}
            </el-tag>
          </template>
        </el-table-column>

        <el-table-column label="操作" align="center" fixed="right" width="150px">
          <template #default="{ row }">
            <el-button @click="update(row)" size="small">修改</el-button>
            <el-button @click="delDictItem(row)" type="danger" 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="[2, 5, 10, 20]" :page-size="listQuery.pageSize"
          layout="total, sizes, prev, pager, next, jumper" :total="total">
        </el-pagination>
      </div>
    </div>

    <div v-if="dialogFormVisible" class="dialog">
      <div class="head_box">
        <span class="title">{{ title }}</span>
        <div>
          <el-button type="primary" :loading="btnLoading" 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 style="width: 48%" prop="ssbmdm" label="所属部门">
          <MOSTY.Department :placeholder="form.ssbm" style="width: 100%" ref="cascader" clearable filterable
            :options="depList" :props="props" @change="handleChange" v-model="form.ssbmdm" />
        </el-form-item>
        <el-form-item style="width: 48%" prop="jzMc" label="警组名称">
          <el-input v-model="form.jzMc" placeholder="请输入警组名称" style="width: 100%" clearable />
        </el-form-item>
        <el-form-item style="width: 48%" prop="ddMjxm" label="警组负责人">
          <el-input @click="chooseUserVisible = true" v-model="form.ddMjxm" placeholder="请选择警组负责人" clearable
            @change="handelJzfzr" style="width: 100%" />
        </el-form-item>
        <el-form-item style="width: 48%" prop="ddMjsfzh" label="负责人身份证号">
          <el-input v-model="form.ddMjsfzh" clearable placeholder="请输入身份证号" style="width: 100%" />
        </el-form-item>
        <el-form-item style="width: 48%" prop="ddDh" label="负责人电话">
          <el-input v-model="form.ddDh" clearable placeholder="请输入负责人电话" style="width: 100%" />
        </el-form-item>
        <el-form-item style="width: 48%" prop="mjjzcy" label="民警成员" @click.stop="mjVisible = true">
          <el-input v-model="form.mjData" placeholder="请选择民警成员" style="width: 100%" clearable readonly
            suffix-icon="ArrowDown" v-if="mjData.length <= 0" />
          <template v-else>
            <el-tag v-for="tag in mjData" :key="tag.id" class="mx-1" closable :type="tag.type"
              @close.stop="handleClose(tag, 'MJ')">
              {{ tag.jlxm }}
            </el-tag>
          </template>
        </el-form-item>

        <el-form-item style="width: 48%" prop="fjjzcy" label="辅警成员" @click.stop="fjVisible = true">
          <el-input v-model="form.fjData" placeholder="请选择辅警成员" style="width: 100%" clearable readonly
            suffix-icon="ArrowDown" v-if="fjData.length <= 0" />
          <template v-else>
            <el-tag v-for="tag in fjData" :key="tag.id" class="mx-1" closable :type="tag.type"
              @close.stop="handleClose(tag, 'FJ')">
              {{ tag.jlxm }}
            </el-tag>
          </template>
        </el-form-item>
        <el-form-item style="width: 48%" prop="jzznzb" label="移动警务终端" @click.stop="(zblx = '81'), (znzbVisible = true)">
          <el-input v-model="form.ydjwzdDate" placeholder="请选择移动警务终端" style="width: 100%" clearable readonly
            suffix-icon="ArrowDown" v-if="ydjwzdDate.length <= 0" />
          <template v-else>
            <el-tag v-for="tag in ydjwzdDate" :key="tag.id" class="mx-1" closable :type="tag.type"
              @close.stop="handleClose(tag, 'YDJWZD')">
              {{ tag.sbmc }}
            </el-tag>
          </template>
        </el-form-item>
        <el-form-item style="width: 48%" prop="jzznzb" label="对讲机" @click.stop="(zblx = '86'), (znzbVisible = true)">
          <el-input v-model="form.scdjjDate" placeholder="请选择对讲机" style="width: 100%" clearable readonly
            suffix-icon="ArrowDown" v-if="scdjjDate.length <= 0" />
          <template v-else>
            <el-tag v-for="tag in scdjjDate" :key="tag.id" class="mx-1" closable :type="tag.type"
              @close.stop="handleClose(tag, 'DJJ')">
              {{ tag.sbmc }}
            </el-tag>
          </template>
        </el-form-item>
        <el-form-item style="width: 48%" prop="jzznzb" label="执法记录仪" @click.stop="(zblx = '80'), (znzbVisible = true)">
          <el-input v-model="form.zfjlyDate" placeholder="请选择执法记录仪" style="width: 100%" clearable readonly
            suffix-icon="ArrowDown" v-if="zfjlyDate.length <= 0" />
          <template v-else>
            <el-tag v-for="tag in zfjlyDate" :key="tag.id" class="mx-1" closable :type="tag.type"
              @close.stop="handleClose(tag, 'ZFJLY')">
              {{ tag.sbmc }}
            </el-tag>
          </template>
        </el-form-item>
        <el-form-item style="width: 100%" prop="jyqxList" label="警用器械" @click.stop="jyqxVisible = true">
          <el-input v-model="form.jyqxData" placeholder="请选择警用器械" style="width: 100%" clearable readonly
            suffix-icon="ArrowDown" v-if="jyqxData.length <= 0" />
          <template v-else>
            <el-tag v-for="tag in jyqxData" :key="tag.id" class="mx-1" closable :type="tag.type"
              @close.stop="handleClose(tag, 'JYQX')">
              {{ tag.qxmc }}
            </el-tag>
          </template>
        </el-form-item>
        <el-form-item style="width: 100%" prop="clList" label="警组车辆" @click.stop="jyclVisible = true">
          <el-input v-model="form.jyclData" placeholder="请选择警组车辆" style="width: 100%" clearable readonly
            suffix-icon="ArrowDown" v-if="jyclData.length <= 0" />
          <template v-else>
            <el-tag v-for="tag in jyclData" :key="tag.id" class="mx-1" closable :type="tag.type"
              @close.stop="handleClose(tag, 'CAR')">
              {{ tag.jdchphm }}
            </el-tag>
          </template>
        </el-form-item>
        <el-form-item prop="bz" label="备注" style="width: 100%">
          <el-input v-model="form.bz" placeholder="请输入关键字" show-word-limit type="textarea" />
        </el-form-item>
      </el-form>
    </div>
    <ChooseUser v-if="chooseUserVisible" v-model="chooseUserVisible" titleValue="选择负责人" :roleIds="hasChooseFzr"
      @choosedUsers="hanlderChoose"></ChooseUser>
    <MjLoad v-if="mjVisible" v-model="mjVisible" titleValue="选择民警" :roleIds="hasChooseMj"
      @choosedUsers="hanlderChooseMj" />

    <FjLoad v-if="fjVisible" v-model="fjVisible" :roleIds="hasChooseFj" @choosedUsers="hanlderChooseFj" />
    <JyqxLoad v-if="jyqxVisible" :roleIds="hasChooseJyqx" v-model="jyqxVisible" @choosedUsers="hanlderChooseJyqx" />
    <ZnzbLoad v-model="znzbVisible" v-if="znzbVisible" :roleIds="hasChooseZnzb" :zblx="zblx"
      @choosedUsers="hanlderChooseZnzb" />
    <JyclLoad v-if="jyclVisible" :roleIds="hasChooseJycl" v-model="jyclVisible" @choosedUsers="hanlderChooseJycl" />
  </div>
</template>

<script setup>
import { selectDeptPage, getUserInfoToId } from "@/api/user-manage";
import { qcckGet, qcckPost } from "@/api/qcckApi.js";
import ChooseUser from "@/components/MyComponents/ChooseUser";
import MjLoad from "@/components/MyComponents/ChooseJz/MjLoad.vue";
import FjLoad from "@/components/MyComponents/ChooseJz/FjLoad.vue";
import JyqxLoad from "@/components/MyComponents/ChooseJz/JyqxLoad.vue";
import JyclLoad from "@/components/MyComponents/ChooseJz/JzclLoad.vue";
import ZnzbLoad from "@/components/MyComponents/ChooseJz/ZnzbLoad.vue";
import {
  getJzList,
  addJz,
  deleteJz,
  getJzInfo,
  updateJz
} from "@/api/basicsmanage/servicejz.js";
import * as MOSTY from "@/components/MyComponents/index";
import { ref, reactive, onMounted, onUnmounted, getCurrentInstance } from "vue";
const loadingTable = ref(true);
const cascader = ref(null);
const { proxy } = getCurrentInstance();
const { D_BZ_SF } = proxy.$dict("D_BZ_SF");
const btnLoading = ref(false);
const mjVisible = ref(false); //民警弹窗
const mjData = ref([]);
const fjVisible = ref(false); //辅警弹窗
const fjData = ref([]);
const jyqxVisible = ref(false); //警用器械弹窗
const jyqxData = ref([]);
const jyclVisible = ref(false); //警用车辆弹窗
const jyclData = ref([]);
const znzbVisible = ref(false); //智能装备弹窗
const zblx = ref("null"); //智能装备类型
const ydjwzdDate = ref([]); //移动警务终端
const zfjlyDate = ref([]); //执法记录仪
const scdjjDate = ref([]); //手持对讲机
const jcData = ref([]);
const searchBox = ref(null); // 搜索盒子
const chooseUserVisible = ref(false);
const totalzq = ref(0);
const tableHeight = ref(null); // 表格高度
const depList = ref([]); //部门数据
const chackAdd = ref(false);
const chackipt = ref(true);
const mapActive = ref(false);
const title = ref("新增勤务警组");
const tableHeight1 = ref(); // 表格高度
const ids = ref([]); //批量删除的ID

const hasChooseFzr = ref([]); //已经选胡负责人
const hasChooseMj = ref([]); //已经选胡民警
const hasChooseFj = ref([]); //已经选胡FU警
const hasChooseZnzb = ref([]); //已经选胡智能装备
const hasChooseJyqx = ref([]); //已经选警用器械
const hasChooseJycl = ref([]); //已经选警用车辆

const listQuery = ref({
  pageCurrent: 1,
  pageSize: 20,
  ssbmdm: "",
  ddMjxm: "",
  jzMc: "",
  isChild: "1",
  ddMjjh: ""
});

onMounted(() => {
  getListData();
  proxy.mittBus.on("mittFn", (data) => {
    keyCount.value = data;
  });
  tabHeightFn();
  window.onresize = function () {
    tabHeightFn();
  };
});

//筛选条件参数执勤
const listQueryzq = ref({
  pageCurrent: 1,
  pageSize: 20
});
function focusF() {
  chackipt.value = false;
}
//级联选择器配置
const props = {
  expandTrigger: "children",
  children: "childDeptList",
  label: "orgName",
  value: "orgCode",
  checkStrictly: true,
  emitPath: false
};
onUnmounted(() => {
  proxy.mittBus.off("mittFn");
});
selectDeptPage({}).then((res) => {
  depList.value = res.records;
});
const tableData = ref([]); //列表数据
const total = ref(0); //总数据
const dialogFormVisible = ref(false);
const keyCount = ref(0); //tabel组件刷新值
const handleFilter = () => {
  listQuery.value.pageCurrent = 1;
  getListData();
};

// 处理删除tag
function handleClose(tag, type) {
  switch (type) {
    case "MJ":
      mjData.value.splice(mjData.value.indexOf(tag), 1);
      if (title.value == "新增勤务警组") {
        hasChooseMj.value.splice(hasChooseMj.value.indexOf(tag.id), 1);
      } else {
        hasChooseMj.value.splice(hasChooseMj.value.indexOf(tag.ryId), 1);
      }
      break;
    case "FJ":
      fjData.value.splice(fjData.value.indexOf(tag), 1);
      if (title.value == "新增勤务警组") {
        hasChooseFj.value.splice(hasChooseFj.value.indexOf(tag.id), 1);
      } else {
        hasChooseFj.value.splice(hasChooseFj.value.indexOf(tag.ryId), 1);
      }
      break;
    case "CAR":
      jyclData.value.splice(jyclData.value.indexOf(tag), 1);
      if (title.value == "新增勤务警组") {
        hasChooseJycl.value.splice(hasChooseJycl.value.indexOf(tag.cid), 1);
      } else {
        hasChooseJycl.value.splice(hasChooseJycl.value.indexOf(tag.clId), 1);
      }

      break;
    case "YDJWZD":
      ydjwzdDate.value.splice(ydjwzdDate.value.indexOf(tag), 1);
      if (title.value == "新增勤务警组") {
        hasChooseZnzb.value.splice(hasChooseZnzb.value.indexOf(tag.id), 1);
      } else {
        hasChooseZnzb.value.splice(hasChooseZnzb.value.indexOf(tag.zbId), 1);
      }

      break;
    case "DJJ":
      scdjjDate.value.splice(scdjjDate.value.indexOf(tag), 1);
      if (title.value == "新增勤务警组") {
        hasChooseZnzb.value.splice(hasChooseZnzb.value.indexOf(tag.id), 1);
      } else {
        hasChooseZnzb.value.splice(hasChooseZnzb.value.indexOf(tag.zbId), 1);
      }
      break;
    case "ZFJLY":
      zfjlyDate.value.splice(zfjlyDate.value.indexOf(tag), 1);
      if (title.value == "新增勤务警组") {
        hasChooseZnzb.value.splice(hasChooseZnzb.value.indexOf(tag.id), 1);
      } else {
        hasChooseZnzb.value.splice(hasChooseZnzb.value.indexOf(tag.zbId), 1);
      }
      break;
    case "JYQX":
      jyqxData.value.splice(jyqxData.value.indexOf(tag), 1);
      if (title.value == "新增勤务警组") {
        hasChooseJyqx.value.splice(hasChooseJyqx.value.indexOf(tag.id), 1);
      } else {
        hasChooseJyqx.value.splice(hasChooseJyqx.value.indexOf(tag.qxId), 1);
      }
      break;
  }
}

//获取数据
const getListData = () => {
  loadingTable.value = true;
  qcckGet(listQuery.value, "/mosty-jcgl/tbJcglJz/queryList").then((res) => {
    tableData.value = res.records;
    total.value = Number(res.total);
    loadingTable.value = false;
  });
};
const reset = () => {
  listQuery.value = {
    pageCurrent: 1,
    pageSize: 20
  };
  getListData();
};
function handleChange(e) { }
const addDict = (row) => {
  isEdit.value = false;
  dialogForm.value = {};
  dialogFormVisible.value = true;
};
//重置表单
function formReset() {
  form.value = {};
}
//关闭弹窗
function close() {
  dialogFormVisible.value = false;
  formReset();
}
//选择用户
const hanlderChoose = (users) => {
  const user = users[0];
  form.value.ddMjxm = user.xm;
  form.value.ddMjsfzh = user.sfzh;
  form.value.ddDh = user.lxdh;
  form.value.ddMjid = user.id;
  form.value.ddMjjh = user.jh;
  hasChooseFzr.value = [user.id];
};
//选择民警
function hanlderChooseMj(arr) {
  hasChooseMj.value = arr.map((v) => {
    return v.ryid;
  });
  const jzryList = arr.map((item) => {
    return {
      ryId: item.ryid,
      jllx: item.fl,
      jlxm: item.xm,
      jh: item.jh,
      sfzh: item.sfzh,
      lxdh: item.lxdh,
      xbdm: item.xbdm
    };
  });
  mjData.value = jzryList;
}

//选择辅警
function hanlderChooseFj(arr) {
  hasChooseFj.value = arr.map((v) => {
    return v.id;
  });
  const jzryList = arr.map((item) => {
    return {
      ryId: item.id,
      jllx: item.fl,
      jlxm: item.xm,
      jh: item.jh,
      sfzh: item.sfzh,
      lxdh: item.lxdh,
      xbdm: item.xbdm
    };
  });
  fjData.value = jzryList;
}
//选择警用车辆
function hanlderChooseJycl(arr) {
  let brr = [];
  const clList = arr.map((item) => {
    brr.push(item.cid);
    return {
      clId: item.cid,
      jdchphm: item.cph,
      jdchpzldm: item.cplx,
      gpsId: item.gpsId,
    };
  });
  hasChooseJycl.value = brr;
  jyclData.value = clList;
}
//单个删除
function delDictItem(row) {
  proxy
    .$confirm("确定要删除", "警告", {
      type: "warning"
    })
    .then(() => {
      qcckPost([row.id], "/mosty-jcgl/tbJcglJz/deleteJz").then(() => {
        proxy.$message({
          type: "success",
          message: "删除成功"
        });
        getListData();
      });
    })
    .catch(() => {
      proxy.$message.info("已取消");
    });
}
//批量数据
const handleSelectionChange = (val) => {
  ids.value = [];
  if (val) {
    val.forEach((item) => {
      ids.value.push(item.id);
    });
  }
};
//批量删除
function batchDelete() {
  proxy
    .$confirm("确定要删除", "警告", {
      type: "warning"
    })
    .then(() => {
      qcckPost(ids.value, "/mosty-jcgl/tbJcglJz/deleteJz").then((res) => {
        proxy.$message({
          type: "success",
          message: "删除成功"
        });
        getListData();
      });
    })
    .catch(() => {
      proxy.$message.info("已取消");
    });
}
//选择警用器械
function hanlderChooseJyqx(arr) {
  let brr = [];
  const jyqxList = arr.map((item) => {
    brr.push(item.id);
    return { qxId: item.id, qxlx: item.scode, qxsl: item.sl, qxmc: item.qxMc };
  });
  jyqxData.value = jyqxList;
  hasChooseJyqx.value = brr;
}
//选择智能装备
function hanlderChooseZnzb(arr) {
  hasChooseZnzb.value = arr.map((v) => {
    return v.id;
  });
  const txzbList = arr.map((item) => {
    return {
      txzblx: item.scode,
      zbId: item.id,
      sbmc: item.sbmc,
      hh: item.sbbh,
      sbbh: item.sbbh,
      sfrh: item.sfrh,
      sfzy: item.sfzy,
      sfxt: item.sfxt,
    };
  });
  switch (zblx.value) {
    case "81":
      // 移动警务终端
      ydjwzdDate.value = txzbList;
      break;
    case "86":
      // 对讲机
      scdjjDate.value = txzbList;
      break;
    case "80":
      // 执法记录仪
      zfjlyDate.value = txzbList;
      break;
  }
  //装备
}
//表单数据
const form = ref({
  jzMc: "",
  ssbm: "",
  jzfzr: "",
  fzrsfzh: "",
  fzrdh: "",
  mjjzcy: "",
  fjjzcy: "",
  jzznzb: "",
  jyqx: "",
  jzcl: "",
  bz: "",
  jczmc: "",
  jczid: ""
});
//新增勤务警组
function add() {
  jyclData.value = [];
  mjData.value = [];
  fjData.value = [];
  jyqxData.value = [];
  ydjwzdDate.value = [];
  zfjlyDate.value = [];
  scdjjDate.value = [];
  jcData.value = [];
  title.value = "新增勤务警组";
  chackAdd.value = true;
  chackipt.value = false;
  formReset();
  dialogFormVisible.value = true;
}
//修改勤务警组
function update(row) {
  jyclData.value = [];
  mjData.value = [];
  fjData.value = [];
  jyqxData.value = [];
  ydjwzdDate.value = [];
  zfjlyDate.value = [];
  scdjjDate.value = [];
  jcData.value = [];
  qcckGet({ id: row.id }, "/mosty-jcgl/tbJcglJz/selectByid").then((res) => {
    form.value = res;
    jcData.value = [res.jczmc];
    form.value.ssbmdm = form.value.ssbmdm * 1;

    let arrCl = [];
    res.clList.forEach((v) => {
      arrCl.push(v.clId);
      jyclData.value.push(v);
    });

    let arrJyqx = [];
    res.jyqxList.forEach((v) => {
      arrJyqx.push(v.qxId);
      jyqxData.value.push(v);
    });

    let arrMJ = [];
    let arrFJ = [];
    res.jzryList.forEach((v) => {
      if (v.jllx == "01") {
        arrMJ.push(v.ryId);
        mjData.value.push(v);
      } else {
        arrFJ.push(v.ryId);
        fjData.value.push(v);
      }
    });

    let arrZb = [];
    res.txzbList.forEach((v) => {
      arrZb.push(v.zbId);
      // 装备
      switch (v.txzblx) {
        case "81":
          //移动警务终端
          ydjwzdDate.value.push(v);
          break;
        case "86":
          //对讲机
          scdjjDate.value.push(v);
          break;
        case "80":
          //执法记录仪
          zfjlyDate.value.push(v);
          break;
      }
    });
    title.value = "修改勤务警组";
    chackAdd.value = false;
    chackipt.value = true;
    dialogFormVisible.value = true;

    // 表格回显
    hasChooseFzr.value = [res.ddMjid]; //负责人
    hasChooseMj.value = arrMJ; //民警
    hasChooseFj.value = arrFJ; //辅警
    hasChooseJyqx.value = arrJyqx; //警用器械
    hasChooseZnzb.value = arrZb; //智能装备
    hasChooseJycl.value = arrCl; //警用车辆
  });
}

function handelJzfzr(val) {
  if (!val) hasChooseFzr.value = [];
}

//表单验证
const rules = reactive({
  jzMc: [
    {
      required: true,
      message: "请输入警组名称",
      trigger: "change"
    }
  ],
  ssbmdm: [
    {
      required: true,
      message: "请选择部门",
      trigger: "change"
    }
  ],
  ddMjxm: [
    {
      required: true,
      message: "请输入警组负责人",
      trigger: "change"
    }
  ],
  ddMjsfzh: [
    {
      required: true,
      message: "请输入负责人身份证号",
      trigger: "change"
    }
  ],
  ddDh: [
    {
      required: true,
      message: "请输入负责人电话",
      trigger: "change"
    }
  ]
});
const elform = ref(null);
//提交
function submit() {
  elform.value.validate((valid) => {
    if (valid) {
      btnLoading.value = true;
      const params = form.value;
      params.ssbmdm = form.value.ssbmdm;
      params.jczmc = form.value.jczmc;
      params.jczid = form.value.jczid;
      params.jzryList = [...fjData.value, ...mjData.value];
      params.txzbList = [
        ...ydjwzdDate.value,
        ...zfjlyDate.value,
        ...scdjjDate.value
      ];
      params.jyqxList = jyqxData.value;
      params.clList = jyclData.value;
      if (chackAdd.value) {
        qcckPost(params, "/mosty-jcgl/tbJcglJz/addJz")
          .then((res) => {
            proxy.$message({
              type: "success",
              message: "新增成功"
            });
            btnLoading.value = false;
            dialogFormVisible.value = false;
            getListData();
          })
          .catch(() => {
            btnLoading.value = false;
          });
      } else {
        qcckPost(form.value, "/mosty-jcgl/tbJcglJz/updateJz")
          .then((res) => {
            proxy.$message({
              type: "success",
              message: "修改成功"
            });
            btnLoading.value = false;
            dialogFormVisible.value = false;
            getListData();
          })
          .catch(() => {
            btnLoading.value = false;
          });
      }
    }
  });
}
/**
 * pageSize 改变触发
 */
const handleSizeChange = (currentSize) => {
  listQuery.value.pageSize = currentSize;
  getListData();
};

/**
 * 页码改变触发
 */
const handleCurrentChange = (currentPage) => {
  listQuery.value.pageCurrent = currentPage;
  getListData();
};
/**
 * pageSize 改变触发
 */
const handleSizeChangezq = (currentSize) => {
  listQueryzq.value.pageSize = currentSize;
  getListData();
};

/**
 * 页码改变触发
 */
const handleCurrentChangezq = (currentPage) => {
  listQueryzq.value.pageCurrent = currentPage;
  getListData();
};
// 表格高度计算
const tabHeightFn = () => {
  tableHeight.value = window.innerHeight - searchBox.value.offsetHeight - 240;
  tableHeight1.value = window.innerHeight - 57 - 20 - 200;
};
</script>

<style lang="scss" scoped>
@import "@/assets/css/layout.scss";
@import "@/assets/css/element-plus.scss";

.ipt {
  border: 1px solid rgb(7, 85, 188);
  width: 100%;
  line-height: 32px;
  min-height: 32px;
  border-radius: 4px;
}
</style>
