<!--
 * @Author: 孙总
 * @Date: 2022-11-03 10:33:34
 * @LastEditTime: 2022-11-03 10:36:50
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \gx-app\src\pages\yyzx\yjtjInfo\gzyInfo.vue
-->
<template>
  <div>
    <TopNav navTitle="人员预警清单" :showRight="false" :showLeft="true" />
    <van-sticky>
      <div class="sticky_box">
        <Tabs :list="tabs" @onYjjb="onSelect" :type="'car'"></Tabs>
        <!-- <Search
          placeholder="请输入预警人员姓名"
          v-model="kwd"
          :isSx="true"
          @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"
          :path="`/yyzx/yjxx/yjDetail?id=${item.id}`"
          :dict="{ D_BZ_YJLX, D_BZ_TYJB }"
        />
        <van-empty
          description="暂无预警信息"
          image="default"
          v-if="yjxx.list.length <= 0 && !loading"
        />
      </van-list>
    </van-pull-refresh>
  </div>
</template>

<script setup>
import TopNav from "../../../components/topNav.vue";
import Tabs from "../../../components/tabs.vue";
import { getYjxxTj, getPageList } from "../../../api/yjxx.js";
import { useRoute } from "vue-router"
import SxPopup from "../../../components/SxPopup.vue";
import List from "../../../components/YjList.vue";
import Search from "../../../components/search.vue";
import { setTimeQuantum } from "../../../utils/tools.js";
import { getDictList, setDict } from "../../../utils/dict";
import { ref, watch, reactive, onMounted } from "vue";
const { D_BZ_YJLX, D_BZ_TYJB } = getDictList("D_BZ_YJLX", "D_BZ_TYJB"); //字典信息
const tabs = ref([
  {
    name: "全部",
    count: 0,
    yjjb: "",
  },
  {
    name: "红色预警",
    count: 0,
    yjjb: "10",
  },
  {
    name: "橙色预警",
    count: 0,
    yjjb: "20",
  },
  {
    name: "黄色预警",
    count: 0,
    yjjb: "30",
  },
  {
    name: "蓝色预警",
    count: 0,
    yjjb: "40",
  },
]);
const yjxx = reactive({
  pageNum: 1,
  pageSize: 10,
  yjJb: "",
  yjLx: "",
  startTime: "",
  endTime: "",
  yjLx: "",
  sxList: [], //筛选条件数据
  list: [], //预警列表数据
});
//时间段选项
yjxx.sxList[1] = setTimeQuantum();
const kwd = ref("");
const finished = ref(false);
const loading = ref(false);
const showPopup = ref(false); //筛选弹窗
const loadingPull = ref(false);
const total = ref(0);
const { yj_rysfzh, yj_ryxm  } = useRoute().query
onMounted(() => {
  // getList();
  getTabs();
});
//下拉刷新
function onRefresh() {
  yjxx.pageNum = 1;
  yjxx.yjJb = "";
  kwd.value = "";
  yjxx.startTime = "";
  yjxx.endTime = "";
  yjxx.yjLx = "";
  yjxx.list = [];
  getList();
  getTabs();
}
// 预警信息统计
function getTabs() {
  getYjxxTj({
    yjRysfzh: yj_rysfzh,
    yjRyxm: yj_ryxm
  }).then((res) => {
    res.forEach((element) => {
      tabs.value[0].count += element.count;
      if (element.yj_jb == "40") {
        tabs.value[4].count = element.count;
      }
      if (element.yj_jb == "30") {
        tabs.value[3].count = element.count;
      }
      if (element.yj_jb == "20") {
        tabs.value[2].count = element.count;
      }
      if (element.yj_jb == "10") {
        tabs.value[1].count = element.count;
      }
    });
  });
}
// 获取预警信息
function getList() {
  loading.value = true;
  getPageList({
    pageNum: yjxx.pageNum,
    pageSize: yjxx.pageSize,
    yjJb: yjxx.yjJb,
    yjRyxm: yj_ryxm,
    // startTime: yjxx.startTime,
    // endTime: yjxx.endTime,
    // yjLx: 1,
    yjRysfzh: yj_rysfzh
  })
    .then((res) => {
      loading.value = false;
      loadingPull.value = false;
      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;
    });
}
getList();
/**
 * tab选择
 * @param {Object} val
 */
function onSelect(val) {
  yjxx.pageNum = 1;
  yjxx.yjJb = tabs.value[val].yjjb;
  getList();
}
/**
 * 关键字搜索
 * @param {Object} val
 */
function onSearch(val) {
  yjxx.pageNum = 1;
  getList();
}
// 弹框盒子
function onConfirm(val) {
  yjxx.startTime = val.startTime;
  yjxx.endTime = val.endTime;
  let arr = [];
  val.list[0].array.forEach((item) => {
    if (item.isCheck) {
      arr.push(item.value);
    }
  });
  yjxx.yjLx = arr.join(",");
  yjxx.pageNum = 1;
  getList();
  showPopup.value = false;
}
function onLoad() {
  if (yjxx.pageNum >= total.value) {
    finished.value = true;
    return;
  }
  finished.value = false;
  yjxx.pageNum += 1;
  getList();
}
</script>

<style>
</style>