join.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. const { apiRequest } = require('../../../utils/API.js')
  2. let end_currentPage = 1
  3. let not_currentPage = 1
  4. Page({
  5. data: {
  6. current: 1,
  7. isShowLoadTip: false,
  8. pageLength: 15,
  9. end_data: [],
  10. not_end_data: [],
  11. dataList: {}
  12. },
  13. changeTab: function ({ detail }) {
  14. let that = this
  15. this.setData({
  16. current: detail.key,
  17. isShowLoadTip: false,
  18. end_data: [],
  19. not_end_data: []
  20. })
  21. end_currentPage = 1
  22. not_currentPage = 1
  23. wx.showLoading({
  24. title: '加载中',
  25. mask: true
  26. })
  27. setTimeout(function () {
  28. let pageLen = that.data.pageLength
  29. let dataAll = that.data.dataList
  30. let endData = dataAll.end.length > pageLen ? dataAll.end.slice(0, pageLen) : dataAll.end
  31. let notEndData = dataAll.not_end.length > pageLen ? dataAll.not_end.slice(0, pageLen) : dataAll.not_end
  32. that.setData({
  33. end_data: endData,
  34. not_end_data: notEndData
  35. })
  36. wx.hideLoading()
  37. }, 500)
  38. },
  39. onLoad: function (options) {
  40. this.getList()
  41. },
  42. getList: function (callback) {
  43. let that = this
  44. wx.showLoading({
  45. title: '加载中',
  46. mask: true
  47. })
  48. apiRequest('/user/lotteries').then(data => {
  49. let endData = data.data.end.length > that.data.pageLength ? data.data.end.slice(0, that.data.pageLength) : data.data.end
  50. let notEndData = data.data.not_end.length > that.data.pageLength ? data.data.not_end.slice(0, that.data.pageLength) : data.data.not_end
  51. that.setData({
  52. dataList: data.data,
  53. end_data: endData,
  54. not_end_data: notEndData
  55. })
  56. wx.hideLoading()
  57. callback && callback()
  58. })
  59. },
  60. toDetail: function (e) {
  61. wx.navigateTo({
  62. url: '/pages/award-detail/award-detail?id=' + e.currentTarget.id
  63. })
  64. },
  65. onPullDownRefresh: function () {
  66. let that = this
  67. wx.showNavigationBarLoading()
  68. this.getList(function() {
  69. wx.hideNavigationBarLoading()
  70. wx.stopPullDownRefresh()
  71. wx.showToast({
  72. title: '刷新成功',
  73. icon: 'none'
  74. })
  75. that.setData({
  76. isShowLoadTip: false
  77. })
  78. end_currentPage = 1
  79. not_currentPage = 1
  80. })
  81. },
  82. onReachBottom: function() {
  83. let that = this
  84. let pageSize = this.data.pageLength
  85. wx.showLoading({
  86. title: '加载中',
  87. mask: true
  88. })
  89. setTimeout(function () {
  90. wx.hideLoading()
  91. if (that.data.current == 1) {
  92. let not_end = that.data.dataList.not_end
  93. if (that.data.not_end_data.length != not_end.length) {
  94. not_currentPage++
  95. }
  96. let data = not_end.length > not_currentPage * pageSize ? not_end.slice(0, not_currentPage * pageSize) : not_end
  97. that.setData({
  98. not_end_data: data
  99. })
  100. if (that.data.not_end_data.length == not_end.length) {
  101. that.setData({
  102. isShowLoadTip: true
  103. })
  104. }
  105. } else if (that.data.current == 2) {
  106. let end = that.data.dataList.end
  107. if (that.data.end_data.length != end.length) {
  108. end_currentPage++
  109. }
  110. let data = end.length > end_currentPage * pageSize ? end.slice(0, end_currentPage * pageSize) : end
  111. that.setData({
  112. end_data: data
  113. })
  114. if (that.data.end_data.length == end.length) {
  115. that.setData({
  116. isShowLoadTip: true
  117. })
  118. }
  119. }
  120. }, 500)
  121. }
  122. })