MailDetail.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import { _decorator, instantiate, Label, Node, Prefab, RichText, ScrollView, tween, UIOpacity, v3 } from 'cc';
  2. import { BaseView } from '../../../framework/layer/BaseView';
  3. import { Framework } from '../../../framework/Framework';
  4. import { StringUtil } from '../../../framework/util/StringUtil';
  5. import { ViewID } from '../../../framework/config/LayerConf';
  6. import { GameEvent } from '../../data/GameEvent';
  7. import { MailData } from '../../data/MailData';
  8. import { LoginMgr } from '../../common/LoginManager';
  9. import List from '../../../framework/list/List';
  10. import { CommonItem } from '../common/CommonItem';
  11. import { MailManager } from '../../manager/MailManager';
  12. const { ccclass, property } = _decorator;
  13. @ccclass('MailDetail')
  14. export class MailDetail extends BaseView {
  15. @property({ type: Label, tooltip: "关闭提示" })
  16. closeTips: Label = null;
  17. @property({ type: Label, tooltip: "标题" })
  18. titleTx: Label = null;
  19. @property({ type: Label, tooltip: "发件人标题" })
  20. fromTitle: Label = null;
  21. @property({ type: Label, tooltip: "发件人文字" })
  22. fromTx: Label = null;
  23. @property({ type: Label, tooltip: "主题标题" })
  24. captionTitle: Label = null;
  25. @property({ type: Label, tooltip: "主题文字" })
  26. captionTx: Label = null;
  27. @property({ type: Label, tooltip: "邮件时间" })
  28. timeTx: Label = null;
  29. @property({ type: RichText, tooltip: "邮件内容" })
  30. msgTx: RichText = null;
  31. @property({ type: Node, tooltip: "附件背景" })
  32. awardsBg: Node = null;
  33. @property({ type: List, tooltip: "附件容器" })
  34. awardsSv: List = null;
  35. @property({ type: Label, tooltip: "附件标题" })
  36. awardsTitle: Label = null;
  37. @property({ type: Node, tooltip: "附件领取标记" })
  38. getTips: Node = null;
  39. @property({ type: Node, tooltip: "领取按钮" })
  40. getBtn: Node = null;
  41. @property({ type: Label, tooltip: "领取按钮文字" })
  42. getBtnTx: Label = null;
  43. @property({ type: Node, tooltip: "删除按钮" })
  44. delBtn: Node = null;
  45. @property({ type: Label, tooltip: "删除按钮文字" })
  46. delBtnTx: Label = null;
  47. private data = null;
  48. onLoad() {
  49. super.onLoad();
  50. this.closeTips.string = StringUtil.getLanguageData('点击空白关闭');
  51. this.titleTx.string = StringUtil.getLanguageData('邮件详情');
  52. this.fromTitle.string = StringUtil.getLanguageData('来自');
  53. this.captionTitle.string = StringUtil.getLanguageData('主题');
  54. this.awardsTitle.string = StringUtil.getLanguageData('附件');
  55. this.getTips.getComponent(Label).string = StringUtil.getLanguageData('附件已领取');
  56. this.getBtnTx.string = StringUtil.getLanguageData('领取附件');
  57. this.delBtnTx.string = StringUtil.getLanguageData('删除邮件');
  58. this.closeTips.node.getComponent(UIOpacity).opacity = 0;
  59. }
  60. onDestroy() {
  61. super.onDestroy();
  62. }
  63. onOpen(data) {
  64. this.data = data;
  65. this.updateUI();
  66. tween(this.closeTips.node.getComponent(UIOpacity))
  67. .to(1, { opacity: 255 })
  68. .to(1.2, { opacity: 10 })
  69. .union()
  70. .repeatForever()
  71. .start()
  72. }
  73. onClose() {
  74. }
  75. onShow() {
  76. }
  77. onHide() {
  78. }
  79. private onTouchButton(event: Event, customStr) {
  80. let target: any = event.target;
  81. if (target.name == 'mask') {
  82. Framework.layer.close(this);
  83. } else if (target.name == 'del_btn') {
  84. MailManager.sendBatchDelMailMsg({ ids: [this.data.id] },()=>{
  85. Framework.event.fireEvent(GameEvent.MailUpdate);
  86. Framework.layer.close(this);
  87. })
  88. } else if (target.name == 'get_btn') {
  89. MailManager.sendReadMailMsg({ id: this.data.id },()=>{
  90. Framework.event.fireEvent(GameEvent.MailUpdate);
  91. Framework.layer.open(ViewID.MailDetail, null, this.data);
  92. })
  93. }
  94. }
  95. private updateUI() {
  96. this.captionTx.string = MailManager.getMailText(this.data.title, true);
  97. let context = MailManager.getMailText(this.data.content, false)
  98. this.msgTx.string = `<b>${StringUtil.getLanguageData(context)}</b>`;
  99. if (this.data.award && this.data.award.size > 0) {
  100. this.awardsBg.active = true;
  101. this.awardsSv.numItems = this.data.award.size;
  102. if (Number(this.data.read) == 1) {
  103. this.getBtn.active = false;
  104. this.delBtn.active = true;
  105. this.getTips.active = false;
  106. } else {
  107. this.getBtn.active = true;
  108. this.delBtn.active = false;
  109. this.getTips.active = false;
  110. }
  111. } else {
  112. this.awardsBg.active = false;
  113. this.getBtn.active = false;
  114. this.delBtn.active = true;
  115. this.getTips.active = false;
  116. }
  117. }
  118. onEventList(item, idx) {
  119. item.getComponent(CommonItem).refreshItem(this.data.award[idx]);
  120. }
  121. }