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

279 lines
6.2 KiB

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