xufangzixunxiangqing.js 35 KB

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