<template>
    <div>
        <!-- 日报 -->
        <daytemple v-if="state.type == '1'" :typelist="state.typelist" :buslist="state.buslist" :form="state.form"
            :list="state.list"></daytemple>

        <!-- 月报 -->
        <monthtemple v-if="state.type == '2'" :typelist="state.typelist" :buslist="state.buslist" :form="state.form"
            :list="state.list">
        </monthtemple>

        <!-- 建设部报表 -->
        <constructtemple v-if="state.type == '3'" :typelist="state.typelist" :buslist="state.buslist" :form="state.form"
            :list="state.list">
        </constructtemple>

        <!-- 省厅报表 -->
        <provincestemple v-if="state.type == '4'" :typelist="state.typelist" :buslist="state.buslist" :form="state.form"
            :list="state.list">
        </provincestemple>
    </div>
</template>

<script setup lang="ts" name="daydetail">
import { defineAsyncComponent, reactive, onMounted, ref } from 'vue';
import { ElMessageBox, ElLoading, ElMessage, ElNotification } from 'element-plus';
import { useRoute, useRouter } from "vue-router";
import { getApi } from "/@/api/district/index";
let loading: any;
const route = useRoute();
const router = useRouter();
import mittBus from "/@/utils/mitt";

// 日报
const daytemple = defineAsyncComponent(
    () => import("/@/views/district/temple/day.vue")
);

// 月报
const monthtemple = defineAsyncComponent(
    () => import("/@/views/district/temple/month.vue")
);

// 建设部报表
const constructtemple = defineAsyncComponent(
    () => import("/@/views/district/temple/construct.vue")
);

// 省厅报表
const provincestemple = defineAsyncComponent(
    () => import("/@/views/district/temple/provinces.vue")
);


const goBack = () => {
    router.go(-1);
    mittBus.emit(
        "onCurrentContextmenuClick",
        Object.assign({}, { contextMenuClickId: 1, ...route })
    );
};

// 定义变量内容
const state = reactive({
    uid: '' as any,
    type: '' as any,
    list: [] as any,
    form: {},
    typelist: [],
    buslist: []
});

async function daygetlist() {
    let item = await getApi().dayget(state.uid)
    state.form = item.data.apply;
    state.list = [item.data.escalation]
    getsor();
}

async function monthgetlist() {
    let item = await getApi().monthget(state.uid)
    state.form = item.data.apply;
    state.list = [item.data.escalation]
    getsor();
}

async function jsgetlist() {
    let item = await getApi().jsget(state.uid)
    state.form = item.data.apply;
    state.list = item.data.escalation
    getsor();
}


async function stgetlist() {
    let item = await getApi().stget(state.uid)
    state.form = item.data.apply;
    state.list = item.data.escalation
    getsor();
}

async function getsor() {
    // 获取type
    const item = await getApi().gettype();
    state.typelist = item.data;
    // 获取状态
    const items = await getApi().getbus();
    state.buslist = items.data;
    loading.close()

}

// 页面加载时
onMounted(() => {
    state.uid = route.query.id
    state.type = route.query.type
    loading = ElLoading.service({
        lock: true,
        text: 'Loading',
        background: 'rgba(0, 0, 0, 0.7)',
    })
    if (route.query.type == '1') return daygetlist();
    if (route.query.type == '2') return monthgetlist();
    if (route.query.type == '3') return jsgetlist();
    if (route.query.type == '4') return stgetlist();
});
</script>

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