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

<script>
export default {
    name: "BatteryStatus",
    props:['storeCode','comState','sn','chgEstimatedTime','soc'],
    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;
	.cangwei{
		width: 20px;
		height: 20px;
		 vertical-align: middle;
		 margin-right: 5px;
		 margin-top: -2px;
	}
    view {
        line-height: 32px;
        font-size: 16px;
        font-weight: 600;
        height: 32px;
        text-align: center;
    }

    view:first-child {
        background-color: #1b263a;
        border: #25334d solid 1px;
        color: white;
        line-height: 32px;
        text-align: left;
        padding: 0 10px 0 5px;
        // .image {
        //     vertical-align: middle;
        // }
    }

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

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

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

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

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

        text {
            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;

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

    .power-text {
        display: flex;
        width: 100%;
        margin-top: 12px;
        justify-content: space-between;

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