172 lines
3.7 KiB
JavaScript
172 lines
3.7 KiB
JavaScript
// pages/member/rankingListSecond/rankingListSecond.js
|
|
var app = getApp();
|
|
Page({
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
active: 0,
|
|
url: '',
|
|
list: [],
|
|
rankType: 'visit',
|
|
|
|
// more
|
|
isLoadMore: true,
|
|
page: 1,
|
|
total_page: 0
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
this.getDate();
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
if (this.data.isLoadMore) {
|
|
this.getMoreData();
|
|
} else {
|
|
console.log('没有更多了');
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage: function () {},
|
|
chooseType(val) {
|
|
let index = val.detail.index;
|
|
switch (index) {
|
|
case 0:
|
|
this.setData({
|
|
rankType: 'visit'
|
|
});
|
|
break;
|
|
case 1:
|
|
this.setData({
|
|
rankType: 'collection'
|
|
});
|
|
break;
|
|
case 2:
|
|
this.setData({
|
|
rankType: 'reliable'
|
|
});
|
|
break;
|
|
default:
|
|
this.setData({
|
|
rankType: 'visit'
|
|
});
|
|
break;
|
|
}
|
|
this.list = [];
|
|
this.getDate();
|
|
},
|
|
getDate() {
|
|
let urlStr = app.getNetAddresss('plugin.business-card.frontend.controllers.rank.card-rank.index');
|
|
urlStr += '&rank_type=' + this.data.rankType + '&page=1';
|
|
app._getNetWork({
|
|
url: urlStr,
|
|
success: (resdata) => {
|
|
var response = resdata.data;
|
|
if (response.result == 1) {
|
|
this.setData({
|
|
isLoadMore: true,
|
|
total_page: response.data.last_page,
|
|
list: response.data.data
|
|
});
|
|
if (!this.data.total_page) {
|
|
this.setData({
|
|
total_page: 0
|
|
});
|
|
}
|
|
} else {
|
|
wx.showToast({
|
|
title: response.msg,
|
|
icon: 'none'
|
|
});
|
|
}
|
|
},
|
|
fail: function (res) {
|
|
console.log(res);
|
|
}
|
|
});
|
|
},
|
|
// 获取更多数据
|
|
getMoreData() {
|
|
this.setData({
|
|
isLoadMore: false
|
|
});
|
|
// 防止多次请求分页数据
|
|
if (this.data.page >= this.data.total_page) {
|
|
return;
|
|
} else {
|
|
let page = this.data.page + 1;
|
|
this.setData({
|
|
page});
|
|
let urlStr = app.getNetAddresss('plugin.business-card.frontend.controllers.rank.card-rank.index');
|
|
urlStr += '&rank_type=' + this.data.rankType + '&page=' + this.data.page;
|
|
app._getNetWork({
|
|
url: urlStr,
|
|
success: (resdata) => {
|
|
var response = resdata.data;
|
|
if (response.result == 1) {
|
|
var myData = response.data.data.concat(this.data.list);
|
|
this.setData({
|
|
list: myData
|
|
});
|
|
} else {
|
|
wx.showToast({
|
|
title: response.msg,
|
|
icon: 'none'
|
|
});
|
|
let pages = this.data.page - 1;
|
|
this.setData({
|
|
page: pages,
|
|
isLoadMore: false
|
|
});
|
|
}
|
|
},
|
|
fail: function (res) {
|
|
console.log(res);
|
|
}
|
|
});
|
|
}
|
|
},
|
|
// 跳转到对应的名片
|
|
goToBackCard(e) {
|
|
let item = e.target.dataset.item || e.currentTarget.dataset.item;
|
|
wx.navigateTo({
|
|
url: '/packageB/member/business_card/BusinessCard/BusinessCard?mark=card&card_id=' + item.card_id
|
|
});
|
|
}
|
|
});
|