"use strict"; cc._RF.push(module, '523a8JgAJFDUaDp8SyCAsbt', 'cmp.act.optionalgift.wnd'); // Scripts/mod/acts/optionalgift/cmp/cmp.act.optionalgift.wnd.js "use strict"; // const ActPage = require( "act.page.base" ); var ActPopup = require("act.popup.base"); var TipsController = require("tips_controller"); var mod = require("act.optionalgift.mod"); var FID = require("bridge.function.ids"); var themeMod = require("acts.mod"); var Payment = require("payment.mod"); var NxExpand = require("nx.fx.sv.expand"); cc.Class({ "extends": ActPopup, properties: { nodCnt: { type: cc.Node, "default": null }, nodShow: { type: cc.Node, "default": null } }, // build: function( _params ){ // }, onLoad: function onLoad() {}, onOpenConfigs: function onOpenConfigs(_params) { this._super(_params); this.mod = mod.getInstance(); if (!this.mod || !this.mod.data) { this.delayClose(); return; } var chargefg = gdata(this.mod.data.config, "data_const").charge_id; var charge_id = 0; if (chargefg) { charge_id = chargefg.val; } this.charge_id = charge_id; var price = game.configs.charge_data.data_charge_data[charge_id].val; nx.gui.setString(this.nodCnt, "op/price", Payment.getInstance().fmtPrice(price) + " " + nx.text.getKey("Buy")); // 活动监听 this.mod.vbind(this, [["optionalGift", this.freshInfo.bind(this)], ["optionalGiftSaveBack", this.dealShow.bind(this)]]); this.mod.reqOptionalGift(); }, onEnable: function onEnable() {}, // 销毁 onDestroy: function onDestroy() { // 活动监听解除 if (this.mod) { this.mod.vunbind(this); } delete this.mod; this._super(); }, freshInfo: function freshInfo(_data) { this.selects = []; if (_data) { var chd = nx.gui.find(this.nodCnt, "choice").children; var rewards = _data.reward; for (var r = 0; r < rewards.length; r++) { var reward = rewards[r]; var shows = []; var show = { bid: reward.item_list[0].item_id, num: reward.item_list[0].num }; var nod = chd[reward.id - 1]; if (reward.id == 1 || reward.id == 2) { this.selects.push({ id: reward.id, bid: reward.item_list[0].item_id }); } shows.push(show); var cmp = nx.gui.getComponent(nod, "item", "cmp.common.itemlayout"); if (cmp) { cmp.rebuild(shows); } } } /***** *{"reward":[ {"id":0,"item_list":[{"item_id":0,"num":2000},{"item_id":10001,"num":0}]}, {"id":3,"item_list":[{"item_id":14001,"num":5}]} **]} ****/ }, onTouchAdd: function onTouchAdd(_idx) { var show_list = gdata(this.mod.data.config, "data_optional_reward")[_idx]; var rewards = []; for (var i in show_list) { var item = show_list[i].reward; var showid = parseInt(i); rewards.push(item); } this.id = _idx; var nowSelect = []; var num = parseInt(_idx); var rrnod = nx.gui.find(this.nodCnt, "choice").children[num - 1]; var rnod = nx.gui.find(rrnod, "item"); if (rnod.children.length > 0) { for (var _i = 0; _i < rnod.children.length; _i++) { var nodd = rnod.children[_i]; var ncmp = nodd.getComponent("cmp.act.optionalgift.item"); if (ncmp) { nowSelect.push(ncmp.mdata.bid); } } } this.setShow(rewards, nowSelect); }, setShow: function setShow(_rewards, _nowselect) { var _this = this; var cmp = nx.gui.getComponent(this.nodShow, "rewards", NxExpand); if (cmp) { cmp.rebuild(_rewards); } var selectss = []; this.selects.forEach(function (_sel) { if (_sel.id != _this.id) { selectss.push(_sel.bid); } }); this.dealShowItem(_nowselect, selectss); }, dealShowItem: function dealShowItem(_select, _selectssss) { var chd = nx.gui.find(this.nodShow, "rewards/list/view/content").children; this.choice = {}; this.already = []; // 已选择的 组为非空 if (nx.dt.arrNEmpty(_selectssss)) { for (var i = 0; i < chd.length; i++) { var nod = chd[i].svItem; if (nod) { nod.setCannotSelect(false); var now = _select[0]; if (now) { if (nod.info.item_id == now) { nod.onFocus(); nod.setCannotSelect(false); // _selectssss.splice( ( _selectssss.indexOf( now ) ), 1 ) ; // this.already.push[now]; } else { nod.setCannotSelect(false); for (var s = 0; s < _selectssss.length; s++) { var selectItem = _selectssss[s]; if (nod.info.item_id == selectItem) { nod.setCannotSelect(true); nod.outFocus(); } else { nod.setCannotSelect(false); nod.outFocus(); } } } } else { for (var _s = 0; _s < _selectssss.length; _s++) { var _selectItem = _selectssss[_s]; if (nod.info.item_id == _selectItem) { nod.setCannotSelect(true); } else { nod.setCannotSelect(false); } } } } else { nod.setCannotSelect(false); } } } else { // 当第二个槽位 没有选择道具 for (var _i2 = 0; _i2 < chd.length; _i2++) { var _nod = chd[_i2].svItem; if (_nod) { _nod.setCannotSelect(false); var _now = _select[0]; if (_now) { if (_nod.info.item_id == _now) { _nod.onFocus(); } } } } } nx.gui.setActive(this.nodShow, "", true); }, onTouchSelect: function onTouchSelect(_item) { var chd = nx.gui.find(this.nodShow, "rewards/list/view/content").children; if (_item.mdata.canshow == 1) { return; } this.choice = []; this.selectsNow = []; for (var i = 0; i < chd.length; i++) { var nod = chd[i].svItem; this.selectsNow.push(nod); if (nod) { nod.outFocus(); if (nod.index == _item.index) { nod.onFocus(); this.selectsNow.push(nod); this.choice = nod.mdata; } else { nod.outFocus(); if (nx.dt.arrMember(this.selectsNow, nod)) { this.selectsNow.splice(this.selectsNow.indexOf(nod), 1); } } } } }, dealShow: function dealShow(_code) { if (!_code) { nx.gui.setActive(this.nodShow, "", false); return; } nx.gui.setActive(this.nodShow, "", _code == 0); }, closeShow: function closeShow() { nx.gui.setActive(this.nodShow, "", false); }, onTouchSave: function onTouchSave() { if (nx.dt.arrEmpty(this.choice)) { return; } // for (let i = 0; i < this.choice.length; i++) { // let item = this.choice[i]; // if( item == 0 ){ // return; // } // } var pusInfo = []; var item = []; var id = { id: parseInt(this.id) }; pusInfo.push(id); var idd = { item_id: this.choice[0], num: this.choice[1] }; item.push(idd); this.mod.reqOptionalSelect(parseInt(this.id), item); }, onTouchBuy: function onTouchBuy(_idx) { var chd = nx.gui.find(this.nodCnt, "choice").children; var num = 0; for (var i = 0; i < chd.length; i++) { var nod = nx.gui.find(chd[i], "item"); if (nod.children.length == 0) { num++; } } if (num > 0) { nx.tbox("ActGiftSelectTips"); return; } Payment.getInstance().reqPayment(this.charge_id); nx.bridge.closePanel("WndActCustomGift"); } }); cc._RF.pop();