<template>
    <div class="_energy">
        <layout>
            <template #left>
                <div style="height: 100%;display: flex;flex-direction: column;overflow: hidden;">
                    <deviceList :resultData="leftData.IlluminatingDevice" />
                </div>
            </template>
            <template #content>
                <!-- <p>景观照明</p> -->
            </template>
            <template #right>
                <div style="height: 100%;display: flex;flex-direction: column;overflow: hidden;">
                    <running :resultData="leftData" style="flex: 1;" />
                    <switchAll :resultData="leftData.RunAnalyse" style="flex: 1;" />
                    <eventList :resultData="leftData.EventList?.alarm" style="flex: 1;" />
                </div>
            </template>
        </layout>
    </div>
</template>

<script setup name="Role">
import { getIlluminating } from "@/api/system/illuminating"
import layout from "@/components/layout_/index.vue";
import deviceList from './modules/deviceList.vue'
import running from './modules/running.vue'
import eventList from './modules/eventList.vue'
import switchAll from './modules/switchAll.vue'
const route = useRoute()
const intervalId = ref(null)
const leftData = ref({})
// 生命周期
onMounted(() => {
    getIlluminatingData()
});
onUnmounted(() => {
    clearInterval(intervalId.value);
})
function getIlluminatingData() {
    clearInterval(intervalId.value);
    getIlluminating().then((res) => {
        if (res.code == 200) {
            leftData.value = res.data
            if (route.path == '/system/sceneLighting') {
                intervalId.value = setInterval(getIlluminatingData, 10000);
            } else {
                clearInterval(intervalId.value);
            }
        }
    }).catch(() => {
        if (route.path == '/system/sceneLighting') {
            intervalId.value = null
            getIlluminatingData()
        }
    })
}
</script>
<style lang="scss">
._energy {
    height: 100%;
}
</style>
