LeaseSaleInfo.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. },
  31. inputValue(value, e) {
  32. var numberTemp = new RegExp("^[A-Za-z0-9]+$");
  33. if (numberTemp.test(value)) {
  34. if (Number(value) >= 1) {
  35. this.inputInviteValue = Number(value);
  36. } else {
  37. this.inputInviteValue = 1;
  38. this.inputContainer.getComponent(cc.EditBox).string = this.inputInviteValue;
  39. }
  40. } else {
  41. this.inputInviteValue = 1;
  42. this.inputContainer.getComponent(cc.EditBox).string = this.inputInviteValue;
  43. console.log("请输入整数的倍数", this.inputInviteValue);
  44. }
  45. },
  46. setInfo(saleName, amount) {
  47. this.saleName.string = saleName;
  48. this.saleAmount.string = amount;
  49. },
  50. onclose() {
  51. this.node.destroy();
  52. },
  53. //确定销售果实
  54. onLeaseSaleFruit() {
  55. //todo 判断一下amount
  56. console.log(this.inputInviteValue, Number(this.saleAmount.string));
  57. if (this.inputInviteValue > Number(this.saleAmount.string)) {
  58. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), "销售的果实数量过多!", 2, () => {
  59. console.log("finish toast!");
  60. });
  61. return;
  62. }
  63. GlobalD.GameData.onSaleFruit({ fruitId: this.fruitInfo.id, amount: this.inputInviteValue }, (res, value) => {
  64. // console.log(value);
  65. if (value.code === 0) {
  66. let NumLabel = this.upTarget.getComponent("Content_Button").NumLabel.getComponent(cc.Label);
  67. if (parseInt(NumLabel.string) <= 1) {
  68. //这里只隐藏
  69. this.upTarget.active = false;
  70. } else {
  71. NumLabel.string = parseInt(NumLabel.string) - this.inputInviteValue;
  72. this.saleAmount.string = parseInt(this.saleAmount.string) - this.inputInviteValue;
  73. }
  74. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), "成功售卖了!", 2, () => {
  75. console.log("finish toast!");
  76. });
  77. } else {
  78. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), value.msg, 2, () => {
  79. console.log("finish toast!");
  80. });
  81. }
  82. });
  83. }
  84. });