car_lib_bottom.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import { _decorator, Color, Component, instantiate, Label, Layout, Node, PageView, Prefab, Sprite, SpriteFrame, UITransform } from 'cc';
  2. import { base_ui } from '../../fw/base_ui';
  3. import { tools } from '../../tools';
  4. import { car_lib_list_item } from './car_lib_list_item';
  5. import { car_lib_page_item } from './car_lib_page_item';
  6. import { uiManager } from '../../manager/uiManager';
  7. import { config } from '../../config';
  8. import { car_info } from '../car_info';
  9. const { ccclass, property } = _decorator;
  10. @ccclass('car_lib_bottom')
  11. export class car_lib_bottom extends base_ui {
  12. @property(Node) btn_num_left:Node = null
  13. @property(Node) btn_num_right:Node = null
  14. @property(Node) lab_num:Node = null
  15. @property(Node) pageView:Node = null
  16. @property(Node) pageView_content:Node = null
  17. @property(Prefab) pageView_page_item:Prefab = null
  18. private num_current_count:number = 1
  19. private num_total_count:number = 1
  20. private current_select_list_item:car_lib_list_item = null
  21. private m_click_item_cb = null
  22. start() {
  23. this.onButtonListen(this.btn_num_left, ()=>{
  24. if(this.num_current_count==1) {
  25. return
  26. }
  27. this.num_current_count -=1
  28. this.updateNumStatus()
  29. })
  30. this.onButtonListen(this.btn_num_right, ()=>{
  31. if(this.num_current_count>=this.num_total_count) {
  32. return
  33. }
  34. this.num_current_count +=1
  35. this.updateNumStatus()
  36. })
  37. this.pageView.on(PageView.EventType. PAGE_TURNING, (e:PageView)=>{
  38. let currentPageIndex = e.getCurrentPageIndex()
  39. // console.log('currentPageIndex=',currentPageIndex)
  40. this.num_current_count = currentPageIndex + 1
  41. this.updateNumStatus()
  42. })
  43. }
  44. public init(click_item_cb) {
  45. this.m_click_item_cb = click_item_cb
  46. this.num_total_count = tools.all_car_page_list.length
  47. this.updateNumStatus()
  48. for (let index = 0; index < this.num_total_count; index++) {
  49. let page = instantiate(this.pageView_page_item)
  50. let data_list = tools.all_car_page_list[index]
  51. page.getComponent(car_lib_page_item).init(this.pageView, index,data_list, this.onSelectedItem.bind(this), this.onClickListItem.bind(this))
  52. this.pageView.getComponent(PageView).addPage(page)
  53. }
  54. }
  55. private getNumCurrentIndex():number {
  56. let index = this.num_current_count - 1
  57. if(index<0) {
  58. index = 0
  59. }
  60. return index
  61. }
  62. private updateNumStatus() {
  63. this.lab_num.getComponent(Label).string = this.num_current_count + '/' + this.num_total_count
  64. let index = this.getNumCurrentIndex()
  65. this.pageView.getComponent(PageView).scrollToPage(index)
  66. }
  67. private onSelectedItem(page_item:car_lib_page_item, list_item:car_lib_list_item) {
  68. this.current_select_list_item = list_item
  69. setTimeout(()=>{
  70. this.pageView.getComponent(PageView).scrollToPage(page_item.getIndex())
  71. },100)
  72. }
  73. private onClickListItem(page_item:car_lib_page_item,list_item:car_lib_list_item) {
  74. if(this.current_select_list_item!=null) {
  75. if(this.current_select_list_item.getData().id == list_item.getData().id) {
  76. return
  77. }
  78. }
  79. if(list_item.getIsJiesuo()==false) {
  80. uiManager.Instance().showUi(config.UI.ui_car_info, null, (node:Node)=>{
  81. node.getComponent(car_info).initView(list_item.getData(),list_item.getIsJiesuo())
  82. })
  83. return
  84. }
  85. if(this.current_select_list_item!=null) {
  86. this.current_select_list_item.setUnselectedStatus()
  87. }
  88. list_item.setSelectedStatus()
  89. this.current_select_list_item = list_item
  90. if(this.m_click_item_cb!=null) {
  91. this.m_click_item_cb(list_item)
  92. }
  93. }
  94. }