manbingjumin.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. var baseInfo = null,// 基础环境信息(包括当前webview)
  2. teamCode,// 从缓存取出所选团队
  3. self,
  4. selectType,//类型
  5. teamInfo,
  6. docInfo;
  7. var $searchbar = $('.searchbar'),// 搜索框
  8. $searchbarInput = $('.searchbar .search-input'),// 搜索输入框
  9. $patiList = $('#pati_list'),// 患者分组列表
  10. $selectedTeamName = $('.demo-comtop h1');// 所选团队的团队名称显示位置
  11. // 获取登录相关信息
  12. var getBaseInfo = function() {
  13. self = plus.webview.currentWebview();
  14. docInfo = JSON.parse(plus.storage.getItem("docInfo"));
  15. teamInfo = JSON.parse(plus.storage.getItem("teamInfo"));
  16. teamCode = self.teamCode;
  17. selectType = self.selectType;
  18. },
  19. // 缓存中的团队
  20. setCurTeamName = function (){
  21. template.helper("setChecked", function(id, i) {
  22. if(teamCode && teamCode==id)
  23. return "checked";
  24. return "";
  25. });
  26. $('.lin-sel-group').html(template('teams_tmpl',teamInfo));
  27. $selectedTeamName.html(($('.lin-sel-group li.checked').attr('data-name'))+'慢病居民<label class="lin-down-arrow"></label>');
  28. },
  29. showGroupSel = function(e,isShow) {
  30. isShow = isShow || $('.lin-mask:hidden').length != 0;
  31. $('.lin-mask').toggle(isShow);
  32. $('.lin-sel-group').toggle(isShow);
  33. },
  34. // 初始化画面患者分组列表
  35. initPatientGroupsList = function(fun) {
  36. var url = "doctor/patient_label_info/label_patient_amount";
  37. plus.nativeUI.showWaiting();
  38. getReqPromise(url,{labelType: 3, teamCode: teamCode,isSlowDisease:true,diseaseCondition:selectType},'POST',true)
  39. .then(function(res) {
  40. plus.nativeUI.closeWaiting();
  41. if(res.status == 200) {
  42. var data = _.filter(res.data,function(o) {
  43. return o.labelCode != 0 || (o.labelCode==0 && o.amount > 0);
  44. })
  45. if(data && data.length>0) {
  46. var html = template("pati_group_tmpl", {list: data});
  47. $patiList.empty().append(html);
  48. //判断总数
  49. var allAmount = 0;
  50. $.map(data,function(item,i){
  51. allAmount += item.amount;
  52. })
  53. if(allAmount == 0){
  54. $('#no_result_wrap').show()
  55. }else{
  56. $('#no_result_wrap').hide()
  57. }
  58. }
  59. fun&&fun.call(this)
  60. }
  61. }).catch(function(e){
  62. plus.nativeUI.closeWaiting();
  63. console && console.error(e)
  64. })
  65. },
  66. showLoadMore = function($el) {
  67. var amount = $el.attr("data-amount"),
  68. loaded = $el.find('ul.n-list li').length,
  69. $loadMore = $el.find('.load-more');
  70. if(amount>loaded) {
  71. $loadMore.show();
  72. } else {
  73. $loadMore.hide();
  74. }
  75. },
  76. initPatientListByGroup = function(code) {
  77. var url = "doctor/patient_label_info/patients_by_label";
  78. var $group = $patiList.find('.patient-list[data-group="'+code+'"]');
  79. plus.nativeUI.showWaiting();
  80. getReqPromise(url, {labelType:3, teamCode: teamCode, labelCode: code, page: 1, pagesize: 30,isSlowDisease:true,diseaseCondition:selectType},'POST',true).then(function(res) {
  81. plus.nativeUI.closeWaiting();
  82. if(res.status == 200) {
  83. var html = template("pati_list_tmpl", {list: _.map(res.data,function(o) {
  84. o.jsonStr = JSON.stringify(o);
  85. return o;
  86. })});
  87. $group.find('ul.n-list').empty().append(html);
  88. showLoadMore($group);
  89. } else {
  90. mui.toast(res.msg);
  91. }
  92. }).catch(function(e){ console && console.error(e); plus.nativeUI.closeWaiting(); });
  93. },
  94. togglePatientListShow = function($el) {
  95. var isOpen = $el.hasClass("current"),
  96. $list = $el.find('ul.n-list'),
  97. $siblings = $el.siblings('.patient-list');
  98. if(isOpen) {
  99. $el.removeClass("current");
  100. $list.hide();
  101. $el.find('.load-more').hide();
  102. } else {
  103. $el.addClass("current");
  104. showLoadMore($el);
  105. $siblings.removeClass('current').find("ul.n-list").hide();
  106. $siblings.find('.load-more').hide();
  107. $list.show();
  108. }
  109. setTimeout(function(){
  110. mui('.mui-scroll-wrapper').scroll().scrollTo(0,0,0);
  111. },100)
  112. return isOpen;
  113. },
  114. refreshPage = function(fun){
  115. queryHeadData()
  116. initPatientGroupsList(fun);
  117. },
  118. // 绑定页面事件
  119. bindEvents = function () {
  120. $patiList.on('tap','.load-more',function() {
  121. plus.nativeUI.showWaiting();
  122. var $wrap = $(this).closest(".patient-list"),
  123. code = $wrap.attr("data-group"),
  124. page = parseInt($wrap.attr("data-page"));
  125. var url = "doctor/patient_label_info/patients_by_label";
  126. getReqPromise(url,{labelType: 3,labelCode: code, teamCode: teamCode, page: page + 1, pagesize: 30,isSlowDisease:true,diseaseCondition:selectType},'POST',true)
  127. .then(function(res) {
  128. if(res.status == 200) {
  129. var html = template("pati_list_tmpl", {list: _.map(res.data,function(o) {
  130. o.jsonStr = JSON.stringify(o);
  131. return o;
  132. })});
  133. $wrap.find('ul.n-list').append(html);
  134. $wrap.attr("data-page",page+1);
  135. showLoadMore($wrap);
  136. }
  137. plus.nativeUI.closeWaiting();
  138. }).catch(function(e){ console && console.error(e); plus.nativeUI.closeWaiting(); });
  139. return false;
  140. }).on('tap','.patient-list',function() {
  141. var code = $.trim($(this).attr("data-group")),
  142. isOpen = togglePatientListShow($(this)),
  143. isEmpty = !$(this).find('ul.n-list li').length;
  144. $patiList.find(".patient-type").css({position: "relative", top: "initial", "z-index": "initial"});
  145. code && !isOpen && isEmpty && initPatientListByGroup(code);
  146. }).on('tap','li[data-patient-code]',function(e) {
  147. var patiInfo = $(this).attr("data-json");
  148. var info = JSON.parse(patiInfo);
  149. mui.openWindow({
  150. id: "huanzhexinxi-mb",
  151. url: "../../huanzhe/html/huanzhexinxi.html",
  152. extras: {
  153. teamCode: teamCode,
  154. patiInfo: patiInfo,
  155. patiCode: info.code
  156. }
  157. })
  158. return false;
  159. })
  160. $selectedTeamName.on('tap', showGroupSel);
  161. $('.lin-sel-group').on('tap', 'li', function(){
  162. showGroupSel(undefined, false);
  163. if(!$(this).hasClass('checked')){
  164. $(this).addClass('checked').siblings().removeClass('checked');
  165. teamCode = $('.lin-sel-group li.checked').attr('data-code');
  166. refreshPage();
  167. setCurTeamName();
  168. }
  169. })
  170. $searchbarInput.on('tap',function() {
  171. mui.openWindow({
  172. id: "manbingjuminsousuo",
  173. url: "juminsousuo.html",
  174. extras: {
  175. teamCode:teamCode
  176. }
  177. })
  178. })
  179. //绿黄红标居民切换
  180. $('#peopleType li').eq(selectType).addClass('active');
  181. $('#peopleType').on('tap','li',function(){
  182. var that = $(this)
  183. if(!that.hasClass('active')){
  184. that.addClass('active').siblings().removeClass('active')
  185. selectType = that.attr('data-type')
  186. initPatientGroupsList();
  187. }
  188. })
  189. /*刷新事件*/
  190. window.addEventListener("refresh", function refresh(e) {
  191. $('.lin-mask').hide();
  192. $('.lin-sel-group').hide();
  193. refreshPage();
  194. })
  195. }
  196. function queryHeadData(){
  197. var params={
  198. teamCode:teamCode,
  199. getcolor:1,//是否获取颜色标签
  200. getstands:0,//是否获取预警人数
  201. gethealthindex:0,//获取体征数据
  202. }
  203. sendPost("doctor/patient_label_info/slowdisease/get/teaminfos",params, function(){
  204. mui.toast("请求失败");
  205. }, function(res){
  206. if(res.status == 200){
  207. $('#red').text(res.data.redcount)
  208. $('#yellow').text(res.data.yellowcount)
  209. $('#green').text(res.data.greencount)
  210. }else{
  211. mui.toast('获取数据失败')
  212. }
  213. },'get')
  214. }
  215. // 页面业务处理流程开始
  216. new Promise(function(resolve, reject) {
  217. mui.plusReady(function() {
  218. resolve(true);
  219. })
  220. }).then(function() {
  221. getBaseInfo();
  222. mui.init({
  223. pullRefresh : {
  224. container:'.mui-scroll-wrapper',
  225. down : {
  226. height:50,
  227. auto: false,
  228. contentdown : "下拉可以刷新",
  229. contentover : "释放立即刷新",
  230. contentrefresh : "正在刷新...",
  231. callback: function() {
  232. var self = this;
  233. refreshPage(function(){
  234. setTimeout(function(){
  235. self.endPulldownToRefresh(false);
  236. },500)
  237. })
  238. }
  239. }
  240. }
  241. })
  242. mui('.mui-scroll-wrapper').scroll()
  243. }).then(function() {
  244. setCurTeamName();
  245. bindEvents();
  246. queryHeadData()
  247. initPatientGroupsList()
  248. }).catch(function(e) {
  249. plus.nativeUI.closeWaiting();
  250. console && console.error(e);
  251. })