@{
    CurrentUser user = ViewBag.CurrentUser;
    IEnumerable<dynamic> fieldData = Html.GetFieldList((string)ViewBag.Table, "list", user);
}
<div class="current-location">
    <ul>
        <li class="left"><i class="glyphicon glyphicon-home"></i><a href="javascript:void(0)" onclick="location.href=location.href">部门管理</a></li>
        <li class="right"><a href="javascript:void(0)" onclick="LoadData()" title="刷新"><span class="glyphicon glyphicon-refresh"></span></a></li>
    </ul>
</div>
<div class="main">
    <table class="tb-head" cellpadding="0" cellspacing="0" border="0">
        <tr>
            <td class="btn-group">
                <button type="button" class="btn btn-default btn-sm ui-selectInvert">反选</button>
                <button type="button" class="btn btn-default dropdown-toggle btn-sm" data-toggle="dropdown" aria-expanded="false">
                    菜单
                    <span class="caret"></span>
                </button>
                <ul class="dropdown-menu" role="menu">
                    <li><a class="ui-dialog" data-custom-params="title:'添加部门', url:'@Url.Action("Add")'" href="javascript:void(0)">添加</a></li>
                    <li class="divider"></li>

                    <li><a href="javascript:void(0)" class="ui-setField" data-custom-params="url:'@Url.Action("SetField")',setField:'isFinal',setValue:'1',limitFinal:'0',includeChildNode:'0',callBack:'LoadData'">转为最终部门</a></li>
                    <li><a href="javascript:void(0)" class="ui-setField" data-custom-params="url:'@Url.Action("SetField")',setField:'isFinal',setValue:'0',limitFinal:'1',callBack:'LoadData'">转为非最终部门</a></li>
                    <li class="divider"></li>
                    <li><a href="javascript:void(0)" class="ui-setMultiple" data-custom-params="url:'@Url.Action("Transfer")',width:'700px',height:'80%'">转移</a></li>
                    <li class="divider"></li>
                    <li><a href="javascript:void(0)" class="ui-deleteMultiple" data-custom-params="url:'@Url.Action("Delete")',callBack:'LoadData',reverseExecute:true">删除</a></li>
                </ul>
            </td>
        </tr>
    </table>
    <table border=0 cellpadding=0 cellspacing=0 class="table table-bordered" id="tb_list">
        <thead>
            <tr>
                <td width="30px"><input type="checkbox" title="选择" class="ui-selectInvert" data-custom-params="isReverse:false"></td>
                <td align="left"><span>名称/</span><span class="ui-folder-switch">展开</span></td>
                <td align="center">Id</td>
                @{
                    foreach (var item in fieldData)
                    {
                        <td align="center">@item.Remark</td>
                    }
                }
                <td align="center">序号</td>
                <td align="center">添加下级</td>
                <td align="center">菜单权限</td>
                <td align="center">投稿权限</td>
                <td align="center">操作</td>
            </tr>
        </thead>
        <tr class="item list-template-item" id='item_{id}' data-id="{id}" data-parentId="{parentId}" data-isFinal="{isFinal}">
            <td align="center" width="30px"><input type="checkbox" class="checked-item" value="{id}"></td>
            <td class="form-inline">{space}<span class="node node_{isFinal}"></span><span>{name}</span></td>
            <td align="center">{id}</td>
            @foreach (var item in fieldData)
            {
                int listWords = item.ListWords;
                int fieldId = item.Id;
                string field = item.Name;
                string fieldType = item.FieldType;
                string valueType = item.ValueType;
                string align = "center";
                if (valueType == "nvarchar" || valueType == "text")
                {
                    if (fieldType != "image")
                    {
                        align = "left";
                    }
                }
                <td align="@align">
                    @if (new string[] { "images", "files", "subtable" }.Contains(fieldType))
                    {
                        <span class="sp_@field sp_values" data-value-params="id:{id},fieldId:@fieldId,name:'@field',fieldType:'@fieldType',valueType:'@valueType',listWords:'@listWords'"><i class="fa fa-spinner fa-spin"></i></span>
                    }
                    else
                    {
                        <span class="sp_@field sp_values" data-value-params="id:{id},fieldId:@fieldId,name:'@field',fieldType:'@fieldType',valueType:'@valueType',listWords:'@listWords'">{@field}</span>
                    }
                </td>
            }

            <td align="center" class="form-inline form-group-sm"><input type="text" name="xuhao" id="xuhao" data-table="pa_department" data-id="{id}" class="form-control ui-listXuhao" value='{xuhao}' style="width:50px" maxlength="3" /></td>
            <td align="center" class="form-inline">
                <button type="button" data-custom-params="title:'{name}-添加子部门',url:'@Url.Action("add")?parentId={id}',width:'700px',height:'400px'" class="btn btn-default btn-sm add_child_{isFinal} ui-dialog">添加</button>
            </td>
            <td align="center">
                <button class="btn btn-default btn-sm ui-dialog btn-{isFinal}" data-custom-params="title:'{name}-菜单权限设置',url:'@Url.Action("Index","DepartmentPermissions")?departmentId={id}'">设置</button>
            </td>
            <td align="center"><a href="javascript:void(0)" class="btn btn-default btn-sm ui-dialog btn-{isFinal}" data-custom-params="title:'{name}-投稿限设置',url:'@Url.Action("Index","DepartmentInfoPermissions")?departmentId={id}'">设置</a></td>
            <td align="center">
                <input type="hidden" name="id" value="{id}" />
                <div class="btn-group btn-group-sm">
                    <button type="button" data-custom-params="title:'{name}-修改',url:'@Url.Action("Edit")?id={id}'" class="btn btn-default btn-sm ui-dialog">修改</button>
                    <button type="button" data-custom-params="url:'@Url.Action("Delete")',callBack:'LoadData'" class="btn btn-default btn-sm ui-deleteSingle">删除</button>
                </div>
            </td>
        </tr>
    </table>
    <div class="tishi"><span class="glyphicon glyphicon-info-sign"></span>部门权限（只作用会员中心）优先于会员组权限，并只对设置了部门属性的用户有效。</div>
