import { _decorator, Button, Color, EditBox, instantiate, Label, Node, RichText, Sprite, SpriteFrame, UITransform } from 'cc'; import { UIViewID } from '@scripts/define/UIDefine'; import { UICloseReason } from '@scripts/framework/ui/UILayer'; import { addBtnClick } from '@scripts/utils/UIHelper'; import { AppKernel } from '@scripts/app/AppKernel'; import { SelectBox } from '@scripts/components/selectBox/SelectBox'; import { UIPopup } from '@scripts/framework/ui/UIPopup'; import { formatNumShort } from '@scripts/utils/Helper'; import { REWARD_OPEN_TYPE } from '../RewardView/RewardView'; const { ccclass, property } = _decorator; @ccclass('WeeklyPassPurchase') export class WeeklyPassPurchase extends UIPopup { readonly viewId = UIViewID.WeeklyPassPurchase; @property(Node) private icon: Node = null; @property(Label) private desc: Label = null; @property(Node) private rewards: Node = null; @property(Node) private btn_close: Node = null; @property(Node) private btn_buy: Node = null; private _tier: any = {}; private _gear: any = {}; private _index: number = 0; protected onOpen(_params): void | Promise { this._tier = _params?.tier; this._gear = _params?.gear; this._index = _params?.index; this.updateView(); } protected onCreate(): void | Promise { AppKernel.events.on("hall:pay-finished", this.handlePayFinished, this); addBtnClick(this.btn_close, this.onBtnCloseClick, this); addBtnClick(this.btn_buy, this.onBtnBuyClick, this); } private updateView() { const money = this._gear?.money; this.icon?.children?.forEach((node, idx) => node.active = idx === this._index); let str = ``; switch (this._index) { case 0: str = `GOLD PASS -$${money} -7x24H`; break; case 1: str = `SILVER PASS -$${money} -7x24H`; break; case 2: str = `IRON PASS -$${money} -7x24H`; break; } this.desc.string = str; this.btn_buy.getChildByName("label").getComponent(Label).string = `BUY $${money}`; const reward = { sc: this._gear?.sc, gc: this._gear?.gc, cp: this._gear?.cp }; 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); } } } private onBtnCloseClick() { AppKernel.ui.close(this.viewId); } private onBtnBuyClick() { const payServices = AppKernel.services.paymentServices; const formatGear = this.formatGoods(this._gear); payServices.startPayment(formatGear, 0); } private handlePayFinished() { AppKernel.stores.weeklyPassStore.reqWeeklyPassInfo(); const tier = this._tier ?? {}; this.closeSelf(); AppKernel.ui.open(UIViewID.RewardView, { reward: tier?.instant_reward, type: REWARD_OPEN_TYPE.INSTANT }); } private formatGoods(goods: any) { goods.gears = JSON.parse(goods.gear); goods.cp = Number(goods.cp); goods.cp_reward = Number(goods.cp_reward); goods.cp_reward_display_percent = Number(goods.cp_reward_display_percent); goods.gc = Number(goods.gc); goods.gc_reward = Number(goods.gc_reward); goods.gc_reward_display_percent = Number(goods.gc_reward_display_percent); goods.gc_vip_reward = Number(goods.gc_vip_reward); goods.gc_vip_reward_display_percent = Number(goods.gc_vip_reward_display_percent); goods.sc = Number(goods.sc); goods.sc_reward = Number(goods.sc_reward); goods.sc_reward_display_percent = Number(goods.sc_reward_display_percent); return goods; } }