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