ItemPay.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. index = 99;
  24. }
  25. else{
  26. this.money = p.DefaultPrice[index];
  27. this.gold = Pay.clacGold(this.money);
  28. this.lb_count.string = UtilsFormat.formatMoney(this.gold);
  29. }
  30. if(index > 4 && this.money != -1)index = 4;
  31. UtilsPanel.setItemIcon(nav_info.bundle, "texture/1"+index+"/spriteFrame", this.sp_icon);
  32. }
  33. public onClick(){
  34. if(this.money == -1){
  35. nav_info.scene.showByUrl("prefab/paycustom");
  36. }
  37. else{
  38. game.emit("select_item", this.money, this.node);
  39. }
  40. }
  41. }