<template>
	<el-submenu v-if="menu.list && menu.list.length >= 1" :index="menu.menuId + ''"
		:popper-class="'site-sidebar--' + sidebarLayoutSkin + '-popper'">
		<template slot="title">
			<icon-svg :name="menu.icon || ''" class="site-sidebar__menu-icon"></icon-svg>
			<span>{{ menu.name }}</span>
		</template>
		<sub-menu v-for="item in menu.list" :key="item.menuId" :menu="item" :dynamicMenuRoutes="dynamicMenuRoutes">
		</sub-menu>
	</el-submenu>

	<el-menu-item v-else :index="menu.menuId + ''" @click="gotoRouteHandle(menu)">
		<!-- <el-badge class="item" v-if="menu.menuId==32&&chatNumYh!=0&&isAuth('userList:pass')" :value="chatNumYh">
			<icon-svg :name="menu.icon || ''" class="site-sidebar__menu-icon"></icon-svg>
			<span>{{ menu.name }}</span>
		</el-badge> -->
		<el-badge class="item" v-if="menu.menuId==116&&chatNumJl!=0&&isAuth('carBrandList:tongguo')" :value="chatNumJl">
			<icon-svg :name="menu.icon || ''" class="site-sidebar__menu-icon"></icon-svg>
			<span>{{ menu.name }}</span>
		</el-badge>
		<el-badge class="item" v-else-if="menu.menuId==77&&chatNumQy!=0&&isAuth('autonym:tongguo')" :value="chatNumQy">
			<icon-svg :name="menu.icon || ''" class="site-sidebar__menu-icon"></icon-svg>
			<span>{{ menu.name }}</span>
		</el-badge>
		<el-badge class="item" v-else-if="menu.menuId==72&&chatNumJzts!=0&&isAuth('locality:shenhe')" :value="chatNumJzts">
			<icon-svg :name="menu.icon || ''" class="site-sidebar__menu-icon"></icon-svg>
			<span>{{ menu.name }}</span>
		</el-badge>
		<el-badge class="item" v-else-if="menu.menuId==103&&chatNumDzh!=0&&isAuth('locality:shenhe')" :value="chatNumDzh">
			<icon-svg :name="menu.icon || ''" class="site-sidebar__menu-icon"></icon-svg>
			<span>{{ menu.name }}</span>
		</el-badge>
		<el-badge class="item" v-else-if="menu.menuId==118&&chatNumPP!=0&&isAuth('recruitListS:update')" :value="chatNumPP">
			<icon-svg :name="menu.icon || ''" class="site-sidebar__menu-icon"></icon-svg>
			<span>{{ menu.name }}</span>
		</el-badge>
		
		<span v-else>
			<icon-svg :name="menu.icon || ''" class="site-sidebar__menu-icon"></icon-svg>
			<span>{{ menu.name }}</span>
		</span>
	</el-menu-item>


</template>

<script>
	import SubMenu from './main-sidebar-sub-menu'
	export default {
		name: 'sub-menu',
		data(){
			return {
				chatNumJl:0,
				chatNumQy:0,
				chatNumYh:0,
				chatNumJzts:0,
				chatNumDzh:0,
				chatNumPP:0,
			}
		},
		props: {
			menu: {
				type: Object,
				required: true
			},
			dynamicMenuRoutes: {
				type: Array,
				required: true
			}
		},
		components: {
			SubMenu
		},
		computed: {
			sidebarLayoutSkin: {
				get() {
					return this.$store.state.common.sidebarLayoutSkin
				}
			}
		},
		methods: {
			// 通过menuId与动态(菜单)路由进行匹配跳转至指定路由
			gotoRouteHandle(menu) {
				var route = this.dynamicMenuRoutes.filter(item => item.meta.menuId === menu.menuId)
				if (route.length >= 1) {
					this.$router.push({
						name: route[0].name
					})
				}
			},
			
		},
		mounted() {
			setInterval(() => {
				if(this.$cookie.get('numberJl')){
					this.chatNumJl = this.$cookie.get('numberJl')
				}
				if(this.$cookie.get('numberQy')){
					this.chatNumQy = this.$cookie.get('numberQy')
				}
				if(this.$cookie.get('numberPP')){
					this.chatNumPP = this.$cookie.get('numberPP')
				}
				if(this.$cookie.get('numberYh')){
					this.chatNumYh = this.$cookie.get('numberYh')
				}
				if(this.$cookie.get('numberJzts')){
					this.chatNumJzts = this.$cookie.get('numberJzts')
				}
				if(this.$cookie.get('numberDzh')){
					this.chatNumDzh = this.$cookie.get('numberDzh')
				}
				
				
			}, 1000)
			// this.chatNum2 = setInterval(() => {
			// 	this.messageSelect2()
			// }, 6000)
			// this.chatNum3 = setInterval(() => {
			// 	this.messageSelect3()
			// }, 6000)
			// this.chatNum4 = setInterval(() => {
			// 	this.messageSelect4()
			// }, 6000)
		},
	}
</script>
<style>
	.item {
		/* margin-top: 10px;
		margin-right: 40px; */

	}

	.el-badge__content.is-fixed.is-dot {
		right: -5px;
		top: 20px;
	}
	.el-badge__content.is-fixed{
		right: 0px;
		top: 20px;
	}
</style>
