
<template>
    <div>
        <Head :headText='headText'></Head>
        <div class='nav-right'>
            <el-radio-group v-model='radio'>
                <el-radio label='1' @change='radioChange'>近30天</el-radio>
                <el-radio label='2' @change='radioChange' style='margin-right:10px;'>自定义</el-radio>
            </el-radio-group>
            <div class='count-top-right'>
                <span class='arrow-left' @click='daterangeLeft'></span>
                <span class='arrow-line arrow-line1' @click='daterangeLeft'></span>
                <el-date-picker
                    v-model='pickerVal2'
                    type='daterange'
                    format='yyyy.MM.dd'
                    value-format='timestamp'
                    range-separator='至'
                    start-placeholder='开始日期'
                    end-placeholder='结束日期'
                    :picker-options='pickerOptions'
                    @change='query(1)'
                ></el-date-picker>
                <span class='arrow-line' @click='daterangeRight'></span>
                <span class='arrow-right' @click='daterangeRight'></span>
            </div>
        </div>
        <div class='evaluateContainer'>
            <div class='ev-content'>
                <div class='ev-cont-div'>
                    <p class='ev-top Micbold'>室内温度满足率</p>
                    <div class='ev-bottom'>
                        <div class='ev-bottom-left'>
                            <ev-satisfaction-rate v-if='tindoorFillRate' :tindoorFillRate='tindoorFillRate'></ev-satisfaction-rate>
                        </div>
                        <div class='ev-bottom-right MicrYaHei'>
                            <p>
                                <!-- <span>超限时长</span>
                <span>{{'--'}}</span>
                                <span>h/日</span>-->
                            </p>
                            <p>
                                <span>超限程度</span>
                                <span>{{tindoorOverrunDegree}}</span>
                                <span>°C</span>
                            </p>
                        </div>
                    </div>
                </div>
                <div class='ev-cont-div'>
                    <p class='ev-top'>节能率</p>
                    <div class='ev-bottom'>
                        <div class='ev-bottom-left'>
                            <ev-energy-saving-rate v-if='energySavingRate' :energySavingRate='energySavingRate'></ev-energy-saving-rate>
                        </div>
                        <div class='ev-bottom-right'>
                            <p>
                                <span>节能量</span>
                                <span>{{energySaving}}</span>
                                <span>kWh</span>
                            </p>
                        </div>
                    </div>
                </div>
                <div class='ev-cont-div'>
                    <p class='ev-top'>策略执行率</p>
                    <div class='ev-bottom'>
                        <div class='ev-bottom-left'>
                            <ev-implementation-rate v-if='chillerExecuteRate' :chillerExecuteRate='chillerExecuteRate'></ev-implementation-rate>
                        </div>
                        <div class='ev-bottom-right'>
                            <p>
                                <span>执行数量</span>
                                <span>{{isExecutedNum}}</span>
                                <span>条</span>
                            </p>
                            <p>
                                <span>已发策略</span>
                                <span>{{allReceivedNum}}</span>
                                <span>条</span>
                            </p>
                        </div>
                    </div>
                </div>
            </div>
            <div class='ev-footer'>
                <ev-indoor-temperature v-if='energyDataList.length>=0' :energyDataList='energyDataList'></ev-indoor-temperature>
            </div>
        </div>
    </div>
