MailDetail.ts 4.4 KB

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