123 lines
3.6 KiB
JavaScript
123 lines
3.6 KiB
JavaScript
|
import GameModel from "../ts/core/GameModel";
|
|||
|
import GameUtil from "../ts/core/GameUtil";
|
|||
|
import MsgAlert from "../ts/game/msg/MsgAlert";
|
|||
|
import FGAlert from "../ts/gear_2.3.4/fgui/FGAlert";
|
|||
|
|
|||
|
cc.Class({
|
|||
|
extends: cc.Component,
|
|||
|
properties: {
|
|||
|
ex_xianyu_label: cc.Label,
|
|||
|
xianyu_label: cc.Label,
|
|||
|
money_label: cc.Label,
|
|||
|
web_view_prefab: cc.Prefab,
|
|||
|
editbox: cc.EditBox,
|
|||
|
xnode: cc.Node,
|
|||
|
},
|
|||
|
|
|||
|
init (data) {
|
|||
|
if (data) {
|
|||
|
this.goodsid = data.goodsid;
|
|||
|
this.ex_xianyu_label.string = data.ex_jade;
|
|||
|
this.xianyu_label.string = data.jade;
|
|||
|
this.money_label.string = '¥'+data.money;
|
|||
|
}
|
|||
|
},
|
|||
|
|
|||
|
onButtonClick (event, param) {
|
|||
|
if(!GameUtil.hasCharge){
|
|||
|
FGAlert.show(`暫未開通線上充值,請聯繫管理!`, () => {
|
|||
|
FGAlert.hide();
|
|||
|
}, () => {
|
|||
|
FGAlert.hide();
|
|||
|
});
|
|||
|
return;
|
|||
|
}
|
|||
|
if (this.goodsid) {
|
|||
|
let send_data = {
|
|||
|
roleid: GameModel.player.roleid,
|
|||
|
goodsid: this.goodsid,
|
|||
|
goodscount: 1,
|
|||
|
money: this.checkNum(this.money_label.string),
|
|||
|
};
|
|||
|
let node = cc.instantiate(this.web_view_prefab);
|
|||
|
node.name="ChargeWebUI";
|
|||
|
node.parent = cc.find('Canvas');
|
|||
|
let webUI= node.getComponent('ChargeWebUI');
|
|||
|
if(webUI){
|
|||
|
webUI.setData(send_data);
|
|||
|
}
|
|||
|
}
|
|||
|
else if(this.checkNum(this.editbox.string) > 1996) {
|
|||
|
let send_data = {
|
|||
|
roleid: GameModel.player.roleid,
|
|||
|
goodsid: 0,
|
|||
|
goodscount: 1,
|
|||
|
money: this.checkNum(this.editbox.string),
|
|||
|
};
|
|||
|
let node = cc.instantiate(this.web_view_prefab);
|
|||
|
node.parent = cc.find('Canvas');
|
|||
|
node.getComponent('ChargeWebUI').setData(send_data);
|
|||
|
}
|
|||
|
else {
|
|||
|
MsgAlert.addMsg('請輸入正確的充值金額!');
|
|||
|
}
|
|||
|
},
|
|||
|
|
|||
|
showEditbox () {
|
|||
|
this.editbox.node.active = true;
|
|||
|
this.ex_xianyu_label.string = '0';
|
|||
|
this.xianyu_label.string = '0';
|
|||
|
this.money_label.string = '0';
|
|||
|
this.money_label.node.active = false;
|
|||
|
this.editbox.node.on('editing-did-ended', this.editEnd.bind(this));
|
|||
|
},
|
|||
|
|
|||
|
checkNum (num) {
|
|||
|
num = num.replace(/¥/, '');
|
|||
|
if (isNaN(parseInt(num))) {
|
|||
|
num = 0;
|
|||
|
}
|
|||
|
else {
|
|||
|
num = Math.abs(parseInt(num));
|
|||
|
}
|
|||
|
return num;
|
|||
|
},
|
|||
|
|
|||
|
editEnd () {
|
|||
|
let money = this.checkNum(this.editbox.string);
|
|||
|
if (money <= 1996) {
|
|||
|
if (money == 0) {
|
|||
|
MsgAlert.addMsg('格式錯誤!');
|
|||
|
} else {
|
|||
|
MsgAlert.addMsg('充值不能少於1996!');
|
|||
|
money = 0;
|
|||
|
}
|
|||
|
this.ex_xianyu_label.string = '0';
|
|||
|
this.xianyu_label.string = '0';
|
|||
|
this.editbox.string = '';
|
|||
|
}
|
|||
|
else if (money > 1996) {
|
|||
|
this.ex_xianyu_label.string = this.calculateExJade(money);
|
|||
|
this.xianyu_label.string = money*100;
|
|||
|
this.editbox.string = '¥' + money;
|
|||
|
}
|
|||
|
this.xnode.x = -this.xianyu_label.node.width-this.xnode.width/2;
|
|||
|
},
|
|||
|
|
|||
|
/*
|
|||
|
* 自定義充值金額計算獎勵仙玉
|
|||
|
*/
|
|||
|
calculateExJade (money) {
|
|||
|
let exjade = 0;
|
|||
|
for (let i = 6; i >= 1; --i) {
|
|||
|
let item = GameModel.conf_charge[i];
|
|||
|
if (item && money >= item.money) {
|
|||
|
let count = Math.floor(money/item.money);
|
|||
|
exjade += count*item.ex_jade;
|
|||
|
money -= count*item.money;
|
|||
|
}
|
|||
|
}
|
|||
|
return exjade;
|
|||
|
},
|
|||
|
});
|