qiuzhuqunliao.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. var prevImage;
  2. var lastId = 0;
  3. var consultInfo;
  4. var groupName;
  5. mui.plusReady(function() {
  6. self = plus.webview.currentWebview();
  7. if(self.openId){
  8. mui.later(function(){
  9. closeOp(self.opener());
  10. }, 500)
  11. }
  12. setTitle(self.groupName);
  13. getMineInfo();//初始化个人信息
  14. // getMemberLs();//获取成员信息
  15. getTeamInfo();
  16. closeRefreshXiaoxi();
  17. prevImage = mui.previewImage();
  18. try {
  19. plus.push.clear();
  20. } catch(e) {
  21. }
  22. });
  23. function closeRefreshXiaoxi(){
  24. mui.back = function() {
  25. var wv = plus.webview.getWebviewById('xiaoxi.html');
  26. if(wv){
  27. mui.fire(wv, "refreshIMMsg");
  28. }
  29. self.close();
  30. }
  31. }
  32. function closeOp(wv){
  33. if(wv){
  34. if(self.openId == wv.id){
  35. wv.close();
  36. } else {
  37. closeOp(wv.opener());
  38. wv.close();
  39. }
  40. }
  41. }
  42. function getTeamInfo(){
  43. sendPost("/doctor/talkgroup/getConsultByGroupCode", {
  44. groupCode: self.groupCode
  45. }, null, function(res){
  46. if(res.status == 200){
  47. consultInfo = res.data;
  48. consultInfo.curGroup = self.groupCode;
  49. if(self.groupCode == consultInfo.group1)
  50. setTitle(consultInfo.groupName1);
  51. else
  52. setTitle(consultInfo.groupName2);
  53. if(consultInfo.group1 && consultInfo.group2==self.groupCode){
  54. $('.topmsg').hide();
  55. /*$('#wrapper1').css('top', '16px');
  56. offTop = 46;*/
  57. } else if(consultInfo.status==1){
  58. $('.topmsg').html("咨询求助已结束");
  59. $('#wrapper1').css({top: '46px', bottom: '0px'});
  60. $('#input_div').hide();
  61. } else if(consultInfo.group1==self.groupCode ||
  62. (!consultInfo.group1 && consultInfo.groupCreator2==getUserId()) ){
  63. $('.topmsg').html('首次回复24小时后,将自动结束咨询<a href="javascript:void(0)" onclick="jieshu()">立即结束</a>');
  64. $('#wrapper1').css({top: '46px', bottom: '52px'});
  65. } else if( consultInfo.groupCreator1 == getUserId() || consultInfo.groupCreator2 == getUserId() ) {
  66. $('.topmsg').html('首次回复24小时后,将自动结束咨询<a href="javascript:void(0)" onclick="jieshu()">立即结束</a>');
  67. $('#wrapper1').css({top: '46px', bottom: '52px'});
  68. } else {
  69. $('.topmsg').hide();
  70. }
  71. if(myScroll) myScroll.refresh();
  72. $('#qiuzhuico').toggle( consultInfo.group1==self.groupCode && docInfo.level==2 );
  73. getMemberLs();
  74. } else {
  75. mui.toast("获取团队信息失败!")
  76. }
  77. })
  78. }
  79. function getMemberLs(t){
  80. sendPost("/doctor/talkgroup/groupmembers", {
  81. groupCode: self.groupCode
  82. }, null, function(res){
  83. if(res.status == 200){
  84. $.each(res.data, function(i, v) {
  85. v.name = v.memberName;
  86. if(v.memberCode == consultInfo.patient)
  87. v.type="patient";
  88. members[v.memberCode] = v;
  89. });
  90. if(!t)
  91. getNewMsgList(true); //读取对话消息,
  92. } else {
  93. mui.toast("获取成员列表失败");
  94. }
  95. })
  96. }
  97. /**
  98. * 获取聊天图片列表
  99. */
  100. function getImgMsgList(handle){
  101. im.getGroupMsg(getUserId(), self.groupCode, lastId, pageSize, function(data) {
  102. chatCache.imgs = data.records.reverse();
  103. appendPrevImgs(chatCache.imgs);
  104. if(handle) handle(data);
  105. }, 2);
  106. }
  107. /**
  108. * 获取未读消息
  109. */
  110. function getNewMsgList(isInit){
  111. if(isInit && self.msgId){
  112. //带msgId定位参数的,
  113. locationLog(self.msgId);
  114. } else if(chatCache.firstMsgId){
  115. im.getGroupMsg(getUserId(), self.groupCode, 10000000000, pageSize, function(data) {
  116. getNewMsgHandle(data, isInit);
  117. }, undefined, chatCache.firstMsgId);
  118. } else{
  119. im.getGroupMsg(getUserId(), self.groupCode, 0, pageSize, function(data) {
  120. getNewMsgHandle(data, isInit);
  121. });
  122. }
  123. }
  124. /**
  125. * 获取消息
  126. */
  127. function getMsgList(pageIndex, isClear, isPre) {
  128. var list = getChacheMsg();
  129. if(list.length<pageSize){
  130. im.getGroupMsg(getUserId(), self.groupCode, lastId, pageSize, function(data) {
  131. if(data.count>0){
  132. if(!chatCache.firstMsgId || data.startId > chatCache.firstMsgId)
  133. chatCache.firstMsgId = data.startId;
  134. addMsgToCache(data);
  135. list = getChacheMsg();
  136. }
  137. showMsg({count: list.length, records: list}, isClear, isPre);
  138. });
  139. } else {
  140. showMsg({count: pageSize, records: list}, isClear, isPre);
  141. }
  142. }
  143. /**
  144. * 发送消息
  145. */
  146. function uploadMsg(type, content) {
  147. service.isConsultFinished(consultInfo.consult, function(res){
  148. if(res.data==0){
  149. im.sendGroupMsg(getUserId(), self.groupCode, content, type, function(data) {
  150. getNewMsgList();
  151. }, 2)
  152. } else {
  153. $('.topmsg').html("咨询求助已结束");
  154. $('#wrapper1').css({top: '46px', bottom: '0px'});
  155. $('#input_div').hide();
  156. myScroll.refresh();
  157. }
  158. })
  159. }
  160. function setTitle(teamName){
  161. groupName = teamName;
  162. document.querySelector("h1").innerText = teamName || "";
  163. }
  164. /**
  165. * 求助
  166. */
  167. function qiuzhu() {
  168. gotSelectDoc();
  169. }
  170. function gotSelectDoc(m){
  171. mui.openWindow('../../qzys/html/select_doctor.html', 'qzys-select_doctor', {
  172. extras: {
  173. consultInfo: consultInfo,
  174. accessData: {
  175. consultCode: consultInfo.consult,
  176. patient: consultInfo.patient
  177. }
  178. }
  179. });
  180. }
  181. function jieshu(){
  182. mui.confirm("结束咨询后,居民及所有医生均无法再次回复,是否确认继续结束?", "", ["继续结束", "我再看看"], function(e) {
  183. if(e.index == 0) {
  184. sendPost("doctor/consult/finish", {
  185. consult: consultInfo.consult
  186. }, null, function(res) {
  187. if(res.status == 200){
  188. $('.topmsg').html("咨询求助已结束");
  189. $('#input_div').hide();
  190. mui.toast("已结束该咨询");
  191. } else {
  192. mui.toast(res.msg)
  193. }
  194. });
  195. }
  196. })
  197. }
  198. $('#contain').on('tap', '.qiuzhu5', function(){
  199. var code = $(this).attr('data-code');
  200. mui.openWindow('../../message/html/qiuzhuqunliao.html', 'qiuzhuqunliao2', {
  201. extras: {
  202. groupCode: code
  203. }
  204. });
  205. })
  206. document.getElementById("qun_detail").addEventListener('tap', function() {
  207. var m = [];
  208. for(var k in members){
  209. members[k].code = members[k].memberCode;
  210. m.push(members[k]);
  211. }
  212. mui.openWindow({
  213. url: "../../tuandui/html/tuanduishezhi.html",
  214. id: "tuanduishezhi.html",
  215. extras: {
  216. teamName: groupName,
  217. members: m,
  218. type: 2
  219. }
  220. })
  221. });
  222. window.addEventListener('updateTeamName', function(e) {
  223. setTitle(e.detail.teamName)
  224. });
  225. window.addEventListener('getMember', function(e) {
  226. getMemberLs(1);
  227. });