MailItem.ts 3.6 KB

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