</div>
<script type="text/javascript">
    function LoadData() {
        var url = "@Url.Action("ListData")";
        $("#tb_list").TreeBind({ url: url, callBack: "LoadedInit" });

    }
    function LoadedInit() {
        $(".add_child_1").attr("disabled", "disabled");
        $(".btn-0").attr("disabled", "disabled");
        var $sp_values = $(".sp_values");
        $sp_values.each(function () {
            var $this = $(this);
            var thisHtml = $this.html();
            var params = $this.attr("data-value-params")
            params = ExtendObject(params);
            var parentId = params.id;
            var listWords = parseInt(params.listWords);
            var valueType = params.valueType;
            var fieldType = params.fieldType;
            var field = params.name;
            var fieldId = params.fieldId;
            if (fieldType == "subtable") {
                $.get("/E/SubData/Count", { _fieldId: fieldId, parentId: parentId }, function (data) { $this.text(data) });
            }
            else if (fieldType == "images" || fieldType == "files") {
                $.get("/E/AttachmentsData/Count", { _fieldId: fieldId, parentId: parentId }, function (data) { $this.text(data) });
            }
            else if (params.fieldType == "image" && thisHtml != "") {
                $this.html("<a href=\"" + thisHtml + "\" target=\"_blank\"><img src=\"" + thisHtml + "\" class=\"ui-thumbnail thumbnail\"></a>");
            }
            else if (valueType == "nvarchar" || valueType == "ntext" || valueType == "datetime") {
                if (thisHtml.length > listWords) {
                    if (field == "title") {
                        $this.html(thisHtml.Left(listWords) + "...");
                    }
                    else {
                        $this.html(thisHtml.Left(listWords));
                    }
                }
            }
        });
    }
    LoadData();

</script>