const RankApi = require('../net/RankApi'); cc.Class({ extends: cc.Component, properties: { content: cc.Node, myNode: cc.Node, allRankSpriteFrame: [cc.SpriteFrame], friendRankSpriteFrame: [cc.SpriteFrame], secondTabSpriteFrame: [cc.SpriteFrame], topDivider: cc.Node, allRankTab: cc.Sprite, friendRankTab: cc.Sprite, companyTab: cc.Sprite, artistTab: cc.Sprite, companyText: cc.RichText, artistText: cc.RichText, srcollView: cc.ScrollView, }, onLoad() { this.node.height = cc.view.getVisibleSize().height; this.contentY = this.content.y; this.content.y = this.content.height - cc.view.getVisibleSize().height; this.currentTab = 0; this.secondTab = 0; this.myScript = this.myNode.getComponent('RankItem'); this.rankListScript = this.srcollView.getComponent('RankList'); this.show(); }, onEnable() { this.allRankSelected(); }, allRankSelected() { // this.allRankTab.node.x = 480; // this.friendRankTab.node.x = 496; this.allRankTab.node.zIndex = 99; this.friendRankTab.node.zIndex = 0; this.allRankTab.spriteFrame = this.allRankSpriteFrame[1]; this.friendRankTab.spriteFrame = this.friendRankSpriteFrame[0]; this.currentTab = 0; this.data = null this.companyTabSelected(); this.getData(); }, friendRankSelected() { // this.allRankTab.node.x = 496; // this.friendRankTab.node.x = 480; this.allRankTab.node.zIndex = 0; this.friendRankTab.node.zIndex = 99; this.allRankTab.spriteFrame = this.allRankSpriteFrame[0]; this.friendRankTab.spriteFrame = this.friendRankSpriteFrame[1]; this.currentTab = 1; this.data = null this.companyTabSelected(); this.getData(); }, companyTabSelected() { this.secondTab = 0; this.topDivider.x = -140; this.companyTab.spriteFrame = this.secondTabSpriteFrame[1]; this.artistTab.spriteFrame = this.secondTabSpriteFrame[0]; this.setSelectedText(this.companyText, '经济公司'); this.setDefaultText(this.artistText, '艺人'); if (this.data) { this.bindData(this.data.companyRank); } }, artistTabSelected() { this.secondTab = 1; this.topDivider.x = 140; this.companyTab.spriteFrame = this.secondTabSpriteFrame[0]; this.artistTab.spriteFrame = this.secondTabSpriteFrame[1]; this.setDefaultText(this.companyText, '经济公司'); this.setSelectedText(this.artistText, '艺人'); if (this.data) { this.bindData(this.data.artistRank); } }, setDefaultText(richText, message) { richText.node.color = new cc.Color(161, 105, 33); richText.string = `${message}` }, setSelectedText(richText, message) { richText.node.color = new cc.Color(255, 244, 222); richText.string = `${message}` }, show() { this.content.y = -cc.view.getVisibleSize().height; let s = cc.sequence(cc.moveTo(0.2, 0, this.contentY + 20).easing(cc.easeCubicActionOut()), cc.moveBy(0.05, 0, -20)); this.content.runAction(s); this.scheduleOnce(() => { }, 0.2); }, close() { if (this.node && this.node.parent) { let self = this; let finish = cc.callFunc(() => { self.node.destroy(); }, this) this.content.runAction(cc.sequence(cc.moveTo(0.2, 0, -cc.view.getVisibleSize().height).easing(cc.easeCubicActionIn()), finish)); } }, getData() { let promise = null; if (this.currentTab === 0) { promise = RankApi.getAllRankPromise(); } else { promise = RankApi.getFriendRankPromise(); } this.scheduleOnce(() => { promise.then(res => { this.data = res.data; this.bindData(this.data.companyRank); }).catch((code, msg) => { console.log(code) }); }, 0.3); }, bindData(pageData) { this.srcollView.stopAutoScroll(); this.srcollView.scrollToTop(0); this.myScript.setType(this.secondTab); this.myScript.bindMySelf(pageData.me); this.rankListScript.bindData(pageData.ranks); }, });