import { _decorator, Component, Label, Node, tween, UIOpacity } from 'cc'; import { BaseView } from '../../../framework/layer/BaseView'; import { MailItem } from './MailItem'; import { StringUtil } from '../../../framework/util/StringUtil'; import { MailData } from '../../data/MailData'; import { GlobalConf } from '../../config/GlobalConf'; import List from '../../../framework/list/List'; import { Framework } from '../../../framework/Framework'; import { LoginMgr } from '../../common/LoginManager'; const { ccclass, property } = _decorator; @ccclass('MailMain') export class MailMain extends BaseView { @property({ type: Label, tooltip: "关闭提示" }) closeTips: Label = null; @property({ type: Label, tooltip: "标题" }) titlteTx: Label = null; @property({ type: Label, tooltip: "邮件数文字" }) numTx: Label = null; @property({ type: List, tooltip: "滑动容器" }) sv: List = null; @property({ type: Node, tooltip: "为空提示节点" }) noneNode: Node = null; @property({ type: Label, tooltip: "为空提示文字" }) noneTx: Label = null; @property({ type: Node, tooltip: "一键删除按钮" }) delAutoBtn: Node = null; @property({ type: Label, tooltip: "一键删除按钮文字" }) delAutoBtnTx: Label = null; @property({ type: Node, tooltip: "一键领取按钮" }) getAutoBtn: Node = null; @property({ type: Label, tooltip: "一键领取按钮文字" }) getAutoBtnTx: Label = null; private _mailList = []; private _nowMailId: number = 0; onLoad() { super.onLoad(); this.closeTips.string = StringUtil.getLanguageData('点击空白关闭'); this.titlteTx.string = StringUtil.getLanguageData('邮件'); this.noneTx.string = StringUtil.getLanguageData('当前空空如也哦~'); this.delAutoBtnTx.string = StringUtil.getLanguageData('一键删除'); this.getAutoBtnTx.string = StringUtil.getLanguageData('一键领取'); tween(this.closeTips.getComponent(UIOpacity)) .to(1.2, { opacity: 10 }) .to(1, { opacity: 255 }) .repeatForever() .start() } onDestroy() { super.onDestroy(); } onOpen() { this.updateMainPanel(); this.updateMailNum(); Framework.event.addEvent("MailUpdate", () => { this.updateMainPanel(); this.updateMailNum(); }, this); } onClose() { } onShow() { } onHide() { } private onTouchButton(event: Event, customStr) { let target: any = event.target; if (target.name == 'mask') { Framework.layer.close(this); } else if (target.name == 'auto_del_btn') { let ids = []; let list = MailData.orderMail(); for (const v of list) { if (Number(v.read) == 1) { ids.push(v.id); } } if (ids.length <= 0) { Framework.tips.setTips(StringUtil.getLanguageData('暂无可删邮件!')); return } LoginMgr.sendPost('user', 'batch_del_mail', (data) => { console.log(data); MailData.removeMail(data.del_mails); this.updateMainPanel(); this.updateMailNum(); }, { ids: ids }) } else if (target.name == 'auto_get_btn') { let ids = []; let list = MailData.orderMail(); for (const v of list) { if (Number(v.read) == 0 && v.awards && v.awards.size > 0) { ids.push(v.id); } } if (ids.length <= 0) { Framework.tips.setTips(StringUtil.getLanguageData('暂无可领邮件!')); return } LoginMgr.sendPost('user', 'batch_mail_awards', (data) => { console.log(data); for (const key in data.read_mails) { if (Object.prototype.hasOwnProperty.call(data.read_mails, key)) { const element = data.read_mails[key]; MailData.setMailReadById(key); this.updateMainPanel(); this.updateMailNum(); } } }, { ids: ids }) } } onEventList(item, idx) { item.getComponent(MailItem).refreshItem(this._mailList[idx]); } private updateMainPanel() { this._mailList = MailData.orderMail(); this._nowMailId = this._mailList.length > 0 ? this._mailList[0].id : 0; if (this._mailList.length == 0) { this.noneNode.active = true; this.delAutoBtn.active = false; this.getAutoBtn.active = false; this.numTx.node.active = false; } else { this.noneNode.active = false; this.delAutoBtn.active = true; this.getAutoBtn.active = true; this.numTx.node.active = true; } this.sv.numItems = this._mailList.length; } private updateMailNum() { this.numTx.string = `${StringUtil.getLanguageData('邮件数: ')}${this._mailList.length}/${GlobalConf.data.MailMaxCount.Value}`; } }