prize.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. const { apiRequest } = require('../../../utils/API.js')
  2. let currentPage = 1
  3. Page({
  4. data: {
  5. isShowLoadTip: false,
  6. pageLength: 15,
  7. prizeList: [],
  8. dataList: []
  9. },
  10. onLoad: function (options) {
  11. this.getList()
  12. },
  13. toDetail: function (e) {
  14. wx.navigateTo({
  15. url: '/pages/award-detail/award-detail?id=' + e.currentTarget.id
  16. })
  17. },
  18. getList: function (callback) {
  19. let that = this
  20. wx.showLoading({
  21. title: '加载中',
  22. mask: true
  23. })
  24. apiRequest('/user/lotteries/win').then(data => {
  25. that.setData({
  26. prizeList: data.data.length > that.data.pageLength ? data.data.slice(0, that.data.pageLength) : data.data,
  27. dataList: data.data
  28. })
  29. wx.hideLoading()
  30. callback && callback()
  31. })
  32. },
  33. onPullDownRefresh: function () {
  34. let that = this
  35. wx.showNavigationBarLoading()
  36. this.getList(function () {
  37. wx.hideNavigationBarLoading()
  38. wx.stopPullDownRefresh()
  39. wx.showToast({
  40. title: '刷新成功',
  41. icon: 'none'
  42. })
  43. that.setData({
  44. isShowLoadTip: false
  45. })
  46. currentPage = 1
  47. })
  48. },
  49. onReachBottom: function () {
  50. let that = this
  51. wx.showLoading({
  52. title: '加载中',
  53. mask: true
  54. })
  55. setTimeout(function () {
  56. wx.hideLoading()
  57. if (that.data.dataList.length != that.data.prizeList.length) {
  58. currentPage++
  59. }
  60. let currentLength = that.data.pageLength * currentPage
  61. let data = that.data.dataList.length > currentLength ? that.data.dataList.slice(0, currentLength) : that.data.dataList
  62. that.setData({
  63. prizeList: data
  64. })
  65. if (that.data.dataList.length == that.data.prizeList.length) {
  66. that.setData({
  67. isShowLoadTip: true
  68. })
  69. }
  70. }, 500)
  71. }
  72. })