MailDetail.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import { AppKernel } from '@scripts/app/AppKernel';
  2. import { UIViewID } from '@scripts/define/UIDefine';
  3. import { UIView } from '@scripts/framework/ui/UIView';
  4. import { addBtnClick } from '@scripts/utils/UIHelper';
  5. import { _decorator, Button, Component, Label, Node } from 'cc';
  6. const { ccclass, property } = _decorator;
  7. import { UIPopup } from '@scripts/framework/ui/UIPopup';
  8. import { formatMailTimeToMMDDYYYY, parseMailRewardStr } from '@scripts/utils/Helper';
  9. @ccclass('MailDetail')
  10. export class MailDetail extends UIPopup {
  11. readonly viewId: UIViewID = UIViewID.MailDetail;
  12. @property(Node)
  13. private btn_close: Node = null;
  14. @property(Node)
  15. private btn_delete: Node = null;
  16. @property(Node)
  17. private btn_claim: Node = null;
  18. @property(Node)
  19. private btn_confirm: Node = null;
  20. @property(Label)
  21. private title: Label = null;
  22. @property(Label)
  23. private from: Label = null;
  24. @property(Label)
  25. private time: Label = null;
  26. @property(Label)
  27. private content: Label = null;
  28. @property(Node)
  29. private reward: Node = null;
  30. @property(Node)
  31. private reward_layout: Node = null;
  32. private _mailData: any = {};
  33. protected onOpen(params?: any) {
  34. this._mailData = params?.mailData;
  35. this.initMailDetail();
  36. }
  37. protected onCreate(): void | Promise<void> {
  38. addBtnClick(this.btn_close, this.onBtnCloseClick, this);
  39. addBtnClick(this.btn_delete, this.onBtnDeleteClick, this);
  40. addBtnClick(this.btn_claim, this.onBtnClaimClick, this);
  41. addBtnClick(this.btn_confirm, this.onBtnCloseClick, this);
  42. }
  43. private initMailDetail() {
  44. console.log('MailDetail onOpen', this._mailData);
  45. const { TitleString, CreateTime, TextString, BonusString, MailStatus } = this._mailData;
  46. this.title.string = TitleString;
  47. this.from.string = 'From System';
  48. this.time.string = formatMailTimeToMMDDYYYY(CreateTime);
  49. this.content.string = TextString;
  50. const rewards = parseMailRewardStr(BonusString);
  51. const hasReward = rewards.length > 0;
  52. if (MailStatus == "1") {//未读
  53. this.btn_claim.active = hasReward ? true : false;
  54. this.btn_delete.active = hasReward ? false : true;
  55. this.btn_confirm.active = hasReward ? false : true;
  56. this.reward.active = hasReward ? true : false;
  57. } else if (MailStatus == "2") {//已读
  58. this.btn_claim.active = hasReward ? true : false;
  59. this.btn_delete.active = hasReward ? false : true;
  60. this.btn_confirm.active = hasReward ? false : true;
  61. this.reward.active = hasReward ? true : false;
  62. } else if (MailStatus == "3") {//已领取
  63. this.btn_claim.active = false;
  64. this.btn_delete.active = true;
  65. this.btn_confirm.active = true;
  66. this.reward.active = false;
  67. }
  68. if (hasReward) {
  69. this.reward_layout.children.forEach(item => item.active = false);
  70. rewards?.forEach(item => {
  71. const node = item?.type == "30000"
  72. ? this.reward_layout.getChildByName("sc")
  73. : this.reward_layout.getChildByName("gc")
  74. const num = node.getChildByName("num");
  75. num.getComponent(Label).string = item?.reward;
  76. node.active = true;
  77. })
  78. }
  79. }
  80. private onBtnCloseClick() {
  81. AppKernel.ui.close(UIViewID.MailDetail);
  82. }
  83. private async onBtnDeleteClick() {
  84. const { MailStatus, MailID, BonusString } = this._mailData;
  85. const { mailStore } = AppKernel.stores;
  86. const rewards = parseMailRewardStr(BonusString);
  87. const hasReward = rewards.length > 0;
  88. console.log("handleMailDelete", MailID);
  89. if (hasReward && MailStatus < "3") return;
  90. await mailStore.reqMailDelete(MailID);
  91. mailStore.reqMailList();
  92. this.onBtnCloseClick();
  93. }
  94. private async onBtnClaimClick() {
  95. const { MailStatus, MailID, BonusString } = this._mailData;
  96. const { mailStore } = AppKernel.stores;
  97. const rewards = parseMailRewardStr(BonusString);
  98. const hasReward = rewards.length > 0;
  99. console.log("handleMailClaim", MailID);
  100. if (hasReward && MailStatus < "3") {
  101. await mailStore.reqMailTake(MailID);
  102. mailStore.reqMailList();
  103. }
  104. this.onBtnCloseClick();
  105. }
  106. }