rank.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import { _decorator, Component, instantiate, Node, Prefab, ScrollView, Sprite, SpriteFrame } from 'cc';
  2. import { uiManager } from '../../manager/uiManager';
  3. import { rank_list_item } from './rank_list_item';
  4. import { rank_my_info } from './rank_my_info';
  5. import { rank_list_top } from './rank_list_top';
  6. import { userDataManager } from '../../manager/userDataManager';
  7. import { GameManager } from '../../GameManager';
  8. const { ccclass, property } = _decorator;
  9. @ccclass('rank')
  10. export class rank extends Component {
  11. @property(Node) btn_back:Node = null;
  12. @property(Node) btn_country:Node = null;
  13. @property(Node) btn_province:Node = null;
  14. @property(Node) btn_city:Node = null;
  15. @property(Node) list:Node = null;
  16. @property(Node) list_top:Node = null;
  17. @property(Node) list_content:Node = null;
  18. @property(Prefab) rank_list_item:Prefab = null;
  19. @property(Node) my_info_node:Node = null;
  20. @property(SpriteFrame) sf_country_selected:SpriteFrame = null;
  21. @property(SpriteFrame) sf_country_unselected:SpriteFrame = null;
  22. @property(SpriteFrame) sf_province_selected:SpriteFrame = null;
  23. @property(SpriteFrame) sf_province_unselected:SpriteFrame = null;
  24. @property(SpriteFrame) sf_city_selected:SpriteFrame = null;
  25. @property(SpriteFrame) sf_city_unselected:SpriteFrame = null;
  26. start() {
  27. uiManager.Instance().onButtonListen(this.btn_back, ()=>{
  28. this.close()
  29. })
  30. uiManager.Instance().onButtonListen(this.btn_country, ()=>{
  31. this.onClassifyItem(1)
  32. })
  33. uiManager.Instance().onButtonListen(this.btn_province, ()=>{
  34. this.onClassifyItem(2)
  35. })
  36. uiManager.Instance().onButtonListen(this.btn_city, ()=>{
  37. this.onClassifyItem(3)
  38. })
  39. this.onClassifyItem(1)
  40. }
  41. onClassifyItem(type:number) {
  42. this.btn_country.getComponent(Sprite).spriteFrame = this.sf_country_unselected
  43. this.btn_province.getComponent(Sprite).spriteFrame = this.sf_province_unselected
  44. this.btn_city.getComponent(Sprite).spriteFrame = this.sf_city_unselected
  45. switch (type) {
  46. case 1:
  47. this.btn_country.getComponent(Sprite).spriteFrame = this.sf_country_selected
  48. break;
  49. case 2:
  50. this.btn_province.getComponent(Sprite).spriteFrame = this.sf_province_selected
  51. break;
  52. case 3:
  53. this.btn_city.getComponent(Sprite).spriteFrame = this.sf_city_selected
  54. break;
  55. default:
  56. break;
  57. }
  58. this.loadView(type)
  59. }
  60. loadView(type:number) {
  61. let id = 0
  62. if(type==1) {
  63. id = 0
  64. } else if(type==2) {
  65. id = userDataManager.user_data.region_pid
  66. } else if(type==3) {
  67. id = userDataManager.user_data.region_id
  68. }
  69. GameManager.requestRankList(id,(d_content)=>{
  70. // console.log('排行列表 id=',id, '数据=',d_content)
  71. this.reloadListTop(d_content)
  72. this.reloadListContent(d_content)
  73. this.reloadMyInfo(type)
  74. })
  75. }
  76. reloadListTop(data_list) {
  77. this.list_top.getComponent(rank_list_top).initView(data_list)
  78. }
  79. reloadListContent(data_list) {
  80. this.list_content.removeAllChildren()
  81. if(data_list.length < 3) {
  82. return
  83. }
  84. for (let index = 3; index < data_list.length; index++) {
  85. const element = data_list[index]
  86. let item = instantiate(this.rank_list_item)
  87. item.parent = this.list_content;
  88. item.getComponent(rank_list_item).initView(element,index)
  89. }
  90. this.list.getComponent(ScrollView).scrollToTop()
  91. }
  92. reloadMyInfo(type:number) {
  93. let stype = 0
  94. if(type==1) {
  95. stype = 0
  96. } else if(type==2) {
  97. stype = 1
  98. } else if(type==3) {
  99. stype = 2
  100. }
  101. GameManager.requestMineRank(stype, (d_content)=>{
  102. // console.log('个人排行 stype=',stype,'数据=',d_content)
  103. this.my_info_node.getComponent(rank_my_info).initView(d_content)
  104. })
  105. }
  106. close() {
  107. this.node.removeFromParent()
  108. }
  109. }