consulting-doctor.js 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327
  1. var dd = dialog({contentType:'load', skin:'bk-popup', content:'发送中...'});
  2. var userAgent = JSON.parse(window.localStorage.getItem(agentName));
  3. var dialroll;
  4. var content = "";
  5. var timeStr = "";
  6. var id = 1;
  7. var pagesize = 10;
  8. var consultCode = "";
  9. var patientcode = "";
  10. var networkStatus = "";
  11. var $ipt_content = $('#input_content');
  12. var recordTimer = null;
  13. var realStartTime = 0;
  14. var aud = document.getElementById('audio');
  15. var $playingDom;
  16. var serverId = "";
  17. var images = [];
  18. var chooseType; //记录选择的咨询类型
  19. //标记renew状态
  20. var isRenew;
  21. var participants = []; //记录参与者的信息
  22. var recordCancel = false;
  23. var recorder = null;
  24. var audio_tips = document.getElementById("audio_tips");
  25. var startTimestamp = null;
  26. var stopTimestamp = null;
  27. var stopTimer = null;
  28. var MIN_SOUND_TIME = 500;
  29. var expensesStatus="";//'扣费状态 【""没有签约信息 "0"未扣费 "1"已扣费 "2"已退费】'
  30. var ui = {
  31. body: document.querySelector('body'),
  32. btnMsgType: document.querySelector('#msg-type'),
  33. boxMsgText: document.querySelector('#msg-text'),
  34. boxMsgSound: document.querySelector('#msg-sound'),
  35. btnMsgImage: document.querySelector('#msg-image'),
  36. areaMsgList: document.querySelector('#msg-list'),
  37. boxSoundAlert: document.querySelector('#sound-alert')
  38. };
  39. patientcode = userAgent.represented?userAgent.represented:userAgent.uid;
  40. var consulting = {
  41. //初始化页面
  42. getInfo: function(){
  43. d.show();
  44. var reqList = [{
  45. //判断当前是否有未结束的咨询
  46. url:'/patient/consult/is_consult_unfinished',
  47. reqType:'POST',
  48. data:{doctor: request.doctor}
  49. },{
  50. //获得会话窗口的用户的头像等信息
  51. url: '/patient/consult/participants',
  52. reqType: 'POST',
  53. data: {
  54. sessionId: patientcode+"_"+request.teamCode+"_"+request.type
  55. }
  56. },{
  57. //获得咨询记录
  58. url: '/patient/consult/logs',
  59. reqType: 'POST',
  60. data: {
  61. sessionId: patientcode+"_"+request.teamCode+"_"+request.type,
  62. startMsgId:"",
  63. endMsgId: "",
  64. page: id,
  65. pagesize: pagesize
  66. }
  67. }];
  68. isRenew = request.isRenew;
  69. getReqPromises(reqList).then(function(res){
  70. // if(isRenew == 1){
  71. // d.close();
  72. // $("#input_div").hide();
  73. // $("#finish_list").hide();
  74. // $(".xzzx").hide();
  75. // winSize(125); //70+45
  76. // }else{
  77. doResponse(res);
  78. // }
  79. });
  80. },
  81. bindEvents: bindConsultEvents
  82. };
  83. //请求回调处理
  84. function doResponse(res){
  85. var res1 = res[0],
  86. res2 = res[1],
  87. res3 = res[2];
  88. if(res1.status == 200 && res2.status == 200 && res3.status == 200){
  89. d.close();
  90. loadSocket();
  91. if(res1.data == ""){
  92. //无正在进行中的咨询
  93. $("#input_div").hide();
  94. $("#finish_list").hide();
  95. $(".xzzx").show();
  96. winSize(125); //70+45
  97. //-1患者已取消,-2已拒绝,-3已解约,-4已到期
  98. switch(request.status){
  99. case "-1":
  100. case "-2":
  101. case "-3":
  102. case "-4":
  103. $(".xzzx").hide();
  104. winSize(45);
  105. break;
  106. }
  107. }else if(res1.data){
  108. //有正在咨询中的问卷
  109. $("#input_div").show();
  110. $("#finish_list").show();
  111. $(".xzzx").hide();
  112. consultCode = res1.data;
  113. //提示谁进入咨询
  114. var data = {
  115. consult:consultCode
  116. }
  117. sendPost('patient/consult/intoTopic', data, "json", "post", null,function(res){})
  118. winSize(167); //102+45
  119. }
  120. participants = res2.list;
  121. var pulldownAction = function() {
  122. getConsultLog();
  123. };
  124. dialroll = iscrollAssist.newVerScrollForPull($('.pull-iscroll-wrap'), pulldownAction, null);
  125. dialroll.refresh();
  126. dialroll.scrollTo(0, dialroll.maxScrollY);
  127. querySuccess2(res3, false);
  128. }else{
  129. queryFailed2();
  130. }
  131. }
  132. //加载socket组件
  133. function loadSocket(){
  134. jQuery.getScript(imurl+"/socket.io/socket.io.js").done(function() {
  135. var socket = io.connect(imurl);
  136. var sessionId = patientcode+"_"+request.teamCode+"_"+request.type;
  137. var userInfo = JSON.parse(window.localStorage.getItem(agentName));
  138. socket.emit('login', {userId: userInfo.represented?userInfo.represented:userInfo.uid, password: userInfo.represented?userInfo.represented:userInfo.uid,sessionId:sessionId,clientType:"patient"});
  139. socket.on('message', function (data) {
  140. // console.log(data)
  141. if((data.type == 1) ||(data.type == 2) || (data.type == 6) || (data.type == 12)){
  142. addReply(1, data.content, new Date(data.timestamp).Format('yyyy-MM-dd HH:mm:ss'), data.type, data.name, getImgUrl(data.sender_img));
  143. // setTimeout(function(){
  144. dialroll.refresh();
  145. dialroll.scrollTo(0, dialroll.maxScrollY);
  146. // },300)
  147. }
  148. });
  149. socket.on('error', function (data) {
  150. // console.log(data);
  151. });
  152. socket.on('ack', function (data) {
  153. // console.log(data);
  154. });
  155. function getLocalTime(nS) {
  156. return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ');
  157. }
  158. })
  159. .fail(function() {
  160. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:"医生实时对话连接失败!"}).show();
  161. });
  162. }
  163. //获得咨询记录
  164. function getConsultLog(){
  165. var url = "/patient/consult/logs",
  166. params = {
  167. sessionId: patientcode+"_"+request.teamCode+"_"+request.type,
  168. startMsgId:"",
  169. endMsgId: "",
  170. page: id,
  171. pagesize: pagesize
  172. };
  173. d.show();
  174. sendPost(url, params, "json", "post", queryFailed2, function(res){
  175. querySuccess2(res, true);
  176. });
  177. }
  178. //控制“发送”按钮的变化
  179. function sendBtn() {
  180. var tval = $(".talk-input input").val();
  181. if (tval != "") {
  182. $(".talk-send a").removeClass("disab");
  183. } else {
  184. $(".talk-send a").addClass("disab");
  185. }
  186. }
  187. //控制页面高度
  188. function winSize(h) {
  189. var totH = $(window).height();
  190. $("#talkwrap").height(totH - h);
  191. }
  192. function queryMsg(logId,msgType){
  193. var data={};
  194. data.consult = consultCode;
  195. data.logId = logId;
  196. data.msgType=msgType;
  197. sendPost('patient/consult/oneLog', data, 'json', 'GET', queryFailed2, function(res){
  198. if(res.status==200){
  199. var reply = res.consult;
  200. if((reply.msgType == 1) || (reply.msgType == 2) || (reply.msgType == 6)){
  201. addReply(reply.type, reply.content, reply.time, reply.msgType, reply.doctorName, reply.photo);
  202. setTimeout(function(){
  203. dialroll.refresh();
  204. dialroll.scrollTo(0, dialroll.maxScrollY);
  205. },300)
  206. }
  207. }
  208. d.close();
  209. });
  210. }
  211. function queryFailed2(res) {
  212. d.close();
  213. if (res && res.msg) {
  214. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:res.msg}).show();
  215. } else {
  216. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:'加载失败'}).show();
  217. }
  218. }
  219. function querySuccess2(res, prepend) {
  220. if (res.status == 200) {
  221. id++;
  222. var list = res.list;
  223. if (list && list.length > 0) {
  224. for (var j = list.length-1; j >=0; j--) {
  225. var reply = JSON.parse(list[j]);
  226. //屏蔽全科医生求助专科医生的消息
  227. if(reply.content_type != 5){
  228. var date = new Date();
  229. date.setTime(reply.timestamp);
  230. var time = date.format('yyyy-MM-dd hh:mm:ss');
  231. var p;
  232. for(var k in participants){
  233. if(participants[k].id==reply.sender_id)
  234. p = participants[k].avatar;
  235. }
  236. var isSystem = reply.sender_id == 'system';
  237. addReply(reply.sender_id==patientcode? 2 : 1, reply.content, time, reply.content_type, reply.sender_name, p, prepend, isSystem);
  238. }
  239. }
  240. dialroll.refresh();
  241. if(!prepend){
  242. dialroll.scrollTo(0, dialroll.maxScrollY);
  243. }
  244. }
  245. d.close();
  246. }
  247. else{
  248. queryFailed2(res);
  249. }
  250. }
  251. function getNowFormatDate() {
  252. var date = new Date();
  253. var seperator1 = "-";
  254. var seperator2 = ":";
  255. var month = date.getMonth() + 1;
  256. var strDate = date.getDate();
  257. if (month >= 1 && month <= 9) {
  258. month = "0" + month;
  259. }
  260. if (strDate >= 0 && strDate <= 9) {
  261. strDate = "0" + strDate;
  262. }
  263. var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
  264. + " " + date.getHours() + seperator2 + date.getMinutes()
  265. + seperator2 + date.getSeconds();
  266. return currentdate;
  267. }
  268. //点击发送按钮
  269. function send(){
  270. content = $("#input_content").text().replace(/\s+/g,"");
  271. if (content && content != null && content != "") {
  272. var now = new Date();
  273. timeStr = "";
  274. if(now.getMonth()<9){
  275. //补0
  276. timeStr = now.getFullYear() + "-0"+ (now.getMonth()+1) + "-" +now.getDate() +' '
  277. + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds();
  278. }else{
  279. timeStr = now.getFullYear() + "-"+ (now.getMonth()+1) + "-" +now.getDate() +' '
  280. + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds();
  281. }
  282. $("#input_content").blur();
  283. dialroll.refresh();
  284. dialroll.scrollTo(0, dialroll.maxScrollY);
  285. dd.showModal();
  286. var data = {};
  287. data.consult = consultCode;
  288. data.content = utf16toEntities(content);
  289. data.type = 1;
  290. sendPost('patient/consult/append', data, 'json', 'post', submitFailed, submitSuccess);
  291. } else {
  292. return;
  293. }
  294. }
  295. function submitFailed(res) {
  296. dd.close();
  297. if (res && res.msg) {
  298. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:res.msg}).show();
  299. } else {
  300. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:'发送失败'}).show();
  301. }
  302. }
  303. function submitSuccess(res) {
  304. if (res.status == 200) {
  305. //置空
  306. $("#input_content").text("");
  307. $(".talk-send a").addClass("disab");
  308. addReply(2, content, timeStr, 1, "");
  309. dialroll.refresh();
  310. dialroll.scrollTo(0, dialroll.maxScrollY);
  311. showSendBtn(false);
  312. dd.close();
  313. } else {
  314. submitFailed(res);
  315. }
  316. }
  317. //回复单条内容填写
  318. var defaultPhoto = "../../../images/p-default.png";
  319. var doctorDefaultPhoto = "../../../images/d-default.png";
  320. function addReply(isPatient, content, time, msgType, doctorName,photo,prepend, isSystem) {
  321. //time = time.substr(10);
  322. var doctorPhoto = photo ? getImgUrl(photo) : doctorDefaultPhoto;
  323. var $div = $("<dl></dl>");
  324. if(msgType == 7 || msgType == 10 || msgType == 13 ||msgType == 14){
  325. if(msgType == 7 && isSystem){
  326. content = "您24小时内未回复,系统自动结束咨询";
  327. }
  328. if(prepend){
  329. $(".talk-box").prepend('<div class="time-tips"><span class="xt-xiaoxi">' + content + '</span></div>');
  330. } else
  331. $(".talk-box").append('<div class="time-tips"><span class="xt-xiaoxi">' + content + '</span></div>');
  332. return;
  333. }
  334. if (isPatient == 1) {
  335. $div.addClass('chat-left');
  336. img = doctorPhoto;
  337. name = doctorName;
  338. } else {
  339. $div.addClass('chat-right');
  340. img = photo? getImgUrl(photo):defaultPhoto;
  341. defaultPhoto = img;
  342. name = window.localStorage.getItem("nowPatientName");
  343. }
  344. var temp = '<dt style="height: auto; text-align: center;"><a><img src="' + img + '" class="c-images-cycle" /></a></dt>' +
  345. '<div class="c-content"><span class="c-f12 name">' + name + '</span>'
  346. switch(parseInt(msgType)) {
  347. case 0: //签约信息
  348. case 1://信息
  349. case 6://咨询问题
  350. temp += '<dd class="word-bread"><span>' + content + '</span></dd>';
  351. break;
  352. case 2://图片
  353. // alert(content);
  354. temp += '<dd class="word-bread wb-img"><img style="width:100px; height:100px;" src="'+ getImgUrl(content) +'" /></dd>';
  355. break;
  356. case 3://语音
  357. var rec = JSON.parse(content);
  358. temp += "<div class='c-msg'><dd class='word-bread audio' data-type='3' data-audio='" + content + "'>"+
  359. "<div class='soundWav'>" +
  360. "<span class='soundWavT'>"+(rec? rec.times: "") +"\'\'</span>"+
  361. "</div>"+
  362. "</dd></div>";
  363. break;
  364. case 4: //文章
  365. temp += formatJyzd(content, "","", time);
  366. // temp += '<dd class="word-bread" data-type="1"><span>' + matchUrl(contentMsg) + '</span></dd>';
  367. break;
  368. case 12://视频
  369. var videoInfo = content.split(",");
  370. var shichang = formatSeconds(videoInfo[2]);//时长
  371. if(isPatient == 1){
  372. temp += '<dd class="preview-video" data-video="'+getImgUrl(videoInfo[1])+'">'+
  373. '<img class="video-img-left" src="'+getImgUrl(videoInfo[0])+'">'+
  374. '<img class="bofang-icon-left" src="../../yszx/images/bofang_icon.png">'+
  375. '<img class="jianjiao-icon-left" src="../../yszx/images/zuoshanjiao_bg.png">'+
  376. '<span class="shichang-time-left">'+shichang+'</span>'+
  377. '</dd>';
  378. }else{
  379. temp += '<dd class="preview-video" data-video="'+getImgUrl(videoInfo[1])+'">'+
  380. '<img class="video-img-right" src="'+getImgUrl(videoInfo[0])+'">'+
  381. '<img class="bofang-icon-right" src="../../yszx/images/bofang_icon.png">'+
  382. '<img class="jianjiao-icon-right" src="../../yszx/images/youshanjiao_bg.png">'+
  383. '<span class="shichang-time-right">'+shichang+'</span>'+
  384. '</dd>';
  385. }
  386. break;
  387. }
  388. if(prepend){
  389. $(".talk-box").prepend($div.append(temp)).prepend('<div class="time-tips"><span>' + time + '</span></div>');
  390. } else{
  391. $(".talk-box").append('<div class="time-tips"><span>' + time + '</span></div>').append($div.append(temp));
  392. }
  393. if(isPatient != null && isPatient != 1) {
  394. $(".tw-add-detail").hide(200);
  395. }
  396. }
  397. function formatJyzd(msg, sendErrDom,yiduHtml, time){
  398. // {"title":"2016年春节放假调休门诊安排通知","id":"ff1b39cfdf6a482c958140ba768474cc","img":"http://f1.yihuimg.com/TFS/upfile/WBJ/111/2016-02-05/160294_1454633481085_fullsize.png","content":"为了您的健康,我给您发送了一篇文章,请咨询查阅,如有问题,可随时与我沟通"}
  399. if(msg){
  400. //针对\n,\r等特殊字符,在json转换时会报错
  401. msg = msg.replace(/\n/g, "\\n");
  402. msg = msg.replace(/\r/g, "\\r");
  403. msg = JSON.parse(msg);
  404. // msg.img = msg.type==1? "../../../images/jkjl_share.png" : msg.img;
  405. if(msg.type == 1){ //健康记录
  406. msg.img = "../../../images/jkjl_share.png";
  407. }else if(msg.type == 2){ //健康指导
  408. var img = msg.img.split(",");
  409. if(img[0] && img[0] != "null"){
  410. msg.img = getImgUrl(img[0]);
  411. }else{
  412. msg.img = "../../../images/default_share_blue.png";
  413. }
  414. }else{ //健康教育
  415. msg.img = getImgUrl(msg.img);
  416. if(!msg.img){
  417. msg.img = "../../../images/default_share_blue.png";
  418. }
  419. }
  420. var temp =
  421. '<div class="c-msg">'+'<dd class="word-bread word-article" data-code="'+ msg.id+'" data-inner-type="'+ msg.type +'" data-type="4" data-time="'+time+'">'
  422. // + yiduHtml
  423. + '<h4 class="text-ellipsis c-f18">'+ msg.title +'</h4>'
  424. + '<div class="article-content"><img src="'+ msg.img +'">'
  425. + '<div>'+ msg.content+'</div>'
  426. + '</div>'
  427. + '</dd></div>';
  428. return temp;
  429. }
  430. return "";
  431. }
  432. //毫秒转换成时分秒
  433. function formatSeconds(value) {
  434. var theTime = parseInt(value/1000);// 秒
  435. var theTime1 = 0;// 分
  436. var theTime2 = 0;// 小时
  437. if(theTime > 60) {
  438. theTime1 = parseInt(theTime/60);
  439. theTime = parseInt(theTime%60);
  440. if(theTime1 > 60) {
  441. theTime2 = parseInt(theTime1/60);
  442. theTime1 = parseInt(theTime1%60);
  443. }
  444. }
  445. var result = ""+parseInt(theTime);//秒
  446. if(parseInt(theTime)<=9){
  447. result = "0"+parseInt(theTime);//秒
  448. }
  449. if(theTime1 > 0) {//分
  450. if(parseInt(theTime1)>9){
  451. result = ""+parseInt(theTime1)+":"+result;
  452. }else{
  453. result = "0"+parseInt(theTime1)+":"+result;
  454. }
  455. }
  456. if(theTime2 > 0) {//小时
  457. if(parseInt(theTime2)>9){
  458. result = ""+parseInt(theTime2)+":"+result;
  459. }else{
  460. result = "0"+parseInt(theTime2)+":"+result;
  461. }
  462. }
  463. var resResult = "";
  464. if(result.split(":").length==1){//秒
  465. resResult = "00:"+result;
  466. }else if(result.split(":").length==2){//分
  467. resResult = "00:"+result;
  468. }else{//时
  469. resResult = result;
  470. }
  471. return resResult;
  472. }
  473. //向上拉取更多
  474. function addReplyBefore(type, content, time, msgType, doctorName) {
  475. //time = time.substr(10);
  476. var doctorPhoto = doctorDefaultPhoto;
  477. var patientPhoto = defaultPhoto;
  478. var $div = $("<div></div>");
  479. if (type == 1) {
  480. if(msgType == 2){
  481. $div.addClass('talk-left');
  482. $div.addClass('clearfix');
  483. $div.html('<div class="leftpart"><img src="'+doctorPhoto+'" /><p style="font-size: 13px; text-align: center;max-width: 40px;">'+ doctorName + '</p></div> '
  484. +'<span class="talktime" style="width: 100%; left: 70px; top:-10px;">' + time+'</span>'
  485. +'<div class="rightpart">'
  486. +' <s class="rightjt jt-left"><s></s></s><img style="height: 150px; width: 100px;" src="'+getImgUrl(content)+'" onclick="viewImg(this)"/>'
  487. +'</div>');
  488. }
  489. else{
  490. $div.addClass('talk-left');
  491. $div.addClass('clearfix');
  492. $div.html('<div class="leftpart"><img src="'+doctorPhoto+'" /><p style="font-size: 13px; text-align: center;max-width: 40px;">'+ doctorName + '</p></div> '
  493. +'<span class="talktime" style="width: 100%; left: 70px; top:-10px;">' + time+'</span>'
  494. +'<div class="rightpart">'
  495. +' <s class="rightjt jt-left"><s></s></s>'+content
  496. +'</div>');
  497. }
  498. } else {
  499. if(msgType == 2){
  500. $div.addClass('talk-right');
  501. $div.addClass('clearfix');
  502. $div.html('<div class="leftpart"><img src="'+patientPhoto+'" /></div> '
  503. +'<span class="talktime" style="width: 100%; position:absolute; right:-45%; top:-10px; float: right;">'+time+'</span>'
  504. +'<div class="rightpart">'
  505. +' <img style="height: 150px; width: 100px;" src="'+getImgUrl(content)+'" onclick="viewImg(this)"/>'
  506. +'</div>');
  507. }
  508. else{
  509. $div.addClass('talk-right');
  510. $div.addClass('clearfix');
  511. $div.html ('<div class="leftpart"><img src="' + patientPhoto + '" /></div>'
  512. + '<span class="talktime" style="width: 100%; position:absolute; right:-45%; top:-10px; float: right;">' + time + '</span>'
  513. + '<div class="rightpart">' + content + '</div>');
  514. }
  515. }
  516. $(".talk-box").prepend($div);
  517. }
  518. //结束咨询
  519. function finish(){
  520. dialog({
  521. content:'是否确认结束该次咨询?结束后医生将无法回复',
  522. ok: function (){
  523. var params = {}
  524. params.code = consultCode;
  525. //发送ajax请求, 查询设备列表信息
  526. sendPost("patient/consult/finish", params, "json", "post", submitFailed3,finish_Successs);
  527. function finish_Successs(res){
  528. if (res.status == 200) {
  529. localStorage.setItem("evaluate",0);//标志未评价
  530. location.reload();
  531. }
  532. else{
  533. submitFailed3(res);
  534. }
  535. }
  536. },
  537. cancel: function () {
  538. return;
  539. }
  540. }).showModal();
  541. }
  542. function submitFailed3(res) {
  543. if (res && res.msg) {
  544. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:res.msg}).show();
  545. } else {
  546. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:'操作失败'}).show();
  547. }
  548. }
  549. //查看图片
  550. function viewImg(dom) {
  551. var $img = $(dom);
  552. var thissrc = $img.attr("src");
  553. var mWid = $(window).width();
  554. var mHei = $(window).height();
  555. 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>';
  556. $("body").append(nHtml);
  557. $(".delimgpop").click(function() {
  558. $(this).remove()
  559. });
  560. }
  561. //微信上传图片
  562. function chooseImageWx(){
  563. wx.chooseImage({
  564. count: 1,
  565. success: function (res) {
  566. for (var i in res.localIds) {
  567. images.push(res.localIds[i]);
  568. }
  569. uploadImage();
  570. }
  571. });
  572. }
  573. function uploadImage(){
  574. if (images.length == 0) {
  575. dd.close();
  576. return;
  577. }
  578. var i = 0, length = images.length;
  579. serverId = "";
  580. var faillength = 0 ;
  581. function upload() {
  582. wx.uploadImage({
  583. localId: images[i],
  584. isShowProgressTips: 0,
  585. success: function (res) {
  586. faillength= 0;
  587. dd.close();
  588. i++;
  589. if(serverId.length == 0){
  590. serverId = res.serverId;
  591. }
  592. else{
  593. serverId =serverId + "," + res.serverId;
  594. }
  595. if (i < length) {
  596. upload();
  597. }
  598. if(i == images.length){
  599. sendImages();
  600. }
  601. },
  602. fail: function (res) {
  603. dd.close();
  604. faillength+=1;
  605. if(faillength<=5){
  606. //失败从传
  607. upload();
  608. }else{
  609. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:"发送图片一次仅限发送单张"}).show();
  610. }
  611. }
  612. });
  613. }
  614. dd.showModal();
  615. upload();
  616. }
  617. //保存图片
  618. function sendImages(){
  619. var now = new Date();
  620. //清空images
  621. images = [];
  622. timeStr = "";
  623. if(now.getMonth()<9){
  624. //补0
  625. timeStr = now.getFullYear() + "-0"+ (now.getMonth()+1) + "-" +now.getDate() +' '
  626. + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds();
  627. }else{
  628. timeStr = now.getFullYear() + "-"+ (now.getMonth()+1) + "-" +now.getDate() +' '
  629. + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds();
  630. }
  631. var data = {};
  632. data.consult = consultCode;
  633. data.content = "";
  634. data.mediaIds = serverId;
  635. data.type = 2;
  636. data.times = 0;
  637. dd.showModal();
  638. sendPost('patient/consult/append', data, 'json', 'post', submitFailed, submitImageSuccess);
  639. }
  640. function submitImageSuccess(res) {
  641. if (res.status == 200) {
  642. var data= JSON.parse(res.data)
  643. dd.close();
  644. addReply(2, data.content, timeStr, 2, "");
  645. dialroll.refresh();
  646. dialroll.scrollTo(0, dialroll.maxScrollY);
  647. } else {
  648. submitFailed(res);
  649. }
  650. }
  651. //function wslogin() {
  652. // var userid = patientcode;
  653. // var ws;
  654. // if (typeof MozWebSocket != "undefined") {
  655. // ws = new MozWebSocket(wsurl, 'netex');
  656. // } else {
  657. // ws = new WebSocket(wsurl, 'netex');
  658. // }
  659. //
  660. // function onopen() {
  661. // var reg = {};
  662. // reg.id = 'reg';
  663. // reg.uid = userid;
  664. // reg.pwd = '';
  665. // ws.send(JSON.stringify(reg));
  666. // }
  667. //
  668. // function onclose() {
  669. // // 断链重连
  670. // if (typeof MozWebSocket != "undefined") {
  671. // ws = new MozWebSocket(wsurl, 'netex');
  672. // } else {
  673. // ws = new WebSocket(wsurl, 'netex');
  674. // }
  675. // }
  676. // function onmessage(msg) {
  677. // var result = eval("("+msg.data+")");
  678. // if(result.msgid){
  679. // queryMsg(result.msgid,result.msgType);
  680. // }
  681. // }
  682. // ws.onopen = onopen;
  683. // ws.onmessage = onmessage;
  684. // ws.onclose = onclose;
  685. // }
  686. function playSoundEnd(){
  687. $playingDom.removeClass('active');
  688. $playingDom = null;
  689. }
  690. function playError(){
  691. var src = $('#audio').attr('src');
  692. if(!$.trim(src)) {
  693. return ;
  694. }
  695. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:"播放语音失败"}).show();
  696. $playingDom.removeClass('active');
  697. $playingDom = null;
  698. }
  699. function showSendBtn(isShow){
  700. if(isShow){
  701. $('.tw-add').hide();
  702. $('#reply').fadeIn('fast', 'swing');
  703. } else {
  704. $('#reply').fadeOut('fast', 'swing', function(){
  705. $('.tw-add').show();
  706. });
  707. }
  708. }
  709. function setSoundAlertVisable(show){
  710. if(show){
  711. ui.boxSoundAlert.style.display = 'block';
  712. ui.boxSoundAlert.style.opacity = 1;
  713. }else{
  714. ui.boxSoundAlert.style.opacity = 0;
  715. //fadeOut 完成再真正隐藏
  716. setTimeout(function(){
  717. ui.boxSoundAlert.style.display = 'none';
  718. },200);
  719. }
  720. };
  721. function recordErr(res){
  722. if(res && res.errMsg == "stopRecord:tooshort") {
  723. audio_tips.innerHTML = "录音时间太短";
  724. ui.boxSoundAlert.classList.add('rprogress-sigh');
  725. recordCancel = true;
  726. stopTimer=setTimeout(function(){
  727. setSoundAlertVisable(false);
  728. },500);
  729. startTimestamp = 0;
  730. //小于300ms,不录音
  731. if(recordTimer)clearTimeout(recordTimer);
  732. return;
  733. }
  734. if(!recordCancel){
  735. dialog({
  736. content:'录音失败,请重试',
  737. okValue:'我知道了',
  738. ok: function() {}
  739. }).showModal();
  740. }
  741. }
  742. //保存图片
  743. function sendSounds(times){
  744. var now = new Date();
  745. timeStr = "";
  746. if(now.getMonth()<9){
  747. //补0
  748. timeStr = now.getFullYear() + "-0"+ (now.getMonth()+1) + "-" +now.getDate() +' '
  749. + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds();
  750. }else{
  751. timeStr = now.getFullYear() + "-"+ (now.getMonth()+1) + "-" +now.getDate() +' '
  752. + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds();
  753. }
  754. var data = {};
  755. data.consult = consultCode;
  756. data.content = "";
  757. data.type = 3;
  758. data.times = times;
  759. wx.uploadVoice({
  760. localId: serverId,
  761. success: function (res) {
  762. data.voices = res.serverId;
  763. dd.showModal();
  764. sendPost('patient/consult/append', data, 'json', 'post', submitFailed,
  765. function submitSoundSuccess(res) {
  766. if (res.status == 200) {
  767. dd.close();
  768. var data = JSON.parse(res.data[0]);
  769. addReply(2, data.content, timeStr, 3, "");
  770. dialroll.refresh();
  771. dialroll.scrollTo(0, dialroll.maxScrollY);
  772. } else {
  773. submitFailed(res);
  774. }
  775. });
  776. }
  777. });
  778. }
  779. function bindConsultEvents(){
  780. //录制视频
  781. /*$(".lz-video-img").click(function(){
  782. $("#upload_input").click();
  783. //dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请录制10秒左右的短视频,以防录制完成后无法发送'}).show();
  784. return false;
  785. })*/
  786. //点击内容区域输入框失焦
  787. $('#talkwrap').click(function(){
  788. $("#input_content").blur();
  789. // dialroll.refresh();
  790. // dialroll.scrollTo(0, dialroll.maxScrollY);
  791. return false;
  792. });
  793. //发送以后定位至最底部
  794. $("#reply a").click(function() {
  795. send();
  796. });
  797. //立即发送
  798. $("#lijifasong").on("tap", function(){
  799. uploadVideo();
  800. mui('#sheet1').popover('toggle');
  801. return false;
  802. });
  803. //不再提醒
  804. $("#buzaitixing").on("tap", function(){
  805. window.localStorage.setItem("isTiXingVideoFaSong","1");
  806. uploadVideo();
  807. mui('#sheet1').popover('toggle');
  808. return false;
  809. });
  810. // window.localStorage.removeItem("isTiXingVideoFaSong");//测试
  811. $('.talk-box').on('click', '.word-bread img', function(){
  812. var src = $(this).attr('src')
  813. $(this).attr('src',src+'?'+$.now())
  814. if(!$(this).closest(".word-bread").hasClass("preview-video")){
  815. var urls = [];
  816. $.each($('.word-bread img'), function(i, v) {
  817. urls.push($(v).attr('src'));
  818. });
  819. wx.previewImage({
  820. current: $(this).attr('src'), // 当前显示图片的http链接
  821. urls: urls // 需要预览的图片http链接列表
  822. });
  823. }
  824. })
  825. .on('touchstart', '.audio', function(){
  826. if($playingDom){
  827. aud.pause();
  828. //aud.stop();
  829. $playingDom.removeClass('active');
  830. if($playingDom[0] == this){
  831. $playingDom = null;
  832. return;
  833. }
  834. }
  835. $playingDom = $(this);
  836. $playingDom.addClass('active');
  837. var ser = JSON.parse($(this).attr('data-audio'));
  838. aud.src = getImgUrl(ser.path);
  839. aud.load();
  840. aud.play();
  841. })
  842. .on('click','.preview-video',function() {
  843. $(document.body).find('video').remove();
  844. var url = $(this).attr('data-video');
  845. var html = '<video style="display: none;" controls preload="auto" width="1" height="1" src="'+url+'"></video>';
  846. $(document.body).append(html);
  847. var video = $(document.body).find('video')[0];
  848. video.play();
  849. });
  850. //键盘输入解决输入框被软键盘覆盖的问题
  851. var bfscrolltop = document.body.scrollTop;//获取软键盘唤起前浏览器滚动部分的高度
  852. var interval;
  853. $ipt_content.focus(function(){//当它获取焦点时触发事件
  854. $(".tw-add-detail").hide();
  855. interval = setInterval(function(){//设置一个计时器,时间设置与软键盘弹出所需时间相近
  856. document.body.scrollTop = document.body.scrollHeight;//获取焦点后将浏览器内所有内容高度赋给浏览器滚动部分高度
  857. },100)
  858. }).blur(function(){//设定输入框失去焦点时的事件
  859. clearInterval(interval);//清除计时器
  860. document.body.scrollTop = bfscrolltop; //将软键盘唤起前的浏览器滚动部分高度重新赋给改变后的高度
  861. });
  862. /**
  863. * 显示发送按钮的事件
  864. */
  865. $ipt_content.on('input', function(e){
  866. if($(this).prop('comstart')) {
  867. //console.log("true");
  868. return;
  869. }
  870. var text = $.trim($(this).text());
  871. showSendBtn(text.length > 0)
  872. }).on('compositionstart', function(){
  873. $(this).prop('comstart', true);
  874. //console.log('中文输入:开始');
  875. }).on('compositionend', function(){
  876. $(this).prop('comstart', false);
  877. // console.log('中文输入:结束');
  878. var text = $.trim($(this).text());
  879. showSendBtn(text.length > 0)
  880. })
  881. .on('tap', function(){
  882. $(".tw-add-detail").hide();
  883. // $ipt_content.focus();
  884. //mui.later(scrollToEnd, 300);
  885. })
  886. /*
  887. * 附加功能
  888. */
  889. $(".tw-add").click(function() {
  890. $(".tw-add-detail").toggle(200);
  891. });
  892. $('body')
  893. //隐藏打开的附加功能
  894. .on('tap', '#talkwrap', function(){
  895. $('.tw-add-detail').hide();
  896. $ipt_content.blur();
  897. })
  898. $(".yy-add").click(function() {
  899. if($('#msg-sound:visible').length){
  900. $ipt_content.show();
  901. ui.boxMsgSound.style.display = 'none';
  902. $(this).find('img:eq(0)').show().next().hide();
  903. } else {
  904. $ipt_content.hide();
  905. ui.boxMsgSound.style.display = 'block';
  906. $(this).find('img:eq(0)').hide().next().show();
  907. }
  908. });
  909. $("body").on('tap', '.word-article', function(){
  910. var type = $(this).attr('data-inner-type');
  911. var code = $(this).attr('data-code');
  912. if(type == 2){
  913. window.location.href = "../../yszd/html/guidance-detail.html?id="+code;
  914. } else{
  915. //根据时间判断该文章是旧的文章还是改造后发送的文章,时间是:2017-12-29 00:00:00
  916. var sendTimeStr = $(this).attr("Data-code"),
  917. sendTime = new Date(sendTimeStr),
  918. cDate = new Date("2017-12-29 00:00:00");
  919. if(sendTime < cDate){
  920. window.location.href = "../../jkjy/html/article.html?dataId="+code;
  921. }else{
  922. window.location.href = "../../jkjy/html/article2.html?dataId="+code;
  923. }
  924. }
  925. });
  926. $(".xzzx").on('tap', function(){
  927. //获取患者信息 判断该患者是否已经缴费 若缴费则正常咨询 未缴费提示咨询次数信息
  928. getPatientInfo();
  929. })
  930. ui.boxMsgSound.addEventListener("touchstart", function(e) {
  931. e.preventDefault();
  932. event.preventDefault();
  933. $(this).addClass('yy-hold');
  934. if(stopTimer)clearTimeout(stopTimer);
  935. recordCancel = false;
  936. audio_tips.innerHTML = "手指上划,取消发送";
  937. ui.boxSoundAlert.classList.remove('rprogress-sigh');
  938. setSoundAlertVisable(true);
  939. startTimestamp = new Date().getTime();
  940. recordTimer = setTimeout(function(){
  941. wx.startRecord({
  942. success: function(){
  943. realStartTime = new Date().getTime();
  944. },
  945. fail: recordErr
  946. });
  947. wx.onVoiceRecordEnd({
  948. // 录音时间超过一分钟没有停止的时候会执行 complete 回调
  949. complete: function (res) {
  950. serverId = res.localId;
  951. sendSounds(60);
  952. },
  953. fail: recordErr
  954. });
  955. },MIN_SOUND_TIME);
  956. }, false);
  957. ui.boxMsgSound.addEventListener("touchend", function(e){
  958. e.preventDefault();
  959. event.preventDefault();
  960. $(this).removeClass('yy-hold');
  961. if (audio_tips.classList.contains("cancel")) {
  962. audio_tips.classList.remove("cancel");
  963. audio_tips.innerHTML = "手指上划,取消发送";
  964. }
  965. var endTimestamp = new Date().getTime();
  966. var times = endTimestamp - startTimestamp;
  967. var realTimes = endTimestamp - realStartTime;
  968. if(times < MIN_SOUND_TIME || realTimes < MIN_SOUND_TIME){
  969. audio_tips.innerHTML = "录音时间太短";
  970. ui.boxSoundAlert.classList.add('rprogress-sigh');
  971. recordCancel = true;
  972. stopTimer=setTimeout(function(){
  973. setSoundAlertVisable(false);
  974. },500);
  975. startTimestamp = 0;
  976. realStartTime = 0;
  977. //小于300ms,不录音
  978. clearTimeout(recordTimer);
  979. wx.stopRecord({
  980. success: function (res) {
  981. },
  982. fail: function(){}
  983. });
  984. }else{
  985. setSoundAlertVisable(false);
  986. wx.stopRecord({
  987. success: function (res) {
  988. if(!recordCancel) {
  989. serverId = res.localId;
  990. sendSounds(Math.round(times/1000));
  991. }
  992. },
  993. fail: recordErr
  994. });
  995. }
  996. }, false)
  997. ui.body.addEventListener('drag', function(event) {
  998. if (Math.abs(event.detail.deltaY) > 50) {
  999. if (!recordCancel) {
  1000. recordCancel = true;
  1001. if (!audio_tips.classList.contains("cancel")) {
  1002. audio_tips.classList.add("cancel");
  1003. }
  1004. audio_tips.innerHTML = "松开手指,取消发送";
  1005. }
  1006. } else {
  1007. if (recordCancel) {
  1008. recordCancel = false;
  1009. if (audio_tips.classList.contains("cancel")) {
  1010. audio_tips.classList.remove("cancel");
  1011. }
  1012. audio_tips.innerHTML = "手指上划,取消发送";
  1013. }
  1014. }
  1015. }, false);
  1016. }
  1017. //录制视频回调
  1018. function videoFileChange(target) {
  1019. var fileSize = (target.files[0].size/1024/1024).toFixed(2);//字节转换成M
  1020. if(parseInt(fileSize)>30){
  1021. dialog({
  1022. content:'对不起,视频超过30Mb,无法发送,请录制10秒左右的短视频',
  1023. okValue:'我知道了',
  1024. ok: function() {
  1025. return;
  1026. }
  1027. }).showModal();
  1028. }else{
  1029. if(networkStatus=="wifi" || window.localStorage.getItem("isTiXingVideoFaSong")=="1"){//wifi环境或用户点击移动网络弹框中的”不再提醒“按钮
  1030. uploadVideo();
  1031. }else{
  1032. $("#mui-content").html('您正在使用移动网络,继续发送将消耗'+fileSize+'Mb流量,是否继续发送?');
  1033. mui('#sheet1').popover('toggle');
  1034. }
  1035. }
  1036. }
  1037. //上传视频
  1038. function uploadVideo(){
  1039. dd.showModal();
  1040. var fd=new FormData();
  1041. fd.append('file',document.getElementById("upload_input").files[0]);
  1042. $.ajax(server+"/upload/chat?type=4", {
  1043. data: fd,
  1044. contentType: false,
  1045. cache: false,
  1046. processData: false,
  1047. type: 'post',
  1048. success: function(resData) {
  1049. if(resData.status==200){
  1050. var data = {consult:consultCode,content:resData.urls,type:12};
  1051. sendPost('patient/consult/append', data, 'json', 'post', submitFailed,
  1052. function submitSoundSuccess(res) {
  1053. if (res.status == 200) {
  1054. dd.close();
  1055. var data = JSON.parse(res.data[0]);
  1056. addReply(2, data.content, new Date(data.timestamp).Format('yyyy-MM-dd HH:mm:ss'), 12, "");
  1057. dialroll.refresh();
  1058. dialroll.scrollTo(0, dialroll.maxScrollY);
  1059. } else {
  1060. submitFailed(res);
  1061. }
  1062. });
  1063. }else{
  1064. dd.close();
  1065. }
  1066. },
  1067. error:function (XMLHttpRequest, textStatus, errorThrown) {
  1068. console.log(XMLHttpRequest.status);
  1069. console.log(XMLHttpRequest.readyState);
  1070. console.log(textStatus)
  1071. }
  1072. });
  1073. }
  1074. Date.prototype.format = function(fmt) { //author: meizz
  1075. var o = {
  1076. "M+": this.getMonth() + 1, //月份
  1077. "d+": this.getDate(), //日
  1078. "h+": this.getHours(), //小时
  1079. "m+": this.getMinutes(), //分
  1080. "s+": this.getSeconds(), //秒
  1081. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  1082. "S": this.getMilliseconds() //毫秒
  1083. };
  1084. if (/(y+)/.test(fmt))
  1085. fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  1086. for (var k in o)
  1087. if (new RegExp("(" + k + ")").test(fmt))
  1088. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  1089. return fmt;
  1090. }
  1091. //未缴费居民限制咨询次数
  1092. function limitZxTimes(){
  1093. //获取剩余家庭咨询次数
  1094. var url = '/patient/consult/remainConsultTimes';
  1095. var remainTimes;//剩余咨询次数
  1096. var countTimes;//总咨询次数
  1097. var zxTimes;//已咨询次数
  1098. d.show();
  1099. sendPost(url, {}, 'json', 'get', queryFailed, function(res){
  1100. if(res.status == 200){
  1101. d.close();
  1102. remainTimes = res.data.amount;
  1103. countTimes = res.data.count;
  1104. zxTimes = countTimes - remainTimes;
  1105. if(zxTimes == countTimes){
  1106. //未缴费的总咨询次数已达上限 提示去缴费
  1107. dialog({
  1108. content: '您本年度家庭医生签约暂未缴费,当前10次免费健康咨询已全部使用.如果需要家庭医生继续为您提供服务,请尽快完成缴费操作',
  1109. okValue:'前往缴费',
  1110. ok: function (){
  1111. window.location.href = "signing_management.html";
  1112. }
  1113. }).showModal();
  1114. }else{
  1115. dialog({
  1116. content: '您本年度家庭医生签约暂未缴费,可使用10次免费健康咨询,当前剩余:'+remainTimes+'次.为避免影响您的服务体验,请尽快完成缴费操作',
  1117. okValue:'前往缴费',
  1118. ok: function (){
  1119. window.location.href = "signing_management.html";
  1120. },
  1121. cancelValue: '开始咨询',
  1122. cancel: function () {
  1123. querySignType(2)
  1124. }
  1125. }).showModal();
  1126. }
  1127. }else{
  1128. queryFailed(res);
  1129. }
  1130. });
  1131. }
  1132. //查询签约类型
  1133. function querySignType(type){
  1134. chooseType = type;
  1135. d.show();
  1136. sendPost('patient/sign_doctors', {}, 'json', 'post', function(res){
  1137. queryFailed(res, '获取咨询类型失败');
  1138. }, querySignTypeSuccess);
  1139. }
  1140. //查询签约类型成功回调处理事件
  1141. function querySignTypeSuccess(res){
  1142. if (res.status == 200) {
  1143. d.close();
  1144. var doctors = "";
  1145. switch(Number(chooseType)) {
  1146. case 1: doctors = res.teamDoctors; break;
  1147. case 2: doctors = res.familyDoctors; break;
  1148. default: break;
  1149. }
  1150. var docInfo,docQkInfo;
  1151. $.each(doctors, function(i, v) {
  1152. if(v.teamlevel){
  1153. if(v.teamlevel == 3){
  1154. docInfo = v;
  1155. }
  1156. if(v.teamlevel == 2){
  1157. docQkInfo = v;
  1158. }
  1159. }else{
  1160. if(v.level == 3){
  1161. docInfo = v;
  1162. }
  1163. if(v.level == 2){
  1164. docQkInfo = v;
  1165. }
  1166. }
  1167. });
  1168. if(!docInfo){
  1169. docInfo = docQkInfo;
  1170. }
  1171. checkDocInWork(chooseType, docInfo,docQkInfo)
  1172. }else {
  1173. queryFailed(res);
  1174. }
  1175. }
  1176. //获取签约医生的工作时间
  1177. function checkDocInWork(type, doctor,docQkInfo){
  1178. var url = 'patient/consult/isDoctorWorkWhenconsult',
  1179. params = {doctor:docQkInfo.code,healthDoctor:doctor.code};
  1180. sendPost(url, params, 'json', 'post', queryFailed, function(res){
  1181. if(res.status == 200){
  1182. // data:0-医生不接受咨询/1-医生当前接受咨询/2-全科医生和健管师当前都不在工作时间/3-全科医生当前不在工作时间/4-健管师当前不在工作时间 健管师当前不在工作时间
  1183. if(res.data==2){
  1184. dialog({
  1185. content: '您好,由于您的签约医生工作繁忙,设置了每日回复咨询的时间段,所以,在该时间段外的时间,您的咨询将不会马上获得医生的回复。',
  1186. okValue:'查看医生工作时间',
  1187. ok: function (){
  1188. window.location.href = "../../yszx/html/doctor-work-hours.html?doctor=" + docQkInfo.code+"&healthDoctor="+doctor.code;
  1189. },
  1190. cancelValue: '继续新增咨询',
  1191. cancel: function () {
  1192. window.location.href = "../../yszx/html/add-consult.html?type="+request.type+"&doctorCode=" + request.doctor;
  1193. }
  1194. }).showModal();
  1195. }else if(res.data==3){
  1196. dialog({
  1197. content: '您好,由于您的签约全科医生工作繁忙……,您的咨询将不会马上获得全科医生的回复 。',
  1198. okValue:'查看医生工作时间',
  1199. ok: function (){
  1200. window.location.href = "../../yszx/html/doctor-work-hours.html?doctor=" + docQkInfo.code+"&healthDoctor="+doctor.code;
  1201. },
  1202. cancelValue: '继续新增咨询',
  1203. cancel: function () {
  1204. window.location.href = "../../yszx/html/add-consult.html?type="+request.type+"&doctorCode=" + request.doctor;
  1205. }
  1206. }).showModal();
  1207. }else if(res.data==4){
  1208. dialog({
  1209. content: '您好,由于您的签约健康管理师工作繁忙……,您的咨询将不会马上获得健康管理师的回复 。',
  1210. okValue:'查看医生工作时间',
  1211. ok: function (){
  1212. window.location.href = "../../yszx/html/doctor-work-hours.html?doctor=" + docQkInfo.code+"&healthDoctor="+doctor.code;
  1213. },
  1214. cancelValue: '继续新增咨询',
  1215. cancel: function () {
  1216. window.location.href = "../../yszx/html/add-consult.html?type="+request.type+"&doctorCode=" + request.doctor;
  1217. }
  1218. }).showModal();
  1219. }else{
  1220. //跳转到新增咨询页面
  1221. window.location.href = "../../yszx/html/add-consult.html?type="+request.type+"&doctorCode=" + request.doctor;
  1222. }
  1223. }else{
  1224. queryFailed(res);
  1225. }
  1226. });
  1227. }
  1228. //获得患者信息判断用户是否已缴费
  1229. function getPatientInfo(){
  1230. d.show();
  1231. sendPost('patient/baseinfo', {}, 'json', 'post', queryFailed, function(res){
  1232. if (res.status == 200) {
  1233. expensesStatus = res.data.expensesStatus;
  1234. if(expensesStatus == 1){
  1235. //如果已经缴费 先判断医生是否在工作空间 若在泽可咨询 若不在则进行相关提示
  1236. querySignType(2);
  1237. }else{
  1238. //咨询问题的居民未缴费
  1239. limitZxTimes();
  1240. }
  1241. } else {
  1242. queryFailed(res);
  1243. }
  1244. });
  1245. }
  1246. //请求失败处理事件
  1247. function queryFailed(res, message){
  1248. d.close();
  1249. if(message){
  1250. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content: message}).show();
  1251. }else{
  1252. if (res && res.msg) {
  1253. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  1254. } else {
  1255. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载失败'}).show();
  1256. }
  1257. }
  1258. }