| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- 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<void> {
- this._tier = _params?.tier;
- this._gear = _params?.gear;
- this._index = _params?.index;
- this.updateView();
- }
- protected onCreate(): void | Promise<void> {
- 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;
- }
- }
|