import Main from "../../main/Main"; import { __PayData } from "../data/sdata/SManage"; /** * 充值节点 */ const { ccclass, property } = cc._decorator; @ccclass export default class PayShopItem extends cc.Component { @property(cc.Label) mGold: cc.Label = null; @property(cc.Label) mGaveGold: cc.Label = null; @property(cc.Label) mRMB: cc.Label = null; @property(cc.Sprite) icon: cc.Sprite = null; @property(cc.Node) text: cc.Node = null; public callback: (item: PayShopItem) => void public _payData: __PayData public main: Main public init(_payData: __PayData, main: Main) { this._payData = _payData this.main = main; this.mGold.string = '' + _payData.gold this.mGaveGold.string = '+' + _payData.firstGive this.mRMB.string = '$' + _payData.usd this.initIcon(_payData.id); this.showFirstGave(); } public initIcon(id: number) { cc.resources.load('icon/shop/gold/' + id, cc.SpriteFrame, (err, spriteFrame: cc.SpriteFrame) => { if (err) { cc.error(err); } else { this.icon.spriteFrame = spriteFrame; } }); } public isFirstPay() { if (this.main.player.firstPayGave.indexOf(this._payData.id) > -1) { return true; } return false; } public showFirstGave() { this.text.active = !this.isFirstPay(); this.mGaveGold.node.active = !this.isFirstPay(); } public setCallback(callback: (item: PayShopItem) => void) { this.callback = callback } public onclick() { this.callback(this) } }