@{
    string State = Request.QueryString["state"];

    string table = ViewBag.Table;
    CurrentUser user = ViewBag.CurrentUser;
    IEnumerable<dynamic> fieldData = Html.GetFieldList(table,"list", user, PageAdmin.Common.FromEnum.Admin);
}
<div class="main">
    <ul class="navTabs">
        <li data-tab-params="tabName:'使用中',tabValue:'1',tabValueObjName:'#state'"></li>
        <li data-tab-params="tabName:'未使用',tabValue:'0',tabValueObjName:'#state'"></li>
        <li data-tab-params="tabName:'已废弃',tabValue:'-1',tabValueObjName:'#state'"></li>
    </ul>

    <table border=0 cellpadding=0 cellspacing=0 class="tb-head form-inline form-group-sm">
        <tr>
            <td>
                    <div class="btn-group left">
                        <button type="button" class="btn btn-default btn-sm ui-selectInvert">反选</button>
                        <button type="button" class="btn btn-default btn-sm ui-deleteMultiple"  data-custom-params="url:'@Url.Action("Delete")?table=@ViewBag.Table',beforeExecute:'BeforeDelete',callBack:'LoadData'">删除</button>
                    </div>
            </td>
            <td align="right">
                <input type="hidden" name="state" id="state" value="1" class="ui-queryString" />
                <select id="order" class="ui-queryString form-control">
                    <option value="id desc">按id↓</option>
                    <option value="id asc">按id↑</option>
                    @Html.Partial("~/Areas/E/Views/CustomForm/OrderFieldPartial.cshtml", fieldData)
                </select>
                <select id="s_field" name="s_field" class="btn-xs ui-queryString ui-setName form-control">
                    @Html.Partial("~/Areas/E/Views/CustomForm/SearchFieldPartial.cshtml", fieldData)
                    <option value="username">按用户名</option>
                </select>
                <input type="text"  class="ui-queryString ui-keyword  form-control" style="width:120px" placeholder="输入关键词">
                <input type="button" value="确定" class="btn btn-default btn-sm ui-queryString-search">
            </td>
        </tr>
    </table>
    <table border=0 cellpadding=0 cellspacing=0 class="table table-bordered form-inline form-group-sm" id="tb_list">
        <thead>
            <tr>
                <td align="center" style="width:40px"><input type="checkbox" title="选择" class="ui-selectInvert" data-custom-params="isReverse:false"></td>
                @foreach (var item in fieldData)
            {
                    <td align="center">@item.Remark</td>
                }
                <td align="center">状态</td>
                <td align="center">用户</td>
                <td align="center">管理</td>
            </tr>
        </thead>
            <tr class="item" id="item_{id}" state="{state}">
                <td align="center"><input type="checkbox" value="{id}" class="id_{id} checked-item"></td>
                @foreach (var item in fieldData)
            {
                int listWords = item.ListWords;
                string listWidth = item.ListWidth;
                if (listWidth != "")
                {
                    listWidth = "style=\"width:" + listWidth + ";\"";
                }
                string id = item.Id.ToString();
                string field = item.Name;
                string fieldType = item.FieldType;
                string valueType = item.ValueType;
                string align = "center";
                if (valueType == "nvarchar" || valueType == "ntext")
                {
                    if (fieldType != "image")
                    {
                        align = "left";
                    }
                }
                @*if (fieldType == "subtable")
            {
                string subTable = ViewBag.Table + "_" + field;
                <td align="@align">
                    <button type="button" class="btn btn-default btn-sm ui-dialog" data-custom-params='title:"@(item.remark)-管理",url:"@Url.Action("Index","SubTableData")?table=@subTable&field_id=@fieldId&parent_guid={guid}&parent_id={id}&objId=@(field)_{id}&from=admin",width:"@item.win_width",height:"@item.win_height",target:"self"'>管理(<span id="@(field)_{id}" class="small">{@field}</span>)</button>
                </td>
            }
            else if (fieldType == "files" || fieldType == "images")
            {
                string attTable = ViewBag.Table + "_" + field;
                <td align="@align">
                    <button type="button" class="btn btn-default btn-sm ui-dialog" data-custom-params='title:"@(item.remark)-管理",url:"@Url.Action("Admin","AttachmentData")?table=@attTable&field_id=@fieldId&parent_guid={guid}&parent_id={id}&objId=@(field)_{id}&fieldType=@(fieldType)&from=admin",width:"@item.win_width",height:"@item.win_height",target:"self"'>管理(<span id="@(field)_{id}" class="small">{@field}</span>)</button>
                </td>
        }*@
                    <td align="@align" @Html.Raw(listWidth)>
                        <span class="sp_@field sp_values" data-custom-params="fieldType:'@fieldType',valueType:'@valueType',listWords:'@listWords'">{@field}</span>
                    </td>
                }
                <td align="center"><span class="lb_state">{state}</span></td>
                <td align="center"><span class="lb_uid" data-custom-params="url:'@Url.Action("GetFieldByIds", "Member")',textField:'Username'">{uid}</span></td>
                <td align="center">
                    <input type="hidden" name="id"  value="{id}" />
                    <input type="hidden" name="guid"  value="{guid}" />
                    <div class="btn-group btn-group-sm">
                        <button type="button" class="btn btn-default btn-sm ui-dialog" data-custom-params='title:"数据修改",url:"@Url.Action("Edit")?id={id}&guid={guid}&table=@ViewBag.Table",target:"self"'>修改</button>
                    </div>
                </td>
            </tr>
</table>
</div>
<script type="text/javascript">
    $(".navTabs").children().InitTab(function () { LoadData() }); //初始化选项卡，并设置回调函数为LoadData()

    var $tbList=$("#tb_list");
    var ajaxUrl = "@Url.Action("PageListData")?table=@ViewBag.Table";
    function LoadData()
    {
        $tbList.ListBind({url:ajaxUrl,callBack: "LoadedInit" });
    }
    function LoadedInit()
    {
        var $sp_values = $(".sp_values")
        $sp_values.each(function () {
            var $this = $(this);
            var thisHtml = $this.html();
            var params = $this.attr("data-custom-params")
            params = eval("({" + params + "})");
            var listWords = parseInt(params.listWords);
            var valueType = params.valueType;
            if (params.fieldType == "image" && thisHtml != "") {
                $this.html("<img src=\"" + thisHtml + "\" class=\"ui-thumbnail\">");
            }
            else if (valueType == "nvarchar" || valueType == "text" || valueType == "datetime") {
                if (thisHtml.length > listWords) {
                    $this.html(thisHtml.Left(listWords));
                }
            }
        });

        var $lb_state = $(".lb_state");
        $lb_state.each(function () {
            var $this = $(this);
            var thisHtml = $this.html();
            if (thisHtml == "-1") {
                $this.html("已废弃")
            }
            else if (thisHtml == "0") {
                $this.html("未使用")
            }
            else if (thisHtml == "1") {
                $this.html("使用中").parent().parent().find(".ui-deleteSingle").attr("disabled", "disabled");
            }
        });
        $(".lb_uid").ConvertText();
    }
    LoadData();


    function BeforeDelete(ids) {
        var arrIds = ids.split(",")
        for (i = 0; i < arrIds.length; i++) {
            if ($("#item_" + arrIds[i]).attr("state") == "1") {
                Alert("使用中的数据不能删除！");
                return false;
            }
        }
        return true;
    }
</script>