@model string
<div class="main">

    <form method="post" id="_form" class=" form form-lg form-group-sm ui-formBind"  data-source="@Model">

        <div class="form-group">
            <label class="control-label">用户名</label>
            <div class="controls form-inline">
                <input type="text" id="Username" name="Username" class="form-control form-control-sm ui-edit-readonly" data-validate="dataType:'username',nullMsg:'请填写用户名',errorMsg:'用户名格式错误'">
                <a href="javascript:void(0)" class="btn btn-default btn-sm ui-dialog btn-select-member" data-custom-params="title:'选择会员',url:'@Url.Action("Select","Member")?objname=#Username',width:'800px',height:'90%',target:'_self'">选择会员</a>
                <span class="help-block"></span>
            </div>
        </div>

        <div class="form-group">
            <label class="control-label">管理员角色</label>
            <div class="controls">
                <select class="form-control" id="RoleId" name="RoleId" data-source="@Html.GetRoleListJson()"></select>
                <span class="help-block"></span>
            </div>
        </div>

        <div class="form-group">
            <label class="control-label">备注</label>
            <div class="controls">
                <input name="Remark" id="Remark" class="form-control" />
                <span class="help-block"></span>
            </div>
        </div>

        <div class="form-group">
            <label class="control-label">选择可管理的站点</label>
            <div class="controls">
                <select id="SiteIds" name="SiteIds" class="form-control  ui-convertSelect multiple-select" multiple style="display:block;height:150px;" data-custom-params="url:'@Url.Action("LoadListByIds","Site")',textField:'Name'"  data-source="@ViewBag.SiteIds"></select>
                <div class="btn-group btn-group-sm" >
                    <a href="javascript:void(0)" class="btn btn-default btn-sm ui-dialog" data-custom-params="title:'选择会员类别',url:'@Url.Action("Select","Site")?objname=#SiteIds',width:'80%',height:'90%',target:'_self'">选择管理站点</a>
                    <a href="javascript:void(0)" class="btn btn-default btn-sm ui-removeSelectedOptions" title="按住Ctrl键可实现多选" data-custom-params="obj:'#SiteIds'">删除选中</a>
                </div>
                <span class="help-block">不选择则默认可以管理所有站点，超级管理员不受此设置限制。</span>
            </div>
        </div>


        <div class="form-group">
            <label class="control-label">选择默认管理的站点</label>
            <div class="controls form-inline">
                <select id="DefaultSiteId" name="DefaultSiteId" class="form-control form-control-sm ui-convertSelect" data-custom-params="url:'@Url.Action("LoadListByIds","Site")',textField:'Name'" data-source="@ViewBag.DefaultSiteId" data-validate="dataType:'select',nullMsg:'请选择默认站点'"></select>
                <a href="javascript:void(0)" class="btn btn-default btn-sm ui-dialog" data-custom-params="title:'选择会员类别',url:'@Url.Action("Select","Site")?objname=#DefaultSiteId',width:'80%',height:'90%',target:'self'">选择默认站点</a>
                <span class="help-block">如果是非超级管理员，默认站点必须属于可管理的站点。</span>
            </div>
        </div>

        <div class="form-group">
            <label class="control-label">选择可管理的会员组</label>
            <div class="controls">
                <select id="MemberGroupIds" name="MemberGroupIds" class="form-control ui-convertSelect multiple-select" multiple style="display:block;height:150px;" data-custom-params="url:'@Url.Action("LoadListByIds","MemberGroup")',textField:'Name'" data-source="@ViewBag.MemberGroupIds" ></select>
                <div class="btn-group btn-group-sm" >
                    <a href="javascript:void(0)" class="btn btn-default btn-sm ui-dialog" data-custom-params="title:'选择会员类别',url:'@Url.Action("Select","MemberGroup")?objname=#MemberGroupIds',width:'80%',height:'90%',target:'self'">选择会员组</a>
                    <a href="javascript:void(0)" class="btn btn-default btn-sm ui-removeSelectedOptions" title="按住Ctrl键可实现多选" data-custom-params="obj:'#MemberGroupIds'">删除选中</a>
                </div>
                <span class="help-block">不选择则默认可管理所有会员组，超级管理员不受此设置限制。</span>
            </div>
        </div>

        <div class="postarea">
            <div class="form-group">
                <div class="controls">
                    @Html.AntiForgeryToken()
                    <input type="hidden" name="Uid" id="Uid" value="0" />
                    <input type="hidden" name="Id" id="Id" value="0" />
                    <button type="button" class="btn btn-sm btn-primary ui-pagePost" data-custom-params="url:'@Url.Action()',beforeExecute:'PostBeforeCheck',callBack:'PostRefreshBack'">提交</button>
                    <button type="button" class="btn btn-sm btn-default ui-closeDialog">关闭</button>
                </div>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript">
    //填充角色下拉
    var params = { valueField:'Id',textField:'Name',dataSourceFrom: "attr"};
    $("#RoleId").SelectBind(params);

    //绑定数据
    var id = Request("id");
    if (id != "") {
        $(".btn-select-member").hide();
    }

    function PostBeforeCheck() {
        var hasExists = false;
        var $site_ids = $("#SiteIds");
        var $default_site_id = $("#DefaultSiteId");
        var default_site_id = $default_site_id.val();
        var $options = $site_ids.children("option");
        if (default_site_id == null) {
            Msg("请选择默认站点！");
            $default_site_id.focus();
            return false;
        }
        if ($options.length == 0) {
            return true;
        }
        $options.each(function () {
            var $this = $(this);
            if ($this.val() == default_site_id) {
                hasExists = true;
                return false;
            }
        });
        if (!hasExists) {
            Msg("默认站点必须包含在可管理的站点中！")
        }
        return hasExists;
    }
</script>

