p2p.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. var lastId = 0;
  2. var prevImage;
  3. var isHidden = "";
  4. var consultData;
  5. var isJieshuCaozuo = false;
  6. mui.plusReady(function() {
  7. self = plus.webview.currentWebview();
  8. isHidden = self.isHidden;
  9. if(isHidden){
  10. $(".header-group").hide();
  11. }
  12. var sessionName = self.name;
  13. if(sessionName){
  14. $("#title").html(sessionName)
  15. }
  16. plus.nativeUI.showWaiting();
  17. getMineInfo();//初始化个人信息
  18. createSession(2, getUnfinishConsult);
  19. prevImage = mui.previewImage();
  20. var opener = self.opener();
  21. if(opener && opener.id=="mingyizixunliebiao"){
  22. backToMyzx();
  23. } else if(self.from == "faqiqiuzhu"){
  24. backToParent();
  25. } else if(opener && opener.id=="faqizixun") {
  26. mui.back = backToWebviewById("mingyizixunliebiao",false,function() {
  27. var mainWebview = plus.webview.getWebviewById("mingyizixunliebiao");
  28. mui.fire(mainWebview,"activeItem");
  29. });
  30. } else if(opener && (opener.id=="jumingim.html" || opener.id=="yishengim.html")){
  31. mui.back = backToWebviewById(opener.id,false,function() {
  32. var mainWebview = plus.webview.getWebviewById(opener.id);
  33. mui.fire(mainWebview,"xiaoxiUpdate");
  34. self.close();
  35. });
  36. } else if (opener && opener.id=="zuyuanziliao") {
  37. function closeOpener(cur){
  38. if(cur.id != "xiaoxi.html" && cur.id != "main" && cur.id != "../../tuandui/html/tuandui.html" &&
  39. cur.id != "mine.html" && cur.id != "home1.html" && cur.id != "home2.html" && cur.id != "huanzhe.html"
  40. && cur.id!="yishengim.html"){
  41. var opener = cur.opener();
  42. cur.close();
  43. closeOpener(opener);
  44. }
  45. }
  46. mui.back = function(){
  47. // if(docInfo.level == 1){
  48. // mui.fire(plus.webview.getWebviewById("home1.html"), "refresh");;
  49. // } else {
  50. // var mainWebview = plus.webview.getWebviewById("main");
  51. // mui.fire(mainWebview,"activeXiaoxi");
  52. // mainWebview.show();
  53. // }
  54. mui.later(function(){
  55. closeOpener(self.opener());
  56. self.close();
  57. }, 300);
  58. }
  59. } else {
  60. backToParent();
  61. }
  62. });
  63. function getUnfinishConsult(){
  64. getMembers(function(){
  65. if(self.consultData){
  66. initPage(self.consultData);
  67. } else {
  68. service.hasUnfinishedConsult(otherCode, function(res){
  69. initPage(res.data);
  70. })
  71. }
  72. })
  73. }
  74. function initPage(data){
  75. consultData = data;
  76. if(self.type=="doctor-to-doctor"){
  77. //医生间,正常聊天
  78. } else if(consultData.consult){
  79. //存在未结束的咨询
  80. $('#wrapper1').css({top:'46px'});
  81. if(myScroll) myScroll.refresh();
  82. $('.topmsg').html('首次回复24小时后,将自动结束咨询<a href="javascript:void(0)" onclick="jieshu()">立即结束</a>').show();
  83. if(consultData.zxGroupCode){
  84. //未结束的咨询属于求助咨询,type为10
  85. if(docInfo.code==consultData.from)
  86. $('.forward').show();
  87. }
  88. } else {
  89. //不存在未结束的咨询
  90. $('#wrapper1').css({bottom: '0px'});
  91. $('#input_div').hide();
  92. }
  93. //getNewMsgs(true);//获取新消息
  94. getFirstMsgs();
  95. }
  96. /**
  97. * 获取聊天图片列表
  98. */
  99. function getImgMsgList(handle){
  100. im.getPrivateMsg(getUserId(), otherCode, lastId, pageSize, function(data) {
  101. console.log("imgs:" + JSON.stringify(data));
  102. chatCache.imgs = data.records.reverse();
  103. appendPrevImgs(chatCache.imgs);
  104. if(handle) handle(data);
  105. }, 2);
  106. }
  107. /**
  108. * 发送消息
  109. */
  110. function uploadMsg(type, content, locSrc, isNotSend, callBack) {
  111. if(consultData && consultData.consult){
  112. service.isConsultFinished(consultData.consult, function(res){
  113. if(res.data==0){
  114. uploadMsgBase(type, content, locSrc, isNotSend, callBack);
  115. } else {
  116. $('.topmsg').hide();
  117. $('#wrapper1').css({top:'16px', bottom: '0px'});
  118. $('#input_div').hide();
  119. $('.forward').hide();
  120. myScroll.refresh();
  121. }
  122. })
  123. } else {
  124. uploadMsgBase(type, content, locSrc, isNotSend, callBack);
  125. }
  126. }
  127. function jieshu(){
  128. mui.confirm("结束咨询后,居民及所有医生均无法再次回复,是否确认继续结束?", "", ["继续结束", "我再看看"], function(e) {
  129. if(e.index == 0) {
  130. sendPost("doctor/consult/finish_consult", {
  131. consult: consultData.consult
  132. }, null, function(res) {
  133. if(res.status == 200){
  134. isJieshuCaozuo = true;
  135. $('.topmsg').html("咨询求助已结束");
  136. $('.forward').hide();
  137. $('#input_div').hide();
  138. $('#wrapper1').css({bottom:'0px'});
  139. myScroll.refresh();
  140. mui.toast("已结束该咨询");
  141. } else {
  142. mui.toast(res.msg)
  143. }
  144. });
  145. }
  146. })
  147. }
  148. function viewZixun(){
  149. openWebview("../../message/html/p2dzixun.html",{
  150. // groupName: name,
  151. sessionName: consultData.patient_name,
  152. sessionId: consultData.zxGroupCode
  153. });
  154. mui.later(function(){
  155. self.close();
  156. }, 1000)
  157. }
  158. function backToMyzx(){
  159. var old_back = mui.back;
  160. mui.back = function() {
  161. if(isJieshuCaozuo){
  162. var wv = plus.webview.getWebviewById("mingyizixunliebiao");
  163. if(wv){
  164. wv.reload(true);
  165. }
  166. }
  167. old_back();
  168. }
  169. }
  170. /**
  171. * 点击查看好友详细信息
  172. */
  173. $('#qun_detail').on("tap", function(){
  174. if(isPatient){
  175. mui.openWindow('../../huanzhe/html/huanzhexinxi.html', 'huanzhexinxi.html', {
  176. extras: {
  177. patiCode: otherCode
  178. }
  179. });
  180. } else {
  181. mui.openWindow('../../mine/html/zuyuanziliao.html', 'zuyuanziliao1', {
  182. extras: {
  183. docCode: otherCode
  184. }
  185. });
  186. }
  187. })