const api = require('../../../../utils/api') Page({ data: { datalenght:0, loveRankingList: [], preloadVisible: true, first: { nickname: '', faceImg: '', kindnessTime: '', participationNum: '' }, second: { nickname: '', faceImg: '', kindnessTime: '', participationNum: '' }, third: { nickname: '', faceImg: '', kindnessTime: '', participationNum: '' } }, onLoad () { this.loadLoveRanking() }, // 加载 爱心互助排行榜 loadLoveRanking () { api.leaderboard().then(res => { this.setData({ datalenght: res.data.length }) console.log('爱心互助排行榜', res+":::::::::"+this.data.datalenght) res.data.forEach((item,index) => { if (index === 0) { for(const key in this.data.first) { this.data.first[key] = item[key] } } else if (index === 1) { for(const key in this.data.second) { this.data.second[key] = item[key] } } else if (index === 2) { for(const key in this.data.third) { this.data.third[key] = item[key] } } else { this.data.loveRankingList.push(item) } }) this.setData({ loveRankingList: this.data.loveRankingList, first: this.data.first, second: this.data.second, third: this.data.third, preloadVisible: false }) }).catch(() => { this.setData({ loveRankingList: [], preloadVisible: false }) }) } })