GoodsItem.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { IGoodsConfig } from '@scripts/store/payStore/data';
  2. import { _decorator, Button, Component, Label, math, Node, Sprite } from 'cc';
  3. import { GoodsValue } from './GoodsValue';
  4. import { formatGoodsNum } from '@scripts/utils/Helper';
  5. import { formatVipLv } from '@scripts/utils/VipHelper';
  6. import { AppKernel } from '@scripts/app/AppKernel';
  7. import { UIViewID } from '@scripts/define/UIDefine';
  8. import { setGoodsIcon } from '@scripts/utils/ResHelper';
  9. const { ccclass, property } = _decorator;
  10. @ccclass('GoodsItem')
  11. export class GoodsItem extends Component {
  12. @property(Sprite)
  13. sptIcon: Sprite;
  14. @property(Node)
  15. sptFirst: Node;
  16. @property(Button)
  17. btnPayment: Button;
  18. @property(Node)
  19. content: Node;
  20. @property(Node)
  21. infoNode: Node;
  22. @property(Node)
  23. lblGCOnly: Node;
  24. @property(Label)
  25. lblMoney: Label;
  26. @property(GoodsValue)
  27. scValue: GoodsValue;
  28. @property(GoodsValue)
  29. gcValue: GoodsValue;
  30. @property(GoodsValue)
  31. vipValue: GoodsValue;
  32. public get data() { return this.goods; }
  33. private goods: IGoodsConfig;
  34. private onClick: (goods: GoodsItem) => void;
  35. private get isGCOnly() {
  36. return this.goods.sc === 0 && this.goods.cp === 0;
  37. }
  38. updateItem(goods: IGoodsConfig, index: number, onClick: (goods: GoodsItem) => void) {
  39. this.goods = goods;
  40. this.onClick = onClick;
  41. this.lblMoney.string = `$${goods.money}`;
  42. this.sptFirst.active = goods.is_first;
  43. this.lblGCOnly.active = this.isGCOnly;
  44. setGoodsIcon(this.sptIcon, goods.icon_id, this.isGCOnly);
  45. this.scValue.initValue(goods.sc, formatGoodsNum(goods.sc), goods.sc_reward, goods.sc_reward_display_percent, true);
  46. this.gcValue.initValue(goods.gc, formatGoodsNum(goods.gc), goods.gc_reward, goods.gc_reward_display_percent);
  47. this.vipValue.initValue(goods.cp, formatVipLv(goods.cp), goods.cp_reward, goods.cp_reward_display_percent);
  48. }
  49. getIconName(index: number) {
  50. const isGCOnly = this.isGCOnly;
  51. if (isGCOnly) return "img_icon_gc";
  52. const spIndex = math.clamp(index, 1, 13);
  53. return 'img_icon' + spIndex;
  54. }
  55. onBtnPaymentClick() {
  56. this.onClick && this.onClick(this);
  57. }
  58. }