<template>
    <div class="storage-item">
        <div class="container">
            <BatteryStatus
            :storeCode="storeCode"
            :comState="comState"
            :sn="sn"
            :soc="soc"
            :chgEstimatedTime="chgEstimatedTime"
            ></BatteryStatus>
            <div class="battery-info">
                <BatteryInfo :num="current" unit="A" text="电流"></BatteryInfo>
                <BatteryInfo :num="voltage" unit="V" text="电压"></BatteryInfo>
                <BatteryInfo :num="minTemperature" unit="℃" text="最低温度"></BatteryInfo>
                <BatteryInfo :num="maxTemperature" unit="℃" text="最高温度"></BatteryInfo>
                <BatteryInfo :num="maxCellVoltage" unit="V" text="最高单体电压"></BatteryInfo>
                <BatteryInfo :num="minCellVoltage" unit="V" text="最低单体电压"></BatteryInfo>
                <BatteryInfo :num="soh" unit="%" text="SOH"></BatteryInfo>
                <div class="info-right">
                    <img src="../assets/s1.png"><span class="text">{{StateNum}}</span>
                </div>
            </div>
            <div class="battery-charger">
                <BatteryCharger
                :chargerCode="chargerInfoVo.chargerCode"
                :comState="chargerInfoVo.comState"
                :chgState="chargerInfoVo.chgState"
                :sn="sn"
                :storeState="storeState"
                v-show="chargerInfoVo.chargerCode"></BatteryCharger>
                <div class="battery-info" v-show="chargerInfoVo.chargerCode">
                    <BatteryInfo :num="chargerInfoVo.demandCurrent" unit="A" text="需求电流"></BatteryInfo>
                    <BatteryInfo :num="chargerInfoVo.demandVoltage" unit="V" text="需求电压"></BatteryInfo>
                    <BatteryInfo :num="chargerInfoVo.chgCurrent" unit="A" text="充电电流"></BatteryInfo>
                    <BatteryInfo :num="chargerInfoVo.chgVoltage" unit="V" text="充电电压"></BatteryInfo>
                    <BatteryInfo :num="chargerInfoVo.chgCapacity" unit="kwh" text="充电电量"></BatteryInfo>
                    <div class="info-right" :style="chargerColor">
                        <img :src="require('../assets/'+`s${chargerState[0]}`+'.png')"><span>{{chargerState[1]}}</span>
                    </div>
                </div>
                <img src="../assets/nodata.png" class="nodata" v-show="!chargerInfoVo.chargerCode">
            </div>
        </div>
    </div>
</template>

<script>
import BatteryInfo from "./BatteryInfo.vue";
import BatteryStatus from "./BatteryStatus.vue";
import BatteryCharger from "./BatteryCharger.vue"
export default {
    name:"StorageInfo",
    props:[
        'storeCode',
        'comState',
        'sn',
        'soc',
        'chgEstimatedTime',
        'current',
        'voltage',
        'minTemperature',
        'maxTemperature',
        'maxCellVoltage',
        'minCellVoltage',
        'soh',
        'storeState',
        'chargerInfoVo'
    ],
    components: {
        BatteryInfo,
        BatteryStatus,
        BatteryCharger
    },
    data(){
        return{
        }
    },
    computed:{
        chargerState(){
            if(this.chargerInfoVo.chgState === 1){
                return [3,' 状态：准备充电']
            }else if(this.chargerInfoVo.chgState === 2){
                return [1,' 状态：充电中']
            }else if(this.chargerInfoVo.chgState === 3){
                return [2,' 状态：充电完成']
            }else if(this.chargerInfoVo.chgState === 4){
                return [8,' 状态：启动失败']
            }else if(this.chargerInfoVo.chgState === 5){
                return [6,' 状态：预约']
            }else if(this.chargerInfoVo.chgState === 6){
                return [5,' 状态：故障']
            }else if(this.chargerInfoVo.chgState === 0){
                return [7,' 状态：空闲']
            }else{
                return [4,' 状态：无法获取']
            }
        },
        chargerColor(){
            if(this.chargerInfoVo.chgState === 3){
                return 'background-color:rgb(19,33,39,0.9);border:#477c62 solid 1px'
            }else if(this.chargerInfoVo.chgState ===1 || this.chargerInfoVo.chgState === 5){
                return 'background-color:rgb(20,38,50,0.9);border:#4a9dab solid 1px'
            }else if(this.chargerInfoVo.chgState ===2 || this.chargerInfoVo.chgState === 0){
                return ''
            }else{
                return 'background-color:rgb(32,25,36,0.9);border:#94494d solid 1px'
            }
        },
        StateNum(){
            if(this.storeState === 0){
                return '空仓'
            }else if(this.storeState === 1){
                return '有电池'
            }else{
                return '连接异常'
            }
        }
    }
};
</script >
<style lang="scss" scoped>
    .storage-item{
        width: 19%;
        background-color: #0a101c;
        min-height: 100%;
        margin-right: 22px;
        .container{
            padding: 1.3vh 15px 0.5vh 15px;
            color: #404a63;
            font-size: 15px;
            
            .battery-info{
                display: flex;
                margin-top: 16px;
                justify-content: space-between;
                flex-wrap: wrap;
                .info-right{
                    width: 46%;
                    height: 34px;
                    line-height:32px;
                    text-align: center;
                    font-size: 14px;
                    font-weight: 500;
                    color: white;
                    background-color: #0e1f31;
                    border: #1b71a4 solid 1px;
                    img{
                        vertical-align: middle;
                    }
                }
                .info-warning{
                    width: 46%;
                    background-color: #201823;
                    border: #834246 solid 1px;
                    height: 34px;
                    line-height:32px;
                    text-align: center;
                    font-size: 14px;
                    font-weight: 500;
                    color: white;
                    img{
                        vertical-align: middle;
                    }
                }
            }
            .battery-charger{
                width: 100%;
                min-height: 228px;
                .nodata{
                    position: relative;
                    left: calc(50% - 33px);
                    margin-top: 6vh;
                    width: 66px;
                    height: 66px;
                }
            }
        }
    }
</style>