<template>
  <div class="container" style="padding-top: 13vw">
    <TopNav :navTitle="obj.bbInfo ? '巡防报备信息' : '巡防排班信息'" />
    <van-form @submit="onSubmit">
      <div class="title_tab">班次岗位</div>
      <van-field
        v-if="normalForm.bblx == '02'"
        v-model="normalForm.qwlxMc"
        required
        name="勤务类型"
        readonly
        is-link
        label="勤务类型"
        placeholder="请选择勤务类型"
        input-align="right"
        :rules="[{ required: true, message: '请选择勤务类型' }]"
        @click="qwlxPicker = true"
      />
      <van-field
        v-if="normalForm.bblx == '01'"
        v-model="normalForm.bcmc"
        required
        name="班次"
        readonly
        is-link
        label="班次"
        placeholder="请选择班次"
        input-align="right"
        :rules="[{ required: true, message: '请选择班次' }]"
        @click="showDialogfn('qwbc')"
      />
      <van-field
        readonly
        v-if="qzsj"
        v-model="qzsj"
        input-align="right"
        label="班次时段"
      />
      <van-field
        class="change"
        label-width="70px"
        required
        name="radio"
        label="巡防类型"
      >
        <template #input>
          <van-radio-group
            v-model="normalForm.xffwlx"
            direction="horizontal"
            :disabled="disable"
          >
            <van-radio shape="square" checked-color="#3e6ee8" name="1"
              >巡防区</van-radio
            >
            <van-radio shape="square" checked-color="#3e6ee8" name="2"
              >快反点</van-radio
            >
            <van-radio shape="square" checked-color="#3e6ee8" name="3"
              >检查站</van-radio
            >
          </van-radio-group>
        </template>
      </van-field>
      <van-field
        v-if="normalForm.xffwlx === '1'"
        v-model="normalForm.xfqMc"
        readonly
        name="picker"
        label="巡防区"
        input-align="right"
        is-link
        placeholder="请选择巡防区"
        @click="showDialogfn('xfq')"
        :rules="[{ required: true, message: '请选择巡防区' }]"
      />
      <van-field
        v-if="normalForm.xffwlx === '2'"
        v-model="normalForm.kfdMc"
        readonly
        name="picker"
        label="快反点"
        input-align="right"
        is-link
        placeholder="请选择快反点"
        @click="showDialogfn('kfd')"
        :rules="[{ required: true, message: '请选择快反点' }]"
      />
      <van-field
        v-if="normalForm.xffwlx === '3'"
        v-model="normalForm.jczMc"
        readonly
        name="picker"
        label="卡点"
        input-align="right"
        is-link
        placeholder="请选择卡点"
        @click="showDialogfn('jcz')"
        :rules="[{ required: true, message: '请选择卡点' }]"
      />
      <div class="title_tab">人员车辆</div>
      <van-field
        v-if="normalForm.bblx == '01'"
        v-model="normalForm.jzMc"
        name="选择警组"
        readonly
        input-align="right"
        label="选择警组"
        is-link
        placeholder="请选择警组"
        :rules="[{ required: true, message: '请选择警组' }]"
        @click="showDialogfn('jz')"
      />
      <van-field
        v-model="normalForm.fzrInfo"
        required
        readonly
        input-align="right"
        :clearable="true"
        name="picker"
        label="负责人"
        placeholder="请选择负责人"
        @click="showDialogfn('fzr')"
        :rules="[{ required: true, message: '请选择负责人' }]"
        is-link
      />

      <van-cell class="mulSelect" title="民警" color="#1989fa">
        <template #right-icon>
          <van-icon
            @click.stop="showDialogfn('mj')"
            name="add-o"
            color="#1989fa"
            size="22"
          />
        </template>
        <template #default>
          <div class="selected-box">
            <div
              class="check-item-tag"
              v-for="(item, index) in list.mj"
              :key="index"
            >
              <van-tag
                color="#7232dd"
                closeable
                @close="deleteCheckTag(item, index, 'mj')"
                plain
                >{{ item.xm || item.jlxm }}</van-tag
              >
            </div>
          </div>
        </template>
      </van-cell>
      <van-cell class="mulSelect" title="辅警" color="#1989fa">
        <template #right-icon>
          <van-icon
            @click.stop="showDialogfn('fj')"
            name="add-o"
            color="#1989fa"
            size="22"
          />
        </template>
        <template #default>
          <div class="selected-box">
            <div
              class="check-item-tag"
              v-for="(item, index) in list.fj"
              :key="index"
            >
              <van-tag
                closeable
                @close="deleteCheckTag(item, index, 'fj')"
                color="#7232dd"
                plain
                >{{ item.xm || item.jlxm }}</van-tag
              >
            </div>
          </div>
        </template>
      </van-cell>
      <van-cell class="mulSelect" title="巡防车辆" color="#1989fa">
        <template #right-icon>
          <van-icon
            @click.stop="showDialogfn('cl')"
            name="add-o"
            color="#1989fa"
            size="22"
          />
        </template>
        <template #default>
          <div class="selected-box">
            <div
              class="check-item-tag"
              v-for="(item, index) in list.cl"
              :key="index"
            >
              <van-tag
                color="#7232dd"
                closeable
                @close="deleteCheckTag(item, index, 'cl')"
                plain
                >{{ item.value || item.jdchphm }}</van-tag
              >
            </div>
          </div>
        </template>
      </van-cell>
      <div class="title_tab">装备</div>
      <van-cell class="mulSelect" title="智能装备" color="#1989fa">
        <template #right-icon>
          <van-icon
            @click.stop="showDialogfn('zn')"
            name="add-o"
            color="#1989fa"
            size="22"
          />
        </template>
        <template #default>
          <div class="selected-box">
            <div
              class="check-item-tag"
              v-for="(item, index) in list.zn"
              :key="index"
            >
              <van-tag
                closeable
                @close="deleteCheckTag(item, index, 'zn')"
                color="#7232dd"
                plain
                >{{ item.value || item.sbmc }}</van-tag
              >
            </div>
          </div>
        </template>
      </van-cell>
      <van-cell class="mulSelect" title="警用器械" color="#1989fa">
        <template #right-icon>
          <van-icon
            @click.stop="showDialogfn('jy')"
            name="add-o"
            color="#1989fa"
            size="22"
          />
        </template>
        <template #default>
          <div class="selected-box">
            <div
              class="check-item-tag"
              v-for="(item, index) in list.jy"
              :key="index"
            >
              <van-tag
                closeable
                @close="deleteCheckTag(item, index, 'jy')"
                color="#7232dd"
                plain
                >{{ item.value || item.qxmc }} * {{ item.qxsl }}</van-tag
              >
            </div>
          </div>
        </template>
      </van-cell>
      <div class="title_tab">巡逻方式</div>

      <van-field class="change" name="radio" label="巡逻方式">
        <template #input>
          <van-radio-group
            v-model="normalForm.xlfs"
            direction="horizontal"
            :disabled="disable"
          >
            <van-radio shape="square" checked-color="#3e6ee8" name="1"
              >步巡</van-radio
            >
            <van-radio shape="square" checked-color="#3e6ee8" name="0"
              >车巡</van-radio
            >
          </van-radio-group>
        </template>
      </van-field>
      <van-field class="change" name="radio" label="着装类型">
        <template #input>
          <van-radio-group
            v-model="normalForm.zzlx"
            direction="horizontal"
            :disabled="disable"
          >
            <van-radio shape="square" checked-color="#3e6ee8" name="0"
              >制服</van-radio
            >
            <van-radio shape="square" checked-color="#3e6ee8" name="1"
              >便衣</van-radio
            >
          </van-radio-group>
        </template>
      </van-field>
      <van-field class="change" name="radio" label="武装类型">
        <template #input>
          <van-radio-group
            v-model="normalForm.wzlx"
            direction="horizontal"
            :disabled="disable"
          >
            <van-radio shape="square" checked-color="#3e6ee8" name="0"
              >武装</van-radio
            >
            <van-radio shape="square" checked-color="#3e6ee8" name="1"
              >非武装</van-radio
            >
          </van-radio-group>
        </template>
      </van-field>
      <van-row>
        <van-col span="24">
          <van-field
            rows="3"
            type="textarea"
            v-model="normalForm.bz"
            name="备注"
            placeholder="备注信息"
          />
        </van-col>
      </van-row>
      <div
        style="padding: 0 5vw"
        v-if="obj.bbInfo && isDays == 1 && qwzt == '02'"
      >
        <van-button
          style="margin: 16px 0"
          :loading="loading"
          round
          @click="editFn(0)"
          block
          type="success"
        >
          结束报备
        </van-button>
      </div>
      <div
        style="margin: 16px 0; padding: 0 5vw"
        v-if="obj.pbInfo && isDays == 1 && qwzt == '01'"
      >
        <van-button
          :loading="loading"
          round
          native-type="submit"
          block
          type="primary"
        >
          开始报备
        </van-button>
      </div>
    </van-form>
    <!-- 负责人 -->
    <Select
      bclx="02"
      :dwlx="dwlx"
      :checked="r_checked"
      :selectType="selectType"
      :show="showSelect"
      :checkedList="list.checkedList"
      @update:cancel="showSelect = false"
      @update:confirm="onComfirm"
      :key="selectIndex"
    />
    <van-popup v-model:show="qwlxPicker" round position="bottom">
      <van-picker
        :columns="normalForm.bblx == '01' ? D_BZ_QWLX : QWLX"
        @cancel="qwlxPicker = false"
        @confirm="onQwlxConfirm"
      />
    </van-popup>
  </div>
