MailItem.ts 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import RedPoint from "../data/RedPoint";
  2. const { ccclass, property } = cc._decorator;
  3. @ccclass
  4. export default class MailItem extends cc.Component {
  5. @property(cc.Label)
  6. mTitle: cc.Label = null;
  7. @property(cc.Label)
  8. mTime: cc.Label = null;
  9. @property(cc.Node)
  10. tipsIcon: cc.Node = null;
  11. /**
  12. * 邮件内容
  13. */
  14. public data: any;
  15. public index: number = 0;
  16. public callback: (mailItem: MailItem) => void;
  17. public init(data: any, index: number) {
  18. this.data = data;
  19. this.index = index;
  20. this.mTitle.string = this.data.title;
  21. this.tipsIcon.active = !data.receive;
  22. let day = this.data.xTime / 86400;
  23. if (day <= 0) {
  24. this.mTime.string = '即将过期';
  25. } else {
  26. this.mTime.string = '剩余' + Math.floor(day) + '天';
  27. }
  28. }
  29. public setCallback(callback: (mailItem: MailItem) => void) {
  30. this.callback = callback;
  31. }
  32. public onclick() {
  33. this.callback(this);
  34. }
  35. }