xiaoxi.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. var first = true, docInfo, teamInfo,thisTeamsId , leader;
  2. var $xfxx=$("[data-code='xfxx']");//续方
  3. //var $xtfw=$("[data-code='xtfw']");//协同
  4. var type;
  5. mui.plusReady(function() {
  6. docInfo = JSON.parse(plus.storage.getItem("docInfo"));
  7. docinfo(docInfo);
  8. initScroll();
  9. juageLeader();
  10. page.init();
  11. teams = JSON.parse(plus.storage.getItem("teamInfo"));
  12. //控制协同
  13. // if(docInfo.hospital){
  14. // if(docInfo.hospital.substr(0,6) == '350211' && docInfo.level == 1){
  15. // $xtfw.show()
  16. // }else{
  17. // $xtfw.hide()
  18. // }
  19. // }else{
  20. // $xtfw.hide()
  21. // }
  22. })
  23. var page={
  24. $consultTeam:$("#consultTeam"),//咨询数
  25. $sign:$("#sign "), //签约
  26. $healthIndex:$("#healthIndex"),//健康指标
  27. $renewIdex:$("#renewIdex"),
  28. $xietong:$("#xietongNum"),
  29. init:function(){
  30. this.initData();
  31. // this.updateBadgeNumber();
  32. },
  33. //数据初始化
  34. initData:function(){
  35. var m=this;
  36. m.selectListSize();
  37. sendPost("doctor/baseinfo", null, function(res){
  38. mui.toast(res.msg);
  39. }, function(res){
  40. if(res.status==200){
  41. var data = res.data;
  42. if(data.isFamous!=1){
  43. $(".myzx").hide();
  44. }
  45. }
  46. }, null, null, true);
  47. },
  48. //查询未读消息数
  49. selectListSize:function(refresh){
  50. var m=this;
  51. sendPost("/doctor/message/messages",{}, function(){
  52. if(refresh)
  53. // myScroll.endPullDownToRefresh();
  54. mui.toast("数据加载失败,请检查网络无误后下拉刷新。");
  55. }, function(res){
  56. if(res.status=="200"){
  57. var lastMessage, p= {msg: "", msgTime: ""};
  58. if(res.data.consult && res.data.consult.amount>0){
  59. lastMessage = res.data.consult.lastMessage || p;
  60. m.$consultTeam.html(assesCount(res.data.consult.amount)).removeClass('c-hide')
  61. .prev().html(lastMessage.msgTime).removeClass('c-hide');
  62. $('#jkzx_lastMsg').html(lastMessage.msg).removeClass('c-hide');
  63. } else {
  64. m.$consultTeam.addClass('c-hide').prev().addClass('c-hide');
  65. $('#jkzx_lastMsg').addClass('c-hide');
  66. }
  67. if(res.data.concern && res.data.concern.amount>0){
  68. lastMessage = res.data.concern.lastMessage || p;
  69. var time = formatShowTime(lastMessage.msgTime);
  70. m.$sign.html(assesCount(res.data.concern.amount)).removeClass('c-hide')
  71. .prev().html(time).removeClass('c-hide');
  72. $('#sign_lastMsg').html(lastMessage.msg).removeClass('c-hide');
  73. } else {
  74. m.$sign.addClass('c-hide').prev().addClass('c-hide');
  75. $('#sign_lastMsg').addClass('c-hide');
  76. }
  77. // if(res.data.healthIndex && res.data.healthIndex.amount>0){
  78. // lastMessage = res.data.healthIndex.lastMessage || p;
  79. // var time = formatShowTime(lastMessage.msgTime);
  80. // m.$healthIndex.html(assesCount(res.data.healthIndex.amount)).removeClass('c-hide')
  81. // .prev().html(time).removeClass('c-hide');
  82. // $('#jktz_lastMsg').html(lastMessage.msg).removeClass('c-hide');
  83. // } else {
  84. // m.$healthIndex.addClass('c-hide').prev().addClass('c-hide');
  85. // $('#jktz_lastMsg').addClass('c-hide');
  86. // }
  87. //处理系统消息
  88. if(res.data.system && res.data.system.amount > 0){
  89. // $('.xitong p.msg-p').html(res.data.system.lastMessage.msg);
  90. var time = formatShowTime(res.data.system.lastMessage.msgTime);
  91. $('#xitong_date').html(time).removeClass("c-hide");
  92. if(res.data.system.amount >0){
  93. $('#xitong_index').html(res.data.system.amount).removeClass("c-hide");
  94. } else {
  95. $('#xitong_index').addClass("c-hide");
  96. }
  97. $('.xitong').show();
  98. } else {
  99. $('#xitong_index').addClass('c-hide').prev().addClass('c-hide');
  100. $('#xitong_lastcontent').addClass('c-hide');
  101. }
  102. //处理 续方消息
  103. // if (res.data.prescription && res.data.prescription.amount>0) {
  104. // $(".xfxx").attr('data-type', res.data.prescription.lastMessage.type);
  105. // lastMessage = res.data.prescription.lastMessage || p;
  106. // var time = formatShowTime(lastMessage.msgTime);
  107. // m.$renewIdex.html(assesCount(res.data.prescription.amount)).removeClass('c-hide')
  108. // .prev().html(time).removeClass('c-hide');
  109. // $('#xfxx_lastMsg').html(lastMessage.title).removeClass('c-hide');
  110. // }else{
  111. // m.$renewIdex.addClass('c-hide').prev().addClass('c-hide');
  112. // $('#xfxx_lastMsg').addClass('c-hide');
  113. // }
  114. //处理 协同消息
  115. // if (res.data.callService && res.data.callService.amount>0) {
  116. // lastMessage = res.data.callService.lastMessage || p;
  117. // var time = formatShowTime(lastMessage.msgTime);
  118. // m.$xietong.html(assesCount(res.data.callService.amount)).removeClass('c-hide')
  119. // .prev().html(time).removeClass('c-hide');
  120. // $('#xt-last').html(lastMessage.msg).removeClass('c-hide');
  121. // }else{
  122. // m.$xietong.addClass('c-hide').prev().addClass('c-hide');
  123. // $('#xt-last').addClass('c-hide');
  124. // }
  125. // if(res.data.famousConsult && res.data.famousConsult.amount>0){
  126. // lastMessage = res.data.famousConsult.lastMessage || p;
  127. // $('#myzx_index').html(assesCount(res.data.famousConsult.amount)).removeClass('c-hide')
  128. // .prev().html(lastMessage.msgTime).removeClass('c-hide');
  129. // $('#myzx_lastMsg').html(lastMessage.msg).removeClass('c-hide');
  130. // } else {
  131. // $('#myzx_index').addClass('c-hide').prev().addClass('c-hide');
  132. // $('#myzx_lastMsg').addClass('c-hide');
  133. // }
  134. //根据消息数显示红点
  135. var imMsgCount = JSON.parse(res.data.imMsgCount);
  136. var xiaoxiHtml = plus.webview.getWebviewById("xiaoxi.html");
  137. var mainHtml = plus.webview.getWebviewById("main");
  138. if(imMsgCount.patient>0 || imMsgCount.doctor>0||imMsgCount.patientEnd>0) {
  139. mui.fire(xiaoxiHtml, 'imMsgCount', imMsgCount);
  140. }
  141. if(res.data.concern.amount>0 || res.data.system.amount>0 || imMsgCount.patient>0 || imMsgCount.doctor>0 ){
  142. mui.fire(mainHtml, "showPoint");
  143. }else if(imMsgCount.patientEnd>0 &&imMsgCount.patient==0 &&imMsgCount.doctor==0){
  144. mui.fire(mainHtml, "showBluePoint");
  145. }else{
  146. mui.fire(mainHtml, "hidePoint");
  147. }
  148. if(xiaoxiHtml && (res.data.concern.amount>0 || res.data.system.amount>0)) {
  149. mui.fire(xiaoxiHtml, "xiaoxiweidu",{status:"1"});
  150. }else{
  151. mui.fire(xiaoxiHtml, "xiaoxiweidu",{status:"0"});
  152. }
  153. }
  154. // if(refresh)
  155. // myScroll.endPullDownToRefresh();
  156. }, null, null, true)
  157. },
  158. //刷新应用角标数字
  159. updateBadgeNumber:function(){
  160. var userId = plus.storage.getItem('im_userid');
  161. imClient.Application.getBadgeNo(userId, function(result) {
  162. try {
  163. if (result && result.badge != null) {
  164. plus.runtime.setBadgeNumber(result.badge);
  165. }
  166. } catch (e) {
  167. }
  168. })
  169. }
  170. }
  171. function assesCount(count){
  172. if(count>99)
  173. return "99+";
  174. return count;
  175. }
  176. var myScroll;
  177. /**
  178. * 初始化iscroll
  179. */
  180. function initScroll () {
  181. //阻尼系数
  182. var deceleration = mui.os.ios?0.003:0.0009;
  183. mui('.mui-scroll-wrapper').scroll({
  184. bounce: false,
  185. indicators: true, //是否显示滚动条
  186. deceleration:deceleration
  187. });
  188. myScroll = mui(".mui-scroll").pullToRefresh({
  189. down: {
  190. callback: function() {
  191. var self = this;
  192. page.selectListSize(true);
  193. setTimeout(function(){
  194. self.endPullDownToRefresh();
  195. },1000)
  196. }
  197. }
  198. });
  199. }
  200. /**
  201. * 列表点击事件
  202. */
  203. var initListEvent = function(){
  204. $('#systemMsg').on('tap', 'li', function(e){
  205. var html = $(this).attr("data-html"),
  206. type = $(this).attr("data-type");
  207. if(html){
  208. openWebview(html,{type:type});
  209. }
  210. })
  211. }();
  212. function asessTime(timestamp, noSeconds){
  213. var today = new Date().format('yyyy-MM-dd');
  214. var date = new Date();
  215. date.setTime(timestamp);
  216. var dateStr = date.format('yyyy-MM-dd');
  217. if(!(today.substring(0,4) == dateStr.substring(0,4))){
  218. return dateStr;
  219. }
  220. if(today == dateStr){
  221. if(noSeconds){
  222. return date.format('hh:mm');
  223. }else
  224. return date.format('hh:mm:ss');
  225. }
  226. return date.format('MM-dd');
  227. }
  228. //显示时间
  229. function formatShowTime(time){
  230. var time = time.replace(/-/g,"/"),
  231. timestamp = new Date(time).getTime();
  232. return asessTime(timestamp, 1);
  233. }
  234. window.addEventListener("refresh", function(){
  235. page.selectListSize(false);
  236. });
  237. // 判断是否为团队长
  238. function juageLeader(){
  239. var leaderUrl = '/statistics/checkDoctorIsTeamLeder';
  240. var params = {};
  241. sendGet(leaderUrl,params,null,function(res){
  242. if (res.status == 200) {
  243. if ( res.data && res.data != null) {
  244. $xfxx.show();
  245. }if(leader==3 && res.data ==null ){
  246. $xfxx.show();
  247. }
  248. }
  249. })
  250. }
  251. function docinfo(data){
  252. return leader= data.level;
  253. }