</template>

<script setup>
import { getBcList, getXfqList, getKfdList } from "../../../api/xfbbAndZbbb.js";
import { getItem } from "../../../utils/storage";
import TopNav from "../../../components/topNav";
import Select from "../../../components/Select.vue";
import { getMybbTodayNew } from "../../../api/common";
import { Dialog, Toast } from "vant";
import { addXFBB, getPbinfo } from "../../../api/report";
import { getBbListById, finishReport } from "../../../api/common";
import { dateFormat, hintToast } from "../../../utils/tools.js";
import { computed, ref, reactive, onMounted, watch } from "vue";
import { useRouter, useRoute } from "vue-router";
import { getDictList, setDict } from "../../../utils/dict";
const showSelect = ref(false);
let D_BZ_QWLX = [];
function getQwlx() {
  D_BZ_QWLX = getDictList("D_BZ_QWLX").D_BZ_QWLX;
}
const obj = reactive({ bbInfo: null, pbInfo: null });
// 是否显示勤务班次弹窗
const router = useRouter();
const route = useRoute();
const userInfo = getItem("userInfo");
const qzsj = ref("");
const isUserDept = ref(false); //是否是用户本部门
const r_checked = ref(""); //单选框默认选中
const kwd = ref(""); //选择器关键字
const selectIndex = ref(1); //选择器组件KEY
const selectType = ref(""); //选择的类型
const znzbCode = ref(""); //智能装备类型筛选
const bcList = ref([]); //班次数据
const dwlx = ref("01");
// 巡防日期
const calShow = ref(false); //是否显示巡防日期选择器
const minDate = new Date(2000, 0, 1);
const maxDate = new Date(2050, 0, 1);
const chooseTime = ref(dateFormat("", new Date()));
const isDays = ref("");
const qwzt = ref("");
const normalForm = reactive({
  xfrq: dateFormat(),
  bbzt: "0",
  xlfs: "1",
  zzlx: "1",
  wzlx: "2",
  kssj: "",
  jssj: "",
  jzMc: "",
  jzId: "",
  ssbm: userInfo.deptName,
  ssbmdm: userInfo.deptList[0].deptCode,
  fzrXm: "",
  fzrSfzh: "",
  fzrLxdh: "",
  fzrInfo: "",
  fzrId: "",
  znzbList: [],
  jyqxList: [],
  clList: [],
  jlList: [],
  bz: "",
  bcmc: "",
  xffwid: "",
  xffwlx: "",
  xffwList: [],
  xfqMc: "",
  kfdMc: "",
  qwlxMc: "",
  qwlx: "",
});
const list = reactive({
  mulChooseList: [],
  mj: [],
  fj: [],
  zn: [],
  jy: [],
  cl: [],
  xfqList: [],
  kfdList: [],
  jczList: [],
});
const QWLX = ref([]);
onMounted(() => {
  let { bbid, isDay, pbid, zt } = route.query;
  isDays.value = isDay;
  qwzt.value = zt;
  Promise.all([
    getQwlx(),
    _getXfqList(),
    _getKfdList(),
    getQwbcList(),
    _getJczList(),
  ]).then((res) => {
    if (zt == "01" && pbid) {
      _getMyXfpbToday(pbid);
    } else if (zt == "02" || (zt == "03" && bbid)) {
      _getMybbTodayNew(bbid);
    }
    D_BZ_QWLX.value.forEach((el, index) => {
      if (index != 0) {
        QWLX.value.push(el);
      }
    }); //字典信息
  });
});
//确认巡防日期选择
function onConfirmTime(val) {
  calShow.value = false;
  chooseTime.value = dateFormat("", val);
  normalForm.xfrq = chooseTime.value;
}
// 选择勤务类型
const qwlxPicker = ref(false);
function onQwlxConfirm(val) {
  normalForm.qwlx = val.value;
  normalForm.qwlxMc = val.text;
  qwlxPicker.value = false;
}
//确认选择
function onComfirm(val) {
  if (val.length <= 0) return;
  switch (selectType.value) {
    case "jz":
      if (r_checked.value == val[0].key) {
        r_checked.value = "";
        normalForm.jzMc = "";
        list.mj = [];
        list.fj = [];
        list.cl = [];
        list.zn = [];
        list.jy = [];
        normalForm.jzId = "";
      } else {
        r_checked.value = val[0].key;
        onjzConfirm(val[0]);
      }
      break;
    case "qwbc":
      r_checked.value = val[0].key;
      onbcConfirm(val[0]);
      break;
    case "fzr":
      r_checked.value = val[0].key;
      onfzrConfirm(val[0]);
      break;
    case "mj":
      // list.mj = [];
      list.checkedList = [];
      val.forEach((item) => {
        list.checkedList.push(item.key);
        toggle(item);
      });
      break;
    case "fj":
      // list.fj = [];
      list.checkedList = [];
      val.forEach((item) => {
        list.checkedList.push(item.key);
        toggle(item);
      });
      break;
    case "zn":
      // list.zn = [];
      list.checkedList = [];
      val.forEach((item) => {
        list.checkedList.push(item.key);
        toggle(item);
      });
      break;
    case "cl":
      // list.cl = [];
      list.checkedList = [];
      val.forEach((item) => {
        list.checkedList.push(item.key);
        toggle(item);
      });
      break;
    case "jy":
      // list.jy = [];
      list.checkedList = [];
      val.forEach((item) => {
        list.checkedList.push(item.key);
        toggle(item);
      });
      break;
    case "xfq":
      list.checkedList = [];
      normalForm.xfqMc = "";
      val.forEach((item) => {
        list.checkedList.push(item.key);
        toggle(item);
      });
      break;
    case "kfd":
      r_checked.value = val[0].key;
      onkfdConfirm(val[0]);
      break;
    case "jcz":
      r_checked.value = val[0].key;
      onkfdConfirm(val[0]);
      break;
  }
}
//获取用户的报备信息
function _getMybbTodayNew(id) {
  Toast.loading({
    message: "加载...",
    forbidClick: true,
    loadingType: "spinner",
    duration: 0,
  });
  getBbListById(id)
    .then((res) => {
      if (res) {
        const resData = JSON.parse(JSON.stringify(res));
        if (!resData.jyqx) {
          resData.jyqx = JSON.stringify([]);
        }
        if (!resData.pbmj) {
          resData.pbmj = JSON.stringify([]);
        }
        if (!resData.pbfj) {
          resData.pbfj = JSON.stringify([]);
        }
        if (!resData.txzb) {
          resData.txzb = JSON.stringify([]);
        }
        if (!resData.pbcl) {
          resData.pbcl = JSON.stringify([]);
        }
        obj.bbInfo = resData;
        _setSubmitData(resData);
        Toast.clear();
      }
    })
    .catch((err) => {
      Toast.clear();
    });
}
//获取用户排班信息
function _getMyXfpbToday(id) {
  Toast.loading({
    message: "加载...",
    forbidClick: true,
    loadingType: "spinner",
    duration: 0,
  });
  getPbinfo({ id, time: dateFormat("", new Date()) })
    .then((res) => {
      if (res) {
        const resData = JSON.parse(JSON.stringify(res));
        if (!resData.jyqx) {
          resData.jyqx = JSON.stringify([]);
        }
        if (!resData.pbmj) {
          resData.pbmj = JSON.stringify([]);
        }
        if (!resData.pbfj) {
          resData.pbfj = JSON.stringify([]);
        }
        if (!resData.txzb) {
          resData.txzb = JSON.stringify([]);
        }
        if (!resData.pbcl) {
          resData.pbcl = JSON.stringify([]);
        }
        normalForm.xfpbId = resData.id;
        obj.pbInfo = resData;
        _setSubmitData(resData);
      } else {
        hintToast("没有排班和报备信息，请自行填写并报备");
      }
      Toast.clear();
    })
    .catch((err) => {
      Toast.clear();
    });
}
//设置需要提交的参数
function _setSubmitData(obj) {
  let {
    jzMc,
    xffwlx,
    xffwid,
    jzId,
    fzrSfzh,
    fzrXm,
    fzrLxdh,
    userName,
    pbmj,
    pbfj,
    txzb,
    jyqx,
    pbcl,
    xlfs,
    zzlx,
    wzlx,
    bz,
    qwbcId,
    fzrId,
    kssj,
    jssj,
    zqsc,
    qwlx,
    xfpbId,
    ssbmid,
  } = obj;
  normalForm.qwbcId = qwbcId;
  normalForm.zqsc = zqsc;
  normalForm.kssj = kssj;
  normalForm.jssj = jssj;
  normalForm.jzMc = jzMc;
  normalForm.jzId = jzId;
  normalForm.ssbmid = ssbmid;
  normalForm.xffwlx = xffwlx;
  normalForm.xffwid = xffwid;
  normalForm.fzrXm = fzrXm;
  normalForm.fzrSfzh = fzrSfzh;
  normalForm.fzrLxdh = fzrLxdh;
  normalForm.fzrId = fzrId;
  normalForm.xfpbId = xfpbId;
  normalForm.fzrInfo = `${fzrXm} ${fzrLxdh}`;
  normalForm.qwlx = qwlx;
  D_BZ_QWLX.value.forEach((item) => {
    if (normalForm.qwlx == item.value) {
      normalForm.qwlxMc = item.text;
    }
  });
  list.mj = JSON.parse(pbmj);
  list.fj = JSON.parse(pbfj);
  list.zn = JSON.parse(txzb);
  list.jy = JSON.parse(jyqx);
  list.cl = JSON.parse(pbcl);
  normalForm.xlfs = xlfs;
  normalForm.zzlx = zzlx;
  normalForm.wzlx = wzlx;
  normalForm.bz = bz;

  if (xffwlx == 1) {
    normalForm.xfqMc = _setHxData(list.xfqList, "id", xffwid);
  } else if (xffwlx == 2) {
    normalForm.kfdMc = _setHxData(list.kfdList, "kfdId", xffwid);
  } else if (xffwlx == 3) {
    normalForm.jczMc = _setHxData(list.jczList, "kfdId", xffwid);
  }
  //设置班次数据
  if (normalForm.bblx == "01") {
    let bcInfo = bcList.value.find((item) => {
      return qwbcId == item.id;
    });
    normalForm.bcmc = bcInfo.bcmc;
    qzsj.value = bcInfo.kssj + " -- " + bcInfo.jssj;
  } else {
    qzsj.value = normalForm.kssj + " -- " + normalForm.jssj;
  }
}
/**
 * 返回回显对象数据
 * @param {*} array 比对数据
 * @param {*} key 比对key
 * @param {*} val 比对值
 */
