<extend name="Public/bases" />
<block name="body" >
  <link href="__CSS__/user.css" rel="stylesheet" >
  <body class="">
    <header class="header">
      <div class="">
        <a href="{:U('User/userset')}" class="hbtn back"><i class="iconfont icon-drop-left"></i></a>
        <h1 class="caption">我的支付宝</h1>
      </div>
    </header>
    <div class="occupy"></div>
    <section class="trunker">
      <section class="container">
        <empty name="user.alipay">
        <form id="form" action="" method="post" class="">
          <div class="t-table user-auth-list">

            <ul class="table clearfix">
              <li class="table-row">
                <span class="table-cell">
                  <input type="text" class="txt" id="alipay" name="alipay" value="" placeholder="支付宝账号" maxlength="20">
                </span>
              </li>
              <li class="table-row">
                <span class="table-cell">
                  <input type="text" class="txt" id="real_name" name="alipay_real_name" value="" placeholder="支付宝实名认证的真实姓名" maxlength="20">
                </span>
              </li>
							<li class="table-row">
                <span class="table-cell">
                  <input type="password" class="txt" id="password" name="password" value="" placeholder="请输入游戏平台登录密码" maxlength="20">
                </span>
              </li>
            </ul>
          </div>
          <div class="btnbox user-set-btnbox">
            <input type="button" class="btn jssubmit" value="确认绑定">
				<span class="" style="margin:0 auto;padding-top:0.7rem;display:inline-block;text-align:center;width:100%;">支付宝账号绑定后无法修改,请谨慎填写</span>
          </div>
        </form>
				<else />
					<div class="t-table user-auth-list">
            <span class="user-auth-list-title">您已绑定过支付宝</span>
            <ul class="table clearfix">
              <li class="table-row"><span class="table-cell">支付宝号</span><span class="table-cell">{:str_replace(substr($user['alipay'],3,-3),'*****',$user['alipay'])}</span></li>
              <li class="table-row"><span class="table-cell">真实姓名</span><span class="table-cell">{:str_replace(mb_substr($user['alipay_real_name'],0,1),'*',$user['alipay_real_name'])}</span></li>
            </ul>
          </div>
				</empty>
      </section>
    </section>
		<empty name="user.alipay">
    <div class="popmsg pop-dialog"></div>
    <script src="__JS__/pop.lwx.min.js"></script>
    <script>
      $(function() {
        $('.jssubmit').click(function() {
					var that = $(this);
					
          var real_name = $.trim($('#real_name').val());
          var alipay = $.trim($('#alipay').val());
          var pmsg = $('.popmsg').pop();
          if(alipay.length == 0){
            pmsg.msg("请输入支付宝账号");
            $('#alipay').focus();
            return false;
          }
          var re1 = /^[_\.0-9a-z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.){1,4}[a-zA-Z]{2,3}$/;
          var re2 = /^1[0-9]{10}$/;
          if(re1.test(alipay) == false && re2.test(alipay) == false){
             pmsg.msg("请输入正确的支付宝账号");
            $('#alipay').focus();
            return false;
          }
          if(real_name == ""){
            pmsg.msg("请输入真实姓名");
            $('#real_name').focus();
            return false;
          }
          if(real_name.length <2){
            pmsg.msg("真实姓名必须大于两个汉字");
            $('#real_name').focus();
            return false;
          }
          var reg = /^[\u4E00-\u9FA5]+$/;
          if(reg.test(real_name) == false){
            pmsg.msg("输入姓名不合法");
            $('#real_name').focus();
            return false;
          }
					
					var password = $.trim($('#password').val());
					if(!password) {pmsg.msg('请输入平台登录密码');return false;}
					if(password.length>6) {pmsg.msg('平台登录密码输入不正确');return false;}
          
					if(that.hasClass('disabled')) {return false;}
					that.addClass('disabled');
 
          $.ajax({
            cache:true,
            type:'post',
            url:"{:U('User/alipay')}",
            data:$('#form').serialize(),
            dataType:'json',
            success:function(data){
							pmsg.msg(data.msg);
							if(parseInt(data.status)==1) {								
                setTimeout(function () {
                  window.location.href = data.url;
                }, 2000);  							
							} else {
								that.removeClass('disabled');
							}
            },
            error:function(){
              pmsg.msg("错误");that.removeClass('disabled');
            }
          })
        });

      
      });
    </script>
		</empty>
  </body>