LeaseSaleInfo.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. // gameToast.getInstance().show(this.ToastParent, "请输入整数的倍数", 2, () => {
  45. // console.log("finish toast!");
  46. // }, this);
  47. }
  48. },
  49. setInfo(saleName, amount) {
  50. this.saleName.string = saleName;
  51. this.saleAmount.string = amount;
  52. },
  53. onclose() {
  54. this.node.destroy();
  55. },
  56. //确定销售果实
  57. onLeaseSaleFruit() {
  58. //todo 判断一下amount
  59. console.log(this.inputInviteValue, Number(this.saleAmount.string));
  60. if (this.inputInviteValue > Number(this.saleAmount.string)) {
  61. gameToast.getInstance().show(cc.find('Canvas/UICamera'), "销售的果实数量过多!", 2, () => {
  62. console.log("finish toast!");
  63. }, this);
  64. return;
  65. }
  66. GlobalD.GameData.onSaleFruit({ fruitId: this.fruitInfo.id, amount: this.inputInviteValue }, (res, value) => {
  67. // console.log(value);
  68. if (value.code === 0) {
  69. let NumLabel = this.upTarget.getComponent("Content_Button").NumLabel.getComponent(cc.Label);
  70. if (parseInt(NumLabel.string) <= 1) {
  71. //这里只隐藏
  72. this.upTarget.active = false;
  73. } else {
  74. NumLabel.string = parseInt(NumLabel.string) - this.inputInviteValue;
  75. this.saleAmount.string = parseInt(this.saleAmount.string) - this.inputInviteValue;
  76. }
  77. gameToast.getInstance().show(cc.find('Canvas/UICamera'), "售卖成功!", 2, () => {
  78. console.log("finish toast!");
  79. }, this);
  80. } else {
  81. gameToast.getInstance().show(cc.find('Canvas/UICamera'), value.msg, 2, () => {
  82. console.log("finish toast!");
  83. }, this);
  84. }
  85. });
  86. }
  87. });