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

5 years ago
// subpages/integralCentre/pages/index/index.js
import {
pointsRecordlist,
5 years ago
userPointsRankinglist,
gradeRankinglist
} 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, //排名方式
selectTab: "tab1",
5 years ago
typeList: [{ //排名方式:0-周,1-月
type: "0",
name: "网格排名",
select: true
},
{
type: "1",
name: "街道排名",
select: false
5 years ago
},
{
type: "2",
name: "等级排名",
select: false
}
5 years ago
],
timestamp: getTimestamp(),
loadMoreType: "none",
5 years ago
loadMoreVisible: false
5 years ago
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({ //前面页面传过来的积分总数
5 years ago
points: options.points
})
5 years ago
this.pointsRankinglist(); //初始化加载积分记录列表
},
5 years ago
// tab 切换
onTabChange (e) {
5 years ago
this.setData({
pageIndex: 1,
5 years ago
pageSize: 15,
loadMoreType: "loading",
5 years ago
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,
loadMoreType: "loading",
5 years ago
loadMoreVisible: true,
5 years ago
})
5 years ago
if ( e.currentTarget.dataset.type == "2") {
that.gradeRankinglist()
} else {
that.pointsRankinglist()
}
5 years ago
},
5 years ago
// 积分记录-积分排行接口
pointsRankinglist () {
5 years ago
let that = this
const para = {
5 years ago
pageIndex: 1,
5 years ago
pageSize: 20,
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",
5 years ago
loadMoreVisible: false,
})
}
5 years ago
}).catch(err => {
that.setData({
5 years ago
pointsRankinglist: [],
nodatapointsRanking: true,
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 () {
5 years ago
},
5 years ago
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {},
5 years ago
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
5 years ago
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
5 years ago
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
5 years ago
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
5 years ago
this.setData({
loadMoreVisible: true
})
if (this.data.selectTab == "tab1") {
5 years ago
// this.pointsRankinglist(); //积分排行
} else {
if (this.data.loadMoreType === "loading") {
5 years ago
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
}
},
5 years ago
//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)
})
},
bindtapIntegralRule () {
console.log('获取积分规则')
wx.navigateTo({
url: `/subpages/understandJs/pages/noticeDetail/noticeDetail?modulecode=notice_points_rule`
})
},
5 years ago
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
5 years ago
}
})