LeaseSaleInfo.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import gameToast from "../Network/gameToast"
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. saleName: {
  6. default: null,
  7. type: cc.Label,
  8. serializable: true,
  9. },
  10. saleAmount: {
  11. default: null,
  12. type: cc.Label,
  13. serializable: true,
  14. },
  15. inputInviteValue: {
  16. default: 1,
  17. visible: false
  18. },
  19. //当前操作的果实信息
  20. fruitInfo: {
  21. default: null,
  22. serializable: true,
  23. visible: false
  24. },
  25. upTarget: {
  26. default: null,
  27. type: cc.Node,
  28. tooltip: "把当前操作的ui按钮传进来"
  29. },
  30. inputContainer: {
  31. default: null,
  32. type: cc.Node,
  33. tooltip: "inputEditbox"
  34. },
  35. },
  36. inputValue(value, e) {
  37. var numberTemp = new RegExp("^[A-Za-z0-9]+$");
  38. if (numberTemp.test(value)) {
  39. if (Number(value) >= 1) {
  40. this.inputInviteValue = Number(value);
  41. } else {
  42. this.inputInviteValue = 1;
  43. this.inputContainer.getComponent(cc.EditBox).string = this.inputInviteValue;
  44. }
  45. } else {
  46. this.inputInviteValue = 1;
  47. this.inputContainer.getComponent(cc.EditBox).string = this.inputInviteValue;
  48. console.log("请输入整数的倍数", this.inputInviteValue);
  49. }
  50. },
  51. setInfo(saleName, amount) {
  52. this.saleName.string = saleName;
  53. this.saleAmount.string = amount;
  54. },
  55. onclose() {
  56. this.node.destroy();
  57. },
  58. //确定销售果实
  59. onLeaseSaleFruit() {
  60. //todo 判断一下amount
  61. console.log(this.inputInviteValue, Number(this.saleAmount.string));
  62. if (this.inputInviteValue > Number(this.saleAmount.string)) {
  63. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), "销售的果实数量过多!", 2, () => {
  64. console.log("finish toast!");
  65. });
  66. return;
  67. }
  68. GlobalD.GameData.onSaleFruit({ fruitId: this.fruitInfo.id, amount: this.inputInviteValue }, (res, value) => {
  69. // console.log(value);
  70. if (value.code === 0) {
  71. // let NumLabel = this.upTarget.getComponent("Content_Button").NumLabel.getComponent(cc.Label);
  72. // if (parseInt(NumLabel.string) <= this.inputInviteValue) {
  73. // //这里只隐藏
  74. // this.upTarget.active = false;
  75. // } else {
  76. // NumLabel.string = parseInt(NumLabel.string) - this.inputInviteValue;
  77. // this.saleAmount.string = parseInt(this.saleAmount.string) - this.inputInviteValue;
  78. // }
  79. GlobalD.GameData.SetSNB(GlobalD.GameData.GetSNB() + (this.inputInviteValue*this.fruitInfo.priceSnb));
  80. var BuildingView = cc.find("Canvas/UICamera/BuildingContainer/BuildingView").getComponent("BuildingView");
  81. BuildingView.onUpdateList();
  82. this.saleAmount.string = parseInt(this.saleAmount.string) - this.inputInviteValue;
  83. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), "成功售卖了!", 2, () => {
  84. console.log("finish toast!");
  85. });
  86. } else {
  87. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), value.msg, 2, () => {
  88. console.log("finish toast!");
  89. });
  90. }
  91. });
  92. }
  93. });