function _setHxData(array, key, val) {
  let arr = [],
    xrqMc = "";
  try {
    arr = val.split(",");
    if (arr.length == 1) {
      r_checked.value = val;
    } else {
      list.checkedList = arr;
    }
  } catch (error) {}
  for (let i = 0; i < arr.length; i++) {
    for (let j = 0; j < array.length; j++) {
      if (arr[i] == array[j].id || arr[i] == array[j].kfdId) {
        xrqMc += array[j].xfqMc || array[j].kfdMc + ",";
        normalForm.xffwList.push({
          fwMc: array[j].xfqMc || array[j].kfdMc,
          glbid: array[j].id || array[j].kfdId,
          id: array[j].id || array[j].kfdId,
          qwlx: "1",
          xffwlx: normalForm.xffwlx,
        });
      }
    }
  }
  return xrqMc;
}
//选中的勤务班次数据
function onbcConfirm(val) {
  qzsj.value = val.kssj + "-" + val.jssj;
  normalForm.bcmc = val.bcmc;
  normalForm.qwbcId = val.id;
  normalForm.zqsc = val.zqsc;
  normalForm.kssj = val.kssj;
  normalForm.jssj = val.jssj;
}

//选中的警组信息
function onjzConfirm(val) {
  list.mj = [];
  list.fj = [];
  list.cl = [];
  list.zn = [];
  list.jy = [];
  list.checkedList = [];
  normalForm.jzMc = val.jzMc;
  normalForm.jzId = val.id;
  normalForm.fzrXm = val.ddMjxm;
  normalForm.fzrLxdh = val.ddDh;
  normalForm.fzrSfzh = val.ddMjsfzh;
  normalForm.fzrId = val.ddMjid;
  // normalForm.xbdm = val.
  normalForm.jh = val.ddMjjh;
  normalForm.ssbm = val.ssbm;
  normalForm.ssbmdm = val.ssbmdm;
  // 民警辅警已有赋值
  val.jzryList.forEach((m) => {
    list.checkedList.push(m.ryId);
    if (m.jllx === "01") {
      list.mj.push({
        jh: m.jh,
        jllx: m.jllx,
        jlxm: m.jlxm,
        text: m.jlxm,
        nl: m.nl,
        qwjzId: m.qwjzId,
        jlId: m.ryId,
        sfzh: m.sfzh,
        xbdm: m.xbdm,
        xm: m.jlxm,
        jh: m.jh,
        lxdh: m.lxdh,
      });
    }
    if (m.jllx === "02") {
      list.fj.push({
        jh: m.jh,
        jllx: m.jllx,
        jlxm: m.jlxm,
        text: m.jlxm,
        nl: m.nl,
        qwjzId: m.qwjzId,
        jlId: m.ryId,
        sfzh: m.sfzh,
        xbdm: m.xbdm,
        xm: m.jlxm,
        jh: m.jh,
        lxdh: m.lxdh,
      });
    }
  });
  // 车辆
  if (val.clList.length > 0) {
    normalForm.xlfs = "0";
    val.clList.forEach((c) => {
      list.checkedList.push(c.clId);
      list.cl.push({
        clId: c.clId,
        jdchphm: c.jdchphm,
        text: c.jdchphm,
        jdchpzldm: c.jdchpzldm,
        qwjzId: c.qwjzId,
      });
    });
  }

  // 警用器械
  val.jyqxList.forEach((j) => {
    list.checkedList.push(j.id);
    list.jy.push({
      qxid: j.qxid,
      qxmc: j.qxmc,
      text: j.qxmc,
      qxsl: j.sl ? j.sl : 1,
      qxlx: j.qxlx,
      qwjzId: j.qwjzId,
    });
  });
  // 智能装备
  val.txzbList.forEach((z) => {
    list.checkedList.push(z.zbId);
    list.zn.push({
      sbmc: z.sbmc,
      text: z.sbmc,
      txzblx: z.txzblx,
      txzbId: z.zbId,
      qwjzId: z.qwjzId,
      hh: z.hh,
    });
  });
}
//选中负责人
function onfzrConfirm(val) {
  normalForm.fzrXm = val.xm;
  normalForm.fzrSfzh = val.sfzh;
  normalForm.fzrLxdh = val.lxdh;
  normalForm.fzrId = val.ryid;
  normalForm.xbdm = val.xbdm;
  normalForm.fzrInfo = `${val.xm} ${val.lxdh}`;
}
// 弹框标题
const checkedList = ref([]);
const selfDefinedPopup = ref(false);

