index.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // pages/luckDraw/index.js
  2. import LuckDraw from '../../api/luck-draw'
  3. import { parseTime } from '../../utils/util';
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. page: 1,
  10. pageSize: 10,
  11. lock: false,
  12. noResult: false,
  13. noMore: false,
  14. activityList: []
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function (options) {
  20. this.getActivityList();
  21. },
  22. /**
  23. * 生命周期函数--监听页面初次渲染完成
  24. */
  25. onReady: function () {
  26. },
  27. /**
  28. * 生命周期函数--监听页面显示
  29. */
  30. onShow: function () {
  31. },
  32. /**
  33. * 生命周期函数--监听页面隐藏
  34. */
  35. onHide: function () {
  36. },
  37. /**
  38. * 生命周期函数--监听页面卸载
  39. */
  40. onUnload: function () {
  41. },
  42. /**
  43. * 页面相关事件处理函数--监听用户下拉动作
  44. */
  45. onPullDownRefresh: function () {
  46. },
  47. /**
  48. * 用户点击右上角分享
  49. */
  50. onShareAppMessage: function () {
  51. },
  52. getActivityList: function() {
  53. LuckDraw.getActivityList({
  54. page: this.data.page,
  55. pageSize: this.data.pageSize
  56. }).then(res => {
  57. if (res.code == 200) {
  58. this.drawListView(res.data)
  59. }
  60. this.data.lock = false
  61. }).catch(_ => {
  62. this.data.lock = false
  63. })
  64. },
  65. drawListView: function(data) {
  66. if (!Array.isArray(data) || data.length == 0) {
  67. console.log("没有获取到数据");
  68. if (this.data.page == 1) {
  69. this.setData({
  70. noResult: true
  71. })
  72. } else {
  73. this.setData({
  74. noMore: true
  75. })
  76. }
  77. return
  78. }
  79. data.forEach(v => {
  80. let beginTime = v.beginTime
  81. let endTime = v.endTime
  82. if (v.timeType == 1 || beginTime == null) {
  83. beginTime = "2021.11.01"
  84. }
  85. if (v.timeType == 1 || endTime == null) {
  86. endTime = "2031.11.01"
  87. }
  88. v.beginTime = parseTime(beginTime, "{y}.{m}.{d}")
  89. v.endTime = parseTime(endTime, "{y}.{m}.{d}")
  90. })
  91. this.data.activityList = this.data.activityList.concat(...data)
  92. this.setData({
  93. activityList: this.data.activityList
  94. })
  95. },
  96. /**
  97. * 页面上拉触底事件的处理函数
  98. */
  99. onReachBottom: function () {
  100. if (this.data.lock || this.data.noMore) {
  101. return
  102. }
  103. this.data.lock = true
  104. this.data.page++
  105. this.getActivityList()
  106. },
  107. toDetail(e) {
  108. const url = "detail?id=" + e.currentTarget.dataset.id
  109. wx.redirectTo({
  110. url
  111. })
  112. }
  113. })