GoodsItem.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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.vipValue.initValue(goods.cp, goods.cp_reward, goods.cp_reward_display_percent);
  46. this.scValue.initValue(goods.sc, goods.sc_reward, goods.sc_reward_display_percent, true);
  47. this.gcValue.initValue(goods.gc,
  48. goods.gc_reward + goods.gc_vip_reward,
  49. goods.gc_reward_display_percent + goods.gc_vip_reward_display_percent);
  50. }
  51. getIconName(index: number) {
  52. const isGCOnly = this.isGCOnly;
  53. if (isGCOnly) return "img_icon_gc";
  54. const spIndex = math.clamp(index, 1, 13);
  55. return 'img_icon' + spIndex;
  56. }
  57. onBtnPaymentClick() {
  58. this.onClick && this.onClick(this);
  59. }
  60. }