consulting-doctor.js 46 KB

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