<template>
    <div class="module-main">
        <div class="module-box">
            <div class="main-one">
                <div class="title" @click="clickUserRanking()">员工好评度排名</div>
                <dv-scroll-board  v-if="userPraiseFlag" :config="config" class="data" />
            </div>
            <div class="main-one">
                <div class="title"  @click="clickMateRanking()">耗材使用排名</div>
                <dv-scroll-board  v-if="flag2" :config="config2" class="data" />
            </div>
            <div class="main-there">
                <div class="module-title">
                    <span  @click="clickDepRanking()">热点科室排名</span>
                    <select v-model="type" class="module-select" @change="updateData">
                        <option value="1">运送</option>
                        <option value="2">陪护</option>
                    </select>
                </div>
                <dv-scroll-board v-if="flag3" :config="config3"  class="data"  />
            </div>

        </div>

        <popup-3 :visible="userVisible"  @closeClick="()=>{userVisible=false}" />
        <popup-4 :visible="mateVisible"  @closeClick="()=>{mateVisible=false}" />
        <popup-5 :visible="depVisible" :ctype="type"  @closeClick="()=>{depVisible=false}" />
    </div>
</template>

<script>
import Vue from 'vue';
import Component from 'vue-class-component';
import Popup3 from '../popup/popup3.vue';
import Popup4 from '../popup/popup4.vue';
import Popup5 from '../popup/popup5.vue';
import api from '../../api';

@Component({
    components: {
        Popup3,
        Popup4,
        Popup5,
    },
    props: {
        data: {
            type: Object,
            default: null,
        },
    },
})
export default class Echarts extends Vue {
    userVisible = false;

    mateVisible = false;

    depVisible = false;

    config = {
        data: [],
        rowNum: '4',
        oddRowBGC: 'rgba(17, 43, 117, 0.5)',
        evenRowBGC: 'rgba(9, 32, 99, 0.5)',
    }

    config2 = {
        data: [
        ],
        rowNum: '4',
        oddRowBGC: 'rgba(17, 43, 117, 0.5)',
        evenRowBGC: 'rgba(9, 32, 99, 0.5)',
    }

    config3 = {
        data: [
        ],
        rowNum: '4',
        oddRowBGC: 'rgba(17, 43, 117, 0.5)',
        evenRowBGC: 'rgba(9, 32, 99, 0.5)',
    }

    userPraiseFlag = false;

    flag2 = false;

    flag3 = false;

    timer = null;

    type = '1';

    created() {
        this.getUserPraise();
        this.getHotMate();
        this.getHotDep();
        setInterval(() => {
            this.getUserPraise();
            this.getHotMate();
            this.getHotDep();
        }, 5000 * 60);
    }

    updateData() {
        if (this.timer) { // 清除定时器
            clearInterval(this.timer);
        }
        this.getHotDep();
        this.timer = setInterval(() => {
            this.getHotDep();
        }, 1000 * 60 * 10);
    }

    getUserPraise() {
        api.getUserPraise().then((res) => {
            this.userPraiseFlag = false;
            this.$nextTick(() => {
                this.userPraiseFlag = true;
                this.config.data = res.data;
            });
        }).catch(() => {}).finally(() => {
            this.userPraiseFlag = true;
        });
    }

    getHotMate() {
        api.getHotMate().then((res) => {
            this.flag2 = false;
            this.$nextTick(() => {
                this.config2.data = res.data;
                this.flag2 = true;
            });
        }).catch(() => {}).finally(() => {
            this.flag2 = true;
        });
    }

    getHotDep() {
        api.getHotDep({
            type: this.type,
        }).then((res) => {
            this.flag3 = false;
            this.$nextTick(() => {
                this.config3.data = res.data;
                this.flag3 = true;
            });
        }).catch(() => {}).finally(() => {
            this.flag3 = true;
        });
    }

    clickUserRanking() {
        this.userVisible = true;
    }

    clickMateRanking() {
        this.mateVisible = true;
    }

    clickDepRanking() {
        this.depVisible = true;
    }
}
</script>

<style scoped lang="scss">
    .main-one{
        width: 33.3%;
        height: 100%;
        display: inline-block;
        float: left;
    }
    .main-one .title{
        width: calc(100% - 10px);
        height: 40px;
        line-height: 40px;
        font-size: 14px;
        color: #FFFFFF;
        padding-left: 10px;
        cursor: pointer;
    }
    .main-one .data{
        width: calc(100% - 20px);
        height: calc(100% - 50px);
        padding:0px 10px;
    }
    .main-there {
        width: 33.3%;
        height: 100%;
        display: inline-block;
        float: left;
    }
    .main-there .module-title{
        /* width: calc(100% - 10px);
        height: 40px;
        line-height: 40px;
        font-size: 14px;
        font-family: Source Han Sans CN;
        font-weight: bold;
        color: #FFFFFF;
        padding-left: 10px;
        overflow: hidden; */
        position: relative;
        height: 40px;
        line-height: 40px;
        font-size: 14px;
        cursor: pointer;
    }
    .main-there .data{
        width: calc(100% - 20px);
        height: calc(100% - 50px);
        padding:0px 10px;
    }

    .module-select{
        width: 50px;
        height: 20px;
        color: #A6D6FF;
        background-color: #3D7FFF;
        outline: none;
        border: 1px solid #A6D6FF;
        float: right;
        vertical-align: middle;
        margin-top: 10px;
        margin-right: 5px;
    }

</style>
