<template>
    <Ssub-menu :icon="icon" :level="level" :hasTitle="hasTitle" :parent="parent">
        <template slot="title">{{menuitem.name}}</template>
        <template v-for="(item,index) in menuitem.children">

            <Smenu-item :icon="item.iconClass" :hasTitle="hasTitle"  v-if="item.isShow&&!(item.children&&item.children.length)" @click="handleOpenFunc(item)">{{item.name}}</Smenu-item>
            
            <Snav-sub-menus :icon="item.iconClass" :menuitem="item" v-if="item.isShow&&item.children&&item.children.length"></Snav-sub-menus>
        </template>
    </Ssub-menu>
</template>
<script> 
import {Smenu,SsubMenu,SmenuItem} from '../Smenus'
export default {
    name:'SnavSubMenus',
    inject:['addTab'],
    components:{
       Smenu,SsubMenu,SmenuItem
    },
    props:{
        icon:{
            type:String
        },
        menuitem:{
            type:Object
        },
        hasTitle:{
            type: Boolean,
        },
        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>