//打开选择框
function showDialogfn(val) {
  selectType.value = val;
  showSelect.value = true;
  if (val == "kfd") {
    dwlx.value = "01";
  } else if (val == "jcz") {
    dwlx.value = "02";
  }
  selectIndex.value++;
}
//设置选中值
const toggle = (item) => {
  switch (selectType.value) {
    case "mj":
      list.mj.push({
        jh: item.jh,
        jllx: item.fl,
        jlxm: item.xm,
        sfzh: item.sfzh,
        xm: item.xm,
        lxdh: item.lxdh,
        xbdm: item.xbdm,
        id: item.ryid,
        qwjzId: "",
        jlId: item.ryid,
      });
      break;
    case "fj":
      list.fj.push({
        jh: item.jh,
        jllx: item.fl,
        jlxm: item.xm,
        id: item.id,
        sfzh: item.sfzh,
        xm: item.xm,
        lxdh: item.lxdh,
        xbdm: item.xbdm,
        qwjzId: "",
        jlId: item.id,
      });
      break;
    case "zn":
      list.zn.push({
        sbmc: item.sbmc,
        text: item.sbmc,
        txzblx: item.scode,
        txzbId: item.id,
        hh: item.sbbh,
      });
      break;
    case "jy":
      list.jy.push({
        qxid: item.id,
        qxmc: item.qxMc,
        text: item.qxMc,
        qxsl: item.sl ? item.sl : 1,
        qxlx: item.scode,
      });
      normalForm.wzlx = "0";
      break;
    case "cl":
      list.cl.push({
        clId: item.cid,
        jdchphm: item.cph,
        text: item.cph,
        jdchpzldm: item.cllx,
      });
      normalForm.xlfs = "0";
      break;
  }
};
//删除选中数据
function deleteCheckTag(item, index, val) {
  switch (val) {
    case "mj":
      list.mj.splice(index, 1);
      break;
    case "fj":
      list.fj.splice(index, 1);
      break;
    case "zn":
      list.zn.splice(index, 1);
      break;
    case "jy":
      list.jy.splice(index, 1);
      list.jyqxList.forEach((el) => {
        if (el.id === item.qxid) {
          el.qxsl = 1;
        }
      });
      if (!list.jy.map((j) => j.scode).includes("01")) {
        normalForm.wzlx = "2";
      }
      break;
    case "cl":
      list.cl.splice(index, 1);
      if (list.cl == false) {
        normalForm.xlfs = "1";
      }
      break;
  }
}
// 查询巡防范围
function _getXfqList() {
  return new Promise((ok) => {
    let data = {
      type: isUserDept.value ? 1 : 2,
      keyword: kwd.value,
    };
    getXfqList(data).then((res) => {
      let xfq = res;
      for (let i = 0; i < res.length; i++) {
        res[i].value = `${res[i].ssbm}-${res[i].xfqMc}`;
        res[i].key = res[i].id;
      }
      list.xfqList = res;
      ok();
    });
  });
}
//获取快反点数据
function _getKfdList() {
  return new Promise((ok) => {
    let data = {
      type: isUserDept.value ? 1 : 2,
      keyword: kwd.value,
      dwlx: "01",
    };
    getKfdList(data).then((res) => {
      for (let i = 0; i < res.length; i++) {
        res[i].value = `${res[i].ssbm}-${res[i].kfdMc}`;
        res[i].key = res[i].kfdId;
      }
      list.kfdList = res;
      ok();
    });
  });
}
function _getJczList() {
  return new Promise((ok) => {
    let data = {
      type: isUserDept.value ? 1 : 2,
      keyword: kwd.value,
      dwlx: "02",
    };
    getKfdList(data).then((res) => {
      for (let i = 0; i < res.length; i++) {
        res[i].value = `${res[i].ssbm}-${res[i].kfdMc}`;
        res[i].key = res[i].kfdId;
      }
      list.jczList = res;
      ok();
    });
  });
}
//获取班次数据
function getQwbcList() {
  return new Promise((ok) => {
    let data = {
      type: isUserDept.value ? 1 : 2,
      keyword: kwd.value,
      bclx: "02",
    };
    getBcList(data).then((res) => {
      if (res) {
        for (let i = 0; i < res.length; i++) {
          res[i].value = `${res[i].ssbm}-${res[i].bcmc}`;
          res[i].key = res[i].id;
        }
        bcList.value = res;
      }
      ok();
    });
  });
}
function onxfqConfirm(val) {
  normalForm.xfqMc = val.xfqMc;
  normalForm.xffwid = val.id;
}

