<template>
    <div class="sidebar">
        <el-menu
            class="sidebar-el-menu"
            :default-active="onRoutes"
            :collapse="collapse"
            background-color="#324157"
            text-color="#bfcbd9"
            active-text-color="#20a0ff"
            unique-opened
            router
        >
            <template v-for="item in items">
                <template v-if="item.subs">
                    <el-submenu :index="item.index" :key="item.index">
                        <template slot="title">
                            <i :class="item.icon"></i>
                            <span slot="title">{{ item.title }}</span>
                        </template>
                        <template v-for="subItem in item.subs">
                            <el-submenu
                                v-if="subItem.subs"
                                :index="subItem.index"
                                :key="subItem.index"
                            >
                                <template slot="title">{{ subItem.title }}</template>
                                <el-menu-item
                                    v-for="(threeItem,i) in subItem.subs"
                                    :key="i"
                                    :index="threeItem.index"
                                >{{ threeItem.title }}</el-menu-item>
                            </el-submenu>
                            <el-menu-item
                                v-else
                                :index="subItem.index"
                                :key="subItem.index"
                            >{{ subItem.title }}</el-menu-item>
                        </template>
                    </el-submenu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.index" :key="item.index">
                        <i :class="item.icon"></i>
                        <span slot="title">{{ item.title }}</span>
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>

<script>
import bus from '../common/bus';
export default {
    data() {
        return {
            collapse: false,
			items:""
        };
    },
    computed: {
        onRoutes() {
            return this.$route.path.replace('/', '');
        }
    },
    created() {
		console.log("侧边")
        // 通过 Event Bus 进行组件间通信，来折叠侧边栏
        bus.$on('collapse', msg => {
            this.collapse = msg;
            bus.$emit('collapse-content', msg);
        });
        bus.$on('usertype', msg => {
          let type=msg;
		  if(type==1){
			  this.items= [
                             {
                                icon: 'el-icon-lx-home',
                                index: '/purchaser/Home',
                                title: '首页'
                            },
                            {
                                icon: 'el-icon-lx-home',
            					index:"2",
                                title: '招标管理',
            					subs:[
            						{
            						icon: 'el-icon-lx-home',
            						index: '/purchaser/bid/administrationList',
            						title: '招标项目管理',
            						}
            					]
                            },
                            {
                                icon: 'el-icon-lx-cascades',
                                title: '应收账款买断管理',
            					index:'3',
            					subs:[
            						{
            						icon: 'el-icon-lx-home',
            						index: '/purchaser/buyOut/buyoutList',
            						title: '应收账款买断列表',
            						}
            					]
                            },
                            {
                                icon: 'el-icon-lx-cascades',
                                title: '供应商管理',
            					index:'4',
            					subs:[
            						{
            						icon: 'el-icon-lx-home',
            						index: '/purchaser/supply/allSupplyList',
            						title: '供应商列表',
            						},
            						{
            						icon: 'el-icon-lx-home',
            						index: '/purchaser/supply/mySupplyList',
            						title: '我的供应商',
            						}
            					]
                            },
            
                            {
                                icon: 'el-icon-lx-copy',
                                title: '组织管理',
            					index:'5',
            					subs:[
            						{
            						icon: 'el-icon-lx-home',
            						index: '/purchaser/organization/informationSee',
            						title: '单位信息',
            						},
            						{
            						icon: 'el-icon-lx-home',
            						index: '/purchaser/organization/memberManagement',
            						title: '成员管理',
            						},
            						{
            						icon: 'el-icon-lx-home',
            						index: '/purchaser/organization/jurisdictionList',
            						title: '角色管理',
            						}
            					]
                            },
                            {
                                icon: 'el-icon-lx-redpacket_fill',
                                title: '系统管理',
            					index:'6',
            					subs:[
            						{
            							icon: 'el-icon-lx-home',
            							index: '/purchaser/organization/jurisdictionList',
            							title: 'CA绑定与解除',
            						},
            						{
            							icon: 'el-icon-lx-home',
            							index: '/purchaser/system/logList',
            							title: '日志列表',
            						},
            					]
                            }
                        ]
		  }else{
			  this.items=[
			     {
			        icon: 'el-icon-lx-home',
			        index: '/supply/Home',
			        title: '首页'
			    },
			    {
			        icon: 'el-icon-lx-home',
					index:"2",
			        title: '招标管理',
					subs:[
						{
						icon: 'el-icon-lx-home',
						index: '/supply/bid/signupOnline',
						title: '在线报名',
						},
						{
						icon: 'el-icon-lx-home',
						index: '/supply/bid/joinProject/projectList',
						title: '我参与的项目',
						}
					]
			    },
			    {
			        icon: 'el-icon-lx-cascades',
			        title: '应收账款买断管理',
					index:'3',
					subs:[
						{
						icon: 'el-icon-lx-home',
						index: '/supply/buyOut/buyoutList',
						title: '应收账款买断列表',
						}
					]
			    },	
			    {
			        icon: 'el-icon-lx-copy',
			        title: '组织管理',
					index:'5',
					subs:[
						{
						icon: 'el-icon-lx-home',
						index: '/supply/organization/informationSee',
						title: '单位信息',
						},
						{
						icon: 'el-icon-lx-home',
						index: '/supply/organization/memberManagement',
						title: '成员管理',
						},
						{
						icon: 'el-icon-lx-home',
						index: '/supply/organization/jurisdictionList',
						title: '角色管理',
						}
					]
			    },
			    {
			        icon: 'el-icon-lx-redpacket_fill',
			        title: '系统管理',
					index:'6',
					subs:[
						{
							icon: 'el-icon-lx-home',
							index: '/supply/organization/jurisdictionList',
							title: 'CA绑定与解除',
						},
						{
							icon: 'el-icon-lx-home',
							index: '/supply/system/logList',
							title: '日志列表',
						},
					]
			    },
				{
				    icon: 'el-icon-lx-cascades',
				    title: '制作投标文件',
					index:'4',
					subs:[
						{
						icon: 'el-icon-lx-home',
						index: '/supply/markBid/markBid',
						title: '制作投标文件',
						}
					]
				},
			]
		  }
        });
    },
    methods: {
       
    }
};
</script>

<style scoped>
.sidebar {
    display: block;
    position: absolute;
    left: 0;
    top: 70px;
    bottom: 0;
    overflow-y: scroll;
}
.sidebar::-webkit-scrollbar {
    width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
    width: 250px;
}
.sidebar > ul {
    height: 100%;
}
</style>
