锦水居民端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
3.3 KiB

5 years ago
import { getTimestamp } from '../../../../utils/common'
const api = require('../../../../utils/api')
const app = getApp()
Page({
data: {
selectedTab: 'tab0',
loadMoreVisible: false,
loadMoreType: 'none',
pageNo: 1,
pageSize: 10,
signedList: [],
preloadVisible: true,
timer: '',
timestamp: getTimestamp()
},
onLoad () {
this.setData({
timestamp: getTimestamp(),
})
this.getSignedList()
},
onShow () {
5 years ago
this.pulldownRefresh()
5 years ago
if (!app.globalData.previewImage) {
console.log('过滤previewImage引起的onShow')
}
app.globalData.previewImage = false
},
onReady () {
this.pullDownRefresh = this.selectComponent('#pulldown-refresh')
},
onPageScroll (e) {
this.pullDownRefresh.onPageScroll(e)
},
onReachBottom () {
this.setData({
loadMoreVisible: true
})
if (this.data.loadMoreType === 'loading') {
this.setData({
pageNo: this.data.pageNo + 1
})
this.getSignedList()
}
},
// 列表 下拉刷新, 初始化加载
pulldownRefresh () {
this.setData({
pageNo: 1,
pageSize: 10,
loadMoreVisible: false,
loadMoreType: 'none',
preloadVisible: true,
signedList: [],
timestamp: getTimestamp()
})
const para = {
pageIndex: this.data.pageNo,
pageSize: this.data.pageSize,
timestamp: this.data.timestamp,
actType: this.data.selectedTab.substr(3,1)
}
api.getSignedList(para).then(res => {
this.pullDownRefresh.stopRefresh()
console.log('已报名活动', res)
this.setData({
signedList: [...res.data],
loadMoreType: res.data.length === 10 ? 'loading' : 'none',
preloadVisible: false
})
}).catch(err => {
this.pullDownRefresh.stopRefresh()
this.setData({
signedList: [],
loadMoreType: 'none',
preloadVisible: false
})
console.log(err)
})
},
// 列表 上拉加载
getSignedList () {
const para = {
pageIndex: this.data.pageNo,
pageSize: this.data.pageSize,
timestamp: this.data.timestamp,
actType: this.data.selectedTab.substr(3,1)
}
api.getSignedList(para).then(res => {
console.log('已报名活动', res)
this.setData({
signedList: [...this.data.signedList,...res.data],
loadMoreType: res.data.length === 10 ? 'loading' : 'none',
preloadVisible: false
})
}).catch(err => {
this.setData({
signedList: [],
loadMoreType: 'none',
preloadVisible: false
})
console.log(err)
}).finally(() => {
this.pullDownRefresh.stopRefresh()
})
},
// tab 切换
tabBarChange (e) {
this.setData({
selectedTab: e.currentTarget.dataset.tab
})
this.pulldownRefresh()
},
// 查看详情
toDetail (e) {
if (this.data.selectedTab === 'tab4') {
wx.navigateTo({
url: `/subpages/heart/pages/refusedOrEndedDetail/refusedOrEndedDetail?id=${e.detail.detailId}`
})
} else if (e.detail.actCurrentState == 5) {
wx.navigateTo({
url: `/subpages/heart/pages/cancelDetail/cancelDetail?id=${e.detail.detailId}`
})
} else {
wx.navigateTo({
url: `/subpages/heart/pages/heartDetail/heartDetail?id=${e.detail.detailId}`
})
}
}
})