<template>
    <div id="device-control-wrapper">
        <div class="title">
            <div class="title-name">设备</div>
            <div class="all-close-btn" @click="allShutDown()">一键全关</div>
        </div>

        <div class="container">
            <div class="content">
                <div
                    v-for="(item, index) in deviceList"
                    :key="index"
                    class="device-card"
                    :class="{
                        'air-quality-you': item.airQuality === '优',
                        'air-quality-liang': item.airQuality === '良',
                        'air-quality-cha': item.airQuality === '差',
                    }"
                >
                    <div class="content-top">
                        <div class="device-name">{{ item.name }}</div>
                        <div v-if="item.self_clean !== 0" class="status-border" :class="{'need-clean-bg': item.self_clean === 1, 'cleaning-bg': item.self_clean === 2}">
                            <!-- 需清洁 -->
                            <span v-if="item.self_clean === 1" class="need-clean">需清洁</span>
                            <!-- 自清洁中 -->
                            <span v-if="item.self_clean === 2" class="cleaning">自清洁中</span>
                        </div>
                    </div>
                    <div class="content-btm">
                        <!-- 非空气盒子 -->
                        <div v-if="item.deviceType !== '02'" class="device-btm">
                            <div :class="!item.openFlg? 'shutdown': 'powerOn'">
                                <span
                                    v-for="i in item.statusArr"
                                    class="status"
                                    :class="!item.openFlg? '': i === '偏热'? 'hot': i === '偏冷'? 'cold': ''">
                                    {{ i }}
                                </span>
                                <span v-for="i in item.unitArr" class="unit">{{ i }}</span>
                            </div>
                            <div class="close-btn" @click="switchDevice(item)">
                                <img src="@/assets/imgs/device-control/power_on@2x.png" v-show="item.openFlg">
                                <img src="@/assets/imgs/device-control/shutdown@2x.png" v-show="!item.openFlg">
                            </div>
                        </div>
                        <!-- 空气盒子 -->
                        <div v-if="item.deviceType === '02'">
                            <div :class="!item.openFlg? 'shutdown': 'powerOn'" class="box-btm">
                                <div v-for="(j, i) in item.statusArr">
                                    <span class="status">{{ j }}</span><span class="unit" style="margin-right: 8px;">{{ item.unitArr[i] }}</span>
                                </div>
                                <div class="air-quality">{{ item.airQuality }}</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script lang="ts" setup>
import { ref, onMounted } from 'vue';

const deviceList: any = ref<any[]>([]);

onMounted(() => {
    deviceList.value = [
        {
            name: 'Q5全热',
            openFlg: true,
            deviceType: '4D',
            self_clean: 0,
            statusArr: ['34'],
            unitArr: ['ug/m³']
        }, {
            name: '书房空调',
            openFlg: false,
            deviceType: '01',
            self_clean: 1,
            statusArr: ['24'],
            unitArr: ['℃']
        }, {
            name: '厨房空调',
            openFlg: true,
            deviceType: '01',
            self_clean: 2,
            statusArr: ['偏热'],
            unitArr: []
        }, {
            name: '主卧空调',
            openFlg: true,
            deviceType: '01',
            self_clean: 0,
            statusArr: ['偏冷'],
            unitArr: []
        }, {
            name: '餐厅空调',
            openFlg: true,
            deviceType: '01',
            self_clean: 0,
            statusArr: ['24'],
            unitArr: ['℃ 设定']
        }, {
            name: '客厅空气盒子',
            openFlg: true,
            deviceType: '02',
            self_clean: 0,
            statusArr: ['25', '68'],
            unitArr: ['℃', '%'],
            airQuality: '良'
        }
    ]
})

/** 设备开关 */
const switchDevice = (item: any) => {
    item.openFlg = !item.openFlg;
}

/** 一键全关 */
const allShutDown = () => {
    deviceList.value.forEach((item: any) => {
        if (item.deviceType !== '02') {
            item.openFlg = false;
        }
    })
}
</script>

<style lang="scss" scoped>
#device-control-wrapper {
    width: 100vw;
    height: 100vh;
    background: #000;
    display: flex;
    flex-direction: column;
    font-family: SourceHanSansCN-Regular, SourceHanSansCN;

    .title {
        width: 100%;
        padding: 35px 0;
        position: relative;
        flex-shrink: 0;

        .title-name {
            text-align: center;
            color: #FFF;
            font-weight: 400;
            font-size: 40px;
        }

        .all-close-btn {
            color: #FFF;
            font-size: 32px;
            padding: 14px 18px;
            background: #394457;
            border-radius: 16px;
            position: absolute;
            top: 25px;
            right: 24px;
        }
    }

    .container {
        flex: 1;
        overflow: auto;
    }

    .content {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        padding: 0 24px;

        .device-card {
            width: 326px;
            height: 146px;
            box-sizing: border-box;
            background: #20252E;
            border-radius: 16px;
            padding: 22px 24px 10px 24px;
            margin-bottom: 20px;

            .content-top {
                display: flex;
                align-items: center;

                .device-name {
                    color: #FFF;
                    font-size: 24px;
                    margin-right: 10px;
                    padding: 6px 0;
                }

                .status-border {
                    font-size: 20px;
                    padding: 6px 10px;
                    border-radius: 16px;

                    span {
                        display: inline-block;
                    }
                }

                .need-clean-bg {
                    background: rgba($color: #FF8F4D, $alpha: 0.3);
                    color: #FF853D;
                }

                .cleaning-bg {
                    background: rgba($color: #4382FF, $alpha: 0.3);
                    color: #5991FF;
                }
            }

            .content-btm {
                margin-top: 18px;
                font-family: Roboto-Light, Roboto;

                // 关机
                .shutdown {
                    color: #999;
                }

                // 开机
                .powerOn {
                    color: #FFF;
                }

                .status {
                    font-size: 40px;
                    font-weight: 300;
                    margin-right: 4px;
                }

                .hot {
                    color: #FF8F4D;
                }

                .cold {
                    color: #507FDD;
                }

                .unit {
                    font-size: 18px;
                    font-weight: 400;
                }

                .air-quality {
                    font-size: 40px;
                }
            }

            // 空调设备底部
            .device-btm {
                display: flex;
                justify-content: space-between;

                .close-btn {
                    width: 60px;
                    height: 60px;
                    
                    img {
                        width: 100%;
                    }
                }
            }

            // 空气盒子底部
            .box-btm {
                display: flex;
                justify-content: space-between;
                align-items: flex-end;
            }
        }
        
        .air-quality-you {
            background: url('@/assets/imgs/device-control/air_quality_you@2x.png') no-repeat;
            background-size: cover;
        }

        .air-quality-liang {
            background: url('@/assets/imgs/device-control/air_quality_liang@2x.png') no-repeat;
            background-size: cover;
        }

        .air-quality-cha {
            background: url('@/assets/imgs/device-control/air_quality_cha@2x.png') no-repeat;
            background-size: cover;
        }
    }
}
</style>