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 + '
'+ doctorName + '
'+ doctorName + '
'+ doctorName + '