123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- 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 { http } from '../../http';
- import { config } from '../../config';
- import { userDataManager } from '../../manager/userDataManager';
- import { tools } from '../../tools';
- 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==2) {
- id = userDataManager.user_data.region_pid
- } else if(type==3) {
- id = userDataManager.user_data.region_id
- }
- tools.requestRankList(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==2) {
- stype = 1
- } else if(type==3) {
- stype = 2
- }
- let opt = {'stype': stype}
- http.post(config.API.user_ranking, opt, (err,d)=>{
- if(!err){
- let data = JSON.parse(d)
- if(data.code===config.status.SUCCESS){
- this.my_info_node.getComponent(rank_my_info).initView(data.content)
- }
- } else{
- console.log("user rank Data err",err)
- }
- })
- }
- close() {
- this.node.removeFromParent()
- }
- }
|