"use strict";
cc._RF.push(module, 'bdd33ZaLJVAp5HTRLGTDcyY', 'newfirstcharge1_window');
// Scripts/mod/newfirstcharge/view/newfirstcharge1_window.js
"use strict";
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
// 这里是描述这个窗体的作用的
//
Create: 2019-08-15 17:44:42
// --------------------------------------------------------------------
var PathTool = require("pathtool");
var VipController = require("vip_controller");
var NewFirstChargeEvent = require("newfirstcharge_event");
var RoleController = require("role_controller");
var Newfirstcharge1Window = cc.Class({
"extends": BaseView,
ctor: function ctor() {
this.prefabPath = PathTool.getPrefabPath("newfirstcharge", "newfirstcharge1_window");
this.viewTag = SCENE_TAG.dialogue; //该窗体所属ui层级,全屏ui需要在ui层,非全屏ui在dialogue层,这个要注意
this.win_type = WinType.Big; //是否是全屏窗体 WinType.Full, WinType.Big, WinType.Mini, WinType.Tips
this.ctrl = arguments[0];
this.model = this.ctrl.getModel();
},
// 初始化一些配置数据,可以用于声明一些变量之类的
initConfig: function initConfig() {
this.effect_list = [];
this.cur_node = null;
this.item_list = {};
this.recharge_list = {};
this.select = new cc.Color().fromHEX("#AB382B");
this.notSelect = new cc.Color().fromHEX("#EC9A3B");
this.item_reward_list = [];
for (var i = 1; i <= 3; i++) {
this.item_reward_list[i] = {};
}
},
// 预制体加载完成之后的回调,可以在这里捕获相关节点或者组件
openCallBack: function openCallBack() {
var _this = this;
this.background = this.root_wnd.getChildByName("background");
this.background.scale = FIT_SCALE;
var bg_sp = this.seekChild("bg", cc.Sprite);
this.loadRes(PathTool.getBigBg("action/txt_cn_action_bigbg_30506"), function (res) {
bg_sp.spriteFrame = res;
}.bind(this));
this.close_btn = this.seekChild("newfirstcharge_btn_close");
this.btn_recharge = this.seekChild("newfirstcharge_btn_bottom");
this.loadRes(PathTool.getUIIconPath("newfirstcharge", "newfirstcharge_btn_bottom"), function (res) {
this.btn_recharge.getComponent(cc.Sprite).spriteFrame = res;
}.bind(this));
this.recharge_6_nd = this.seekChild("toggle1");
this.recharge_6_lb = this.seekChild(this.recharge_6_nd, "Label", cc.Label);
this.recharge_100_nd = this.seekChild("toggle2");
this.recharge_100_lb = this.seekChild(this.recharge_100_nd, "Label", cc.Label);
this.text_rt = this.seekChild("Text", cc.RichText);
this.text_rt.string = Utils.TI18N("机会仅1次!以下仅可选择一个充值档位获得四倍钻石!");
this.recharge_6_lb.string = Utils.TI18N("首充赠礼");
this.recharge_100_lb.string = Utils.TI18N("100元赠礼");
this.tab_view = [this.recharge_6_nd, this.recharge_100_nd];
this.remain_charge = this.seekChild("recharge_num", cc.Label);
this.remain_charge.string = Utils.TI18N("已累充: ");
var _loop = function _loop(_i) {
_this.tab_view[_i].index = _i;
_this.tab_view[_i].on("toggle", function (event) {
this.changeTabView(_i);
}, _this);
};
for (var _i = 0; _i < this.tab_view.length; ++_i) {
_loop(_i);
}
this.model.setFirstRechargeNewData();
this.recharge_info_nd = this.seekChild("rechargeInfo");
this.help_nd = this.seekChild(this.recharge_info_nd, "help");
for (var i = 1; i <= 3; i++) {
var item = this.recharge_info_nd.getChildByName("item_" + i);
if (item) {
var object = {};
object.scroll = item.getChildByName("scroll").getChildByName("content");
object.finish_icon = item.getChildByName("finish_icon");
object.finish_icon.active = false;
object.title = item.getChildByName("title").getComponent(cc.Label);
object.title.string = Utils.TI18N("第") + i + Utils.TI18N("天免费领");
object.list = {};
this.item_list[i] = object;
}
}
this.btn_label = this.btn_recharge.getChildByName("Label").getComponent(cc.Label);
this.btn_label.string = Utils.TI18N("前往充值");
var chargeBtn = this.seekChild("newfirstcharge_effect");
var _loop2 = function _loop2(_i2) {
var obj = {};
obj.node = chargeBtn.getChildByName("charge_item_" + _i2);
obj.node.active = false;
obj.bg = obj.node.getComponent(cc.Sprite);
obj.node.getChildByName("title_img").getChildByName("num").getComponent(cc.Label).string = Utils.TI18N("4倍");
obj.rmbNum = obj.node.getChildByName("layout").getChildByName("rmb").getComponent(cc.Label);
obj.goldNum = obj.node.getChildByName("layout").getChildByName("goldIcon").getChildByName("goldNum").getComponent(cc.Label);
obj.referral = obj.node.getChildByName("referral");
obj.referral.active = false;
_this.recharge_list[_i2] = obj;
var icon_sp = obj.node.getChildByName("layout").getChildByName("goldIcon").getChildByName("gold").getComponent(cc.Sprite);
_this.loadRes(PathTool.getItemRes("3"), function (res) {
icon_sp.spriteFrame = res;
});
obj.node.on('click', function () {
Utils.playButtonSound(1);
var config = Config.charge_data.data_quadruple_rebate[_i2];
SDK.pay(config.val, null, config.charge_id, config.name, config.name);
}, _this);
};
for (var _i2 = 1; _i2 < 5; ++_i2) {
_loop2(_i2);
}
},
// 注册事件监听的接口,不需要手动调用,如果是使用gcore.GlobalEvent监听,可以直接调用addGlobalEvent
registerEvent: function registerEvent() {
this.addGlobalEvent(NewFirstChargeEvent.New_First_Charge_Event, function (data) {
this.updata_charge_data = data;
var role_vo = RoleController.getInstance().getRoleVo();
var totle_str = cc.js.formatStr(Utils.TI18N("已累充: %d"), Math.floor(role_vo.vip_exp * 0.1));
this.remain_charge.string = totle_str;
this.setRedPointTab();
this.updateData(data);
}.bind(this));
this.close_btn.on("click", function () {
Utils.playButtonSound(2);
this.ctrl.openNewFirstChargeView(false);
}, this);
this.btn_recharge.on('click', function () {
var first_data = this.model.getFirstRechargeData(this.cur_node.index + 1);
if (this.get_gift_id == 0) {
this.setVisible(false);
VipController.getInstance().openVipMainWindow(true, VIPTABCONST.CHARGE, null, function () {
this.setVisible(true);
}.bind(this));
} else if (this.get_gift_id == 1) {
if (first_data[this.gift_index]) {
this.ctrl.sender21001(first_data[this.gift_index].id);
}
} else {
this.ctrl.openNewFirstChargeView(false);
}
}, this);
this.help_nd.on("click", function (event) {
Utils.playButtonSound(3);
var config = Config.holiday_client_data.data_constant.shouchong_rules;
var pos = event.node.convertToWorldSpaceAR(cc.v2(0, 0));
require("tips_controller").getInstance().showCommonTips(config.desc, pos);
}, this);
this.role_vo = RoleController.getInstance().getRoleVo();
if (this.role_assets_event == null) {
this.role_assets_event = this.role_vo.bind(EventId.UPDATE_ROLE_ATTRIBUTE, function (key, value) {
if (key == "vip_exp") {
this.updateData();
}
}.bind(this));
}
},
// 预制体加载完成之后,添加到对应主节点之后的回调,也就是一个窗体的正式入口,可以设置一些数据了
openRootWnd: function openRootWnd(index) {
index = index || 1;
this.tab_view[index - 1].getComponent(cc.Toggle).check();
if (index == 1) {
this.changeTabView(index - 1);
}
this.ctrl.sender21000();
},
changeTabView: function changeTabView(index) {
var temp = this.cur_node;
if (temp) {
temp.getChildByName("Label").color = this.notSelect;
} else {
for (var i = 0; i < this.tab_view.length; ++i) {
this.tab_view[i].getChildByName("Label").color = this.notSelect;
}
}
this.cur_node = this.tab_view[index];
this.cur_node.getChildByName("Label").color = this.select;
var first_data = this.model.getFirstRechargeData(index + 1);
this.fillItemList(first_data);
if (this.updata_charge_data) {
this.updateData(this.updata_charge_data);
}
},
updateData: function updateData() {
var _this2 = this;
var status_list = [[1, 2, 3], [4, 5, 6]];
var charge_list = [];
var index = this.cur_node.index;
for (var _i3 = 0; _i3 < status_list[index].length; ++_i3) {
var status = this.model.getFirstBtnStatus(status_list[index][_i3]);
charge_list[_i3] = status;
this.item_list[parseInt(_i3) + 1].finish_icon.active = status == 2;
}
this.gift_index = 0; //领取的位置
var totle = 0;
this.get_gift_id = 10;
for (var i = 0; i < charge_list.length; ++i) {
totle = totle + charge_list[i];
if (charge_list[i] == 1) {
this.get_gift_id = 1;
this.gift_index = i;
}
}
this.btn_recharge.active = false;
var role_vo = RoleController.getInstance().getRoleVo();
if (role_vo.vip_exp * 0.1 < 6) {
var _loop3 = function _loop3(_i4) {
var config = Config.charge_data.data_quadruple_rebate[_i4];
var obj = _this2.recharge_list[_i4];
obj.node.active = true;
obj.rmbNum.string = Utils.TI18N(config.val + "元");
obj.goldNum.string = config.gold;
if (config.star == 1) {
obj.referral.active = true;
_this2.loadRes(PathTool.getUIIconPath("newfirstcharge", "newfirstcharge_btn_top"), function (res) {
obj.bg.spriteFrame = res;
}.bind(_this2));
} else {
obj.referral.active = false;
_this2.loadRes(PathTool.getUIIconPath("newfirstcharge", "newfirstcharge_btn_bottom"), function (res) {
obj.bg.spriteFrame = res;
}.bind(_this2));
}
};
for (var _i4 in this.recharge_list) {
_loop3(_i4);
}
} else {
this.text_rt.string = Utils.TI18N("累充100元可领取更多豪礼!");
for (var _i5 in this.recharge_list) {
var obj = this.recharge_list[_i5];
obj.node.active = false;
}
this.btn_recharge.active = true;
if (totle == 0) {
this.get_gift_id = 0;
this.btn_label.string = Utils.TI18N("前往充值");
} else if (totle == 1 || totle == 3 || totle == 5) {
this.btn_label.string = Utils.TI18N("领取奖励");
} else if (totle == 2 || totle == 4) {
this.btn_label.string = Utils.TI18N("明日再来");
} else if (totle == 6) {
this.btn_label.string = Utils.TI18N("领取完毕");
}
}
},
setRedPointTab: function setRedPointTab() {
var status_1 = false;
for (var i = 1; i <= 3; i++) {
var get_data = this.model.getFirstBtnStatus(i);
if (get_data) {
if (get_data == 1) {
status_1 = true;
break;
}
}
}
Utils.addRedPointToNodeByStatus(this.tab_view[0], status_1);
var status_2 = false;
for (var i = 4; i <= 6; i++) {
var get_data = this.model.getFirstBtnStatus(i);
if (get_data) {
if (get_data == 1) {
status_2 = true;
break;
}
}
}
Utils.addRedPointToNodeByStatus(this.tab_view[1], status_2);
},
fillItemList: function fillItemList(list) {
var _this3 = this;
var scale = 0.7;
var size = 119 * scale;
var create_index = 1;
for (var i = 0; i < list.length; i++) {
var object = this.item_list[i + 1];
var num = list[i].item_list.length;
object.scroll.setContentSize(cc.size(size * num + (list.length - 1) * 10, object.scroll.getContentSize().height));
for (var k = 0; k < num; k++) {
var _x = size * (k + 1) - size * 0.5 + k * 10;
var _y = size * 0.5;
if (!this.item_reward_list[i + 1][k]) {
this.item_reward_list[i + 1][k] = ItemsPool.getInstance().getItem("backpack_item");
this.item_reward_list[i + 1][k].setParent(object.scroll);
this.item_reward_list[i + 1][k].setExtendData({
scale: scale,
is_show_tips: true
});
this.item_reward_list[i + 1][k].show();
if (list[i].effect_list) {
var spine = new cc.Node().addComponent(sp.Skeleton);
object.scroll.addChild(spine.node, 6 + create_index);
this.effect_list[create_index - 1] = spine;
spine.node.active = false;
}
}
if (this.item_reward_list[i + 1][k]) {
this.item_reward_list[i + 1][k].setPosition(_x, _y);
this.item_reward_list[i + 1][k].setData({
bid: list[i].item_list[k][0],
num: list[i].item_list[k][1]
});
this.effect_list[create_index - 1].node.active = true;
this.effect_list[create_index - 1].node.setPosition(_x, _y);
if (list[i].effect_list) {
(function () {
var effect_action = "action";
var scale1 = 1.0;
if (list[i].effect_list[0][k] == 263) {
effect_action = "action1";
scale1 = 1.1;
}
_this3.effect_list[create_index - 1].node.scale = scale * scale1;
var index = create_index - 1;
_this3.loadRes(PathTool.getSpinePath(PathTool.getEffectRes(list[i].effect_list[0][k])), function (res) {
this.effect_list[index].skeletonData = res;
this.effect_list[index].setAnimation(0, effect_action, true);
}.bind(_this3));
})();
}
}
create_index = create_index + 1;
}
}
},
// 关闭窗体回调,需要在这里调用该窗体所属controller的close方法没用于置空该窗体实例对象
closeCallBack: function closeCallBack() {
if (this.item_reward_list) {
for (var i = 1; i <= 3; i++) {
for (var j in this.item_reward_list[i]) {
this.item_reward_list[i][j].deleteMe();
this.item_reward_list[i][j] = null;
}
this.item_reward_list[i] = null;
}
this.item_reward_list = null;
}
if (this.role_vo != null) {
if (this.role_assets_event != null) {
this.role_vo.unbind(this.role_assets_event);
this.role_assets_event = null;
}
}
if (this.effect_list) {
for (var _i6 = 0; _i6 < this.effect_list.length; ++_i6) {
if (this.effect_list[_i6]) {
this.effect_list[_i6].destroy();
this.effect_list[_i6] = null;
}
}
this.effect_list = null;
}
var GuideEvent = require("guide_event");
gcore.GlobalEvent.fire(GuideEvent.CloseTaskEffect);
this.ctrl.openNewFirstChargeView(false);
}
});
cc._RF.pop();