<template>
  <div class="content-wrapper">
    <div class="filter-wrapper">
      <gw-select v-model:value="inspectType" :columns="inspectTypes"/>
      <gw-select v-model:value="baseBatch" :columns="baseBatchs"/>
      <gw-select v-model:value="twoBatch" :columns="twoBatchs"/>
    </div>
    <van-pull-refresh v-model="loading" class="inspect-group-wrapper" @refresh="getInspBase(twoBatch, 3)">
      <card01 v-for="item in list" :key="item" :description="`时间：${item.sttm} 至 ${item.entm}`"
              :title="item.prsnTitle + ''"
              icon="notes"
              @click="jumpPage(`/inspect/${item.plnaId}/objects`, { inspectType  })"/>
    </van-pull-refresh>
  </div>
</template>
<script setup>
import {ref, watch} from "vue";
import GwSelect from "@/components/GwSelect.vue";
import card01 from '@/components/card01.vue';
import {getInspBaseByPersid} from "@/api/inspect";
import {jumpPage} from "@/utils/page";

const inspectType = ref('008');
const inspectTypes = [{text: '稽察工作', value: '008'}];

const baseBatch = ref(null);
const baseBatchs = ref([]);

const twoBatch = ref(null);
const twoBatchs = ref([]);

const list = ref([]);
const loading = ref(false);

function getInspBase(value, level = 1) {
  if (!value) {
    return;
  }
  // 获取批次
  getInspBaseByPersid(value).then(res => {
    if (level === 3) {
      list.value = res.data;
      loading.value = false;
      return;
    }
    if (level === 2) {
      // twoBatchs.value = res.data?.map(item => ({text: item.prsnTitle, value: item.plnaId}))
      // twoBatch.value = twoBatchs.value[0].value;
      // return;
      twoBatchs.value = (res.data || []).map(function(item) {
  return {
    text: item.prsnTitle,
    value: item.plnaId
  };
});

twoBatch.value = twoBatchs.value.length > 0 ? twoBatchs.value[0].value : null;
return;
    }
    // baseBatchs.value = res.data?.map(item => ({text: item.prsnTitle, value: item.plnaId})).reverse();
    // baseBatch.value = baseBatchs.value[0].value;
    baseBatchs.value = (res.data || []).map(function(item) {
  return {
    text: item.prsnTitle,
    value: item.plnaId
  };
});

baseBatch.value = baseBatchs.value.length > 0 ? baseBatchs.value[0].value : null;
return;
  });
}

watch(() => inspectType, inspectType => {
  if (inspectType.value) {
    getInspBase(inspectType.value);
  }
}, {deep: true, immediate: true})
watch(() => baseBatch, baseBatch => {
  if (baseBatch.value) {
    getInspBase(baseBatch.value, 2);
  }
}, {deep: true, immediate: true})
watch(() => twoBatch, twoBatch => {
  if (twoBatch.value) {
    getInspBase(twoBatch.value, 3)
  }
}, {deep: true, immediate: true})
</script>
<style lang="scss" scoped>
@import '@/assets/styles/filter.scss';

.content-wrapper {
  padding-top: 8px;
  height: 100%;
  overflow: auto;

  .inspect-group-wrapper {
    height: calc(100% - 35px);
    overflow: auto;
  }

}
</style>
