@{
    Layout = "~/Areas/Member/Views/_LoginLayoutPage.cshtml";
    ViewBag.Title = "用户注册";
    IEnumerable<dynamic> canRegMemberGroupList = ViewBag.CanRegMemberGroupList;
    int defaultMemberGroupId = (int)ViewBag.DefaultMemberGroupId; //默认会员组id
    int defaultIndex = 0;
    int i = 0;
    string guid = Html.Guid();
    string beforeSubmitJs = "";
}
<div class="container">
    <div class="loginBox regBox">
        <div class="row header">
            <div class="col-md-6 col-xs-6">
                <a href="/">返回首页</a>
            </div>
            <div class="col-md-6 col-xs-6 text-right">
                已有账户？<a href="@Url.ActionUrl("Index","Login")">去登录</a>
            </div>
        </div>
        <div class="content-box">
            <div class="media logo-media"></div>
            <div class="login-sign">会员注册<span></span></div>
            <div id="regBox">
                @if (canRegMemberGroupList.Count() > 1)
            {
                    <div class="reg-member-group">
                        <ul class="reg-member-group-items">
                            @foreach (dynamic memberGroup in canRegMemberGroupList)
                            {
                                int memberGroupId = memberGroup.Id;
                                if (defaultMemberGroupId == memberGroupId)
                                {
                                    defaultIndex = i;
                                }
                                <li class="memberGroup-@memberGroupId" data-tab-params="tabName:'@memberGroup.Name',tabUrl:'@Url.Action("index",new { id = memberGroupId,area="Member" })'"></li>
                                i++;
                            }
                        </ul>
                    </div>
                    <script type="text/javascript">
                        $(".reg-member-group-items").children().InitTab({ defaultIndex:@defaultIndex}); //初始化选项卡
                    </script>
                }
                <form method="post" id="regForm" data-validate-params="tipsStyle:1" class="form">
                    <div class="validate-all-tips-box"></div>
                    <div class="form-group">
                        <label class="control-label">用户名*</label>
                        <div class="controls ">
                            <input type="text" id="username" name="username" class="form-control" maxlength="15" placeholder="用户名" data-validate="dataType:'username',nullMsg:'请填写用户名',errorMsg:'',checkUrl:'@Url.Action("CheckUserName","CheckRepeate",new {id=Request.QueryString["id"],area = "E" })',checkError:'此用户名已经被注册，请重新填写'">
                            <span class="help-block"></span>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label">密码*</label>
                        <div class="controls">
                            <input type="password" id="password" name="password" class="form-control ui-passwordEye" maxlength="15" placeholder="密码" data-validate="dataType:'password',nullMsg:'请填写密码',errorMsg:''">
                            <span class="help-block"></span>
                        </div>
                    </div>

                    @if (ViewBag.MobileFieldSet == "1" || ViewBag.MobileFieldSet == "2")
                    {
                        <div class="form-group">
                            <label class="control-label">手机*</label>
                            <div class="controls">
                                <input type="text" id="mobile" name="mobile" class="form-control" maxlength="15" placeholder="手机号码" data-validate="dataType:'mobile',nullMsg:'请填写手机号码',errorMsg:'手机号码格式错误'@if(ViewBag.MobileOnlyOne =="1"){<text>,checkUrl: '@Url.Action("CheckRegMobile","CheckRepeate",new {id=Request.QueryString["id"],area = "E" })',checkError: '此手机号已经被注册'</text>}">
                                <span class="help-block"></span>
                            </div>
                        </div>

                    }
                    @if (ViewBag.MobileFieldSet == "2")
                    {
                        <div class="form-group">
                            <label class="control-label">手机验证码*</label>
                            <div class="controls">
                                <div class="input-group clearfix">
                                    <input type="text" id="_SmsCode" name="_SmsCode" class="form-control" maxlength="6" placeholder="点击右侧按钮获取手机验证码" data-validate="dataType:'numeric',minLength:6,minLengthErrorMsg:'手机验证码为6位数字！',nullMsg:'请填写手机验证码！',checkUrl:'/E/SmsCode/Validate',checkError:'手机验证码填写错误',additionals:'#mobile'">
                                    <span class="input-group-btn">
                                        <button type="button" class="btn btn-primary ui-btn-sendCode" data-send-params="type:'mobile',accordingObj:'#mobile'">获取验证码</button>
                                    </span>
                                </div>
                                <span class="help-block"></span>
                            </div>
                        </div>
                    }
                    @if (ViewBag.EmailFieldSet == "1" || ViewBag.EmailFieldSet == "2")
                    {
                        <div class="form-group">
                            <label class="control-label">邮箱*</label>
                            <div class="controls">
                                <input type="text" id="email" name="email" class="form-control" maxlength="30" placeholder="邮箱地址" data-validate="dataType:'email',nullMsg:'请填写邮箱地址',errorMsg:'邮箱地址格式错误！'@if (ViewBag.EmailOnlyOne == "1") {<text>,checkUrl:'@Url.Action("CheckRegEmail", "CheckRepeate", new { id = Request.QueryString["id"], area = "E" })',checkError:'此邮箱已经被注册'</text>} ">
                                <span class="help-block"></span>
                            </div>
                        </div>
                    }
                    @if (ViewBag.EmailFieldSet == "2")
                    {
                        <div class="form-group">
                            <label class="control-label">邮件验证码*</label>
                            <div class="controls">
                                <div class="input-group clearfix">
                                    <input type="text" id="_EmailCode" name="_EmailCode" class="form-control" maxlength="6" placeholder="点击右侧按钮获取邮件验证码" data-validate="dataType:'numeric',minLength:6,minLengthErrorMsg:'邮件验证码为6位数字！',nullMsg:'请填写邮件验证码',checkUrl:'/E/EmailCode/Validate',checkError:'邮件验证码填写错误',additionals:'#email'">
                                    <span class="input-group-btn">
                                        <button type="button" class="btn btn-primary ui-btn-sendCode" data-send-params="type:'email',accordingObj:'#email'">获取验证码</button>
                                    </span>
                                </div>
                                <span class="help-block"></span>
                            </div>
                        </div>
                    }

                    @{

                        var data = new ViewDataDictionary();
                        data.Add("from", "member");
                        data.Add("guid", guid);
                        data.Add("currentUser", null);
                        data.Add("memberGroupId", ViewBag.DefaultMemberGroupId);
                        data.Add("i", 0);
                        IEnumerable<dynamic> FieldData = ViewBag.FieldData;
                        i = 0;
                        if (FieldData != null)
                        {
                            foreach (var row in FieldData)
                            {
                                data["i"] = i;
                                beforeSubmitJs += row.BeforeSubmitJs;
                                Html.RenderPartial("~/Areas/E/Views/CustomForm/FormPartial.cshtml", (object)row, data);
                                i++;
                            }
                        }

                    }

                    @if (ViewBag.VerificationCode == "1")
                    {
                        <div class="form-group">
                            <label class="control-label">验证码*</label>
                            <div class="controls">
                                <div class="input-group">
                                    <input type="text" id="_VerificationCode" name="_VerificationCode" class="form-control" maxlength="4" placeholder="输入右侧的验证码" data-validate="dataType:'*',minLength:4,minLengthErrorMsg:'验证码最少4个字符',nullMsg:'请填写验证码',checkUrl:'/E/VerificationCode/Validate',checkError:'验证码填写错误'">
                                    <span class="input-group-btn">
                                        <a class="btn btn-default btn-verificationCodeImg"><img id="verificationCodeImg" src="/E/VerificationCode/?width=100&height=39" class="ui-verificationCodeImage" /></a>
                                    </span>
                                </div>
                                <span class="help-block" id="_ValidateTips__VerificationCode"></span>
                            </div>
                        </div>
                    }

                    <div class="form-group">
                        <div class="controls">
                            <input id="agreement" name="agreement" type="checkbox" value="1" data-validate="dataType:'*',nullMsg:'必须阅读并同意用户注册协议'" checked> <label for="agreement" class="text-muted font-normal">&nbsp;已阅读并同意<a href="@Url.ActionUrl("RegAgreement")" target="_blank" class="blue">《用户注册协议》</a></label>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="controls">
                            @Html.AntiForgeryToken()
                            <input type="hidden" id="guid" name="guid" value="@guid" />
                            <input type="hidden" id="memberGroupId" name="memberGroupId" value="@ViewBag.DefaultMemberGroupId" />
                            <input type="hidden" id="_AttachmentFields" name="_AttachmentFields" value="@Html.GetAttachmentFields("pa_member")" />
                            <button type="button" class="btn  btn-primary btn-lg col-xs-12 col-md-12  ui-pagePost" data-custom-params="url:'@Url.ActionUrl("Index")',callBack:'LoginSuccess',successMsg:''">注册</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    var open = @ViewBag.Open;
    var $regBox = $("#regBox");
    if (open == 0)
    {
        $regBox.html("对不起，网站注册功能已关闭!")
    }
    var $form = $("#regForm");
    var $verificationCode = $("#verificationCode");
    $verificationCode.val("");

    function BeforeSubmit() {
         @Html.Raw(beforeSubmitJs)
        return true;
    }

   function LoginSuccess(result)
    {
            layer.msg('注册成功...', {
                icon: 16,
                time: 200000, //200秒
                shade: 0.01
       });
            var to=Request("to");
            if (to == "") {
                to = "@Url.ActionUrl("Success")"+UrlEncode(result.Description)
            }
            top.location.href = to;
    }
</script>
