template_list.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. var page = 1,
  2. pagesize = 15,
  3. hasMore = true;
  4. mui.init();
  5. mui.plusReady(function(){
  6. getTemplateLabel();
  7. getTemplateList(true);
  8. initScroll();
  9. bindEvents();
  10. });
  11. function initScroll(){
  12. //阻尼系数
  13. var deceleration = mui.os.ios?0.003:0.0009;
  14. mui('.mui-scroll-wrapper').scroll({
  15. bounce: false,
  16. indicators: true, //是否显示滚动条
  17. deceleration:deceleration
  18. });
  19. mui('.mui-scroll-wrapper').pullRefresh({
  20. down: {
  21. callback: function() {
  22. setTimeout(function() {
  23. getTemplateList(true);
  24. mui('.mui-scroll-wrapper').pullRefresh().endPulldownToRefresh();
  25. }, 1000);
  26. }
  27. },
  28. up:{
  29. contentrefresh: '正在加载...',
  30. callback: function(){
  31. var self = this;
  32. setTimeout(function() {
  33. getTemplateList(false);
  34. mui('.mui-scroll-wrapper').pullRefresh().endPullupToRefresh(!hasMore);
  35. }, 1000);
  36. }
  37. }
  38. });
  39. }
  40. function getTemplateLabel(){
  41. plus.nativeUI.showWaiting();
  42. var url = "/doctor/questionnaire/getTemplateLabel";
  43. sendGet(url, {}, null, function(res){
  44. if(res.status == 200){
  45. if(res.data.length == 0){
  46. $(".header-link").hide();
  47. }else{
  48. var html = template("label_tmp", {list: res.data});
  49. $("#group_label_list").append(html);
  50. }
  51. }else{
  52. $(".header-link").hide();
  53. }
  54. plus.nativeUI.closeWaiting();
  55. }, true);
  56. }
  57. function getTemplateList(isInit, label){
  58. page = isInit ? 1: page;
  59. var url = "/doctor/questionnaire/getTemplateByLabel",
  60. labels = label ? label.join(",") : "",
  61. params = {labels: labels, pageNo: page, pageSize: pagesize};
  62. plus.nativeUI.showWaiting();
  63. sendGet(url, params, null, function(res){
  64. if(res.status == 200){
  65. page ++;
  66. if(isInit && res.data.length == 0){
  67. $("#no_result_wrap").show();
  68. $("#search_bar").hide();
  69. $(".mui-scroll-wrapper").hide();
  70. // $("#newTemplate").hide();
  71. $(".header-link").hide();
  72. }else{
  73. $("#no_result_wrap").hide();
  74. $("#search_bar").show();
  75. $(".mui-scroll-wrapper").show();
  76. $("#newTemplate").show();
  77. if(res.data.length < pagesize){
  78. hasMore = false;
  79. isInit && mui(".mui-scroll-wrapper").pullRefresh().endPullupToRefresh(!hasMore);
  80. }else{
  81. hasMore = true;
  82. }
  83. var list = _.map(res.data, function(o){
  84. o.jsonStr = JSON.stringify(o);
  85. return o;
  86. });
  87. var html = template("list_tmp", {list: list});
  88. if(isInit){
  89. $(".mui-scroll").empty().append(html);
  90. }else{
  91. $(".mui-scroll").append(html);
  92. }
  93. }
  94. }else{
  95. mui.toast(res.msg);
  96. }
  97. plus.nativeUI.closeWaiting();
  98. }, true);
  99. }
  100. function bindEvents(){
  101. $(".header-link").on('tap', function(){
  102. showGroupSel();
  103. });
  104. $(".sel-group").on("click",'.icon-checkbox', function(){
  105. //发送请求
  106. var $labels = $(".icon-checkbox:checked"),
  107. len = $labels.length,
  108. ids = [];
  109. for(i=0; i<len; i++){
  110. var item = $labels[i];
  111. ids.push(item.value);
  112. }
  113. getTemplateList(true, ids);
  114. });
  115. $("body").on("tap", '.tmpl', function(){
  116. var jsonStr = $(this).attr("data-json"),
  117. template_id = $(this).attr("data-code");
  118. openWebview("template_info.html", {
  119. template_id: template_id,
  120. info: JSON.parse(jsonStr)
  121. });
  122. });
  123. $("#newTemplate").on('tap', function(){
  124. openWebview("new_summary.html");
  125. });
  126. $(".search-bar").on('tap', function(){
  127. openWebview("search_template.html");
  128. });
  129. $(".lin-mask").on('tap', function(){
  130. showGroupSel();
  131. });
  132. window.addEventListener("refresh", function(e){
  133. getTemplateList(true);
  134. });
  135. }
  136. function showGroupSel(){
  137. var isShow = isShow || $('.sel-group:hidden').length != 0;
  138. $('.lin-mask').fadeToggle(isShow);
  139. $('.sel-group').fadeToggle(isShow);
  140. }