var pagetype = 21; var d = null; var imgKey = null; $(function(){ var selectData='';//用户信息 initValidate(); d= dialog({contentType:'load', skin:'bk-popup'}); checkUserAgent(); var doctorInfo = window.localStorage.getItem("doctorInfo"); if(doctorInfo&&doctorInfo!=""){ doctorInfo = JSON.parse(doctorInfo); }else{ //dialog({contentType:'tipsbox', skin:'bk-popup' , content:'医生数据异常重新选择!',bottom:true}).show(); //return; } var arrangeDate = window.localStorage.getItem("arrangeDate"); if(arrangeDate&&arrangeDate!=""){ arrangeDate = JSON.parse(arrangeDate); }else{ //dialog({contentType:'tipsbox', skin:'bk-popup' , content:'预约日期异常请返回重新选择!',bottom:true}).show(); //return; } bindEvents(); function initValidate(){ var serurl="patient/captcha"; var posttype="get"; if(imgKey!=null){ serurl=serurl+"/"+imgKey; posttype="post"; } sendPost(serurl,{},"json",posttype,function(res){ dialog({contentType:'tipsbox', skin:'bk-popup' , content:"验证码获取失败!",bottom:true}).show(); },function(res){ if(res.status==200){ imgKey = res.data.key; $("#validateDiv").attr("src","data:image/png;base64,"+res.data.image); }else{ dialog({contentType:'tipsbox', skin:'bk-popup' , content:"验证码获取失败!",bottom:true}).show(); } }) } $("#validateDiv").on("click",function(){ initValidate(); }) function getUsersPromise() { return new Promise(function(resolve, reject) { sendPost('patient/family/authorize_members',{},"json",'GET',function(res){ dialog({contentType:'tipsbox', skin:'bk-popup' , content:"就诊居民列表获取失败!",bottom:true}).show(); },function(res){ if(res.status==200){ resolve(res) }else{ dialog({contentType:'tipsbox', skin:'bk-popup' , content:"就诊居民列表获取失败!",bottom:true}).show(); } }) }) } function bindEvents(){ var scroller1 = new IScrollPullUpDown('wrapper',{ probeType:2, bounceTime: 250, bounceEasing: 'quadratic', mouseWheel:false, scrollbars:true, fadeScrollbars:true, click:true, interactiveScrollbars:false },null,null); $("#mobile").on("focus",function(){ $(".searchbar-clear").css("pointer-events","none").css("opacity",0); if($(this).val()){ $(this).next().css("pointer-events","auto").css("opacity",1); $(this).next().show(); } }).on("input",function(){ $(this).next().css("pointer-events","auto").css("opacity",1); $(this).next().show(); }); $(".visit-ul").on("click",".searchbar-clear",function(){ $(this).prev().val(""); $(this).css("pointer-events","none").css("opacity",0); $(this).prev().focus(); return false; }); $(".div-immediately-btn").on("click",function(){ var mobile = $("#mobile").val(); if(!isphone(mobile)){ dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'手机号格式不正确'}).show(); return; } $("#validateCode").blur(); $("#mobile").blur(); //校验验证码是否正确 sendPost("patient/captcha/"+imgKey,{"text":$("#validateCode").val()},"json","get",function(res){ dialog({contentType:'tipsbox', skin:'bk-popup' , content:"验证码校验失败!",bottom:true}).show(); },function(res){ if(res.status==200){ if(res.pass==true){ imgKey = null; initValidate(); applyData(); }else{ dialog({contentType:'tipsbox', skin:'bk-popup' , content:"验证码错误,请重新输入!",bottom:true}).show(); } }else{ dialog({contentType:'tipsbox', skin:'bk-popup' , content:"验证码校验失败!",bottom:true}).show(); } }); }) window.addEventListener("resize", function(){ var u = navigator.userAgent; if(u.indexOf('Android') > -1 || u.indexOf('Linux') > -1){ var self = document.getElementById("validateCode"); setTimeout(function(){ self.scrollIntoView({block: "end", behavior: "smooth"}); }, 150); } }) } initData(); function initData(){ $("#hospitalName").html(doctorInfo['hospitalName']); $("#hosDeptDocName").html(doctorInfo['hosDeptName']+" "+doctorInfo['name']); $("#yyTime").html(arrangeDate['startTime'].split(" ")[0]+" "+arrangeDate['yysj']); // query(); getUsersPromise().then(function(res) { var list = res.data; selectData = list[0] $("#mobile").val(selectData.mobile); $("#username").html(selectData.name); $("#idcard").html(selectData.idcard); $("#ssc").html(selectData.ssc); $('#ms-username').mobiscroll({ theme: 'ios', lang: 'zh', formatValue: function(d) { return d.join(','); }, customWheels: true, wheels: [ [{ keys: _.range(0, list.length), values: _.pluck(list, 'name') }] ], onSelect: function(valueText, inst) { var dd = eval("[" + valueText + "]"); var selectKey = dd[0].keys; var user = list[selectKey]; selectData = list[selectKey];//储存信息 $('#username').text(user.name); $('#idcard').text(user.idcard); $('#ssc').text(user.ssc); $("#mobile").val(user.mobile); } }); }) .catch(function(e) { console && console.error(e) }) } function query() { d.show(); var data={}; sendPost('patient/baseinfo', data, 'json', 'post', queryFailed, querySuccess); } function querySuccess(res){ d.close(); if(res.status==200){ var ssc = res.data.ssc; var j = ssc.substring(ssc.length,ssc.length-3); var sscStr = ssc.replace(j,'***'); $("#username").html(res.data.name); $("#idcard").html(res.data.idcard); $("#ssc").html(sscStr); }else{ queryFailed(res); } } function queryFailed(res){ d.close(); if (res && res.msg) { if((res.msg).indexOf("SOAP")>=0){ dialog({contentType:'tipsbox', skin:'bk-popup' , content:"医院接口访问异常,请刷新后重试!",bottom:true}).show(); return false; } dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg,bottom:true}).show(); } else { dialog({contentType:'tipsbox', skin:'bk-popup' , content:'加载失败',bottom:true}).show(); } } function applyData(){ d.show(); var params = {}; params.city="350200"; params.hospitalId=doctorInfo.hospitalId; params.hospitalName = doctorInfo.hospitalName; params.hosDeptId = doctorInfo.hosDeptId; params.hosDeptName = doctorInfo.hosDeptName; params.doctorId = doctorInfo.id; params.doctorName = doctorInfo.name; delete arrangeDate.yysj; params.arrangeDate=JSON.stringify(arrangeDate); params.patient = selectData.code params.patientName = selectData.name; params.cardNo = selectData.idcardAll; params.clinicCard = selectData.ssc; params.patientPhone = $("#mobile").val(); sendPost("third/guahao/CreateOrder",params,"json","POST",queryFailed,submitSuccess); } function submitSuccess(res){ d.close(); if(res.status==200){ dialog({contentType:'tipsbox', skin:'bk-popup' , content:'预约成功!',bottom:true}).show(); setTimeout(function(){ location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+appId+"&redirect_uri="+wxurl+"%2fwdyy%2fhtml%2fmy-appointment.html&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect"; },200); }else{ queryFailed(res); } } });