<!--{assign var="menu_id" value="cp"}-->
<!--{include file="<!--{$oetplpath}-->block_header.tpl"}-->
<div class="oe_ntop">
  <i class="iconfont" onclick="goBack();">&#xe616;</i>
  <p>认证手机</p>
</div>
<div class="oe_rz">
  <div class="tips">手机号码可以用来登录网站，取回密码，同时方便获取优惠券、订单等信息</div>
  <ul>
    <!--{if $login.user.mobilerz == '1'}-->
    <li style="text-align:left;">已认证手机号码：<!--{$login.user.mobile}--></li>
	

    <li class="li_1">
	  <input type="text" name="mobile" id="mobile" placeholder="请输入新手机号码" />
      <span class="current" name="btn_mobilecode" id="btn_mobilecode">获取验证码</span>
    </li>
    <li class="li_2">
	  <input type="text" name="checkcode" id="checkcode" placeholder="请输入短信验证码" />
    </li>
	<!--{else}-->
	<li class="li_1">
	  <input type="text" name="mobile" id="mobile" placeholder="请输入手机号码" value="<!--{$login.user.mobile}-->" />
      <span class="current" name="btn_mobilecode" id="btn_mobilecode">获取验证码</span>
    </li>
    <li class="li_2">
	  <input type="text" name="checkcode" id="checkcode" placeholder="请输入短信验证码" />
    </li>
	<!--{/if}-->

  </ul>
  <div class="ge"></div>
  <div class="oe_rz_btn">
    <p style="padding:10px;text-align:center;" id="tips_submit"></p>
    <span f="but_submit">确定认证</span>
  </div>
</div>

<script type="text/javascript">
$(function(){

	$("#btn_mobilecode").bind("click", function(){ //获取验证码
		$tips_obj = $("#tips_submit");
		$tips_obj.html("");
		$val_mobile = $("#mobile").val();
		if ($val_mobile.length != 11) {
			$tips_obj.html("<font color='red'>请输入手机号码</font>");
			return false;
		}
		if (!isMobile($val_mobile)) {
			$tips_obj.html("<font color='red'>手机号码不正确</font>");
			return false;
		}
		$(this).html("获取中...");
		$.ajax({
			type: "POST",
			url: "<!--{$oefile}-->&c=<!--{$c}-->&a=sendmobilecode",
			cache: false,
			data: {mobile:$val_mobile, r:get_rndnum(8)},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") {
					ToastShow("发送成功，请查收短信");
				}
				else {
					if ($result.length > 0) {
						ToastShow($result);
					}
					else {
						ToastShow("发送失败，请检查");
					}
					
				}
				$("#btn_mobilecode").html("获取验证码");

			},
			error: function() {
				ToastShow("系统繁忙，请稍后再试");
				$("#btn_mobilecode").html("获取验证码");
			}
		});

	});



	$("[f='but_submit']").bind("click", function(){ //确定
		$.ajax({
			type: "POST",
			url: "<!--{$oefile}-->&c=<!--{$c}-->&a=checkmobilecode",
			cache: false,
			data: {mobile:$("#mobile").val(), checkcode:$("#checkcode").val(), r:get_rndnum(8)},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") {
					ToastShow("认证成功");
					setTimeout(function(){
						window.location.reload();
					}, 500);
				}
				else {
					if ($result.length > 0) {
						ToastShow($result);
					}
					else {
						ToastShow("验证失败，请检查输入");
					}
				}

			},
			error: function() {
				ToastShow("系统繁忙，请稍后再试");
			}
		});

	});

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