"use strict"; cc._RF.push(module, '80f2bGe77tAzoSU1kZ/FCI0', 'cmp.act.limit.item'); // Scripts/mod/acts/limitShop/cmp/cmp.act.limit.item.js "use strict"; /****************************************************************** * Copyright(C) 2019 - 2020 Nx Studio * * 通用支付项 * * 2024.01.24 ******************************************************************/ var SVCItem = require("nx.fx.sv.expand.item"); var Payment = require("payment.mod"); var TipsController = require("tips_controller"); // 价格标记 var PFS = { TimeLimit: 2, // 次数上限 TimeCurrent: 6, // 已购买次数 PriceRaw: 26, // 原价 PriceDisInfo: 25, // 折扣信息 PriceDiscount: 27, // 折后价 SortRight: 39 // 排序 }; cc.Class({ "extends": SVCItem, properties: { // 基本信息 fabItem: { "default": null, type: cc.Prefab }, nodGoods: { "default": null, type: cc.Node }, nodName: { "default": null, type: cc.Node }, nodReaminTimes: { "default": null, type: cc.Node }, // 价格 nodRMB: { "default": null, type: cc.Node }, nodDiamond: { "default": null, type: cc.Node }, // 具体操作 nodBuy: { "default": null, type: cc.Node }, nodDone: { "default": null, type: cc.Node }, // 回调 doneEvent: { "default": [], type: cc.Component.EventHandler, displayName: "购买回调" } }, // 数据重置 rebind: function rebind(_idx, _data, _key) { this._super(_idx, _data, _key); this.setData(_data); }, // 设置 setData: function setData(_data, _bgRes) { this.mdata = nx.dt.objClone(_data); // 背景刷新 if (nx.dt.strNEmpty(_bgRes)) { var path = cc.path.join("prefab/acts/limitShop/ui", _bgRes); nx.gui.setSpriteFrame(this, "", path); } // 名字刷新 if (this.nodName) { var name = nx.text.getKey(_data.aim_str); nx.gui.setString(this.nodName, "", name); } // 商品刷新 if (this.nodGoods && this.fabItem) { var items = _data.item_list || []; if (nx.dt.arrEmpty(items)) { this.nodGoods.active = false; } else { this.nodGoods.active = true; for (var i = 0; i < this.nodGoods.children.length; ++i) { var info = items[i]; var node = this.nodGoods.children[i]; if (nx.dt.objEmpty(info)) { node.active = false; continue; } node.active = true; if (node.children.length == 0) { var item = cc.instantiate(this.fabItem); item.parent = node; item.position = cc.v2(0, 0); } var cmp = node.children[0].getComponent("cmp.item.base"); cmp.setData(info.bid, info.num); } } // 自动布局 this.autoLayout(); } // 数据统计 this.infos = {}; for (var _i = 0; _i < _data.aim_args.length; ++_i) { var tmp = _data.aim_args[_i]; if (!tmp) { continue; } switch (tmp.aim_args_key) { case PFS.TimeLimit: { this.infos.maxTimes = tmp.aim_args_val; } break; case PFS.TimeCurrent: { this.infos.curTimes = tmp.aim_args_val; } break; case PFS.PriceRaw: { this.infos.price = tmp.aim_args_val; } break; case PFS.PriceDisInfo: { this.infos.disinfo = tmp.aim_args_val; } break; case PFS.PriceDiscount: { this.infos.disprice = tmp.aim_args_val; } break; case PFS.SortRight: { this.infos.sort = tmp.aim_args_val; } break; default: break; } ; } // 价格刷新 if (this.nodRMB || this.nodDiamond) { var price = this.infos.disprice || this.infos.price || 0; if (_data.aim == 0) { nx.gui.setActive(this.nodRMB, "", false); nx.gui.setActive(this.nodDiamond, "", true); nx.gui.setString(this.nodDiamond, "txt", price); } else { nx.gui.setActive(this.nodRMB, "", true); nx.gui.setActive(this.nodDiamond, "", false); var txt = Payment.getInstance().fmtPrice(price); nx.gui.setString(this.nodRMB, "txt", txt); } } // 变数刷新 this.freshInfos(); }, // 变数刷新 freshInfos: function freshInfos() { // 次数刷新 var times = this.infos.maxTimes - this.infos.curTimes || 0; if (this.nodReaminTimes) { nx.gui.setString(this.nodReaminTimes, "", times); } // 操作刷新 nx.gui.setActive(this.nodBuy, "", times > 0); nx.gui.setActive(this.nodDone, "", times <= 0); }, // 点击购买 onTouchBuy: function onTouchBuy() { var _this = this; if (!this.mdata || !this.infos) { return; } var self = this; var done = function done() { self.infos.curTimes += 1; self.freshInfos(); }; // 如果aim=0则为钻石购买,直接抛出 if (this.mdata.aim == 0) { var TC = TipsController.getInstance(); if (TC) { var item = { item_bid: this.mdata.item_list[0].bid, has_buy: this.infos.curTimes, discount: 0, price: this.infos.disprice || this.infos.price || 0, limit_count: this.infos.maxTimes, pay_type: 3 }; TC.openBuyPanel(true, item, 28, function (_data) { self.doneEvent.forEach(function (_event) { if (_event && _event.customEventData === "" || _event.customEventData) { _event.customEventData = { diamond: true, data: self.mdata, num: _data.num, cb: function cb() { self.infos.curTimes += _data.num; self.freshInfos(); } }; } }); TC.openBuyPanel(false); cc.Component.EventHandler.emitEvents(_this.doneEvent); }); } return; } // 支付 Payment.getInstance().reqPayment(this.mdata.aim, function (_ret) { if (_ret && nx.dt.arrNEmpty(_this.doneEvent)) { done(); cc.Component.EventHandler.emitEvents(_this.doneEvent); } }); }, // 自动布局 autoLayout: function autoLayout() { var shows = []; for (var i = 0; i < this.nodGoods.children.length; ++i) { var node = this.nodGoods.children[i]; if (node && node.active) { shows.push(node); } } if (shows.length <= 0) { return; } var POS = [[[0, 0]], [[-60, 0], [60, 0]], [[0, 56], [-60, -55], [60, -55]], [[-60, 56], [60, 56], [-60, -55], [60, -55]]]; var poses = POS[shows.length - 1]; if (!poses) { return; } for (var _i2 = 0; _i2 < shows.length; ++_i2) { var pos = poses[_i2]; var _node = shows[_i2]; _node.position = cc.v2(pos[0], pos[1]); } } }); cc._RF.pop();