Request = GetRequest(); var chooseType = Request["type"];//界面传送的类型 0不定义类型 1.慢病咨询 2.家庭医生咨询 6.名医咨询 var doctorCode = Request["doctorCode"]; var id = Request["id"]; var guidance = ""; var workTime = "";//医生工作时间 var doctorName = "";//医生名称 var patientName = window.localStorage.getItem('nowPatientName'); var fromPage = Request["fromPage"]; // updateTitle(); //修改header 的标题 function updateTitle(title){ //需要jQuery var $body = $('body'); document.title = title; // hack在微信等webview中无法修改document.title的情况 var $iframe = $(''); $iframe.on('load',function() { setTimeout(function() { $iframe.off('load').remove(); }, 0); }).appendTo($body); } $(function(){ if(fromPage && fromPage=="jkzx") { updateTitle("新增医生健康咨询") } else { guidance = window.localStorage.getItem("guidance") } // 指导内容显示 if (guidance) { $("#guidance").html(guidance); } else { $("#guidanceWrap").hide(); } // 咨询类别 if(chooseType==1){ //$(".span-type").html("慢病管理"); querySignType();//填充下拉框 }else if(chooseType==2){ //$(".span-type").html("家庭医生"); querySignType();//填充下拉框 }else if(chooseType==0) { querySignType();//填充下拉框 } /* 复选框兼容 */ $(document).on("click", ".input-group-pack > input[type=checkbox]", function() { var $cpChk = $(this).parent(); if ($(this).attr("checked") == "checked") { $cpChk.removeClass("checked"); $(this).removeAttr("checked"); } else { $cpChk.addClass("checked"); $(this).attr("checked", true); } }); //弹窗 $('.broadcast-icon').on('click',function(){ $('.broadcast-shadow-panel').removeClass('c-hide'); }); $('.win-cancle').on('click',function(){ $('.broadcast-shadow-panel').addClass('c-hide'); }); //从后台那边获取签名等信息 var params = {}; params.pageUrl = window.location.href; $.ajax(server + "weixin/getSign", { data: params, dataType: "json", type: "post", success: function(res){ if (res.status == 200) { var t = res.data.timestamp; var noncestr = res.data.noncestr; var signature = res.data.signature; wx.config({ // debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId: appId, // 必填,公众号的唯一标识 timestamp: t, // 必填,生成签名的时间戳 nonceStr: noncestr, // 必填,生成签名的随机串 signature: signature,// 必填,签名,见附录1 jsApiList: [ 'chooseImage', 'uploadImage' ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 }); } else{ dialog({ title:'提示', skin:"ui-dialog ax-popup pror", content:"获取微信签名失败", ok: function (){} }).showModal(); window.location.href = "doctor-guidance.html"; } } }); function successFun(res){ if(res.status==200){ var dataList = res.data.doctor; doctorName = dataList.name; $("#lbl_doctor").html(dataList.name+"("+dataList.jobName+")"); $("#lbl_patient").html(patientName); }else{ getListFail(res); } } function getListFail(res){ if (res && res.msg) { dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg,bottom:true}).show(); } else { dialog({contentType:'tipsbox', skin:'bk-popup' , content:'加载失败',bottom:true}).show(); } } //提交咨询 $("#commit").click(function() { if($(this).hasClass("active")){ var data = {}; data.type = Number($("#txtTypeCode").val()); if($("#txtContent").val() == null) data.symptoms = ""; else data.symptoms = utf16toEntities($("#txtContent").val().replace(/\s+/g,"")); data.voice = ""; if (validate(data)) { //验证通过执行 dd.showModal(); var images = getImages(); if(images.length == 0){ $("#commit").css("pointer-events","none"); doSubmit(data); } else{ uploadImage(data); } } } }); }); function checkInWork(doctor){ sendPost('/patient/consult/is_doctor_working', {doctor:doctor}, 'json', 'post', queryFailed, function(res){ if(res.status==200){ if(res.data==0){ dialog({ title: '提示', content: '您好,由于您的签约医生工作繁忙,所以设置了每日回复咨询的时间段,所以,在该时间段外的时间,您的咨询将不会马上获得医生的回复', okValue:'我知道了', ok: function (){ return; }, cancelValue: '查看时间', cancel: function () { alert("查看时间") } }).showModal(); } }else{ queryFailed(res); } }); } //查询咨询类型 function querySignType(){ d.show(); sendPost('patient/sign_status', {}, 'json', 'post', querySignTypeFailed, querySignTypeSuccess); } function querySignTypeFailed(res) { d.close(); if (res && res.msg) { dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show(); } else { dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'获取咨询类型失败'}).show(); } } function querySignTypeSuccess(res) { if (res.status == 200) { $('#txtTypeCode').val(chooseType); $('#lbl_doctor').html(getSignDoctor(res,chooseType)); $("#lbl_patient").html(patientName); var arr_key=[]; var arr_value=[]; var sign = Number(res.data); if(sign == 1){ arr_key=[1]; arr_value=['慢病管理']; } else if(sign == 2){ arr_key=[2]; arr_value=['家庭医生']; } else if(sign == 3&&chooseType==0){ arr_key=[1,2,6]; arr_value=['慢病管理', '家庭医生']; }else if(sign == 3&&chooseType==1){ arr_key=[1]; arr_value=['慢病管理']; }else if(sign == 3&&chooseType==2){ arr_key=[2]; arr_value=['家庭医生']; } else{ arr_key=[]; arr_value=[]; } //签约类型 var option1 = { theme: 'ios', lang: 'zh', formatValue: function(d) { return d.join(','); }, customWheels: true, wheels: [ [{ keys: arr_key, values: arr_value }] ], onSelect: function(valueText, inst) { var dd = eval("[" + valueText + "]"); $('#txtTypeCode').val(dd[0].keys); $('#txtTypeName').val(dd[0].values); $('#lbl_doctor').html(getSignDoctor(res,dd[0].keys)); } }; $('#txtTypeName').mobiscroll(option1); $('#txtTypeName').val(option1.wheels[0][0].values[0]); $('#txtTypeCode').val(option1.wheels[0][0].keys[0]); $('#lbl_doctor').html(getSignDoctor(res,option1.wheels[0][0].keys[0])); //选择发病时间 $('li.ill-time').mobiscroll({ theme: 'ios', lang: 'zh', formatValue: function(d) { return d.join(','); }, customWheels: true, wheels: [ [{ keys: ['0', '1', '2', '3', '4', '5'], values: ['最近24小时', '最近一周', '最近三个月', '最近一年', '一年以上', '不清楚'] }] ], onSelect: function(valueText, inst) { var dd = eval("[" + valueText + "]"); $('input[data-time=illTime]').val(dd[0].values); } }); d.close(); } else { querySignTypeFailed(res); } } //获取医生信息 function getSignDoctor(data,type){ var doctor_name = ""; var doctor_type = ""; switch(Number(type)) { case 1: doctor_type = data.teamDoctors; break; case 2: doctor_type = data.familyDoctors; break; default: break; } for(var i=0; i < doctor_type.length; i++){ doctor_name += doctor_type[i] + ","; } if(doctor_name.length > 0){ doctor_name = doctor_name.substring(0, doctor_name.length-1); } return doctor_name; } //验证信息 function validate(data) { // if (data.type == '') { // dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请选择咨询类型'}).show(); // return false; // } // if (data.when == '') { // dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请选择发病时间'}).show(); // return false; // } if (data.symptoms.length < 10) { dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请至少用10个字描述您的症状'}).show(); return false; } if (data.symptoms.length > 500) { dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请在500字以内完成您的症状描述'}).show(); return false; } if(!$(".input-group-pack > input[type=checkbox]").attr("checked")){ dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请勾选"我已阅读咨询说明"'}).show(); return false; } return true; } var serverId = ""; function chooseImage(){ wx.chooseImage({ count: 9-getImages().length, success: function (res) { for (var i in res.localIds) { appendFile(res.localIds[i]); } } }); } function uploadImage(data){ $("#commit").css("pointer-events","none"); var images = getImages(); if (images.length == 0) { return; } var i = 0, length = images.length; serverId = ""; function upload() { wx.uploadImage({ localId: images[i], isShowProgressTips: 0, success: function (res) { i++; if(serverId.length == 0){ serverId = res.serverId; } else{ serverId =serverId + "," + res.serverId; } if (i < length) { upload(); } if(i == images.length){ doSubmit(data); } }, fail: function (res) { $("#commit").css("pointer-events",""); alert(JSON.stringify(res)); } }); } upload(); } // 添加文件 function appendFile(p) { var amount = getImages().length; if (amount >= 8) { $("#add_img_li").hide(); } if(amount < 9){ var $li = $('
  • ' + ' ' + ' ' + '
  • '); var $add_img_li = $("#add_img_li"); $add_img_li.before($li); $("#image_tips").text(getImages().length + "/9"); } } //获取需要上传的图片 function getImages() { var images = []; $("#img_ul").find("img").each(function() { var imgSrc = $(this).attr("data-src"); images.push(imgSrc); }); return images; } //查看图片 function viewImg(dom) { var $img = $(dom); var thissrc = $img.attr("data-src"); var mWid = $(window).width(); var mHei = $(window).height(); var nHtml = '
    '; $("body").append(nHtml); $(".delimgpop").click(function() { $(this).remove() }); }; //删除图片 function delImg(dom) { var $li = $(dom).parent(); $li.remove(); $("#image_tips").text(getImages().length + "/9"); var amount = getImages().length; if(amount <= 8){ $("#add_img_li").show(); } return; } //微信sdk配置出错 wx.error(function (res) { alert("wx.error:" + res.errMsg); }); //提交咨询 function doSubmit(data) { data.images = serverId; var url = 'patient/consult/add';//新增三师或家庭 data.guidance = id; sendPost(url, data, 'json', 'post', submitFailed, submitSuccess); } function time_range(beginTime, endTime, nowTime) { var strb = beginTime.split (":"); if (strb.length != 2) { return false; } var stre = endTime.split (":"); if (stre.length != 2) { return false; } var strn = nowTime.split (":"); if (stre.length != 2) { return false; } var b = new Date (); var e = new Date (); var n = new Date (); b.setHours (strb[0]); b.setMinutes (strb[1]); e.setHours (stre[0]); e.setMinutes (stre[1]); n.setHours (strn[0]); n.setMinutes (strn[1]); if (n.getTime () - b.getTime () > 0 && n.getTime () - e.getTime () < 0) { return "1";//在时间范围内 } else { return "0";//不在工作时间内 } } function CompareDate(t1,t2) { var date = new Date(); var a = t1.split(":"); var b = t2.split(":"); return date.setHours(a[0],a[1]) > date.setHours(b[0],b[1]); } //判断医生是否在工作时间内 function isWordTime(curWorkTime){ dd.close(); var week = new Date().getDay(); var myDate = new Date(); debugger if(curWorkTime){//有上班时间 var cosultTimeArr = curWorkTime.split("~"); var curHours = myDate.getHours(); //获取当前小时数(0-23) var curMinutes = myDate.getMinutes();//获取当前分钟数(0-59) var curTime = curHours+":"+curMinutes; var timeRange = time_range(cosultTimeArr[0],cosultTimeArr[1],curTime) if(timeRange=="1"){//在工作时间内,查询某个医生名医当前剩余咨询次数 consultTimesRemain(); }else{//不在工作时间内,判断早晚 var isFlag1 = CompareDate(curTime,cosultTimeArr[0]); var isFlag2 = CompareDate(curTime,cosultTimeArr[1]); if(!isFlag1){//来早了 dialog({ content: '您来早了哦,'+doctorName+'医生将在'+cosultTimeArr[0]+'准时开始接受咨询~', cancelValue: '我知道了', cancel: function () { $("#commit").removeClass("active"); dd.close(); return; } }).showModal(); return false; } if(isFlag2){//来晚了 dialog({ content: '您来晚了哦~'+doctorName+'医生本日咨询时间已过,请改日再来~', cancelValue: '我知道了', cancel: function () { $("#commit").removeClass("active"); dd.close(); return; } }).showModal(); return false; } } }else{ dialog({ content: '医生今天不上班哦,请在医生咨询计划时间段内咨询', cancelValue: '我知道了', cancel: function () { $("#commit").removeClass("active"); dd.close(); return; } }).showModal(); return false; } } function submitFailed(res) { $("#commit").css("pointer-events",""); dd.close(); if (res && res.msg) { dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show(); } else { dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'提交失败'}).show(); } } function submitSuccess(res) { if (res.status == 200) { $("#commit").css("pointer-events",""); dd.close(); window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appId + "&redirect_uri=http%3a%2f%2f" + weixinUrl + "%2f" + urlName + "%2fwx%2fhtml%2fyszx%2fhtml%2fdoctor-consultation.html&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect"; //window.location.href = "vedio-consulting-commit-success.html?type=2"; } else { submitFailed(res); } } //function voicePop(n) { // $(".win-broadcast,.win-broadcast-mb").show(); // $("#voice-finish").click(function() { // $("#voice" + n).show(); // $(".win-broadcast,.win-broadcast-mb").hide(); // }); //} // //function voicePopClose() { // $(".win-broadcast,.win-broadcast-mb").hide(); //}