$(function () { var winHeight=window.innerHeight,//窗体高度 winWidth=window.innerWidth,//窗体高度 msgListUrl = 'doctor/consult/loglist', myScroll = null, self, docInfo, teamInfo, offTop = 45, offBot = 52, pageSize = 1000, prevImage, otherCode = '',//咨询者code sessionId = '',//咨询者拼接id sessionName = '',//咨询者姓名 createTime = '',//咨询时间 qyDocInfo = null,//签约医生信息 consultInfo = {},//患者详情 status = '',//0 待回复 1进行中 2完成 type = '', //咨询类型 1三师咨询,2家庭医生咨询,3图文咨询,4公共咨询,5病友圈, 6名医咨询 lastTimestamp = '', urlRegex = new RegExp('((https|http|ftp|rtsp|mms)?://)' + '?(([0-9a-zA-Z_!~*\'().&=+$%-]+: )?[0-9a-zA-Z_!~*\'().&=+$%-]+@)?' //ftp的user@ + '(([0-9]{1,3}\\.){3}[0-9]{1,3}' // IP形式的URL- 199.194.52.184 + '|' // 允许IP和DOMAIN(域名) + '([0-9a-zA-Z_!~*\'()-]+\\.)*' // 域名- www. + '([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]\\.' // 二级域名 + '(gov|edu|int|com|cn|cx|cn|wang|cc|xin|net|org|top|tech|red|pub|ink|info|xyz|win))' // first level domain- .com or .museum + '(:[0-9]{1,4})?' // 端口- :80 + '((/[0-9a-zA-Z_!~*\'().;?:@&=+$,%#-]+)+/?)?' + '((\\?[0-9a-zA-Z_!~*\'().;:@&=+$,%#-]+)+/?)?'); var $title = $('#title'), $xzzd = $('#xzzd'), $tixys = $('.tixys'); //mui初始化 mui.init({ gestureConfig:{ doubletap: true, longtap: true, hold: true, release: true } }); mui.plusReady(function () { docInfo = JSON.parse(plus.storage.getItem("docInfo")); self = plus.webview.currentWebview(); sessionId = self.sessionId; sessionName = self.sessionName; createTime = self.sessionTime; qyDocInfo = self.qyDocInfo ? JSON.parse(self.qyDocInfo) : null; consultInfo = self.consultInfo; otherCode = self.otherCode; status = self.stutas; type = self.type; //设置标题 $title.html(sessionName + createTime + '咨询'); //设置高度 if(status == 2){ offTop = 70 } //获取成员信息 getMembers(); myScroll = $('#contain').lscroll({ type: 2, pullDownMsg1: "下拉加载更多", pullDownMsg2: "松手开始加载", pullDownAction: function(g){ getMsgList(g.options.page, false, true); }, style: "top: "+ offTop +"px; bottom: "+ offBot +"px", }); prevImage = mui.previewImage(); }); /** * 获取消息(下拉刷新) */ function getMsgList(pageIndex, isClear, isPre) { getMsgs(pageIndex,function(data){ if (!!!data.list) { plus.nativeUI.closeWaiting(); myScroll.refresh(!!!data.list); return; } showMsg(data.list, isClear, isPre); }) } /** * 获取成员信息 */ function getMembers(callBack){ imClient.Sessions.getParticipants(sessionId, function(rs){ members = {}; var patientCode; $.each( rs , function(i, v) { if(v.id!=docInfo.code) otherCode = v.id; if(v.is_patient==1){ isPatient = true; patientCode = v.id; } }); otherCode = patientCode||otherCode; isSign(); }, function(msg){ console.log("e:"+JSON.stringify(msg)) mui.toast("获取成员列表失败!"); }) } //判断是否有签约关系 function isSign() { //status === 2:已完成回复 if (status != 2) { sendGet("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.msg === '无签约关系') { //没有签约关系 //判断是否是名医咨询,名医咨询可以跳转去IM页面 if(type == 6){ $xzzd.show(); } // 修复bug#3460 【医生端】健康咨询:患者签约到期与医生存在未结束咨询时,从健康咨询进入无法回复咨询。 if(qyDocInfo&& (docInfo.code != qyDocInfo.doctor)){ $tixys.show(); } else { $xzzd.show(); } } else { $xzzd.show(); } } else { mui.toast("获取签约关系失败!"); } }) }else{ //获取被评价成员 sendGet("doctor/consult/evaluate/list", { consult:consultInfo.id, type:1 }, null, function(res) { if(res.status == 200) { if(res.list.length > 0){ //已经评分 //兼容1.3.4的数据 if(res.list[0].evaluate_type == 0){//旧数据 $.each( res.list , function(i, v) { showStar(v); }) $('#service').show(); }else{ if(res.list[0].type == 1){//实名 var obj = _.groupBy(res.list, function(item){ return item.doctor; }) for(var key in obj){ var arr = obj[key], dataObj = {}; $.each( arr , function(i, v) { if(v.evaluate_type == 1){ dataObj.ability = v.score; } if(v.evaluate_type == 2){ dataObj.attitude = v.score; } if(v.evaluate_type == 3){ dataObj.speed = v.score; } }) dataObj.name = arr[0].name; dataObj.avatar = arr[0].photo; showStar2(dataObj); } $('#service').show(); }else{ $('.no-service').show(); } } }else{ $('.no-service').show(); } }else{ mui.toast("获取评分数据失败"); } }) } getMsgs(1,function (res) { if (!!!res.list) { plus.nativeUI.closeWaiting(); mui.toast("暂无咨询记录!"); myScroll.refresh(!!!res.list); return; } showMsg(res.list, false, false, true) }); } /** * 获取聊天图片列表 */ 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 showStar(obj){ if(obj){ var list='', num=''; var one = '
  • '; num = Math.floor(obj.score/20); for(var i=0;i
    '+obj.name+'
    '; $('#starList').append(html); } } //显示星星 新数据 function showStar2(obj){ if(obj){ var abList = addStars(obj.ability) var atList = addStars(obj.attitude) var spList = addStars(obj.speed) var html='
  • '+obj.name+'
    专业能力
      '+abList+'
    服务态度
      '+atList+'
    回复速度
      '+spList+'
  • '; $('#starList').append(html); } } function addStars(score){ var list='', num=''; var one = '
  • '; num = Math.floor(score/20); for(var i=0;i= 0; i--) { msg = msgList.list[i]; msg = JSON.parse(msg); setLastMsg(msg); typeMsg = parseInt(msg.content_type); if (typeMsg === 4|| typeMsg==14) { continue; } var contentMsg = msg.content; if(typeMsg == 7 || typeMsg==10 || typeMsg==13){ if(typeMsg == 7 && msg.sender_id == 'system'){ contentMsg = "居民24小时内未回复,系统自动结束咨询"; } html += '
    '+ contentMsg +'
    '; continue; } else if(typeMsg == 5){ var con = JSON.parse(msg.content); if(msg.sender_id == docInfo.code){ console.log(msg.content) html += '
    已向'+ con.doctor_name +'医生求助立即查看
    '; } continue; } var _class = ["chat-log"]; if (users.length > 0) { for (var ii = 0; ii < users.length; ii++) { var user = users[ii]; if (user['id'] === msg['sender_id']) { doctor_img = getImgUrl(user['avatar']); doctor_name = user['name']; if(docInfo.code != user['id']) { _class.push("chat-left"); } else { _class.push("chat-right"); } break; } } } if(msg.timestamp - preTime > 60 * 1000) { preTime = msg.timestamp; var date = new Date(); date.setTime(msg.timestamp); var time = date.format('yyyy-MM-dd hh:mm:ss'); html += '
    ' + time + '
    '; } //type:1.文字 2.图片 3.音频 var temp = '
    '+ '
    ' + '
    ' + doctor_name + ''; var sendErrDom = ""; if(!msg.beforeSend && msg.id && msg.id.indexOf('loc')==0){ sendErrDom = ""; } switch(typeMsg) { case 0: case 1://普通文本 case 8://求助文本 temp += '
    '+ sendErrDom +'
    ' + matchUrl(contentMsg) + '
    '; break; case 6://开始咨询文本 //如果是续方咨询,显示样式不一致 if(type == 8){ var rs = JSON.parse(contentMsg); temp += '
    '+ sendErrDom + '
    '+ '

    【本消息为系统提醒】

    '+ '

    '+rs.title+'

    '+ '

    '+rs.tzMsg+'

    '+ /*'

    上次续方时间'+rs.lastTime+'

    '+*/ '
    '; }else{ temp += '
    '+ sendErrDom +'
    ' + matchUrl(contentMsg) + '
    '; } break; case 2://图片 case 9://求助图片 if(msg.local_src=="data:,") contentMsg = msg.content; else if(msg.local_src) contentMsg = msg.local_src.indexOf('data:')==0? msg.local_src: plus.io.convertLocalFileSystemURL(msg.local_src); else contentMsg = msg.content; temp += '
    '+ sendErrDom + '
    '+'
    '; $('img.l-previmg[data-code="'+ msg.id +'"]').remove(); break; case 3://语音 var rec = msg.local_src? JSON.parse(msg.local_src) : contentMsg? JSON.parse(contentMsg) : undefined; if(rec){ var path = msg.local_src?msg.local_src:msg.content; temp += "
    "+ sendErrDom + "
    "+ "
    " + ""+(rec? rec.times: "") +"\'\'"+ "
    "+ "
    "; } break; case 12: //视频 var videoInfo = msg.content.split(","); var shichang = formatSeconds(videoInfo[2]);//时长 if(docInfo.code != msg.sender_id) { temp += '
    '+ ''+ ''+ ''+ ''+shichang+''+ '
    '; }else{ temp += '
    '+ ''+ ''+ ''+ ''+shichang+''+ '
    '; } break; case 15: //审核消息 var rs = JSON.parse(contentMsg); var reason = ""; if(rs.reason){ reason = '

    原因:'+rs.reason+'

    '; } temp += '
    '+ sendErrDom + '
    '+ '

    【本消息为系统提醒】

    '+ '

    审核消息:

    '+ '

    '+rs.title+'

    '+ '

    审核结果:'+rs.result+'

    '+reason+ '点此查看详情'+ '
    '; break; } html += temp + '
    '; } if(isPre) lastId = msgList.list[msgList.list.length - 1].id; if(isClear){ $("#contain").html(html); }else{ if(isPre){ $("#contain").prepend(html); if(scrollToTop) myScroll.refreshToTop(); else myScroll.refresh(msgList.list.length==0); return; } else { $("#contain").append(html); } } myScroll.refreshToEnd(); plus.nativeUI.closeWaiting(); } function imgLoad(img){ if(img.src.indexOf('data:')==0) return; var canvas = document.createElement('CANVAS'), ctx = canvas.getContext('2d'), newImg = new Image(); newImg.src = img.src; canvas.height = newImg.height; canvas.width = newImg.width; ctx.drawImage(newImg, 0, 0); var src = newImg.src; var outputFormat = src.substring(src.lastIndexOf('.')+1); outputFormat = outputFormat.toLowerCase()=="jpg"? "jpeg" : outputFormat; var dataURL = canvas.toDataURL('image/' + outputFormat); // updateCacheMsgById($(img).attr('data-code'), "", "", "", dataURL); canvas = null; } /** * 获取消息 */ function getMsgs(page,sucHandle){ sendGet(msgListUrl,{ consult: consultInfo.id, page: page, pagesize: pageSize },null,function (res) { if (res.status === 200) { sucHandle.call(this,res); } else { mui.toast(res.msg); } }); } /** * 设置获取到的最后一条消息 */ function setLastMsg(msg){ if(!lastTimestamp || lastTimestamp>msg.timestamp){ lastTimestamp = msg.timestamp; lastSeq = msg.seq; lastId = msg.id.indexOf("loc")==0? lastId : msg.id; } } //毫秒转换成时分秒 function formatSeconds(value) { var theTime = parseInt(value/1000);// 秒 var theTime1 = 0;// 分 var theTime2 = 0;// 小时 if(theTime > 60) { theTime1 = parseInt(theTime/60); theTime = parseInt(theTime%60); if(theTime1 > 60) { theTime2 = parseInt(theTime1/60); theTime1 = parseInt(theTime1%60); } } var result = ""+parseInt(theTime);//秒 if(parseInt(theTime)<=9){ result = "0"+parseInt(theTime);//秒 } if(theTime1 > 0) {//分 if(parseInt(theTime1)>9){ result = ""+parseInt(theTime1)+":"+result; }else{ result = "0"+parseInt(theTime1)+":"+result; } } if(theTime2 > 0) {//小时 if(parseInt(theTime2)>9){ result = ""+parseInt(theTime2)+":"+result; }else{ result = "0"+parseInt(theTime2)+":"+result; } } var resResult = ""; if(result.split(":").length==1){//秒 resResult = "00:"+result; }else if(result.split(":").length==2){//分 resResult = "00:"+result; }else{//时 resResult = result; } return resResult; } /** * 定位聊天记录位置 * @param {Object} id */ function locationLog(id){ var $logdom = $('.chat-log[data-code="'+ id +'"]'); if($logdom.length){ myScroll.scrollToElement( $logdom[0], 0, 0, -20 ); plus.nativeUI.closeWaiting(); } else { getCacheMsgById(id, function(tx, data){ if(data.length>0){ getCacheMsg("", "", function(tx, ls){ showMsg(ls, false, true, false, true); }, data[0].timestamp, true ) } else { getLastCacheMsg(function(tx, msg){ var startmsg = msg.length>0? msg[msg.length-1] : undefined; getMsgs(1,function(ls){ if(ls.length>0 && (!firstMsg || (firstMsg.timestamp'+ sendErrDom +'
    ' // + yiduHtml // + '

    '+ msg.title +'

    ' // + '
    ' // + '
    '+ msg.content+'
    ' // + '
    ' // + '
    '; // return temp; // } // return ""; // } function matchUrl(content){ var a = urlRegex.exec(content); if(a){ var ah = ''+ a[0] +''; var str = ""; var s = content.split(a[0]); // var i = content.indexOf(a[0]); for(var i=0; i'; $(document.body).append(html); var video = $(document.body).find('video')[0]; video.play(); }else{//andriod var Intent = plus.android.importClass("android.content.Intent"); var Uri = plus.android.importClass("android.net.Uri"); var main = plus.android.runtimeMainActivity(); var intent=new Intent(Intent.ACTION_VIEW); var uri=Uri.parse(url); intent.setDataAndType(uri,"video/*"); main.startActivity(intent); } }); //点击健康教育文章连接 // .on('tap', '.word-article', function(){ // var type = $(this).attr('data-inner-type'); // var code = $(this).attr('data-code'); // if(type==1){ // mui.openWindow('../../jkjl/html/health-record.html', 'health-record', { // extras: { // patientCode: code, // qyRelation: 0 // } // }); // }else if(type == 2){ // mui.openWindow('../../hzzd/html/guidance_info.html', 'guidance_info', { // extras:{ // guideId: code // } // }) // } else{ // mui.openWindow("../../jkjy/html/article.html", "article", { // extras: { // article: code // } // }) // } // // }); //绑定挂号链接 $(document).on('tap', 'a', function(){ if($(this).attr("name") == "guahao"){ var id = $(this).attr("data-id"); mui.openWindow("../../wdyy/html/detail-appointment.html", "detail-appointment", { extras: { dataId: id } }) } }); $(document).on('tap','#xzzd',function(){ // 回复咨询 sendPost("/doctor/consult/readed", { consult:consultInfo.id }, function() { plus.nativeUI.closeWaiting() }, function() { plus.nativeUI.closeWaiting(); if(type == 8){ mui.openWindow('../../message/html/xufangzixun.html', 'xufangzixun.html', { extras: { sessionId: consultInfo.session_id, otherCode: otherCode, otherName: consultInfo.patientName, type: type // 解决type参数值与从“消息”页面进入时携带的值代表的意义不一致,导致了bug#3225 【医生端】健康咨询:首页健康咨询中进入im详情无法邀请全科/求助。 } }) }else{ mui.openWindow('../../message/html/p2dzixun.html', 'p2dzixun', { extras: { sessionId: consultInfo.session_id, otherCode: otherCode, otherName: consultInfo.patientName, type: (type == 1 || type == 2 )?1:type // 解决type参数值与从“消息”页面进入时携带的值代表的意义不一致,导致了bug#3225 【医生端】健康咨询:首页健康咨询中进入im详情无法邀请全科/求助。 } }) } }); }).on('tap','.tixys',function(){ //提醒医生 openWebview("../../message/html/p2p.html",{otherCode: qyDocInfo.doctor, otherName: qyDocInfo.name}); }); var player; var $playDom = false; function playRecord(path, dom){ var isPlayBenDi = path.indexOf('.amr')>=0; if($playDom){ if(player){ if(plus.os.name=="iOS" && !isPlayBenDi){//ios player.pause(); }else{ player.stop(); } $playDom.removeClass('active'); if($playDom.attr('data-code') == dom.attr('data-code')){ $playDom = false; return; } } } $playDom = dom; if(plus.os.name=="iOS" && !isPlayBenDi){//ios $(document.body).find('audio').remove(); var html = ''; $(document.body).append(html); player = $(document.body).find('audio')[0]; player.play(); player.addEventListener('ended', function () { $playDom.removeClass('active'); $playDom = false; }, false); }else{//andriod player = plus.audio.createPlayer(getImgUrl(path)); player.play(function() { $playDom.removeClass('active'); $playDom = false; }, function(e) { $playDom.removeClass('active'); $playDom = false; }); } } /** * 点击查看好友详细信息 */ $('#qun_detail').on("tap", function() { mui.openWindow('../../huanzhe/html/huanzhexinxi.html', 'huanzhexinxi.html', { extras: { patiCode: consultInfo.patient } }); }) //显示星级评价 $('.j-show-btn').on('tap',function(){ var $this = $(this); $('.j-show-btn').show(); $this.hide(); }) });