<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>免费送滤芯</title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="format-detection" content="telphone=no, email=no" />
		<link rel="stylesheet" type="text/css" href="//s.iamberry.com/watero/css/mui.min.css?v=2016111701" />
		<link rel="stylesheet" type="text/css" href="//s.iamberry.com/watero/css/iconfont.css?v=2016111701" />
		<link rel="stylesheet" type="text/css" href="//s.iamberry.com/watero/css/style.css?v=2016111701" />
		<style>
			.register-group{margin: 0 auto;width: 300px;}
			.register-group:before,.register-group:after,.register-group .mui-input-row:before,.register-group .mui-input-row:after{display: none}
			.register-group .mui-input-row label{padding: 11px 5px;width: 20%;}
			.register-group .mui-input-row label~input{width: 80%;border-bottom:1px solid #ccc;font-size: 16px;}
			.register-group .mui-input-row label~input::-webkit-input-placeholder{font-size: 15px;color: #ccc;}
			.pull-code {border: 0;color: #666;padding:8px 0;position: absolute;right:0;}
			.pull-code.active{color: #6dd4e5;}
			.pull-code:active{background-color: #fff !important;color: #666 !important;}
			.my-btn-confirm{background-color: #fff;border:1px solid #59c0d9;border-radius: 0;width: 200px;margin: 0 auto;color: #666;padding: 7px 0;color: #59c0d9;}
			.my-btn-confirm:active{background-color: #59c0d9 !important;border:1px solid #59c0d9;color: #fff;}
			.my-btn-confirm.active{background-color: #59c0d9 !important;border:1px solid #59c0d9;color: #fff;}
		</style>
	</head>

	<body style="background: #fff;">
		<!--内容开始-->
		<div class="mui-content" style="background: #fff;">
			<div>
				<img width="100%" src="//s.iamberry.com/watero/images/banner-11.jpg" />
			</div>
			<div class="mui-text-center" style="color:#59c0d9;font-size: 16px;padding: 15px 0;">
				验证手机信息
			</div>
			<form class="mui-input-group register-group">
				<div class="mui-input-row">
					<label>手机号</label>
					<input type="tel" placeholder="输入您购买时的手机号(11位)" id="ipt-phone" maxlength="11">
				</div>
				<div class="mui-input-row">
					<label>验证码</label>
					<input type="tel" placeholder="输入验证码" maxlength="4" id="code"><button type="button" class="pull-code" id="pull-code">获取验证码</button>
				</div>
			</form>
			<br />
			<div class="mui-content-padded">
				<button type="button" data-loading-icon="mui-spinner mui-spinner-custom" data-loading-text="提交中" class="mui-btn mui-btn-block my-btn-confirm" id="btn-confirm" disabled="disabled">领取滤芯</button>
			</div>
			<div class="mui-content-padded">
				<div style="border-top: 1px solid rgba(0,0,0,.1);margin: 20px 0;"></div>
				<ul>
					<li style="color:#59c0d9;padding-bottom: 10px;">活动说明：</li>
					<li class="mui-h6">1,此福利仅针对购买过WaterO产品的老顾客</li>
					<li class="mui-h6">2,如您现在使用的手机号码与购买下单的手机号码不同，请联系官方客服</li>
					<li class="mui-h6">3,每个手机号码仅限领取一次</li>
					<li class="mui-h6">4,领取成功之后，即可在会员中心查看您的兑换券及优惠权益。</li>

					<li style="color:#59c0d9;padding:10px 0;">尊享福利：</li>
					<li class="mui-h6">1.免费赠送WaterO T1/T2滤芯</li>
					<li class="mui-h6">2.尊享滤芯套装立减100元/套优惠</li>
					<li class="mui-h6">3.尊享WaterO品牌一对一售后服务</li>
				</ul>
			</div>
		</div>
		<!--内容结束-->

		<script src="//s.iamberry.com/watero/js/mui.min.js?v=2016111701"></script>
		<script src="//s.iamberry.com/watero/js/jquery-2.1.1.min.js"></script>
		<script src="//s.iamberry.com/watero/js/shop/main.js?v=20170622"></script>
		<script src="//s.iamberry.com/watero/js/shop/wechat-utils-1.0.js"></script>
		<script>
			var countdown = 60;
			var check = false,
				alert_msg = '';
			var reg_Ch_En_Num = /^[A-Za-z0-9_ \-\u4e00-\u9fa5]{1,15}$/; //简体中文英文数字，横线下划线空格(1-15位)
			var mobile = /^(13|14|15|16|17|18|19)[0-9]{9}$/; //手机号码
			var code = /^[0-9]{4}$/; //数字
			var validate_flag = false,
				show_msg = '',phone='';
			//ready事件
			mui.ready(function() {
				if(!window.localStorage) {
					mui.alert("浏览器不支持localStorage");
				} else {
					var codedata = JSON.parse(localStorage.getItem('pull-code-data'));
					if(codedata != null) {
						var dates = new Date();
						$("#ipt-phone").val(codedata.phone);
						if(codedata.codeTime > 0) {
							if(((dates.getTime() / 1000) - codedata.updateTime) < codedata.codeTime) {
								countdown = (codedata.codeTime - (parseInt(dates.getTime() / 1000) - codedata.updateTime)) + 1;
								settime("pull-code");
							} else {
								$(".pull-code").removeAttr("disabled");
							}
							$('#btn-confirm').removeAttr("disabled").addClass("active");
						} else {
							$(".pull-code").removeAttr("disabled").addClass("active");
						}
					}
				}
			});

			//实时监听文本框字数
			document.getElementById("ipt-phone").addEventListener("input", function() {
				var phone = this.value;
				if(phone.length == 11) {
					if(mobile.test(phone) && countdown == 60) {
						$(".pull-code").removeAttr("disabled").addClass("active");
					} else {
						$(".pull-code,#btn-confirm").attr("disabled", "disabled").removeClass("active");
					}
				} else {
					$(".pull-code,#btn-confirm").attr("disabled", "disabled").removeClass("active");
				}
			});
			//发送验证码
			$(document).on('tap', '.pull-code', function() {
						if($("#ipt-phone").val().trim() == "" && (!$(".pull-code").hasClass("active"))) {
							mui.alert("请填写手机号码", function() {
								$("#ipt-phone").select();
							});
							return;
						} else {
							if(!mobile.test($("#ipt-phone").val().trim())) {
								mui.alert("手机号码不正确，请重新填写", function() {
									$("#ipt-phone").select();
								});
								return;
							} else {
								if($(this).hasClass("active")) {
                                    phone=$("#ipt-phone").val().trim();
									$.ajax(base_path + '/tanksgiv/send_veri?dates=' + new Date().getTime(), {
										data: {
											"phone": $("#ipt-phone").val().trim()
										},
										dataType: 'json',
										xhrFields: {
											withCredentials: true
										},
										crossDomain: true,
										type: 'get',
										timeout: 15000,
										success: function(dt) {
											if(dt.isRedirect) {
												location.href = dt.redirectURL;
											} else {
												if(dt.status) {
													settime("pull-code");
													$("#code").select();
													if(!window.localStorage) {
														alert("浏览器不支持localStorage");
													} else {
														var dates = new Date();
														//自定义json数据
														var obj = {
															"phone": $("#ipt-phone").val().trim(),
															"codeTime": countdown,
															"updateTime": parseInt(dates.getTime() / 1000)
														};
														//json格式化插入    
														localStorage.setItem('pull-code-data', JSON.stringify(obj));
													}
													$('#btn-confirm').removeAttr("disabled").addClass("active");
												} else {
													mui.alert(dt.message);
												}
											}
										},
										error: function(xhr, type, errorThrown) {
											console.log(xhr);
											mui.alert("发送短信失败！网络错误");
										}
									});

								}
							}
						}
			});

			function settime(val) {
				pullid = dc(val);
				if(countdown == 0) {
					pullid.removeAttribute("disabled");
					pullid.className = 'pull-code active';
					pullid.innerText = "获取验证码";
					countdown = 60;
					return false;
				} else {
					countdown--;
					pullid.setAttribute("disabled", "disabled");
					pullid.className = 'pull-code';
					pullid.innerText = "重新发送(" + countdown + ")";
				}
				setTimeout(function() {
					settime(val)
				}, 1000);

				if(!window.localStorage) {
					alert("浏览器不支持localStorage");
				} else {
					//检查值是否存在
					if(localStorage.getItem("pull-code-data") != null) {
						var dates = new Date();
						var codedata = JSON.parse(localStorage.getItem('pull-code-data'));
						var edit = JSON.stringify({
							"phone": codedata.phone,
							"codeTime": countdown,
							"updateTime": parseInt(dates.getTime() / 1000)
						});
						//改，即重新给变量赋值
						localStorage.setItem("pull-code-data", edit);
					}
				}
			}
			//提交
			mui('body').on('tap', '#btn-confirm', function() {
				var val = $("#code").val().trim(),
					th = this;
				if(code.test(val)) {
					mui(th).button('loading');
					$.ajax(base_path + '/tanksgiv/receive_coupon?dates=' + new Date().getTime(), {
						data: {
							"phone": phone,
							"code": val
						},
						dataType: 'json',
						xhrFields: {
							withCredentials: true
						},
						crossDomain: true,
						type: 'post',
						timeout: 15000,
						success: function(dt) {
							if(dt.isRedirect) {
								location.href = dt.redirectURL;
							} else {
								if(dt.status) {
									mui.alert(dt.message,function(){
									    location.href = "/watero/view/coupon_.html";
									});
								} else {
									mui.alert(dt.message, function() {
										mui(th).button('reset');
									});
								}
							}
						},
						error: function(xhr, type, errorThrown) {
							console.log(xhr);
							mui.alert("领取失败！网络出小差了", function() {
								mui(th).button('reset');
							});
						}
					});
				} else {
					if(val != "") {
						mui.alert("验证码错误！", function() {
							$("#code").select();
						});
					} else {
						mui.alert("请填写验证码！", function() {
							$("#code").select();
						});
					}
				}
			});
		</script>
	</body>

</html>