"use strict"; cc._RF.push(module, 'e39ffOhMmRJ2K4miUWyjUar', 'cmp.planesafk.item.shop'); // Scripts/mod/pve/planesafk/cmp/cmp.planesafk.item.shop.js "use strict"; var ItemBase = require("nx.fx.sv.expand.item"); var PlanesafkController = require("planesafk_controller"); var PlanesafkConst = require("planesafk_const"); var Pathtool = require("pathtool"); var RoleController = require("role_controller"); var BackpackController = require("backpack_controller"); var BackPackConst = require("backpack_const"); cc.Class({ "extends": ItemBase, properties: { comfirm_btn: { "default": null, type: cc.Button }, price_txt: { "default": null, type: cc.RichText }, discount: { "default": null, type: cc.Node }, disIcon: { "default": null, type: cc.Node }, itemNd: { "default": null, type: cc.Node }, fabItem: { "default": null, type: cc.Prefab }, shopCmp: { "default": null, type: cc.Node } }, // 数据重置 rebind: function rebind(_idx, _data, _key) { this.is_select = _key; this.mdata = _data; this.initui(); }, setParentData: function setParentData() { var parCmp = nx.gui.getComponent(this.shopCmp, "", "cmp.planesafk.wnd.evtshop"); if (parCmp) { this.parentdata = parCmp.data; } else { this.parentdata = null; } }, initui: function initui() { if (nx.dt.objEmpty(this.mdata)) { return; } this.setParentData(); //测试数据 var shop_config = gdata("planes_data", "data_shop_info", this.mdata.id); if (!shop_config) return; this.shop_config = shop_config; if (!this.item) { this.item = cc.instantiate(this.fabItem); this.item.parent = this.itemNd; } var cmp = nx.gui.getComponent(this.item, "", "cmp.item.base"); if (cmp) { cmp.setData({ bid: shop_config.base_id, num: shop_config.num }); } if (shop_config.discount > 0) { this.discount.active = true; nx.gui.setString(this.discount, "num", 10 * (10 - shop_config.discount) + "%"); } else { this.discount.active = false; } if (this.is_select == 1) { if (this.mdata.is_flag == 1) { this.comfirm_btn.interactable = false; this.price_txt.string = nx.text.getKey("lab_planesafk_evt_shop_havenothing"); } else { this.comfirm_btn.interactable = true; var pay_type = gdata("item_data", "data_assets_label2id", shop_config.type); var item_config = gitemdata(pay_type); if (item_config) { var res = item_config.icon; var price = shop_config.price; var price_str = cc.js.formatStr(" %s", res, Utils.getMoneyString(price)); var res_path = Pathtool.queryIconPath(item_config.id); nx.gui.setSpriteFrame(this.disIcon, "", res_path); this.price_txt.string = price_str; } } } else { var pay_type = gdata("item_data", "data_assets_label2id", shop_config.type); var item_config = gitemdata(pay_type); if (item_config) { var res = item_config.icon; var price = shop_config.price; var price_str = cc.js.formatStr(" %s", res, Utils.getMoneyString(price)); var _res_path = Pathtool.queryIconPath(item_config.id); nx.gui.setSpriteFrame(this.disIcon, "", _res_path); this.price_txt.string = price_str; } this.comfirm_btn.interactable = true; } }, clickAlert: function clickAlert() { // if (this.is_select == 1) { if (this.mdata.is_flag == 1) { nx.tbox("lab_planesafk_evt_shop_havenothing"); return; } this.onBuyItem(); // } // else // { // nx.tbox("lab_planesafk_evt_shop_must_goto_first"); // } }, onBuyItem: function onBuyItem() { if (!this.shop_config) return; var self = this; //购买实际价格 var price = this.shop_config.price; var role_vo = RoleController.getInstance().getRoleVo(); if (!role_vo) return; var pay_type = gdata("item_data", "data_assets_label2id", this.shop_config.type); var cur_num = BackpackController.getInstance().getModel().getItemNumByBid(pay_type); if (cur_num >= price) { var item_cfg = gitemdata(this.shop_config.base_id); var bag_type = BackPackConst.Bag_Code.BACKPACK; if (item_cfg.sub_type == 1) { //背包中装备类型 bag_type = BackPackConst.Bag_Code.EQUIPS; } var num = BackpackController.getInstance().getModel().getItemNumByBid(this.shop_config.base_id, bag_type); var tips_str = cc.js.formatStr(nx.text.getKey("msg_planesafk_evt_shop_isbuy"), item_cfg.name, num); nx.mbox(tips_str, ["confirm"], function (_key, _box) { _box.close(); if (_key == "confirm") { if (self.mdata && self.parentdata) { PlanesafkController.getInstance().sender28600(self.parentdata.line, self.parentdata.index, 1, [{ type: PlanesafkConst.Proto_28600._7, val1: self.mdata.pos, val2: 0 }]); } } }); } else { var pay_config = null; if (typeof this.shop_config.type == 'number') { pay_config = gitemdata(this.shop_config.type); } else { pay_config = gdata("item_data", "data_assets_label2id", this.shop_config.type); } if (pay_config) { if (pay_config.id == gdata("item_data", "data_assets_label2id", "gold")) { var fun = function fun() { nx.bridge.createPanel("WndPayment", { key: "recharge" }); }; var str = cc.js.formatStr(nx.text.getKey("lab_planesafk_evt_shop_nogold_is_tobuygold"), pay_config.name); nx.mbox(str, ["confirm"], function (_key, _box) { _box.close(); if (_key == "confirm") { fun(); } }); } else { var TipsController = require("tips_controller"); TipsController.getInstance().showItemTips(pay_config); } } } } }); cc._RF.pop();