MailMain.ts 4.4 KB

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