<template>
    <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
        <card01 v-for="item in list" :key="item" :title="item.prsnTitle + ''" icon="notes"
            :description="`时间：${item.sttm} 至 ${item.entm}`" @click="handleClick(item.prsnId)" />
    </van-list>
</template>
<script setup>
import { ref, defineProps, watch, defineEmits } from 'vue';
import card01 from './card01.vue';
import { getCurrGroup, getInspBaseByPersid } from '@/api/inspect.js';

const emits = defineEmits(['onClick']);

const props = defineProps({
    type: {
        type: String,
    },
    batch: {
        type: String,
    },
})


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

function onLoad() {
    if (props.type === 'history' && props.batch) {
        getInspBaseByPersid(props.batch).then(res => {
            list.value = res.data;
            debugger
            loading.value = false;
            finished.value = true;
        })
    } else {
        getCurrGroup(props.batch).then(res => {
            list.value = res.data;
            loading.value = false;
            finished.value = true;
        })
    }
}

function handleClick(id) {
    emits('onClick', id);
}


watch(() => props.batch, batch => {
    if (batch) {
        onLoad()
    }
})
</script>