<template>
    <div>
        <!-- <div class="communication">
            <div><img src="../assets/cangwei.png" />{{storeCode}}号仓位</div>
            <div :class="statustext[1]">{{statustext[0]}}</div>
        </div> -->
        <div class="battery-number">
            <span>电池编号</span><span>{{sn}}</span>
        </div>
        <div class="percent">
            <div><span>{{soc | exchangerFilter}}</span></div>
            <div>%</div>
        </div>
        <div class="line"><span></span><span></span></div>
        <div class="power">
            <div class="power-percent">
                <span v-for="item in 100" :key="item" :style="{'backgroundColor': soc >= item ? setcolor :''}"></span>
            </div>
            <div class="power-text">
                <span>电池电量</span>
                <span v-if="showCode ==0">预计 <em>{{chgEstimatedTime}}</em> 分钟后充满</span>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    name: "BatteryStatus",
    props:['storeCode','comState','sn','chgEstimatedTime','soc','showCode'],
    computed:{
        statustext(){
            if(this.comState===1){
                return ['通讯正常','success']
            }else{
                return ['通讯异常','warning']
            }
        },
        setcolor(){
            if(this.soc<=30 && this.soc > 0){
                return '#ce4545'
            }else if(this.soc > 30 && this.soc <= 70){
                return '#f8dc4b'
            }else if(this.soc > 70){
                return '#44ab41'
            }
        }
    }
};
</script>

<style lang="scss" scoped>
.communication {
    display: flex;
    justify-content: space-between;
    div {
        line-height: 36px;
        font-size: 16px;
        font-weight: 600;
        height: 36px;
        text-align: center;
    }
    @media screen and (min-width: 1024px) and (max-width: 1153px) {
        div{
            font-weight: normal;
            font-size: 12px;
            white-space:nowrap;
            transform: scale(0.9);
        }
    }
    div:first-child {
        background-color: #1b263a;
        border: #25334d solid 1px;
        color: white;
        line-height: 34px;
        text-align: left;
        padding: 0 5px;
        img {
            vertical-align: middle;
            width: 30px;
            height: 30px;
        }
        @media screen and (min-width: 1024px) and (max-width: 1153px) {
            img{
                transform: scale(1.1);
                margin-bottom: 3px;
            }
        }
    }

    .success {
        color: #92fdb9;
        text-align: right;
    }
    .warning {
        color: #ff4d4f;
        text-align: right;
    }
}

.battery-number {
    margin-top: 16px;
    display: flex;

    :last-child {
        color: white;
        padding-left: 10px;
        font-size: 14px;
        font-weight: 600;
    }
}

.percent {
    margin-top: 16px;
    display: flex;

    div:first-child {
        background-color: #181e2a;
        width: 90%;
        border-radius: 5px;
        height: 10px;

        span {
            color: white;
            font-weight: 600;
            font-size: 16px;
            position: relative;
            bottom: 5px;
        }
    }

    :last-child {
        position: relative;
        bottom: 4px;
        width: 30px;
        text-align: right;
        font-weight: 500;
    }
}

.line {
    display: flex;


    :first-child {
        width: 1%;
        background-color: white;
        height: 2px;
    }

    :last-child {
        height: 2px;
        width: 97%;
        background-color: #14172a;
        margin-left: 5px;
    }
}

.power {
    display: flex;
    flex-direction: column;
    margin-top: 10px;

    .power-percent {
        width: 100%;
        display: flex;

        span {
            background-color: #1e2535;
            height: 6px;
            width: 2px;
            margin-right: 1px;
        }
    }

    .power-text {
        display: flex;
        width: 100%;
        margin-top: 1.2vh;
        margin-bottom: 0.8vh;
        justify-content: space-between;

        em {
            color: #246CF9;
            font-weight: 500;
            font-style: normal;
        }
    }
}
</style>