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. id = 1;
  50. var reqList = [{
  51. //判断当前是否有未结束的咨询
  52. url:'/patient/consult/is_consult_unfinished',
  53. reqType:'POST',
  54. data:{doctor: request.doctor}
  55. },{
  56. //获得会话窗口的用户的头像等信息
  57. url: '/patient/consult/participants',
  58. reqType: 'POST',
  59. data: {
  60. sessionId: patientcode+"_"+request.doctor+"_1"
  61. }
  62. },{
  63. //获得咨询记录
  64. url: '/patient/consult/logs',
  65. reqType: 'POST',
  66. data: {
  67. sessionId: patientcode+"_"+request.doctor+"_1",
  68. startMsgId:"",
  69. endMsgId: "",
  70. page: id,
  71. pagesize: pagesize
  72. }
  73. }];
  74. isRenew = request.isRenew;
  75. getReqPromises(reqList).then(function(res){
  76. // if(isRenew == 1){
  77. // d.close();
  78. // $("#input_div").hide();
  79. // $("#finish_list").hide();
  80. // $(".xzzx").hide();
  81. // winSize(125); //70+45
  82. // }else{
  83. doResponse(res);
  84. // }
  85. });
  86. var userAgent1 = JSON.parse(window.localStorage.getItem(agentName1));
  87. patientName = userAgent1.name;
  88. },
  89. bindEvents: bindConsultEvents
  90. };
  91. //请求回调处理
  92. function doResponse(res){
  93. var res1 = res[0],
  94. res2 = res[1],
  95. res3 = res[2];
  96. if(res1.status == 200 && res2.status == 200 && res3.status == 200){
  97. d.close();
  98. loadSocket();
  99. if(res1.data == ""){
  100. //无正在进行中的咨询
  101. $("#input_div").hide();
  102. $("#finish_list").hide();
  103. $(".xzzx").show();
  104. winSize(125); //70+45
  105. //-1患者已取消,-2已拒绝,-3已解约,-4已到期
  106. switch(request.status){
  107. case "-1":
  108. case "-2":
  109. case "-3":
  110. case "-4":
  111. $(".xzzx").hide();
  112. winSize(45);
  113. break;
  114. }
  115. }else if(res1.data){
  116. //有正在咨询中的问卷
  117. $("#input_div").show();
  118. $("#finish_list").show();
  119. $(".xzzx").hide();
  120. consultCode = res1.data;
  121. //提示谁进入咨询
  122. var data = {
  123. consult:consultCode
  124. }
  125. sendPost('patient/consult/intoTopic', data, "json", "post", null,function(res){})
  126. winSize(167); //102+45
  127. }
  128. participants = res2.list;
  129. var pulldownAction = function() {
  130. getConsultLog();
  131. };
  132. dialroll = iscrollAssist.newVerScrollForPull($('.pull-iscroll-wrap'), pulldownAction, null);
  133. dialroll.refresh();
  134. dialroll.scrollTo(0, dialroll.maxScrollY);
  135. querySuccess2(res3, false);
  136. }else{
  137. queryFailed2();
  138. }
  139. }
  140. //加载socket组件
  141. function loadSocket(){
  142. jQuery.getScript(imurl+"/socket.io/socket.io.js").done(function() {
  143. var socket = io.connect(imurl);
  144. var sessionId = patientcode+"_"+request.doctor+"_1";
  145. var userInfo = JSON.parse(window.localStorage.getItem(agentName));
  146. socket.emit('login', {userId: userInfo.represented?userInfo.represented:userInfo.uid, password: userInfo.represented?userInfo.represented:userInfo.uid,sessionId:sessionId,clientType:"patient"});
  147. socket.on('message', function (data) {
  148. // console.log(data)
  149. if((data.type == 1) ||(data.type == 2) || (data.type == 3) || (data.type == 6) || (data.type == 12)){
  150. addReply(1, data.content, new Date(data.timestamp).Format('yyyy-MM-dd HH:mm:ss'), data.type, data.name, getImgUrl(data.sender_img));
  151. // setTimeout(function(){
  152. dialroll.refresh();
  153. dialroll.scrollTo(0, dialroll.maxScrollY);
  154. // },300)
  155. }
  156. });
  157. socket.on('error', function (data) {
  158. // console.log(data);
  159. });
  160. socket.on('ack', function (data) {
  161. // console.log(data);
  162. });
  163. function getLocalTime(nS) {
  164. return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ');
  165. }
  166. })
  167. .fail(function() {
  168. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:"医生实时对话连接失败!"}).show();
  169. });
  170. }
  171. //获得咨询记录
  172. function getConsultLog(){
  173. var url = "/patient/consult/logs",
  174. params = {
  175. sessionId: patientcode+"_"+request.doctor+"_1",
  176. startMsgId:"",
  177. endMsgId: "",
  178. page: id,
  179. pagesize: pagesize
  180. };
  181. d.show();
  182. sendPost(url, params, "json", "post", queryFailed2, function(res){
  183. querySuccess2(res, true);
  184. });
  185. }
  186. //控制“发送”按钮的变化
  187. function sendBtn() {
  188. var tval = $(".talk-input input").val();
  189. if (tval != "") {
  190. $(".talk-send a").removeClass("disab");
  191. } else {
  192. $(".talk-send a").addClass("disab");
  193. }
  194. }
  195. //控制页面高度
  196. function winSize(h) {
  197. var totH = $(window).height();
  198. $("#talkwrap").height(totH - h);
  199. }
  200. function queryMsg(logId,msgType){
  201. var data={};
  202. data.consult = consultCode;
  203. data.logId = logId;
  204. data.msgType=msgType;
  205. sendPost('patient/consult/oneLog', data, 'json', 'GET', queryFailed2, function(res){
  206. if(res.status==200){
  207. var reply = res.consult;
  208. if((reply.msgType == 1) || (reply.msgType == 2) || (reply.msgType == 6)){
  209. addReply(reply.type, reply.content, reply.time, reply.msgType, reply.doctorName, reply.photo);
  210. setTimeout(function(){
  211. dialroll.refresh();
  212. dialroll.scrollTo(0, dialroll.maxScrollY);
  213. },300)
  214. }
  215. }
  216. d.close();
  217. });
  218. }
  219. function queryFailed2(res) {
  220. d.close();
  221. if (res && res.msg) {
  222. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:res.msg}).show();
  223. } else {
  224. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:'加载失败'}).show();
  225. }
  226. }
  227. function querySuccess2(res, prepend) {
  228. if (res.status == 200) {
  229. id++;
  230. var list = res.list;
  231. if (list && list.length > 0) {
  232. for (var j = list.length-1; j >=0; j--) {
  233. var reply = JSON.parse(list[j]);
  234. //屏蔽全科医生求助专科医生的消息
  235. if(reply.content_type != 5){
  236. var date = new Date();
  237. date.setTime(reply.timestamp);
  238. var time = date.format('yyyy-MM-dd hh:mm:ss');
  239. var p;
  240. for(var k in participants){
  241. if(participants[k].id==reply.sender_id)
  242. p = participants[k].avatar;
  243. }
  244. var isSystem = reply.sender_id == 'system';
  245. addReply(reply.sender_id==patientcode? 2 : 1, reply.content, time, reply.content_type, reply.sender_name, p, prepend, isSystem);
  246. }
  247. }
  248. dialroll.refresh();
  249. if(!prepend){
  250. dialroll.scrollTo(0, dialroll.maxScrollY);
  251. }
  252. }else{
  253. dialroll.refresh();
  254. }
  255. d.close();
  256. }
  257. else{
  258. queryFailed2(res);
  259. }
  260. }
  261. function getNowFormatDate() {
  262. var date = new Date();
  263. var seperator1 = "-";
  264. var seperator2 = ":";
  265. var month = date.getMonth() + 1;
  266. var strDate = date.getDate();
  267. if (month >= 1 && month <= 9) {
  268. month = "0" + month;
  269. }
  270. if (strDate >= 0 && strDate <= 9) {
  271. strDate = "0" + strDate;
  272. }
  273. var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
  274. + " " + date.getHours() + seperator2 + date.getMinutes()
  275. + seperator2 + date.getSeconds();
  276. return currentdate;
  277. }
  278. //点击发送按钮
  279. function send(){
  280. content = $("#input_content").text().replace(/\s+/g,"");
  281. if (content && content != null && content != "") {
  282. var now = new Date();
  283. timeStr = "";
  284. if(now.getMonth()<9){
  285. //补0
  286. timeStr = now.getFullYear() + "-0"+ (now.getMonth()+1) + "-" +now.getDate() +' '
  287. + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds();
  288. }else{
  289. timeStr = now.getFullYear() + "-"+ (now.getMonth()+1) + "-" +now.getDate() +' '
  290. + now.getHours() + ":" +now.getMinutes() + ":" +now.getSeconds();
  291. }
  292. $("#input_content").blur();
  293. dialroll.refresh();
  294. dialroll.scrollTo(0, dialroll.maxScrollY);
  295. dd.showModal();
  296. var data = {};
  297. data.consult = consultCode;
  298. data.content = utf16toEntities(content);
  299. data.type = 1;
  300. sendPost('patient/consult/append', data, 'json', 'post', submitFailed, submitSuccess);
  301. } else {
  302. return;
  303. }
  304. }
  305. function submitFailed(res) {
  306. dd.close();
  307. if (res && res.msg) {
  308. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:res.msg}).show();
  309. } else {
  310. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:'发送失败'}).show();
  311. }
  312. }
  313. function submitSuccess(res) {
  314. if (res.status == 200) {
  315. //置空
  316. $("#input_content").text("");
  317. $(".talk-send a").addClass("disab");
  318. addReply(2, content, timeStr, 1, "");
  319. dialroll.refresh();
  320. dialroll.scrollTo(0, dialroll.maxScrollY);
  321. showSendBtn(false);
  322. dd.close();
  323. } else {
  324. submitFailed(res);
  325. }
  326. }
  327. //回复单条内容填写
  328. var defaultPhoto = "../../../images/p-default.png";
  329. var doctorDefaultPhoto = "../../../images/d-default.png";
  330. function addReply(isDoctor, content, time, msgType, doctorName,photo,prepend, isSystem) {
  331. //time = time.substr(10);
  332. var doctorPhoto = photo ? getImgUrl(photo) : doctorDefaultPhoto;
  333. var $div = $("<dl></dl>");
  334. if(msgType == 7 || msgType == 10 || msgType == 13 ||msgType == 14){
  335. if(msgType == 7 && isSystem){
  336. content = "您24小时内未回复,系统自动结束咨询";
  337. }
  338. if(prepend){
  339. $(".talk-box").prepend('<div class="time-tips"><span class="xt-xiaoxi">' + content + '</span></div>');
  340. } else
  341. $(".talk-box").append('<div class="time-tips"><span class="xt-xiaoxi">' + content + '</span></div>');
  342. return;
  343. }
  344. if (isDoctor == 1) {
  345. $div.addClass('chat-left');
  346. img = doctorPhoto;
  347. name = doctorName;
  348. } else {
  349. $div.addClass('chat-right');
  350. img = photo? getImgUrl(photo):defaultPhoto;
  351. defaultPhoto = img;
  352. name = patientName;
  353. }
  354. var temp = '<dt style="height: auto; text-align: center;"><a><img src="' + img + '" class="c-images-cycle" /></a></dt>' +
  355. '<div class="c-content"><span class="c-f12 name">' + name + '</span>'
  356. switch(parseInt(msgType)) {
  357. case 0: //签约信息
  358. case 1://信息
  359. case 6://咨询问题
  360. temp += '<dd class="word-bread"><span>' + content + '</span>';
  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. }