</template>
<script>
import Head from '../main/index'
import EvEnergySavingRate from './evEnergySavingRate'
import EvImplementationRate from './evImplementationRate'
import EvSatisfactionRate from './evSatisfactionRate'
import EvIndoorTemperature from './evIndoorTemperature'
import { runDataQury } from '@/api/evaluate/evaluate.js'
import moment from 'moment'
import { timestamp2String } from '@/utils/helper.js'
import { mapGetters } from 'vuex'
export default {
    data() {
        return {
            headText: '运行评价',
            pickerOptions: {
                onPick: ({ maxDate, minDate }) => {
                    this.pickerMinDate = minDate.getTime()
                    if (maxDate) {
                        this.pickerMinDate = ''
                    }
                },
                disabledDate(time) {
                    return time.getTime() > Date.now() - 8.64e7
                }
            },
            date: '2',
            pickerVal2: [new Date().getTime() - 24 * 60 * 60 * 1000 * 30, new Date().getTime() - 24 * 60 * 60 * 1000],
            radio: '1',
            tindoorFillRate: '', //室内温度满足率
            energySavingRate: '', //节能率
            chillerExecuteRate: '', //略执行率
            energySaving: '', //节能量
            isExecutedNum: '', //已执行数量
            allReceivedNum: '', //共收到数量
            tindoorOverrunDegree: '', //超限程度
            energyDataList: [] //图标数据
        }
    },
    components: {
        Head,
        EvEnergySavingRate,
        EvImplementationRate,
        EvSatisfactionRate,
        EvIndoorTemperature
    },
    mounted() {
        this.query(0)
    },
    computed: {
        ...mapGetters(['projects', 'projectId'])
    },
    methods: {
        formatter(date) {
            return moment.unix(date / 1000).format('YYYYMMDD')
        },
        radioChange(val) {
            if (this.radio == '1') {
                this.pickerVal2 = [new Date().getTime() - 24 * 60 * 60 * 1000 * 30, new Date().getTime() - 24 * 60 * 60 * 1000]
            }
            this.query(0)
        },
        query(type) {
            if (type == '1') {
                this.radio = '2'
            }
            this.runDataQuryArr = []
            let getParams = {
                begin: timestamp2String(this.pickerVal2[0]).slice(0, 8),
                end: timestamp2String(this.pickerVal2[1]).slice(0, 8)
            }
            runDataQury(null, { getParams }).then(res => {
                if (res.result == 'success') {
                    this.tindoorFillRate = res.tindoorFillRate ? res.tindoorFillRate.toFixed(1) : 0 //室内温度满足率
                    console.log('室内温度满足率', this.tindoorFillRate)
                    this.energySavingRate = res.energySavingRate ? res.energySavingRate.toFixed(1) : 0 //节能率
                    console.log('节能率', this.energySavingRate)
                    this.chillerExecuteRate = res.chillerExecuteRate ? res.chillerExecuteRate.toFixed(1) : 0 //略执行率
                    console.log('略执行率', this.chillerExecuteRate)
                    this.energySaving = res.energySaving ? res.energySaving.toFixed(0) : 0 //节能量
                    console.log('节能量', this.energySaving)
                    this.isExecutedNum = res.isExecutedNum //已执行数量
                    console.log('已执行数量', this.isExecutedNum)
                    this.allReceivedNum = res.allReceivedNum //共收到数量
                    console.log('共收到数量', this.allReceivedNum)
                    this.tindoorOverrunDegree = res.tindoorOverrunDegree ? res.tindoorOverrunDegree.toFixed(1) : 0 //超限程度
                    console.log('超限程度', this.tindoorOverrunDegree)
                    this.energyDataList = res.dataList
                }
            })
        },
        daterangeLeft() {
            if (this.pickerVal2.length > 0) {
                // let dateTime = new Date(this.pickerVal2[0]);
                // let newData = this.formatter(
                //   new Date(dateTime.setDate(dateTime.getDate() - 1))
                // );
                this.pickerVal2[0] = this.pickerVal2[0] - 24 * 60 * 60 * 1000
                this.pickerVal2[1] = this.pickerVal2[1] - 24 * 60 * 60 * 1000
                // this.pickerVal2[0] =
                //   newData.slice(0, 4) +
                //   "." +
                //   newData.slice(4, 6) +
                //   "." +
                //   newData.slice(6, 8);
                this.pickerVal2 = [this.pickerVal2[0], this.pickerVal2[1]]
                this.query(0)
            }
        },
        daterangeRight() {
            if (this.pickerVal2.length > 0) {
                // let dateTime = new Date(this.pickerVal2[1]);
                // let newData = this.formatter(
                //   new Date(dateTime.setDate(dateTime.getDate() + 1))
                // );
                // this.pickerVal2[1] =
                //   newData.slice(0, 4) +
                //   "." +
                //   newData.slice(4, 6) +
                //   "." +
                //   newData.slice(6, 8);
                let end = this.formatter(new Date().getTime() - 24 * 60 * 60 * 1000)
                if (this.formatter(this.pickerVal2[1]) == end) {
                    this.pickerVal2[1] = new Date().getTime() - 24 * 60 * 60 * 1000
                } else {
                    this.pickerVal2[0] = this.pickerVal2[0] + 24 * 60 * 60 * 1000
                    this.pickerVal2[1] = this.pickerVal2[1] + 24 * 60 * 60 * 1000
                }
                this.pickerVal2 = [this.pickerVal2[0], this.pickerVal2[1]]
                this.query(0)
            }
        }
    }
}
</script>
<style lang="scss" scoped>
.nav-right {
    height: 48px;
    position: fixed;
    right: 24px;
    top: 53px;
    z-index: 1;
    display: flex;
    align-items: center;
    .count-top-right {
        width: 264px;
        height: 32px;
        background: rgba(255, 255, 255, 1);
        border-radius: 4px;
        border: 1px solid rgba(195, 198, 203, 1);
        display: flex;
        align-items: center;
        .arrow-left {
            width: 16px;
            height: 16px;
            background: url('../../assets/left.png');
            margin-right: 5px;
            margin-left: 7px;
            cursor: pointer;
        }
        .arrow-right {
            margin-right: 7px;
            margin-left: 5px;
            width: 16px;
            height: 16px;
            background: url('../../assets/right.png');
            cursor: pointer;
        }
        .arrow-line {
            display: inline-block;
            width: 2px;
            height: 16px;
            background: rgba(228, 229, 231, 1);
        }
        .arrow-line1 {
            margin-right: 3.5px;
        }
    }
}
.evaluateContainer {
    padding: 0 24px;
    background: #fff;
    .ev-content {
        margin-top: 20px;
        display: flex;
        .ev-cont-div {
            padding: 16px 20px;
            background: rgba(248, 249, 250, 1);
            border-radius: 6px;
            border: 1px solid rgba(238, 238, 238, 1);
            margin-right: 12px;
            flex: 1;
            .ev-top {
                margin: 0;
                height: 24px;
                font-size: 16px;
                color: rgba(31, 36, 41, 1);
                line-height: 21px;
            }
            .ev-bottom {
                display: flex;
                align-items: center;

                p {
                    margin: 0;
                }
                .ev-bottom-left {
                    width: 124px;
                    height: 124px;
                    justify-content: flex-start;
                    margin: 0;
                }
                .ev-bottom-right {
                    p {
                        font-size: 14px;
                        color: rgba(100, 108, 115, 1);
                        line-height: 19px;
                        span {
                            display: inline-block;
                        }
                        span:nth-of-type(1) {
                            margin-right: 12px;
                        }
                        span:nth-of-type(2) {
                            font-size: 18px;
                            font-family: Persagy;
                            color: rgba(32, 35, 42, 1);
                            line-height: 22px;
                        }
                        span:nth-of-type(3) {
                            font-size: 10px;
                        }
                    }
                    p:nth-of-type(1) {
                        margin-bottom: 10px;
                    }
                }
            }
        }
    }
    .ev-footer {
        width: 100%;
        height: 430px;
        margin-top: 36px;
    }
}
</style>
<style lang="scss">
.count-top-right {
    .count-top-right .el-input__inner {
        margin: 7px 0;
    }
    .el-input__inner {
        width: 210px;
        margin: 7px 6px;
        height: 22px;
        line-height: 22px;
        font-size: 12px;
        border: none;
    }
    .el-input__icon {
        display: none;
    }
    .el-range-editor.el-input__inner {
        padding: 3px 0;
    }
    .el-input--prefix .el-input__inner {
        padding-left: 5px;
    }
    .el-input--suffix .el-input__inner {
        padding-right: 5px;
    }
    .el-date-editor .el-range-input {
        width: 65%;
    }
    .el-date-editor .el-range-separator {
        line-height: 18px;
        color: #8d9399;
    }
    .el-date-editor .el-range-input {
        color: #1f2329;
    }
    .el-date-editor .el-range-separator {
        padding: 0 15px;
    }
    .el-radio__label {
        height: 22px;
        font-size: 14px;
        font-family: MicrosoftYaHei;
        color: rgba(31, 36, 41, 1);
        line-height: 19px;
        padding-left: 5px;
    }
    .el-radio {
        margin-right: 20px !important;
    }
}
</style>