123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- import { _decorator, Label, Node, Sprite, SpriteFrame } from 'cc';
- import { ResKeeper } from '../../../framework/res/ResKeeper';
- import { StringUtil } from '../../../framework/util/StringUtil';
- import { MailData } from '../../data/MailData';
- import { Framework } from '../../../framework/Framework';
- import { ViewID } from '../../../framework/config/LayerConf';
- import { LoginMgr } from '../../common/LoginManager';
- import { GameEvent } from '../../data/GameEvent';
- const { ccclass, property } = _decorator;
- @ccclass('MailItem')
- export class MailItem extends ResKeeper {
- @property({ type: Node, tooltip: "邮件状态" })
- awardBg: Node = null;
- @property({ type: Node, tooltip: "奖励节点" })
- awardNode: Node = null;
- @property({ type: Label, tooltip: "邮件标题" })
- titleTx: Label = null;
- @property({ type: Label, tooltip: "邮件时间" })
- timeTx: Label = null;
- @property({ type: Node, tooltip: "已读状态" })
- readIco: Node = null;
- @property({ type: Label, tooltip: "已读状态文字" })
- readIcoTx: Label = null;
- @property({ type: Node, tooltip: "附件" })
- awardTips: Node = null;
- @property({ type: Label, tooltip: "附件文字" })
- awardTipsTx: Label = null;
- @property({ type: Node, tooltip: "已读遮罩" })
- maskImg: Node = null;
- private data = null;
- protected onLoad() {
- this.readIcoTx.string = StringUtil.getLanguageData('已读');
- this.awardTipsTx.string = StringUtil.getLanguageData('附件');
- }
- refreshItem(data) {
- this.data = data;
- this.titleTx.string = MailData.getMailText(data.title,true);
- this.maskImg.active = false;
- this.readIco.active = false;
- let date = new Date(data.time);
- let Y = date.getFullYear() + '-';
- let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
- let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + '';
- this.timeTx.string = Y + M + D;
- if (data.award && data.award.size > 0) {
- this.awardTips.active = false;
- let showAward = MailData.getShowAward(data.id)
- if (showAward) {
- this.awardBg.active = false;
- this.awardNode.active = true;
- } else {
- this.awardBg.active = true;
- this.awardNode.active = false;
- this.load('mail', 'texture/mail_3/spriteFrame', SpriteFrame, (res: SpriteFrame) => {
- this.awardBg.getComponent(Sprite).spriteFrame = res;
- })
- }
- } else {
- this.awardBg.active = true;
- this.awardNode.active = false;
- this.awardTips.active = false;
- this.load('mail', 'texture/mail_3/spriteFrame', SpriteFrame, (res: SpriteFrame) => {
- this.awardBg.getComponent(Sprite).spriteFrame = res;
- })
- }
- if (data.read == 1) {
- this.awardBg.active = true;
- this.awardNode.active = false;
- this.awardTips.active = false;
- this.readIco.active = true;
- this.maskImg.active = true;
- this.load('mail', 'texture/mail_2/spriteFrame', SpriteFrame, (res: SpriteFrame) => {
- this.awardBg.getComponent(Sprite).spriteFrame = res;
- })
- }
- }
- protected onDestroy() {
- super.onDestroy();
- }
- onClose() {
- }
- //UI事件处理
- private onTouchButton(event: Event) {
- let target: any = event.target;
- if (target.name == 'bg') {
- if (this.data.read == 1) {
- console.log('=============== aa')
- Framework.layer.open(ViewID.MailDetail, null, this.data);
- return;
- }
- if (this.data.award && this.data.award.size > 0) {
- console.log('=============== bb')
- Framework.layer.open(ViewID.MailDetail, null, this.data);
- } else {
- LoginMgr.sendPost('user', 'read_mail', (data) => {
- console.log(data);
- MailData.setMailReadById(data.id)
- // Framework.event.fireEvent(GameEvent.MailUpdate);
- Framework.layer.open(ViewID.MailDetail, null, this.data);
- }, { id: this.data.id })
- }
- }
- }
- }
|