rank_classify.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { _decorator, Component, Label, Node, Sprite, SpriteFrame } from 'cc';
  2. import { base_ui } from '../../fw/base_ui';
  3. import { userDataManager } from '../../manager/userDataManager';
  4. const { ccclass, property } = _decorator;
  5. @ccclass('rank_classify')
  6. export class rank_classify extends base_ui {
  7. @property(Node) btn_country:Node = null;
  8. @property(Node) btn_province:Node = null;
  9. @property(Node) btn_city:Node = null;
  10. @property(Node) lab_country:Node = null;
  11. @property(Node) lab_province:Node = null;
  12. @property(Node) lab_city:Node = null;
  13. @property(SpriteFrame) sf_selected:SpriteFrame = null;
  14. @property(SpriteFrame) sf_un_selected:SpriteFrame = null;
  15. private m_click_cb = null
  16. start() {
  17. this.onButtonListen(this.btn_country, ()=>{
  18. this.onClassifyItem(1)
  19. })
  20. this.onButtonListen(this.btn_province, ()=>{
  21. this.onClassifyItem(2)
  22. })
  23. this.onButtonListen(this.btn_city, ()=>{
  24. this.onClassifyItem(3)
  25. })
  26. }
  27. init(type:number, click_cb) {
  28. this.setType(type)
  29. this.m_click_cb = click_cb
  30. }
  31. private setType(type:number) {
  32. this.btn_country.getComponent(Sprite).spriteFrame = this.sf_un_selected
  33. this.btn_province.getComponent(Sprite).spriteFrame = this.sf_un_selected
  34. this.lab_province.getComponent(Label).string = '省排名'
  35. this.btn_city.getComponent(Sprite).spriteFrame = this.sf_un_selected
  36. this.lab_city.getComponent(Label).string = '市排名'
  37. switch (type) {
  38. case 1:
  39. this.btn_country.getComponent(Sprite).spriteFrame = this.sf_selected
  40. break;
  41. case 2:
  42. this.btn_province.getComponent(Sprite).spriteFrame = this.sf_selected
  43. this.lab_province.getComponent(Label).string = userDataManager.user_data.province_name
  44. break;
  45. case 3:
  46. this.btn_city.getComponent(Sprite).spriteFrame = this.sf_selected
  47. this.lab_city.getComponent(Label).string = userDataManager.user_data.city_name
  48. break;
  49. default:
  50. break;
  51. }
  52. }
  53. private onClassifyItem(type:number) {
  54. this.setType(type)
  55. if(this.m_click_cb) {
  56. this.m_click_cb(type)
  57. }
  58. }
  59. }