var request = getRequest(), sessionId = request.sessionId, patiCode, consultCode, prescriptionStatus, prescriptionCode; page = 1, members = []; var docInfo = window.localStorage.getItem("docInfo"); docInfo = JSON.parse(docInfo); $(function(){ //续方咨询的sessionId 格式 居民code+咨询code+咨询类型( 8 ) patiCode = sessionId.split("_")[0]; consultCode = sessionId.split("_")[1]; getConsultStatus(); //获得会话参与人员 consultingAPI.getMembers(sessionId).then(function(res){ members = res; getMessage(true); }) getPrescriptionInfo(); getPatientServiceType(); //获得患者的标签类型 connectSocket(); bindEvents(); }) function getConsultStatus(){ var params = {consult: consultCode}; consultingAPI.getConsultStatus({data: params}).then(function(res){ if(res.status == 200){ //咨询状态(0进行中,1已完成,-1患者取消,-2超时未响应自动关闭) if(res.data == 0) { //咨询未结束 } else { //咨询已结束 $('.info-panel').html('咨询求助已结束'); $('.send-btn').addClass("disabled"); $("#file_head").attr("disabled", true); } }else{ } }); } function getMessage(isInit){ var params = { page: page, pagesize: 10, end_msg_id: '', start_msg_id: '', user: docInfo.code, session_id: sessionId, content_type: '', isoffset: '' } consultingAPI.getMessages(sessionId, {data: params}).then(function(res){ var list = res; if (list && list.length > 0) { id = list[list.length - 1].id; var html = '', length = list.length; for (var j = list.length-1; j >= 0; j--) { var reply = list[j]; html += formatMsg(reply); } if(isInit){ $("#talkBox").append(html); $("#talkBox").slimScroll({ height: '100%', width: '100%', alwaysVisible: true, start : 'bottom', }).bind('slimscroll', function(e, pos) { if(pos == 'top'){ if(length == 10){ page++; getMessage(); } } }); }else{ $("#talkBox").prepend(html); $("#talkBox").slimScroll({ scrollTo: 'bottom' }); } $(".fancybox").fancybox({openEffect:"none",closeEffect:"none"}); plyr.setup(); } }); } function formatMsg(reply){ try{ reply = JSON.parse(reply); }catch(e){ } var isSelf = (reply.sender_id==docInfo.code) ? true : false; var isSystem = reply.sender_id == 'system'; var html = ''; if(reply.content_type == 7 || reply.content_type == 10){ var content = reply.content; if(isSystem){ content = '居民24小时内未回复,系统自动结束咨询'; } html = template('sys_msg_tmp', {content: content}); }else{ var member; for(var i=0; i0){ disease += ','+item.name; }else{ disease += item.name; } } $(".diseaseInfo").text("该居民为"+disease+"患者"); } }else{ showWarningMsg(res.msg) } }); } function connectSocket(){ jQuery.getScript(APIService.socketUrl+"/socket.io/socket.io.js").done(function() { var socket = io.connect(APIService.socketUrl ); socket.emit('login', { userId: docInfo.code, password: docInfo.code, sessionId: sessionId, clientType: "doctor" }); socket.on('message', function (data) { console.log(data); if(data.read && data.read == "all"){ return ; } var html = formatMsg(data); $("#talkBox").append(html); $("#talkBox").slimscroll({ scrollTo: 'bottom' }); }); socket.on('error', function (data) { console.log(data) }); socket.on('ack', function (data) { }); }).fail(function() { // dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:"医生实时对话连接失败!"}).show(); }); } function sendMessage(contentType, content){ var params = { sender_id: docInfo.code, sender_name: docInfo.name, content_type: contentType, content: content, view: 0 }; consultingAPI.sendMessage(sessionId, {data: params}).then(function(res){ console.log(res); // var html = ""; // for(var i=0; i 0 && prescriptionStatus < 21){ dialog({ content:'续方申请未审核,不能结束咨询', width: 460, okValue:'我知道了', ok: function() { return; } }).width(320).showModal(); return false; } dialog({ content:'结束咨询后,居民及所有医生均无法再次回复,是否确认继续结束?', width: '460px', okValue:'继续结束', ok: function() { var params = {consult: consultCode}; consultingAPI.finishConsult({data: params}).then(function(res){ if(res.status == 200) { var content = docInfo.name+'结束了咨询', html = template('sys_msg_tmp', {content: content}); $("#talkBox").append(html); $("#talkBox").slimScroll({ scrollTo: 'bottom' }); $('.info-panel').html("咨询求助已结束"); $(".send-btn").addClass("disabled"); $("#file_head").attr("disabled", true); showSuccessMsg("已结束咨询"); } else { showErrorMsg(res.msg); } }) }, cancelValue: '我再看看', cancel: function(){} }).showModal(); } function bindEvents(){ $(".send-btn").on('click', function(){ var $this = $(this); if($this.hasClass("disabled")){ return false; }else{ var text = $.trim($("#input_content").text()); if(text.length == 0){ showWarningMsg('发送内容不能为空'); return false; }else{ sendMessage(1, text); $("#input_content").text(''); var obj = { content: text, content_type: '1', sender_id: docInfo.code, timestamp: new Date().getTime() } var html = formatMsg(obj); $("#talkBox").append(html); $("#talkBox").slimscroll({ scrollTo: 'bottom' }); } } }); $("#file_head").on('change', function(){ var file = this.files[0]; //先上传图片去服务器,然后再发送消息 var fd=new FormData(); fd.append("action", "UploadVMKImagePath"); fd.append("file", file); //加入文件对象 fd.append("type", '2'); var ajaxObj = { data: fd, cache: false, processData: false, contentType: false } consultingAPI.uploadImage(ajaxObj).then(function(res){ if(res.status == 200){ sendMessage(2, res.urls); var obj = { content: res.urls, content_type: '2', sender_id: docInfo.code, timestamp: new Date().getTime() } var html = formatMsg(obj); $("#talkBox").append(html); $("#talkBox").slimscroll({ scrollTo: 'bottom' }); }else{ } }); }); //查看详情 $("body").on('click', '.view-detail', function(res){ //修改顶部tab页面的 var url = parent.document.getElementById("tab").src; parent.document.getElementById("tab").src = "prescription-tabs.html?sessionId="+sessionId+"&patiCode="+patiCode+"&code="+prescriptionCode+"&tab=1&fromTabIdx=0"; }) } template.helper('getSourceUrl', function(str){ return APIService.getImgUrl(str); })