<template>
    <!-- 落地罐：水位、ph、搅拌 -->
    <div class="tank_body" :style="getTankBodyStyle">
        <!-- 罐体 -->
        <i class="icon iconfont-hnyz-colour tank" :class="tankIconClass" :style="getTankStyle">
            <!-- 标题 200-30px-->
            <div class="tank_title" v-if="title" :style="{ fontSize: `${iconSize * 0.15}px` }">{{ title }}</div>
        </i>
        <!-- 搅拌电机 -->
        <div class="mixer_machine" v-if="typeof fanStatus === 'boolean'">
            <i class="icon iconfont icon-fengshan" :class="{ 'fan_run': fanStatus }"></i>
        </div>
        <!-- 水位图 -->
        <WaterLevelMap :waterLevelValue="waterLevelValue" :textSize="iconSize * 0.12"
            class="water_level water_level_pos" />
        <!-- ph值组件 -->
        <PhSlider :phValue="phValue" class="ph_pos" />
    </div>
</template>

<script setup>
import PhSlider from '@/components/HnyzDcs/PhSliderComponent.vue'
import WaterLevelMap from '@/components/HnyzDcs/WaterLevelMapComponent.vue'
import { computed } from 'vue'

const props = defineProps({
    phValue: {//ph
        type: Number,
        default: null
    },
    waterLevelValue: {// 水位值
        type: Number,
        default: -1,// -1表示未传水位值
    },
    fanStatus: {//风扇状态
        type: Boolean,
        default: undefined,
    },
    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 || props.fanStatus ? 'icon-hnyz-colourfloorTank_hollowedOut' : 'icon-hnyz-colourfloorTank'
});

//ph值
const phValue = computed({
    get() {
        return props.phValue
    },
})

</script>

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

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

    //水位图位置
    .water_level_pos {
        position: absolute;
        top: 17%;
        left: 25%;
    }

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

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

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

    .ph_pos {
        position: absolute;
        top: 22%;
        left: 60%;
        z-index: 100;
    }

    .mixer_machine {
        position: absolute;
        top: 37%;
        left: 50%;
        transform: translate(-50%, -50%);

        .icon-fengshan {
            color: aliceblue;
            font-size: 50px;
            display: inline-block;
        }

        //旋转动画
        @keyframes rotate-clockwise {
            from {
                transform: rotate(0deg);
            }

            to {
                transform: rotate(360deg);
            }
        }

        .fan_run {
            animation: rotate-clockwise 1s linear infinite;
        }
    }

}
</style>