| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- /**
- * 购买小狗
- */
- cc.Class({
- extends: cc.Component,
- properties: {
- inputInviteValue: {
- default: 1,
- visible: false
- },
- //1 小包,2 大包
- toggleInputValue: {
- default: '1',
- visible: false
- },
- totalPriceLabel: {
- default: null,
- type: cc.Label,
- serializable: true
- },
- totalPriceValue: {
- default: 0,
- visible: false
- },
- currentFoodUnitLabel: {
- default: null,
- type: cc.Label,
- serializable: true
- },
- ToastParent: {
- default: null,
- type: cc.Node,
- serializable: true
- },
- //输入节点
- inputContainer: {
- default: null,
- type: cc.Node,
- serializable: true
- },
- foodTypeToggle1: {
- default: null,
- type: cc.Toggle,
- serializable: true
- },
- foodTypeToggle2: {
- default: null,
- type: cc.Toggle,
- serializable: true
- },
- foodList: {
- default: [],
- visible: false
- },
- foodSmall: {
- default: null,
- visible: false
- },
- foodBig: {
- default: null,
- visible: false
- },
- currentFood: {
- default: null,
- visible: false
- },
- parentNode: {
- default: null,
- visible: false
- }
- },
- onLoadFoodList() {
- GlobalD.GameData.onGetMallFoodList((value) => {
- if (0 === value.code) {
- this.foodList = value.data;
- for (let i = 0; i < this.foodList.length; i++) {
- if (1 === this.foodList[i].id) {
- this.foodSmall = this.foodList[i];
- this.currentFood = this.foodSmall;
- this.currentFoodUnitLabel.string = "X" + this.currentFood.priceSnb;
- } else if (2 === this.foodList[i].id) {
- this.foodBig = this.foodList[i];
- }
- }
- this.toggleInputValue = '1';
- this._updatePrice();
- } else {
- GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), value.msg, 1);
- }
- });
- this.inputContainer.getComponent(cc.EditBox).string = this.inputInviteValue;
- },
- //初始化时候需要初始化一次默认值
- onToggleInput(value, evnentData) {
- // console.log(value.isChecked, evnentData);
- this.toggleInputValue = evnentData;
- this._updatePrice();
- },
- inputValue(value, e) {
- var numberTemp = new RegExp("^[A-Za-z0-9]+$");
- let limitValue = 100;
- if (numberTemp.test(value)) {
- if (Number(value) >= 1 && Number(value) <= limitValue) {
- this.inputInviteValue = Number(value);
- } else if (Number(value) > limitValue) {
- //限制只能输入100
- this.inputInviteValue = limitValue;
- this.inputContainer.getComponent(cc.EditBox).string = this.inputInviteValue;
- } 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() {
- switch (this.toggleInputValue) {
- case "1":
- this.totalPriceValue = this.foodSmall.priceSnb * this.inputInviteValue;
- this.totalPriceLabel.string = "X" + this.totalPriceValue;
- this.currentFood = this.foodSmall;
- break;
- case "2":
- this.totalPriceValue = this.foodBig.priceSnb * this.inputInviteValue;
- this.totalPriceLabel.string = "X" + this.totalPriceValue;
- this.currentFood = this.foodBig;
- break;
- default:
- console.error("this.toggleInputValue 不是1 2", this.toggleInputValue);
- break;
- }
- this.currentFoodUnitLabel.string = "X" + this.currentFood.priceSnb;
- },
- //租赁支付
- onPlaySnbInfo() {
- if (this.currentFood == null) {
- GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "购买狗粮NULL", 1);
- return;
- }
- GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "添加狗粮..", 5);
- let data = { foodId: this.currentFood.id, buyAmount: this.inputInviteValue };
- GlobalD.GameData.onGetAddDogFood(data, (value) => {
- console.log(value);
- if (0 === value.code) {
- GlobalD.GameData.SetSNB(value.data.snb + value.data.snbPart);
- GlobalD.Dog = value.data.dog;
- GlobalD.GameData.hideToast();
- //更新日志数据
- cc.find("GameNode/ManageDapp").getComponent("ManageDapp").onUpdateSnbList();
- //需要赋值
- this.parentNode.getComponent('DogContainer')._updateDogState(GlobalD.Dog);
- } else {
- GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), value.msg, 1);
- }
- });
- },
- onClose() {
- this.node.destroy();
- }
- });
|