1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- const RankApi = require('../net/RankApi');
- cc.Class({
- extends: cc.Component,
- properties: {
- scrollView: cc.ScrollView,
- 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);
- }
- if (Global.winSize.height <= 1000) {
- this.scrollView.vertical = true;
- }
- },
- 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();
- this.scrollView.scrollToTop();
- },
- nextPage() {
- if (this.pageIndex >= (Math.ceil(this.ranks.length / 5) - 1) || this.ranks == undefined || this.ranks.length == 0) {
- return;
- }
- this.pageIndex += 1;
- this._setupList();
- this.scrollView.scrollToTop();
- }
- // update (dt) {},
- });
|