activity-square.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // 基本信息(包括userAgent)
  2. var baseInfo = null,
  3. // 基础环境信息(包括当前webview)
  4. baseEnv = null;
  5. // 搜索结果
  6. var $resultList = $('.activiy-list');
  7. var self;
  8. var docInfo;
  9. var scrollered,
  10. page = 1,
  11. size = 10;
  12. // 获取登录相关信息
  13. var getBaseInfo = function() {
  14. // 登录的相关信息
  15. var userAgent = JSON.parse(plus.storage.getItem("userAgent"))
  16. return {
  17. userAgent: userAgent,
  18. teamInfo: JSON.parse(plus.storage.getItem("teamInfo"))
  19. }
  20. },
  21. // 获取基础环境信息
  22. getBaseEnvPromise = function () {
  23. self = plus.webview.currentWebview();
  24. docInfo = JSON.parse(plus.storage.getItem("docInfo"));
  25. var env = {
  26. webview: plus&&plus.webview.currentWebview()
  27. };
  28. return Promise.resolve().then(function(res) {
  29. return env;
  30. });
  31. },
  32. //下拉刷新上拉加载
  33. updatePullUpText = function(scroller, list) {
  34. var $wrap = $(scroller.wrapper),
  35. $pullupLabel = $wrap.find('.pullUpLabel');
  36. $(".pullUp").removeClass("loading");
  37. if(!list) {
  38. $pullupLabel.text('没有更多');
  39. } else if(list.length < 10) {
  40. $(".pullUp").hide();
  41. } else {
  42. $pullupLabel.text('上拉加载更多');
  43. }
  44. scroller.on('refresh', function() {
  45. if(!list) {
  46. $pullupLabel.text('没有更多');
  47. } else if(list.length < 10) {
  48. $(".pullUp").hide();
  49. } else {
  50. $pullupLabel.text('上拉加载更多');
  51. }
  52. });
  53. },
  54. // 初始化活动列表
  55. activityList = function(boolean) {
  56. plus.nativeUI.showWaiting();
  57. var params = {
  58. task:"{}",
  59. page: page,
  60. size: size
  61. }
  62. sendPost("/doctor/healthBank/selectTask", params, queryFails, function(res) {
  63. if(res.status == 200) {
  64. plus.nativeUI.closeWaiting();
  65. var list = _.map(res.data.detailModelList, function(o) {
  66. if(o.img){
  67. o.img = getImgUrl(o.img)
  68. }else{
  69. o.img = "../images/morenhuodong_banner01_img.png";
  70. }
  71. return o;
  72. })
  73. if(list.length < 10) {
  74. $(".lastmsg").show()
  75. }
  76. updatePullUpText(scrollered, list);
  77. var html = template("result_tmpl", {list: list});
  78. if(boolean) {
  79. $resultList.empty().append(html);
  80. if(list.length == 0) {
  81. $("#no_result_wrap").show();
  82. } else {
  83. $("#no_result_wrap").hide();
  84. }
  85. } else {
  86. $resultList.append(html);
  87. }
  88. $('#wrapper').show();
  89. scrollered.refresh();
  90. } else {
  91. plus.nativeUI.closeWaiting();
  92. queryFails(res);
  93. }
  94. }, 'post')
  95. },
  96. //查询失败回调
  97. queryFails = function(res) {
  98. if(res) {
  99. mui.toast(res.msg)
  100. } else {
  101. mui.toast("加载失败!")
  102. }
  103. },
  104. // 绑定页面事件
  105. bindEvents = function () {
  106. //初始化下拉刷新 上拉加载
  107. scrollered = $("#wrapper").initScroll({
  108. pullDownAction: function() {
  109. page = 1
  110. activityList(true)
  111. },
  112. pullUpAction: function() {
  113. page++
  114. activityList(false)
  115. }
  116. });
  117. $resultList.on("tap", "li", function() {
  118. activityId = $(this).attr("data-code")
  119. openWebview("activity-detail.html", {
  120. activityId: activityId
  121. });
  122. });
  123. };
  124. // 页面业务处理流程开始
  125. mui.plusReady(function() {
  126. //获取当前页面
  127. var self = plus.webview.currentWebview();
  128. getBaseEnvPromise();
  129. //绑定事件
  130. bindEvents();
  131. //数据渲染
  132. activityList(true);
  133. })