<!--{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.emailrz == '1'}-->
	<li style="text-align:left;">已认证邮箱：<!--{$login.user.email}--></li>

  	<li class="li_1">
	  <input type="text" name="email" id="email" placeholder="请输入新邮箱" />
      <span class="current" name="btn_emailcode" id="btn_emailcode">获取验证码</span>
    </li>
    <li class="li_2">
	  <input type="text" name="checkcode" id="checkcode" placeholder="输入新邮箱收到的验证码" />
    </li>
	<!--{else}-->
	<li class="li_1">
	  <input type="text" name="email" id="email" placeholder="请输入邮箱" value="<!--{$login.user.email}-->" />
      <span class="current" name="btn_emailcode" id="btn_emailcode">获取验证码</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_emailcode").bind("click", function(){ //获取验证码
		$tips_obj = $("#tips_submit");
		$tips_obj.html("");

		$val_email = $("#email").val();
		if ($val_email.length == 0) {
			$tips_obj.html("<font color='red'>请输入邮箱地址</font>");
			return false;
		}

		$(this).val("获取中...");
		$.ajax({
			type: "POST",
			url: "<!--{$oefile}-->&c=<!--{$c}-->&a=sendemailcode",
			cache: false,
			data: {email:$val_email, 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_emailcode").html("获取验证码");

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


	$("[f='but_submit']").bind("click", function(){ //确定
		$.ajax({
			type: "POST",
			url: "<!--{$oefile}-->&c=<!--{$c}-->&a=checkemailcode",
			cache: false,
			data: {email:$("#email").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();
					}, 800);
				}
				else {
					if ($result.length > 0) {
						ToastShow($result);
					}
					else {
						ToastShow("验证失败，请检查输入");
					}
				}

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

	});

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