| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- import { AppKernel } from '@scripts/app/AppKernel';
- import { UIViewID } from '@scripts/define/UIDefine';
- import { UIView } from '@scripts/framework/ui/UIView';
- import { formatMailTimeToMMDDYYYY, formatNumShort, parseMailRewardStr } from '@scripts/utils/Helper';
- import { setOriginalSp, setSpriteFrame } from '@scripts/utils/ResHelper';
- import { addBtnClick, removeBtnClick } from '@scripts/utils/UIHelper';
- import { _decorator, Button, Component, Enum, instantiate, Label, Node, NodePool, Prefab, ProgressBar, Sprite, tween, UIOpacity, UITransform } from 'cc';
- const { ccclass, property } = _decorator;
- @ccclass('RewardItem')
- export class RewardItem extends Component {
- @property(Node)
- private bg: Node = null;
- @property(Node)
- private bg_canClaim: Node = null;
- @property(Label)
- private title: Label = null;
- @property(Node)
- private rewards: Node = null;
- @property(Node)
- private light: Node = null;
- @property(Node)
- private lock: Node = null;
- @property(Node)
- private claimed: Node = null;
- private _data: any = {};
- private _claiming: boolean = false;
- onLoad() {
- // 只绑定一次!
- addBtnClick(this.node, this.handleClaim, this);
- }
- initItem(data: any = {}) {
- this._data = data;
- const { day, purchase_times, status, reward } = this._data;
- this.title.string = `C${purchase_times} . DAY${day}`;
- const claimable = status == "claimable";
- const locked = status == "locked";
- const claimed = status == "claimed";
- const unclaimed = status == "unclaimed";
- this.bg.active = !claimable;
- this.bg_canClaim.active = claimable;
- this.light.active = claimable;
- this.stopLightBlink(this.light);
- if (claimable) this.startLightBlink(this.light);
- this.lock.active = locked;
- this.claimed.active = claimed;
- this.rewards?.children?.forEach(item => item.active = false);
- for (const [key, val] of Object.entries(reward)) {
- const propKey = `prop_${key}`;
- const item = this.rewards.getChildByName(propKey);
- if (!item || val == 0) continue;
- item.active = true;
- const num = item.getChildByName('num');
- const label = num.getComponent(Label);
- if (key == "sc" || key == "gc") {
- // label.string = `${(Number(val) / 100).toFixed(2)}`;
- label.string = formatNumShort(String(val), 999);
- } else {
- // label.string = `${val}`;
- label.string = formatNumShort(String(val), 999, 1);
- }
- }
- }
- async handleClaim() {
- if (this._claiming) return;
- this._claiming = true;
- const { day, subscription_id } = this._data;
- const payload = {
- day,
- subscription_id
- }
- try {
- const res = await AppKernel.stores.weeklyPassStore.reqWeeklyPassClaim(payload) as any;
- console.log("reqWeeklyPassClaim", res);
- if (res) AppKernel.ui.open(UIViewID.WeeklyPassClaim, { data: res });
- } finally {
- this._claiming = false;
- }
- }
- startLightBlink(lightNode: Node) {
- const uiOpacity = lightNode.getComponent(UIOpacity) || lightNode.addComponent(UIOpacity);
- // 先重置初始透明度
- uiOpacity.opacity = 255;
- tween(uiOpacity)
- .to(0.6, { opacity: 0 })
- .to(0.6, { opacity: 255 })
- .union()
- .repeatForever() // 无限循环闪烁
- .start();
- }
- // 停止闪烁
- stopLightBlink(lightNode: Node) {
- const uiOpacity = lightNode.getComponent(UIOpacity);
- if (!uiOpacity) return;
- tween(uiOpacity).stop();
- uiOpacity.opacity = 255; // 恢复不透明
- }
- }
|