123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- 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';
- import { GameEvent } from '../../data/GameEvent';
- 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('一键领取');
- this.closeTips.node.getComponent(UIOpacity).opacity = 0;
- }
- onDestroy() {
- super.onDestroy();
- }
- onOpen() {
- this.updateMainPanel();
- this.updateMailNum();
- Framework.event.addEvent(GameEvent.MailUpdate, () => {
- this.updateMainPanel();
- this.updateMailNum();
- }, this);
- tween(this.closeTips.node.getComponent(UIOpacity))
- .to(1, { opacity: 255 })
- .to(1.2, { opacity: 10 })
- .union()
- .repeatForever()
- .start()
- }
- 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}`;
- }
- }
|