CompanySaleTipPanel.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. var ItemType = require("ItemType");
  2. var TempBonus = require("TempBonus");
  3. var CompanySaleTipPanel = cc.Class({
  4. extends: cc.Component,
  5. properties: {
  6. Atlas:cc.SpriteAtlas,
  7. IconSp:cc.Sprite,
  8. TitleName:cc.Sprite,
  9. SaleNumLbl:cc.Label,
  10. EarnLbl:cc.Label,
  11. Slider:cc.Slider,
  12. InPutBox:cc.EditBox,
  13. Progress:cc.ProgressBar,
  14. SaleNum:0,
  15. Data:null,
  16. },
  17. ShowPanel:function (data) {
  18. this.Data = data;
  19. this.IconSp.spriteFrame = this.Atlas.getSpriteFrame(data.icon);
  20. this.TitleName.spriteFrame = this.Atlas.getSpriteFrame(data.name);
  21. var data = cc.Mgr.UserDataMgr.getDataByItemTypeAndId(ItemType.Company,this.Data.Id);
  22. var marketPrice = data.stockPrice;
  23. var cost = data.stockCost;
  24. this.SaleNum = Math.floor(this.Data.stockNum / 100);
  25. var money = Math.floor(this.Data.stockNum * (marketPrice - cost));
  26. if(cc.Mgr.global.TempAdsStockBonus == TempBonus.StockBonus)
  27. {
  28. if(money > 0)
  29. money = Math.floor(money * 1.2); //有之前看过广告
  30. }
  31. this.EarnLbl.string = cc.Mgr.global.FormatNum(money);
  32. this.SaleNumLbl.string = this.SaleNum;
  33. this.InPutBox.string = this.SaleNum;
  34. this.Slider.progress = 1;
  35. this.Progress.progress = 1;
  36. },
  37. OnSliderChange:function(){
  38. this.SaleNum = Math.floor(this.Slider.progress * (this.Data.stockNum / 100));
  39. this.Progress.progress = this.Slider.progress;
  40. var data = cc.Mgr.UserDataMgr.getDataByItemTypeAndId(ItemType.Company,this.Data.Id);
  41. var marketPrice = data.stockPrice;
  42. var cost = data.stockCost;
  43. var money = Math.floor(this.SaleNum * 100 * (marketPrice - cost));
  44. if(cc.Mgr.global.TempAdsStockBonus == TempBonus.StockBonus)
  45. {
  46. if(money > 0)
  47. money = Math.floor(money *1.2); //有之前看过广告
  48. }
  49. this.EarnLbl.string = cc.Mgr.global.FormatNum(money);
  50. this.SaleNumLbl.string = this.SaleNum;
  51. this.InPutBox.string = this.SaleNum;
  52. },
  53. OnInputBoxEnd:function(){
  54. if(this.InPutBox.string != "")
  55. {
  56. if(Number(this.InPutBox.string) != null)
  57. {
  58. if(Number(this.InPutBox.string) > Math.floor(this.Data.stockNum / 100))
  59. {
  60. this.InPutBox.string = Math.floor(this.Data.stockNum / 100);
  61. this.SaleNum = Math.floor(this.Data.stockNum / 100);
  62. this.Progress.progress = 1;
  63. this.Slider.progress = 1;
  64. }
  65. else
  66. {
  67. this.SaleNum = Number(this.InPutBox.string);
  68. this.Slider.progress = Math.floor(this.SaleNum / (this.Data.stockNum / 100));
  69. this.Progress.progress = this.Slider.progress;
  70. }
  71. }
  72. }
  73. else
  74. {
  75. this.InPutBox.string = "0";
  76. this.SaleNum = 0;
  77. this.Progress.progress = 0;
  78. this.Slider.progress = 0;
  79. }
  80. var data = cc.Mgr.UserDataMgr.getDataByItemTypeAndId(ItemType.Company,this.Data.Id);
  81. var marketPrice = data.stockPrice;
  82. var cost = data.stockCost;
  83. var money = Math.floor(this.SaleNum * 100 * (marketPrice - cost));
  84. if(cc.Mgr.global.TempAdsStockBonus == TempBonus.StockBonus)
  85. {
  86. if(money > 0)
  87. money = Math.floor(money *1.2); //有之前看过广告
  88. }
  89. this.EarnLbl.string = cc.Mgr.global.FormatNum(money);
  90. },
  91. ClickSaleBtn:function(){
  92. if(this.SaleNum <= 0)
  93. {
  94. cc.Mgr.AudioMgr.playSFX("click");
  95. return;
  96. }
  97. var data = cc.Mgr.UserDataMgr.getDataByItemTypeAndId(ItemType.Company,this.Data.Id);
  98. var marketPrice = data.stockPrice;
  99. var cost = data.stockCost;
  100. var getMoney = Math.floor(marketPrice * this.SaleNum * 100);
  101. if(cc.Mgr.global.TempAdsStockBonus == TempBonus.StockBonus)
  102. {
  103. var money = this.SaleNum * (marketPrice - cost);
  104. if(money > 0)
  105. getMoney = Math.floor(getMoney *1.2); //有之前看过广告
  106. //cc.Mgr.global.TempAdsBonus = TempBonus.NULL;
  107. }
  108. cc.Mgr.UserDataMgr.Cash += getMoney;
  109. var param = {};
  110. param.Num = this.SaleNum * 100;
  111. param.price = marketPrice;
  112. param.Id = this.Data.Id;
  113. var data = cc.Mgr.UserDataMgr.SaleStocks(param);
  114. //通知刷新
  115. cc.director.GlobalEvent.emit(cc.Mgr.Event.SaleStockSuccess, data);
  116. this.ClosePanel();
  117. },
  118. ClosePanel:function(){
  119. cc.Mgr.AudioMgr.playSFX("click");
  120. this.node.active = false;
  121. },
  122. });
  123. module.exports = CompanySaleTipPanel;