var d = dialog({contentType:'load', skin:'bk-popup'}); var dd = dialog({contentType:'load', skin:'bk-popup', content:'发送中...'}); var userAgent = window.localStorage.getItem(agentName); var dialroll; var doctorInfo; var content = ""; var timeStr = ""; var id = 0; var pagesize = 10; var Request = new Object(); Request = GetRequest(); var consult = Request["consult"]; var status = Request["status"]; var docMsg = 0; $(function() { checkStatus(); //点击内容区域输入框失焦 $('#talkwrap').click(function(){ $("#chatTxtCon").blur(); dialroll.refresh(); dialroll.scrollTo(0, dialroll.maxScrollY); return false; }); //发送以后定位至最底部 $(".talk-send a").click(function() { send(); }); //从后台那边获取签名等信息 var params = {}; var url1 = ""; if(status == 0 || status == 1){ url1 = server + "wx/html/zxwz/html/consulting-doctor.html?status=" + status + "&consult=" + consult; }else{ url1 = server + "wx/html/zxwz/html/consulting-doctor.html?consult=" + consult; } params.pageUrl = url1; $.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({ appId: appId, // 必填,公众号的唯一标识 timestamp: t, // 必填,生成签名的时间戳 nonceStr: noncestr, // 必填,生成签名的随机串 signature: signature,// 必填,签名,见附录1 jsApiList: [ 'chooseImage', 'uploadImage' ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 }); } } }); }); //控制“发送”按钮的变化 function sendBtn() { var tval = $(".talk-input input").val(); if (tval != "") { $(".talk-send a").removeClass("disab"); } else { $(".talk-send a").addClass("disab"); } } //控制页面高度 function winSize(h) { var totH = $(window).height(); $("#talkwrap").height(totH - h); } //判断记录的状态 function checkStatus(){ d.show(); if(status == 0 || status == 1){ if(status == 0){ $("#divBottom").show(); $("#finish_list").show(); winSize(102); }else{ $("#divBottom").hide(); $("#finish_list").hide(); winSize(0); } //页面初始化查询 queryList(); var pulldownAction = function() { getPage(this); }; dialroll = iscrollAssist.newVerScrollForPull($('.pull-iscroll-wrap'), pulldownAction, null); dialroll.refresh(); dialroll.scrollTo(0, dialroll.maxScrollY); $(window).resize(function() { if(status == 0){ winSize(102); } else{ winSize(0); } }); }else{ var data = {}; data.consult = consult; sendPost('patient/consult/status', data, 'json', 'post', queryFailed, querySuccess); } } function queryFailed(res) { d.close(); if (res && res.msg) { dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show(); } else { dialog({contentType:'tipsbox', skin:'bk-popup' , content:'获取咨询记录状态失败'}).show(); } } function querySuccess(res) { if (res.status == 200) { if(res.data == 0){ $("#divBottom").show(); $("#finish_list").show(); winSize(102); }else{ $("#divBottom").hide(); $("#finish_list").hide(); winSize(0); } //聊天记录填充 queryList(); var pulldownAction = function() { getPage(this); }; dialroll = iscrollAssist.newVerScrollForPull($('.pull-iscroll-wrap'), pulldownAction, null); dialroll.refresh(); dialroll.scrollTo(0, dialroll.maxScrollY); $(window).resize(function() { if(res.data == 0){ winSize(102); } else{ winSize(0); } }); } else{ queryFailed(res); } } //页面初始化 function queryList(){ var data = {}; data.consult = consult; data.id = id; data.pagesize = pagesize; sendPost('patient/consult/loglist', data, 'json', 'post', queryFailed2, querySuccess2); } function queryFailed2(res) { d.close(); if (res && res.msg) { dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show(); } else { dialog({contentType:'tipsbox', skin:'bk-popup' , content:'加载失败'}).show(); } } function querySuccess2(res) { if (res.status == 200) { var list = res.list; if (list && list.length > 0) { id = list[list.length - 1].id; docMsg = list[list.length - 1].type; for (var j = list.length-1; j >=0; j--) { var reply = list[j]; //type为1时,医生发的 addReply(reply.type, reply.content, reply.time, reply.msgType, reply.doctorName); } dialroll.refresh(); dialroll.scrollTo(0, dialroll.maxScrollY); } d.close(); } else{ queryFailed2(res); } } //点击发送按钮 function send(){ content = $("#chatTxtCon").val().replace(/\s+/g,""); if (content && content != null && content != "") { var now = new Date(); timeStr = ""; if(now.getMonth()<9){ //补0 timeStr = now.getFullYear() + "-0"+ (now.getMonth()+1) + "-" +now.getDate() +' ' + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds(); }else{ timeStr = now.getFullYear() + "-"+ (now.getMonth()+1) + "-" +now.getDate() +' ' + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds(); } $("#chatTxtCon").blur(); dialroll.refresh(); dialroll.scrollTo(0, dialroll.maxScrollY); dd.showModal(); var data = {}; data.consult = consult; data.content = utf16toEntities(content); data.type = 1; sendPost('patient/consult/append', data, 'json', 'post', submitFailed, submitSuccess); } else { return; } } function submitFailed(res) { dd.close(); if (res && res.msg) { dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show(); } else { dialog({contentType:'tipsbox', skin:'bk-popup' , content:'发送失败'}).show(); } } function submitSuccess(res) { if (res.status == 200) { //置空 $("#chatTxtCon").val(""); $(".talk-send a").addClass("disab"); addReply(2, content, timeStr, 1, ""); dialroll.refresh(); dialroll.scrollTo(0, dialroll.maxScrollY); dd.close(); } else { submitFailed(res); } } //回复单条内容填写 var defaultPhoto = "../../../images/p-default.png"; var doctorDefaultPhoto = "../../../images/d-default.png"; function addReply(type, content, time, msgType, doctorName) { //time = time.substr(10); var doctorPhoto = doctorDefaultPhoto; var patientPhoto = defaultPhoto; var $div = $("
"); if (type == 1) { if(msgType == 2){ $div.addClass('talk-left'); $div.addClass('clearfix'); $div.html('

'+ doctorName + '

' +'' + time+'' +'
' +' ' +'
'); } else{ $div.addClass('talk-left'); $div.addClass('clearfix'); $div.html('

'+ doctorName + '

' +'' + time + '' +'
' +' '+content +'
'); } } else { if(msgType == 2){ $div.addClass('talk-right'); $div.addClass('clearfix'); $div.html('
' +''+time+'' +'
' +' ' +'
'); } else{ $div.addClass('talk-right'); $div.addClass('clearfix'); $div.html ('
' + '' + time + '' + '
' + content + '
'); } } $(".talk-box").append($div); } //向上拉取更多 function addReplyBefore(type, content, time, msgType, doctorName) { //time = time.substr(10); var doctorPhoto = doctorDefaultPhoto; var patientPhoto = defaultPhoto; var $div = $("
"); if (type == 1) { if(msgType == 2){ $div.addClass('talk-left'); $div.addClass('clearfix'); $div.html('

'+ doctorName + '

' +'' + time+'' +'
' +' ' +'
'); } else{ $div.addClass('talk-left'); $div.addClass('clearfix'); $div.html('

'+ doctorName + '

' +'' + time+'' +'
' +' '+content +'
'); } } else { if(msgType == 2){ $div.addClass('talk-right'); $div.addClass('clearfix'); $div.html('
' +''+time+'' +'
' +' ' +'
'); } else{ $div.addClass('talk-right'); $div.addClass('clearfix'); $div.html ('
' + '' + time + '' + '
' + content + '
'); } } $(".talk-box").prepend($div); } //页面初始化 function getPage(t){ var data = {}; data.consult = consult; data.id = id; data.pagesize = pagesize; $.ajax(server + "patient/consult/loglist", { data: data, type: 'POST', dataType: 'json', beforeSend: function(request) { request.setRequestHeader("userAgent", userAgent); }, error: function(res) { if(res.status == 999 || res.status == 998 || res.status == 997){ loginUrl(res.status); return; } dialog({contentType:'tipsbox', skin:'bk-popup' , content:"加载失败"}).show(); }, success: function(res) { if(res.status == 999 || res.status == 998 || res.status == 997){ loginUrl(res.status); } else if (res.status == 200) { var list = res.list; if (list && list.length > 0) { id = list[list.length - 1].id; for (var j = 0; j < list.length; j++) { var reply = list[j]; //type为1时,医生发的 addReplyBefore(reply.type, reply.content, reply.time, reply.msgType, reply.doctorName); } } t.refresh(); } else { dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show(); } } }); } //结束咨询 function finish(){ dialog({ title:'提示', content:'您确定结束这次咨询之旅了吗?', ok: function (){ var params = {} params.code = consult; //发送ajax请求, 查询设备列表信息 sendPost("patient/consult/finish", params, "json", "post", submitFailed3,finish_Successs); function finish_Successs(res){ if (res.status == 200) { window.history.go(-1); //window.location.href = "teachers-consulting-list.html"; } else{ submitFailed3(res); } } }, cancel: function () { return; } }).showModal(); } function submitFailed3(res) { if (res && res.msg) { dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show(); } else { dialog({contentType:'tipsbox', skin:'bk-popup' , content:'操作失败'}).show(); } } //查看图片 function viewImg(dom) { var $img = $(dom); var thissrc = $img.attr("src"); var mWid = $(window).width(); var mHei = $(window).height(); var nHtml = '
'; $("body").append(nHtml); $(".delimgpop").click(function() { $(this).remove() }); } //微信上传图片 var serverId = ""; var images = []; function chooseImage(){ wx.chooseImage({ count: 3, success: function (res) { for (var i in res.localIds) { images.push(res.localIds[i]); } dd.showModal(); uploadImage(); } }); } function uploadImage(){ if (images.length == 0) { dd.close(); return; } var i = 0, length = images.length; serverId = ""; var faillength = 0 ; function upload() { wx.uploadImage({ localId: images[i], isShowProgressTips: 0, success: function (res) { faillength= 0; dd.close(); i++; if(serverId.length == 0){ serverId = res.serverId; } else{ serverId =serverId + "," + res.serverId; } if (i < length) { upload(); } if(i == images.length){ sendImages(); } }, fail: function (res) { dd.close(); faillength+=1; if(faillength<=5){ //失败从传 upload(); }else{ alert(JSON.stringify(res)); } } }); } upload(); } //保存图片 function sendImages(){ var now = new Date(); timeStr = ""; if(now.getMonth()<9){ //补0 timeStr = now.getFullYear() + "-0"+ (now.getMonth()+1) + "-" +now.getDate() +' ' + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds(); }else{ timeStr = now.getFullYear() + "-"+ (now.getMonth()+1) + "-" +now.getDate() +' ' + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds(); } var data = {}; data.consult = consult; data.content = ""; data.mediaIds = serverId; data.type = 2; sendPost('patient/consult/append', data, 'json', 'post', submitFailed, submitImageSuccess); } function submitImageSuccess(res) { if (res.status == 200) { dd.close(); var imageList = res.data.split(','); for(var i=0; i < imageList.length; i++){ addReply(2, imageList[i], timeStr, 2, ""); } dialroll.refresh(); dialroll.scrollTo(0, dialroll.maxScrollY); } else { submitFailed(res); } }