import { checkResponse } from '@scripts/api/ApiHelper'; import { AppKernel } from '@scripts/app/AppKernel'; import { UIPopup } from '@scripts/framework/ui/UIPopup'; import { IFirstPack } from '@scripts/store/payStore/data'; import { formatGCNum, formatSCNum } from '@scripts/utils/Helper'; import { addBtnClick } from '@scripts/utils/UIHelper'; import { formatVipLv } from '@scripts/utils/VipHelper'; import { _decorator, Button, Component, find, instantiate, Label, Node } from 'cc'; const { ccclass, property } = _decorator; @ccclass('UIFirstPack') export class UIFirstPack extends UIPopup { @property(Label) lblGC: Label; @property(Label) lblSC: Label; @property(Label) lblVIP: Label; @property(Label) lblButton: Label; @property(Button) btnClose: Button; @property(Button) btnPay: Button; @property(Node) btnDisabled: Node; @property(Label) lblDisabled: Label; @property(Node) testGears: Node; private _packInfo: IFirstPack; protected onCreate(): void | Promise { addBtnClick(this.btnClose, this.closeSelf, this); addBtnClick(this.btnPay, this.onBtnPayClick, this); } protected async onBeforeOpen(_params: unknown) { const payStore = AppKernel.stores.payStore; const res = await payStore.reqFirstPackInfo(); if (!checkResponse(res)) return false; this._packInfo = res.data; return !!res.data; } private onBtnPayClick() { } protected onOpen(_params: unknown): void | Promise { const data = this._packInfo?.list?.[0]; if (!this._packInfo || !data) { this.lblGC.string = ""; this.lblSC.string = ""; this.lblVIP.string = ""; this.btnDisabled.active = true; return; } const gc = data.gc + data.gc_reward; const sc = data.sc + data.sc_reward; const cp = data.cp + data.cp_reward; this.lblGC.string = formatGCNum(gc); this.lblSC.string = formatSCNum(sc); this.lblVIP.string = cp.toString(); const btn_str = AppKernel.i18n.t("store.buynow", Number(data.money)); this.lblButton.string = btn_str; this.lblDisabled.string = btn_str; this.btnDisabled.active = data.purchased; //// Test if (!data.purchased) { for (let i = 0; i < data.gears.length; ++i) { const gearIdx = i; const gear = data.gears[i]; const gearPrefab = find("Button", this.testGears); const gearItem = instantiate(gearPrefab); gearItem.parent = this.testGears; gearItem.active = true; const lblName = find("Label", gearItem).getComponent(Label); lblName.string = gear.name; addBtnClick(gearItem, () => { const payServices = AppKernel.services.paymentServices; payServices.startPayment(data, gearIdx); }) } } } }