rank.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 { http } from '../../http';
  7. import { config } from '../../config';
  8. import { userDataManager } from '../../manager/userDataManager';
  9. const { ccclass, property } = _decorator;
  10. @ccclass('rank')
  11. export class rank extends Component {
  12. @property(Node) btn_back:Node = null;
  13. @property(Node) btn_country:Node = null;
  14. @property(Node) btn_province:Node = null;
  15. @property(Node) btn_city:Node = null;
  16. @property(Node) list:Node = null;
  17. @property(Node) list_top:Node = null;
  18. @property(Node) list_content:Node = null;
  19. @property(Prefab) rank_list_item:Prefab = null;
  20. @property(Node) my_info_node:Node = null;
  21. @property(SpriteFrame) sf_country_selected:SpriteFrame = null;
  22. @property(SpriteFrame) sf_country_unselected:SpriteFrame = null;
  23. @property(SpriteFrame) sf_province_selected:SpriteFrame = null;
  24. @property(SpriteFrame) sf_province_unselected:SpriteFrame = null;
  25. @property(SpriteFrame) sf_city_selected:SpriteFrame = null;
  26. @property(SpriteFrame) sf_city_unselected:SpriteFrame = null;
  27. start() {
  28. uiManager.Instance().onButtonListen(this.btn_back, ()=>{
  29. this.close()
  30. })
  31. uiManager.Instance().onButtonListen(this.btn_country, ()=>{
  32. this.onClassifyItem(1)
  33. })
  34. uiManager.Instance().onButtonListen(this.btn_province, ()=>{
  35. this.onClassifyItem(2)
  36. })
  37. uiManager.Instance().onButtonListen(this.btn_city, ()=>{
  38. this.onClassifyItem(3)
  39. })
  40. this.onClassifyItem(1)
  41. }
  42. onClassifyItem(type:number) {
  43. this.btn_country.getComponent(Sprite).spriteFrame = this.sf_country_unselected
  44. this.btn_province.getComponent(Sprite).spriteFrame = this.sf_province_unselected
  45. this.btn_city.getComponent(Sprite).spriteFrame = this.sf_city_unselected
  46. switch (type) {
  47. case 1:
  48. this.btn_country.getComponent(Sprite).spriteFrame = this.sf_country_selected
  49. break;
  50. case 2:
  51. this.btn_province.getComponent(Sprite).spriteFrame = this.sf_province_selected
  52. break;
  53. case 3:
  54. this.btn_city.getComponent(Sprite).spriteFrame = this.sf_city_selected
  55. break;
  56. default:
  57. break;
  58. }
  59. this.loadView(type)
  60. }
  61. loadView(type:number) {
  62. let id = 0
  63. if(type==2) {
  64. id = userDataManager.user_data.region_pid
  65. } else if(type==3) {
  66. id = userDataManager.user_data.region_id
  67. }
  68. http.get(config.STATIC_API.rankings(id),(err,d)=>{
  69. if(!err){
  70. let data = JSON.parse(d)
  71. if(data.code===config.status.SUCCESS){
  72. // console.log('data=',data.content)
  73. this.reloadListTop(data.content)
  74. this.reloadListContent(data.content)
  75. this.reloadMyInfo(type)
  76. }
  77. } else{
  78. console.log("initData err",err)
  79. }
  80. })
  81. }
  82. reloadListTop(data_list) {
  83. this.list_top.getComponent(rank_list_top).initView(data_list)
  84. }
  85. reloadListContent(data_list) {
  86. this.list_content.removeAllChildren()
  87. if(data_list.length < 3) {
  88. return
  89. }
  90. for (let index = 3; index < data_list.length; index++) {
  91. const element = data_list[index]
  92. let item = instantiate(this.rank_list_item)
  93. item.parent = this.list_content;
  94. item.getComponent(rank_list_item).initView(element,index)
  95. }
  96. this.list.getComponent(ScrollView).scrollToTop()
  97. }
  98. reloadMyInfo(type:number) {
  99. let stype = 0
  100. if(type==2) {
  101. stype = 1
  102. } else if(type==3) {
  103. stype = 2
  104. }
  105. let opt = {'stype': stype}
  106. http.post(config.API.user_ranking, opt, (err,d)=>{
  107. if(!err){
  108. let data = JSON.parse(d)
  109. if(data.code===config.status.SUCCESS){
  110. // console.log('data=',data.content)
  111. this.my_info_node.getComponent(rank_my_info).initView(data.content)
  112. }
  113. } else{
  114. console.log("initData err",err)
  115. }
  116. })
  117. }
  118. close() {
  119. this.node.removeFromParent()
  120. }
  121. }