<template>
    <p-sub-menu :level="level" :parent="parent">
        <template slot="title">{{menuitem.name}}</template>
        <template v-for="(item,index) in menuitem.children">
            <p-menu-item :icon="item.iconClass"  v-if="item.isShow&&!(item.children&&item.children.length)" @click="handleOpenFunc(item)">{{item.name}}</p-menu-item>            
            <nav-sub-menus :menuitem="item" v-if="item.isShow&&item.children&&item.children.length"></nav-sub-menus>
        </template>
    </p-sub-menu>
</template>
<script> 
import {PMenu,PSubMenu,PMenuItem} from '../menus'
export default {
    name:'NavSubMenus',
    inject:['addTab','showTab','hideTab'],
    components:{
        PMenu,PSubMenu,PMenuItem
    },
    props:{
        menuitem:{
            type:Object
        },
        level:{
            type:Number
        },
        parent:{
            type:Object
        }
    },
    methods:{  
        async handleOpenFunc(item){
            //url,title,uid,callback,nearest
            if(item.type== "link"){
                window.open(item.resUrl,item.name);
                return;
            }else if(item.type=="sso"){
                item.ssoUrl=await this.$store.dispatch("user/openSSOFuncPage",{
                    serviceUrl:item.resUrl
                });
            }

            // this.addTab(item.resUrl,item.name)
            this.addTab(item);//inject 提供的方法只能 传一个参数
        }
    }
}
</script>