<template>
	<el-submenu v-if="menu.list && menu.list.length >= 1" :index="menu.menuId + ''"
				:popper-class="'site-sidebar--' + sidebarLayoutSkin + '-popper'">
		<template slot="title">
			<span>
				<icon-svg :name="menu.icon || ''" class="site-sidebar__menu-icon"></icon-svg>
				<span>{{ menu.name }}</span>
			</span>
			<el-badge class="item" v-if="menu.menuId==311&&havaMsg(311)" is-dot>
				<span> </span>
			</el-badge>
			<el-badge class="item" v-if="menu.menuId==129&&chatNumLts!=0" is-dot>
				<span> </span>
			</el-badge>
			<el-badge class="item" v-if="menu.menuId==195&&chatNumLts!=0" is-dot>
				<span> </span>
			</el-badge>
		</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)">
		<icon-svg :name="menu.icon || ''" class="site-sidebar__menu-icon"></icon-svg>
		<span>{{ menu.name }}</span>
	</el-menu-item> -->
	<el-menu-item v-else :index="menu.menuId + ''" @click="gotoRouteHandle(menu)">
		<span>
			<icon-svg :name="menu.icon || ''" class="site-sidebar__menu-icon"></icon-svg>
			<span>{{ menu.name }}</span>
		</span>
		<el-badge class="item" v-if="menu.menuId==79&&chatNumLts!=0" :value="chatNumLts">
			<span> </span>
		</el-badge>
		<el-badge class="item" v-if="menu.menuId==174&&chatNumJjqz!=0" :value="chatNumJjqz">
			<span> </span>
		</el-badge>
		<el-badge class="item" v-if="menu.menuId==77&&chatNumDrz!=0" :value="chatNumDrz">
			<span> </span>
		</el-badge>
		<el-badge class="item" v-if="menu.menuId==167&&chatNumDts!=0" :value="chatNumDts">
			<span> </span>
		</el-badge>
		<el-badge class="item" v-if="menu.menuId==182&&chatNumDsm!=0" :value="chatNumDsm">
			<span> </span>
		</el-badge>
		<el-badge class="item" v-if="menu.menuId==224&&chatNumFwz!=0" :value="chatNumFwz">
			<span> </span>
		</el-badge>
		<el-badge class="item" v-if="menu.menuId==314&&chatNumSpq!=0" :value="chatNumSpq">
			<span> </span>
		</el-badge>
	</el-menu-item>
</template>

<script>
import SubMenu from './main-sidebar-sub-menu'
export default {
	name: 'sub-menu',
	data(){
		return {
			chatNumDrz:0,//实名认证
			chatNumDts:0,
			chatNumDsm:0,
			chatNumJjqz:0,
			chatNumFwz:0,
			chatNumLts:0,
			chatNumSpq: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
				})
			}
		},
		//检测菜单下是否有消息
		havaMsg(index){
			if(index == 311){
				return this.chatNumDrz != 0 || this.chatNumDts != 0 || this.chatNumJjqz != 0 || this.chatNumDsm != 0 || this.chatNumFwz != 0 || this.chatNumLts != 0 || this.chatNumSpq != 0
			}
			return false
		}
	},
	mounted() {
		setInterval(() => {
			if(this.$cookie.get('numberDrz')){
				this.chatNumDrz = this.$cookie.get('numberDrz')
			}
			if(this.$cookie.get('numberDts')){
				this.chatNumDts = this.$cookie.get('numberDts')
			}

			if(this.$cookie.get('numberJjqz')){
				this.chatNumJjqz = this.$cookie.get('numberJjqz')
			}
			if(this.$cookie.get('numberDsh')){
				this.chatNumDsm = this.$cookie.get('numberDsh')
			}
			if(this.$cookie.get('numberJg')>=0||this.$cookie.get('numberCs')>=0){
				this.chatNumFwz = Number(this.$cookie.get('numberCs')) + Number(this.$cookie.get('numberJg'))
			}
			if(this.$cookie.get('numberLts')){
				this.chatNumLts = this.$cookie.get('numberLts')
			}
			if(this.$cookie.get('numberSpq')){
				this.chatNumSpq = this.$cookie.get('numberSpq')
			}

		}, 1000)
		// this.chatNum2 = setInterval(() => {
		// 	this.messageSelect2()
		// }, 6000)
		// this.chatNum3 = setInterval(() => {
		// 	this.messageSelect3()
		// }, 6000)
		// this.chatNum4 = setInterval(() => {
		// 	this.messageSelect4()
		// }, 6000)
	},
}
</script>
<style scoped lang="scss">
.item {
	padding-left: 10px;
}

</style>
