@{
    CurrentUser user = ViewBag.CurrentUser;
    bool isTree = bool.Parse(ViewBag.IsTree);
    bool isColumn = bool.Parse(ViewBag.isColumn);
}
<div class="main">
    <table border=0 cellpadding=0 cellspacing=0 class="tb-head form-inline form-group-sm">
        <tr>
            <td>
                <div class="btn-group btn-group-sm">
                    <button type="button" class="btn btn-default ui-selectInvert">反选</button>
                    <button type="button" class="btn btn-default" onclick="SelectData()">确定</button>
                    <input type="hidden" id="fieldId" name="fieldId" class="ui-queryString" value="@ViewBag.FieldId" />
                </div>
            </td>
            @if (!isTree)
            {
                <td align="right">
                    <input type="text" id="@ViewBag.TextField" name="@ViewBag.TextField" maxlength="20" class="form-control  ui-queryString" style="width:140px;">
                    <input type="button" value="搜索" class="btn btn-default btn-sm ui-queryString-search">
                </td>
            }
            @if (isColumn)
            {
                <td align="right">
                    <select name="siteId" id="siteId" style="width:auto;display:inline" class="form-control ui-queryString" data-source="@Html.GetSiteListJsonByUser(user)" data-custom-params="dataSourceFrom:'attr'">
                        <option value="0">选择站点</option>
                    </select>
                    <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 style="width:40px" align="center"><input type="checkbox" title="选择" class="ui-selectInvert" data-custom-params="isReverse:false"></td>
                <td align=left>@ViewBag.TextfieldName</td>
            </tr>
        </thead>
        <tr @if (isTree) { <text> class="item item-template parent_{parentGuid}" id="item_{id}" data-id="{id}" data-parentId="{parentId}" data-isFinal="{isFinal}" </text>        } else { <text> class="item item-template" id="item_{id}" </text>        }>
            <td align="center" style="width:40px"><input type="checkbox" id="id" name="id" value="{@ViewBag.ValueField}" class="checked-item ck id_{id}@if(isTree){<text> ck_isfinal_{isFinal}</text>}"></td>
            @if (isTree)
            {
                <td align="center" style="text-align:left">{space}<span class="node node_{isFinal}"></span><span class="title">{@ViewBag.TextField}</span></td>
            }
            else
            {
                <td align=left><span class="title">{@ViewBag.TextField}</span></td>
            }
        </tr>
    </table>
    @*<div style="color:#999">提示：选择框呈灰色时表示已经选中或存在相同的数据！</div>*@
</div>
<script type="text/javascript">
    var objName = "@Request.QueryString["objName"]";
    if (objName == "")
    {
        objName = "#@ViewBag.FieldName";
    }

    var $siteId = $("#siteId");
    function BindSite()
    {
        var currentSiteId = "@ViewBag.CurrentSiteId";
        $siteId.SelectBind();
        $siteId.SetValue(currentSiteId);
    }
    BindSite();


    var onlySelectFinal=@ViewBag.OnlySelectFinal;
    var isTree=@ViewBag.IsTree;
    var $tbList=$("#tb_list")
    function LoadData()
    {
        var url="@Url.Action("ListData","SelectData")";
        if(isTree)
        {
            $tbList.TreeBind({url:url,callBack: "LoadedInit" });
        }
        else
        {
            $tbList.ListBind({url:url,callBack: "LoadedInit" });
        }
    }
    LoadData();

    function LoadedInit()
    {
        if (onlySelectFinal && isTree)
        {
            $(".ck_isfinal_0").attr("disabled", "disabled");
        }
        var $title = $(".title");
        $title.each(function () {
            var $this = $(this);
            if ($this.html().length>60) {
                $this.html($this.html().substring(0,60)+"...");
            }
        });
        SetSelectedDisabled() //把已经选中的设置为Disabled
    }
</script>
<script src="/Js/selectData.js" type="text/javascript"></script>