<template>
    <!-- 储罐：水位 -->
    <div class="tank_body" :style="getTankBodyStyle">
        <!-- 罐体 -->
        <i class="icon iconfont-hnyz-colour tank zIndex10" :class="tankIconClass" :style="getTankStyle">
            <!-- 标题 -->
            <div class="tank_title" v-if="title" :style="{ fontSize: `${iconSize * 0.15}px` }">{{ title }}</div>
            <!-- 水位 -->
            <WaterLevelMap :waterLevelValue="waterLevelValue" :textSize="iconSize * 0.12"
                class="water_level water_level_pos3" />
        </i>
    </div>
</template>

<script setup>
import WaterLevelMap from '@/components/HnyzDcs/WaterLevelMapComponent.vue'

import { computed } from 'vue'

const props = defineProps({
    waterLevelValue: {// 水位值
        type: Number,
        default: -1,// -1表示未传水位值
    },
    iconSize: {//图标大小
        type: Number,
        default: 200,
    },
    title: {//罐名
        type: String,
    },
    iconWidth: {//图标宽度
        type: Number,
    },
    iconHeight: {//图标高度
        type: Number,
    },
})


//罐体样式
const getTankBodyStyle = computed(() => ({
    width: `${props.iconWidth ?? props.iconSize}px`,
    height: `${props.iconHeight ?? props.iconSize}px`,
    fontSize: `${props.iconSize}px`,
}))

// 罐子样式
const getTankStyle = computed(() => {
    const style = {
        fontSize: props.iconSize + 'px',
        display: 'inline-block'
    }
    //根据传进来的iconWidth和iconHeight来控制图标的大小
    const scaleX = props.iconWidth ? props.iconWidth / props.iconSize : 1
    const scaleY = props.iconHeight ? props.iconHeight / props.iconSize : 1

    if (scaleX !== 1 || scaleY !== 1) {
        style.transform = `scale(${scaleX}, ${scaleY})`
    }
    return style
})

// 罐型图标
const tankIconClass = computed(() => {
    return props.waterLevelValue >= 0 ? 'icon-hnyz-colourstorageTank_hollowedOut' : 'icon-hnyz-colourstorageTank'
});

// 仅传 waterLevelValue，内部组装 config
const waterLevelConfig = computed(() => ({
    data: [props.waterLevelValue],
    waveHeight: 5,// 波浪高度
}))



</script>

<style scoped lang="scss">
//水位罐
.tank_body {
    text-align: center;
    position: relative;

    .tank {
        position: relative;
        z-index: 10;

        //罐子名称
        .tank_title {
            position: absolute;
            top: 82%;
            left: 49%;
            transform: translate(-50%, -50%);
            font-size: 30px;
            color: #e65100;
            font-weight: bold;
        }

        // 水位
        .water_level {
            width: 58%;
            height: 60%;
        }

        //水位图位置
        .water_level_pos3 {
            z-index: -1;
            position: absolute;
            top: 16%;
            left: 22%;
        }

        .dv-water-pond-level :deep(canvas) {
            position: absolute;
            left: 0%;
        }

        .dv-water-pond-level :deep(rect) {
            // fill:unset;//去掉默认的颜色
            width: 99%;
            height: 99%;
            stroke-width: 0 !important;
        }

    }

}
</style>