<template>
    <div v-if="HasAuth" class="page-sidebar sidebar-fixed" id="sidebar">
        <ul class="nav sidebar-menu">
            <template v-for="item in Menu">
                <li class="" v-bind:id="item.MenuId" >
                <a href="javascript:void(0)" class="menu-dropdown ">
                    <i class="menu-icon fa fa-table"></i>
                    <span class="menu-text"> {{item.FullName}} </span>
                    <i class="menu-expand"></i>
                </a>

                <ul class="submenu">
                    <template v-for="subitem in item.children">
                        <li class="vue-menu" v-bind:id="subitem.MenuId">
                            <a v-bind:href="(subitem.NavigateUrl ==null || subitem.NavigateUrl =='')?'':subitem.NavigateUrl + (subitem.NavigateUrl.indexOf('?')==-1?'?':'&') +'mid=' + subitem.MenuId">
                                <span class="menu-text"> {{subitem.FullName}} </span>
                            </a>
                        </li>
                    </template>

                </ul>
            </li>
            </template>

        </ul>
    </div>
</template>

<script>

    export default {
        data () {
             if(!this.HasAuth)return [];

            var ret;
            getDataSync(FrameHost+"/Spa/GetPageSidebar?ApplicationID="+window.ApplicationID, "post", { ApplicationID:window.ApplicationID}, function (result) {
                if (result.state == "1") {
                    ret = result.data;
                } else {
                    NotifyError(result.errmsg);
                    ret = "[]";
                }
            });

            return JSON.parse(ret);
        },
        props: ['HasAuth'],
        mounted () {

            var that = this;


            $('.vue-menu').click(function(event){
                event.preventDefault();
                //if(!isPC())return;
                var $a = $(this).find('a');
                 $(".sidebar-menu").find(".submenu > li").each(function () {
                     $(this).removeClass("active");
                 });
                 $(this).addClass("active");

                 var url = $a.attr("href");
                 var menuText = $a.find("span").eq(0).text();
                 var appendHtml = '<small><i class="fa fa-angle-right"></i>' + menuText + '</small>';
                 $("#breadcrumbs").find("small").remove();
                 $("#breadcrumbs").append(appendHtml);
                 rememberMid(url);

                 saveCondition(that,null);
                 //loadShareJs();
                 that.$router.push(url);

            });
        },
        methods:{
            subMenuChange:function (groupid) {
                
            }
        }
    }
</script>

