<template>
    <div class="homePage">
        <div class="frameMain" :style="allHeight">
            <div class="menuList">
                <el-menu
                :default-active="$route.path"
                router
                :unique-opened="true"
                :default-openeds="openeds"
                @select="handleNodeClick"
                text-color="#fff"
                background-color="#184FB4"
                active-text-color="#fff">
                    <!-- 引入组件 -->
                    <menu-tree :menuData="forecastDatas"></menu-tree>
                </el-menu>
            </div>
            <div class="homeMain" :style="mainHeight">
                <div class="homeMain_tag">
                    <el-tag
                        v-for="tag in routeTags"
                        :key="tag.name"
                        closable
                        size="large"
                        class="tagArr"
                        effect="dark"
                        :type="tag.index === $route.path ? '': 'info'"
                        @close="handleClose(tag)"
                        @click="handleShowPage(tag)"
                    >
                        <span>{{ tag.name }}</span>
                    </el-tag>
                </div>
                <div class="mainMessage" :style="viewHeight">
                    <router-view></router-view>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import MenuTree from '../components/menuTreeconfig.vue'
import homeImg from '../assets/menuImg/home.png'
import yewuImg from '../assets/menuImg/yewu.png'
import tixiImg from '../assets/menuImg/tixi.png'
import zhishikuImg from '../assets/menuImg/zhishiku.png'
import quanxianImg from '../assets/menuImg/quanxian.png'
export default {
    components: {MenuTree},
    data() {
        return {
            forecastDatas: [],
            expendData: ['0'],
            openeds:[],
            routeTags: [],
            defaultProps: {
                children: 'children',
                label: 'label',
            }
        }
    },
    created(){
        this.forecastDatas = [
            {
                index: '/home',
                name: '考评首页',
                img: homeImg
            },
            {
                index: '1',
                name: '考评业务',
                img: yewuImg,
                children: [
                    {
                        index: '/assessment/evaluationStart',
                        name: '考评目标启动',
                    },
                    {
                        index: '/assessment/monthQuarter',
                        name: '月/季度目标考评'
                    },
                    {
                        index: '',
                        name: '年度目标考评'
                    },
                    {
                        index: '',
                        name: '考评项对标'
                    },
                    {
                        index: '',
                        name: '考评项预警'
                    },
                    {
                        index: '',
                        name: '人员考评'
                    },
                    {
                        index: '',
                        name: '任期考评'
                    },
                    {
                        index: '',
                        name: '考评监督'
                    },
                    {
                        index: '',
                        name: '考评评级'
                    },
                    {
                        index: '',
                        name: '考评报告'
                    },
                    {
                        index: '',
                        name: '考评公告'
                    },
                    {
                        index: '',
                        name: '单位考核结果应用'
                    },
                    {
                        index: '',
                        name: '部门考核结果应用'
                    }
                ]
            },
            {
                index: '2',
                name: '考评体系配置',
                img: tixiImg,
                children: [
                    {
                        index: '/evaluationSystem/evaluationIndex',
                        name: '考评指标管理',
                    },
                    {
                        index: '/evaluationSystem/evaluationRules',
                        name: '考评规则配置',
                    },
                    {
                        index: '/evaluationSystem/company',
                        name: '单位权重配置',
                    },
                    {
                        index: '/evaluationSystem/department',
                        name: '考评部门配置',
                    },
                    {
                        index: '/evaluationSystem/personnel',
                        name: '考评人员配置',
                    },
                    {
                        index: '',
                        name: '业绩考核系数配置',
                    },
                    {
                        index: '',
                        name: '党建考核系数配置',
                    },
                ]
            },
            {
                index: '3',
                name: '考评知识库',
                img: zhishikuImg,
                children: [
                    {
                        index: '/knowledgePage/scoringRules',
                        name: '考评得分规则',
                    },
                    {
                        name: '考评评级规则',
                    },
                    {
                        name: '考评预警规则',
                    }
                ]
            },
            {
                index: '4',
                name: '基础信息配置',
                img: quanxianImg,
                children: [
                    {
                        index: '',
                        name: '人员权限配置',
                    },
                    {
                        index: '',
                        name: '工作流程配置',
                    }
                ]
            }
        ]
        if (window.localStorage.getItem('routeTags')) {
            this.routeTags = JSON.parse(window.localStorage.getItem('routeTags'))
            if (this.$route?.path === '/') {
                this.$router.push({ path: this.routeTags[0].index})
            }
        } else {
            this.routeTags = [
                {
                    index: '/home',
                    name: '考评首页'
                }
            ]
            this.$router.push({ path: this.routeTags[0].index})
            window.localStorage.setItem('routeTags', JSON.stringify(this.routeTags))
        }
        
    },
    mounted() {
    },
    computed:{
        mainHeight() {
            return {
                // 'height': document.documentElement.clientHeight-50 + 'px'
                'height': '100vh'
            }
        },
        allHeight() {
            return {
                'width': '100%',
                // 'height': document.documentElement.clientHeight-40 + 'px'
                'height': '100vh'
            }
        },
        viewHeight() {
            return {
                'width': '100%',
                // 'height': document.documentElement.clientHeight-40 + 'px'
                'height': '91vh'
            }
        }
    },
    methods:{
        getBac(val) {
            let strWea = ''
            debugger
            if (val) {
                strWea = 'changeBacksty'
            } else {
                strWea = 'defaultBacksty'
            }
            return strWea
        },
        changeRoute(item) {
            if (item.index) {
                this.$router.push({ path: item.index})
            }
        },
        handleNodeClick(index, indexPath) {
            if (indexPath) {
                this.forecastDatas.forEach(it =>{
                    if (it.index !== '') {
                        if (it.index === indexPath[0]) {
                            if (!it.children) {
                                let showM = 0
                                this.routeTags.forEach(item =>{
                                    if (item.name === it.name) {
                                        showM++
                                    }
                                })
                                if (showM === 0) {
                                    this.routeTags.push(it)
                                }
                            } else {
                                it.children.forEach(iv =>{
                                    if (iv.index !== '') {
                                        if (iv.index === indexPath[1]) {
                                            let showM = 0
                                            this.routeTags.forEach(item =>{
                                                if (item.name === iv.name) {
                                                    showM++
                                                }
                                            })
                                            if (showM === 0) {
                                                this.routeTags.push(iv)
                                            }
                                        }
                                    }
                                })
                            }
                        }
                    }
                })
                window.localStorage.setItem('routeTags', JSON.stringify(this.routeTags))
            }
        },
        handleClose(tag) {
            if (this.routeTags.length > 1) {
                this.routeTags.splice(this.routeTags.indexOf(tag), 1)
                window.localStorage.setItem('routeTags', JSON.stringify(this.routeTags))
            }
        },
        handleShowPage(tag) {
            this.$router.push({ path: tag.index})
        }
    }
}
</script>

