<template>
  <div>
    <TopNav navTitle="打卡记录" :showRight="false" :showLeft="true" />
    <van-sticky>
      <div class="sticky_box">
        <Search placeholder="请输入人员姓名" v-model="kwd" :isSx="false" @update:sx="showPopup = !showPopup"
          @update:modelValue="onSearch"></Search>
      </div>
    </van-sticky>
    <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 yjxx.list" :key="index" :item="item" />
        <van-empty description="暂无信息" image="default" v-if="yjxx.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/clockList.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 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 yjxx = 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() {
  yjxx.list = [];
  yjxx.pageNum = 1;
  kwd.value = "";
  tabsIndex.value++;
  getList();
}
// 获取警情信息
function getList() {
  loading.value = true;
  qcckPost({
    pageCurrent: yjxx.pageNum,
    pageSize: yjxx.pageSize,
    dkrxm: kwd.value,
  }, "/mosty-qwzx/tbQwXfbb/selectXfbbDkPage")
    .then((res) => {
      loading.value = false;
      loadingPull.value = false;
      if (!res.records || res.records.length <= 0) showEmpty.value = true;
      if (yjxx.pageNum == 1) {
        yjxx.list = res.records;
      } else {
        res.records.forEach((item) => {
          yjxx.list.push(item);
        });
      }
      total.value = res.pages;
    })
    .catch((err) => {
      loading.value = false;
      showEmpty.value = true;
    });
}
/**
 * 关键字搜索
 * @param {Object} val
 */
function onSearch(val) {
  yjxx.pageNum = 1;
  getList();
}
function onLoad() {
  if (yjxx.pageNum >= total.value) {
    finished.value = true;
    return;
  }
  yjxx.pageNum += 1;
  getList();
}
</script>

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