<template>
    <div class="_energy">
        <layout>
            <template #left>
                <div style="height: 100%;display: flex;flex-direction: column;overflow: hidden;">
                    <consumptionWater :resultData="leftData.waterCount" style="flex: 1;" />
                    <consumptionPower :resultData="leftData.electricityCount" style="flex: 1;" />
                    <sameDay :resultData="leftData.OnedayWaterConsumption" style="flex: 1;" />
                </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;" />
                    <consume :resultData="leftData.waterNight" style="flex: 1;" />
                    <carbonEmission :resultData="leftData.electricityNight" style="flex: 1;" />
                </div>
            </template>
        </layout>
    </div>
</template>

<script setup name="Role">
import { getEnergy } from "@/api/system/energy"
import layout from "@/components/layout_/index.vue";
import sameDay from './modules/sameDay.vue'
import consumptionPower from './modules/consumptionPower.vue'
import consumptionWater from './modules/consumptionWater.vue'
import running from './modules/running.vue'
import carbonEmission from './modules/carbonEmission.vue'
import consume from './modules/consume.vue'

const intervalId = ref(null)
const leftData = ref({})
// 生命周期
onMounted(() => {
    getEnergyData()
});
onUnmounted(() => {
    clearInterval(intervalId.value);
})
function getEnergyData() {
    clearInterval(intervalId.value);
    getEnergy().then((res) => {
        if (res.code == 200) {
            leftData.value = res.data
            intervalId.value = setInterval(getEnergyData, 30000);
        }
    }).catch(() => {
        intervalId.value = null
        getEnergyData()
    })
}
</script>
<style lang="scss">
._energy {
    height: 100%;
}
</style>