MailMain.ts 4.5 KB

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