| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- import gameToast from "../Network/gameToast"
- cc.Class({
- extends: cc.Component,
- properties: {
- saleName: {
- default: null,
- type: cc.Label,
- serializable: true,
- },
- saleAmount: {
- default: null,
- type: cc.Label,
- serializable: true,
- },
- inputInviteValue: {
- default: 1,
- visible: false
- },
- //当前操作的果实信息
- fruitInfo: {
- default: null,
- serializable: true,
- visible: false
- },
- upTarget: {
- default: null,
- type: cc.Node,
- tooltip: "把当前操作的ui按钮传进来"
- },
- },
- inputValue(value, e) {
- var numberTemp = new RegExp("^[A-Za-z0-9]+$");
- if (numberTemp.test(value)) {
- if (Number(value) >= 1) {
- this.inputInviteValue = Number(value);
- } else {
- this.inputInviteValue = 1;
- this.inputContainer.getComponent(cc.EditBox).string = this.inputInviteValue;
- }
- } else {
- this.inputInviteValue = 1;
- this.inputContainer.getComponent(cc.EditBox).string = this.inputInviteValue;
- console.log("请输入整数的倍数", this.inputInviteValue);
- }
- },
- setInfo(saleName, amount) {
- this.saleName.string = saleName;
- this.saleAmount.string = amount;
- },
- onclose() {
- this.node.destroy();
- },
- //确定销售果实
- onLeaseSaleFruit() {
- //todo 判断一下amount
- console.log(this.inputInviteValue, Number(this.saleAmount.string));
- if (this.inputInviteValue > Number(this.saleAmount.string)) {
- GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), "销售的果实数量过多!", 2, () => {
- console.log("finish toast!");
- });
- return;
- }
- GlobalD.GameData.onSaleFruit({ fruitId: this.fruitInfo.id, amount: this.inputInviteValue }, (res, value) => {
- // console.log(value);
- if (value.code === 0) {
- let NumLabel = this.upTarget.getComponent("Content_Button").NumLabel.getComponent(cc.Label);
- if (parseInt(NumLabel.string) <= 1) {
- //这里只隐藏
- this.upTarget.active = false;
- } else {
- NumLabel.string = parseInt(NumLabel.string) - this.inputInviteValue;
- this.saleAmount.string = parseInt(this.saleAmount.string) - this.inputInviteValue;
- }
- GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), "成功售卖了!", 2, () => {
- console.log("finish toast!");
- });
- } else {
- GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), value.msg, 2, () => {
- console.log("finish toast!");
- });
- }
- });
- }
- });
|