<template>
    <div class="flex_home">
        <HeadlineTag type="left" :value="deviceName"></HeadlineTag>
        <div class="box_arch">
            <div class="left_content">
                <div class="item_water_supply" v-for="(item, index) in leftData" :key="index">
                    <div class="left_supply">{{ item.title }}</div>
                    <div class="left_supply_value">{{ item.value || 0 }}{{ item.configUnit }}</div>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import HeadlineTag from '@/components/HeadlineTag'
const props = defineProps({
    waterData: {
        type: Object,
        default: {}
    }
})
const deviceName = ref('')
const leftData = ref([{
    title: '水箱液位',
    pointId: '01030016W0',
    value: '',
    configUnit: 'm',
}, {
    title: '压力',
    pointId: '03030002W0',
    value: '',
    configUnit: 'MPa',
}, {
    title: '温度',
    pointId: '01030009K0',
    value: '',
    configUnit: '℃',
}, {
    title: '湿度',
    pointId: '01030008K0',
    value: '',
    configUnit: '%RH',
}])
const deptData = ref([{ id: '9', deptName: '格尔木南站', address: '格尔木南站', longitude: 94.90405, latitude: 36.355008, status: '0' },
{ id: 'j494440', deptName: '大灶火', address: '大灶火站', longitude: 94.046751, latitude: 36.594943, status: '1' },
{ id: '3', deptName: '乌图美仁', address: '乌图美仁', longitude: 93.162812, latitude: 36.909138, status: '2' },
{ id: 'j625043', deptName: '甘森', address: '甘森', longitude: 92.470147, latitude: 37.285573, status: '3' },
{ id: '4', deptName: '茫崖', address: '茫崖', longitude: 90.80729, latitude: 38.250777, status: '3' },
{ id: '5', deptName: '那曲', address: '那曲', longitude: 91.990936, latitude: 31.442993, status: '3' },
{ id: '6', deptName: '那曲物流', address: '那曲物流', longitude: 92.067379, latitude: 31.486961, status: '3' },
{ id: '7', deptName: '当雄', address: '当雄', longitude: 91.106599, latitude: 30.472104, status: '3' },
{ id: '8', deptName: '安多', address: '安多', longitude: 91.667323, latitude: 32.250644, status: '3' }])
watch(() => props.waterData, (newVal) => {
    if (newVal) {
        leftData.value[0].value = newVal.liquid_level
        leftData.value[1].value = newVal.pressure
        leftData.value[2].value = newVal.temperature
        leftData.value[3].value = newVal.humidity
        deptData.value.forEach(item => {
            if (item.id == newVal.deviceid) {
                deviceName.value = item.deptName
            }
        });
    }
}, { deep: true, immediate: true })
</script>

<style scoped lang="scss">
.flex_home {
    width: 100%;
    height: auto;
    color: #fff;
    margin-bottom: 10px;
}

.box_arch {
    display: flex;
    align-items: center;
    justify-content: center;
    height: auto;
}

.arch_icon {
    width: 45%;
    height: 45%;
    margin-bottom: 5%;
}

.left_content {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.item_water_supply {
    width: calc(100% - 20px);
    height: 45px;
    background: url("@/assets/images/table_row_bg.png");
    background-size: 100% 100%;
    background-position: right;
    background-repeat: no-repeat;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0px 30px;
    margin: 10px 10px 0px 10px;
}

.left_supply {
    font-size: 18px;
    font-weight: bold;
}

.left_supply_value {
    font-size: 18px;
    color: #9bf06f;
    padding-left: 10px;
}

.right_content {
    flex: 1;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: flex-end;
}

.title_row {
    display: flex;
    align-items: center;
}
</style>