123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323 |
- var d = dialog({contentType:'load', skin:'bk-popup'});
- var dd = dialog({contentType:'load', skin:'bk-popup', content:'发送中...'});
- var dialroll;
- var doctorInfo;
- var content = "";
- var timeStr = "";
- var id = 1;
- var pagesize = 500;
- var Request = new Object();
- Request = GetRequest();
- var consult = Request["consult"];
- var status = Request["status"];
- var doctorType = Request["type"];
- var doctor = Request['doctor'];
- var toUser = Request["toUser"];
- var toName = decodeURIComponent(Request["toName"]);
- var openid = Request["openid"];
- var represented = Request["represented"];
- //var evaluate = localStorage.getItem("evaluate");//1为有评价 0为无评价
- var evaluate = 0;
- var docMsg = 0;
- var patientcode = "";
- var pagetype=24;
- var networkStatus = "";
- var userAgent = window.localStorage.getItem(agentName);
- var userInfo = '',
- patientName = "";
- $(function(){
- checkUserAgent();
- })
- function queryInit() {
-
- userInfo = JSON.parse(window.localStorage.getItem(agentName))
- patientcode = userInfo.represented?userInfo.represented:userInfo.uid;
-
- var userAgent1 = JSON.parse(window.localStorage.getItem(agentName1));
- patientName = userAgent1.name;
-
- getWeixinSign();
- // initFamilyData();
- bindEvents();
- checkStatus();
-
- //点击内容区域输入框失焦
- $('#talkwrap').click(function(){
- $("#input_content").blur();
- return false;
- });
- //发送以后定位至最底部
- $("#reply a").click(function() {
- send();
- });
-
- }
- //判断关系
- function hasFamilyRelation(a,b){
- return new Promise(function(resolve, reject) {
- var data={
- patient:a,
- familyMember:b
- }
- sendPost("patient/family/is_authorize", data, "json", "get", function(res){
- dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求家庭成员关系失败'}).show();
- }, function(res){
- if(res.status == 200) {
- window.localStorage.setItem('nowPatientName',res.data.name);
- resolve(res)
- }else if(res.status == 100) {
- dialog({
- content:'对不起,'+res.data.name+'未授权给您,如需查看,请切换'+res.data.name+'账号登录',
- okValue:'切换账号',
- ok: function() {
- window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))
- window.location.href = "../../grzx/html/change-login.html?type=0&openid="+ Request["openid"];
- },
- cancelValue: '我不看了',
- cancel: function () {
- wx.closeWindow();
- }
- }).showModal();
- }else{
- relogin();
- }
-
- })
- })
- }
- //重新登录操作
- function relogin(){
- dialog({
- content:'对不起,该消息是发给'+toName+',如需查看,请切换'+toName+'账号登录',
- okValue:'切换账号',
- ok: function() {
- window.localStorage.setItem(pageName, JSON.stringify({pageurl: location.href}))
- window.location.href = "../../grzx/html/change-login.html?type=0&openid="+ Request["openid"];
- },
- cancelValue: '我不看了',
- cancel: function () {
- wx.closeWindow();
- }
- }).showModal();
- }
- //保存信息
- function saveUserInfo(a,b){
- Promise.all([hasFamilyRelation(a,b)]).then(function () {
- userInfo.represented = represented;
- window.localStorage.setItem(agentName,JSON.stringify(userInfo));
- userInfo = JSON.parse(window.localStorage.getItem(agentName));
- bindEvents();
- checkStatus();
- })
- }
- function initFamilyData () {
- //从微信模板消息进入
- if(represented && userAgent && toUser){
- if(toUser == represented){
- saveUserInfo(represented,userInfo.uid)
- }else if(toUser != represented && represented == userInfo.uid){
- //本人代理
- saveUserInfo(represented,newUaObj.uid)
- }else if(toUser != represented && toUser == userInfo.uid){
- //需要判定关系 200有授权 100家人 1无关系
- saveUserInfo(represented, userInfo.uid)
- }else{
- //重新登录
- relogin();
- }
- }else{
- userInfo = JSON.parse(window.localStorage.getItem(agentName));
- bindEvents();
- checkStatus();
- }
- }
- function getTopic(){
- //获取sessionId
- sendPost('/patient/consult/getTopic', {consult:consult}, 'json', 'GET', queryFailed2, function(res){
- if(res.status==200){
- var sessionId = JSON.parse(res.msg)[0].session_id;
- //加载socket组件
- /*jQuery.getScript(imurl+"/socket.io/socket.io.js").done(function() {
- var socket = io.connect(imurl);
- socket.emit('login', {userId: userInfo.represented?userInfo.represented:userInfo.uid, password: userInfo.represented?userInfo.represented:userInfo.uid,sessionId:sessionId,clientType:"patient"});
- socket.on('message', function (data) {
- // console.log(data)
- if((data.type == 1) ||(data.type == 2) || (data.type == 6) || (data.type == 12)){
- addReply(1, data.content, new Date(data.timestamp).Format('yyyy-MM-dd HH:mm:ss'), data.type, data.name,data.sender_img);
- setTimeout(function(){
- dialroll.refresh();
- dialroll.scrollTo(0, dialroll.maxScrollY);
- },300)
- }
- });
-
- socket.on('error', function (data) {
- // console.log(data);
- });
-
- socket.on('ack', function (data) {
- // console.log(data);
- });
- function getLocalTime(nS) {
- return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ');
- }
- })
- .fail(function() {
- dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:"医生实时对话连接失败!"}).show();
- });*/
-
- }
- });
- }
- //控制“发送”按钮的变化
- 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 getDoctorWork(){
- if(doctorType=="6") {
- checkDoctorInWork(doctor);
- } else {
- sendPost('patient/sign_doctors', {patientCode:patientcode}, 'json', 'post', queryFailed, function(res){
- if(res.status==200){
- var doctorArray = res.familyDoctors;//家庭
- if(doctorType==1){//三师
- doctorArray = res.teamDoctors
- }
- if(doctorArray){
- var doctorInfo ="";
- for(var j in doctorArray){
- if(doctorArray[j].level=="3"){
- doctorInfo = doctorArray[j];//取出健康管理师
- break;
- }
- }
- if(doctorInfo!=""){
- checkDoctorInWork(doctorInfo.code);
- }
- }
- }else{
- queryFailed(res);
- }
- })
- }
-
- }
- function checkDoctorInWork(doctor){
- sendPost('patient/consult/is_doctor_working', {doctor:doctor}, 'json', 'post', queryFailed, function(res){
- if(res.status==200){
- if(res.data!=1){
- addReply(7, "医生不在工作时间,无法及时回复您的消息。<br/><a class='workhours' href='#'>查看工作时间!</a>", getNowFormatDate(),1, "系统消息");
-
- $(".workhours").on("click",function(){
- location.href='doctor-work-hours.html?doctor='+doctor;
- });
-
- setTimeout(function(){
- dialroll.refresh();
- dialroll.scrollTo(0, dialroll.maxScrollY);
- },20);
- }
- }else{
- queryFailed(res);
- }
- });
- }
- //判断记录的状态
- 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', 'get', queryFailed, querySuccess);
- }
- }
- function queryFailed(res) {
- d.close();
- if (res && res.msg) {
- dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:res.msg}).show();
- } else {
- dialog({contentType:'tipsbox', skin:'bk-popup' , bottom:true,content:'获取咨询记录状态失败'}).show();
- }
- }
- function querySuccess(res) {
- if (res.status == 200) {
- if(res.data == 0){
- //未结束的咨询跳转去咨询页面
- // window.location.href = "../../qygl/html/sign_info.html?doctor="+doctor+"&consult="+consult;
- var url = "../../qygl/html/sign_info.html?doctor="+doctor+"&consult="+consult;
- window.location.replace(url);
- }else{
- $("#divBottom").hide();
- $("#finish_list").hide();
- $("#input_div").hide();
- winSize(0);
- //新增评价状态 1、已评价 0、未评价
- var data = {};
- data.consult = consult;
- sendPost('patient/consult/evaluateStatus', data, 'json', 'get', queryFailed, function(res){
- if (res.status == 200) {
- evaluate = res.data;
- //显示评价按钮
- if(evaluate == 0){
- $('#valFoot').show();
- $('#noval').show();
- $('#hasval').hide();
- }else if(evaluate == 1){
- $('#valFoot').show();
- $('#noval').hide();
- $('#hasval').show();
- }
- }else{
- queryFailed(res);
- }
- });
-
- }
- status = res.data;
- //聊天记录填充
- 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);
- }
- });
- d.close();
- }
- else{
- queryFailed(res);
- }
- }
- //页面初始化
- function queryList(){
- var data = {};
- data.consult = consult;
- data.page = id;
- data.pagesize = pagesize;
- sendPost('patient/consult/loglist', data, 'json', 'GET', queryFailed2, querySuccess2);
- }
- function queryMsg(logId,msgType){
- var data={};
- data.consult = consult;
- data.logId = logId;
- data.msgType=msgType;
- sendPost('patient/consult/oneLog', data, 'json', 'GET', queryFailed2, function(res){
- if(res.status==200){
- var reply = res.consult;
- if((reply.msgType == 1) || (reply.msgType == 2) || (reply.msgType == 6)){
- addReply(reply.type, reply.content, reply.time, reply.msgType, reply.doctorName, reply.photo);
- setTimeout(function(){
- dialroll.refresh();
- dialroll.scrollTo(0, dialroll.maxScrollY);
- },300)
- }
-
- }
- d.close();
- });
-
-
- }
- function queryFailed2(res) {
- d.close();
- if (res && res.msg) {
- dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:res.msg}).show();
- } else {
- dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:'加载失败'}).show();
- }
- }
- function querySuccess2(res) {
- if (res.status == 200) {
- id++;
- res = res.list;
- var doctorPar = [];//储存参与咨询的医生
- for(var k in res.users){
- if(res.users[k].is_patient == 0 && res.users[k].id==doctor){
- doctorPar.push(res.users[k])
- }else if(res.users[k].is_patient == 0 && res.users[k].id!=doctor){
- doctorPar.unshift(res.users[k])
- }
- }
- doctorPar=JSON.stringify(doctorPar)
- window.localStorage.setItem('doctorPar',doctorPar);
-
- var list = res.list;
- if (list && list.length > 0) {
- docMsg = list[list.length - 1].content_type;
- var doctor = "";
- for (var j = list.length-1; j >=0; j--) {
- var reply = JSON.parse(list[j]);
- //type为1时,医生发的
- if((reply.content_type == 3) || (reply.content_type == 1) || (reply.content_type == 2) || (reply.content_type == 6) || (reply.content_type == 12)){
- var date = new Date();
- date.setTime(reply.timestamp);
- var time = date.format('yyyy-MM-dd hh:mm:ss');
- var p;
-
- for(var k in res.users){
- if(res.users[k].id==reply.sender_id){
- p = res.users[k].avatar;
- }
- }
- addReply(reply.sender_id==patientcode? 2 : 1, reply.content, time, reply.content_type, reply.sender_name, p);
- }
- }
- if(status==0){
- getDoctorWork();
- }
- dialroll.refresh();
- dialroll.scrollTo(0, dialroll.maxScrollY);
- }
- d.close();
- }
- else{
- queryFailed2(res);
- }
- }
- function getNowFormatDate() {
- var date = new Date();
- var seperator1 = "-";
- var seperator2 = ":";
- var month = date.getMonth() + 1;
- var strDate = date.getDate();
- if (month >= 1 && month <= 9) {
- month = "0" + month;
- }
- if (strDate >= 0 && strDate <= 9) {
- strDate = "0" + strDate;
- }
- var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
- + " " + date.getHours() + seperator2 + date.getMinutes()
- + seperator2 + date.getSeconds();
- return currentdate;
- }
- //点击发送按钮
- function send(){
- content = $("#input_content").text().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();
- }
- $("#input_content").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' ,bottom:true, content:res.msg}).show();
- } else {
- dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:'发送失败'}).show();
- }
- }
- function submitSuccess(res) {
- if (res.status == 200) {
- //置空
- $("#input_content").text("");
- $(".talk-send a").addClass("disab");
- addReply(2, content, timeStr, 1, "");
- dialroll.refresh();
- dialroll.scrollTo(0, dialroll.maxScrollY);
- showSendBtn(false);
- dd.close();
- } else {
- submitFailed(res);
- }
- }
- //回复单条内容填写
- var defaultPhoto = "../../../images/p-default.png";
- var doctorDefaultPhoto = "../../../images/d-default.png";
- function addReply(type, content, time, msgType, doctorName,photo,prepend) {
- //time = time.substr(10);
- var doctorPhoto = photo ? getImgUrl(photo) : doctorDefaultPhoto;
- var $div = $("<dl></dl>");
-
- if(type == 7){
- if(prepend){
- $(".talk-box").prepend('<div class="time-tips"><span class="xt-xiaoxi">' + content + '</span></div>');
- } else
- $(".talk-box").append('<div class="time-tips"><span class="xt-xiaoxi">' + content + '</span></div>');
- return;
- }
-
- if (type == 1) {
- $div.addClass('chat-left');
- img = doctorPhoto;
- name = doctorName;
- } else {
- $div.addClass('chat-right');
- img = photo?getImgUrl(photo):defaultPhoto;
- defaultPhoto = img;
- name = patientName;
- }
-
- var temp = '<dt style="height: auto; text-align: center;"><a><img src="' + img + '" class="c-images-cycle" /></a></dt>' +
- '<div class="c-content"><span class="c-f12 name">' + name + '</span>'
-
- switch(parseInt(msgType)) {
- case 1://信息
- case 6://咨询问题
- temp += '<dd class="word-bread"><span>' + content + '</span>';
- //医生回复的内容底部加上“仅供参考”的字样
- if(type == 1){
- temp += '<div class="c-t-right c-909090 c-f12" style="min-width: 80px;">仅供参考</div></dd></dl>';
- }else{
- temp += '</dd></dl>';
- }
- break;
- case 2://图片
- temp += '<dd class="word-bread wb-img"><img width="100" height="100" src="'+ getImgUrl(content) +'" />';
- //医生回复的内容底部加上“仅供参考”的字样
- if(type == 1){
- temp += '<div class="c-t-right c-909090 c-f12" style="min-width: 80px;">仅供参考</div></dd></dl>';
- }else{
- temp += '</dd></dl>';
- }
- break;
- case 3://语音
- var rec = JSON.parse(content);
- temp += "<div class='c-msg'><dd class='word-bread audio' data-type='3' data-audio='" + getImgUrl(content) + "'>"+
- "<div class='soundWav'>" +
- "<span class='soundWavT'>"+(rec? rec.times: "") +"\'\'</span>"+
- "</div>";
- //医生回复的内容底部加上“仅供参考”的字样
- if(type == 1){
- temp += '<div class="c-t-right c-909090 c-f12" style="min-width: 80px;">仅供参考</div></dd></dl>';
- }else{
- temp += '</dd></dl>';
- }
- break;
- case 12://视频
- var videoInfo = content.split(",");
- var shichang = formatSeconds(videoInfo[2]);//时长
- if(type == 1){
- temp += '<dd class="preview-video" data-video="'+getImgUrl(videoInfo[1])+'">'+
- '<img class="video-img-left" src="'+getImgUrl(videoInfo[0])+'">'+
- '<img class="bofang-icon-left" src="../images/bofang_icon.png">'+
- '<img class="jianjiao-icon-left" src="../images/zuoshanjiao_bg.png">'+
- '<span class="shichang-time-left">'+shichang+'</span>'+
- '<div class="c-t-right c-909090 c-f12" style="min-width: 80px;">仅供参考</div>'+
- '</dd>';
- }else{
- temp += '<dd class="preview-video" data-video="'+getImgUrl(videoInfo[1])+'">'+
- '<img class="video-img-right" src="'+getImgUrl(videoInfo[0])+'">'+
- '<img class="bofang-icon-right" src="../images/bofang_icon.png">'+
- '<img class="jianjiao-icon-right" src="../images/youshanjiao_bg.png">'+
- '<span class="shichang-time-right">'+shichang+'</span>'+
- '</dd>';
- }
-
- break;
- }
-
- if(prepend){
- $(".talk-box").prepend($div.append(temp)).prepend('<div class="time-tips"><span>' + time + '</span></div>');
- } else
- $(".talk-box").append('<div class="time-tips"><span>' + time + '</span></div>').append($div.append(temp));
-
- if(type != null && type != 1) {
- $(".tw-add-detail").hide(200);
- }
- }
- //毫秒转换成时分秒
- 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;
- }
- //向上拉取更多
- 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;max-width: 40px;">'+ 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;max-width: 40px;">'+ 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){
- // $(".talk-box").html("");
- var data = {};
- data.consult = consult;
- data.page = 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' ,bottom:true, content:"加载失败"}).show();
- },
- success: function(res) {
- if(res.status == 999 || res.status == 998 || res.status == 997){
- loginUrl(res.status);
- }
- else if (res.status == 200) {
- id++;
- 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时,医生发的
- if((reply.msgType == 1)|| (reply.msgType == 3) || (reply.msgType == 2) || (reply.msgType == 6)){
- addReply(reply.type, reply.content, reply.time, reply.msgType, reply.doctorName, reply.photo, true);
- }
- }
- }
- t.refresh();
- } else {
- dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:res.msg}).show();
- }
- }
- });
- }
- //结束咨询
- function finish(){
- dialog({
- content:'是否确认结束该次咨询?结束后医生将无法回复',
- ok: function (){
- d.show();
- var params = {}
- params.code = consult;
- //发送ajax请求, 查询设备列表信息
- sendPost("patient/consult/finish", params, "json", "post", submitFailed3,finish_Successs);
- function finish_Successs(res){
- if (res.status == 200) {
- d.close();
- location.reload();
- // window.location.href = "doctor-consultation.html";
- }
- else{
- submitFailed3(res);
- }
- }
- },
- cancel: function () {
- return;
- }
- }).showModal();
- }
- function submitFailed3(res) {
- if (res && res.msg) {
- dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:res.msg}).show();
- } else {
- dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, 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 chooseImageWx(){
- 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{
- dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:"图片上传失败,请控制发送频率"}).show();
- }
- }
- });
- }
- 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;
- data.times = 0;
- sendPost('patient/consult/append', data, 'json', 'post', submitFailed, submitImageSuccess);
- }
- function submitImageSuccess(res) {
- if (res.status == 200) {
- var data= JSON.parse(res.data)
- dd.close();
- addReply(2, data.content, timeStr, 2, "");
- dialroll.refresh();
- dialroll.scrollTo(0, dialroll.maxScrollY);
- } else {
- submitFailed(res);
- }
- }
- var aud = document.getElementById('audio');
- var $playingDom;
- function playSoundEnd(){
- $playingDom.removeClass('active');
- $playingDom = null;
- }
- function playError(){
- var src = $('#audio').attr('src');
- if(!$.trim(src)) {
- return ;
- }
- dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:"播放语音失败"}).show();
- $playingDom.removeClass('active');
- $playingDom = null;
- }
- $('.talk-box').on('click', '.word-bread img', function(){
- if(!$(this).closest(".word-bread").hasClass("preview-video")){
- var urls = [];
- $.each($('.word-bread img'), function(i, v) {
- urls.push($(v).attr('src'));
- });
- wx.previewImage({
- current: $(this).attr('src'), // 当前显示图片的http链接
- urls: urls // 需要预览的图片http链接列表
- });
- }
- })
- .on('touchstart', '.audio', function(){
- if($playingDom){
- aud.pause();
- //aud.stop();
- $playingDom.removeClass('active');
- if($playingDom[0] == this){
- $playingDom = null;
- return;
- }
- }
- $playingDom = $(this);
- $playingDom.addClass('active');
- var ser = JSON.parse($(this).attr('data-audio'));
- aud.src = getImgUrl(ser.path);
- aud.load();
- aud.play();
- })
- .on('click','.preview-video',function() {
- $(document.body).find('video').remove();
- var url = $(this).attr('data-video');
- var html = '<video style="display: none;" controls preload="auto" width="1" height="1" src="'+url+'" ></video>';
- $(document.body).append(html);
- var video = $(document.body).find('video')[0];
- video.play();
- });
- var valLen = 0;
- var $ipt_content = $('#input_content');
- function showSendBtn(isShow){
- if(isShow){
- $('.tw-add').hide();
- $('#reply').fadeIn('fast', 'swing');
- } else if(valLen == 1 || isShow==false){
- $('#reply').fadeOut('fast', 'swing', function(){
- $('.tw-add').show();
- });
- }
- valLen = isShow ? isShow.length : 0;
- }
- /**
- * 显示发送按钮的事件
- */
- $ipt_content.on('input', function(e){
- showSendBtn($(this).text())
- })
- .on('tap', function(){
- $(".tw-add-detail").hide();
- $ipt_content.focus();
- })
- /*
- * 附加功能
- */
- $(".tw-add").click(function() {
- $(".tw-add-detail").toggle(200);
- });
- $('body')
- //隐藏打开的附加功能
- .on('tap', '#talkwrap', function(){
- $('.tw-add-detail').hide();
- $ipt_content.blur();
- })
- $(".yy-add").click(function() {
- if($('#msg-sound:visible').length){
- $ipt_content.show();
- ui.boxMsgSound.style.display = 'none';
- $(this).find('img:eq(0)').show().next().hide();
- } else {
- $ipt_content.hide();
- ui.boxMsgSound.style.display = 'block';
- $(this).find('img:eq(0)').hide().next().show();
- }
- });
- mui.init({
- gestureConfig:{
- hold:true,//默认为false,不监听
- release:true//默认为false,不监听
- }
- });
- var recordCancel = false;
- var recorder = null;
- var audio_tips = document.getElementById("audio_tips");
- var startTimestamp = null;
- var stopTimestamp = null;
- var stopTimer = null;
- var MIN_SOUND_TIME = 500;
- var ui = {
- body: document.querySelector('body'),
- btnMsgType: document.querySelector('#msg-type'),
- boxMsgText: document.querySelector('#msg-text'),
- boxMsgSound: document.querySelector('#msg-sound'),
- btnMsgImage: document.querySelector('#msg-image'),
- areaMsgList: document.querySelector('#msg-list'),
- boxSoundAlert: document.querySelector('#sound-alert')
- };
- var recordTimer = null;
- var realStartTime = 0;
- ui.boxMsgSound.addEventListener("touchstart", function(e) {
- e.preventDefault();
- event.preventDefault();
- $(this).addClass('yy-hold');
- if(stopTimer)clearTimeout(stopTimer);
- recordCancel = false;
- audio_tips.innerHTML = "手指上划,取消发送";
- ui.boxSoundAlert.classList.remove('rprogress-sigh');
- setSoundAlertVisable(true);
- startTimestamp = new Date().getTime();
- recordTimer = setTimeout(function(){
- wx.startRecord({
- success: function(){
- realStartTime = new Date().getTime();
- },
- fail: recordErr
- });
- wx.onVoiceRecordEnd({
- // 录音时间超过一分钟没有停止的时候会执行 complete 回调
- complete: function (res) {
- serverId = res.localId;
- sendSounds(60);
- },
- fail: recordErr
- });
- },MIN_SOUND_TIME);
- }, false);
- ui.boxMsgSound.addEventListener("touchend", function(e){
- e.preventDefault();
- event.preventDefault();
- $(this).removeClass('yy-hold');
- if (audio_tips.classList.contains("cancel")) {
- audio_tips.classList.remove("cancel");
- audio_tips.innerHTML = "手指上划,取消发送";
- }
- var endTimestamp = new Date().getTime();
-
- var times = endTimestamp - startTimestamp;
- var realTimes = endTimestamp - realStartTime;
- if(times < MIN_SOUND_TIME || realTimes < MIN_SOUND_TIME){
- audio_tips.innerHTML = "录音时间太短";
- ui.boxSoundAlert.classList.add('rprogress-sigh');
- recordCancel = true;
- stopTimer=setTimeout(function(){
- setSoundAlertVisable(false);
- },500);
- startTimestamp = 0;
- realStartTime = 0;
- //小于300ms,不录音
- clearTimeout(recordTimer);
- wx.stopRecord({
- success: function (res) {
- },
- fail: function(){}
- });
- }else{
- setSoundAlertVisable(false);
- wx.stopRecord({
- success: function (res) {
- if(!recordCancel) {
- serverId = res.localId;
- sendSounds(Math.round(times/1000));
- }
- },
- fail: recordErr
- });
- }
- }, false)
-
- ui.body.addEventListener('drag', function(event) {
- if (Math.abs(event.detail.deltaY) > 50) {
- if (!recordCancel) {
- recordCancel = true;
- if (!audio_tips.classList.contains("cancel")) {
- audio_tips.classList.add("cancel");
- }
- audio_tips.innerHTML = "松开手指,取消发送";
- }
- } else {
- if (recordCancel) {
- recordCancel = false;
- if (audio_tips.classList.contains("cancel")) {
- audio_tips.classList.remove("cancel");
- }
- audio_tips.innerHTML = "手指上划,取消发送";
- }
- }
- }, false);
- var setSoundAlertVisable=function(show){
- if(show){
- ui.boxSoundAlert.style.display = 'block';
- ui.boxSoundAlert.style.opacity = 1;
- }else{
- ui.boxSoundAlert.style.opacity = 0;
- //fadeOut 完成再真正隐藏
- setTimeout(function(){
- ui.boxSoundAlert.style.display = 'none';
- },200);
- }
- };
- function recordErr(res){
- if(res && res.errMsg == "stopRecord:tooshort") {
- audio_tips.innerHTML = "录音时间太短";
- ui.boxSoundAlert.classList.add('rprogress-sigh');
- recordCancel = true;
- stopTimer=setTimeout(function(){
- setSoundAlertVisable(false);
- },500);
- startTimestamp = 0;
- //小于300ms,不录音
- if(recordTimer)clearTimeout(recordTimer);
- return;
- }
- if(!recordCancel){
- dialog({
- content:'录音失败,请重试',
- okValue:'我知道了',
- ok: function() {}
- }).showModal();
- }
- }
- //保存图片
- function sendSounds(times){
- 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.type = 3;
- data.times = times;
- wx.uploadVoice({
- localId: serverId,
- success: function (res) {
- data.voices = res.serverId;
- sendPost('patient/consult/append', data, 'json', 'post', submitFailed,
- function submitSoundSuccess(res) {
- if (res.status == 200) {
- dd.close();
- var data = JSON.parse(res.data[0]);
- addReply(2, data.content, timeStr, 3, "");
- dialroll.refresh();
- dialroll.scrollTo(0, dialroll.maxScrollY);
- } else {
- submitFailed(res);
- }
- });
- }
- });
- }
- function bindEvents(){
- //录制视频
- /*$(".lz-video-img").click(function(){
- $("#upload_input").click();
- //dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请录制10秒左右的短视频,以防录制完成后无法发送'}).show();
- return false;
- })*/
-
- //立即发送
- $("#lijifasong").on("tap", function(){
- uploadVideo();
- mui('#sheet1').popover('toggle');
- return false;
- });
- //不再提醒
- $("#buzaitixing").on("tap", function(){
- window.localStorage.setItem("isTiXingVideoFaSong","1");
- uploadVideo();
- mui('#sheet1').popover('toggle');
- return false;
- });
- // window.localStorage.removeItem("isTiXingVideoFaSong");//测试
- //点击评价
- $('body').on('tap','#noval',function(){
- window.location.href = "manyidu.html?consult=" +consult;
- })
- $('body').on('tap','#hasval',function(){
- window.location.href = "manyidu.html?consult=" +consult;
- })
- }
- //录制视频回调
- function videoFileChange(target) {
- var fileSize = (target.files[0].size/1024/1024).toFixed(2);//字节转换成M
- if(parseInt(fileSize)>30){
- dialog({
- content:'对不起,视频超过30Mb,无法发送,请录制10秒左右的短视频',
- okValue:'我知道了',
- ok: function() {
- return;
- }
- }).showModal();
- }else{
- if(networkStatus=="wifi" || window.localStorage.getItem("isTiXingVideoFaSong")=="1"){//wifi环境或用户点击移动网络弹框中的”不再提醒“按钮
- uploadVideo();
- }else{
- $("#mui-content").html('您正在使用移动网络,继续发送将消耗'+fileSize+'Mb流量,是否继续发送?');
- mui('#sheet1').popover('toggle');
- }
- }
-
- }
- //上传视频
- function uploadVideo(){
- dd.showModal();
- var fd=new FormData();
- fd.append('file',document.getElementById("upload_input").files[0]);
- $.ajax(server+"/upload/chat?type=4", {
- data: fd,
- contentType: false,
- cache: false,
- processData: false,
- type: 'post',
- success: function(resData) {
- if(resData.status==200){
- var data = {consult:consult,content:resData.urls,type:12};
- sendPost('patient/consult/append', data, 'json', 'post', submitFailed,
- function submitSoundSuccess(res) {
- if (res.status == 200) {
- dd.close();
- var data = JSON.parse(res.data[0]);
- addReply(2, data.content, new Date(data.timestamp).Format('yyyy-MM-dd HH:mm:ss'), 12, "");
- dialroll.refresh();
- dialroll.scrollTo(0, dialroll.maxScrollY);
- } else {
- submitFailed(res);
- }
- });
-
- }else{
- dd.close();
- }
-
- },
- error:function (XMLHttpRequest, textStatus, errorThrown) {
- console.log(XMLHttpRequest.status);
- console.log(XMLHttpRequest.readyState);
- console.log(textStatus)
- }
- });
- }
- Date.prototype.format = function(fmt) { //author: meizz
- var o = {
- "M+": this.getMonth() + 1, //月份
- "d+": this.getDate(), //日
- "h+": this.getHours(), //小时
- "m+": this.getMinutes(), //分
- "s+": this.getSeconds(), //秒
- "q+": Math.floor((this.getMonth() + 3) / 3), //季度
- "S": this.getMilliseconds() //毫秒
- };
- if (/(y+)/.test(fmt))
- fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
- for (var k in o)
- if (new RegExp("(" + k + ")").test(fmt))
- fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
- return fmt;
- }
- function getWeixinSign(){
- //从后台那边获取签名等信息
- var params = {};
- var url1 = window.location.href;
- 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',
- 'startRecord',
- 'stopRecord',
- 'onVoiceRecordEnd',
- 'playVoice',
- 'pauseVoice',
- 'stopVoice',
- 'onVoicePlayEnd',
- 'uploadVoice',
- 'getNetworkType'
- ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
- });
-
- // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。
- wx.ready(function(){
- wx.getNetworkType({
- success: function (res) {
- networkStatus = res.networkType; // 返回网络类型2g,3g,4g,wifi
- }
- });
- });
- }
- }
- });
- }
|