MailItem.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { AppKernel } from '@scripts/app/AppKernel';
  2. import { UIViewID } from '@scripts/define/UIDefine';
  3. import { UIView } from '@scripts/framework/ui/UIView';
  4. import { formatMailTimeToMMDDYYYY, parseMailRewardStr } from '@scripts/utils/Helper';
  5. import { addBtnClick, removeBtnClick } from '@scripts/utils/UIHelper';
  6. import { _decorator, Button, Component, instantiate, Label, Node, UIOpacity } from 'cc';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('MailItem')
  9. export class MailItem extends Component {
  10. @property(Node)
  11. private unread: Node = null;
  12. @property(Node)
  13. private read: Node = null;
  14. @property(Label)
  15. private title: Label = null;
  16. @property(Label)
  17. private desc: Label = null;
  18. @property(Node)
  19. private item_gc: Node = null;
  20. @property(Node)
  21. private item_sc: Node = null;
  22. @property(Node)
  23. private reward_layout: Node = null;
  24. private _mailData: any = {};
  25. onLoad() {
  26. // 只绑定一次!
  27. addBtnClick(this.node, this.handleMailClick, this);
  28. }
  29. initItem(mailData: any = {}) {
  30. this._mailData = mailData;
  31. this.updateReward();
  32. this.updateStatus();
  33. this.updateTxt();
  34. }
  35. async handleMailClick() {
  36. const { MailStatus, MailID } = this._mailData;
  37. const { mailStore } = AppKernel.stores;
  38. console.log("handleMailClick", MailID);
  39. if (MailStatus == "1") {
  40. await mailStore.reqMailRead(MailID);
  41. mailStore.reqMailList();
  42. }
  43. AppKernel.ui.open(UIViewID.MailDetail, { mailData: this._mailData });
  44. }
  45. updateReward() {
  46. this.reward_layout.removeAllChildren();
  47. const { BonusString } = this._mailData;
  48. const rewards = parseMailRewardStr(BonusString);
  49. rewards?.forEach(item => {
  50. const node = instantiate(
  51. item?.type == "30000" ? this.item_sc : this.item_gc
  52. );
  53. const num = node.getChildByName("num");
  54. num.getComponent(Label).string = item?.reward;
  55. node.active = true;
  56. node.parent = this.reward_layout;
  57. })
  58. }
  59. updateStatus() {
  60. const { MailStatus } = this._mailData;
  61. this.unread.active = MailStatus == "1" ? true : false;
  62. this.read.active = MailStatus == "1" ? false : true;
  63. const opacityCmp = this.reward_layout.getComponent(UIOpacity);
  64. if (MailStatus == "1") {
  65. opacityCmp.opacity = 255;
  66. } else if (MailStatus == "2") {
  67. opacityCmp.opacity = 255 * 0.45;
  68. } else if (MailStatus == "3") {
  69. opacityCmp.opacity = 0;
  70. }
  71. }
  72. updateTxt() {
  73. this.title.string = this._mailData.TitleString;
  74. this.desc.string = "System " + formatMailTimeToMMDDYYYY(this._mailData.CreateTime);
  75. }
  76. }