zixunxiangqing.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783
  1. $(function () {
  2. var winHeight=window.innerHeight,//窗体高度
  3. winWidth=window.innerWidth,//窗体高度
  4. msgListUrl = 'doctor/consult/loglist',
  5. myScroll = null,
  6. self,
  7. docInfo,
  8. teamInfo,
  9. offTop = 45,
  10. offBot = 52,
  11. pageSize = 1000,
  12. prevImage,
  13. otherCode = '',//咨询者code
  14. sessionId = '',//咨询者拼接id
  15. sessionName = '',//咨询者姓名
  16. createTime = '',//咨询时间
  17. qyDocInfo = null,//签约医生信息
  18. consultInfo = {},//患者详情
  19. status = '',//0 待回复 1进行中 2完成
  20. type = '', //咨询类型 1三师咨询,2家庭医生咨询,3图文咨询,4公共咨询,5病友圈, 6名医咨询
  21. lastTimestamp = '',
  22. urlRegex = new RegExp('((https|http|ftp|rtsp|mms)?://)'
  23. + '?(([0-9a-zA-Z_!~*\'().&=+$%-]+: )?[0-9a-zA-Z_!~*\'().&=+$%-]+@)?' //ftp的user@
  24. + '(([0-9]{1,3}\\.){3}[0-9]{1,3}' // IP形式的URL- 199.194.52.184
  25. + '|' // 允许IP和DOMAIN(域名)
  26. + '([0-9a-zA-Z_!~*\'()-]+\\.)*' // 域名- www.
  27. + '([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]\\.' // 二级域名
  28. + '(gov|edu|int|com|cn|cx|cn|wang|cc|xin|net|org|top|tech|red|pub|ink|info|xyz|win))' // first level domain- .com or .museum
  29. + '(:[0-9]{1,4})?' // 端口- :80
  30. + '((/[0-9a-zA-Z_!~*\'().;?:@&=+$,%#-]+)+/?)?'
  31. + '((\\?[0-9a-zA-Z_!~*\'().;:@&=+$,%#-]+)+/?)?');
  32. var $title = $('#title'),
  33. $xzzd = $('#xzzd'),
  34. $tixys = $('.tixys');
  35. //mui初始化
  36. mui.init({
  37. gestureConfig:{
  38. doubletap: true,
  39. longtap: true,
  40. hold: true,
  41. release: true
  42. }
  43. });
  44. mui.plusReady(function () {
  45. docInfo = JSON.parse(plus.storage.getItem("docInfo"));
  46. self = plus.webview.currentWebview();
  47. sessionId = self.sessionId;
  48. sessionName = self.sessionName;
  49. createTime = self.sessionTime;
  50. qyDocInfo = self.qyDocInfo ? JSON.parse(self.qyDocInfo) : null;
  51. consultInfo = self.consultInfo;
  52. otherCode = self.otherCode;
  53. status = self.stutas;
  54. type = self.type;
  55. //设置标题
  56. $title.html(sessionName + createTime + '咨询');
  57. //设置高度
  58. if(status == 2){
  59. offTop = 70
  60. }
  61. //获取成员信息
  62. getMembers();
  63. myScroll = $('#contain').lscroll({
  64. type: 2,
  65. pullDownMsg1: "下拉加载更多", pullDownMsg2: "松手开始加载",
  66. pullDownAction: function(g){
  67. getMsgList(g.options.page, false, true);
  68. },
  69. style: "top: "+ offTop +"px; bottom: "+ offBot +"px",
  70. });
  71. prevImage = mui.previewImage();
  72. });
  73. /**
  74. * 获取消息(下拉刷新)
  75. */
  76. function getMsgList(pageIndex, isClear, isPre) {
  77. getMsgs(pageIndex,function(data){
  78. if (!!!data.list) {
  79. plus.nativeUI.closeWaiting();
  80. myScroll.refresh(!!!data.list);
  81. return;
  82. }
  83. showMsg(data.list, isClear, isPre);
  84. })
  85. }
  86. /**
  87. * 获取成员信息
  88. */
  89. function getMembers(callBack){
  90. imClient.Sessions.getParticipants(sessionId, function(rs){
  91. members = {};
  92. var patientCode;
  93. $.each( rs , function(i, v) {
  94. if(v.id!=docInfo.code)
  95. otherCode = v.id;
  96. if(v.is_patient==1){
  97. isPatient = true;
  98. patientCode = v.id;
  99. }
  100. });
  101. otherCode = patientCode||otherCode;
  102. isSign();
  103. }, function(msg){
  104. console.log("e:"+JSON.stringify(msg))
  105. mui.toast("获取成员列表失败!");
  106. })
  107. }
  108. //判断是否有签约关系
  109. function isSign() {
  110. //status === 2:已完成回复
  111. if (status != 2) {
  112. sendGet("doctor/family_contract/doctor_patient_sign_exist", {
  113. doctor: docInfo.code,
  114. patient: otherCode
  115. }, null, function(res) {
  116. if(res.status == 200) {
  117. if(res.data.status == -1 && res.data.msg === '无签约关系') {
  118. //没有签约关系
  119. //判断是否是名医咨询,名医咨询可以跳转去IM页面
  120. if(type == 6){
  121. $xzzd.show();
  122. }
  123. // 修复bug#3460 【医生端】健康咨询:患者签约到期与医生存在未结束咨询时,从健康咨询进入无法回复咨询。
  124. if(qyDocInfo&& (docInfo.code != qyDocInfo.doctor)){
  125. $tixys.show();
  126. } else {
  127. $xzzd.show();
  128. }
  129. } else {
  130. $xzzd.show();
  131. }
  132. } else {
  133. mui.toast("获取签约关系失败!");
  134. }
  135. })
  136. }else{
  137. //获取被评价成员
  138. sendGet("doctor/consult/evaluate/list", {
  139. consult:consultInfo.id,
  140. type:1
  141. }, null, function(res) {
  142. if(res.status == 200) {
  143. if(res.list.length > 0){ //已经评分
  144. //兼容1.3.4的数据
  145. if(res.list[0].evaluate_type == 0){//旧数据
  146. $.each( res.list , function(i, v) {
  147. showStar(v);
  148. })
  149. $('#service').show();
  150. }else{
  151. if(res.list[0].type == 1){//实名
  152. var obj = _.groupBy(res.list, function(item){ return item.doctor; })
  153. for(var key in obj){
  154. var arr = obj[key],
  155. dataObj = {};
  156. $.each( arr , function(i, v) {
  157. if(v.evaluate_type == 1){
  158. dataObj.ability = v.score;
  159. }
  160. if(v.evaluate_type == 2){
  161. dataObj.attitude = v.score;
  162. }
  163. if(v.evaluate_type == 3){
  164. dataObj.speed = v.score;
  165. }
  166. })
  167. dataObj.name = arr[0].name;
  168. dataObj.avatar = arr[0].photo;
  169. showStar2(dataObj);
  170. }
  171. $('#service').show();
  172. }else{
  173. $('.no-service').show();
  174. }
  175. }
  176. }else{
  177. $('.no-service').show();
  178. }
  179. }else{
  180. mui.toast("获取评分数据失败");
  181. }
  182. })
  183. }
  184. getMsgs(1,function (res) {
  185. if (!!!res.list) {
  186. plus.nativeUI.closeWaiting();
  187. mui.toast("暂无咨询记录!");
  188. myScroll.refresh(!!!res.list);
  189. return;
  190. }
  191. showMsg(res.list, false, false, true)
  192. });
  193. }
  194. /**
  195. * 获取聊天图片列表
  196. */
  197. function getImgMsgList(handle) {
  198. im.getPrivateMsg(getUserId(), otherCode, lastId, pageSize, function(data) {
  199. console.log("imgs:" + JSON.stringify(data));
  200. chatCache.imgs = data.records.reverse();
  201. appendPrevImgs(chatCache.imgs);
  202. if(handle) handle(data);
  203. }, 2);
  204. }
  205. //显示星星 旧数据
  206. function showStar(obj){
  207. if(obj){
  208. var list='',
  209. num='';
  210. var one = '<li><img src="../images/icon_xingxing.png" alt="" /></li>';
  211. num = Math.floor(obj.score/20);
  212. for(var i=0;i<num;i++){
  213. list += one;
  214. }
  215. var html='<li class="one"><div class="img"><img src="'+obj.photo+'" alt="" /></div><div class="name">'+obj.name+'</div><ul class="star">'+list+'</ul></li>';
  216. $('#starList').append(html);
  217. }
  218. }
  219. //显示星星 新数据
  220. function showStar2(obj){
  221. if(obj){
  222. var abList = addStars(obj.ability)
  223. var atList = addStars(obj.attitude)
  224. var spList = addStars(obj.speed)
  225. var html='<li class="new-li"><div class="p1"><div class="imgs"><img src="'+getImgUrl(obj.avatar)+'" alt=""/></div><div class="name">'+obj.name+'</div></div><div class="p2"><div class="div"><div class="label">专业能力</div><ul class="list">'+abList+'</ul></div><div class="div"><div class="label">服务态度</div><ul class="list">'+atList+'</ul></div><div class="div"><div class="label">回复速度</div><ul class="list">'+spList+'</ul></div></div></li>';
  226. $('#starList').append(html);
  227. }
  228. }
  229. function addStars(score){
  230. var list='',
  231. num='';
  232. var one = '<li><img src="../images/icon_xingxing.png" alt="" /></li>';
  233. num = Math.floor(score/20);
  234. for(var i=0;i<num;i++){
  235. list += one;
  236. }
  237. return list
  238. }
  239. /**
  240. * 显示消息
  241. */
  242. function showMsg(msgList, isClear, isPre, appendImg, scrollToTop) {
  243. if(msgList.list.length == 0) {
  244. plus.nativeUI.closeWaiting();
  245. myScroll.refresh(msgList.length==0);
  246. return;
  247. }
  248. var html = "";
  249. var preTime = 0;
  250. var typeMsg = 1;
  251. var doctor_img ;
  252. var doctor_name = "";
  253. var msg;
  254. var sender;
  255. var users = msgList.users;
  256. var isDoc = false;
  257. for(var i = msgList.list.length - 1; i >= 0; i--) {
  258. msg = msgList.list[i];
  259. msg = JSON.parse(msg);
  260. setLastMsg(msg);
  261. typeMsg = parseInt(msg.content_type);
  262. if (typeMsg === 4|| typeMsg==14) {
  263. continue;
  264. }
  265. var contentMsg = msg.content;
  266. if(typeMsg == 7 || typeMsg==10 || typeMsg==13){
  267. if(typeMsg == 7 && msg.sender_id == 'system'){
  268. contentMsg = "居民24小时内未回复,系统自动结束咨询";
  269. }
  270. html += '<div class="time-tips"><div>'+ contentMsg +' </div></div>';
  271. continue;
  272. } else if(typeMsg == 5){
  273. var con = JSON.parse(msg.content);
  274. if(msg.sender_id == docInfo.code){
  275. console.log(msg.content)
  276. html += '<div class="time-tips"><div>已向'+ con.doctor_name +'医生求助<a data-name="'+ con.doctor_name +'" data-code="'+ con.doctor +'" class="qiuzhu5" href="javascript:void(0)">立即查看</a> </div></div>';
  277. }
  278. continue;
  279. }
  280. var _class = ["chat-log"];
  281. if (users.length > 0) {
  282. for (var ii = 0; ii < users.length; ii++) {
  283. var user = users[ii];
  284. if (user['id'] === msg['sender_id']) {
  285. doctor_img = getImgUrl(user['avatar']);
  286. doctor_name = user['name'];
  287. if(docInfo.code != user['id']) {
  288. _class.push("chat-left");
  289. } else {
  290. _class.push("chat-right");
  291. }
  292. break;
  293. }
  294. }
  295. }
  296. if(msg.timestamp - preTime > 60 * 1000) {
  297. preTime = msg.timestamp;
  298. var date = new Date();
  299. date.setTime(msg.timestamp);
  300. var time = date.format('yyyy-MM-dd hh:mm:ss');
  301. html += '<div class="time-tips"><span>' + time + '</span></div>';
  302. }
  303. //type:1.文字 2.图片 3.音频
  304. var temp = '<dl data-type="'+ typeMsg +'" data-code="'+ msg.id +'" class="' + _class.join(" ") + '">'+
  305. '<dt style="text-align: center;"><a><img src="' + doctor_img + '" class="c-images-cycle" width="40" height="40"/></a></dt>' +
  306. '<div class="c-content"><span class="c-f12 name">' + doctor_name + '</span>';
  307. var sendErrDom = "";
  308. if(!msg.beforeSend && msg.id && msg.id.indexOf('loc')==0){
  309. sendErrDom = "<i data-info='"+ JSON.stringify(msg) +"' class='c-tips'></i>";
  310. }
  311. switch(typeMsg) {
  312. case 0:
  313. case 1://普通文本
  314. case 8://求助文本
  315. temp += '<div class="c-msg">'+ sendErrDom +'<dd class="word-bread" data-type="1"><span>' + matchUrl(contentMsg) + '</span></dd></div>';
  316. break;
  317. case 6://开始咨询文本
  318. //如果是续方咨询,显示样式不一致
  319. if(type == 8){
  320. var rs = JSON.parse(contentMsg);
  321. temp += '<div class="c-msg">'+ sendErrDom +
  322. '<dd class="word-bread" data-type="1">'+
  323. '<p>【本消息为系统提醒】</p>'+
  324. '<p>'+rs.title+'</p>'+
  325. '<p>'+rs.tzMsg+'</p>'+
  326. /*'<p>上次续方时间'+rs.lastTime+'</p>'+*/
  327. '</dd></div>';
  328. }else{
  329. temp += '<div class="c-msg">'+ sendErrDom +'<dd class="word-bread" data-type="1"><span>' + matchUrl(contentMsg) + '</span></dd></div>';
  330. }
  331. break;
  332. case 2://图片
  333. case 9://求助图片
  334. if(msg.local_src=="data:,")
  335. contentMsg = msg.content;
  336. else if(msg.local_src)
  337. contentMsg = msg.local_src.indexOf('data:')==0? msg.local_src: plus.io.convertLocalFileSystemURL(msg.local_src);
  338. else
  339. contentMsg = msg.content;
  340. temp += '<div class="c-msg">'+ sendErrDom + '<dd class="word-bread word-bread-img" data-type="2">'+'<img onload="imgLoad(this)" data-src="'+ msg.content +'" data-code="'+ msg.id +'" data-preview-src="" data-preview-group="1" width="100" height="100" src="'+ getImgUrl(contentMsg) +'" /></dd></div>';
  341. $('img.l-previmg[data-code="'+ msg.id +'"]').remove();
  342. break;
  343. case 3://语音
  344. var rec = msg.local_src? JSON.parse(msg.local_src) : contentMsg? JSON.parse(contentMsg) : undefined;
  345. if(rec){
  346. var path = msg.local_src?msg.local_src:msg.content;
  347. temp += "<div class='c-msg'>"+ sendErrDom + "<dd class='word-bread audio' data-type='3' data-code='"+ msg.id +"' data-audio='" + contentMsg + "' data-loc-audio='" + path +"'>"+
  348. "<div style='width:"+ (rec.times*1.5+30) +"px' class='soundWav'>" +
  349. "<span class='soundWavT'>"+(rec? rec.times: "") +"\'\'</span>"+
  350. "</div>"+
  351. "</dd></div>";
  352. }
  353. break;
  354. case 12: //视频
  355. var videoInfo = msg.content.split(",");
  356. var shichang = formatSeconds(videoInfo[2]);//时长
  357. if(docInfo.code != msg.sender_id) {
  358. temp += '<div class="c-msg"><dd data-content="'+msg.content+'" class="preview-video" data-type="12" data-video="'+ getImgUrl(videoInfo[1])+'">'+
  359. '<img class="video-img-left" src="'+getImgUrl(videoInfo[0])+'">'+
  360. '<img class="bofang-icon-left" src="../../message/images/bofang_icon.png">'+
  361. '<img class="jianjiao-icon-left" src="../../message/images/zuoshanjiao_bg.png">'+
  362. '<span class="shichang-time-left">'+shichang+'</span>'+
  363. '</dd></div>';
  364. }else{
  365. temp += '<div class="c-msg"><dd data-content="'+msg.content+'" class="preview-video" data-type="12" data-video="'+getImgUrl(videoInfo[1])+'">'+
  366. '<img class="video-img-right" src="'+getImgUrl(videoInfo[0])+'">'+
  367. '<img class="bofang-icon-right" src="../../message/images/bofang_icon.png">'+
  368. '<img class="jianjiao-icon-right" src="../../message/images/youshanjiao_bg.png">'+
  369. '<span class="shichang-time-right">'+shichang+'</span>'+
  370. '</dd></div>';
  371. }
  372. break;
  373. case 15: //审核消息
  374. var rs = JSON.parse(contentMsg);
  375. var reason = "";
  376. if(rs.reason){
  377. reason = '<p class="ml10 c-333">原因:'+rs.reason+'</p>';
  378. }
  379. temp += '<div class="c-msg">'+ sendErrDom +
  380. '<dd class="word-bread" data-type="1">'+
  381. '<p class="c-333">【本消息为系统提醒】</p>'+
  382. '<p class="c-333">审核消息:</p>'+
  383. '<p class="ml10 c-333">'+rs.title+'</p>'+
  384. '<p class="ml10 c-333">审核结果:'+rs.result+'</p>'+reason+
  385. '<a href="javascript:void(0);" class="view-detail">点此查看详情</a>'+
  386. '</dd></div>';
  387. break;
  388. }
  389. html += temp + '</div></dl>';
  390. }
  391. if(isPre)
  392. lastId = msgList.list[msgList.list.length - 1].id;
  393. if(isClear){
  394. $("#contain").html(html);
  395. }else{
  396. if(isPre){
  397. $("#contain").prepend(html);
  398. if(scrollToTop)
  399. myScroll.refreshToTop();
  400. else
  401. myScroll.refresh(msgList.list.length==0);
  402. return;
  403. } else {
  404. $("#contain").append(html);
  405. }
  406. }
  407. myScroll.refreshToEnd();
  408. plus.nativeUI.closeWaiting();
  409. }
  410. function imgLoad(img){
  411. if(img.src.indexOf('data:')==0)
  412. return;
  413. var canvas = document.createElement('CANVAS'),
  414. ctx = canvas.getContext('2d'),
  415. newImg = new Image();
  416. newImg.src = img.src;
  417. canvas.height = newImg.height;
  418. canvas.width = newImg.width;
  419. ctx.drawImage(newImg, 0, 0);
  420. var src = newImg.src;
  421. var outputFormat = src.substring(src.lastIndexOf('.')+1);
  422. outputFormat = outputFormat.toLowerCase()=="jpg"? "jpeg" : outputFormat;
  423. var dataURL = canvas.toDataURL('image/' + outputFormat);
  424. // updateCacheMsgById($(img).attr('data-code'), "", "", "", dataURL);
  425. canvas = null;
  426. }
  427. /**
  428. * 获取消息
  429. */
  430. function getMsgs(page,sucHandle){
  431. sendGet(msgListUrl,{
  432. consult: consultInfo.id,
  433. page: page,
  434. pagesize: pageSize
  435. },null,function (res) {
  436. if (res.status === 200) {
  437. sucHandle.call(this,res);
  438. } else {
  439. mui.toast(res.msg);
  440. }
  441. });
  442. }
  443. /**
  444. * 设置获取到的最后一条消息
  445. */
  446. function setLastMsg(msg){
  447. if(!lastTimestamp || lastTimestamp>msg.timestamp){
  448. lastTimestamp = msg.timestamp;
  449. lastSeq = msg.seq;
  450. lastId = msg.id.indexOf("loc")==0? lastId : msg.id;
  451. }
  452. }
  453. //毫秒转换成时分秒
  454. function formatSeconds(value) {
  455. var theTime = parseInt(value/1000);// 秒
  456. var theTime1 = 0;// 分
  457. var theTime2 = 0;// 小时
  458. if(theTime > 60) {
  459. theTime1 = parseInt(theTime/60);
  460. theTime = parseInt(theTime%60);
  461. if(theTime1 > 60) {
  462. theTime2 = parseInt(theTime1/60);
  463. theTime1 = parseInt(theTime1%60);
  464. }
  465. }
  466. var result = ""+parseInt(theTime);//秒
  467. if(parseInt(theTime)<=9){
  468. result = "0"+parseInt(theTime);//秒
  469. }
  470. if(theTime1 > 0) {//分
  471. if(parseInt(theTime1)>9){
  472. result = ""+parseInt(theTime1)+":"+result;
  473. }else{
  474. result = "0"+parseInt(theTime1)+":"+result;
  475. }
  476. }
  477. if(theTime2 > 0) {//小时
  478. if(parseInt(theTime2)>9){
  479. result = ""+parseInt(theTime2)+":"+result;
  480. }else{
  481. result = "0"+parseInt(theTime2)+":"+result;
  482. }
  483. }
  484. var resResult = "";
  485. if(result.split(":").length==1){//秒
  486. resResult = "00:"+result;
  487. }else if(result.split(":").length==2){//分
  488. resResult = "00:"+result;
  489. }else{//时
  490. resResult = result;
  491. }
  492. return resResult;
  493. }
  494. /**
  495. * 定位聊天记录位置
  496. * @param {Object} id
  497. */
  498. function locationLog(id){
  499. var $logdom = $('.chat-log[data-code="'+ id +'"]');
  500. if($logdom.length){
  501. myScroll.scrollToElement( $logdom[0], 0, 0, -20 );
  502. plus.nativeUI.closeWaiting();
  503. } else {
  504. getCacheMsgById(id, function(tx, data){
  505. if(data.length>0){
  506. getCacheMsg("", "", function(tx, ls){
  507. showMsg(ls, false, true, false, true);
  508. }, data[0].timestamp, true )
  509. } else {
  510. getLastCacheMsg(function(tx, msg){
  511. var startmsg = msg.length>0? msg[msg.length-1] : undefined;
  512. getMsgs(1,function(ls){
  513. if(ls.length>0 && (!firstMsg || (firstMsg.timestamp<ls[0].timestamp) ))
  514. firstMsg = ls[0];
  515. showMsg(msg.concat(ls), false, true, false, true);
  516. })
  517. }, lastTimestamp);
  518. }
  519. })
  520. }
  521. }
  522. /**
  523. * 将字符串转为对象
  524. * @param {Object} data
  525. */
  526. function parseMsg(data){
  527. var d = [];
  528. for(var i=0; i<data.length; i++){
  529. d.push(JSON.parse(data[i]));
  530. }
  531. return d;
  532. }
  533. // function formatJyzd(msg, sendErrDom,yiduHtml){
  534. // // {"title":"2016年春节放假调休门诊安排通知","id":"ff1b39cfdf6a482c958140ba768474cc","img":"http://f1.yihuimg.com/TFS/upfile/WBJ/111/2016-02-05/160294_1454633481085_fullsize.png","content":"为了您的健康,我给您发送了一篇文章,请咨询查阅,如有问题,可随时与我沟通"}
  535. // if(msg){
  536. // //针对\n,\r等特殊字符,在json转换时会报错
  537. // msg = msg.replace(/\n/g, "\\n");
  538. // msg = msg.replace(/\r/g, "\\r");
  539. // msg = JSON.parse(msg);
  540. // // msg.img = msg.type==1? "../../../images/jkjl_share.png" : msg.img;
  541. // if(msg.type == 1){ //健康记录
  542. // msg.img = "../../../images/jkjl_share.png";
  543. // }else if(msg.type == 2){ //健康指导
  544. // var img = msg.img.split(",");
  545. // if(img[0] && img[0] != "null"){
  546. // msg.img = img[0];
  547. // }else{
  548. // msg.img = "../../../images/default_share_blue.png";
  549. // }
  550. // }else{ //健康教育
  551. // msg.img = msg.img;
  552. // }
  553. // var temp =
  554. // '<div class="c-msg">'+ sendErrDom +'<dd class="word-bread word-article" data-code="'+ msg.id+'" data-inner-type="'+ msg.type +'" data-type="4">'
  555. // + yiduHtml
  556. // + '<h4 class="text-ellipsis c-f18">'+ msg.title +'</h4>'
  557. // + '<div class="article-content"><img src="'+ msg.img +'">'
  558. // + '<div>'+ msg.content+'</div>'
  559. // + '</div>'
  560. // + '</dd></div>';
  561. // return temp;
  562. // }
  563. // return "";
  564. // }
  565. function matchUrl(content){
  566. var a = urlRegex.exec(content);
  567. if(a){
  568. var ah = '<a class="urlMatch" href="javascript:void(0)">'+ a[0] +'</a>';
  569. var str = "";
  570. var s = content.split(a[0]);
  571. // var i = content.indexOf(a[0]);
  572. for(var i=0; i<s.length; i++){
  573. if(i==s.length-1)
  574. str += s[i];
  575. else
  576. str += s[i] + ah;
  577. }
  578. return str;
  579. }
  580. return content;
  581. }
  582. //事件绑定
  583. $('#contain').on('tap', '.word-bread[data-type="3"]', function(){
  584. $('#contain').find('.word-bread[data-type="3"]').removeClass("active");
  585. var $dom = $(this);
  586. var loc = $(this).attr('data-loc-audio');
  587. $dom.addClass('active');
  588. if(!loc){
  589. var ser = $(this).attr('data-audio');
  590. if(ser){
  591. ser = JSON.parse(ser);
  592. //下载
  593. var path = "_doc/audio/"+new Date().getTime()+".wav";
  594. var dtask = plus.downloader.createDownload( ser.path, {
  595. filename: path
  596. },
  597. function ( d, status ) {
  598. if ( status == 200 ) {
  599. //更新数据,播放语音
  600. playRecord(path, $dom);
  601. } else {
  602. $dom.removeClass('active');
  603. mui.toast("下载语音失败!");
  604. }
  605. });
  606. dtask.start();
  607. } else{
  608. $dom.removeClass('active');
  609. mui.toast("语音数据丢失!");
  610. }
  611. } else {
  612. console.log(loc)
  613. loc = JSON.parse(loc);
  614. //播放语音
  615. playRecord(getImgUrl(loc.path), $dom);
  616. }
  617. }).on('tap', '.preview-video[data-type="12"]', function(){//播放视频
  618. var url = $(this).attr('data-video');
  619. if(plus.os.name=="iOS"){//ios
  620. $(document.body).find('video').remove();
  621. var html = '<video controls style="display:none;" preload="auto" width="1" height="1" src="'+url+'" ></video>';
  622. $(document.body).append(html);
  623. var video = $(document.body).find('video')[0];
  624. video.play();
  625. }else{//andriod
  626. var Intent = plus.android.importClass("android.content.Intent");
  627. var Uri = plus.android.importClass("android.net.Uri");
  628. var main = plus.android.runtimeMainActivity();
  629. var intent=new Intent(Intent.ACTION_VIEW);
  630. var uri=Uri.parse(url);
  631. intent.setDataAndType(uri,"video/*");
  632. main.startActivity(intent);
  633. }
  634. });
  635. //点击健康教育文章连接
  636. // .on('tap', '.word-article', function(){
  637. // var type = $(this).attr('data-inner-type');
  638. // var code = $(this).attr('data-code');
  639. // if(type==1){
  640. // mui.openWindow('../../jkjl/html/health-record.html', 'health-record', {
  641. // extras: {
  642. // patientCode: code,
  643. // qyRelation: 0
  644. // }
  645. // });
  646. // }else if(type == 2){
  647. // mui.openWindow('../../hzzd/html/guidance_info.html', 'guidance_info', {
  648. // extras:{
  649. // guideId: code
  650. // }
  651. // })
  652. // } else{
  653. // mui.openWindow("../../jkjy/html/article.html", "article", {
  654. // extras: {
  655. // article: code
  656. // }
  657. // })
  658. // }
  659. //
  660. // });
  661. //绑定挂号链接
  662. $(document).on('tap', 'a', function(){
  663. if($(this).attr("name") == "guahao"){
  664. var id = $(this).attr("data-id");
  665. mui.openWindow("../../wdyy/html/detail-appointment.html", "detail-appointment", {
  666. extras: {
  667. dataId: id
  668. }
  669. })
  670. }
  671. });
  672. $(document).on('tap','#xzzd',function(){
  673. // 回复咨询
  674. sendPost("/doctor/consult/readed", {
  675. consult:consultInfo.id
  676. }, function() {
  677. plus.nativeUI.closeWaiting()
  678. }, function() {
  679. plus.nativeUI.closeWaiting();
  680. if(type == 8){
  681. mui.openWindow('../../message/html/xufangzixun.html', 'xufangzixun.html', {
  682. extras: {
  683. sessionId: consultInfo.session_id,
  684. otherCode: otherCode,
  685. otherName: consultInfo.patientName,
  686. type: type // 解决type参数值与从“消息”页面进入时携带的值代表的意义不一致,导致了bug#3225 【医生端】健康咨询:首页健康咨询中进入im详情无法邀请全科/求助。
  687. }
  688. })
  689. }else{
  690. mui.openWindow('../../message/html/p2dzixun.html', 'p2dzixun', {
  691. extras: {
  692. sessionId: consultInfo.session_id,
  693. otherCode: otherCode,
  694. otherName: consultInfo.patientName,
  695. type: (type == 1 || type == 2 )?1:type // 解决type参数值与从“消息”页面进入时携带的值代表的意义不一致,导致了bug#3225 【医生端】健康咨询:首页健康咨询中进入im详情无法邀请全科/求助。
  696. }
  697. })
  698. }
  699. });
  700. }).on('tap','.tixys',function(){
  701. //提醒医生
  702. openWebview("../../message/html/p2p.html",{otherCode: qyDocInfo.doctor, otherName: qyDocInfo.name});
  703. });
  704. var player;
  705. var $playDom = false;
  706. function playRecord(path, dom){
  707. var isPlayBenDi = path.indexOf('.amr')>=0;
  708. if($playDom){
  709. if(player){
  710. if(plus.os.name=="iOS" && !isPlayBenDi){//ios
  711. player.pause();
  712. }else{
  713. player.stop();
  714. }
  715. $playDom.removeClass('active');
  716. if($playDom.attr('data-code') == dom.attr('data-code')){
  717. $playDom = false;
  718. return;
  719. }
  720. }
  721. }
  722. $playDom = dom;
  723. if(plus.os.name=="iOS" && !isPlayBenDi){//ios
  724. $(document.body).find('audio').remove();
  725. var html = '<audio preload="auto" src="'+getImgUrl(path)+'"></audio>';
  726. $(document.body).append(html);
  727. player = $(document.body).find('audio')[0];
  728. player.play();
  729. player.addEventListener('ended', function () {
  730. $playDom.removeClass('active');
  731. $playDom = false;
  732. }, false);
  733. }else{//andriod
  734. player = plus.audio.createPlayer(getImgUrl(path));
  735. player.play(function() {
  736. $playDom.removeClass('active');
  737. $playDom = false;
  738. }, function(e) {
  739. $playDom.removeClass('active');
  740. $playDom = false;
  741. });
  742. }
  743. }
  744. /**
  745. * 点击查看好友详细信息
  746. */
  747. $('#qun_detail').on("tap", function() {
  748. mui.openWindow('../../huanzhe/html/huanzhexinxi.html', 'huanzhexinxi.html', {
  749. extras: {
  750. patiCode: consultInfo.patient
  751. }
  752. });
  753. })
  754. //显示星级评价
  755. $('.j-show-btn').on('tap',function(){
  756. var $this = $(this);
  757. $('.j-show-btn').show();
  758. $this.hide();
  759. })
  760. });