ItemPay.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { _decorator, Component, game, Label, Node, Sprite } from 'cc';
  2. import { UtilsPanel } from '../../scene/script/UtilsPanel';
  3. import { ViewItemPro } from '../../scene/script/components/ViewItemPro';
  4. import { nav_info } from '../../scene/script/NavInfo';
  5. import { Pay, ShopData } from './Pay';
  6. import { UtilsFormat } from '../../scene/script/UtilsFormat';
  7. const { ccclass } = _decorator;
  8. @ccclass('ItemPay')
  9. export class ItemPay extends ViewItemPro {
  10. private sp_icon: Sprite = null;
  11. private lb_count: Label = null;
  12. private money = 0;
  13. private gold = 0;
  14. protected onLoad(){
  15. UtilsPanel.getAllNeedCom(this, this.node, false);
  16. UtilsPanel.addBtnEvent(this.node, this.onClick, this);
  17. }
  18. public init(data:any, index: number, p0?: any): void {
  19. let p = Pay.data_shop;
  20. if(index == p.DefaultPrice.length){
  21. this.money = -1;
  22. this.lb_count.string = "أدخل المبلغ";
  23. }
  24. else{
  25. this.money = p.DefaultPrice[index];
  26. this.gold = Pay.clacGold(this.money);
  27. this.lb_count.string = UtilsFormat.formatMoney(this.gold);
  28. }
  29. if(index > 5)index = 5;
  30. UtilsPanel.setItemIcon(nav_info.bundle, "texture/1"+index+"/spriteFrame", this.sp_icon);
  31. }
  32. public onClick(){
  33. if(this.money == -1){
  34. nav_info.scene.showByUrl("prefab/paycustom");
  35. }
  36. else{
  37. game.emit("select_item", this.money, this.gold);
  38. }
  39. }
  40. }