
<template>
    <div>
        <Head :headText='headText'></Head>
        <div class='nav-right'>
            <img class='nav-icon' v-if='chillerIsNotExecutedCount ' src='@/assets/shape.png' alt />
            <span class='nav-text1' v-if='chillerIsNotExecutedCount'>今日已收到 {{chillerCount}} 条策略，其中有 {{chillerIsNotExecutedCount}} 条未执行</span>
            <span class='nav-text' v-else>今天已收到 {{chillerCommand.chillerCount || 0}} 条策略</span>
            <span class='nav-look MicrYaHei' @click='lookSnapshot'>查看</span>
        </div>
        <div class='strategyContainer'>
            <div class='strate-left'>
                <div class='strate-left-1'>今天营业时间</div>
                <div
                    class='strate-left-2'
                >{{chillerCommand.openTime?( chillerCommand.openTime.slice(0,2)+':'+chillerCommand.openTime.slice(2,4)):"--"}} - {{chillerCommand.endTime?(chillerCommand.endTime.slice(0,2)+':'+chillerCommand.endTime.slice(2,4)):"--"}}</div>
                <div class='strate-left-1'>当前运行模式</div>
                <div class='strate-left-2'>{{chillerCommand.model || '--'}}</div>
                <div class='strate-left-box'>
                    <div class='strate-left-info-1'>通风策略</div>
                    <div
                        class='strate-left-info'
                    >开启时间：{{chillerCommand.freshAirEqOpenTime?(chillerCommand.freshAirEqOpenTime.slice(0,2)+":"+chillerCommand.freshAirEqOpenTime.slice(2,4)):"--"}} - {{chillerCommand.freshAirEqCloseTime?(chillerCommand.freshAirEqCloseTime.slice(0,2)+":"+chillerCommand.freshAirEqCloseTime.slice(2,4)):"--"}}</div>
                    <div class='strate-left-info'>新风机组：{{chillerCommand.freshAirHandlingUnit}}</div>
                    <div class='strate-left-info'>组合式空调机组:{{chillerCommand.airHandlingUnit}}</div>
                </div>
            </div>
            <div class='starte-right'>
                <p class='strate-right-title'>当前状态</p>
                <water-unit :data='chillerOrg ' :type='1'></water-unit>
                <animation-box :data='chillerCommand' :chillerHourList='chillerHourList' :chillerCommandQ='chillerCommand'></animation-box>
            </div>
        </div>
        <el-dialog title='提示' :visible.sync='showTodayStrategy' width='1260px'>
            <today-strategy v-if='tableData.length>0 && idArr.length>0' :data='tableData' :idArr='idArr'></today-strategy>
        </el-dialog>
    </div>
</template>

<script>
import Head from '../main/index'
import animationBox from './animationBox'
import waterUnit from './waterUnit'
import TodayStrategy from '@/components/todayStrategy.vue'
import { queryCommand, getCommand } from '@/api/strategy/strategy.js'
export default {
    data() {
        return {
            headText: '当日运行策略',
            navText: true,
            showTodayStrategy: false,
            tableData: [],
            chillerCommand: {},
            chillerCount: 0,
            chillerIsNotExecutedCount: 0,
            today: '',
            now: '',
            chillerOrg: {},
            chillerHourList: [],
            idArr: []
        }
    },
    components: {
        Head,
        animationBox,
        waterUnit,
        TodayStrategy
    },
    methods: {
        lookSnapshot() {
            this.showTodayStrategy = true
            this.getData()
            // console.log(this.$store.state);
        },
        formatTime() {
            let year = new Date().getFullYear()
            let month = new Date().getMonth() + 1 > 10 ? new Date().getMonth() + 1 : '0' + (new Date().getMonth() + 1)
            let date = new Date().getDate() > 10 ? new Date().getDate() : '0' + new Date().getDate()
            return (this.today = year + '' + month + '' + date)
        },
        getPer5Time() {
            let now = new Date().getTime()
            let datetime = now - 5 * 60 * 1000
            let hours = new Date(datetime).getHours() < 10 ? '0' + new Date(datetime).getHours() : new Date(datetime).getHours()
            let minute = new Date(datetime).getMinutes() < 10 ? '0' + new Date(datetime).getMinutes() : new Date(datetime).getMinutes()
            return (this.now = hours + '' + minute)
        },
        getChiller() {
            let params = {
                getParams: {}
            }
            queryCommand(params).then(res => {
                console.log(res)
                this.chillerCount = res.chillerCount || 0
                this.chillerIsNotExecutedCount = res.chillerIsNotExecutedCount ? res.chillerIsNotExecutedCount : 0
                this.chillerOrg = res.chillerOrg
                this.chillerCommand = res.chillerCommand || {}
                console.log(this.chillerCommand)
                this.chillerHourList = res.chillerHourList
            })
        },
        getData() {
            this.idArr = []
            let params = {
                postParams: {
                    criteria: {
                        projectId: this.$store.state.projectId,
                        date: this.today
                    }
                }
            }
            console.log(this.$store.state.userInfo.userId)
            // return
            getCommand(params).then(res => {
                this.tableData = res.content ? res.content : []
                if (this.tableData.length > 0) {
                    this.tableData.forEach(el => {
                        this.idArr.push(el.appealId)
                    })
                }
                console.log(this.tableData)
            })
        }
    },
    mounted() {
        this.formatTime()
        this.getPer5Time()
        // let vm = this
        // setInterval(function(){
        //    vm.getData()
        // },1500)
        // this.getQuickData();
        this.getChiller()
    }
}
</script>

<style lang="scss" scoped>
.nav-right {
    height: 48px;
    position: fixed;
    right: 24px;
    top: 48px;
    z-index: 1;
    display: flex;
    align-items: center;
    .nav-text {
        height: 22px;
        font-size: 14px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: rgba(31, 36, 41, 1);
        line-height: 20px;
    }
    .nav-text1 {
        margin: 0 4px;
        height: 20px;
        font-size: 14px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: rgba(245, 78, 69, 1);
        line-height: 20px;
    }
    .nav-icon {
        width: 16px;
        height: 14px;
    }
    .nav-look {
        height: 22px;
        font-size: 14px;
        color: rgba(0, 145, 255, 1);
        line-height: 22px;
        margin: 0 12px;
        cursor: pointer;
    }
}

.strategyContainer {
    background: #fff;
    display: flex;
    .strate-left {
        min-width: 224px;
        background: #fff;
        border-right: 1px solid #f7f9fa;
        margin-left: 16px;
        .strate-left-1 {
            margin-top: 24px;
            color: #646c73;
            font-size: 14px;
        }
        .strate-left-2 {
            margin-top: 8px;
            font-size: 20px;
        }
        .strate-left-box {
            width: 192px;
            height: 150px;
            border-radius: 6px;
            background: #e4e5e7;
            margin-top: 67px;
            .strate-left-info-1 {
                padding-top: 20px;
                padding-left: 20px;
                font-size: 16px;
                color: #1f2429;
            }
            .strate-left-info {
                padding-left: 20px;
                font-size: 14px;
                margin-top: 8px;
                color: #646c73;
            }
        }
    }
    .starte-right {
        margin-right: 30px;
        flex: 1;
        .starte-right-title {
            height: 74px;
            line-height: 74px;
            color: #1f2429;
            font-size: 22px;
        }
    }
}
</style>