mailbox_details.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { _decorator, Component, instantiate, Label, Node, Prefab } from 'cc';
  2. import { base_ui } from '../../fw/base_ui';
  3. import { mail_item_data } from '../../data';
  4. import { mailbox_reward_item } from './mailbox_reward_item';
  5. const { ccclass, property } = _decorator;
  6. @ccclass('mailbox_details')
  7. export class mailbox_details extends base_ui {
  8. @property(Node) public_bg:Node = null
  9. @property(Node) lab_content:Node = null
  10. @property(Node) lab_time:Node = null
  11. @property(Node) reward_content:Node = null
  12. @property(Prefab) reward_item:Prefab = null
  13. @property(Node) btn_delete:Node = null
  14. @property(Node) btn_recv:Node = null
  15. private m_data:mail_item_data = null
  16. private m_delete_cb = null
  17. private m_recv_cb = null
  18. start() {
  19. this.onButtonListen(this.public_bg, ()=>{
  20. this.node.active = false
  21. })
  22. this.onButtonListen(this.btn_delete, ()=>{
  23. if(this.m_delete_cb) {
  24. this.m_delete_cb(this)
  25. }
  26. })
  27. this.onButtonListen(this.btn_recv, ()=>{
  28. if(this.m_recv_cb) {
  29. this.m_recv_cb(this)
  30. }
  31. })
  32. }
  33. initView(data:mail_item_data, delete_cb, recv_cb) {
  34. this.m_data = data
  35. this.m_delete_cb = delete_cb
  36. this.m_recv_cb = recv_cb
  37. this.lab_content.getComponent(Label).string = ' ' + data.content
  38. this.btn_delete.active = false
  39. this.btn_recv.active = false
  40. if(data.state==1) {
  41. this.btn_delete.active = true
  42. } else {
  43. this.btn_recv.active = true
  44. }
  45. this.reward_content.removeAllChildren()
  46. // console.log('rewards_list=',data.rewards_list)
  47. for (let index = 0; index < data.rewards_list.length; index++) {
  48. const element = data.rewards_list[index];
  49. let item = instantiate(this.reward_item)
  50. item.parent = this.reward_content
  51. item.getComponent(mailbox_reward_item).initView(element)
  52. }
  53. }
  54. public getData():mail_item_data {
  55. return this.m_data
  56. }
  57. }