Files
fc/dev/project/library/imports/eb/eb54d4a7-e5dc-4118-ba7a-254cb552b5de.js
2026-05-24 10:21:26 +08:00

226 lines
6.5 KiB
JavaScript

"use strict";
cc._RF.push(module, 'eb54dSn5dxBGLp6JUy1UrXe', 'pop.items.buy');
// Scripts/mod/tips/popup/pop.items.buy.js
"use strict";
/****
* 购买
*/
var ItemBase = require("cmp.item.base");
var BridgeWindow = require("bridge.window");
var SliderProgress = require("cmp.slider.prog.selector");
var BackPackController = require("backpack_controller");
var ElfinController = require("elfin_controller");
var TDefine = require("trace.define");
var TTT = TDefine.TraceType;
cc.Class({
"extends": BridgeWindow,
properties: {
cmpItem: {
"default": null,
type: ItemBase
},
cmpCounter: {
"default": null,
type: SliderProgress
},
nodPrice: {
"default": null,
type: cc.Node
},
nodMat: {
"default": null,
type: cc.Node
},
nodResult: {
"default": null,
type: cc.Node
}
},
// 重载:参数打开
onOpenConfigs: function onOpenConfigs(_params) {
// console.log( "购买的数据" + JSON.stringify( _params ) );
// this.item = _params[0];
this.item = _params.data;
this.extra_data = _params.type;
this.cb = _params.cb;
// if (!this.item || !this.config) {
// nx.error("[Merge]合成失败,参数无效!");
// return;
// }
// 重建
this.rebuild();
},
// 重建
rebuild: function rebuild() {
var _this = this;
if (this.extra_data == 1) {
// 道具信息
this.cmpItem.setData(this.item);
} else {
// 道具信息
this.cmpItem.setData(this.item.item_bid || this.item.item_id);
}
// // 数量范围&&默认
var Bag = BackPackController.getInstance().getModel();
// 显示单个信息
var pfg = {};
var icon = 0;
// 孵化 僚機購買
if (this.extra_data == 1) {
pfg = game.configs.sprite_data.data_hatch_egg[this.item];
this.price = pfg.price[0][1];
icon = pfg.price[0][0];
}
if (this.extra_data == 2 || this.extra_data == 4) {
if (this.item.limit_count > 0) {
pfg.limit_num = this.item.limit_count - this.item.has_buy;
}
if (this.item.limit_day > 0) {
pfg.limit_num = this.item.limit_day - this.item.has_buy;
}
if (this.item.limit_week > 0) {
pfg.limit_num = this.item.limit_week - this.item.has_buy;
}
if (this.item.limit_month > 0) {
pfg.limit_num = this.item.limit_month - this.item.has_buy;
}
this.price = this.item.discount > 0 ? this.item.discount : this.item.price;
pfg.limit_num = !pfg.limit_num ? Math.floor(parseInt(Bag.getItemNumByBid(this.item.pay_type) / this.price)) : pfg.limit_num;
icon = this.item.pay_type;
}
// 戰體商店
if (this.extra_data == 28) {
if (this.item.limit_count > 0) {
pfg.limit_num = this.item.limit_count - this.item.has_buy;
}
if (this.item.limit_day > 0) {
pfg.limit_num = this.item.limit_day - this.item.has_buy;
}
if (this.item.limit_week > 0) {
pfg.limit_num = this.item.limit_week - this.item.has_buy;
}
if (this.item.limit_month > 0) {
pfg.limit_num = this.item.limit_month - this.item.has_buy;
}
this.price = this.item.discount > 0 ? this.item.discount : this.item.price;
var can = Bag.getItemNumByBid(this.item.pay_type) >= parseInt(this.price * pfg.limit_num);
pfg.limit_num = !pfg.limit_num || !can ? Math.floor(parseInt(Bag.getItemNumByBid(this.item.pay_type) / this.price)) : pfg.limit_num;
icon = this.item.pay_type;
}
// 競技場購買
if (this.extra_data == 5) {
this.price = this.item.price;
pfg.limit_num = !pfg.limit_num ? Math.floor(parseInt(Bag.getItemNumByBid(this.item.pay_type) / this.price)) : pfg.limit_num;
icon = this.item.pay_type;
}
// 冠軍賽下注
if (this.extra_data == 9) {
this.price = this.item.price;
pfg.limit_num = this.item.own;
icon = this.item.pay_type;
}
nx.bridge.setIconS(this.nodPrice, "icon", icon);
nx.gui.setString(this.nodPrice, "txt", nx.dt.shortCount(this.price));
nx.bridge.setIconS(this.nodMat, "mat1/icon", icon);
var canMergeCount = pfg.limit_num;
// 设置滚动条
this.cmpCounter.build(1, canMergeCount, 1, function (_count) {
_this.changeCount(_count);
});
},
// 数量改变
changeCount: function changeCount(_count) {
nx.gui.setActive(this.nodMat, "", _count > 0);
if (this.cur == _count || !nx.dt.numPositive(_count, false)) {
return;
}
nx.gui.setString(this.nodMat, "mat1/txt", nx.dt.shortCount(this.price * _count));
this.cur = _count;
},
// 点击合成按钮
onTouchBuy: function onTouchBuy() {
if (this.extra_data == 1) {
var data = {
type: this.extra_data,
item_id: this.item,
num: this.cur
};
// 返回
nx.dt.fnInvoke(this.cb, data);
// {"type":1,"item_id":10602,"num":1}
}
// 兌換商城
if (this.extra_data == 2) {
// [13407]:{"order":2,"type":2,"buy_type":1,"num":1}
if (this.item.limit_count > 0 && this.item.pay_type != 3) {
var _data = {
order: this.item.order,
type: this.extra_data,
buy_type: 1,
num: this.cur
};
// 返回
nx.dt.fnInvoke(this.cb, _data);
return;
}
if (this.item.limit_count > 0 && this.item.pay_type == 3 || this.item.limit_count < 0) {
var _data2 = {
eid: this.item.id,
num: this.cur
};
// console.log( JSON.stringify( this.item ) + "顯示" );
nx.mTrace.trace(TTT.buyStart, this.item.id, this.cur);
// 返回
nx.dt.fnInvoke(this.cb, _data2);
// {"type":1,"item_id":10602,"num":1}
}
}
if (this.extra_data == 28) {
// [13407]:{"order":2,"type":2,"buy_type":1,"num":1}
var _data3 = {
eid: this.item.id,
num: this.cur
};
// 返回
nx.dt.fnInvoke(this.cb, _data3);
return;
}
// 兌換商城
if (this.extra_data == 4) {
// [13407]:{"order":2,"type":2,"buy_type":1,"num":1}
var _data4 = {
order: this.item.order,
type: this.extra_data,
buy_type: 1,
num: this.cur
};
// 返回
nx.dt.fnInvoke(this.cb, _data4);
return;
}
if (this.extra_data == 5 || this.extra_data == 9) {
// [13407]:{"order":2,"type":2,"buy_type":1,"num":1}
var _data5 = {
num: this.cur
};
// 返回
nx.dt.fnInvoke(this.cb, _data5);
return;
}
}
});
cc._RF.pop();