| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- /**
- * 租赁
- */
- 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);
- }
- 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
- let _configLandInfo = this.leaseFarmlandInfoNode.getComponent("LeaseFarmlandInfo").configLandInfo
- let payType = 0;
- switch (this.toggleInputValue) {
- case "1":
- payType = 1;
- break;
- case "2":
- payType = 5;
- break;
- case "3":
- payType = 6;
- break;
- default:
- console.error("this.toggleInputValue 不是1 2 3!", this.toggleInputValue);
- break;
- }
- if(0 === payType){
- console.log('选择租赁日错误:' + this.totalPriceValue + " == " + payType);
- }
- GlobalD.GameData.payCNT(this.totalPriceValue, payType, _configLandInfo.id, (data) => {
- console.log("土地支付:", this.totalPriceValue, "== playType=", 1, ",item_type==", _configLandInfo.id);
- console.log("支付data:", data);
- const [err, tx] = data;
- if (err === null) {
- // TODO 成功, 支付为链上操作,需要提供回调接口给这边服务端确认交易成功后修改购买订单结果
- console.log(tx) // 交易hash,唯一标识符
- //解锁土地操作
- this.leaseFarmlandInfoNode.getComponent("LeaseFarmlandInfo").onUnlockLand();
- this.onClose();
- } 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)
- // }
- // })
- },
- onClose() {
- this.node.destroy();
- },
- });
|