car_lib.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { _decorator, Component, Label, Node, Sprite } from 'cc';
  2. import { base_ui } from '../../fw/base_ui';
  3. import { car_lib_top } from './car_lib_top';
  4. import { car_lib_bottom } from './car_lib_bottom';
  5. import { car_lib_list_item } from './car_lib_list_item';
  6. import { userDataManager } from '../../manager/userDataManager';
  7. import { ClientEvent } from '../../lib/clientEvent';
  8. import { config } from '../../config';
  9. import { http } from '../../http';
  10. const { ccclass, property } = _decorator;
  11. @ccclass('car_lib')
  12. export class car_lib extends base_ui {
  13. @property(Node) btn_back:Node = null
  14. @property(Node) top_node:Node = null
  15. @property(Node) bottom_node:Node = null
  16. start() {
  17. this.onButtonListen(this.btn_back, ()=>{
  18. this.close()
  19. })
  20. this.initData()
  21. }
  22. initData() {
  23. this.top_node.getComponent(car_lib_top).init()
  24. this.bottom_node.getComponent(car_lib_bottom).init(this.onClickListItem.bind(this))
  25. }
  26. private onClickListItem(item:car_lib_list_item) {
  27. let opt = {'car_id': item.getData().id}
  28. http.post(config.API.user_set_default_car_id, opt, (err,d)=>{
  29. let nd = JSON.parse(d)
  30. if(nd.code === config.status.SUCCESS){
  31. userDataManager.user_car_list.default_car_id = item.getData().id
  32. this.top_node.getComponent(car_lib_top).reloadUserCar()
  33. ClientEvent.dispatchEvent(config.UI_EVENT.UPDATE_USER_DEFAULT_CAR)
  34. }
  35. })
  36. }
  37. }