<template>
  <div>
    <TopNav navTitle="处警记录" :showRight="false" :showLeft="true" />
    <van-sticky>
      <div class="sticky_box">
        <Search placeholder="请输入上报人员姓名" v-model="kwd" :isSx="true" @update:sx="showPopup = !showPopup"
          @update:modelValue="onSearch"></Search>
      </div>
    </van-sticky>
    <SxPopup :showPopup="showPopup" :list="cjxx.sxList" :showTime='false' :p_top="110" @update:close="showPopup = false"
      @update:onConfirm="onConfirm" />
    <van-pull-refresh v-model="loadingPull" @refresh="onRefresh">
      <van-list v-model:loading="loading" :finished="finished" finished-text=" " @load="onLoad" offset="1"
        :immediate-check="false">
        <List v-for="(item, index) in cjxx.list" :key="index" :item="item" :dict="{ D_QW_CJSBLX }" />
        <van-empty description="暂无信息" image="default" v-if="cjxx.list.length <= 0 && showEmpty" />
      </van-list>
    </van-pull-refresh>
  </div>
</template>

<script setup>
import { getRypcList, getRypcCount } from "../../../api/common.js";
import TopNav from "../../../components/topNav.vue";
import Search from "../../../components/search.vue";
import Tabs from "../../../components/tabs.vue";
import SxPopup from "../../../components/SxPopup.vue";
import List from "../../../components/cjbsList.vue";
import { setTimeQuantum } from "../../../utils/tools.js";
import { getDictList, setDict } from "../../../utils/dict";
import { ref, reactive, onMounted, watch } from "vue";
import { qcckGet, qcckPost } from "@/api/qcckApi.js";
const showEmpty = ref(false);
const { D_QW_CJSBLX } = getDictList(
  "D_QW_CJSBLX"
); //字典信息
watch(D_QW_CJSBLX, (newValue) => {
  for (let i = 0; i < newValue.length; i++) {
    newValue[i].name = newValue[i].text;
    newValue[i].key = newValue[i].dm;
    newValue[i].isCheck = false;
  }
  cjxx.sxList = [
    {
      title: "警情类型",
      isCheckBox: true,
      array: newValue,
    },
  ];
  //时间段选项
  // cjxx.sxList[1] = setTimeQuantum();
});
const tabsIndex = ref(1);
const total = ref(0);
const tabs = ref([
  {
    name: "全部",
    count: 0,
    pclx: "",
  },
  {
    name: "盘查",
    count: 0,
    pclx: "9",
  },
  {
    name: "移交",
    count: 0,
    pclx: "2",
  },
  {
    name: "放行",
    count: 0,
    pclx: "1",
  },
]);
const cjxx = reactive({
  pageNum: 1,
  pageSize: 10,
  yjJb: "",
  yjLx: "",
  startTime: "",
  endTime: "",
  yjLx: "",
  sxList: [], //筛选条件数据
  list: [], //预警列表数据
});
const kwd = ref("");
const finished = ref(false);
const loading = ref(false);
const loadingPull = ref(false);
const showPopup = ref(false); //筛选弹窗

onMounted(() => {
  getList();
});
//下拉刷新
function onRefresh() {
  cjxx.list = [];
  cjxx.pageNum = 1;
  kwd.value = "";
  tabsIndex.value++;
  getList();
}
// 获取警情信息
function getList() {
  loading.value = true;
  qcckGet({
    pageCurrent: cjxx.pageNum,
    pageSize: cjxx.pageSize,
    cjsbRyXm: kwd.value,
    cjsbLx: cjxx.cjsbLx
  }, "/mosty-qwzx/tbQwCjbs/selectPage")
    .then((res) => {
      loading.value = false;
      loadingPull.value = false;
      if (!res.records || res.records.length <= 0) showEmpty.value = true;
      if (cjxx.pageNum == 1) {
        cjxx.list = res.records;
      } else {
        res.records.forEach((item) => {
          cjxx.list.push(item);
        });
      }
      total.value = res.pages;
    })
    .catch((err) => {
      loading.value = false;
      showEmpty.value = true;
    });
}
/**
 * 关键字搜索
 * @param {Object} val
 */
function onSearch(val) {
  cjxx.pageNum = 1;
  getList();
}
// 弹框盒子
function onConfirm(val) {
  cjxx.startTime = val.startTime;
  cjxx.endTime = val.endTime;
  let arr = [];
  if (val.list) {
    val.list[0].array.forEach((item) => {
      if (item.isCheck) {
        arr.push(item.value);
      }
    });
    cjxx.cjsbLx = arr.join(",");
  }

  cjxx.pageNum = 1;
  getList();
  showPopup.value = false;
}
function onLoad() {
  if (cjxx.pageNum >= total.value) {
    finished.value = true;
    return;
  }
  cjxx.pageNum += 1;
  getList();
}
</script>

<style lang="scss" scoped>
.sticky_box {
  margin-top: 13vw;
}
</style>
