12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- const RankApi = require('../net/RankApi');
- cc.Class({
- extends: cc.Component,
- properties: {
- layout: cc.Layout,
- rankItem: cc.Prefab,
- meNode: cc.Node
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- this.pageIndex = 0;
- this.listItem = [];
- for(let i = 0; i < 5; i++) {
- let item = cc.instantiate(this.rankItem);
- this.layout.node.addChild(item);
- item.active = false;
- this.listItem.push(item);
- }
- },
- start () {
- },
- init() {
- RankApi.getAllRanks((responseData) => {
- console.log(responseData);
- this.ranks = responseData.ranks;
- this.me = responseData.me;
- this._setupList();
- this._setupMeData();
- }, (error) => {
- console.log('all rank error' + error);
- });
- },
- _setupList() {
- let start = this.pageIndex * 5;
- let end = start + 5;
- let sortArray = this.ranks.slice(start,end);
- this.listItem.forEach(n => {
- n.active = false;
- });
- for(let i = 0; i < sortArray.length; i++) {
- let item = this.listItem[i];
- item.active = true;
- item.getComponent('GameRankItem').init(sortArray[i]);
- }
- },
- _setupMeData() {
- this.meNode.active = true;
- this.meNode.getComponent('GameRankItem').init(this.me, true);
- },
- previousPage() {
- if (this.pageIndex <= 0 || this.ranks == undefined || this.ranks.length == 0) {
- return;
- }
- this.pageIndex -= 1;
- this._setupList();
- },
- nextPage() {
- if (this.pageIndex >= (Math.ceil(this.ranks.length / 5) - 1) || this.ranks == undefined || this.ranks.length == 0) {
- return;
- }
- this.pageIndex += 1;
- this._setupList();
- }
- // update (dt) {},
- });
|