function onkfdConfirm(val) {
  normalForm.kfdMc = val.kfdMc;
  normalForm.xffwid = val.kfdId;
}

// 新增报备接口
function onSubmit() {
  normalForm.jlList = [...list.mj, ...list.fj];
  normalForm.clList = list.cl;
  normalForm.jyqxList = list.jy;
  normalForm.znzbList = list.zn;
  normalForm.xfbmid = normalForm.ssbmid
    ? normalForm.ssbmid
    : JSON.parse(window.localStorage.getItem("userInfo")).deptList[0].deptId;
  // normalForm.xfpbId = obj.pbInfo ? obj.pbInfo.id : "";
  normalForm.bblx = "01";
  if (!normalForm.xffwlx) {
    hintToast("请选择巡防类型！！");
    return;
  }
  Dialog.confirm({
    title: "提示",
    message: "是否确认报备信息无误!",
    confirmButtonColor: "#3e6ee8",
  }).then((res) => {
    addXFBB(normalForm).then((res) => {
      getMybbTodayNew().then((res) => {
        userInfo.bbId = res.id;
        userInfo.jzId = res.jzId;
        userInfo.jzMc = res.jzMc;
        setStorage("userInfo", JSON.stringify(userInfo));
      });
      hintToast("报备成功");
      finishReport({
        bbzt: "0",
        id: res,
      }).then((res) => {});
      router.go(-1);
    });
  });
}
//结束报备
function editFn(e) {
  Dialog.confirm({
    title: "提示",
    message: "是否确认结束报备!",
    confirmButtonColor: "#3e6ee8",
  }).then((res) => {
    finishReport({
      bbzt: "1",
      id: obj.bbInfo.id,
    }).then((res) => {
      userInfo.bbId = "";
      userInfo.jzId = "";
      userInfo.jzMc = "";
      setStorage("userInfo", JSON.stringify(userInfo));
      hintToast("报备结束成功");
      router.go(-1);
    });
  });
}
</script>

