xufangzixunxiangqing.js 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  1. //mui初始化
  2. mui.init({
  3. gestureConfig:{
  4. doubletap: true,
  5. longtap: true,
  6. hold: true,
  7. release: true
  8. }
  9. });
  10. var winHeight=window.innerHeight,//窗体高度
  11. winWidth=window.innerWidth,//窗体高度
  12. msgListUrl = 'doctor/consult/loglist',
  13. myScroll = null,
  14. self,
  15. docInfo,
  16. teamInfo,
  17. offTop =180,
  18. offBot = 52,
  19. pageSize = 100,
  20. prevImage,
  21. otherDocCodeArr=[],//储存可能存在的其他医生
  22. patiCode = '',//患者code
  23. sessionId = '',//患者拼接id
  24. sessionName = '',//患者姓名
  25. createTime = '',//咨询时间
  26. patientInfo,
  27. zx_status = '',//0 待回复 1进行中 2完成
  28. type = '', //咨询类型 8续方
  29. consultCode="",
  30. prescriptionCode, //续方的code
  31. prescriptionStatus, //续方的状态
  32. prescriptionMsg,//续方信息
  33. followObj,
  34. jwCode, //基卫那边存储的原处方的code
  35. lastTimestamp = '',
  36. urlRegex = new RegExp('((https|http|ftp|rtsp|mms)?://)'
  37. + '?(([0-9a-zA-Z_!~*\'().&=+$%-]+: )?[0-9a-zA-Z_!~*\'().&=+$%-]+@)?' //ftp的user@
  38. + '(([0-9]{1,3}\\.){3}[0-9]{1,3}' // IP形式的URL- 199.194.52.184
  39. + '|' // 允许IP和DOMAIN(域名)
  40. + '([0-9a-zA-Z_!~*\'()-]+\\.)*' // 域名- www.
  41. + '([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]\\.' // 二级域名
  42. + '(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
  43. + '(:[0-9]{1,4})?' // 端口- :80
  44. + '((/[0-9a-zA-Z_!~*\'().;?:@&=+$,%#-]+)+/?)?'
  45. + '((\\?[0-9a-zA-Z_!~*\'().;:@&=+$,%#-]+)+/?)?');
  46. var $title = $('#title'),
  47. $xzzd = $('#xzzd');
  48. mui.plusReady(function () {
  49. docInfo = JSON.parse(plus.storage.getItem("docInfo"));
  50. self = plus.webview.currentWebview();
  51. sessionId = self.sessionId;
  52. sessionName = self.sessionName;
  53. createTime = self.sessionTime;
  54. patiCode = self.patiCode;
  55. zx_status = self.stutas;
  56. type = self.type;
  57. consultCode = sessionId.split("_")[1];
  58. //设置标题
  59. $title.html(sessionName + createTime + '续方咨询');
  60. //获取成员信息
  61. getMembers();
  62. getPrescriptionInfo();
  63. getPatientInfo();
  64. getPatientDeviceList();
  65. if(zx_status==2){
  66. offTop = 105;
  67. $('.div-drug').hide()
  68. offBot = 10;
  69. }
  70. myScroll = $('#contain').lscroll({
  71. type: 2,
  72. // pullDownMsg1: "下拉加载更多", pullDownMsg2: "松手开始加载",
  73. // pullDownAction: function(g){
  74. // getMsgList(g.options.page, false, true);
  75. // },
  76. style: "top: "+ offTop +"px; bottom: "+ offBot +"px",
  77. });
  78. prevImage = mui.previewImage();
  79. bindEvents2();
  80. });
  81. /**
  82. * 获得续方的内容
  83. */
  84. function getPrescriptionInfo(){
  85. plus.nativeUI.showWaiting();
  86. var url = "/doctor/consult/prescriptionDetail",
  87. params = {consult: consultCode};
  88. sendGet(url, params, function(){
  89. plus.nativeUI.closeWaiting();
  90. mui.toast('请求失败')
  91. }, function(res){
  92. plus.nativeUI.closeWaiting();
  93. if(res.status == 200){
  94. prescriptionMsg = res.data;
  95. followObj = prescriptionMsg.followup=="null"?'':JSON.parse(prescriptionMsg.followup);
  96. jwCode = res.data.jwCode;
  97. prescriptionCode = res.data.code;
  98. $("#preDTName").text(res.data.symptoms+"-续方咨询");
  99. var status = res.data.status;
  100. prescriptionStatus = status;
  101. var statusName = getStatusName(status);
  102. $("#xfStatus").text(statusName);
  103. var drugmsg = "";
  104. for(j=0; j<res.data.prescriptionInfo.length; j++){
  105. var item = res.data.prescriptionInfo[j];
  106. drugmsg += item.drugName+" "+item.num+item.drugNumUnitName+" ";
  107. }
  108. $("#drugInfo").find('.j-msg').text(drugmsg);
  109. if(zx_status!=2){
  110. $('.div-drug').show()
  111. }
  112. if(status<0){
  113. $('.suifang').hide()
  114. }
  115. }else{
  116. mui.toast(res.msg);
  117. }
  118. }, true);
  119. }
  120. //获得患者信息
  121. function getPatientInfo(){
  122. var url = '/doctor/patient_label_info/patient',
  123. params = {patient: patiCode};
  124. sendPost(url, params, null, function(res){
  125. if(res.status == 200){
  126. patientInfo = res.data;
  127. }else{
  128. mui.toast(res.msg);
  129. }
  130. }, 'POST', '', true)
  131. }
  132. //判断患者是否有设备绑定
  133. function getPatientDeviceList(){
  134. var url = "doctor/device/PatientDeviceList",
  135. params = {patient: patiCode, page:1, pagesize: 2};
  136. sendGet(url, params, null, function(res){
  137. if(res.status == 200){
  138. if(res.data.length == 0){
  139. //没有绑定设备
  140. $(".tzjl").hide();
  141. }else{
  142. //绑定了设备
  143. $(".tzjl").show();
  144. }
  145. }else{
  146. //获取设备信息失败
  147. }
  148. }, true);
  149. }
  150. function bindEvents2(){
  151. //顶部内容的展开和收缩
  152. $("#expandBox").on('click', function(e){
  153. e.stopPropagation();
  154. var $this = $(this);
  155. if($this.hasClass('expand')){
  156. $this.removeClass('expand');
  157. $this.find('img').attr('src', '../images/zhankai_icon.png');
  158. $("#prescriptionInfo").hide();
  159. var top = $(".div-drug").height()+73;
  160. $("#wrapper1").css({
  161. "top" : top+'px'
  162. });
  163. }else{
  164. $this.addClass('expand');
  165. $this.find('img').attr('src', '../images/shouqi_icon.png');
  166. $("#prescriptionInfo").show();
  167. var top = $(".div-drug").height()+73;
  168. $("#wrapper1").css({
  169. "top" : top+'px'
  170. });
  171. }
  172. });
  173. //体征记录
  174. $(".tzjl").on('click', function(){
  175. mui.openWindow('../../jkjl/html/health-record.html', 'health-record', {
  176. extras: {
  177. patientCode: patiCode,
  178. patientName: patientInfo.name,
  179. qyRelation: 1
  180. }
  181. });
  182. });
  183. //检查检验
  184. $(".jcjy").on('click', function(){
  185. openWebview("../../huanzhe/html/jianchajianyan.html",{
  186. patiInfo: {
  187. code: patiCode
  188. }
  189. });
  190. });
  191. //诊断处方
  192. $(".zdcf").on('click', function(){
  193. openWebview("../../prescription/html/chufangxiangqing.html",{
  194. code: jwCode,
  195. patient:patiCode,
  196. preCode: prescriptionCode
  197. });
  198. });
  199. //历史续方
  200. $(".lsxf").on('click', function(){
  201. openWebview('../../prescription/html/juminxufangjilu.html', {
  202. teamCode: patientInfo.jtAdminTeam,
  203. patiCode: patiCode,
  204. patiName: patientInfo.name
  205. });
  206. });
  207. $("#prescriptionInfo").on("click", function(){
  208. openWebview('../../prescription/html/xufangxiangqing.html',{
  209. prescriptionCode: prescriptionCode,
  210. teamCode: patientInfo.jtAdminTeam
  211. });
  212. });
  213. //事件绑定
  214. $('#contain').on('tap', '.word-bread[data-type="3"]', function(){
  215. $('#contain').find('.word-bread[data-type="3"]').removeClass("active");
  216. var $dom = $(this);
  217. var loc = $(this).attr('data-loc-audio');
  218. $dom.addClass('active');
  219. if(!loc){
  220. var ser = $(this).attr('data-audio');
  221. if(ser){
  222. ser = JSON.parse(ser);
  223. //下载
  224. var path = "_doc/audio/"+new Date().getTime()+".wav";
  225. var dtask = plus.downloader.createDownload( ser.path, {
  226. filename: path
  227. },function ( d, status ) {
  228. if ( status == 200 ) {
  229. //更新数据,播放语音
  230. playRecord(path, $dom);
  231. } else {
  232. $dom.removeClass('active');
  233. mui.toast("下载语音失败!");
  234. }
  235. });
  236. dtask.start();
  237. } else{
  238. $dom.removeClass('active');
  239. mui.toast("语音数据丢失!");
  240. }
  241. } else {
  242. loc = JSON.parse(loc);
  243. //播放语音
  244. playRecord(getImgUrl(loc.path), $dom);
  245. }
  246. }).on('tap', '.preview-video[data-type="12"]', function(){//播放视频
  247. var url = $(this).attr('data-video');
  248. if(plus.os.name=="iOS"){//ios
  249. $(document.body).find('video').remove();
  250. var html = '<video controls style="display:none;" preload="auto" width="1" height="1" src="'+url+'" ></video>';
  251. $(document.body).append(html);
  252. var video = $(document.body).find('video')[0];
  253. video.play();
  254. }else{//andriod
  255. var Intent = plus.android.importClass("android.content.Intent");
  256. var Uri = plus.android.importClass("android.net.Uri");
  257. var main = plus.android.runtimeMainActivity();
  258. var intent=new Intent(Intent.ACTION_VIEW);
  259. var uri=Uri.parse(url);
  260. intent.setDataAndType(uri,"video/*");
  261. main.startActivity(intent);
  262. }
  263. });
  264. $(document).on('tap','#xzzd',function(){
  265. //回复咨询
  266. sendPost("/doctor/consult/readed", {
  267. consult:consultCode
  268. }, function() {
  269. plus.nativeUI.closeWaiting()
  270. }, function() {
  271. plus.nativeUI.closeWaiting();
  272. mui.openWindow('../../message/html/xufangzixun.html', 'xufangzixun.html', {
  273. extras: {
  274. sessionId: sessionId,
  275. otherCode: patiCode,
  276. otherName: patientInfo.name,
  277. type: 8
  278. }
  279. });
  280. })
  281. });
  282. /**
  283. * 点击查看好友详细信息
  284. */
  285. $('#qun_detail').on("tap", function() {
  286. mui.openWindow('../../huanzhe/html/huanzhexinxi.html', 'huanzhexinxi.html', {
  287. extras: {
  288. patiCode: patiCode
  289. }
  290. });
  291. });
  292. //显示星级评价
  293. $('.j-show-btn').on('tap',function(){
  294. var $this = $(this);
  295. $('.j-show-btn').show();
  296. $this.hide();
  297. });
  298. //点击查看详情,查看续方详情
  299. $("body").on('tap', '.view-detail', function(){
  300. openWebview('xufangxiangqing.html',{
  301. prescriptionCode: prescriptionCode,
  302. teamCode: patientInfo.jtAdminTeam
  303. });
  304. })
  305. //随访调查
  306. $("body").on('tap', ".viewData", function(){
  307. var type = $(this).attr('data-type')
  308. mui.openWindow('../../message/html/questionaires.html', 'questionaires', {
  309. extras: {
  310. pro_id:type,
  311. prescriptionCode: prescriptionCode,
  312. followupid:followObj.id
  313. }
  314. })
  315. })
  316. //登记随访
  317. function registerSuifang(){
  318. var followClass;
  319. if(prescriptionMsg.symptoms == "高血压"){
  320. followClass = 1;
  321. }else if(prescriptionMsg.symptoms == "糖尿病"){
  322. followClass = 2;
  323. }else{
  324. followClass = '1,2';
  325. }
  326. mui.openWindow('../../suifang/html/follow_way.html', 'xf_follow_way', {
  327. extras: {
  328. followup_id:followObj.id,
  329. followClass:followClass,
  330. patientInfo:patientInfo,
  331. prescriptionCode: prescriptionCode,
  332. prescriptionStatus:prescriptionMsg.status
  333. }
  334. })
  335. }
  336. $(".suifang").on('click', function(){
  337. if(! followObj){
  338. registerSuifang()
  339. }else{
  340. if(followObj.status == 2){
  341. registerSuifang()
  342. }else{
  343. mui.openWindow('../../suifang/html/fvDetail.html', 'xf_fvDetail', {
  344. extras: {
  345. followup_id:followObj.id,
  346. prescriptionCode:prescriptionCode
  347. }
  348. })
  349. }
  350. }
  351. })
  352. $(".wenjuan").on('click', function(){
  353. mui.openWindow('../../message/html/wenjuan.html', 'wenjuan', {
  354. extras: {
  355. prescriptionCode: prescriptionCode,
  356. followup_id:followObj.id,
  357. zx_Status: zx_status==2?1:0
  358. }
  359. })
  360. })
  361. $("body").on('tap', ".fillData", function(){
  362. if(! followObj){
  363. mui.toast('随访已不存在')
  364. return
  365. }else{
  366. var type = $(this).attr('data-type');
  367. var healthindexid = $(this).attr('data-health');
  368. var url;
  369. if(type == 1){
  370. url="doctor/prescription/followupcontent/importbloodpressure"
  371. }else{
  372. url="doctor/prescription/followupcontent/importbloodsugar"
  373. }
  374. plus.nativeUI.showWaiting();
  375. sendPost(url,{followupid:followObj.id,prescriptioncode:prescriptionCode,healthindexid:healthindexid},function(){
  376. plus.nativeUI.closeWaiting();
  377. mui.toast('请求失败')
  378. }, function(res){
  379. plus.nativeUI.closeWaiting();
  380. if(res.status == 200){
  381. mui.toast('成功填入随访记录')
  382. }else{
  383. mui.toast(res.msg)
  384. }
  385. })
  386. }
  387. })
  388. $(".follow").click(function(e){
  389. e.stopPropagation();
  390. if(! followObj){
  391. mui.toast('随访已不存在')
  392. return
  393. }else{
  394. plus.nativeUI.showWaiting();
  395. sendPost('doctor/prescription/followupcontent/importdrugs',{followupid:followObj.id,prescriptioncode:prescriptionCode},function(){
  396. plus.nativeUI.closeWaiting();
  397. mui.toast('请求失败')
  398. }, function(res){
  399. plus.nativeUI.closeWaiting();
  400. if(res.status == 200){
  401. mui.toast('成功填入随访记录')
  402. }else{
  403. mui.toast(res.msg)
  404. }
  405. })
  406. }
  407. })
  408. //头部导航
  409. mui('#nav').scroll({
  410. deceleration: 0.0005,
  411. scrollY: false, //是否竖向滚动
  412. scrollX: true, //是否横向滚动
  413. indicators: false
  414. })
  415. }
  416. function getStatusName(status){
  417. var name = "",
  418. img = "";
  419. status = status + '';
  420. switch (status){
  421. case '-3':
  422. name = '支付过期';
  423. break;
  424. case '-2':
  425. name = '患者取消';
  426. break;
  427. case '-1':
  428. name = '审核不通过';
  429. break;
  430. case '0':
  431. case '2':
  432. case '3':
  433. case '4':
  434. case '10':
  435. name = '审核中';
  436. break;
  437. case '20':
  438. name = '药师审核中';
  439. break;
  440. case '21':
  441. name = '药师审核失败';
  442. break;
  443. case '30':
  444. name = '开方中';
  445. break;
  446. case '31':
  447. name = '开方失败';
  448. break;
  449. case '40':
  450. name = '待支付';
  451. break;
  452. case '41':
  453. name = '支付失败';
  454. break;
  455. case '50':
  456. name = '配药中';
  457. break;
  458. case '60':
  459. name = '等待领药';
  460. break;
  461. case '61':
  462. case '62':
  463. case '65':
  464. case '69':
  465. name = '配送中';
  466. break;
  467. case '100':
  468. name = '已完成';
  469. break;
  470. default:
  471. break;
  472. }
  473. return name;
  474. }
  475. /**
  476. * 获取消息(下拉刷新)
  477. */
  478. function getMsgList(pageIndex, isClear, isPre) {
  479. getMsgs(pageIndex,function(data){
  480. if (!!!data.list) {
  481. plus.nativeUI.closeWaiting();
  482. myScroll.refresh(!!!data.list);
  483. return;
  484. }
  485. showMsg(data.list, isClear, isPre);
  486. })
  487. }
  488. /**
  489. * 获取成员信息
  490. */
  491. function getMembers(callBack){
  492. imClient.Sessions.getParticipants(sessionId, function(rs){
  493. members = {};
  494. $.each( rs , function(i, v) {
  495. if(v.id!=docInfo.code && v.id!=patiCode){
  496. otherDocCodeArr.push(v.id)
  497. }
  498. })
  499. isSign()
  500. }, function(msg){
  501. mui.toast("获取成员列表失败!");
  502. })
  503. }
  504. //判断是否有签约关系
  505. function isSign() {
  506. //status=2 已完成回复
  507. if (zx_status != 2) {
  508. sendGet("doctor/family_contract/doctor_patient_sign_exist", {
  509. doctor: docInfo.code,
  510. patient: patiCode
  511. }, null, function(res) {
  512. if(res.status == 200) {
  513. if(res.data.status == -1 && res.data.msg === '无签约关系'){
  514. //没有签约关系
  515. $xzzd.show();//与团队长没有签约关系
  516. }else{
  517. $xzzd.show();
  518. }
  519. } else {
  520. mui.toast("获取签约关系失败");
  521. }
  522. })
  523. }else{
  524. //获取被评价成员
  525. sendGet("doctor/consult/evaluate/list", {
  526. consult:consultCode,
  527. type:1
  528. }, null, function(res) {
  529. if(res.status == 200) {
  530. if(res.list.length > 0){ //已经评分
  531. if(res.list[0].type == 1){//实名
  532. var obj = _.groupBy(res.list, function(item){ return item.doctor; })
  533. for(var key in obj){
  534. var arr = obj[key],
  535. dataObj = {};
  536. $.each( arr , function(i, v) {
  537. if(v.evaluate_type == 1){
  538. dataObj.ability = v.score;
  539. }
  540. if(v.evaluate_type == 2){
  541. dataObj.attitude = v.score;
  542. }
  543. if(v.evaluate_type == 3){
  544. dataObj.speed = v.score;
  545. }
  546. })
  547. dataObj.name = arr[0].name;
  548. dataObj.avatar = arr[0].photo;
  549. showStar(dataObj);
  550. }
  551. $('#service').show();
  552. }else{
  553. $('.no-service').show();
  554. }
  555. }else{
  556. $('.no-service').show();
  557. }
  558. }else{
  559. mui.toast("获取评分数据失败");
  560. }
  561. })
  562. }
  563. getMsgs(1,function (res) {
  564. if (!!!res.list) {
  565. plus.nativeUI.closeWaiting();
  566. mui.toast("暂无咨询记录!");
  567. myScroll.refresh(!!!res.list);
  568. return;
  569. }
  570. showMsg(res.list, false, false, true)
  571. });
  572. }
  573. /**
  574. * 获取聊天图片列表
  575. */
  576. function getImgMsgList(handle) {
  577. im.getPrivateMsg(getUserId(), otherCode, lastId, pageSize, function(data) {
  578. chatCache.imgs = data.records.reverse();
  579. appendPrevImgs(chatCache.imgs);
  580. if(handle) handle(data);
  581. }, 2);
  582. }
  583. //显示星星
  584. function showStar(obj){
  585. if(obj){
  586. var abList = addStars(obj.ability)
  587. var atList = addStars(obj.attitude)
  588. var spList = addStars(obj.speed)
  589. 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>';
  590. $('#starList').append(html);
  591. }
  592. }
  593. function addStars(score){
  594. var list='',
  595. num='';
  596. var one = '<li><img src="../images/icon_xingxing.png" alt="" /></li>';
  597. num = Math.floor(score/20);
  598. for(var i=0;i<num;i++){
  599. list += one;
  600. }
  601. return list
  602. }
  603. /**
  604. * 显示消息
  605. */
  606. function showMsg(msgList, isClear, isPre, appendImg, scrollToTop) {
  607. if(msgList.list.length == 0) {
  608. plus.nativeUI.closeWaiting();
  609. myScroll.refresh(msgList.length==0);
  610. return;
  611. }
  612. var html = "";
  613. var preTime = 0;
  614. var typeMsg = 1;
  615. var doctor_img ;
  616. var doctor_name = "";
  617. var msg;
  618. var sender;
  619. var users = msgList.users;
  620. var isDoc = false;
  621. for(var i = msgList.list.length - 1; i >= 0; i--) {
  622. msg = msgList.list[i];
  623. msg = JSON.parse(msg);
  624. setLastMsg(msg);
  625. typeMsg = parseInt(msg.content_type);
  626. if (typeMsg === 4|| typeMsg==14) {
  627. continue;
  628. }
  629. var contentMsg = msg.content;
  630. if(typeMsg == 7 || typeMsg==10 || typeMsg==13){
  631. if(typeMsg == 7 && msg.sender_id == 'system'){
  632. contentMsg = "居民24小时内未回复,系统自动结束咨询";
  633. }
  634. html += '<div class="time-tips"><div>'+ contentMsg +' </div></div>';
  635. continue;
  636. } else if(typeMsg == 5){
  637. var con = JSON.parse(msg.content);
  638. if(msg.sender_id == docInfo.code){
  639. 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>';
  640. }
  641. continue;
  642. }
  643. var _class = ["chat-log"];
  644. if (users.length > 0) {
  645. for (var ii = 0; ii < users.length; ii++) {
  646. var user = users[ii];
  647. if (user['id'] === msg['sender_id']) {
  648. doctor_img = getImgUrl(user['avatar']);
  649. doctor_name = user['name'];
  650. if(docInfo.code != user['id']) {
  651. _class.push("chat-left");
  652. } else {
  653. _class.push("chat-right");
  654. }
  655. break;
  656. }
  657. }
  658. }
  659. if(msg.timestamp - preTime > 60 * 1000) {
  660. preTime = msg.timestamp;
  661. var date = new Date();
  662. date.setTime(msg.timestamp);
  663. var time = date.format('yyyy-MM-dd hh:mm:ss');
  664. html += '<div class="time-tips"><span>' + time + '</span></div>';
  665. }
  666. //type:1.文字 2.图片 3.音频
  667. var temp = '<dl data-type="'+ typeMsg +'" data-code="'+ msg.id +'" class="' + _class.join(" ") + '">'+
  668. '<dt style="height: auto; text-align: center;"><a><img src="' + doctor_img + '" class="c-images-cycle" /></a></dt>' +
  669. '<div class="c-content"><span class="c-f12 name">' + doctor_name + '</span>';
  670. var sendErrDom = "";
  671. if(!msg.beforeSend && msg.id && msg.id.indexOf('loc')==0){
  672. sendErrDom = "<i data-info='"+ JSON.stringify(msg) +"' class='c-tips'></i>";
  673. }
  674. switch(typeMsg) {
  675. case 0:
  676. case 1://普通文本
  677. case 8://求助文本
  678. temp += '<div class="c-msg">'+ sendErrDom +'<dd class="word-bread" data-type="1"><span>' + matchUrl(contentMsg) + '</span></dd></div>';
  679. break;
  680. case 6://开始咨询文本
  681. var rs = JSON.parse(contentMsg);
  682. var tzMsg = rs.tzMsg;
  683. temp += '<div class="c-msg">'+ sendErrDom +
  684. '<dd class="word-bread new-sty" data-type="1">'+
  685. '<div class="new-messg"><p class="new-mess-p">本消息为系统提醒</p></div>'+
  686. '<p class="c-333">'+rs.title+'</p>'+
  687. '<p class="c-333">体征信息:'+rs.tzMsg+'</p>'+
  688. '</dd></div>';
  689. break;
  690. case 2://图片
  691. case 9://求助图片
  692. if(msg.local_src=="data:,"){
  693. contentMsg = msg.content;
  694. }else if(msg.local_src){
  695. contentMsg = msg.local_src.indexOf('data:')==0? msg.local_src: plus.io.convertLocalFileSystemURL(msg.local_src);
  696. }else{
  697. contentMsg = msg.content;
  698. }
  699. 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>';
  700. $('img.l-previmg[data-code="'+ msg.id +'"]').remove();
  701. break;
  702. case 3://语音
  703. var rec = msg.local_src? JSON.parse(msg.local_src) : contentMsg? JSON.parse(contentMsg) : undefined;
  704. if(rec){
  705. var path = msg.local_src?msg.local_src:msg.content;
  706. 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 +"'>"+
  707. "<div style='width:"+ (rec.times*1.5+30) +"px' class='soundWav'>" +
  708. "<span class='soundWavT'>"+(rec? rec.times: "") +"\'\'</span>"+
  709. "</div>"+
  710. "</dd></div>";
  711. }
  712. break;
  713. case 12: //视频
  714. var videoInfo = msg.content.split(",");
  715. var shichang = formatSeconds(videoInfo[2]);//时长
  716. if(docInfo.code != msg.sender_id) {
  717. temp += '<div class="c-msg"><dd data-content="'+msg.content+'" class="preview-video" data-type="12" data-video="'+getImgUrl(videoInfo[1])+'">'+
  718. '<img class="video-img-left" src="'+getImgUrl(videoInfo[0])+'">'+
  719. '<img class="bofang-icon-left" src="../../message/images/bofang_icon.png">'+
  720. '<img class="jianjiao-icon-left" src="../../message/images/zuoshanjiao_bg.png">'+
  721. '<span class="shichang-time-left">'+shichang+'</span>'+
  722. '</dd></div>';
  723. }else{
  724. temp += '<div class="c-msg"><dd data-content="'+msg.content+'" class="preview-video" data-type="12" data-video="'+getImgUrl(videoInfo[1])+'">'+
  725. '<img class="video-img-right" src="'+getImgUrl(videoInfo[0])+'">'+
  726. '<img class="bofang-icon-right" src="../images/bofang_icon.png">'+
  727. '<img class="jianjiao-icon-right" src="../images/youshanjiao_bg.png">'+
  728. '<span class="shichang-time-right">'+shichang+'</span>'+
  729. '</dd></div>';
  730. }
  731. break;
  732. case 15: //审核消息
  733. var rs = JSON.parse(contentMsg);
  734. var reason = "";
  735. if(rs.reason){
  736. reason = '<p class="c-333 xf-word">原因:'+rs.reason+'</p>';
  737. }
  738. temp += '<div class="c-msg">'+ sendErrDom +
  739. '<dd class="word-bread new-sty" data-type="1">'+
  740. '<div class="new-messg"><p class="new-mess-p">本消息为系统提醒</p></div>'+
  741. '<p class="c-333">'+rs.title+'</p>'+
  742. '<p class="c-333">审核结果:'+rs.result+'</p>'+reason+
  743. '<a href="javascript:void(0);" class="view-detail">点此查看详情</a>'+
  744. '</dd></div>';
  745. break;
  746. case 16:
  747. var rs = JSON.parse(contentMsg);
  748. if(msg.sender_id == docInfo.code){
  749. temp += '<dd class="word-bread survey-msg"><div class="msg-body clearfix">'+
  750. '<p class="c-333 c-f15">'+rs.text+'</p>'+
  751. '</div></dd>';
  752. }else{
  753. var alertMsg;
  754. if(rs.needUpload == 'false'){
  755. alertMsg = rs.tzAlert+' <a href="javascript:;" data-health="'+rs.healthindexid+'" data-type="'+rs.type+'" class="fillData">自动填入随访记录</a>'
  756. temp += '<div class="c-msg">'+
  757. '<dd class="word-bread new-sty" data-type="1">'+
  758. '<div class="new-messg"><p class="new-mess-p">本消息为系统提醒</p></div>'+
  759. '<p class="c-333">'+rs.tzMsg+'</p>'+
  760. '<p class="c-333">'+rs.tzTime+'</p>'+
  761. '<p class="c-333">'+alertMsg+'</p>'+
  762. '</dd></div>';
  763. }else{
  764. alertMsg = rs.tzAlert
  765. temp += '<div class="c-msg">'+
  766. '<dd class="word-bread new-sty" data-type="1">'+
  767. '<div class="new-messg"><p class="new-mess-p">本消息为系统提醒</p></div>'+
  768. // '<p class="c-333">'+rs.tzMsg+'</p>'+
  769. // '<p class="c-333">'+rs.tzTime+'</p>'+
  770. '<p class="c-333">'+alertMsg+'</p>'+
  771. '</dd></div>';
  772. }
  773. }
  774. break;
  775. case 17://随访调查
  776. var rs = JSON.parse(contentMsg);
  777. if(msg.sender_id == docInfo.code){
  778. temp += '<dd class="word-bread survey-msg"><div class="msg-body clearfix">'+
  779. '<p class="c-333 c-f15">'+rs.text+'</p>'+
  780. '</div></dd><div class="xf-notice">'+rs.doctorremind+'</div>';
  781. }else{
  782. if(rs.sysMsg){
  783. temp += '<div class="c-msg">'+
  784. '<dd class="word-bread new-sty" data-type="1">'+
  785. '<div class="new-messg"><p class="new-mess-p">本消息为系统提醒</p></div>'+
  786. '<p class="c-333">'+rs.text+'</p>'+
  787. '<a href="javascript:;" data-type="'+rs.msgType+'" class="viewData">查看</a>'+
  788. '</dd></div>';
  789. }
  790. }
  791. break;
  792. }
  793. html += temp + '</div></dl>';
  794. }
  795. if(isPre)
  796. lastId = msgList.list[msgList.list.length - 1].id;
  797. if(isClear){
  798. $("#contain").append(html);
  799. }else{
  800. if(isPre){
  801. $("#contain").prepend(html);
  802. if(scrollToTop)
  803. myScroll.refreshToTop();
  804. else
  805. myScroll.refresh(msgList.list.length==0);
  806. return;
  807. } else {
  808. $("#contain").append(html);
  809. }
  810. }
  811. myScroll.refreshToEnd();
  812. plus.nativeUI.closeWaiting();
  813. }
  814. function imgLoad(img){
  815. if(img.src.indexOf('data:')==0)
  816. return;
  817. var canvas = document.createElement('CANVAS'),
  818. ctx = canvas.getContext('2d'),
  819. newImg = new Image();
  820. newImg.src = img.src;
  821. canvas.height = newImg.height;
  822. canvas.width = newImg.width;
  823. ctx.drawImage(newImg, 0, 0);
  824. var src = newImg.src;
  825. var outputFormat = src.substring(src.lastIndexOf('.')+1);
  826. outputFormat = outputFormat.toLowerCase()=="jpg"? "jpeg" : outputFormat;
  827. var dataURL = canvas.toDataURL('image/' + outputFormat);
  828. canvas = null;
  829. }
  830. /**
  831. * 获取消息
  832. */
  833. function getMsgs(page,sucHandle){
  834. sendGet(msgListUrl,{
  835. consult: consultCode,
  836. page: page,
  837. pagesize: pageSize
  838. },null,function (res) {
  839. if (res.status === 200) {
  840. sucHandle.call(this,res);
  841. } else {
  842. mui.toast(res.msg);
  843. }
  844. });
  845. }
  846. /**
  847. * 设置获取到的最后一条消息
  848. */
  849. function setLastMsg(msg){
  850. if(!lastTimestamp || lastTimestamp>msg.timestamp){
  851. lastTimestamp = msg.timestamp;
  852. lastSeq = msg.seq;
  853. lastId = msg.id.indexOf("loc")==0? lastId : msg.id;
  854. }
  855. }
  856. //毫秒转换成时分秒
  857. function formatSeconds(value) {
  858. var theTime = parseInt(value/1000);// 秒
  859. var theTime1 = 0;// 分
  860. var theTime2 = 0;// 小时
  861. if(theTime > 60) {
  862. theTime1 = parseInt(theTime/60);
  863. theTime = parseInt(theTime%60);
  864. if(theTime1 > 60) {
  865. theTime2 = parseInt(theTime1/60);
  866. theTime1 = parseInt(theTime1%60);
  867. }
  868. }
  869. var result = ""+parseInt(theTime);//秒
  870. if(parseInt(theTime)<=9){
  871. result = "0"+parseInt(theTime);//秒
  872. }
  873. if(theTime1 > 0) {//分
  874. if(parseInt(theTime1)>9){
  875. result = ""+parseInt(theTime1)+":"+result;
  876. }else{
  877. result = "0"+parseInt(theTime1)+":"+result;
  878. }
  879. }
  880. if(theTime2 > 0) {//小时
  881. if(parseInt(theTime2)>9){
  882. result = ""+parseInt(theTime2)+":"+result;
  883. }else{
  884. result = "0"+parseInt(theTime2)+":"+result;
  885. }
  886. }
  887. var resResult = "";
  888. if(result.split(":").length==1){//秒
  889. resResult = "00:"+result;
  890. }else if(result.split(":").length==2){//分
  891. resResult = "00:"+result;
  892. }else{//时
  893. resResult = result;
  894. }
  895. return resResult;
  896. }
  897. /**
  898. * 定位聊天记录位置
  899. * @param {Object} id
  900. */
  901. function locationLog(id){
  902. var $logdom = $('.chat-log[data-code="'+ id +'"]');
  903. if($logdom.length){
  904. myScroll.scrollToElement( $logdom[0], 0, 0, -20 );
  905. plus.nativeUI.closeWaiting();
  906. } else {
  907. getCacheMsgById(id, function(tx, data){
  908. if(data.length>0){
  909. getCacheMsg("", "", function(tx, ls){
  910. showMsg(ls, false, true, false, true);
  911. }, data[0].timestamp, true )
  912. } else {
  913. getLastCacheMsg(function(tx, msg){
  914. var startmsg = msg.length>0? msg[msg.length-1] : undefined;
  915. getMsgs(1,function(ls){
  916. if(ls.length>0 && (!firstMsg || (firstMsg.timestamp<ls[0].timestamp) ))
  917. firstMsg = ls[0];
  918. showMsg(msg.concat(ls), false, true, false, true);
  919. })
  920. }, lastTimestamp);
  921. }
  922. })
  923. }
  924. }
  925. /**
  926. * 将字符串转为对象
  927. * @param {Object} data
  928. */
  929. function parseMsg(data) {
  930. var d = [];
  931. for(var i = 0; i < data.length; i++) {
  932. d.push(JSON.parse(data[i]));
  933. }
  934. return d;
  935. }
  936. function matchUrl(content){
  937. var a = urlRegex.exec(content);
  938. if(a){
  939. var ah = '<a class="urlMatch" href="javascript:void(0)">'+ a[0] +'</a>';
  940. var str = "";
  941. var s = content.split(a[0]);
  942. for(var i=0; i<s.length; i++){
  943. if(i==s.length-1)
  944. str += s[i];
  945. else
  946. str += s[i] + ah;
  947. }
  948. return str;
  949. }
  950. return content;
  951. }
  952. var player;
  953. var $playDom = false;
  954. function playRecord(path, dom){
  955. var isPlayBenDi = path.indexOf('.amr')>=0;
  956. if($playDom){
  957. if(player){
  958. if(plus.os.name=="iOS" && !isPlayBenDi){//ios
  959. player.pause();
  960. }else{
  961. player.stop();
  962. }
  963. $playDom.removeClass('active');
  964. if($playDom.attr('data-code') == dom.attr('data-code')){
  965. $playDom = false;
  966. return;
  967. }
  968. }
  969. }
  970. $playDom = dom;
  971. if(plus.os.name=="iOS" && !isPlayBenDi){//ios
  972. $(document.body).find('audio').remove();
  973. var html = '<audio preload="auto" src="'+getImgUrl(path)+'"></audio>';
  974. $(document.body).append(html);
  975. player = $(document.body).find('audio')[0];
  976. player.play();
  977. player.addEventListener('ended', function () {
  978. $playDom.removeClass('active');
  979. $playDom = false;
  980. }, false);
  981. }else{//andriod
  982. player = plus.audio.createPlayer(getImgUrl(path));
  983. player.play(function() {
  984. $playDom.removeClass('active');
  985. $playDom = false;
  986. }, function(e) {
  987. $playDom.removeClass('active');
  988. $playDom = false;
  989. });
  990. }
  991. }