<template>
    <BaseReport :feature="feature" :reportData="reportData" :reportParams="reportParams" :reportName="reportName"
        :reportDateTime="reportDateTime" :isEmpty="isEmpty" :isDone="isDone" />
</template>

<script setup>

const feature = ref("");
const reportData = ref([]);
const reportParams = ref({});
const reportName = ref("");
const reportDateTime = ref(null);
const isEmpty = ref(false);
const isDone = ref(false);
const active = ref(0);


onBeforeMount(() => {
    const query = new URLSearchParams(window.location.search);
    feature.value = query.get("feature");

    if (!feature.value) return;
    getReport();
});

const getReport = async () => {
    let queryUrl = `/query/example?feature=${feature.value}`;
    const { data, error } = await useApiFetch(queryUrl).get().json();

    if (data.value && !error.value) {
        if (data.value.code === 200) {
            reportData.value = data.value.data.query_data.sort((a, b) => {
                return a.feature.sort - b.feature.sort;
            });
            reportParams.value = data.value.data.query_params;
            reportName.value = data.value.data.product_name;
            reportDateTime.value = data.value.data.create_time;
        } else if (data.value.code === 200003) {
            isEmpty.value = true;
        }
        isDone.value = true;
    }
};
</script>

<style lang="scss" scoped></style>
