var lastId = 0; var prevImage, offTop = 46, offBot = 0; var consultInfo; var isJieshuCaozuo = false; var notEndConsultId; var isNotQzQkys = false; var isYaoQingQk = true; //是否建管已邀请全科 true:已邀请 ;false:未邀请 mui.plusReady(function() { self = plus.webview.currentWebview(); $('#title').html(self.otherName); getMineInfo(); //初始化个人信息 consultInfo = self.consultInfo; createSession(self.type, getMembersExt); prevImage = mui.previewImage(); var opener = self.opener(); if(opener && opener.id == "faqizixun") { mui.back = backToWebviewById("mingyizixunliebiao", false, function() { var mainWebview = plus.webview.getWebviewById("mingyizixunliebiao"); mui.fire(mainWebview, "activeItem"); }); }else if(opener && (opener.id == "zixunxiangqing")) { var zxxq = plus.webview.getWebviewById("zixunxiangqing"); zxxq.close('none'); backToZdzx(); } else if(opener && (opener.id == "zuyuanziliao")) { function closeOpener(cur) { if(cur.id != "xiaoxi.html" && cur.id != "main" && cur.id != "../../tuandui/html/tuandui.html" && cur.id != "mine.html" && cur.id != "home1.html" && cur.id != "home2.html" && cur.id != "huanzhe.html") { var opener = cur.opener(); cur.close(); closeOpener(opener); } } mui.back = function() { closeOpener(self.opener()); self.close(); var mainWebview = plus.webview.getWebviewById("main"); mui.fire(mainWebview, "activeXiaoxi"); mainWebview.show(); } } else { backToParent(); } }); function getMembersExt() { getMembers(function() { for(var k in members) { if(members[k].role == 1) { //全科还没有被邀请 isNotQzQkys = true; isYaoQingQk = false; //未被邀请 } } isSign(); }); } var qyRelation = 0; function isSign() { sendPost("doctor/family_contract/doctor_patient_sign_exist", { doctor: docInfo.code, patient: otherCode }, null, function(res) { if(res.status == 200) { if(res.data.status != -1 && res.data.status != 0) { //没有签约关系 qyRelation = 1; } consultInfo ? initPage() : getConsultInfo(); } else { mui.toast("获取签约关系失败!"); } }) } function backToZdzx() { var old_back = mui.back; mui.back = function() { if(isJieshuCaozuo) { wv = plus.webview.getWebviewById("zixunjilu"); if(wv) { wv.reload(true); } } var wv = plus.webview.getWebviewById("zhidingzixun"); if(wv) { mui.fire(wv, "refresh"); } old_back(); } } //标签数目影响的轮播事件 function bindSlider() { $('.notmy').hide(); $('#muiSliderIndicator').hide(); $('.mui-slider-group').removeClass('.mui-slider-group'); var slider = mui('#other_div').slider(); slider.stopped = true; //关闭滑动切换 } /** * 获取咨询信息 */ function getConsultInfo() { plus.nativeUI.showWaiting(); imClient.Sessions.isTopicEnded(sessionId, "current", function(res) { if(isEmptyObject(res)) { //患者和医生建立了会话,但是患者没有发送任何咨询信息 $('#input_div').hide(); consultInfo = { patient: otherCode } //getNewMsgs(true); if(!observer) { $('#wrapper1').css({ top: '16px', bottom: '52px' }); $('.xzzd').show(); } else { $('#wrapper1').css({ top: '16px', bottom: '0px' }); $('.xzzd').hide(); } getFirstMsgs(); } else { if(res.status == 10) { //咨询已结束 if(qyRelation == 1 && !observer) { $('#wrapper1').css({ top: '16px', bottom: '52px' }); $('.xzzd').show(); } else { $('#wrapper1').css({ top: '16px', bottom: '0px' }); $('.xzzd').hide(); } $('#input_div').hide(); consultInfo = { patient: otherCode } //getNewMsgs(true); getFirstMsgs(); } else { //咨询未结束 $('#wrapper1').css('bottom', '52px'); offBot = 52; if(myScroll) myScroll.refresh(); notEndConsultId = res.id; $('.topmsg').html('首次回复24小时后,将自动结束咨询立即结束'); sendPost("/doctor/talkgroup/getConsultByGroupCode", { consultCode: res.id }, null, function(res) { console.log(JSON.stringify(res)) consultInfo = res.data; if(consultInfo) { if(consultInfo.type == 7 || consultInfo.type == 6) { bindSlider() } } //getNewMsgs(true); getFirstMsgs(); // PDZiXuanLieXing(); }) } } plus.nativeUI.closeWaiting(); }, function(res) { plus.nativeUI.closeWaiting(); mui.toast("判断是否存在未结束咨询失败") }) } //判断object是否为空 function isEmptyObject(e) { var t; for(t in e) return !1; return !0 } /** * 初始化页面 */ function initPage() { if(consultInfo.type == 7 || consultInfo.type == 6) { bindSlider() } console.log(docInfo.code) console.log(consultInfo.patient) sendPost("/doctor/consult/is_consult_unfinished", {//? doctor: docInfo.code, patient: consultInfo.patient }, undefined, function(res) { console.log(res) if(res.status == 200) { consultInfo.hasOver = res.data; if(res.data != "") { //咨询未结束 notEndConsultId = res.data; $('.topmsg').html('首次回复24小时后,将自动结束咨询立即结束'); $('#wrapper1').css('bottom', '52px'); offBot = 52; if(myScroll) myScroll.refresh(); PDZiXuanLieXing(); } else { //咨询已结束 if(qyRelation == 1 && !observer) { $('#wrapper1').css({ top: '16px', bottom: '52px' }); $('.xzzd').show(); } else { $('#wrapper1').css({ top: '16px', bottom: '0px' }); $('.xzzd').hide(); } $('#input_div').hide(); } //getNewMsgs(true); getFirstMsgs(); } else { mui.toast("获取信息失败"); } } ) } /** * 点击查看好友详细信息 */ $('#qun_detail').on("tap", function() { mui.openWindow('../../huanzhe/html/huanzhexinxi.html', 'huanzhexinxi.html', { extras: { patiCode: consultInfo.patient } }); }) /** * 获取聊天图片列表 */ function getImgMsgList(handle) { im.getPrivateMsg(getUserId(), otherCode, lastId, pageSize, function(data) { console.log("imgs:" + JSON.stringify(data)); chatCache.imgs = data.records.reverse(); appendPrevImgs(chatCache.imgs); if(handle) handle(data); }, 2); } /** * 发送消息 */ function uploadMsg(type, content, locSrc, isNotSend, callBack) { service.isConsultFinished(notEndConsultId, function(res) { if(res.data == 0) { //作用: 更新咨询状态 // sendPost("doctor/consult/reply", { // patient: otherCode, // consult: consultInfo.consult, // type: type, // content: content // }, null, function(res) { // // }) uploadMsgBase(type, content, locSrc, isNotSend, callBack); } else if(res == "timeout" && type == 1) { var tim = new Date().getTime(); var id = "loc" + tim; var d = [{ "sender_id": docInfo.code, "sender_name": docInfo.name, "content_type": 1, "content": content, "timestamp": tim, "id": id, local_src: "", beforeSend: true }]; showMsg(d, false, false, true); addMsgToCache(d, true); $('#contain dl[data-code="' + id + '"]').find('.c-msg').prepend(""); } else { $('.topmsg').hide(); if(qyRelation == 1 && !observer) { $('#wrapper1').css({ top: '16px', bottom: '52px' }); $('.xzzd').show(); } else { $('#wrapper1').css({ top: '16px', bottom: '0px' }); $('.xzzd').hide(); } $('#input_div').hide(); myScroll.refresh(); } }) } /** * 代预约 */ function dyyjl() { mui.openWindow('../../wdyy/html/appointment-register.html', 'appointment-register', { extras: { patient: consultInfo.patient } }); } /** * 健康教育 */ function jkjy() { // mui.openWindow('../../jkjy/html/jiankangjiaoyu.html', 'jiankangjiaoyu', { mui.openWindow('../../jkjy/html/article-store.html', 'jiankangjiaoyu', { extras: { patient: consultInfo.patient, patientName: consultInfo.name } }); } /** * 健康指导 */ function jkzd() { mui.openWindow('../../hzzd/html/guidance_list.html', 'jkzd', { extras: { code: otherCode } }); } /** * 临时随访 */ function lssf() { var url = "../../suifang/html/choose_suifang.html"; mui.openWindow(url, 'choose_suifang', { extras: { patiCode: otherCode } }); } //判断咨询类型各种情况 var quankeCode = ""; //全科code var jianguanCode = ""; //建管code function PDZiXuanLieXing() { if(self.type != "1") { // 家庭医生咨询或三师咨询才能请求doctor/family_contract/patient_team_doctors接口 return ; } sendPost("/doctor/family_contract/patient_team_doctors", { sessionId: self.sessionId }, null, function(res) { // console.error(JSON.stringify(res)) if(res.status == 200) { var curConsultType = consultInfo.type; //当前的咨询类型 1:三师签约 2:家庭签约 var curDoctorCode = docInfo.code; var data = res.data; var qianyueData = null; if(curConsultType == 1) { //三师签约 qianyueData = data.ssSign; } else if(curConsultType == 2) { //家庭签约 qianyueData = data.jtSign; } if(qianyueData) { quankeCode = qianyueData.doctor.doctor; jianguanCode = qianyueData.doctorHealth.doctor; } //当前医生既是全科,也是建管:显示求助专科 if(curDoctorCode == jianguanCode && curDoctorCode == quankeCode) { $("#qiuzhuico p").html("求助"); } //当前医生是建管,不是全科:显示邀请全科 else if(curDoctorCode == jianguanCode && curDoctorCode != quankeCode) { $("#qiuzhuico p").html("邀请全科"); } //当前医生不是建管,是全科:显示求助专科 else if(curDoctorCode != jianguanCode && curDoctorCode == quankeCode) { $("#qiuzhuico p").html("求助"); } } else { mui.toast("获取患者和医生咨询类型失败!"); } }) } /** * 求助/邀请全科 */ function qiuzhu() { plus.nativeUI.showWaiting(); if($("#qiuzhuico p").html() == "邀请全科") { if(isYaoQingQk) { //已邀请全科 mui.toast("已邀请全科"); plus.nativeUI.closeWaiting(); } else { //去邀请全科 var userAgent = plus.storage.getItem("userAgent"); //记录观察者模式 if(JSON.parse(userAgent).teamCode == "1"){ mui.toast("观察者模式无法进行增删改操作"); plus.nativeUI.closeWaiting(); return; } imClient.Sessions.addParticipant(sessionId, quankeCode, function(res) { mui.toast("邀请成功!"); isYaoQingQk = true; imClient.Sessions.sendMessage(sessionId, docInfo.code, "系统", docInfo.name + "已邀请全科医生一起参与咨询", 13, function(data) { showMsg(data.messages, false, false, true); plus.nativeUI.closeWaiting(); }, function(data) { console.log("sendFail" + JSON.stringify(data)); }) }, function(res) { console.error(JSON.stringify(res)); mui.toast('邀请失败,请稍后重试!'); }) } } else { //求助医生 mui.openWindow('../../qzys/html/select_doctor.html', 'qzys-select_doctor', { extras: { consultInfo: consultInfo, sessionId:self.sessionId, accessData: { consultCode: consultInfo.consult, patient: consultInfo.patient } } }); } } function jieshu() { dialog({ content: '