// pages/luckDraw/index.js import LuckDraw from '../../api/luck-draw' import { parseTime } from '../../utils/util'; Page({ /** * 页面的初始数据 */ data: { page: 1, pageSize: 10, lock: false, noResult: false, noMore: false, activityList: [] }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.getActivityList(); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, getActivityList: function() { LuckDraw.getActivityList({ page: this.data.page, pageSize: this.data.pageSize }).then(res => { if (res.code == 200) { this.drawListView(res.data) } this.data.lock = false }).catch(_ => { this.data.lock = false }) }, drawListView: function(data) { if (!Array.isArray(data) || data.length == 0) { console.log("没有获取到数据"); if (this.data.page == 1) { this.setData({ noResult: true }) } else { this.setData({ noMore: true }) } return } data.forEach(v => { let beginTime = v.beginTime let endTime = v.endTime if (v.timeType == 1 || beginTime == null) { beginTime = "2021.11.01" } if (v.timeType == 1 || endTime == null) { endTime = "2031.11.01" } v.beginTime = parseTime(beginTime, "{y}.{m}.{d}") v.endTime = parseTime(endTime, "{y}.{m}.{d}") }) this.data.activityList = this.data.activityList.concat(...data) this.setData({ activityList: this.data.activityList }) }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { if (this.data.lock || this.data.noMore) { return } this.data.lock = true this.data.page++ this.getActivityList() }, toDetail(e) { const url = "detail?id=" + e.currentTarget.dataset.id wx.redirectTo({ url }) } })