consulting-doctor.js 46 KB

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