<template>
    <div class="content-wrapper">
        <div class="filter-wrapper">
            <gw-select :columns="inspectTypes" v-model:value="inspectType" />
            <gw-select :columns="baseBatchs" v-model:value="baseBatch" />
            <gw-select :columns="twoBatchs" v-model:value="twoBatch" />
        </div>
        <van-pull-refresh class="inspect-group-wrapper" v-model="loading" @refresh="getInspBase(twoBatch, 3)">
            <card01 v-for="item in list" :key="item" :title="item.prsnTitle + ''" icon="notes"
                :description="`时间：${item.sttm} 至 ${item.entm}`" @click="jumpPage(`/inspect/${item.plnaId}/objects`, { inspectType  })" />
        </van-pull-refresh>
    </div>
</template>
<script setup>
import { ref, watch, defineEmits } 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 emits = defineEmits(['onClick']);

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;
        }
        baseBatchs.value = res.data.map(item => ({ text: item.prsnTitle, value: item.plnaId })).reverse();
        baseBatch.value = baseBatchs.value[0].value;
    });
}

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>