fenggu/pages/ranking/ranking.js

106 lines
2.3 KiB
JavaScript

// pages/ranking/ranking.js
var urlPath = require('../../config.js');
Page({
/**
* 页面的初始数据
*/
data: {
//列表
ranking_list:[]
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
var that = this;
that.getList();
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
onShow:function(){
if (typeof this.getTabBar === 'function' &&
this.getTabBar()) {
this.getTabBar().setData({
selected: 2
})
}
},
getList:function(){
var that = this;
wx.request({
url: urlPath.getVoteList,
header:{
'token': wx.getStorageSync('token')
},
success(res){
if(res.data.code == 0){
if(res.data.data.length > 0){
var ranking_list = [];
res.data.data.forEach(function(item, index){
ranking_list.push({
ranks: index + 1,
name: item.user_name,
ids: item.id,
img: urlPath.host + item.pic,
number: item.votes,
});
});
that.setData({
ranking_list:ranking_list
});
}
}else{
console.log(res.data.msg); //失败
}
}
});
}
})