MailMain.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import { _decorator, Component, Label, Node, tween, UIOpacity } from 'cc';
  2. import { BaseView } from '../../../framework/layer/BaseView';
  3. import { MailItem } from './MailItem';
  4. import { StringUtil } from '../../../framework/util/StringUtil';
  5. import { MailData } from '../../data/MailData';
  6. import { GlobalConf } from '../../config/GlobalConf';
  7. import List from '../../../framework/list/List';
  8. import { Framework } from '../../../framework/Framework';
  9. import { LoginMgr } from '../../common/LoginManager';
  10. import { GameEvent } from '../../data/GameEvent';
  11. import { MailManager } from '../../manager/MailManager';
  12. const { ccclass, property } = _decorator;
  13. @ccclass('MailMain')
  14. export class MailMain extends BaseView {
  15. @property({ type: Label, tooltip: "关闭提示" })
  16. closeTips: Label = null;
  17. @property({ type: Label, tooltip: "标题" })
  18. titlteTx: Label = null;
  19. @property({ type: Label, tooltip: "邮件数文字" })
  20. numTx: Label = null;
  21. @property({ type: List, tooltip: "滑动容器" })
  22. sv: List = null;
  23. @property({ type: Node, tooltip: "为空提示节点" })
  24. noneNode: Node = null;
  25. @property({ type: Label, tooltip: "为空提示文字" })
  26. noneTx: Label = null;
  27. @property({ type: Node, tooltip: "一键删除按钮" })
  28. delAutoBtn: Node = null;
  29. @property({ type: Label, tooltip: "一键删除按钮文字" })
  30. delAutoBtnTx: Label = null;
  31. @property({ type: Node, tooltip: "一键领取按钮" })
  32. getAutoBtn: Node = null;
  33. @property({ type: Label, tooltip: "一键领取按钮文字" })
  34. getAutoBtnTx: Label = null;
  35. private _mailList = [];
  36. private _nowMailId: number = 0;
  37. onLoad() {
  38. super.onLoad();
  39. this.closeTips.string = StringUtil.getLanguageData('点击空白关闭');
  40. this.titlteTx.string = StringUtil.getLanguageData('邮件');
  41. this.noneTx.string = StringUtil.getLanguageData('当前空空如也哦~');
  42. this.delAutoBtnTx.string = StringUtil.getLanguageData('一键删除');
  43. this.getAutoBtnTx.string = StringUtil.getLanguageData('一键领取');
  44. this.closeTips.node.getComponent(UIOpacity).opacity = 0;
  45. }
  46. onDestroy() {
  47. super.onDestroy();
  48. }
  49. onOpen() {
  50. this.updateMainPanel();
  51. this.updateMailNum();
  52. Framework.event.addEvent(GameEvent.MailUpdate, () => {
  53. this.updateMainPanel();
  54. this.updateMailNum();
  55. }, this);
  56. tween(this.closeTips.node.getComponent(UIOpacity))
  57. .to(1, { opacity: 255 })
  58. .to(1.2, { opacity: 10 })
  59. .union()
  60. .repeatForever()
  61. .start()
  62. }
  63. onClose() {
  64. }
  65. onShow() {
  66. }
  67. onHide() {
  68. }
  69. private onTouchButton(event: Event, customStr) {
  70. let target: any = event.target;
  71. if (target.name == 'mask') {
  72. Framework.layer.close(this);
  73. } else if (target.name == 'auto_del_btn') {
  74. let ids = [];
  75. let list = MailManager.orderMail();
  76. for (const v of list) {
  77. if (Number(v.read) == 1) {
  78. ids.push(v.id);
  79. }
  80. }
  81. if (ids.length <= 0) {
  82. Framework.tips.setTips(StringUtil.getLanguageData('暂无可删邮件!'));
  83. return
  84. }
  85. MailManager.sendBatchDelMailMsg({ ids: ids },()=>{
  86. this.updateMainPanel();
  87. this.updateMailNum();
  88. });
  89. } else if (target.name == 'auto_get_btn') {
  90. let ids = [];
  91. let list = MailManager.orderMail();
  92. for (const v of list) {
  93. if (Number(v.read) == 0 && v.awards && v.awards.size > 0) {
  94. ids.push(v.id);
  95. }
  96. }
  97. if (ids.length <= 0) {
  98. Framework.tips.setTips(StringUtil.getLanguageData('暂无可领邮件!'));
  99. return
  100. }
  101. MailManager.sendBatchMaillAwardsMsg({ ids: ids },()=>{
  102. this.updateMainPanel();
  103. this.updateMailNum();
  104. });
  105. }
  106. }
  107. onEventList(item, idx) {
  108. item.getComponent(MailItem).refreshItem(this._mailList[idx]);
  109. }
  110. private updateMainPanel() {
  111. this._mailList = MailManager.orderMail();
  112. this._nowMailId = this._mailList.length > 0 ? this._mailList[0].id : 0;
  113. if (this._mailList.length == 0) {
  114. this.noneNode.active = true;
  115. this.delAutoBtn.active = false;
  116. this.getAutoBtn.active = false;
  117. this.numTx.node.active = false;
  118. } else {
  119. this.noneNode.active = false;
  120. this.delAutoBtn.active = true;
  121. this.getAutoBtn.active = true;
  122. this.numTx.node.active = true;
  123. }
  124. this.sv.numItems = this._mailList.length;
  125. }
  126. private updateMailNum() {
  127. this.numTx.string = `${StringUtil.getLanguageData('邮件数: ')}${this._mailList.length}/${GlobalConf.data.MailMaxCount.Value}`;
  128. }
  129. }