select_collect_event.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { _decorator, Component, instantiate, Node, Prefab } from 'cc';
  2. import { event_item } from '../../../data/data';
  3. import { select_collect_event_item } from './select_collect_event_item';
  4. const { ccclass, property } = _decorator;
  5. @ccclass('select_collect_event')
  6. export class select_collect_event extends Component {
  7. @property(Node) content:Node = null;
  8. @property(Node) btn_close:Node = null;
  9. @property(Prefab) item_prefab:Prefab = null;
  10. @property(Node) btn_sure:Node = null;
  11. private call_back = null;
  12. public show(list:event_item[],call,cur_event_id:number,event_list_id:number[]){
  13. this.call_back = call;
  14. for (let index = 0; index < list.length; index++) {
  15. const element = list[index];
  16. let isHave = false;
  17. for (let i = 0; i < event_list_id.length; i++) {
  18. const id = event_list_id[i];
  19. if(id==element.event_id){
  20. isHave = true;
  21. break;
  22. }
  23. }
  24. if(element.event_id!=cur_event_id){
  25. let item = instantiate(this.item_prefab)
  26. item.parent = this.content;
  27. item.getComponent(select_collect_event_item).initView(element,isHave)
  28. }
  29. }
  30. this.btn_close.on(Node.EventType.TOUCH_END,()=>{
  31. this.close()
  32. })
  33. this.btn_sure.on(Node.EventType.TOUCH_END,()=>{
  34. if(this.call_back!=null){
  35. this.call_back(this.getSelectList())
  36. }
  37. this.close();
  38. })
  39. }
  40. public getSelectList():number[]{
  41. let temp = []
  42. for (let index = 0; index < this.content.children.length; index++) {
  43. const element = this.content.children[index];
  44. if( element.getComponent(select_collect_event_item).getIsSelect()){
  45. temp.push(element.getComponent(select_collect_event_item).getData().event_id)
  46. }
  47. }
  48. return temp;
  49. }
  50. close(){
  51. this.node.destroy()
  52. }
  53. }