patients-record.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. var baseInfo = null,// 基础环境信息(包括当前webview)
  2. teamCode,// 从缓存取出所选团队
  3. self,
  4. keyword, // 搜索关键字
  5. type = 0, //类型
  6. startDate = getDateBefore(6),
  7. endDate = getNowDate();
  8. var page1 = 1,
  9. page2 = 1,
  10. pagesize = 10,
  11. $search = $('#search'), // 搜索框
  12. scrollers = [],
  13. loaded = [false, false];
  14. // 选择血糖血压容器
  15. function selTypeDiv() {
  16. if(type == 0) {
  17. $("#viewTabs").find("li").eq(0).addClass("curr")
  18. $(".selectDate li").first().addClass("curr");
  19. $("#xuetangView").show();
  20. $("#xueyaView").hide();
  21. } else {
  22. $("#viewTabs").find("li").eq(1).addClass("curr")
  23. $(".selectDate").find("li").eq(4).addClass("curr");
  24. $("#xuetangView").hide();
  25. $("#xueyaView").show();
  26. }
  27. }
  28. // 获取登录相关信息
  29. function getBaseInfo() {
  30. self = plus.webview.currentWebview();
  31. teamCode = self.teamCode;
  32. type = self.type;
  33. selTypeDiv();
  34. }
  35. function initPatientListByTeam(isInit) {
  36. if(isInit){
  37. if(type == 0){
  38. page1 = 1;
  39. }else{
  40. page2 = 1;
  41. }
  42. }
  43. var url = "/doctor/scheme/getTrackPatientIndexCountList";
  44. plus.nativeUI.showWaiting();
  45. sendGet(url, {
  46. type: type == 0 ? 1 : 2,
  47. teamCode: teamCode,
  48. startDate: startDate,
  49. endDate: endDate,
  50. keyword: keyword ? keyword : "",
  51. page: type == 0 ? page1 : page2,
  52. size: pagesize
  53. }, null, function(res) {
  54. plus.nativeUI.closeWaiting();
  55. $(".pullUp").hide();
  56. $(".pullDown").hide();
  57. if(res.status == 200) {
  58. if(res.data.length > 0) {
  59. loaded[type] == true;
  60. $("#XTlist").show();
  61. $("#XYlist").show();
  62. $(".no-result").hide();
  63. var html = template('listDataToHtml', {data: res.data})
  64. if(isInit) {
  65. if(type == 0){
  66. $("#XTlist").html(html);
  67. }else{
  68. $("#XYlist").html(html);
  69. }
  70. // scrollers[type].scrollTo(0,0,100);
  71. } else {
  72. if(type == 0){
  73. $("#XTlist").append(html);
  74. }else{
  75. $("#XYlist").append(html);
  76. }
  77. }
  78. if(res.data.length < pagesize){
  79. scrollers[type].endPullupToRefresh(true);
  80. }else{
  81. if(type == 0){
  82. page1 ++;
  83. }else{
  84. page2 ++;
  85. }
  86. scrollers[type].enablePullupToRefresh();
  87. }
  88. } else {
  89. if(isInit) {
  90. if(type == 0){
  91. $("#XTlist").hide();
  92. $("#xuetangView .no-result").show();
  93. }else{
  94. $("#XYlist").hide();
  95. $("#xueyaView .no-result").show();
  96. }
  97. } else {
  98. mui.toast("暂无更多数据!");
  99. }
  100. }
  101. } else {
  102. mui.toast(res.msg);
  103. }
  104. }, true)
  105. }
  106. // 绑定页面事件
  107. function bindEvents() {
  108. // 头像路径
  109. template.helper("getPatientImg", function(str){
  110. if(str){
  111. if(str.indexOf("../") > -1){
  112. return str; //原福州代码中返回的相对路径
  113. }
  114. var url = getImgUrl(str);
  115. return url;
  116. }
  117. return "";
  118. });
  119. // 搜索
  120. $search.bind("input propertychange", function() {
  121. keyword = $search.val();
  122. initPatientListByTeam(true);
  123. });
  124. // 血糖血压切换
  125. $(document).on("tap", "#viewTabs li", function() {
  126. $(this).addClass("curr").siblings().removeClass("curr");
  127. $(".selectDate").children().removeClass("curr");
  128. type = $(this).index();
  129. selTypeDiv();
  130. if(!loaded[type]){
  131. startDate = getDateBefore(6);
  132. initPatientListByTeam(true);
  133. }
  134. });
  135. // 天数选择
  136. $(document).on("tap", ".selectDate li", function() {
  137. var days = $(this).attr("data-days");
  138. startDate = getDateBefore(days);
  139. $(this).addClass("curr").siblings().removeClass("curr");
  140. page = 1;
  141. initPatientListByTeam(true);
  142. });
  143. // 血糖时间段切换
  144. // $(document).on("tap", "#duringList li", function() {
  145. // $(this).addClass("curr").siblings().removeClass("curr");
  146. // })
  147. // 跳转个人血糖记录页
  148. $(document).on("tap", "#XTlist li", function() {
  149. var patient = $(this).attr("data-patient");
  150. openWebview("xuetang-view.html",{
  151. code: patient,
  152. dateT: endDate
  153. });
  154. })
  155. // 跳转个人血压记录页
  156. $(document).on("tap", "#XYlist li", function() {
  157. var patient = $(this).attr("data-patient");
  158. openWebview("xueya-view.html",{
  159. code: patient,
  160. dateT: endDate
  161. });
  162. })
  163. }
  164. function initScroll(){
  165. $.each(document.querySelectorAll('.mui-scroll-wrapper'), function(index, pullRefreshEl) {
  166. var pullRefresh = mui(pullRefreshEl).pullRefresh({
  167. down:{
  168. callback: function(){
  169. var self = this;
  170. setTimeout(function(){
  171. initPatientListByTeam(true);
  172. self.endPulldownToRefresh();
  173. }, 300);
  174. }
  175. },
  176. up: {
  177. callback: function(){
  178. var self = this;
  179. setTimeout(function(){
  180. initPatientListByTeam(false);
  181. // self.endPullupToRefresh();
  182. }, 300);
  183. }
  184. }
  185. });
  186. scrollers.push(pullRefresh);
  187. })
  188. }
  189. // 页面业务处理流程开始
  190. new Promise(function(resolve, reject) {
  191. mui.plusReady(function() {
  192. resolve(true);
  193. })
  194. }).then(function() {
  195. getBaseInfo();
  196. }).then(function() {
  197. bindEvents();
  198. initScroll();
  199. initPatientListByTeam(true);
  200. }).catch(function(e) {
  201. plus.nativeUI.closeWaiting();
  202. console && console.error(e);
  203. })