rank.ts 4.2 KB

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