rank.js
4.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
import {
getBindtapData
} from '../../utils/util';
let app = getApp();
Page({
data: {
authorizeVisible: false,
navIndex: 0,
status: "promotion",
turnsIndex: 0, //轮次 0:本轮 1:历史
rankInfo: {},
historyRankInfoList: [],
historyIndex: 0,
isInit: false
},
onShareAppMessage() {},
showAuth() {
this.setData({
authorizeVisible: true
})
},
onLoad(options) {
this.initData();
},
initData() {
this.refreshStatus();
},
/**
* 推广积分排行
*/
queryActivity() {
this.setData({
isInit: false
})
return new Promise((resolve, reject) => {
let status = this.data.status;
app.post({
url: app.api.activity,
data: {
key: status
}
}).then((result) => {
let rankInfo = this.formatRankInfo(result, status);
this.setData({
isInit: true,
rankInfo: rankInfo
});
console.log("rankInfo 1:", rankInfo);
resolve();
})
});
},
/**
* 历史积分排行
*/
queryActivityHistory() {
this.setData({
isInit: false
})
return new Promise((resolve, reject) => {
let status = this.data.status;
app.post({
url: app.api.activityHistory,
data: {
page: 1,
size: 999999,
key: this.data.status
}
}).then((result) => {
let historyRankInfoList = result.list;
this.setData({
isInit: true,
historyRankInfoList: historyRankInfoList
})
console.log("rankInfo 2 history:", historyRankInfoList);
this.setHistory();
resolve();
})
});
},
/**
* 格式化
*/
formatRankInfo(val, status) {
let rankInfo = val;
if (!rankInfo) return null;
if (status == "promotion") {
rankInfo.myMember.rank = rankInfo.myMember.promotionNo;
rankInfo.myMember.points = rankInfo.myMember.promotionPoints;
rankInfo.memberList.forEach(element => {
element.rank = element.promotionNo;
element.points = element.promotionPoints;
});
} else {
rankInfo.myMember.rank = rankInfo.myMember.rankNo;
rankInfo.myMember.points = rankInfo.myMember.rankPoints;
rankInfo.memberList.forEach(element => {
element.rank = element.rankNo;
element.points = element.rankPoints;
});
}
return rankInfo;
},
/**
* 设置
*/
setHistory() {
let index = this.data.historyIndex;
let status = this.data.status;
let historyRankInfoList = this.data.historyRankInfoList
let rankInfo = this.formatRankInfo(historyRankInfoList[index], status);
this.setData({
rankInfo
})
console.log("rankInfo:", rankInfo);
},
/**
* 选择导航
* @param {*} evt
*/
onNavSelectHandler(evt) {
let navIndex = this.data.navIndex;
let curIndex = getBindtapData(evt, "index");
if (navIndex != curIndex) {
this.setData({
navIndex: curIndex,
turnsIndex: 0,
historyIndex: 0,
})
}
this.refreshStatus();
},
// 选择轮次 历史/本轮
onChangeTurnsHandler(evt) {
let turnsIndex = this.data.turnsIndex;
let curIndex = getBindtapData(evt, "index");
if (turnsIndex != curIndex) {
this.setData({
turnsIndex: curIndex
});
console.log("curIndex:", curIndex);
if (curIndex == 0) {
this.queryActivity();
} else {
this.queryActivityHistory();
}
}
},
/**
* 拾取历史活动
*/
bindHistoryChange(e) {
let index = e.detail.value;
this.setData({
historyIndex: index,
})
this.setHistory()
},
/**
* 刷新状态重新请求
*/
refreshStatus() {
let status = "";
let navIndex = this.data.navIndex + "";
switch (navIndex) {
// 全部
case "0":
status = "promotion";
break;
// 购买积分
case "1":
status = "rank";
break;
default:
break;
}
this.setData({
status: status
})
// this.resetPage();
this.queryActivity();
},
/**
* 排行榜奖励
* @param {*} evt
*/
onRankGiftHandler(evt) {
app.router.push({
path: "rankGift"
})
},
// 滚动到底部 分页加载
onRankScrolltolower(e) {
},
// 隐藏蒙层
hideMask() {
this.setData({
authorizeVisible: false,
})
},
// 子组件事件
evtcomp(evt) {
let {
name,
data
} = evt.detail;
switch (name) {
// 隐藏弹窗
case "_evt_hide_mask":
this.hideMask();
break;
default:
break;
}
},
})