index.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. const {getLotteries} = require('../../utils/API.js')
  2. let cur_page = 1
  3. Page({
  4. data: {
  5. has_more: true,
  6. loading: false,
  7. lotteries: [], // 抽奖列表
  8. recommend: {} // 推荐的抽奖
  9. },
  10. loadMore(){
  11. if(this.data.has_more) {
  12. cur_page++
  13. this.setData({loading: true})
  14. getLotteries(cur_page)
  15. .then(data => {
  16. data.data.rows.length === 0 && this.setData({has_more: false})
  17. this.setData({
  18. lotteries: this.data.lotteries.concat(data.data.rows),
  19. loading: false
  20. })
  21. })
  22. }
  23. },
  24. onLoad: function () {
  25. wx.showLoading({title: '加载中', mask: true})
  26. getLotteries(cur_page).then(data => {
  27. this.setData({
  28. lotteries: data.data.rows,
  29. recommend: data.data.recommend_lottery
  30. })
  31. wx.hideLoading()
  32. })
  33. },
  34. onPullDownRefresh(){
  35. cur_page = 1
  36. getLotteries(cur_page).then(data => {
  37. this.setData({
  38. lotteries: data.data.rows,
  39. recommend: data.data.recommend_lottery
  40. })
  41. wx.stopPullDownRefresh()
  42. })
  43. },
  44. onReachBottom(){
  45. this.loadMore()
  46. },
  47. onShareAppMessage() {
  48. return {
  49. path: '/pages/index/index'
  50. }
  51. }
  52. })