LeaseGrantInfo.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import gameToast from "../Network/gameToast"
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. grantName: {
  6. default: null,
  7. type: cc.Label,
  8. serializable: true,
  9. },
  10. amount: {
  11. default: null,
  12. type: cc.Label,
  13. serializable: true,
  14. },
  15. //介绍
  16. describe: {
  17. default: null,
  18. type: cc.Label,
  19. serializable: true,
  20. },
  21. inputAddressValue: {
  22. default: "",
  23. visible: false,
  24. serializable: false
  25. },
  26. inputAmountValue: {
  27. default: 0,
  28. visible: false,
  29. serializable: false
  30. },
  31. inputAmountContainer: {
  32. default: null,
  33. type: cc.Node,
  34. tooltip: "输入果实数量的节点"
  35. },
  36. //当前操作的果实信息
  37. fruitInfo: {
  38. default: null,
  39. serializable: true,
  40. visible: false
  41. },
  42. upTarget: {
  43. default: null,
  44. type: cc.Node,
  45. tooltip: "把当前操作的ui按钮传进来"
  46. },
  47. },
  48. // LIFE-CYCLE CALLBACKS:
  49. // onLoad () {},
  50. // start() {
  51. // },
  52. /**
  53. * 赠送
  54. */
  55. // onGrant() {
  56. // },
  57. setInfo(grantName, amount) {
  58. this.grantName.string = grantName;
  59. this.amount.string = amount;
  60. },
  61. onInputAddressValue(value, e) {
  62. this.inputAddressValue = value;
  63. },
  64. onInputAmountValue(value, e) {
  65. var numberTemp = new RegExp("^[A-Za-z0-9]+$");
  66. if (numberTemp.test(value)) {
  67. if (Number(value) >= 1) {
  68. this.inputAmountValue = Number(value);
  69. } else {
  70. this.inputAmountValue = 0;
  71. this.inputAmountContainer.getComponent(cc.EditBox).string = this.inputAmountValue;
  72. }
  73. } else {
  74. this.inputAmountValue = 0;
  75. this.inputAmountContainer.getComponent(cc.EditBox).string = this.inputAmountValue;
  76. // console.log("请输入整数的倍数", this.inputAmountValue);
  77. }
  78. },
  79. onclose() {
  80. this.node.destroy();
  81. },
  82. //确定增送果实
  83. onLeaseGrantFruit() {
  84. //todo 判断一下amount
  85. console.log(this.inputAddressValue);
  86. if (this.inputAddressValue.length < 20) {
  87. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), "请输入地址!", 1);
  88. return;
  89. }
  90. if (Number(this.inputAmountValue) <= 0) {
  91. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), "请输入赠送的果实数量!", 1);
  92. return;
  93. }
  94. if (Number(this.inputAmountValue) > Number(this.amount.string)) {
  95. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), "输入赠送的果实数量过多!", 1);
  96. return;
  97. }
  98. if (GlobalD.GameData.isOnGrantFruit) return;
  99. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), "赠送果实中...", 5);
  100. //赠送一部分果实
  101. GlobalD.GameData.onGrantFruit({ fruitId: this.fruitInfo.id, amount: this.inputAmountValue, address: this.inputAddressValue }, (value) => {
  102. // console.log(value);
  103. if (value.code === 0) {
  104. // let NumLabel = this.upTarget.getComponent("Content_Button").NumLabel.getComponent(cc.Label);
  105. //这里只隐藏
  106. // this.upTarget.active = false;
  107. // NumLabel.string = 0;
  108. var BuildingView = cc.find("Canvas/UICamera/BuildingContainer/BuildingView").getComponent("BuildingView");
  109. BuildingView.onUpdateList();
  110. this.amount.string = Number(this.amount.string) - this.inputAmountValue;
  111. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), value.msg, 1);
  112. } else {
  113. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), value.msg, 1);
  114. }
  115. });
  116. }
  117. });