import { IGoodsConfig } from '@scripts/store/payStore/data'; import { _decorator, Button, Component, Label, math, Node, Sprite } from 'cc'; import { GoodsValue } from './GoodsValue'; import { formatGoodsNum } from '@scripts/utils/Helper'; import { formatVip } from '@scripts/utils/VipHelper'; import { AppKernel } from '@scripts/app/AppKernel'; import { UIViewID } from '@scripts/define/UIDefine'; import { setGoodsIcon } from '@scripts/utils/ResHelper'; const { ccclass, property } = _decorator; @ccclass('GoodsItem') export class GoodsItem extends Component { @property(Sprite) sptIcon: Sprite; @property(Node) sptFirst: Node; @property(Button) btnPayment: Button; @property(Node) content: Node; @property(Node) infoNode: Node; @property(Node) lblGCOnly: Node; @property(Label) lblMoney: Label; @property(GoodsValue) scValue: GoodsValue; @property(GoodsValue) gcValue: GoodsValue; @property(GoodsValue) vipValue: GoodsValue; public get data() { return this.goods; } private goods: IGoodsConfig; private onClick: (goods: GoodsItem) => void; private get isGCOnly() { return this.goods.sc === 0 && this.goods.cp === 0; } updateItem(goods: IGoodsConfig, index: number, onClick: (goods: GoodsItem) => void) { this.goods = goods; this.onClick = onClick; this.lblMoney.string = `$${goods.money}`; this.sptFirst.active = goods.is_first; this.lblGCOnly.active = this.isGCOnly; setGoodsIcon(this.sptIcon, goods.icon_id, this.isGCOnly); this.scValue.initValue(goods.sc, formatGoodsNum(goods.sc), goods.sc_reward, goods.sc_reward_display_percent, true); this.gcValue.initValue(goods.gc, formatGoodsNum(goods.gc), goods.gc_reward, goods.gc_reward_display_percent); this.vipValue.initValue(goods.cp, formatVip(goods.cp), goods.cp_reward, goods.cp_reward_display_percent); } getIconName(index: number) { const isGCOnly = this.isGCOnly; if (isGCOnly) return "img_icon_gc"; const spIndex = math.clamp(index, 1, 13); return 'img_icon' + spIndex; } onBtnPaymentClick() { this.onClick && this.onClick(this); } }