锦水居民端小程序
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.
 

278 lines
6.2 KiB

import { getTimestamp } from '../../../../utils/common'
const api = require('../../../../utils/api')
var api_banner = require('../../../../utils/activity.js')
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
selectTab: 'tab1',
selectedTab_B: 'tab0',
typeList: [{ //排名方式:0-周,1-月
type: 'tab0',
name: '审核中',
select: true
},
{
type: 'tab1',
name: '已通过',
select: false
},
{
type: 'tab4',
name: '未通过',
select: false
}, {
type: 'tab5',
name: '已结束',
select: false
}
],
// 积分排行榜相关
datalenght: null,
loveRankingList: [],
preloadVisible: true,
// 列表相关
loadMoreVisible: false,
loadMoreType: 'none',
pageNo: 1,
pageSize: 10,
signedList: [],
timer: '',
timestamp: getTimestamp(),
jilu: true,
banner:[]
},
// tab 切换
onTabChange(e) {
this.setData({
selectTab: e.currentTarget.dataset.tab,
})
if (e.currentTarget.dataset.tab == 'tab2') {
this.setData({
jilu: false,
})
this.getSignedList()
} else {
this.setData({
jilu: true,
})
this.loadLoveRanking()
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.loadLoveRanking()
this.bannerListV2()
this.setData({
timestamp: getTimestamp(),
})
},
bannerListV2: function () {
let that = this
api_banner.bannerList().then(function (res) {
that.setData({
banner: res.data
})
console.log('?'+JSON.stringify(that.data.banner))
})
},
preViewImage(e) {
let list = [];
list.push(this.data.banner[0].bannerImg)
list.push(this.data.banner[1].bannerImg)
wx.previewImage({
urls: list,
current: e.currentTarget.dataset.src
})
},
// 加载 爱心互助排行榜
loadLoveRanking() {
this.setData({
loveRankingList: [],
preloadVisible: true
})
api.leaderboard().then(res => {
this.setData({
datalenght: res.data.length
})
res.data.forEach((item, index) => {
this.data.loveRankingList.push(item)
})
this.setData({
loveRankingList: this.data.loveRankingList,
preloadVisible: false
})
}).catch(() => {
this.setData({
datalenght:0,
loveRankingList: [],
preloadVisible: false
})
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
if(this.data.selectTab == 'tab2'){
this.pulldownRefresh()
}
if (!app.globalData.previewImage) {
console.log('过滤previewImage引起的onShow')
}
app.globalData.previewImage = false
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
// 参与记录切换
onButtonChange: function (e) {
const list = this.data.typeList
let that = this;
list.forEach(item => {
if (item.type === e.currentTarget.dataset.type) {
item.select = true
} else {
item.select = false
}
})
that.setData({
typeList: list,
selectedTab_B: e.currentTarget.dataset.type
})
this.pulldownRefresh()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
this.pullDownRefresh = this.selectComponent('#pulldown-refresh')
},
onPageScroll(e) {
this.pullDownRefresh.onPageScroll(e)
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
if(this.data.selectTab == 'tab2'){
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_B.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() {
console.log('+++++++++++++++++++++++++')
const para = {
pageIndex: this.data.pageNo,
pageSize: this.data.pageSize,
timestamp: this.data.timestamp,
actType: this.data.selectedTab_B.substr(3, 1)
}
api.getSignedList(para).then(res => {
console.log('已报名活动', res.data.length)
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()
})
},
// 查看详情
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}`
})
}
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})