/** * 租赁 */ import gameToast from "../Network/gameToast" cc.Class({ extends: cc.Component, properties: { inputInviteValue: { default: 1, visible: false }, //1 对应3个月,2对应1年,3对应5年 toggleInputValue: { default: '1', visible: false }, totalPriceLabel: { default: null, type: cc.Label, serializable: true }, totalPriceValue: { default: 0, visible: false }, ToastParent: { default: null, type: cc.Node, serializable: true }, //输入节点 inputContainer: { default: null, type: cc.Node, serializable: true }, toggle1: { default: null, type: cc.Toggle, serializable: true }, toggle2: { default: null, type: cc.Toggle, serializable: true }, toggle3: { default: null, type: cc.Toggle, serializable: true }, //这个显示的时候,拦截输入 blockInput: { default: null, type: cc.Node, serializable: true }, leaseFarmlandInfoNode: { default: null, type: cc.Node, serializable: true, visible:false, toolTip:"操作的土地对象,初始化时候传入" } }, // LIFE-CYCLE CALLBACKS: // onLoad () {}, // start() { // }, onOpenInfo() { this.node.active = true; }, //初始化时候需要初始化一次默认值 onToggleInput(value, evnentData) { // console.log(value.isChecked, evnentData); this.toggleInputValue = evnentData; this._updatePrice(); }, inputLeaseValue(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); // gameToast.getInstance().show(this.ToastParent, "请输入整数的倍数", 2, () => { // console.log("finish toast!"); // }, this); } this._updatePrice(); }, _updatePrice() { //this.inputInviteValue 默认是1倍 // console.log( this.inputInviteValue); switch (this.toggleInputValue) { case "1": this.totalPriceValue = 700 * this.inputInviteValue; this.totalPriceLabel.string = this.totalPriceValue + "CNT"; break; case "2": this.totalPriceValue = 2500 * this.inputInviteValue; this.totalPriceLabel.string = this.totalPriceValue + "CNT"; break; case "3": this.totalPriceValue = 5000 * this.inputInviteValue; this.totalPriceLabel.string = this.totalPriceValue + "CNT"; break; default: console.error("this.toggleInputValue 不是1 2 3!", this.toggleInputValue); break; } }, /** * 显示面板时候,设置一下初始化数据 */ onInitLeaseInfo(multiple){ //这里处理倍数 this.inputInviteValue = multiple; this.inputContainer.getComponent(cc.EditBox).string = this.inputInviteValue; this._updatePrice(); }, //租赁支付 onLeaseInfo() { console.log('支付总额:' + this.totalPriceValue); if (!GlobalD.dapp) { console.error("onBindInviteInfo warn,dapp未初始化!"); return; } let _self = this; //cntAmount,payType,itemType,callback Global.game.payCNT(this.totalPriceValue, 1, this.toggleInputValue, (data) => { console.log("土地支付", this.totalPriceValue, "==", 1, "==", this.toggleInputValue); console.log("支付data:", data); gameToast.getInstance().show(this.ToastParent, "支付成功!", 3, () => { console.log("finish toast!"); }, this); if (err === null) { // TODO 成功, 支付为链上操作,需要提供回调接口给这边服务端确认交易成功后修改购买订单结果 console.log(tx) // 交易hash,唯一标识符 //解锁土地操作 this.leaseFarmlandInfoNode.getComponent("LeaseFarmlandInfo").onUnlockLand(); } else { console.log(err) } }); // GlobalD.dapp.bindParent(_self.inputInviteValue).then((data) => { // if (data.err === null) { // // 返回成功,见下面消息体 // console.log(data.res) // //绑定成功时候,隐藏输入框,设置父节点 // GlobalD.Dapp.UserInfo.parent = data.res; // _self.parentInviteValue.string = GlobalD.Dapp.UserInfo.parent.invite_code; // //如果存在父节点,隐藏输入框 // _self.inputContainer.active = false; // } else { // //TODO 服务错误 // console.log(data.err) // gameToast.getInstance().show(_self.ToastParent, "绑定失败!", 3, () => { // console.log("finish toast!"); // }, _self); // } // }) }, onClose() { this.node.destroy(); }, });