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

232 lines
5.2 KiB

5 years ago
// subpages/integralCentre/pages/index/index.js
import {
pointsRecordlist,
5 years ago
pointsRankinglist,
userPointsRankinglist
} from '../../../../utils/api'
import {
getTimestamp
} from '../../../../utils/common'
5 years ago
Page({
/**
* 页面的初始数据
*/
data: {
nodatapointsRecord: false,
nodatapointsRanking: false,
points: 0, //积分
5 years ago
pageIndex: 1,
5 years ago
pageSize: 15,
pointsRecordlist: [], //积分记录列表
pointsRankinglist: [], //积分排行
rankingType: 0, //排名方式
5 years ago
selectTab: 'tab1',
typeList: [{ //排名方式:0-周,1-月
type: '0',
5 years ago
name: '网格排名',
5 years ago
select: true
},
{
type: '1',
5 years ago
name: '街道排名',
5 years ago
select: false
}
],
timestamp: getTimestamp(),
loadMoreType: 'none',
loadMoreVisible: false,
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
this.setData({ //前面页面传过来的积分总数
5 years ago
points: options.points
})
5 years ago
this.pointsRankinglist(); //初始化加载积分记录列表
},
5 years ago
// tab 切换
onTabChange(e) {
this.setData({
pageIndex: 1,
5 years ago
pageSize: 15,
5 years ago
loadMoreType: 'loading',
loadMoreVisible: true,
pointsRecordlist: [],
pointsRankinglist: [],
5 years ago
pointsRankingUser: {},//当前用户排名信息
5 years ago
selectTab: e.currentTarget.dataset.tab,
nodatapointsRecord: false,
nodatapointsRanking: false,
5 years ago
})
if (this.data.selectTab == 'tab1') {
this.pointsRankinglist(); //积分排行
5 years ago
} else {
this.pointsRecordlist(); //初始化加载积分记录列表
5 years ago
}
},
// 排行切换
onButtonChange: function(e) {
5 years ago
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,
rankingType: e.currentTarget.dataset.type,
pageIndex: 1,
5 years ago
pageSize: 15,
timestamp: this.data.timestamp,
pointsRankinglist: [],
nodatapointsRanking: false,
5 years ago
loadMoreType: 'loading',
loadMoreVisible: true,
5 years ago
})
that.pointsRankinglist()
5 years ago
},
5 years ago
// 积分记录-积分排行接口
pointsRankinglist() {
5 years ago
let that = this
const para = {
5 years ago
pageIndex: 1,
pageSize: 10,
timestamp: this.data.timestamp,
5 years ago
rankingType: this.data.rankingType, //排名方式:0-周,1-月
5 years ago
}
5 years ago
userPointsRankinglist(para).then(res => {
5 years ago
that.setData({
5 years ago
pointsRankingUser: res.data.currentUser,
pointsRankinglist: that.data.pointsRankinglist.concat(res.data.rank),
5 years ago
})
5 years ago
if (that.data.pointsRankinglist.length > 0) {
that.setData({
5 years ago
nodatapointsRanking: false,
loadMoreType: 'none',
})
} else {
that.setData({
5 years ago
nodatapointsRanking: true,
loadMoreType: 'none',
loadMoreVisible: false,
})
}
5 years ago
}).catch(err => {
that.setData({
5 years ago
pointsRankinglist: [],
nodatapointsRanking: true,
5 years ago
loadMoreType: 'none',
5 years ago
loadMoreVisible: false,
5 years ago
})
console.log(err)
})
},
5 years ago
// 积分记录-积分记录接口
pointsRecordlist() {
let that = this
const para = {
pageIndex: this.data.pageIndex,
pageSize: this.data.pageSize,
timestamp: this.data.timestamp,
}
5 years ago
pointsRecordlist(para).then(res => {
that.setData({
5 years ago
pointsRecordlist: that.data.pointsRecordlist.concat(res.data),
loadMoreType: res.data.length === that.data.pageSize ? 'loading' : 'none',
})
5 years ago
if (that.data.pointsRecordlist.length > 0) {
that.setData({
5 years ago
nodatapointsRecord: false,
})
} else {
that.setData({
5 years ago
nodatapointsRecord: true,
loadMoreVisible: false,
})
}
}).catch(err => {
that.setData({
loadMoreType: 'none',
5 years ago
loadMoreVisible: false,
pointsRecordlist: [],
nodatapointsRecord: true,
})
console.log(err)
})
},
5 years ago
5 years ago
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function(options) {},
5 years ago
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function() {
this.setData({
loadMoreVisible: true
})
5 years ago
5 years ago
if (this.data.selectTab == 'tab1') {
// this.pointsRankinglist(); //积分排行
} else {
if (this.data.loadMoreType === 'loading') {
this.setData({
pageIndex: this.data.pageIndex + 1,
pageSize: this.data.pageSize,
timestamp: this.data.timestamp,
nodatapointsRecord: false,
})
5 years ago
this.pointsRecordlist(); //初始化加载积分记录列表
5 years ago
}
5 years ago
}
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function() {
}
})