import { AppKernel } from '@scripts/app/AppKernel'; import { UIViewID } from '@scripts/define/UIDefine'; import { UIView } from '@scripts/framework/ui/UIView'; import { addBtnClick } from '@scripts/utils/UIHelper'; import { _decorator, Button, Component, Label, Node } from 'cc'; const { ccclass, property } = _decorator; import { UIPopup } from '@scripts/framework/ui/UIPopup'; import { formatMailTimeToMMDDYYYY, parseMailRewardStr } from '@scripts/utils/Helper'; @ccclass('MailDetail') export class MailDetail extends UIPopup { readonly viewId: UIViewID = UIViewID.MailDetail; @property(Node) private btn_close: Node = null; @property(Node) private btn_delete: Node = null; @property(Node) private btn_claim: Node = null; @property(Node) private btn_confirm: Node = null; @property(Label) private title: Label = null; @property(Label) private from: Label = null; @property(Label) private time: Label = null; @property(Label) private content: Label = null; @property(Node) private reward: Node = null; @property(Node) private reward_layout: Node = null; private _mailData: any = {}; protected onOpen(params?: any) { this._mailData = params?.mailData; this.initMailDetail(); } protected onCreate(): void | Promise { addBtnClick(this.btn_close, this.onBtnCloseClick, this); addBtnClick(this.btn_delete, this.onBtnDeleteClick, this); addBtnClick(this.btn_claim, this.onBtnClaimClick, this); addBtnClick(this.btn_confirm, this.onBtnCloseClick, this); } private initMailDetail() { console.log('MailDetail onOpen', this._mailData); const { TitleString, CreateTime, TextString, BonusString, MailStatus } = this._mailData; this.title.string = TitleString; this.from.string = 'From System'; this.time.string = formatMailTimeToMMDDYYYY(CreateTime); this.content.string = TextString; const rewards = parseMailRewardStr(BonusString); const hasReward = rewards.length > 0; if (MailStatus == "1") {//未读 this.btn_claim.active = hasReward ? true : false; this.btn_delete.active = hasReward ? false : true; this.btn_confirm.active = hasReward ? false : true; this.reward.active = hasReward ? true : false; } else if (MailStatus == "2") {//已读 this.btn_claim.active = hasReward ? true : false; this.btn_delete.active = hasReward ? false : true; this.btn_confirm.active = hasReward ? false : true; this.reward.active = hasReward ? true : false; } else if (MailStatus == "3") {//已领取 this.btn_claim.active = false; this.btn_delete.active = true; this.btn_confirm.active = true; this.reward.active = false; } if (hasReward) { this.reward_layout.children.forEach(item => item.active = false); rewards?.forEach(item => { const node = item?.type == "30000" ? this.reward_layout.getChildByName("sc") : this.reward_layout.getChildByName("gc") const num = node.getChildByName("num"); num.getComponent(Label).string = item?.reward; node.active = true; }) } } private onBtnCloseClick() { AppKernel.ui.close(UIViewID.MailDetail); } private async onBtnDeleteClick() { const { MailStatus, MailID, BonusString } = this._mailData; const { mailStore } = AppKernel.stores; const rewards = parseMailRewardStr(BonusString); const hasReward = rewards.length > 0; console.log("handleMailDelete", MailID); if (hasReward && MailStatus < "3") return; await mailStore.reqMailDelete(MailID); mailStore.reqMailList(); this.onBtnCloseClick(); } private async onBtnClaimClick() { const { MailStatus, MailID, BonusString } = this._mailData; const { mailStore } = AppKernel.stores; const rewards = parseMailRewardStr(BonusString); const hasReward = rewards.length > 0; console.log("handleMailClaim", MailID); if (hasReward && MailStatus < "3") { await mailStore.reqMailTake(MailID); mailStore.reqMailList(); } this.onBtnCloseClick(); } }