prescription-consulting.js 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213
  1. var d = dialog({contentType:'load', skin:'bk-popup'});
  2. var dd = dialog({contentType:'load', skin:'bk-popup', content:'发送中...'});
  3. var dialroll;
  4. var doctorInfo;
  5. var content = "";
  6. var timeStr = "";
  7. var id = 1;
  8. var pagesize = 100;
  9. var Request = new Object();
  10. Request = GetRequest();
  11. var consult = Request["consult"];
  12. var status = Request["status"];
  13. var consultType = Request["type"]; //咨询类型,1-三师咨询,2-家庭咨询, 6-名医咨询, 8-续方咨询
  14. var doctor = Request['doctor'];
  15. var toUser = Request["toUser"];
  16. var toName = decodeURIComponent(Request["toName"]);
  17. var openid = Request["openid"];
  18. var represented = Request["represented"];
  19. var evaluate = localStorage.getItem("evaluate");//1为有评价 0为无评价
  20. var prescriptionCode;
  21. var docMsg = 0;
  22. var patientcode = '';
  23. var networkStatus = "";
  24. var userAgent = window.localStorage.getItem(agentName);
  25. var userInfo = JSON.parse(window.localStorage.getItem(agentName));
  26. //回复单条内容填写
  27. var defaultPhoto = "../../../images/p-default.png";
  28. var doctorDefaultPhoto = "../../../images/d-default.png";
  29. var presciptionStatus = 0; //标记续方状态
  30. mui.init({
  31. gestureConfig:{
  32. hold:true,//默认为false,不监听
  33. release:true//默认为false,不监听
  34. }
  35. });
  36. //页面初始化
  37. $(function(){
  38. isRepresent(function(){
  39. pageInit();
  40. })
  41. })
  42. function pageInit(){
  43. patientcode = userInfo.represented ? userInfo.represented : userInfo.uid;
  44. createSocketConnect();
  45. checkStatus();
  46. getPrescriptionDetail();
  47. getWXSign();
  48. bindEvents();
  49. }
  50. //im建立socket连接
  51. function createSocketConnect(){
  52. //获取sessionId
  53. sendPost('/patient/consult/getTopic', {consult:consult}, 'json', 'GET', queryFailed, function(res){
  54. if(res.status==200){
  55. var sessionId = JSON.parse(res.msg)[0].session_id;
  56. //登录IM
  57. sendPost('/patient/consult/intoTopic', {consult: consult}, 'json', 'get', queryFailed, function(res){});
  58. //加载socket组件
  59. jQuery.getScript(imurl+"/socket.io/socket.io.js").done(function() {
  60. var socket = io.connect(imurl);
  61. var userInfo = JSON.parse(window.localStorage.getItem(agentName));
  62. var uid = userInfo.represented ? userInfo.represented : userInfo.uid;
  63. socket.emit('login', {
  64. userId: uid,
  65. password: uid,
  66. sessionId:sessionId,
  67. clientType:"patient"
  68. });
  69. socket.on('message', function (data) {
  70. console.log(data)
  71. if((data.type == 1) ||(data.type == 2) || (data.type == 6) || (data.type == 12) || (data.type == 7) || (data.type == 15)){
  72. addReply(1, data.content, new Date(data.timestamp).Format('yyyy-MM-dd HH:mm:ss'), data.type, data.name,data.sender_img);
  73. setTimeout(function(){
  74. dialroll.refresh();
  75. dialroll.scrollTo(0, dialroll.maxScrollY);
  76. },300)
  77. }
  78. if((data.type == 16)||(data.type == 17)){
  79. if(data.sender_id == patientcode){
  80. addReply(2, data.content, new Date(data.timestamp).Format('yyyy-MM-dd HH:mm:ss'), data.type, data.name,data.sender_img);
  81. }else{
  82. addReply(1, data.content, new Date(data.timestamp).Format('yyyy-MM-dd HH:mm:ss'), data.type, data.name,data.sender_img);
  83. }
  84. setTimeout(function(){
  85. dialroll.refresh();
  86. dialroll.scrollTo(0, dialroll.maxScrollY);
  87. },300)
  88. }
  89. });
  90. socket.on('error', function (data) {
  91. });
  92. socket.on('ack', function (data) {
  93. });
  94. // function getLocalTime(nS) {
  95. // return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ');
  96. // }
  97. }).fail(function() {
  98. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:"医生实时对话连接失败!"}).show();
  99. });
  100. }
  101. });
  102. }
  103. //判断咨询记录的状态
  104. function checkStatus(){
  105. d.show();
  106. var url = 'patient/consult/status',
  107. data = {consult: consult};
  108. sendPost(url, data, 'json', 'get', queryFailed, queryStatusSuccess);
  109. }
  110. //获取咨询状态成功回调处理
  111. function queryStatusSuccess(res){
  112. if(res.status == 200) {
  113. if(res.data == 0){ //咨询未结束
  114. $("#divBottom").show();
  115. $("#finish_list").show();
  116. $("#input_div").show();
  117. winSize(165); // 110+55
  118. }else{ //咨询已结束
  119. $("#divBottom").hide();
  120. $("#finish_list").hide();
  121. $("#input_div").hide();
  122. winSize(75);
  123. //显示评价按钮
  124. if(evaluate == 0){
  125. $('#valFoot').show();
  126. $('#noval').show();
  127. $('#hasval').hide();
  128. }else if(evaluate == 1){
  129. $('#valFoot').show();
  130. $('#noval').hide();
  131. $('#hasval').show();
  132. }
  133. }
  134. status = res.data;
  135. //聊天记录填充
  136. queryList();
  137. var pulldownAction = function() {
  138. getPage(this);
  139. };
  140. dialroll = iscrollAssist.newVerScrollForPull($('.pull-iscroll-wrap'), pulldownAction, null);
  141. dialroll.refresh();
  142. dialroll.scrollTo(0, dialroll.maxScrollY);
  143. d.close();
  144. } else {
  145. queryFailed(res);
  146. }
  147. }
  148. //获得续方详情
  149. function getPrescriptionDetail(){
  150. var url = "/patient/consult/prescriptionDetail",
  151. params = {consult: consult};
  152. sendPost(url, params, 'json', 'get', queryFailed, function(res){
  153. if(res.status == 200){
  154. res.data.statusName = getStatusName(res.data.status);
  155. presciptionStatus = res.data.status;
  156. var html = template('prescription_tmp', res.data);
  157. $("#prescriptionInfo").empty().append(html);
  158. $("#prescriptionInfo").attr("data-code", res.data.code);
  159. prescriptionCode = res.data.code;
  160. }else{
  161. queryFailed(res);
  162. }
  163. });
  164. }
  165. //查询咨询记录
  166. function queryList(){
  167. var url = 'patient/consult/loglist',
  168. data = {
  169. consult: consult,
  170. page: id,
  171. pagesize: pagesize
  172. };
  173. sendPost(url, data, 'json', 'GET', queryFailed, queryListSuccess);
  174. }
  175. //查询咨询记录成功的回调处理
  176. function queryListSuccess(res){
  177. if (res.status == 200) {
  178. id++;
  179. var data = res.list;
  180. var docCode;
  181. for(var k in data.users){
  182. if(data.users[k].is_patient == 0){
  183. docCode = data.users[k].id;
  184. }
  185. }
  186. var list = data.list;
  187. if (list && list.length > 0) {
  188. docMsg = list[list.length - 1].content_type;
  189. for (var j = list.length-1; j >=0; j--) {
  190. var reply = JSON.parse(list[j]);
  191. // console.log(reply)
  192. // TODO 判断咨询回复的类型,区别是否显示在患者端
  193. if((reply.content_type == 3) || (reply.content_type == 1) || (reply.content_type == 2) || (reply.content_type == 6) || (reply.content_type == 12) || (reply.content_type == 7)|| (reply.content_type == 15)|| (reply.content_type == 16)|| (reply.content_type == 17)){
  194. var date = new Date();
  195. date.setTime(reply.timestamp);
  196. var time = date.format('yyyy-MM-dd hh:mm:ss');
  197. var p;
  198. for(var k in data.users){
  199. if(data.users[k].id==reply.sender_id){
  200. p = data.users[k].avatar;
  201. }
  202. }
  203. var isSystem = reply.sender_id == 'system';
  204. //第一个参数为1时,医生发的
  205. addReply(reply.sender_id==patientcode? 2 : 1, reply.content, time, reply.content_type, reply.sender_name, p, false, isSystem);
  206. }
  207. }
  208. dialroll.refresh();
  209. dialroll.scrollTo(0, dialroll.maxScrollY);
  210. }
  211. if(status==0){
  212. checkDoctorInWork(docCode);
  213. }
  214. d.close();
  215. }
  216. else{
  217. queryFailed(res);
  218. }
  219. }
  220. //判断医生是否在工作时间内
  221. function checkDoctorInWork(doctor){
  222. var url = 'patient/consult/is_doctor_working';
  223. sendPost(url, {doctor:doctor}, 'json', 'post', queryFailed, function(res){
  224. if(res.status==200){
  225. if(res.data!=1){
  226. var time = (new Date()).Format('yyyy-MM-dd hh:mm:ss');
  227. addReply(1, "医生不在工作时间,无法及时回复您的消息。<br/><a class='workhours' href='#'>查看工作时间!</a>", time, 7, "系统消息");
  228. $(".workhours").on("click",function(){
  229. location.href='doctor-work-hours.html?doctor='+doctor;
  230. });
  231. setTimeout(function(){
  232. dialroll.refresh();
  233. dialroll.scrollTo(0, dialroll.maxScrollY);
  234. },20);
  235. }
  236. }else{
  237. queryFailed(res);
  238. }
  239. });
  240. }
  241. function queryFailed(res, msg){
  242. d.close();
  243. dd.close();
  244. if(msg){
  245. dialog({contentType:'tipsbox', skin:'bk-popup' , bottom:true,content: msg}).show();
  246. }else{
  247. if (res && res.msg) {
  248. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:res.msg}).show();
  249. } else {
  250. dialog({contentType:'tipsbox', skin:'bk-popup' , bottom:true,content:'加载失败'}).show();
  251. }
  252. }
  253. }
  254. //点击发送按钮事件
  255. function send(){
  256. content = $("#input_content").text().replace(/\s+/g,"");
  257. if (content && content != null && content != "") {
  258. var now = new Date(),
  259. timeStr = now.Format('yyyy-MM-dd hh:mm:ss');
  260. $("#input_content").blur();
  261. dialroll.refresh();
  262. dialroll.scrollTo(0, dialroll.maxScrollY);
  263. dd.showModal();
  264. var url = "patient/consult/append",
  265. data = {
  266. consult: consult,
  267. content: utf16toEntities(content),
  268. type: 1
  269. };
  270. sendPost(url, data, 'json', 'post', function(res){
  271. queryFailed(res, '发送失败');
  272. }, submitSuccess);
  273. } else {
  274. return;
  275. }
  276. }
  277. //发送文本消息成功回调
  278. function submitSuccess(res){
  279. if (res.status == 200) {
  280. //置空
  281. $("#input_content").text("");
  282. $(".talk-send a").addClass("disab");
  283. addReply(2, content, timeStr, 1, "");
  284. dialroll.refresh();
  285. dialroll.scrollTo(0, dialroll.maxScrollY);
  286. showSendBtn(false);
  287. dd.close();
  288. } else {
  289. queryFailed(res, '发送失败');
  290. }
  291. }
  292. /**
  293. * 组装信息
  294. * @param {number} type 消息是本人发送还是他们发送, 1-医生发送,2-自己发送
  295. * @param {string} content 消息内容
  296. * @param {string} time 时间
  297. * @param {string} msgType 消息类型
  298. * @param {string} doctorName
  299. * @param {string} photo 头像图片路径
  300. * @param {boolean} prepend 消息是否往前添加
  301. */
  302. function addReply(type, content, time, msgType, doctorName, photo, prepend, isSystem){
  303. //time = time.substr(10);
  304. var $div = $("<dl></dl>");
  305. if(msgType == 7){
  306. if(msgType == 7 && isSystem){
  307. content = "您24小时内未回复,系统自动结束咨询";
  308. }
  309. // if(msgType == 1){
  310. // var content1 = '您未绑定智能设备,请手动上传体征数据,绑定设备后系统将会自动将您的体征数据上报给医生<br><a href="javascript:;" class="add-equip">点击绑定</a>';
  311. // if(prepend){
  312. // $(".talk-box").prepend('<div class="time-tips"><span class="">' + content1 + '</span></div>');
  313. // } else{
  314. // $(".talk-box").append('<div class="time-tips"><span class="">' + content1 + '</span></div>');
  315. // }
  316. // return;
  317. // }
  318. if(prepend){
  319. $(".talk-box").prepend('<div class="time-tips"><span class="xt-xiaoxi">' + content + '</span></div>');
  320. } else
  321. $(".talk-box").append('<div class="time-tips"><span class="xt-xiaoxi">' + content + '</span></div>');
  322. return;
  323. }
  324. if (type == 1) {
  325. $div.addClass('chat-left');
  326. img = photo ? getImgUrl(photo) : doctorDefaultPhoto;
  327. doctorDefaultPhoto = img;
  328. name = doctorName;
  329. } else {
  330. $div.addClass('chat-right');
  331. img = photo ? getImgUrl(photo) : defaultPhoto;
  332. defaultPhoto = img;
  333. name = window.localStorage.getItem("nowPatientName");
  334. }
  335. var temp = '<dt style="height: auto; text-align: center;"><a><img src="' + img + '" class="c-images-cycle" /></a></dt>' +
  336. '<div class="c-content"><span class="c-f12 name">' + name + '</span>'
  337. switch(parseInt(msgType)) {
  338. case 1://信息
  339. temp += '<dd class="word-bread"><span>' + content + '</span></dd></dl>';
  340. break;
  341. case 6://咨询问题
  342. var rs = JSON.parse(content);
  343. var tzMsg = rs.tzMsg;
  344. temp += '<dd class="word-bread sys-msg">'+
  345. '<div class="c-f14 sys-header mb5"><img src="../images/xitongtixing_im_icon.png" width="14">本消息为系统提示</div>'+
  346. '<p class="c-333 c-f14">' + rs.title + '</p>'+
  347. '<p class="c-333 c-f14">体征信息:'+tzMsg+'</p>'+
  348. '</dd></dl>';
  349. break;
  350. case 2://图片
  351. temp += '<dd class="word-bread wb-img"><img width="100" height="100" src="'+ getImgUrl(content) +'" /></dd></dl>';
  352. break;
  353. case 3://语音
  354. var rec = JSON.parse(content);
  355. temp += "<div class='c-msg'><dd class='word-bread audio' data-type='3' data-audio='" + getImgUrl(content) + "'>"+
  356. "<div class='soundWav'>" +
  357. "<span class='soundWavT'>"+(rec? rec.times: "") +"\'\'</span>"+
  358. "</div>"+
  359. "</dd></div>";
  360. break;
  361. case 12://视频
  362. var videoInfo = content.split(",");
  363. var shichang = formatSeconds(videoInfo[2]);//时长
  364. if(type == 1){
  365. temp += '<dd class="preview-video" data-video="'+getImgUrl(videoInfo[1])+'">'+
  366. '<img class="video-img-left" src="'+getImgUrl(videoInfo[0])+'">'+
  367. '<img class="bofang-icon-left" src="../images/bofang_icon.png">'+
  368. '<img class="jianjiao-icon-left" src="../images/zuoshanjiao_bg.png">'+
  369. '<span class="shichang-time-left">'+shichang+'</span>'+
  370. '</dd>';
  371. }else{
  372. temp += '<dd class="preview-video" data-video="'+getImgUrl(videoInfo[1])+'">'+
  373. '<img class="video-img-right" src="'+getImgUrl(videoInfo[0])+'">'+
  374. '<img class="bofang-icon-right" src="../images/bofang_icon.png">'+
  375. '<img class="jianjiao-icon-right" src="../images/youshanjiao_bg.png">'+
  376. '<span class="shichang-time-right">'+shichang+'</span>'+
  377. '</dd>';
  378. }
  379. break;
  380. case 15:
  381. var rs = JSON.parse(content);
  382. var reason = "";
  383. if(rs.reason){
  384. reason = '<p class="c-333 c-f14">原因:'+rs.reason+'</p>';
  385. }
  386. temp += '<dd class="word-bread sys-msg">'+
  387. '<div class="c-f14 sys-header mb5"><img src="../images/xitongtixing_im_icon.png" width="14">本消息为系统提示</div>'+
  388. '<p class="c-333 c-f14">审核消息:</p>'+
  389. '<p class="c-333 c-f14">' + rs.title + '</p>'+
  390. '<p class="c-333 c-f14">审核结果:'+rs.result+'</p>'+reason+
  391. '<a href="javascript:void(0);" class="view-detail c-f14">点此查看详情</a>'+
  392. '</dd>';
  393. break;
  394. case 16:
  395. var rs = JSON.parse(content);
  396. if(type == 2){
  397. var bttn="";
  398. if(rs.needUpload == 'true'){
  399. if(rs.type == 1){
  400. bttn = ' <a href="javascript:void(0);" class="add-xy c-f14">上传血压数据</a>'
  401. }else{
  402. bttn = ' <a href="javascript:void(0);" class="add-xt c-f14">上传血糖数据</a>'
  403. }
  404. temp += '<dd class="word-bread sys-msg">'+
  405. '<div class="c-f14 sys-header mb5"><img src="../images/xitongtixing_im_icon.png" width="14">本消息为系统提示</div>'+
  406. '<p class="c-333 c-f14">'+rs.patientAlert+bttn+'</p>'+
  407. '</dd></div>';
  408. }else{
  409. temp += '<dd class="word-bread sys-msg">'+
  410. '<div class="c-f14 sys-header mb5"><img src="../images/xitongtixing_im_icon.png" width="14">本消息为系统提示</div>'+
  411. '<p class="c-333 c-f14">'+rs.tzMsg+'</p>'+
  412. '<p class="c-333 c-f14">'+rs.tzTime+'</p>'+
  413. '</dd></div>';
  414. }
  415. break;
  416. }else{
  417. var dev="";
  418. if(rs.deviceMsg){
  419. dev = '<p class="c-999 c-f12">'+rs.deviceMsg+' <a href="javascript:void(0);" class="add-equip c-f14">点击绑定</a></p>'
  420. }
  421. temp += '<dd class="word-bread survey-msg"><div class="msg-body clearfix">'+
  422. '<p class="c-333 c-f15">'+rs.text+'</p>'+dev+
  423. '</div></dd>';
  424. }
  425. break;
  426. case 17://随访调查
  427. var rs = JSON.parse(content);
  428. if(type==2){
  429. if(rs.sysMsg){
  430. temp += '<dd class="word-bread sys-msg">'+
  431. '<div class="c-f14 sys-header mb5"><img src="../images/xitongtixing_im_icon.png" width="14">本消息为系统提示</div>'+
  432. '<p class="c-f14 c-333">'+rs.text+
  433. ' <a href="javascript:void(0);" data-type="'+rs.msgType+'" class="survey c-f14">查看</a></p>'+
  434. '</dd></div>';
  435. }
  436. }else{
  437. temp += '<dd class="word-bread survey-msg"><div class="msg-body clearfix">'+
  438. '<p class="c-333 c-f15">'+rs.text+' <a href="javascript:void(0);" data-type="'+rs.msgType+'" class="survey c-f14">开始填写</a></p>'+
  439. '</div></dd><p class="xf-notice">'+rs.patientremind+'</p>';
  440. }
  441. break;
  442. }
  443. if(prepend){
  444. $(".talk-box").prepend($div.append(temp)).prepend('<div class="time-tips"><span>' + time + '</span></div>');
  445. } else
  446. $(".talk-box").append('<div class="time-tips"><span>' + time + '</span></div>').append($div.append(temp));
  447. if(type != null && type != 1) {
  448. $(".tw-add-detail").hide(200);
  449. }
  450. }
  451. //下拉刷新加载数据方法
  452. function getPage(t){
  453. var url = 'patient/consult/loglist',
  454. data = {
  455. consult: consult,
  456. page: id,
  457. pagesize: pagesize
  458. };
  459. sendPost(url, data, 'json', 'post', queryFailed, function(res){
  460. if(res.status == 200){
  461. var list = res.list;
  462. if (list && list.length > 0) {
  463. id = list[list.length - 1].id;
  464. for (var j = 0; j < list.length; j++) {
  465. var reply = list[j];
  466. if((reply.msgType == 1) || (reply.msgType == 3) || (reply.msgType == 2) || (reply.msgType == 6) || (reply.msgType == 12) || (reply.msgType == 7) || (reply.msgType == 15)){
  467. //type为1时,医生发的
  468. var type = (reply.sender_id==patientcode) ? 2 : 1;
  469. var isSystem = reply.sender_id == 'system';
  470. addReply(type, reply.content, reply.time, reply.msgType, reply.doctorName, reply.photo, true, isSystem);
  471. }
  472. }
  473. }
  474. t.refresh();
  475. }else{
  476. queryFailed(res);
  477. }
  478. });
  479. }
  480. //结束咨询方法
  481. function finish(){
  482. //先判断是否可以结束咨询,续方申请状态为待审核时,不可以结束咨询
  483. if((presciptionStatus >= 0) && (presciptionStatus < 21)){
  484. dialog({
  485. contentType:'tipsbox',
  486. content: '续方申请未审核,不可关闭续方咨询',
  487. skin: 'bk-popup',
  488. closeTime: 2000
  489. }).show();
  490. return false;
  491. }
  492. dialog({
  493. content:'是否确认结束该次咨询?结束后医生将无法回复',
  494. ok: function (){
  495. var params = {}
  496. params.code = consult;
  497. //发送ajax请求, 查询设备列表信息
  498. sendPost("patient/consult/finish", params, "json", "post", function(res){
  499. queryFailed(res, '操作失败');
  500. },function(res){
  501. if (res.status == 200) {
  502. location.reload();
  503. }
  504. else{
  505. queryFailed(res, '操作失败');
  506. }
  507. });
  508. },
  509. cancel: function () {
  510. return;
  511. }
  512. }).showModal();
  513. }
  514. /*--------------------------- 事件监听 ------------------------------------*/
  515. function bindEvents(){
  516. //点击续方卡片,跳转去续方记录页面
  517. $("#prescriptionInfo").on('click', function(){
  518. var code = $(this).attr("data-code");
  519. window.location.href = "../../prescription/html/re-prescription_info.html?code="+code+'&toUser='+toUser;
  520. });
  521. //点击内容区域输入框失焦
  522. $('#talkwrap').click(function(){
  523. $("#input_content").blur();
  524. // dialroll.refresh();
  525. // dialroll.scrollTo(0, dialroll.maxScrollY);
  526. return false;
  527. });
  528. //发送以后定位至最底部
  529. $("#reply a").click(function() {
  530. send();
  531. });
  532. //立即发送
  533. $("#lijifasong").on("tap", function(){
  534. uploadVideo();
  535. mui('#sheet1').popover('toggle');
  536. return false;
  537. });
  538. //不再提醒
  539. $("#buzaitixing").on("tap", function(){
  540. window.localStorage.setItem("isTiXingVideoFaSong","1");
  541. uploadVideo();
  542. mui('#sheet1').popover('toggle');
  543. return false;
  544. });
  545. //查看续方详情
  546. $("body").on("tap", '.view-detail', function(){
  547. window.location.href = "../../prescription/html/re-prescription_info.html?code="+prescriptionCode+'&toUser='+toUser;
  548. })
  549. //调查问卷
  550. $("body").on("tap", '.survey', function(){
  551. var $this = $(this)
  552. window.location.href = "questionaires.html?prescriptionCode="+prescriptionCode+"&pro_id="+$this.attr('data-type')
  553. })
  554. $("body").on("tap", '.view-check', function(){
  555. window.location.href = "questionaires.html?prescriptionCode="+prescriptionCode+"&pro_id=2"
  556. })
  557. //血压血糖
  558. $("body").on("tap", '.j-btn', function(){
  559. window.location.href = "../../jkjl/html/health-index-add-bloodpressure.html?origin=suifang&prescriptionCode="+prescriptionCode
  560. })
  561. $("body").on("tap", '.add-xt', function(){
  562. window.location.href = "../../jkjl/html/health-index-add-bloodsugar.html?origin=suifang&prescriptionCode="+prescriptionCode
  563. })
  564. $("body").on("tap", '.add-xy', function(){
  565. window.location.href = "../../jkjl/html/health-index-add-bloodpressure.html?origin=suifang&prescriptionCode="+prescriptionCode
  566. })
  567. //添加设备
  568. $("body").on("tap", '.add-equip', function(){
  569. window.location.href = "../../wdsb/html/my-equipments.html?prescriptionCode="+prescriptionCode
  570. })
  571. //点击评价
  572. $('body').on('tap','#noval',function(){
  573. window.location.href = "manyidu.html?consult=" +consult;
  574. });
  575. $('body').on('tap','#hasval',function(){
  576. window.location.href = "manyidu.html?consult=" +consult;
  577. });
  578. var $ipt_content = $('#input_content');
  579. //键盘输入解决输入框被软键盘覆盖的问题
  580. var bfscrolltop = document.body.scrollTop;//获取软键盘唤起前浏览器滚动部分的高度
  581. var interval;
  582. $ipt_content.focus(function(){//当它获取焦点时触发事件
  583. $(".tw-add-detail").hide();
  584. interval = setInterval(function(){//设置一个计时器,时间设置与软键盘弹出所需时间相近
  585. document.body.scrollTop = document.body.scrollHeight;//获取焦点后将浏览器内所有内容高度赋给浏览器滚动部分高度
  586. },100)
  587. }).blur(function(){//设定输入框失去焦点时的事件
  588. clearInterval(interval);//清除计时器
  589. document.body.scrollTop = bfscrolltop; //将软键盘唤起前的浏览器滚动部分高度重新赋给改变后的高度
  590. });
  591. //显示发送按钮的事件
  592. $ipt_content.on('input', function(e){
  593. if($(this).prop('comstart')) {
  594. return;
  595. }
  596. var text = $.trim($(this).text());
  597. showSendBtn(text.length > 0)
  598. }).on('compositionstart', function(){
  599. $(this).prop('comstart', true);
  600. //console.log('中文输入:开始');
  601. }).on('compositionend', function(){
  602. $(this).prop('comstart', false);
  603. //console.log('中文输入:结束');
  604. var text = $.trim($(this).text());
  605. showSendBtn(text.length > 0)
  606. })
  607. .on('tap', function(){
  608. $(".tw-add-detail").hide();
  609. // $ipt_content.focus();
  610. })
  611. //附加功能
  612. $(".tw-add").click(function() {
  613. $(".tw-add-detail").toggle(200);
  614. });
  615. //隐藏打开的附加功能
  616. $('body').on('tap', '#talkwrap', function(){
  617. $('.tw-add-detail').hide();
  618. $ipt_content.blur();
  619. });
  620. $(".yy-add").click(function() {
  621. if($('#msg-sound:visible').length){
  622. $ipt_content.show();
  623. ui.boxMsgSound.style.display = 'none';
  624. $(this).find('img:eq(0)').show().next().hide();
  625. } else {
  626. $ipt_content.hide();
  627. ui.boxMsgSound.style.display = 'block';
  628. $(this).find('img:eq(0)').hide().next().show();
  629. }
  630. });
  631. //预览图片
  632. $('.talk-box').on('click', '.word-bread img', function(){
  633. if(!$(this).closest(".word-bread").hasClass("preview-video")){
  634. var urls = [];
  635. $.each($('.word-bread img'), function(i, v) {
  636. urls.push($(v).attr('src'));
  637. });
  638. wx.previewImage({
  639. current: $(this).attr('src'), // 当前显示图片的http链接
  640. urls: urls // 需要预览的图片http链接列表
  641. });
  642. }
  643. })
  644. //播放语音
  645. .on('touchstart', '.audio', function(){
  646. if($playingDom){
  647. aud.pause();
  648. //aud.stop();
  649. $playingDom.removeClass('active');
  650. if($playingDom[0] == this){
  651. $playingDom = null;
  652. return;
  653. }
  654. }
  655. $playingDom = $(this);
  656. $playingDom.addClass('active');
  657. var ser = JSON.parse($(this).attr('data-audio'));
  658. aud.src = getImgUrl(ser.path);
  659. aud.load();
  660. aud.play();
  661. })
  662. //播放视频
  663. .on('click','.preview-video',function() {
  664. $(document.body).find('video').remove();
  665. var url = $(this).attr('data-video');
  666. var html = '<video style="display: none;" controls preload="auto" width="1" height="1" src="'+url+'" ></video>';
  667. $(document.body).append(html);
  668. var video = $(document.body).find('video')[0];
  669. video.play();
  670. });
  671. }
  672. /*--------------------------- 事件监听 ------------------------------------*/
  673. /*--------------------------- 辅助方法 ------------------------------------*/
  674. //控制页面高度
  675. function winSize(h){
  676. var totH = $(window).height();
  677. $("#talkwrap").height(totH - h);
  678. if(h > 75){
  679. $(".c-main").css("top", '110px');
  680. }
  681. }
  682. //控制是否显示文本消息框
  683. function showSendBtn(isShow){
  684. if(isShow){
  685. $('.tw-add').hide();
  686. $('#reply').fadeIn('fast', 'swing');
  687. } else {
  688. $('#reply').fadeOut('fast', 'swing', function(){
  689. $('.tw-add').show();
  690. });
  691. }
  692. };
  693. //毫秒转换成时分秒
  694. function formatSeconds(value){
  695. var theTime = parseInt(value/1000);// 秒
  696. var theTime1 = 0;// 分
  697. var theTime2 = 0;// 小时
  698. if(theTime > 60) {
  699. theTime1 = parseInt(theTime/60);
  700. theTime = parseInt(theTime%60);
  701. if(theTime1 > 60) {
  702. theTime2 = parseInt(theTime1/60);
  703. theTime1 = parseInt(theTime1%60);
  704. }
  705. }
  706. var result = ""+parseInt(theTime);//秒
  707. if(parseInt(theTime)<=9){
  708. result = "0"+parseInt(theTime);//秒
  709. }
  710. if(theTime1 > 0) {//分
  711. if(parseInt(theTime1)>9){
  712. result = ""+parseInt(theTime1)+":"+result;
  713. }else{
  714. result = "0"+parseInt(theTime1)+":"+result;
  715. }
  716. }
  717. if(theTime2 > 0) {//小时
  718. if(parseInt(theTime2)>9){
  719. result = ""+parseInt(theTime2)+":"+result;
  720. }else{
  721. result = "0"+parseInt(theTime2)+":"+result;
  722. }
  723. }
  724. var resResult = "";
  725. if(result.split(":").length==1){//秒
  726. resResult = "00:"+result;
  727. }else if(result.split(":").length==2){//分
  728. resResult = "00:"+result;
  729. }else{//时
  730. resResult = result;
  731. }
  732. return resResult;
  733. }
  734. /*--------------------------- 辅助方法 ------------------------------------*/
  735. //-----------------------------【图片】处理方法-------------------------------------
  736. //微信上传图片
  737. var serverId = "";
  738. var images = [];
  739. //查看图片
  740. function viewImg(dom){
  741. var $img = $(dom);
  742. var thissrc = $img.attr("src");
  743. var mWid = $(window).width();
  744. var mHei = $(window).height();
  745. 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>';
  746. $("body").append(nHtml);
  747. $(".delimgpop").click(function() {
  748. $(this).remove()
  749. });
  750. }
  751. //微信选择图片
  752. function chooseImageWx(){
  753. wx.chooseImage({
  754. count: 3,
  755. success: function (res) {
  756. for (var i in res.localIds) {
  757. images.push(res.localIds[i]);
  758. }
  759. dd.showModal();
  760. uploadImage();
  761. }
  762. });
  763. }
  764. //上传图片到微信
  765. function uploadImage(){
  766. if (images.length == 0) {
  767. dd.close();
  768. return;
  769. }
  770. var i = 0, length = images.length;
  771. serverId = "";
  772. var faillength = 0 ;
  773. function upload() {
  774. wx.uploadImage({
  775. localId: images[i],
  776. isShowProgressTips: 0,
  777. success: function (res) {
  778. faillength= 0;
  779. i++;
  780. if(serverId.length == 0){
  781. serverId = res.serverId;
  782. }
  783. else{
  784. serverId =serverId + "," + res.serverId;
  785. }
  786. if (i < length) {
  787. upload();
  788. }
  789. if(i == images.length){
  790. sendImages();
  791. }
  792. },
  793. fail: function (res) {
  794. dd.close();
  795. faillength+=1;
  796. if(faillength<=5){
  797. //失败从传
  798. upload();
  799. }else{
  800. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:"图片上传失败,请控制发送频率"}).show();
  801. }
  802. }
  803. });
  804. }
  805. upload();
  806. }
  807. //保存图片到后台
  808. function sendImages(){
  809. var now = new Date();
  810. timeStr = now.Format('yyyy-MM-dd hh:mm:ss');
  811. var url = 'patient/consult/append'
  812. data = {
  813. consult: consult,
  814. content: '',
  815. mediaIds: serverId,
  816. type: 2,
  817. times: ''
  818. };
  819. sendPost(url, data, 'json', 'post', function(res){
  820. queryFailed(res, '发送失败');
  821. }, function(res){
  822. if (res.status == 200) {
  823. var data= JSON.parse(res.data)
  824. dd.close();
  825. addReply(2, data.content, timeStr, 2, "");
  826. dialroll.refresh();
  827. dialroll.scrollTo(0, dialroll.maxScrollY);
  828. } else {
  829. queryFailed(res, '发送失败');
  830. }
  831. });
  832. }
  833. //-----------------------------【图片】处理方法-------------------------------------
  834. //------------------------------【语音】处理方法------------------------------------
  835. var aud = document.getElementById('audio');
  836. var $playingDom;
  837. //播放语音结束方法
  838. function playSoundEnd(){
  839. $playingDom.removeClass('active');
  840. $playingDom = null;
  841. }
  842. //播放语音错误提示方法
  843. function playError(){
  844. var src = $('#audio').attr('src');
  845. if(!$.trim(src)) {
  846. return ;
  847. }
  848. dialog({contentType:'tipsbox', skin:'bk-popup' ,bottom:true, content:"播放语音失败"}).show();
  849. $playingDom.removeClass('active');
  850. $playingDom = null;
  851. }
  852. var recordCancel = false;
  853. var recorder = null;
  854. var audio_tips = document.getElementById("audio_tips");
  855. var startTimestamp = null;
  856. var stopTimestamp = null;
  857. var stopTimer = null;
  858. var MIN_SOUND_TIME = 500;
  859. var ui = {
  860. body: document.querySelector('body'),
  861. btnMsgType: document.querySelector('#msg-type'),
  862. boxMsgText: document.querySelector('#msg-text'),
  863. boxMsgSound: document.querySelector('#msg-sound'),
  864. btnMsgImage: document.querySelector('#msg-image'),
  865. areaMsgList: document.querySelector('#msg-list'),
  866. boxSoundAlert: document.querySelector('#sound-alert')
  867. };
  868. var recordTimer = null;
  869. var realStartTime = 0;
  870. ui.boxMsgSound.addEventListener("touchstart", function(e) {
  871. e.preventDefault();
  872. event.preventDefault();
  873. $(this).addClass('yy-hold');
  874. if(stopTimer)clearTimeout(stopTimer);
  875. recordCancel = false;
  876. audio_tips.innerHTML = "手指上划,取消发送";
  877. ui.boxSoundAlert.classList.remove('rprogress-sigh');
  878. setSoundAlertVisable(true);
  879. startTimestamp = new Date().getTime();
  880. recordTimer = setTimeout(function(){
  881. wx.startRecord({
  882. success: function(){
  883. realStartTime = new Date().getTime();
  884. },
  885. fail: recordErr
  886. });
  887. wx.onVoiceRecordEnd({
  888. // 录音时间超过一分钟没有停止的时候会执行 complete 回调
  889. complete: function (res) {
  890. serverId = res.localId;
  891. sendSounds(60);
  892. },
  893. fail: recordErr
  894. });
  895. },MIN_SOUND_TIME);
  896. }, false);
  897. ui.boxMsgSound.addEventListener("touchend", function(e){
  898. e.preventDefault();
  899. event.preventDefault();
  900. $(this).removeClass('yy-hold');
  901. if (audio_tips.classList.contains("cancel")) {
  902. audio_tips.classList.remove("cancel");
  903. audio_tips.innerHTML = "手指上划,取消发送";
  904. }
  905. var endTimestamp = new Date().getTime();
  906. var times = endTimestamp - startTimestamp;
  907. var realTimes = endTimestamp - realStartTime;
  908. if(times < MIN_SOUND_TIME || realTimes < MIN_SOUND_TIME){
  909. audio_tips.innerHTML = "录音时间太短";
  910. ui.boxSoundAlert.classList.add('rprogress-sigh');
  911. recordCancel = true;
  912. stopTimer=setTimeout(function(){
  913. setSoundAlertVisable(false);
  914. },500);
  915. startTimestamp = 0;
  916. realStartTime = 0;
  917. //小于300ms,不录音
  918. clearTimeout(recordTimer);
  919. wx.stopRecord({
  920. success: function (res) {
  921. },
  922. fail: function(){}
  923. });
  924. }else{
  925. setSoundAlertVisable(false);
  926. wx.stopRecord({
  927. success: function (res) {
  928. if(!recordCancel) {
  929. serverId = res.localId;
  930. sendSounds(Math.round(times/1000));
  931. }
  932. },
  933. fail: recordErr
  934. });
  935. }
  936. }, false)
  937. ui.body.addEventListener('drag', function(event) {
  938. if (Math.abs(event.detail.deltaY) > 50) {
  939. if (!recordCancel) {
  940. recordCancel = true;
  941. if (!audio_tips.classList.contains("cancel")) {
  942. audio_tips.classList.add("cancel");
  943. }
  944. audio_tips.innerHTML = "松开手指,取消发送";
  945. }
  946. } else {
  947. if (recordCancel) {
  948. recordCancel = false;
  949. if (audio_tips.classList.contains("cancel")) {
  950. audio_tips.classList.remove("cancel");
  951. }
  952. audio_tips.innerHTML = "手指上划,取消发送";
  953. }
  954. }
  955. }, false);
  956. var setSoundAlertVisable=function(show){
  957. if(show){
  958. ui.boxSoundAlert.style.display = 'block';
  959. ui.boxSoundAlert.style.opacity = 1;
  960. }else{
  961. ui.boxSoundAlert.style.opacity = 0;
  962. //fadeOut 完成再真正隐藏
  963. setTimeout(function(){
  964. ui.boxSoundAlert.style.display = 'none';
  965. },200);
  966. }
  967. },
  968. //保存语音
  969. sendSounds = function(times){
  970. var now = new Date();
  971. timeStr = now.Format('yyyy-MM-dd hh:mm:ss');
  972. var data = {};
  973. data.consult = consult;
  974. data.content = "";
  975. data.type = 3;
  976. data.times = times;
  977. dd.show();
  978. wx.uploadVoice({
  979. localId: serverId,
  980. success: function (res) {
  981. data.voices = res.serverId;
  982. sendPost('patient/consult/append', data, 'json', 'post', function(){
  983. queryFailed(res, '发送失败');
  984. },
  985. function submitSoundSuccess(res) {
  986. if (res.status == 200) {
  987. dd.close();
  988. var data = JSON.parse(res.data[0]);
  989. addReply(2, data.content, timeStr, 3, "");
  990. dialroll.refresh();
  991. dialroll.scrollTo(0, dialroll.maxScrollY);
  992. } else {
  993. queryFailed(res, '发送失败');
  994. }
  995. });
  996. }
  997. });
  998. },
  999. //录制语音错误提示信息
  1000. recordErr = function(res){
  1001. if(res && res.errMsg == "stopRecord:tooshort") {
  1002. audio_tips.innerHTML = "录音时间太短";
  1003. ui.boxSoundAlert.classList.add('rprogress-sigh');
  1004. recordCancel = true;
  1005. stopTimer=setTimeout(function(){
  1006. setSoundAlertVisable(false);
  1007. },500);
  1008. startTimestamp = 0;
  1009. //小于300ms,不录音
  1010. if(recordTimer)clearTimeout(recordTimer);
  1011. return;
  1012. }
  1013. if(!recordCancel){
  1014. dialog({
  1015. content:'录音失败,请重试',
  1016. okValue:'我知道了',
  1017. ok: function() {}
  1018. }).showModal();
  1019. }
  1020. };
  1021. //------------------------------【语音】处理方法------------------------------------
  1022. //【视频】处理方法
  1023. //录制视频回调
  1024. var videoFileChange = function(target){
  1025. var fileSize = (target.files[0].size/1024/1024).toFixed(2);//字节转换成M
  1026. if(parseInt(fileSize)>30){
  1027. dialog({
  1028. content:'对不起,视频超过30Mb,无法发送,请录制10秒左右的短视频',
  1029. okValue:'我知道了',
  1030. ok: function() {
  1031. return;
  1032. }
  1033. }).showModal();
  1034. }else{
  1035. if(networkStatus=="wifi" || window.localStorage.getItem("isTiXingVideoFaSong")=="1"){//wifi环境或用户点击移动网络弹框中的”不再提醒“按钮
  1036. uploadVideo();
  1037. }else{
  1038. $("#mui-content").html('您正在使用移动网络,继续发送将消耗'+fileSize+'Mb流量,是否继续发送?');
  1039. mui('#sheet1').popover('toggle');
  1040. }
  1041. }
  1042. },
  1043. //上传视频
  1044. uploadVideo = function(){
  1045. dd.showModal();
  1046. var fd=new FormData();
  1047. fd.append('file',document.getElementById("upload_input").files[0]);
  1048. $.ajax(server+"/upload/chat?type=4", {
  1049. data: fd,
  1050. contentType: false,
  1051. cache: false,
  1052. processData: false,
  1053. type: 'post',
  1054. success: function(resData) {
  1055. if(resData.status==200){
  1056. var data = {consult:consult,content:resData.urls,type:12};
  1057. sendPost('patient/consult/append', data, 'json', 'post', function(){
  1058. queryFailed(res, '发送失败');
  1059. },
  1060. function submitSoundSuccess(res) {
  1061. if (res.status == 200) {
  1062. dd.close();
  1063. var data = JSON.parse(res.data[0]);
  1064. addReply(2, data.content, new Date(data.timestamp).Format('yyyy-MM-dd HH:mm:ss'), 12, "");
  1065. dialroll.refresh();
  1066. dialroll.scrollTo(0, dialroll.maxScrollY);
  1067. } else {
  1068. queryFailed(res, '发送失败');
  1069. }
  1070. });
  1071. }else{
  1072. dd.close();
  1073. }
  1074. },
  1075. error:function (XMLHttpRequest, textStatus, errorThrown) {
  1076. console.log(XMLHttpRequest.status);
  1077. console.log(XMLHttpRequest.readyState);
  1078. console.log(textStatus)
  1079. }
  1080. });
  1081. };
  1082. Date.prototype.format = function(fmt) { //author: meizz
  1083. var o = {
  1084. "M+": this.getMonth() + 1, //月份
  1085. "d+": this.getDate(), //日
  1086. "h+": this.getHours(), //小时
  1087. "m+": this.getMinutes(), //分
  1088. "s+": this.getSeconds(), //秒
  1089. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  1090. "S": this.getMilliseconds() //毫秒
  1091. };
  1092. if (/(y+)/.test(fmt))
  1093. fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  1094. for (var k in o)
  1095. if (new RegExp("(" + k + ")").test(fmt))
  1096. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  1097. return fmt;
  1098. }
  1099. //从后台那边获取签名等信息
  1100. function getWXSign(){
  1101. var params = {};
  1102. var url1 = window.location.href;
  1103. params.pageUrl = url1;
  1104. $.ajax(server + "weixin/getSign", {
  1105. data: params,
  1106. dataType: "json",
  1107. type: "post",
  1108. success: function(res){
  1109. if (res.status == 200) {
  1110. var t = res.data.timestamp;
  1111. var noncestr = res.data.noncestr;
  1112. var signature = res.data.signature;
  1113. wx.config({
  1114. appId: appId, // 必填,公众号的唯一标识
  1115. timestamp: t, // 必填,生成签名的时间戳
  1116. nonceStr: noncestr, // 必填,生成签名的随机串
  1117. signature: signature,// 必填,签名,见附录1
  1118. jsApiList: [
  1119. 'chooseImage',
  1120. 'uploadImage',
  1121. 'startRecord',
  1122. 'stopRecord',
  1123. 'onVoiceRecordEnd',
  1124. 'playVoice',
  1125. 'pauseVoice',
  1126. 'stopVoice',
  1127. 'onVoicePlayEnd',
  1128. 'uploadVoice',
  1129. 'getNetworkType'
  1130. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  1131. });
  1132. // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。
  1133. wx.ready(function(){
  1134. wx.getNetworkType({
  1135. success: function (res) {
  1136. networkStatus = res.networkType; // 返回网络类型2g,3g,4g,wifi
  1137. }
  1138. });
  1139. });
  1140. }
  1141. }
  1142. });
  1143. }