<style lang="less">
.homePage{
    display: flex;
    .leftMenu{
        width: 70px;
        .logoSty{
            padding: 10px 0 0 10px;
            img{
                width: 35px;
                height: 35px;
            }
        }
        .firstLevel{
            margin-top: 30px;
            .firstLevel_icon{
                margin-bottom: 30px;
                cursor: pointer;
                .firstLevel_img{
                    width: 35px;
                    height: 37px;
                    text-align: center;
                    border-radius: 5px;
                    position: relative;
                    left: 10px;
                    img{
                        position: relative;
                        top: 6px;
                        width: 20px;
                        height: 20px;
                    }
                    &:hover{
                        background: rgba(255,255,255,.2);
                    }
                }
                .changeBacksty{
                    background: rgba(255,255,255,.2);
                }
                .defaultBacksty{
                    background: rgba(255,255,255,0);
                }
                .firstLevel_title{
                    margin-left: 5px;
                    span{
                        font-size: 12px;
                        color: #fff;
                    }
                }
            }
        }
    }
    .frameMain{
        // background: #f3f7f8;
        border-radius: 30px;
        display: flex;
        .menuList{
            width: 13vw;
            height: 100vh;
            background-color: #184FB4;
            .el-menu{
                .el-sub-menu{
                    .el-menu--inline{
                        .el-menu-item{
                            height: 30px;
                            margin-bottom: 10px;
                            border-radius: 15px 0 0 15px;
                            width: 90%;
                            position: relative;
                            left: 12%;
                            padding-left: 15px;
                        }
                        .el-menu-item:hover, .el-menu-item.is-active{
                            background-color: #fff;
                            border-radius: 15px 0 0 15px;
                            color: #2778FF;
                            width: 90%;
                            position: relative;
                            left: 12%;
                            padding-left: 15px;
                        }
                        .el-sub-menu__title:hover{
                            background-color: #1063CB !important;
                        }
                    }
                }
            }
        }
        .homeMain{
            width: 86vw;
            .homeMain_tag{
                height:60px;
                border-bottom: 1px solid #D6DBEA;
                .tagArr{
                    height: 33px;
                    margin-left: 10px;
                    cursor: pointer;
                    position: relative;
                    top: 28px;
                }
                .el-tag--dark{
                    background-color: #184FB4;
                    border: 1px solid #184FB4;
                }
                .el-tag--info{
                    background-color: #E6EBF5;
                    border: 1px solid #E6EBF5;
                    color: #9DA5BE;
                    .el-tag__close{
                        color: #9DA5BE;
                    }
                }
            }
            .mainMessage{
                // width: 85vw;
                // height: 91vh;
                padding: 0 10px;
                // background: #fff;
                border-radius: 20px;
            }
        }
    }
}
</style>