MailItem.ts 3.6 KB

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