import { _decorator, Component, instantiate, Node, Prefab, ScrollView, Sprite, SpriteFrame } from 'cc'; import { uiManager } from '../../manager/uiManager'; import { rank_list_item } from './rank_list_item'; import { rank_my_info } from './rank_my_info'; import { rank_list_top } from './rank_list_top'; import { userDataManager } from '../../manager/userDataManager'; import { GameManager } from '../../GameManager'; const { ccclass, property } = _decorator; @ccclass('rank') export class rank extends Component { @property(Node) btn_back:Node = null; @property(Node) btn_country:Node = null; @property(Node) btn_province:Node = null; @property(Node) btn_city:Node = null; @property(Node) list:Node = null; @property(Node) list_top:Node = null; @property(Node) list_content:Node = null; @property(Prefab) rank_list_item:Prefab = null; @property(Node) my_info_node:Node = null; @property(SpriteFrame) sf_country_selected:SpriteFrame = null; @property(SpriteFrame) sf_country_unselected:SpriteFrame = null; @property(SpriteFrame) sf_province_selected:SpriteFrame = null; @property(SpriteFrame) sf_province_unselected:SpriteFrame = null; @property(SpriteFrame) sf_city_selected:SpriteFrame = null; @property(SpriteFrame) sf_city_unselected:SpriteFrame = null; start() { uiManager.Instance().onButtonListen(this.btn_back, ()=>{ this.close() }) uiManager.Instance().onButtonListen(this.btn_country, ()=>{ this.onClassifyItem(1) }) uiManager.Instance().onButtonListen(this.btn_province, ()=>{ this.onClassifyItem(2) }) uiManager.Instance().onButtonListen(this.btn_city, ()=>{ this.onClassifyItem(3) }) this.onClassifyItem(1) } onClassifyItem(type:number) { this.btn_country.getComponent(Sprite).spriteFrame = this.sf_country_unselected this.btn_province.getComponent(Sprite).spriteFrame = this.sf_province_unselected this.btn_city.getComponent(Sprite).spriteFrame = this.sf_city_unselected switch (type) { case 1: this.btn_country.getComponent(Sprite).spriteFrame = this.sf_country_selected break; case 2: this.btn_province.getComponent(Sprite).spriteFrame = this.sf_province_selected break; case 3: this.btn_city.getComponent(Sprite).spriteFrame = this.sf_city_selected break; default: break; } this.loadView(type) } loadView(type:number) { let id = 0 if(type==1) { id = 0 } else if(type==2) { id = userDataManager.user_data.region_pid } else if(type==3) { id = userDataManager.user_data.region_id } GameManager.requestRankList(id,(d_content)=>{ // console.log('排行列表 id=',id, '数据=',d_content) this.reloadListTop(d_content) this.reloadListContent(d_content) this.reloadMyInfo(type) }) } reloadListTop(data_list) { this.list_top.getComponent(rank_list_top).initView(data_list) } reloadListContent(data_list) { this.list_content.removeAllChildren() if(data_list.length < 3) { return } for (let index = 3; index < data_list.length; index++) { const element = data_list[index] let item = instantiate(this.rank_list_item) item.parent = this.list_content; item.getComponent(rank_list_item).initView(element,index) } this.list.getComponent(ScrollView).scrollToTop() } reloadMyInfo(type:number) { let stype = 0 if(type==1) { stype = 0 } else if(type==2) { stype = 1 } else if(type==3) { stype = 2 } GameManager.requestMineRank(stype, (d_content)=>{ // console.log('个人排行 stype=',stype,'数据=',d_content) this.my_info_node.getComponent(rank_my_info).initView(d_content) }) } close() { this.node.removeFromParent() } }