CompanyBuyTipPanel.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. var CompanyBuyTipPanel = cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. Atlas:cc.SpriteAtlas,
  5. IconSp:cc.Sprite,
  6. TitleName:cc.Sprite,
  7. BuyNumLbl:cc.Label,
  8. DesLbl:cc.Label,
  9. Slider:cc.Slider,
  10. InPutBox:cc.EditBox,
  11. Progress:cc.ProgressBar,
  12. BuyNum:0,
  13. Data:null,
  14. },
  15. ShowPanel:function (data) {
  16. this.Data = data;
  17. this.IconSp.spriteFrame = this.Atlas.getSpriteFrame(data.icon);
  18. this.TitleName.spriteFrame = this.Atlas.getSpriteFrame(data.name);
  19. this.BuyNum = Math.floor(cc.Mgr.UserDataMgr.Cash / (this.Data.stockPrice * 100));
  20. var money = Math.floor(this.BuyNum * 100 * this.Data.stockPrice);
  21. this.DesLbl.string = cc.Mgr.global.FormatNum(money);
  22. this.BuyNumLbl.string = this.BuyNum;
  23. this.InPutBox.string = this.BuyNum;
  24. this.Slider.progress = 1;
  25. this.Progress.progress = 1;
  26. },
  27. ClickBuyBtn:function(){
  28. if(this.BuyNum <= 0)
  29. {
  30. cc.Mgr.AudioMgr.playSFX("click");
  31. return;
  32. }
  33. cc.Mgr.UserDataMgr.Cash -= Math.floor(this.Data.stockPrice * (this.BuyNum * 100));
  34. var param = {};
  35. param.Num = this.BuyNum * 100;
  36. param.price = this.Data.stockPrice;
  37. param.Id = this.Data.Id;
  38. var data = cc.Mgr.UserDataMgr.BuyStocks(param);
  39. //通知刷新现金
  40. cc.director.GlobalEvent.emit(cc.Mgr.Event.BuyStockSuccess, data);
  41. this.ClosePanel();
  42. },
  43. OnSliderChange:function(){
  44. this.BuyNum = Math.floor(this.Slider.progress * cc.Mgr.UserDataMgr.Cash / (this.Data.stockPrice * 100));
  45. this.Progress.progress = this.Slider.progress;
  46. this.DesLbl.string = cc.Mgr.global.FormatNum(Math.floor(this.BuyNum * this.Data.stockPrice * 100));
  47. this.BuyNumLbl.string = this.BuyNum;
  48. this.InPutBox.string = this.BuyNum;
  49. },
  50. OnInputBoxEnd:function(){
  51. var MaxNum = Math.floor(cc.Mgr.UserDataMgr.Cash / (this.Data.stockPrice * 100));
  52. if(this.InPutBox.string != "")
  53. {
  54. if(Number(this.InPutBox.string) != null)
  55. {
  56. if(Number(this.InPutBox.string) > MaxNum)
  57. {
  58. this.InPutBox.string = MaxNum;
  59. this.BuyNum = MaxNum;
  60. this.Progress.progress = 1;
  61. this.Slider.progress = 1;
  62. }
  63. else
  64. {
  65. this.BuyNum = Number(this.InPutBox.string);
  66. this.Slider.progress = this.BuyNum / MaxNum;
  67. this.Progress.progress = this.Slider.progress;
  68. }
  69. }
  70. }
  71. else
  72. {
  73. this.InPutBox.string = "0";
  74. this.BuyNum = 0;
  75. this.Progress.progress = 0;
  76. this.Slider.progress = 0;
  77. }
  78. this.DesLbl.string = cc.Mgr.global.FormatNum(Math.floor(this.BuyNum * this.Data.stockPrice * 100));
  79. },
  80. ClosePanel:function(){
  81. cc.Mgr.AudioMgr.playSFX("click");
  82. this.node.active = false;
  83. },
  84. });
  85. module.exports = CompanyBuyTipPanel;