{set:$config = Config::getInstance(); $other = $config->get('other'); $reg_way = isset($other['other_reg_way'])?$other['other_reg_way']:0;$reg_way = explode(',',$reg_way);$reg_way = array_flip($reg_way);}
<div class="login-bg">
    <div class="container list">
        <div class="row-4">
            <div class="col-2">
                <div class="login-box" style="width:360px;">
                <form action="{url:/simple/reg_act}" class="tiny-form  hidden-msg" method="post" callback="checkReadme" formMsg="field-info">
                    <input type="hidden" name="redirectURL" value="{$redirectURL|$this->perPage()}">
                    <li class="line ">
                                <div class="clearfix"><span class="fl">会员注册</span><a class="fr" href="{url:/simple/login}">立即登录</a></div>
                                <div id="field-info" class="alert alert-danger" style="display:none" role="alert">
                                </div>
                            </li>
                    <ul>
                        {if:isset($reg_way[0])}
                        <li class="line icon"><span class="caption perfix fa">&#xf007;</span>
                            <input name="email" id="email" class="field" pattern="email" placeholder="邮箱(例如:demo@tinyx.com)" alt="邮箱格式不正确!">
                        </li>
                        {/if} {if:isset($reg_way[1])} {if:class_exists('SMS')}
                        <li class="line icon">
                            <span class="caption perfix fa">&#xf095;</span>
                            <input type="text" id="mobile" class="field" name="mobile" pattern="mobi" value="{$mobile}" placeholder="手机号码" alt="正确的手机号码">
                        </li>
                        {else:}
                        <li class="line">
                            非对应授权版本无法使用手机注册用户功能！
                        </li>
                        {/if} {/if}
                        <li class="line icon">
                            <span class="caption perfix fa">&#xf023;</span>
                            <input bind="repassword" minlen=6 maxlen=20 class="field" type="password" name="password" pattern="required" placeholder="密码" alt="6-20任意字符组合">
                        </li>
                        <li class="line icon">
                            <span class="caption perfix fa">&#xf084;</span>
                            <input bind="password" minlen=6 maxlen=20 class="field" type="password" name="repassword" pattern="required" placeholder="确认密码" alt="6-20任意字符组合">
                        </li>
                        {if:isset($reg_way[1]) && class_exists('SMS') && SMS::getInstance()->getStatus()}
                        <li class="line icon">
                            <label class="caption perfix fa">&#xf02a;</label>
                            <input type="text" style="width:117px;" class="input-sm field" name="mobile_code" pattern="\d{6}" placeholder="验证码" alt="6位短信验证码">
                            <label style="position: absolute;display:none ;"></label>
                            <input id="sendSMS" type="button" class=" btn btn-default" value="获取短信验证码">
                        </li>
                        {else:}
                        <li class="line icon">
                            <span class="caption perfix fa">&#xf02a;</span>
                            <input type="text" class="field" name="verifyCode" id="verifyCode" pattern="\w{4}" maxlength="4" style="width:117px;"  alt="验证码不正确">
                            <label style="position: absolute;display:none ;left:-100px;"></label><img id="captcha_img" src="{url:/simple/captcha/h/40/w/120/bc/ffffff}">
                            <label><a href="javascript:void(0)" class="red" onclick="document.getElementById('captcha_img').src='{url:/simple/captcha/h/40/w/120/bc/ffffff/random/}'+Math.random()">换一张</a></label>
                        </li>
                        {/if}
                        <li class="line">
                                <input id="readme" type="checkbox" alt="同意后才可注册">
                                <label></label>
                                <label>我已阅读并同意《<a class="" id="user-license" href="javascript:;">{$site_title}用户注册协议</a>》</label>
                        </li>
                        <li>
                            <button class="btn btn-main " style="padding:10px 40px; width:100%">同意协议，立即注册</button>
                        </li>
                        {token:key=reg}
                    </ul>
                </form>
                </div>
            </div>
            <div class="col-2">
            </div>
        </div>
    </div>
</div>
<div id="license-content" style="display:none;">
    <div style="padding:20px;">
        {query:name=help where=id eq 14} {$item['content']} {/query}
    </div>
</div>


