var d = dialog({contentType:'load', skin:'bk-popup'}); var dd = dialog({contentType:'load', skin:'bk-popup', content:'提交中...'}); var num = 60, // 默认发送验证码时间 timer; // 计时器 var scroller1 = new IScrollPullUpDown('wrapper',{ probeType:2, bounceTime: 250, bounceEasing: 'quadratic', mouseWheel:false, scrollbars:true, click:true, fadeScrollbars:true, interactiveScrollbars:false }, null, null); $(function(){ // 判断是否登录 checkUserAgent(); var code = window.localStorage.getItem("familyCode"); var name = window.localStorage.getItem("familyName"); var mobile = window.localStorage.getItem("familyMobile"); var imgUrl = window.localStorage.getItem("familyImgUrl"); var relation = window.localStorage.getItem("familyRelation"); var temp = name + ' (' + mobile + ')'; // 头像为空设置默认头像 if(imgUrl == undefined || imgUrl == null || imgUrl == ""){ imgUrl = "../../../images/p-default.png"; } $("#people").html(temp); $("#imgUrl").attr("src", getImgUrl(imgUrl)); // 验证码 $("#sendCode").bind("tap", function () { // 发送验证码 var data = {}; data.mobile = mobile; data.type = 10; data.status = 200; dd.show(); sendPost("common/captcha", data, "json", "post", sendCodeFailed, sendCodeSuccesss); }); // 确认提交 $("#submit").bind("tap", function () { var captcha = $("#captcha").val(); if (captcha.trim() == "") { dialog({contentType:'tipsbox', skin:'bk-popup' , content:'验证码不能为空'}).show(); return false; } dd.show(); var data = {}; data.member = code; data.captcha = captcha; data.relation = relation; sendPost("patient/family/member_add", data, "json", "post", addFailed, addSuccesss); }); }); // 禁止拖动 document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false); // 添加成功 function addSuccesss (res) { if (res.status == 200) { dd.close(); var d3 = dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show(); setTimeout(function () { window.location.href = "family.html"; }, 1000); } else { //非200则为失败 addFailed(res); } } // 添加失败 function addFailed (res) { dd.close(); if (res && res.msg) { var d1 = dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show(); } else { var d2 = dialog({contentType:'tipsbox', skin:'bk-popup' , content:'加载失败'}).show(); } } // 验证码计时器 function doLoop(){ num--; if(num > 0){ $("#message").html(num + '秒后可重新获取'); }else{ clearInterval(timer); //清除js定时器 $("#code1").show(); $("#code2").hide(); num = 60; //重置时间 } } // 发送验证码成功 function sendCodeSuccesss (res) { if (res.status == 200) { dd.close(); var d3 = dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show(); // 清除计时器 $("#code1").hide(); $("#message").html(num + '秒后可重新获取'); $("#code2").show(); timer = setInterval(doLoop, 1000); //一秒执行一次 } else { //非200则为失败 sendCodeFailed(res); } } // 发送验证码失败 function sendCodeFailed (res) { dd.close(); if (res && res.msg) { var d1 = dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show(); } else { var d2 = dialog({contentType:'tipsbox', skin:'bk-popup' , content:'加载失败'}).show(); } }