|
@@ -1,8 +1,11 @@
|
|
|
-import { _decorator, Component, instantiate, Node, Prefab, Sprite, SpriteFrame } from 'cc';
|
|
|
+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';
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
@ccclass('rank')
|
|
@@ -11,6 +14,7 @@ export class rank extends Component {
|
|
|
@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;
|
|
@@ -62,26 +66,64 @@ export class rank extends Component {
|
|
|
}
|
|
|
|
|
|
loadView(type:number) {
|
|
|
- this.reloadListTop()
|
|
|
- this.reloadListContent()
|
|
|
- this.reloadMyInfo()
|
|
|
+ let id = 0
|
|
|
+ if(type==2) {
|
|
|
+ id = userDataManager.user_data.region_pid
|
|
|
+ } else if(type==3) {
|
|
|
+ id = userDataManager.user_data.region_id
|
|
|
+ }
|
|
|
+ http.get(config.STATIC_API.rankings(id),(err,d)=>{
|
|
|
+ if(!err){
|
|
|
+ let data = JSON.parse(d)
|
|
|
+ if(data.code===config.status.SUCCESS){
|
|
|
+ // console.log('data=',data.content)
|
|
|
+ this.reloadListTop(data.content)
|
|
|
+ this.reloadListContent(data.content)
|
|
|
+ this.reloadMyInfo(type)
|
|
|
+ }
|
|
|
+ } else{
|
|
|
+ console.log("initData err",err)
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
- reloadListTop() {
|
|
|
- // this.list_top.getComponent(rank_list_top).initView()
|
|
|
+ reloadListTop(data_list) {
|
|
|
+ this.list_top.getComponent(rank_list_top).initView(data_list)
|
|
|
}
|
|
|
|
|
|
- reloadListContent() {
|
|
|
+ reloadListContent(data_list) {
|
|
|
this.list_content.removeAllChildren()
|
|
|
- for (let index = 0; index < 10; index++) {
|
|
|
+ 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()
|
|
|
+ item.getComponent(rank_list_item).initView(element,index)
|
|
|
}
|
|
|
+ this.list.getComponent(ScrollView).scrollToTop()
|
|
|
}
|
|
|
|
|
|
- reloadMyInfo() {
|
|
|
- // this.my_info_node.getComponent(rank_my_info).initView()
|
|
|
+ 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){
|
|
|
+ // console.log('data=',data.content)
|
|
|
+ this.my_info_node.getComponent(rank_my_info).initView(data.content)
|
|
|
+ }
|
|
|
+ } else{
|
|
|
+ console.log("initData err",err)
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
close() {
|