{echo:JS::import('form')}
<script type="text/javascript">
    var readLayer = null;
	$("#user-license").on("click",function(){
        readLayer = layer.open({
            id:'license-dialog',
            title:"{$site_title}用户注册协议",
            type: 1,
            area: ['820px', '440px'], //宽高
            content: document.getElementById('license-content').innerHTML,
            btn:['同意用户注册协议'],
            yes:function(index, layero){
                closeLicense();
            }
        });
	});

	function closeLicense(){
		$('#readme').prop("checked",'true');
		autoValidate.showMsg({id:document.getElementById('readme'),error:false,msg:''});
		layer.close(readLayer);
	}

	$("#sendSMS").click(function(){
		var data = 'mobile=' + $("#mobile").val()+'&r=' + Math.random();
		if(autoValidate.validate(document.getElementById('mobile'))===false)return;

		$.ajax({
			type: "get",
			url: "{url:/ajax/send_sms}",
            data: data,
            dataType:'json',
            success:function(result){
            	if(result['status']=='success'){
            		$('#mobile').attr("readonly","readonly");
            		var send_sms = $("#sendSMS");
            		send_sms.attr("disabled",true);
            		send_sms.addClass("btn-disable");
            		var i = 120;
                    send_sms.val(i + '秒后重新获取');
                    var timer = setInterval(function () {
                        i--;
                        send_sms.val(i + '秒后重新获取');
                        if (i <= 0) {
                            clearInterval(timer);
                            send_sms.val('获取短信验证码');
                            $('#mobile').removeAttr("readonly");
                            send_sms.removeClass("btn-disable");
                            send_sms.attr("disabled",false);
                        }
                    }, 1000);
            	}else{
            		art.dialog.tips("<p class='fail'>"+result['msg']+"</p>");
            	}
            }
        });
	});

	$("input[name='email']").on("change",function(event){
		if(autoValidate.validate(event)){
			$.post("{url:/ajax/email/email/}"+$(this).val(),function(data){
			autoValidate.showMsg({id:document.getElementById('email'),error:!data['status'],msg:data['msg']});
		},'json');
		}
	});

    $("input[name='mobile']").on("change",function(event){
        if(autoValidate.validate(event)){
            $.post("{url:/ajax/mobile/mobile/}"+$(this).val(),function(data){
            autoValidate.showMsg({id:document.getElementById('mobile'),error:!data['status'],msg:data['msg']});
        },'json');
        }
    });

	$("input[name='verifyCode']").on("change",function(){
		$.post("{url:/ajax/verifyCode/verifyCode/}"+$(this).val(),function(data){
			autoValidate.showMsg({id:document.getElementById('verifyCode'),error:!data['status'],msg:data['msg']});
		},'json');
	})
	$("#readme").on("change",function(){
		if($("#readme:checked").length>0)autoValidate.showMsg({id:document.getElementById('readme'),error:false,msg:''});
		else autoValidate.showMsg({id:document.getElementById('readme'),error:true,msg:'同意后才可注册'});
	});
	function checkReadme(e){
		if(e) return false;
		else{
			if($('#readme').is(':checked'))return true;
			else{
				autoValidate.showMsg({id:document.getElementById('readme'),error:true,msg:'同意后才可注册'});
				return false;
			}
		}
	}
	{if:isset($invalid)}
		var form = new Form();
		form.setValue('email', '{$email}');
		autoValidate.showMsg({id:$("input[name='{$invalid['field']}']").get(0),error:true,msg:"{$invalid['msg']}"});
	{/if}

    $("input[pattern]").on("blur",function(event){
            var current_input = $(this);
            var result = autoValidate.validate(event);
            if(result){
                if(current_input.attr('id')=='email'){
                    $.post("{url:/ajax/email/email/}"+$(this).val(),function(data){
                        var msg = '合法用户';
                        if(!data['status']){
                            msg = '用户已存在';
                        }
                        autoValidate.showMsg({id:document.getElementById('email'),error:!data['status'],msg:msg});
                    },'json');
                }if(current_input.attr('id')=='mobile'){
                    $.post("{url:/ajax/mobile/mobile/}"+$(this).val(),function(data){
                        var msg = '合法用户';
                        if(!data['status']){
                            msg = '用户已存在';
                        }
                        autoValidate.showMsg({id:document.getElementById('mobile'),error:!data['status'],msg:msg});
                    },'json');
                }else if(current_input.attr('id')=='verifyCode'){
                    $.post("{url:/ajax/verifyCode/verifyCode/}"+$(this).val(),function(data){
                        autoValidate.showMsg({id:document.getElementById('verifyCode'),error:!data['status'],msg:data['msg']});
                    },'json');
                }
            }
        });
</script>
