<template>
    <el-menu default-active="1-4-1" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose"
        :collapse="isCollapse" background-color="#545C65" text-color="#fff" active-text-color="#ffd04b">
        <h3>人员采样系统</h3>
        <!-- 渲染只有一级菜单的-->
        <el-menu-item v-for="item in noChildMenu" :index="item.path" :key="item.path" @click="clickMenu(item)">
            <i :class="'el-icon-' + item.icon"></i>
            <span slot="title">{{ item.label }}</span>
        </el-menu-item>
        <!-- 渲染包含二级菜单的 -->
        <el-submenu v-for="item in hasChildMenu" :index="item.path" :key="item.path">
            <template slot="title">
                <i :class="'el-icon-' + item.icon"></i>
                <span slot="title">{{ item.label }}</span>
            </template>
            <el-menu-item-group v-for="data in item.children" :key="data.path">
                <el-menu-item :index="data.path">{{ data.label }}</el-menu-item>
            </el-menu-item-group>
        </el-submenu>
    </el-menu>
</template>

<script>
export default {
    name: 'CommonAside',
    data() {
        return {
            isCollapse: false,
            menuList: [
                {
                    path: '/',
                    name: 'home',
                    label: '首页',
                    icon: 's-home',
                    url: 'Home/Home'
                }, {
                    path: '/admissionapplyman',
                    name: 'AdmissionApplyMan',
                    label: '入场申请人',
                    icon: 'el-icon-s-ticket',
                    url: 'AdmissionApplyMan/AdmissionApplyMan'
                },
                {
                    path: '/admissionapply',
                    name: 'AdmissionApply',
                    label: '入场申请',
                    icon: 'el-icon-s-ticket',
                    url: 'AdmissionApply/AdmissionApply'
                }, {
                    path: '/laboratory',
                    name: 'Laboratory',
                    label: '实验室',
                    icon: 'el-icon-office-building',
                    url: 'Laboratory/Laboratory'
                }, {
                    path: '/isolationpoint',
                    name: 'IsolationPoint',
                    label: '隔离点',
                    icon: 'el-icon-office-building',
                    url: 'IsolationPoint/IsolationPoint'
                }
            ]
        };
    },
    methods: {
        handleOpen(key, keyPath) {
            console.log(key, keyPath,1);
        },
        handleClose(key, keyPath) {
            console.log(key, keyPath);
        },
        clickMenu(item) {
            // console.log(item)
            this.$router.push({
                name: item.name
            })
        }
    },
    computed: {
        noChildMenu() {
            return this.menuList.filter(item => !item.children)
        },
        hasChildMenu() {
            return this.menuList.filter(item => item.children)
        }
    }
}
</script>

<style lang="less" scoped>
.el-menu-vertical-demo:not(.el-menu--collapse) {
    width: 200px;
    min-height: 400px;
}

.el-menu {
    height: 100%;
    text-align: left;
    border: none;

    h3 {
        color: #fff;
        text-align: center;
        line-height: 60px;
    }
}
</style>