MailMain.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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.node.getComponent(UIOpacity))
  43. .to(1.2, { opacity: 10 })
  44. .to(1, { opacity: 255 })
  45. .union()
  46. .repeatForever()
  47. .start()
  48. }
  49. onDestroy() {
  50. super.onDestroy();
  51. }
  52. onOpen() {
  53. this.updateMainPanel();
  54. this.updateMailNum();
  55. Framework.event.addEvent("MailUpdate", () => {
  56. this.updateMainPanel();
  57. this.updateMailNum();
  58. }, this);
  59. }
  60. onClose() {
  61. }
  62. onShow() {
  63. }
  64. onHide() {
  65. }
  66. private onTouchButton(event: Event, customStr) {
  67. let target: any = event.target;
  68. if (target.name == 'mask') {
  69. Framework.layer.close(this);
  70. } else if (target.name == 'auto_del_btn') {
  71. let ids = [];
  72. let list = MailData.orderMail();
  73. for (const v of list) {
  74. if (Number(v.read) == 1) {
  75. ids.push(v.id);
  76. }
  77. }
  78. if (ids.length <= 0) {
  79. Framework.tips.setTips(StringUtil.getLanguageData('暂无可删邮件!'));
  80. return
  81. }
  82. LoginMgr.sendPost('user', 'batch_del_mail', (data) => {
  83. console.log(data);
  84. MailData.removeMail(data.del_mails);
  85. this.updateMainPanel();
  86. this.updateMailNum();
  87. }, { ids: ids })
  88. } else if (target.name == 'auto_get_btn') {
  89. let ids = [];
  90. let list = MailData.orderMail();
  91. for (const v of list) {
  92. if (Number(v.read) == 0 && v.awards && v.awards.size > 0) {
  93. ids.push(v.id);
  94. }
  95. }
  96. if (ids.length <= 0) {
  97. Framework.tips.setTips(StringUtil.getLanguageData('暂无可领邮件!'));
  98. return
  99. }
  100. LoginMgr.sendPost('user', 'batch_mail_awards', (data) => {
  101. // console.log(data);
  102. for (const key in data.read_mails) {
  103. if (Object.prototype.hasOwnProperty.call(data.read_mails, key)) {
  104. const element = data.read_mails[key];
  105. MailData.setMailReadById(key);
  106. this.updateMainPanel();
  107. this.updateMailNum();
  108. }
  109. }
  110. }, { ids: ids })
  111. }
  112. }
  113. onEventList(item, idx) {
  114. item.getComponent(MailItem).refreshItem(this._mailList[idx]);
  115. }
  116. private updateMainPanel() {
  117. this._mailList = MailData.orderMail();
  118. this._nowMailId = this._mailList.length > 0 ? this._mailList[0].id : 0;
  119. if (this._mailList.length == 0) {
  120. this.noneNode.active = true;
  121. this.delAutoBtn.active = false;
  122. this.getAutoBtn.active = false;
  123. this.numTx.node.active = false;
  124. } else {
  125. this.noneNode.active = false;
  126. this.delAutoBtn.active = true;
  127. this.getAutoBtn.active = true;
  128. this.numTx.node.active = true;
  129. }
  130. this.sv.numItems = this._mailList.length;
  131. }
  132. private updateMailNum() {
  133. this.numTx.string = `${StringUtil.getLanguageData('邮件数: ')}${this._mailList.length}/${GlobalConf.data.MailMaxCount.Value}`;
  134. }
  135. }