MailMain.ts 4.4 KB

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