123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506 |
- 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 = $("<div></div>");
- if (type == 1) {
- if(msgType == 2){
- $div.addClass('talk-left');
- $div.addClass('clearfix');
- $div.html('<div class="leftpart"><img src="'+doctorPhoto+'" /><p style="font-size: 13px; text-align: center;">'+ doctorName + '</p></div> '
- +'<span class="talktime" style="width: 100%; left: 70px; top:-10px;">' + time+'</span>'
- +'<div class="rightpart">'
- +' <s class="rightjt jt-left"><s></s></s><img style="height: 150px; width: 100px;" src="'+getImgUrl(content)+'" onclick="viewImg(this)"/>'
- +'</div>');
- }
- else{
- $div.addClass('talk-left');
- $div.addClass('clearfix');
- $div.html('<div class="leftpart"><img src="'+doctorPhoto+'" /><p style="font-size: 13px; text-align: center;">'+ doctorName + '</p></div> '
- +'<span class="talktime" style="width: 100%; left: 70px; top:-10px;">' + time + '</span>'
- +'<div class="rightpart">'
- +' <s class="rightjt jt-left"><s></s></s>'+content
- +'</div>');
- }
-
- } else {
- if(msgType == 2){
- $div.addClass('talk-right');
- $div.addClass('clearfix');
- $div.html('<div class="leftpart"><img src="'+patientPhoto+'" /></div> '
- +'<span class="talktime" style="width: 100%; position:absolute; right:-45%; top:-10px; float: right;">'+time+'</span>'
- +'<div class="rightpart">'
- +' <img style="height: 150px; width: 100px;" src="'+getImgUrl(content)+'" onclick="viewImg(this)"/>'
- +'</div>');
- }
- else{
- $div.addClass('talk-right');
- $div.addClass('clearfix');
- $div.html ('<div class="leftpart"><img src="' + patientPhoto + '" /></div>'
- + '<span class="talktime" style="width: 100%; position:absolute; right:-45%; top:-10px; float: right;">' + time + '</span>'
- + '<div class="rightpart">' + content + '</div>');
- }
- }
- $(".talk-box").append($div);
- }
- //向上拉取更多
- function addReplyBefore(type, content, time, msgType, doctorName) {
- //time = time.substr(10);
- var doctorPhoto = doctorDefaultPhoto;
- var patientPhoto = defaultPhoto;
- var $div = $("<div></div>");
- if (type == 1) {
- if(msgType == 2){
- $div.addClass('talk-left');
- $div.addClass('clearfix');
- $div.html('<div class="leftpart"><img src="'+doctorPhoto+'" /><p style="font-size: 13px; text-align: center;">'+ doctorName + '</p></div> '
- +'<span class="talktime" style="width: 100%; left: 70px; top:-10px;">' + time+'</span>'
- +'<div class="rightpart">'
- +' <s class="rightjt jt-left"><s></s></s><img style="height: 150px; width: 100px;" src="'+content+'" onclick="viewImg(this)"/>'
- +'</div>');
- }
- else{
- $div.addClass('talk-left');
- $div.addClass('clearfix');
- $div.html('<div class="leftpart"><img src="'+doctorPhoto+'" /><p style="font-size: 13px; text-align: center;">'+ doctorName + '</p></div> '
- +'<span class="talktime" style="width: 100%; left: 70px; top:-10px;">' + time+'</span>'
- +'<div class="rightpart">'
- +' <s class="rightjt jt-left"><s></s></s>'+content
- +'</div>');
- }
-
- } else {
- if(msgType == 2){
- $div.addClass('talk-right');
- $div.addClass('clearfix');
- $div.html('<div class="leftpart"><img src="'+patientPhoto+'" /></div> '
- +'<span class="talktime" style="width: 100%; position:absolute; right:-45%; top:-10px; float: right;">'+time+'</span>'
- +'<div class="rightpart">'
- +' <img style="height: 150px; width: 100px;" src="'+getImgUrl(content)+'" onclick="viewImg(this)"/>'
- +'</div>');
- }
- else{
- $div.addClass('talk-right');
- $div.addClass('clearfix');
- $div.html ('<div class="leftpart"><img src="' + patientPhoto + '" /></div>'
- + '<span class="talktime" style="width: 100%; position:absolute; right:-45%; top:-10px; float: right;">' + time + '</span>'
- + '<div class="rightpart">' + content + '</div>');
- }
- }
- $(".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 = '<div class="delimgpop"><div class="del-img-box"><div class="del-img-con"><img class="del-pop-img" src="' + thissrc + '" style="max-width:' + mWid + 'px; max-height:' + mHei + 'px;"></div></div></div>';
- $("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);
- }
- }
|