<style lang="scss" scoped>
@import "../../../assets/styles/mixin.scss";
.popupTitle {
  text-align: center;
  background-color: rgb(11, 137, 247);
  height: 6vh;
  line-height: 6vh;
}

.popbtn-box {
  width: 100%;
  display: flex;
  justify-content: space-around;
}

.check-item-tag {
  display: inline-block;
  margin: 0 6px;
}

.check-data-box {
  height: 25vh;
  overflow: auto;
}

.time-box {
  display: flex;
}

::v-deep .mulSelect .van-cell__title,
.van-cell__value {
  flex: unset;
}

::v-deep .mulSelect .van-cell__value {
  flex: 1;
}
.title_tab {
  @include font_color($font-color-theme);
  padding-left: 7vw;
  position: relative;
  margin: 2vw 0;
  letter-spacing: 2px;
}
.title_tab::after {
  content: "";
  position: absolute;
  top: 0;
  left: 5vw;
  bottom: 0;
  width: 4px;
  background: #3b6be7;
  border-radius: 2px;
}
.van-cell:after {
  display: none;
}
.van-cell {
  @include table_item_color($table-item-theme);
  box-sizing: border-box;
  border-radius: 4px;
  padding: 6px;
  margin: 8px 5%;
  width: 90%;
  overflow: hidden;
  color: var(--van-cell-text-color);
  font-size: var(--van-cell-font-size);
  line-height: var(--van-cell-line-height);
}
.popupTitle {
  color: #fff;
}
::v-deep .van-field__control--custom {
  justify-content: flex-end;
}
::v-deep .van-field__label {
  margin-right: 0px;
}
</style>
