MailMain.ts 4.5 KB

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