const jcgamelog = require('../../jcfw/service/jcgamelog'); const NetManage = require('../../manages/NetManage'); const { operation, OperationType } = require('../../Operation/Operation'); cc.Class({ extends: cc.Component, properties: { nd_my: { default: null, type: cc.Node, }, tableView: { default: null, type: cc.Node, }, spine_hero: { default: null, type: sp.Skeleton, }, nd_btn1: { default: null, type: cc.Node, }, nd_btn2: { default: null, type: cc.Node, }, tableContent: { default: null, type: cc.Node, }, title_time: { default: null, type: cc.Node, }, title_score: { default: null, type: cc.Label, }, }, // LIFE-CYCLE CALLBACKS: init(data) { this.type = 0; this.rankData = data; }, onLoad() { // set can open // NetManage.getRankOpenList((res) => { // var rankList = res.list; // if (rankList.includes(2) && this.nd_btn2) // this.nd_btn2.active = true; // }); this.title_time.active = false; this.title_score.stirng = 'Score'; jcgamelog.addOperation(OperationType.BUTTON, 'get into rank'); cc.Notifier.on('clickrankhero', this, this.clickrankhero.bind(this)); }, onClickFirstRank() { this.title_time.active = false; this.title_score.stirng = 'Score'; this.type = 1; NetManage.getactivityRankingList(1, (data) => { this.initTable(JSON.stringify(data)); }); }, onClickSecondRank() { this.title_time.active = false; this.title_score.stirng = 'Score'; this.type = 2; NetManage.getactivityRankingList(2, (data) => { this.initTable(JSON.stringify(data)); }); }, onClickThirdRank() { this.title_time.active = true; this.title_score.stirng = 'Level'; this.type = 3; NetManage.getactivityRankingList(3, (data) => { this.initTable(JSON.stringify(data)); }); }, onClickFourthRank() { this.title_time.active = true; this.title_score.stirng = 'Level'; this.type = 4; NetManage.getactivityRankingList(4, (data) => { this.initTable(JSON.stringify(data)); }); }, initTable(rankData) { this.tableContent.destroyAllChildren(); var data = JSON.parse(rankData); if (this.type == 1 || this.type == 2) { data.my_ranked.modifytime = null; data.rows.forEach((element) => { element.modifytime = null; }); } this.nd_my.getComponent('cellRank').initdata(data.my_ranked); setTimeout(() => { this.tableView .getComponent('tableView') .initTableView(data.rows.length, { array: data.rows, target: this, }); if (data.rows.length > 0) { cc.Notifier.emit('clickrankhero', { account_id: data.rows[0].user.account_id, hero_id: data.rows[0].user.hero_id, }); } }, 100); }, onDestroy() { cc.Notifier.off('clickrankhero', this); }, clickrankhero(v) { var skinres = cc.playerData.getheroSkinbyId(v.hero_id, 0); cc.loader.loadRes( 'spine/heropic/pic_hero' + skinres, sp.SkeletonData, function (err, sp) { this.spine_hero.skeletonData = sp; this.spine_hero._updateSkeletonData(); this.spine_hero.setAnimation(0, 'animation', true); }.bind(this) ); }, start() { this.type = 1; this.initTable(this.rankData); }, onclose() { this.node.destroy(); }, // update (dt) {}, });