MailItem.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import { _decorator, Label, Node, Sprite, SpriteFrame } from 'cc';
  2. import { ResKeeper } from '../../../framework/res/ResKeeper';
  3. import { StringUtil } from '../../../framework/util/StringUtil';
  4. import { MailData } from '../../data/MailData';
  5. import { Framework } from '../../../framework/Framework';
  6. import { ViewID } from '../../../framework/config/LayerConf';
  7. import { LoginMgr } from '../../common/LoginManager';
  8. import { GameEvent } from '../../data/GameEvent';
  9. import { MailManager } from '../../manager/MailManager';
  10. const { ccclass, property } = _decorator;
  11. @ccclass('MailItem')
  12. export class MailItem extends ResKeeper {
  13. @property({ type: Node, tooltip: "邮件状态" })
  14. awardBg: Node = null;
  15. @property({ type: Node, tooltip: "奖励节点" })
  16. awardNode: Node = null;
  17. @property({ type: Label, tooltip: "邮件标题" })
  18. titleTx: Label = null;
  19. @property({ type: Label, tooltip: "邮件时间" })
  20. timeTx: Label = null;
  21. @property({ type: Node, tooltip: "已读状态" })
  22. readIco: Node = null;
  23. @property({ type: Label, tooltip: "已读状态文字" })
  24. readIcoTx: Label = null;
  25. @property({ type: Node, tooltip: "附件" })
  26. awardTips: Node = null;
  27. @property({ type: Label, tooltip: "附件文字" })
  28. awardTipsTx: Label = null;
  29. @property({ type: Node, tooltip: "已读遮罩" })
  30. maskImg: Node = null;
  31. private data = null;
  32. protected onLoad() {
  33. this.readIcoTx.string = StringUtil.getLanguageData('已读');
  34. this.awardTipsTx.string = StringUtil.getLanguageData('附件');
  35. }
  36. refreshItem(data) {
  37. this.data = data;
  38. this.titleTx.string = MailManager.getMailText(data.title,true);
  39. this.maskImg.active = false;
  40. this.readIco.active = false;
  41. let date = new Date(data.time);
  42. let Y = date.getFullYear() + '-';
  43. let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
  44. let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + '';
  45. this.timeTx.string = Y + M + D;
  46. if (data.award && data.award.size > 0) {
  47. this.awardTips.active = false;
  48. let showAward = MailManager.getShowAward(data.id)
  49. if (showAward) {
  50. this.awardBg.active = false;
  51. this.awardNode.active = true;
  52. } else {
  53. this.awardBg.active = true;
  54. this.awardNode.active = false;
  55. this.load('mail', 'texture/mail_3/spriteFrame', SpriteFrame, (res: SpriteFrame) => {
  56. this.awardBg.getComponent(Sprite).spriteFrame = res;
  57. })
  58. }
  59. } else {
  60. this.awardBg.active = true;
  61. this.awardNode.active = false;
  62. this.awardTips.active = false;
  63. this.load('mail', 'texture/mail_3/spriteFrame', SpriteFrame, (res: SpriteFrame) => {
  64. this.awardBg.getComponent(Sprite).spriteFrame = res;
  65. })
  66. }
  67. if (data.read == 1) {
  68. this.awardBg.active = true;
  69. this.awardNode.active = false;
  70. this.awardTips.active = false;
  71. this.readIco.active = true;
  72. this.maskImg.active = true;
  73. this.load('mail', 'texture/mail_2/spriteFrame', SpriteFrame, (res: SpriteFrame) => {
  74. this.awardBg.getComponent(Sprite).spriteFrame = res;
  75. })
  76. }
  77. }
  78. protected onDestroy() {
  79. super.onDestroy();
  80. }
  81. onClose() {
  82. }
  83. //UI事件处理
  84. private onTouchButton(event: Event) {
  85. let target: any = event.target;
  86. if (target.name == 'bg') {
  87. if (this.data.read == 1) {
  88. Framework.layer.open(ViewID.MailDetail, null, this.data);
  89. return;
  90. }
  91. if (this.data.award && this.data.award.size > 0) {
  92. Framework.layer.open(ViewID.MailDetail, null, this.data);
  93. } else {
  94. MailManager.sendReadMailMsg({ id: this.data.id },()=>{
  95. Framework.event.fireEvent(GameEvent.MailUpdate);
  96. Framework.layer.open(ViewID.MailDetail, null, this.data);
  97. })
  98. }
  99. }
  100. }
  101. }