@using GBLab.Common.Expand
@using System.Text;
@{
    var CmsConfig = ViewData["CmsConfig"] as GBLab.Entities.Config.CmsConfig;
    var menu = ViewData["Menu"] as List<GBLab.Entities.SiteNodes>;
}
<nav class="navbar navbar-default navbar-fixed-top">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                <span class="sr-only">导航</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#this">学校软件</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
            @{
                StringBuilder sb = new StringBuilder();
                sb.Append("<ul class=\"nav navbar-nav\">");
                foreach (var item in menu)
                {
                    if (item.midNodes.Count == 0)
                    {
                        sb.Append(string.Format(@"
<li><a href='{1}'>{0}</a></li>"
, item.node.F_Name.DefaultIsNullOrEmpty("")
, nodetourl(item.node)
));
                    }
                    else
                    {

                        StringBuilder sbMid = new StringBuilder();
                        foreach (var midItem in item.midNodes)
                        {
                            sbMid.Append(string.Format(@"
<li><a href='{1}'>{0}</a></li>"
, midItem.node.F_Name.DefaultIsNullOrEmpty("")
, nodetourl(midItem.node)
));
                        }


                        sb.Append(string.Format(@"
<li  class='dropdown'>
<a href='javascript:;' class='dropdown-toggle' data-toggle='dropdown' role='button' aria-haspopup='true' aria-expanded='false'>
{0}
<span class='caret'></span>
</a>
<ul class='dropdown-menu'>
{1}
</ul>
</li>"
, item.node.F_Name.DefaultIsNullOrEmpty("")
, sbMid.ToString()));
                    }
                }
                sb.Append("</ul>");
            }
            @Html.Raw(sb.ToString())
        </div>
    </div>
</nav>

@helper nodetourl(GBLab.Entities.T_CmsNode node)
{
    string result = "";
    if (node.F_CmsModelId == 3 || node.F_CmsModelId == 10 || node.F_CmsModelId == 2)
    {
        @node.F_Url.DefaultIsNullOrEmpty("");
    }
    else
    {
        switch (node.F_CmsModelId)
        {
            case 1:
                result = Url.Domain_RouteUrl("Site.CmsNews.Node.List", new { typeId = node.F_Type });
                break;
            case 7:
                result = Url.Domain_RouteUrl("Site.CmsImg.Node.List", new { typeId = node.F_Type });
                break;
            case 6:
                result = Url.Domain_RouteUrl("Site.CmsHire.Node.List", new { typeId = node.F_Type });
                break;
            case 11:
                result = Url.Domain_RouteUrl("Site.CmsTeacher.Node.List", new { typeId = node.F_Type });
                break;
            case 13:
                result = Url.Domain_RouteUrl("Site.CmsGuestBook.Node.List", new { typeId = node.F_Type });
                break;
        }
        @*如果无法识别的，特殊处理*@
        if (string.IsNullOrWhiteSpace(result))
        {
            result = "#this";
        }
        @result;
    }
}