CompanyStruct.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //公司
  2. var CompanyStruct = cc.Class({
  3. name:"CompanyStruct",
  4. properties:{
  5. icon:"",
  6. name:"",
  7. Id:cc.Integer,
  8. LimitYear:cc.Integer, //交易收益开发年限
  9. isOwned:false,
  10. bonusRatio:0.02,//收益回报率
  11. stockNum:cc.Integer, //股票数量
  12. stockCost:0.00,//股票成本
  13. bankruptPrice:0.00, //破产价格
  14. stockPrice:15.25,//股票单价
  15. },
  16. //创办或者购买完成后
  17. RefreshDataAfterOper:function (data) {
  18. var allAss = (this.stockCost * this.stockNum) + (data.price * data.Num);
  19. this.stockNum += data.Num;
  20. this.stockCost = Math.floor(allAss / this.stockNum * 100)/100;
  21. this.stockPrice = data.price
  22. if(this.stockNum > 0)
  23. this.isOwned = true;
  24. else
  25. this.isOwned = false;
  26. cc.Mgr.UserDataMgr.hasCompany = true;
  27. var param = {};
  28. param.Id = this.Id;
  29. param.stockNum = this.stockNum;
  30. param.stockPrice = this.stockPrice;
  31. param.stockCost = this.stockCost;
  32. return param;
  33. },
  34. //出售操作刷新
  35. RefreshDataAfterSale:function (data) {
  36. this.stockNum -= data.Num;
  37. this.stockPrice = data.price
  38. if(this.stockNum > 0)
  39. {
  40. this.isOwned = true;
  41. cc.Mgr.UserDataMgr.hasCompany = true;
  42. }
  43. else
  44. {
  45. //cc.log("破产或者卖光了");
  46. this.stockCost = 0;//全部賣光
  47. cc.Mgr.UserDataMgr.hasCompany = false;
  48. cc.Mgr.UserDataMgr.CanGetStockProfit = false;
  49. this.isOwned = false;
  50. }
  51. var param = {};
  52. param.Id = this.Id;
  53. param.stockNum = this.stockNum;
  54. param.stockPrice = this.stockPrice;
  55. param.stockCost = this.stockCost;
  56. return param;
  57. },
  58. //离婚后操作刷新
  59. RefreshDataAfterDisvorce:function () {
  60. this.stockNum = Math.floor(this.stockNum * 0.8);
  61. },
  62. });
  63. module.exports = CompanyStruct;