consulting-doctor.js 49 KB

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