<template>
    <div class="_sameDay">
        <HeadlineTag value="水、电统计"></HeadlineTag>
        <div class="_sameDay_mains">
            <div class="_sameDay_mains_left" id="dayWidth" :style="{ '--heightSameDay': heightDay + 'px' }">
                <div class="_sameDay_mains_left_tuan"></div>
                <div class="_sameDay_mains_left_conter">
                    <div class="_sameDay_mains_left_conter_num">
                        {{resultData.PowerConsumption}}<span style="font-size: 12px;">kwh</span>/{{resultData.WaterConsumption}}<span style="font-size: 12px;">T</span></div>
                    <div class="_sameDay_mains_left_conter_text">今日实时电/水</div>
                </div>
            </div>
            <div class="_sameDay_mains_right">
                <div class="_sameDay_mains_right_item" v-for="item, index in sameDayList" :key="index">
                    <div class="_sameDay_mains_right_item_tuan">
                        <span class="_sameDay_mains_right_item_tuan_flag"
                            :style="{ backgroundColor: item.color }"></span>
                        <el-text class="w-150px mb-2" truncated style="color: #ccc;">
                            {{ item.name }}
                        </el-text>
                    </div>
                    <div class="_sameDay_mains_right_item__txt">
                        {{ item.state }}
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { ref } from "vue";
import HeadlineTag from '@/components/HeadlineTag'
const props = defineProps({
    resultData: {
        type: Object,
        default: {}
    }
})

const sameDayList = ref([
    { name: '昨日用电', state: 0, color: '#15acaa' },
    { name: '本月用电', state: 0, color: '#15acaa' },
    { name: '昨日用水', state: 0, color: '#FFC107' },
    { name: '本月用水', state: 0, color: '#FFC107' },
])

watch(() => props.resultData, (newVal) => {
    if (newVal) {
        sameDayList.value[0].state = newVal.YesterdayConsumption
        sameDayList.value[1].state = newVal.MonthElectricityConsumption
        sameDayList.value[2].state = newVal.YesterdayWaterConsumption
        sameDayList.value[3].state = newVal.MonthWaterConsumption
    }
}, { deep: true, immediate: true } // 开启深度监听
)
const heightDay = ref(0)
// 生命周期
onMounted(() => {
    var element = document.getElementById("dayWidth");
    var width = element.offsetWidth;
    heightDay.value = width
});
</script>
<style lang="scss" scoped>
._sameDay {
    display: flex;
    align-items: center;
    flex-direction: column;

    &_mains {
        flex: 1;
        width: calc(100% - 30px);
        padding-left: 30px;
        display: flex;
        align-items: center;

        &_left {
            width: 50%;
            height: var(--heightSameDay);
            position: relative;
            flex-shrink: 0;

            &_tuan {
                width: 100%;
                height: 100%;
                background: url("@/assets/images/content_circle.png");
                background-size: 100% 100%;
                background-position: center;
                background-repeat: no-repeat;
                animation: scanning 4s linear infinite;
            }

            &_conter {
                position: absolute;
                left: 0;
                top: 0;
                flex-shrink: 0;
                width: 100%;
                height: 100%;
                display: flex;
                flex-direction: column;
                align-items: center;
                justify-content: center;
                color: #fff;

                &_num {
                    font-size: 18px;
                }

                &_text {
                    font-size: 12px;
                }
            }
        }

        &_right {
            margin-left: 10px;
            flex: 1;
            color: #fff;

            &_item {
                display: flex;
                align-items: center;
                gap: 40px;
                padding: 5px 0;

                &_tuan {
                    display: flex;
                    align-items: center;

                    &_flag {
                        display: block;
                        width: 7px;
                        height: 7px;
                        border-radius: 50%;
                        margin-right: 10px;
                    }
                }

                &__txt {
                    font-size: 24px;
                }
            }
        }


    }
}

@keyframes scanning {
    to {
        transform: rotate(1turn);
    }
}
</style>