| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- import { AppKernel } from '@scripts/app/AppKernel';
- import { UIViewID } from '@scripts/define/UIDefine';
- import { UIView } from '@scripts/framework/ui/UIView';
- import { formatMailTimeToMMDDYYYY, parseMailRewardStr } from '@scripts/utils/Helper';
- import { addBtnClick, removeBtnClick } from '@scripts/utils/UIHelper';
- import { _decorator, Button, Component, instantiate, Label, Node, UIOpacity } from 'cc';
- const { ccclass, property } = _decorator;
- @ccclass('MailItem')
- export class MailItem extends Component {
- @property(Node)
- private unread: Node = null;
- @property(Node)
- private read: Node = null;
- @property(Label)
- private title: Label = null;
- @property(Label)
- private desc: Label = null;
- @property(Node)
- private item_gc: Node = null;
- @property(Node)
- private item_sc: Node = null;
- @property(Node)
- private reward_layout: Node = null;
- private _mailData: any = {};
- onLoad() {
- // 只绑定一次!
- addBtnClick(this.node, this.handleMailClick, this);
- }
- initItem(mailData: any = {}) {
- this._mailData = mailData;
- this.updateReward();
- this.updateStatus();
- this.updateTxt();
- }
- async handleMailClick() {
- const { MailStatus, MailID } = this._mailData;
- const { mailStore } = AppKernel.stores;
- console.log("handleMailClick", MailID);
- if (MailStatus == "1") {
- await mailStore.reqMailRead(MailID);
- mailStore.reqMailList();
- }
- AppKernel.ui.open(UIViewID.MailDetail, { mailData: this._mailData });
- }
- updateReward() {
- this.reward_layout.removeAllChildren();
- const { BonusString } = this._mailData;
- const rewards = parseMailRewardStr(BonusString);
- rewards?.forEach(item => {
- const node = instantiate(
- item?.type == "30000" ? this.item_sc : this.item_gc
- );
- const num = node.getChildByName("num");
- num.getComponent(Label).string = item?.reward;
- node.active = true;
- node.parent = this.reward_layout;
- })
- }
- updateStatus() {
- const { MailStatus } = this._mailData;
- this.unread.active = MailStatus == "1" ? true : false;
- this.read.active = MailStatus == "1" ? false : true;
- const opacityCmp = this.reward_layout.getComponent(UIOpacity);
- if (MailStatus == "1") {
- opacityCmp.opacity = 255;
- } else if (MailStatus == "2") {
- opacityCmp.opacity = 255 * 0.45;
- } else if (MailStatus == "3") {
- opacityCmp.opacity = 0;
- }
- }
- updateTxt() {
- this.title.string = this._mailData.TitleString;
- this.desc.string = "System " + formatMailTimeToMMDDYYYY(this._mailData.CreateTime);
- }
- }
|