consulting-doctor.js 46 KB

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