consulting-doctor.js 47 KB

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