consulting-doctor.js 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335
  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. var params = {}
  531. params.code = consultCode;
  532. //发送ajax请求, 查询设备列表信息
  533. sendPost("patient/consult/finish", params, "json", "post", submitFailed3,finish_Successs);
  534. function finish_Successs(res){
  535. if (res.status == 200) {
  536. localStorage.setItem("evaluate",0);//标志未评价
  537. location.reload();
  538. }
  539. else{
  540. submitFailed3(res);
  541. }
  542. }
  543. },
  544. cancel: function () {
  545. return;
  546. }
  547. }).showModal();
  548. }
  549. function submitFailed3(res) {
  550. if (res && res.msg) {
  551. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:res.msg}).show();
  552. } else {
  553. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:'操作失败'}).show();
  554. }
  555. }
  556. //查看图片
  557. function viewImg(dom) {
  558. var $img = $(dom);
  559. var thissrc = $img.attr("src");
  560. var mWid = $(window).width();
  561. var mHei = $(window).height();
  562. 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>';
  563. $("body").append(nHtml);
  564. $(".delimgpop").click(function() {
  565. $(this).remove()
  566. });
  567. }
  568. //微信上传图片
  569. function chooseImageWx(){
  570. dd.showModal();
  571. wx.chooseImage({
  572. count: 3,
  573. success: function (res) {
  574. for (var i in res.localIds) {
  575. images.push(res.localIds[i]);
  576. }
  577. uploadImage();
  578. }
  579. });
  580. }
  581. function uploadImage(){
  582. if (images.length == 0) {
  583. dd.close();
  584. return;
  585. }
  586. var i = 0, length = images.length;
  587. serverId = "";
  588. var faillength = 0 ;
  589. function upload() {
  590. wx.uploadImage({
  591. localId: images[i],
  592. isShowProgressTips: 0,
  593. success: function (res) {
  594. faillength= 0;
  595. dd.close();
  596. i++;
  597. if(serverId.length == 0){
  598. serverId = res.serverId;
  599. }
  600. else{
  601. serverId =serverId + "," + res.serverId;
  602. }
  603. if (i < length) {
  604. upload();
  605. }
  606. if(i == images.length){
  607. sendImages();
  608. }
  609. },
  610. fail: function (res) {
  611. dd.close();
  612. faillength+=1;
  613. if(faillength<=5){
  614. //失败从传
  615. upload();
  616. }else{
  617. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:"图片上传失败,请控制发送频率"}).show();
  618. }
  619. }
  620. });
  621. }
  622. upload();
  623. }
  624. //保存图片
  625. function sendImages(){
  626. var now = new Date();
  627. //清空images
  628. images = [];
  629. timeStr = "";
  630. if(now.getMonth()<9){
  631. //补0
  632. timeStr = now.getFullYear() + "-0"+ (now.getMonth()+1) + "-" +now.getDate() +' '
  633. + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds();
  634. }else{
  635. timeStr = now.getFullYear() + "-"+ (now.getMonth()+1) + "-" +now.getDate() +' '
  636. + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds();
  637. }
  638. var data = {};
  639. data.consult = consultCode;
  640. data.content = "";
  641. data.mediaIds = serverId;
  642. data.type = 2;
  643. data.times = 0;
  644. dd.showModal();
  645. sendPost('patient/consult/append', data, 'json', 'post', submitFailed, submitImageSuccess);
  646. }
  647. function submitImageSuccess(res) {
  648. if (res.status == 200) {
  649. var data= JSON.parse(res.data)
  650. dd.close();
  651. addReply(2, data.content, timeStr, 2, "");
  652. dialroll.refresh();
  653. dialroll.scrollTo(0, dialroll.maxScrollY);
  654. } else {
  655. submitFailed(res);
  656. }
  657. }
  658. //function wslogin() {
  659. // var userid = patientcode;
  660. // var ws;
  661. // if (typeof MozWebSocket != "undefined") {
  662. // ws = new MozWebSocket(wsurl, 'netex');
  663. // } else {
  664. // ws = new WebSocket(wsurl, 'netex');
  665. // }
  666. //
  667. // function onopen() {
  668. // var reg = {};
  669. // reg.id = 'reg';
  670. // reg.uid = userid;
  671. // reg.pwd = '';
  672. // ws.send(JSON.stringify(reg));
  673. // }
  674. //
  675. // function onclose() {
  676. // // 断链重连
  677. // if (typeof MozWebSocket != "undefined") {
  678. // ws = new MozWebSocket(wsurl, 'netex');
  679. // } else {
  680. // ws = new WebSocket(wsurl, 'netex');
  681. // }
  682. // }
  683. // function onmessage(msg) {
  684. // var result = eval("("+msg.data+")");
  685. // if(result.msgid){
  686. // queryMsg(result.msgid,result.msgType);
  687. // }
  688. // }
  689. // ws.onopen = onopen;
  690. // ws.onmessage = onmessage;
  691. // ws.onclose = onclose;
  692. // }
  693. function playSoundEnd(){
  694. $playingDom.removeClass('active');
  695. $playingDom = null;
  696. }
  697. function playError(){
  698. var src = $('#audio').attr('src');
  699. if(!$.trim(src)) {
  700. return ;
  701. }
  702. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:"播放语音失败"}).show();
  703. $playingDom.removeClass('active');
  704. $playingDom = null;
  705. }
  706. function showSendBtn(isShow){
  707. if(isShow){
  708. $('.tw-add').hide();
  709. $('#reply').fadeIn('fast', 'swing');
  710. } else {
  711. $('#reply').fadeOut('fast', 'swing', function(){
  712. $('.tw-add').show();
  713. });
  714. }
  715. }
  716. function setSoundAlertVisable(show){
  717. if(show){
  718. ui.boxSoundAlert.style.display = 'block';
  719. ui.boxSoundAlert.style.opacity = 1;
  720. }else{
  721. ui.boxSoundAlert.style.opacity = 0;
  722. //fadeOut 完成再真正隐藏
  723. setTimeout(function(){
  724. ui.boxSoundAlert.style.display = 'none';
  725. },200);
  726. }
  727. };
  728. function recordErr(res){
  729. if(res && res.errMsg == "stopRecord:tooshort") {
  730. audio_tips.innerHTML = "录音时间太短";
  731. ui.boxSoundAlert.classList.add('rprogress-sigh');
  732. recordCancel = true;
  733. stopTimer=setTimeout(function(){
  734. setSoundAlertVisable(false);
  735. },500);
  736. startTimestamp = 0;
  737. //小于300ms,不录音
  738. if(recordTimer)clearTimeout(recordTimer);
  739. return;
  740. }
  741. if(!recordCancel){
  742. dialog({
  743. content:'录音失败,请重试',
  744. okValue:'我知道了',
  745. ok: function() {}
  746. }).showModal();
  747. }
  748. }
  749. //保存图片
  750. function sendSounds(times){
  751. var now = new Date();
  752. timeStr = "";
  753. if(now.getMonth()<9){
  754. //补0
  755. timeStr = now.getFullYear() + "-0"+ (now.getMonth()+1) + "-" +now.getDate() +' '
  756. + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds();
  757. }else{
  758. timeStr = now.getFullYear() + "-"+ (now.getMonth()+1) + "-" +now.getDate() +' '
  759. + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds();
  760. }
  761. var data = {};
  762. data.consult = consultCode;
  763. data.content = "";
  764. data.type = 3;
  765. data.times = times;
  766. wx.uploadVoice({
  767. localId: serverId,
  768. success: function (res) {
  769. data.voices = res.serverId;
  770. dd.showModal();
  771. sendPost('patient/consult/append', data, 'json', 'post', submitFailed,
  772. function submitSoundSuccess(res) {
  773. if (res.status == 200) {
  774. dd.close();
  775. var data = JSON.parse(res.data[0]);
  776. addReply(2, data.content, timeStr, 3, "");
  777. dialroll.refresh();
  778. dialroll.scrollTo(0, dialroll.maxScrollY);
  779. } else {
  780. submitFailed(res);
  781. }
  782. });
  783. }
  784. });
  785. }
  786. function bindConsultEvents(){
  787. //录制视频
  788. /*$(".lz-video-img").click(function(){
  789. $("#upload_input").click();
  790. //dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请录制10秒左右的短视频,以防录制完成后无法发送'}).show();
  791. return false;
  792. })*/
  793. //点击内容区域输入框失焦
  794. $('#talkwrap').click(function(){
  795. $("#input_content").blur();
  796. // dialroll.refresh();
  797. // dialroll.scrollTo(0, dialroll.maxScrollY);
  798. return false;
  799. });
  800. //发送以后定位至最底部
  801. $("#reply a").click(function() {
  802. send();
  803. });
  804. //立即发送
  805. $("#lijifasong").on("tap", function(){
  806. uploadVideo();
  807. mui('#sheet1').popover('toggle');
  808. return false;
  809. });
  810. //不再提醒
  811. $("#buzaitixing").on("tap", function(){
  812. window.localStorage.setItem("isTiXingVideoFaSong","1");
  813. uploadVideo();
  814. mui('#sheet1').popover('toggle');
  815. return false;
  816. });
  817. // window.localStorage.removeItem("isTiXingVideoFaSong");//测试
  818. $('.talk-box').on('click', '.word-bread img', function(){
  819. var src = $(this).attr('src')
  820. $(this).attr('src',src+'?'+$.now())
  821. if(!$(this).closest(".word-bread").hasClass("preview-video")){
  822. var urls = [];
  823. $.each($('.word-bread img'), function(i, v) {
  824. urls.push($(v).attr('src'));
  825. });
  826. wx.previewImage({
  827. current: $(this).attr('src'), // 当前显示图片的http链接
  828. urls: urls // 需要预览的图片http链接列表
  829. });
  830. }
  831. })
  832. .on('touchstart', '.audio', function(){
  833. if($playingDom){
  834. aud.pause();
  835. //aud.stop();
  836. $playingDom.removeClass('active');
  837. if($playingDom[0] == this){
  838. $playingDom = null;
  839. return;
  840. }
  841. }
  842. $playingDom = $(this);
  843. $playingDom.addClass('active');
  844. var ser = JSON.parse($(this).attr('data-audio'));
  845. aud.src = getImgUrl(ser.path);
  846. aud.load();
  847. aud.play();
  848. })
  849. .on('click','.preview-video',function() {
  850. $(document.body).find('video').remove();
  851. var url = $(this).attr('data-video');
  852. var html = '<video style="display: none;" controls preload="auto" width="1" height="1" src="'+url+'"></video>';
  853. $(document.body).append(html);
  854. var video = $(document.body).find('video')[0];
  855. video.play();
  856. });
  857. //键盘输入解决输入框被软键盘覆盖的问题
  858. var bfscrolltop = document.body.scrollTop;//获取软键盘唤起前浏览器滚动部分的高度
  859. var interval;
  860. $ipt_content.focus(function(){//当它获取焦点时触发事件
  861. $(".tw-add-detail").hide();
  862. interval = setInterval(function(){//设置一个计时器,时间设置与软键盘弹出所需时间相近
  863. document.body.scrollTop = document.body.scrollHeight;//获取焦点后将浏览器内所有内容高度赋给浏览器滚动部分高度
  864. },100)
  865. }).blur(function(){//设定输入框失去焦点时的事件
  866. clearInterval(interval);//清除计时器
  867. document.body.scrollTop = bfscrolltop; //将软键盘唤起前的浏览器滚动部分高度重新赋给改变后的高度
  868. });
  869. /**
  870. * 显示发送按钮的事件
  871. */
  872. $ipt_content.on('input', function(e){
  873. if($(this).prop('comstart')) {
  874. //console.log("true");
  875. return;
  876. }
  877. var text = $.trim($(this).text());
  878. showSendBtn(text.length > 0)
  879. }).on('compositionstart', function(){
  880. $(this).prop('comstart', true);
  881. //console.log('中文输入:开始');
  882. }).on('compositionend', function(){
  883. $(this).prop('comstart', false);
  884. // console.log('中文输入:结束');
  885. var text = $.trim($(this).text());
  886. showSendBtn(text.length > 0)
  887. })
  888. .on('tap', function(){
  889. $(".tw-add-detail").hide();
  890. // $ipt_content.focus();
  891. //mui.later(scrollToEnd, 300);
  892. })
  893. /*
  894. * 附加功能
  895. */
  896. $(".tw-add").click(function() {
  897. $(".tw-add-detail").toggle(200);
  898. });
  899. $('body')
  900. //隐藏打开的附加功能
  901. .on('tap', '#talkwrap', function(){
  902. $('.tw-add-detail').hide();
  903. $ipt_content.blur();
  904. })
  905. $(".yy-add").click(function() {
  906. if($('#msg-sound:visible').length){
  907. $ipt_content.show();
  908. ui.boxMsgSound.style.display = 'none';
  909. $(this).find('img:eq(0)').show().next().hide();
  910. } else {
  911. $ipt_content.hide();
  912. ui.boxMsgSound.style.display = 'block';
  913. $(this).find('img:eq(0)').hide().next().show();
  914. }
  915. });
  916. $("body").on('tap', '.word-article', function(){
  917. var type = $(this).attr('data-inner-type');
  918. var code = $(this).attr('data-code');
  919. if(type == 2){
  920. window.location.href = "../../yszd/html/guidance-detail.html?id="+code;
  921. } else{
  922. //根据时间判断该文章是旧的文章还是改造后发送的文章,时间是:2017-12-29 00:00:00
  923. var sendTimeStr = $(this).attr("Data-code"),
  924. sendTime = new Date(sendTimeStr),
  925. cDate = new Date("2017-12-29 00:00:00");
  926. if(sendTime < cDate){
  927. window.location.href = "../../jkjy/html/article.html?dataId="+code;
  928. }else{
  929. window.location.href = "../../jkjy/html/article2.html?dataId="+code;
  930. }
  931. }
  932. });
  933. $(".xzzx").on('tap', function(){
  934. //获取患者信息 判断该患者是否已经缴费 若缴费则正常咨询 未缴费提示咨询次数信息
  935. getPatientInfo();
  936. })
  937. ui.boxMsgSound.addEventListener("touchstart", function(e) {
  938. e.preventDefault();
  939. event.preventDefault();
  940. $(this).addClass('yy-hold');
  941. if(stopTimer)clearTimeout(stopTimer);
  942. recordCancel = false;
  943. audio_tips.innerHTML = "手指上划,取消发送";
  944. ui.boxSoundAlert.classList.remove('rprogress-sigh');
  945. setSoundAlertVisable(true);
  946. startTimestamp = new Date().getTime();
  947. recordTimer = setTimeout(function(){
  948. wx.startRecord({
  949. success: function(){
  950. realStartTime = new Date().getTime();
  951. },
  952. fail: recordErr
  953. });
  954. wx.onVoiceRecordEnd({
  955. // 录音时间超过一分钟没有停止的时候会执行 complete 回调
  956. complete: function (res) {
  957. serverId = res.localId;
  958. sendSounds(60);
  959. },
  960. fail: recordErr
  961. });
  962. },MIN_SOUND_TIME);
  963. }, false);
  964. ui.boxMsgSound.addEventListener("touchend", function(e){
  965. e.preventDefault();
  966. event.preventDefault();
  967. $(this).removeClass('yy-hold');
  968. if (audio_tips.classList.contains("cancel")) {
  969. audio_tips.classList.remove("cancel");
  970. audio_tips.innerHTML = "手指上划,取消发送";
  971. }
  972. var endTimestamp = new Date().getTime();
  973. var times = endTimestamp - startTimestamp;
  974. var realTimes = endTimestamp - realStartTime;
  975. if(times < MIN_SOUND_TIME || realTimes < MIN_SOUND_TIME){
  976. audio_tips.innerHTML = "录音时间太短";
  977. ui.boxSoundAlert.classList.add('rprogress-sigh');
  978. recordCancel = true;
  979. stopTimer=setTimeout(function(){
  980. setSoundAlertVisable(false);
  981. },500);
  982. startTimestamp = 0;
  983. realStartTime = 0;
  984. //小于300ms,不录音
  985. clearTimeout(recordTimer);
  986. wx.stopRecord({
  987. success: function (res) {
  988. },
  989. fail: function(){}
  990. });
  991. }else{
  992. setSoundAlertVisable(false);
  993. wx.stopRecord({
  994. success: function (res) {
  995. if(!recordCancel) {
  996. serverId = res.localId;
  997. sendSounds(Math.round(times/1000));
  998. }
  999. },
  1000. fail: recordErr
  1001. });
  1002. }
  1003. }, false)
  1004. ui.body.addEventListener('drag', function(event) {
  1005. if (Math.abs(event.detail.deltaY) > 50) {
  1006. if (!recordCancel) {
  1007. recordCancel = true;
  1008. if (!audio_tips.classList.contains("cancel")) {
  1009. audio_tips.classList.add("cancel");
  1010. }
  1011. audio_tips.innerHTML = "松开手指,取消发送";
  1012. }
  1013. } else {
  1014. if (recordCancel) {
  1015. recordCancel = false;
  1016. if (audio_tips.classList.contains("cancel")) {
  1017. audio_tips.classList.remove("cancel");
  1018. }
  1019. audio_tips.innerHTML = "手指上划,取消发送";
  1020. }
  1021. }
  1022. }, false);
  1023. }
  1024. //录制视频回调
  1025. function videoFileChange(target) {
  1026. var fileSize = (target.files[0].size/1024/1024).toFixed(2);//字节转换成M
  1027. if(parseInt(fileSize)>30){
  1028. dialog({
  1029. content:'对不起,视频超过30Mb,无法发送,请录制10秒左右的短视频',
  1030. okValue:'我知道了',
  1031. ok: function() {
  1032. return;
  1033. }
  1034. }).showModal();
  1035. }else{
  1036. if(networkStatus=="wifi" || window.localStorage.getItem("isTiXingVideoFaSong")=="1"){//wifi环境或用户点击移动网络弹框中的”不再提醒“按钮
  1037. uploadVideo();
  1038. }else{
  1039. $("#mui-content").html('您正在使用移动网络,继续发送将消耗'+fileSize+'Mb流量,是否继续发送?');
  1040. mui('#sheet1').popover('toggle');
  1041. }
  1042. }
  1043. }
  1044. //上传视频
  1045. function uploadVideo(){
  1046. dd.showModal();
  1047. var fd=new FormData();
  1048. fd.append('file',document.getElementById("upload_input").files[0]);
  1049. $.ajax(server+"/upload/chat?type=4", {
  1050. data: fd,
  1051. contentType: false,
  1052. cache: false,
  1053. processData: false,
  1054. type: 'post',
  1055. success: function(resData) {
  1056. if(resData.status==200){
  1057. var data = {consult:consultCode,content:resData.urls,type:12};
  1058. sendPost('patient/consult/append', data, 'json', 'post', submitFailed,
  1059. function submitSoundSuccess(res) {
  1060. if (res.status == 200) {
  1061. dd.close();
  1062. var data = JSON.parse(res.data[0]);
  1063. addReply(2, data.content, new Date(data.timestamp).Format('yyyy-MM-dd HH:mm:ss'), 12, "");
  1064. dialroll.refresh();
  1065. dialroll.scrollTo(0, dialroll.maxScrollY);
  1066. } else {
  1067. submitFailed(res);
  1068. }
  1069. });
  1070. }else{
  1071. dd.close();
  1072. }
  1073. },
  1074. error:function (XMLHttpRequest, textStatus, errorThrown) {
  1075. console.log(XMLHttpRequest.status);
  1076. console.log(XMLHttpRequest.readyState);
  1077. console.log(textStatus)
  1078. }
  1079. });
  1080. }
  1081. Date.prototype.format = function(fmt) { //author: meizz
  1082. var o = {
  1083. "M+": this.getMonth() + 1, //月份
  1084. "d+": this.getDate(), //日
  1085. "h+": this.getHours(), //小时
  1086. "m+": this.getMinutes(), //分
  1087. "s+": this.getSeconds(), //秒
  1088. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  1089. "S": this.getMilliseconds() //毫秒
  1090. };
  1091. if (/(y+)/.test(fmt))
  1092. fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  1093. for (var k in o)
  1094. if (new RegExp("(" + k + ")").test(fmt))
  1095. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  1096. return fmt;
  1097. }
  1098. //未缴费居民限制咨询次数
  1099. function limitZxTimes(){
  1100. //获取剩余家庭咨询次数
  1101. var url = '/patient/consult/remainConsultTimes';
  1102. var remainTimes;//剩余咨询次数
  1103. var countTimes;//总咨询次数
  1104. var zxTimes;//已咨询次数
  1105. d.show();
  1106. sendPost(url, {}, 'json', 'get', queryFailed, function(res){
  1107. if(res.status == 200){
  1108. d.close();
  1109. remainTimes = res.data.amount;
  1110. countTimes = res.data.count;
  1111. zxTimes = countTimes - remainTimes;
  1112. if(zxTimes == countTimes){
  1113. //未缴费的总咨询次数已达上限 提示去缴费
  1114. dialog({
  1115. content: '您本年度家庭医生签约暂未缴费,当前10次免费健康咨询已全部使用.如果需要家庭医生继续为您提供服务,请尽快完成缴费操作',
  1116. okValue:'前往缴费',
  1117. ok: function (){
  1118. window.location.href = "signing_management.html";
  1119. }
  1120. }).showModal();
  1121. }else{
  1122. dialog({
  1123. content: '您本年度家庭医生签约暂未缴费,可使用10次免费健康咨询,当前剩余:'+remainTimes+'次.为避免影响您的服务体验,请尽快完成缴费操作',
  1124. okValue:'前往缴费',
  1125. ok: function (){
  1126. window.location.href = "signing_management.html";
  1127. },
  1128. cancelValue: '开始咨询',
  1129. cancel: function () {
  1130. querySignType(2)
  1131. }
  1132. }).showModal();
  1133. }
  1134. }else{
  1135. queryFailed(res);
  1136. }
  1137. });
  1138. }
  1139. //查询签约类型
  1140. function querySignType(type){
  1141. chooseType = type;
  1142. d.show();
  1143. sendPost('patient/sign_doctors', {}, 'json', 'post', function(res){
  1144. queryFailed(res, '获取咨询类型失败');
  1145. }, querySignTypeSuccess);
  1146. }
  1147. //查询签约类型成功回调处理事件
  1148. function querySignTypeSuccess(res){
  1149. if (res.status == 200) {
  1150. d.close();
  1151. var doctors = "";
  1152. switch(Number(chooseType)) {
  1153. case 1: doctors = res.teamDoctors; break;
  1154. case 2: doctors = res.familyDoctors; break;
  1155. default: break;
  1156. }
  1157. var docInfo,docQkInfo;
  1158. $.each(doctors, function(i, v) {
  1159. if(v.teamlevel){
  1160. if(v.teamlevel == 3){
  1161. docInfo = v;
  1162. }
  1163. if(v.teamlevel == 2){
  1164. docQkInfo = v;
  1165. }
  1166. }else{
  1167. if(v.level == 3){
  1168. docInfo = v;
  1169. }
  1170. if(v.level == 2){
  1171. docQkInfo = v;
  1172. }
  1173. }
  1174. });
  1175. if(!docInfo){
  1176. docInfo = docQkInfo;
  1177. }
  1178. checkDocInWork(chooseType, docInfo,docQkInfo)
  1179. }else {
  1180. queryFailed(res);
  1181. }
  1182. }
  1183. //获取签约医生的工作时间
  1184. function checkDocInWork(type, doctor,docQkInfo){
  1185. var url = 'patient/consult/isDoctorWorkWhenconsult',
  1186. params = {doctor:docQkInfo.code,healthDoctor:doctor.code};
  1187. sendPost(url, params, 'json', 'post', queryFailed, function(res){
  1188. if(res.status == 200){
  1189. // data:0-医生不接受咨询/1-医生当前接受咨询/2-全科医生和健管师当前都不在工作时间/3-全科医生当前不在工作时间/4-健管师当前不在工作时间 健管师当前不在工作时间
  1190. if(res.data==2){
  1191. dialog({
  1192. content: '您好,由于您的签约医生工作繁忙,设置了每日回复咨询的时间段,所以,在该时间段外的时间,您的咨询将不会马上获得医生的回复。',
  1193. okValue:'查看医生工作时间',
  1194. ok: function (){
  1195. window.location.href = "../../yszx/html/doctor-work-hours.html?doctor=" + docQkInfo.code+"&healthDoctor="+doctor.code;
  1196. },
  1197. cancelValue: '继续新增咨询',
  1198. cancel: function () {
  1199. window.location.href = "../../yszx/html/add-consult.html?type="+request.type+"&doctorCode=" + request.doctor;
  1200. }
  1201. }).showModal();
  1202. }else if(res.data==3){
  1203. dialog({
  1204. content: '您好,由于您的签约全科医生工作繁忙……,您的咨询将不会马上获得全科医生的回复 。',
  1205. okValue:'查看医生工作时间',
  1206. ok: function (){
  1207. window.location.href = "../../yszx/html/doctor-work-hours.html?doctor=" + docQkInfo.code+"&healthDoctor="+doctor.code;
  1208. },
  1209. cancelValue: '继续新增咨询',
  1210. cancel: function () {
  1211. window.location.href = "../../yszx/html/add-consult.html?type="+request.type+"&doctorCode=" + request.doctor;
  1212. }
  1213. }).showModal();
  1214. }else if(res.data==4){
  1215. dialog({
  1216. content: '您好,由于您的签约健康管理师工作繁忙……,您的咨询将不会马上获得健康管理师的回复 。',
  1217. okValue:'查看医生工作时间',
  1218. ok: function (){
  1219. window.location.href = "../../yszx/html/doctor-work-hours.html?doctor=" + docQkInfo.code+"&healthDoctor="+doctor.code;
  1220. },
  1221. cancelValue: '继续新增咨询',
  1222. cancel: function () {
  1223. window.location.href = "../../yszx/html/add-consult.html?type="+request.type+"&doctorCode=" + request.doctor;
  1224. }
  1225. }).showModal();
  1226. }else{
  1227. //跳转到新增咨询页面
  1228. window.location.href = "../../yszx/html/add-consult.html?type="+request.type+"&doctorCode=" + request.doctor;
  1229. }
  1230. }else{
  1231. queryFailed(res);
  1232. }
  1233. });
  1234. }
  1235. //获得患者信息判断用户是否已缴费
  1236. function getPatientInfo(){
  1237. d.show();
  1238. sendPost('patient/baseinfo', {}, 'json', 'post', queryFailed, function(res){
  1239. if (res.status == 200) {
  1240. expensesStatus = res.data.expensesStatus;
  1241. if(expensesStatus == 1){
  1242. //如果已经缴费 先判断医生是否在工作空间 若在泽可咨询 若不在则进行相关提示
  1243. querySignType(2);
  1244. }else{
  1245. //咨询问题的居民未缴费
  1246. limitZxTimes();
  1247. }
  1248. } else {
  1249. queryFailed(res);
  1250. }
  1251. });
  1252. }
  1253. //请求失败处理事件
  1254. function queryFailed(res, message){
  1255. d.close();
  1256. if(message){
  1257. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content: message}).show();
  1258. }else{
  1259. if (res && res.msg) {
  1260. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  1261. } else {
  1262. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'加载失败'}).show();
  1263. }
  1264. }
  1265. }