|
|
@@ -81,6 +81,26 @@ cc.Class({
|
|
|
default: null,
|
|
|
type: cc.Node,
|
|
|
},
|
|
|
+
|
|
|
+ //购买种类数值
|
|
|
+ toggleInputValue: {
|
|
|
+ default: '1',
|
|
|
+ visible: false
|
|
|
+ },
|
|
|
+ PayCNTPopViewNameLabel: {
|
|
|
+ default: null,
|
|
|
+ type: cc.Label,
|
|
|
+ },
|
|
|
+ PayCNTPopViewPriceLabel: {
|
|
|
+ default: null,
|
|
|
+ type: cc.Label,
|
|
|
+ },
|
|
|
+ PayCNTPopViewMutureDurLabel: {
|
|
|
+ default: null,
|
|
|
+ type: cc.Label,
|
|
|
+ },
|
|
|
+
|
|
|
+ isPlaying: false,
|
|
|
},
|
|
|
HiddenAll() {
|
|
|
if (this.Seed.active)
|
|
|
@@ -214,8 +234,17 @@ cc.Class({
|
|
|
node.setSiblingIndex(dst);
|
|
|
}
|
|
|
},
|
|
|
+ OpentSNBExchangeToCNT() {
|
|
|
+ //更新数据
|
|
|
+ this.snbAmountLabel.string = GlobalD.GameData.SNB;
|
|
|
+ this.ExchangePopView.active = true;
|
|
|
+ },
|
|
|
SNBExchangeToCNT() {
|
|
|
GlobalD.GameData.onSnbToCnt(this.snbAmount, (data) => {
|
|
|
+
|
|
|
+ //更新数据
|
|
|
+ this.snbAmountLabel.string = GlobalD.GameData.SNB;
|
|
|
+
|
|
|
this.ExchangePopView.active = false;
|
|
|
console.log('data=', data)
|
|
|
// console.log('res=', res)
|
|
|
@@ -225,9 +254,14 @@ cc.Class({
|
|
|
this.buySeedIndex = myIndex;
|
|
|
this.PayCNTPopView.active = true;
|
|
|
// console.log('this.mySeedList[this.buySeedIndex] =',this.mySeedList[this.buySeedIndex])
|
|
|
- this.PayCNTPopView.getChildByName("BG").getChildByName("BG1_sprite_splash").getChildByName("NameLabel").getChildByName("label").getComponent(cc.Label).string = this.mySeedList[this.buySeedIndex].name;
|
|
|
- this.PayCNTPopView.getChildByName("BG").getChildByName("BG1_sprite_splash").getChildByName("PriceLabel").getChildByName("label").getComponent(cc.Label).string = this.mySeedList[this.buySeedIndex].priceCnt + ' CNT';
|
|
|
- this.PayCNTPopView.getChildByName("BG").getChildByName("BG1_sprite_splash").getChildByName("MutureDurLabel").getChildByName("label").getComponent(cc.Label).string = this.mySeedList[this.buySeedIndex].maturity;
|
|
|
+ // this.PayCNTPopView.getChildByName("BG").getChildByName("BG1_sprite_splash").getChildByName("NameLabel").getChildByName("label").getComponent(cc.Label).string = this.mySeedList[this.buySeedIndex].name;
|
|
|
+ // this.PayCNTPopView.getChildByName("BG").getChildByName("BG1_sprite_splash").getChildByName("PriceLabel").getChildByName("label").getComponent(cc.Label).string = this.mySeedList[this.buySeedIndex].priceCnt + ' CNT';
|
|
|
+ // this.PayCNTPopView.getChildByName("BG").getChildByName("BG1_sprite_splash").getChildByName("MutureDurLabel").getChildByName("label").getComponent(cc.Label).string = this.mySeedList[this.buySeedIndex].maturity;
|
|
|
+ this._updatePrice();
|
|
|
+ // this.PayCNTPopViewNameLabel.string = this.mySeedList[this.buySeedIndex].name;
|
|
|
+ // this.PayCNTPopViewPriceLabel.string = this.mySeedList[this.buySeedIndex].priceCnt + ' CNT';
|
|
|
+ // this.PayCNTPopViewMutureDurLabel.string = this.mySeedList[this.buySeedIndex].maturity;
|
|
|
+
|
|
|
},
|
|
|
onPaySNBPopView(myIndex) {
|
|
|
this.buySeedIndex = myIndex;
|
|
|
@@ -236,6 +270,7 @@ cc.Class({
|
|
|
this.PaySNBPopView.getChildByName("BG").getChildByName("BG1_sprite_splash").getChildByName("NameLabel").getChildByName("label").getComponent(cc.Label).string = this.mySeedList[this.buySeedIndex].name;
|
|
|
this.PaySNBPopView.getChildByName("BG").getChildByName("BG1_sprite_splash").getChildByName("PriceLabel").getChildByName("label").getComponent(cc.Label).string = this.mySeedList[this.buySeedIndex].priceCnt + ' SNB';
|
|
|
this.PaySNBPopView.getChildByName("BG").getChildByName("BG1_sprite_splash").getChildByName("MutureDurLabel").getChildByName("label").getComponent(cc.Label).string = this.mySeedList[this.buySeedIndex].maturity;
|
|
|
+
|
|
|
},
|
|
|
PayCNT() {
|
|
|
console.log('this.cntAmount=', this.cntAmount)
|
|
|
@@ -255,9 +290,20 @@ cc.Class({
|
|
|
seedId: this.mySeedList[this.buySeedIndex].id,
|
|
|
currentAmount: currentAmount //把当前背包的数据传进去
|
|
|
});
|
|
|
-
|
|
|
- GlobalD.GameData.payCNT(this.cntAmount * parseInt(this.mySeedList[this.buySeedIndex].priceCnt), 4, this.mySeedList[this.buySeedIndex].id + "", (data) => {
|
|
|
+ let playAmount = this.cntAmount * parseInt(this.mySeedList[this.buySeedIndex].priceCnt);
|
|
|
+ if (0 === playAmount) {
|
|
|
+ GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "请输入购买数量", 1);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // if (this.isPlaying) {
|
|
|
+ // GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "购买过快!", 1);
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // this.isPlaying = true;
|
|
|
+ // GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "区块确认中,请耐心等待!", 120);
|
|
|
+ GlobalD.GameData.payCNT(playAmount, 4, this.mySeedList[this.buySeedIndex].id + "", (data) => {
|
|
|
const [err, tx] = data;
|
|
|
+ // this.isPlaying = false;
|
|
|
if (err === null) {
|
|
|
// TODO 成功, 支付为链上操作,需要提供回调接口给这边服务端确认交易成功后修改购买订单结果
|
|
|
console.log(tx) // 交易hash,唯一标识符
|
|
|
@@ -278,9 +324,9 @@ cc.Class({
|
|
|
if (0 === value.code) {
|
|
|
this.unschedule(this.AutoGetSeedsData);
|
|
|
console.log("轮询种子购买成功");
|
|
|
- GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "种子购买成功!", 5);
|
|
|
+ GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "种子购买成功!", 1);
|
|
|
|
|
|
- this.PayCNTPopView.active = false;
|
|
|
+ // this.PayCNTPopView.active = false;
|
|
|
|
|
|
//直接重新初始化一下列表,
|
|
|
this.buildingViewScript.onUpdateList();
|
|
|
@@ -290,7 +336,7 @@ cc.Class({
|
|
|
this.schedule(this.AutoGetSeedsData, 5);
|
|
|
} else {
|
|
|
console.log(err)
|
|
|
- GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), err, 5);
|
|
|
+ GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), err, 2);
|
|
|
}
|
|
|
|
|
|
});
|
|
|
@@ -299,29 +345,38 @@ cc.Class({
|
|
|
console.log('this.snbAmount=', this.cntAmount)
|
|
|
console.log('priceSnb price=', this.mySeedList[this.buySeedIndex].priceSnb)
|
|
|
console.log('this.snbAmount price=', this.cntAmount * parseInt(this.mySeedList[this.buySeedIndex].priceSnb))
|
|
|
- // let currentAmount = 0;
|
|
|
- // for (let i = 0; i < this.myWareHouseSeedList.length; i++) {
|
|
|
- // if (this.myWareHouseSeedList[i].id == this.mySeedList[this.buySeedIndex].id) {
|
|
|
- // currentAmount = this.myWareHouseSeedList[i].amount;
|
|
|
- // }
|
|
|
- // }
|
|
|
- //当前背包的数量
|
|
|
- // console.log("currentAmount:", {
|
|
|
- // seedId: this.mySeedList[this.buySeedIndex].id,
|
|
|
- // currentAmount: currentAmount //把当前背包的数据传进去
|
|
|
- // });
|
|
|
- console.log("支付价格:"+this.cntAmount * parseInt(this.mySeedList[this.buySeedIndex].priceCnt*5));
|
|
|
- GlobalD.GameData.onBuySeedsWithSNB(this.cntAmount * parseInt(this.mySeedList[this.buySeedIndex].priceCnt*5), this.mySeedList[this.buySeedIndex].id, (res, value) => {
|
|
|
- console.log('snb res =====', res) // 交易hash,唯一标识符
|
|
|
- console.log('snb value =====', value) // 交易hash,唯一标识符
|
|
|
+ console.log("支付价格:" + this.cntAmount * parseInt(this.mySeedList[this.buySeedIndex].priceSnb));
|
|
|
+ let playAmount = this.cntAmount * parseInt(this.mySeedList[this.buySeedIndex].priceSnb);
|
|
|
+ if (0 === playAmount) {
|
|
|
+ GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "请输入购买数量", 1);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.isPlaying) {
|
|
|
+ GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "购买过快!", 1);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "支付处理中...", 10);
|
|
|
+
|
|
|
+ this.isPlaying = true;
|
|
|
+ GlobalD.GameData.onBuySeedsWithSNB(playAmount, this.mySeedList[this.buySeedIndex].id, (res, value) => {
|
|
|
+ // console.log("SNB购买后", value);
|
|
|
+ this.isPlaying = false;
|
|
|
if (0 === value.code) {
|
|
|
//todo 种子
|
|
|
- GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "种子购买成功!", 5);
|
|
|
- this.PaySNBPopView.active = false;
|
|
|
+ GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "种子购买成功!", 1);
|
|
|
+ // this.PayCNTPopView.active = false;
|
|
|
+
|
|
|
+ //重新获取一下snb,会自动更新到面板
|
|
|
+ GlobalD.GameData.onGetUserSnb();
|
|
|
+
|
|
|
//直接重新初始化一下列表,
|
|
|
this.buildingViewScript.onUpdateList();
|
|
|
+
|
|
|
+ //更新日志数据
|
|
|
+ cc.find("GameNode/ManageDapp").getComponent("ManageDapp").onUpdateSnbList();
|
|
|
} else {
|
|
|
- GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), value.msg, 5);
|
|
|
+ GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), value.msg, 2);
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
@@ -338,4 +393,47 @@ cc.Class({
|
|
|
// 这里的 customEventData 参数就等于你之前设置的 "foobar"
|
|
|
this.snbAmount = parseInt(text);
|
|
|
},
|
|
|
+
|
|
|
+ onToggleInput(value, evnentData) {
|
|
|
+ this.toggleInputValue = evnentData;
|
|
|
+ this._updatePrice();
|
|
|
+ },
|
|
|
+
|
|
|
+ _updatePrice() {
|
|
|
+ switch (this.toggleInputValue) {
|
|
|
+ case "1":
|
|
|
+ // this.totalPriceValue = 700 * this.inputInviteValue;
|
|
|
+ // this.totalPriceLabel.string = this.totalPriceValue + "CNT";
|
|
|
+ this.PayCNTPopViewNameLabel.string = this.mySeedList[this.buySeedIndex].name;
|
|
|
+ this.PayCNTPopViewPriceLabel.string = this.mySeedList[this.buySeedIndex].priceCnt + ' CNT';
|
|
|
+ this.PayCNTPopViewMutureDurLabel.string = this.mySeedList[this.buySeedIndex].maturity;
|
|
|
+ break;
|
|
|
+ case "2":
|
|
|
+ // this.totalPriceValue = 2500 * this.inputInviteValue;
|
|
|
+ // this.totalPriceLabel.string = this.totalPriceValue + "CNT";
|
|
|
+ this.PayCNTPopViewNameLabel.string = this.mySeedList[this.buySeedIndex].name;
|
|
|
+ this.PayCNTPopViewPriceLabel.string = this.mySeedList[this.buySeedIndex].priceSnb + ' SNB';
|
|
|
+ this.PayCNTPopViewMutureDurLabel.string = this.mySeedList[this.buySeedIndex].maturity;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ console.error("this.toggleInputValue 不是1 2 3!", this.toggleInputValue);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+ //根据状态吊起不同支付
|
|
|
+ onSwitchPlayType() {
|
|
|
+ switch (this.toggleInputValue) {
|
|
|
+ case "1"://cnt 支付
|
|
|
+ this.PayCNT();
|
|
|
+ break;
|
|
|
+ case "2": //snb 支付
|
|
|
+ this.PaySNB();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ console.error("状态吊起错误", this.toggleInputValue);
|
|
|
+ GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "请先选择支付方式", 1);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
});
|