262 lines
7.6 KiB
JavaScript
262 lines
7.6 KiB
JavaScript
"use strict";
|
|
cc._RF.push(module, '8919azt99BAm7PL+qe4L7t1', 'cmp.act.firstcharge');
|
|
// Scripts/mod/acts/firstcharge/cmp/cmp.act.firstcharge.js
|
|
|
|
"use strict";
|
|
|
|
var _FID_TOP_BG, _FID_CHONG, _FID_CURVAL_BG;
|
|
// /******************************************************************
|
|
// *
|
|
// * 首充禮包
|
|
// *
|
|
// ******************************************************************/
|
|
|
|
var BasePage = require("act.page.base");
|
|
var NxTogs = require("nx.fx.togs");
|
|
var NxSpine = require("nx.fx.spine");
|
|
var PathTool = require("pathtool");
|
|
var Payment = require("payment.mod");
|
|
var FID_TOP_BG = (_FID_TOP_BG = {}, _FID_TOP_BG[1] = "bg_charge_3_9", _FID_TOP_BG[2] = "bg_charge_2_9", _FID_TOP_BG);
|
|
var FID_CHONG = (_FID_CHONG = {}, _FID_CHONG[1] = "bg_charge_6", _FID_CHONG[2] = "bg_charge_7", _FID_CHONG);
|
|
var FID_CURVAL_BG = (_FID_CURVAL_BG = {}, _FID_CURVAL_BG[1] = "bg_charge_9", _FID_CURVAL_BG[2] = "bg_charge_8", _FID_CURVAL_BG);
|
|
cc.Class({
|
|
"extends": BasePage,
|
|
properties: {
|
|
frontBgs: {
|
|
"default": null,
|
|
type: cc.Node
|
|
},
|
|
behindBgs: {
|
|
"default": null,
|
|
type: cc.Node
|
|
},
|
|
togs: {
|
|
"default": null,
|
|
type: NxTogs
|
|
},
|
|
topTar: {
|
|
//頂層標題背景
|
|
"default": null,
|
|
type: cc.Node
|
|
},
|
|
topNd: {
|
|
"default": null,
|
|
type: cc.Node
|
|
},
|
|
chongTar: {
|
|
//充字標題背景
|
|
"default": null,
|
|
type: cc.Node
|
|
},
|
|
curTar: {
|
|
//當前價格背景
|
|
"default": null,
|
|
type: cc.Node
|
|
},
|
|
totalVal: {
|
|
//原來的總價值
|
|
"default": null,
|
|
type: cc.Node
|
|
},
|
|
curVal: {
|
|
//當前的價值
|
|
"default": null,
|
|
type: cc.Node
|
|
},
|
|
rechangeVal: {
|
|
//此時的充值價值
|
|
"default": null,
|
|
type: cc.Node
|
|
},
|
|
list: {
|
|
"default": null,
|
|
type: cc.Node
|
|
},
|
|
items: {
|
|
"default": [],
|
|
type: [cc.Node]
|
|
},
|
|
role1: {
|
|
"default": null,
|
|
type: NxSpine
|
|
},
|
|
role2: {
|
|
"default": null,
|
|
type: NxSpine
|
|
},
|
|
btnBuy: {
|
|
"default": null,
|
|
type: cc.Node
|
|
}
|
|
},
|
|
// 初始化
|
|
build: function build(_data) {
|
|
this._super(_data);
|
|
|
|
// 无效
|
|
if (!this.mod) {
|
|
return;
|
|
}
|
|
this.charge_data = game.configs.charge_data.data_new_first_charge_data3;
|
|
this.select_index = 1; //fid
|
|
this.togs.posTog = this.onTogMenu.bind(this);
|
|
this.togs.togTo(0);
|
|
// 活动监听
|
|
this.mod.vbind(this, [["firstCharge", this.freshInfos.bind(this)]]);
|
|
|
|
// 请求信息
|
|
this.setMainInfo();
|
|
},
|
|
onEnable: function onEnable() {
|
|
var _this = this;
|
|
var nds = this.togs.togs;
|
|
var idx = 1;
|
|
for (var i = 0; i < nds.length; i++) {
|
|
var nd = nds[i];
|
|
for (var j in this.charge_data) {
|
|
if (this.charge_data[j].fid == idx) {
|
|
nx.gui.setString(nd, "off/txt", this.charge_data[j].desc);
|
|
nx.gui.setString(nd, "on/txt", this.charge_data[j].desc);
|
|
|
|
//tip
|
|
var dot = nx.gui.getComponent(nd, "tip", "nx.vb.visible");
|
|
if (!dot) {
|
|
nx.gui.setActive(dot, "", false);
|
|
} else {
|
|
var key = this.mod.getTipKey(this.mod.tipKeys()[i]);
|
|
dot.setTarget(nx.mTip, key);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
idx++;
|
|
}
|
|
this.scheduleOnce(function () {
|
|
var res_path1 = PathTool.getSpinePath("H30100", "show", false);
|
|
_this.role1.load(res_path1, function (_e) {
|
|
if (!_e) {
|
|
_this.role1.action("action1", true);
|
|
} else {
|
|
_this.role1.stop();
|
|
}
|
|
});
|
|
var res_path2 = PathTool.getSpinePath("H30099", "show", false);
|
|
_this.role2.load(res_path2, function (_e) {
|
|
if (!_e) {
|
|
_this.role2.action("action1", true);
|
|
} else {
|
|
_this.role2.stop();
|
|
}
|
|
});
|
|
}, 0.2);
|
|
},
|
|
// 销毁
|
|
onDestroy: function onDestroy() {
|
|
// 活动监听解除
|
|
if (this.mod) {
|
|
this.mod.vunbind(this);
|
|
}
|
|
this._super();
|
|
},
|
|
onTogMenu: function onTogMenu(_index) {
|
|
this.select_index = _index + 1;
|
|
this.setMainInfo();
|
|
var gfits = this.mod.vget("firstCharge");
|
|
this.freshInfos(gfits);
|
|
},
|
|
freshInfos: function freshInfos(_data) {
|
|
if (nx.dt.arrEmpty(_data)) return;
|
|
var cur_list = [];
|
|
var is_buy = false;
|
|
for (var i in this.charge_data) {
|
|
if (this.charge_data[i].fid == this.select_index) {
|
|
var award_status = 0;
|
|
for (var id in _data) {
|
|
is_buy = _data[id].status == 0;
|
|
if (_data[id].id == this.charge_data[i].id) {
|
|
award_status = _data[id].status;
|
|
break;
|
|
}
|
|
}
|
|
cur_list.push({
|
|
cfg: this.charge_data[i],
|
|
status: award_status
|
|
});
|
|
}
|
|
}
|
|
cur_list.sort(function (a, b) {
|
|
return a.cfg.day - b.cfg.day;
|
|
});
|
|
this.refreshItems(cur_list);
|
|
nx.gui.setActive(this.btnBuy, "", is_buy);
|
|
},
|
|
refreshItems: function refreshItems(cur_list) {
|
|
nx.bridge.NodeChidrenDestroy(this.list);
|
|
var fab = this.items[this.select_index - 1];
|
|
if (fab) {
|
|
for (var i = 0; i < cur_list.length; i++) {
|
|
var item = cc.instantiate(fab);
|
|
item.parent = this.list;
|
|
item.x = 0;
|
|
var cmp = nx.gui.getComponent(item, "", "cmp.act.firstcharge.item");
|
|
if (cmp) {
|
|
cmp.rebind(i, cur_list[i], this.mod);
|
|
}
|
|
}
|
|
}
|
|
},
|
|
setMainInfo: function setMainInfo() {
|
|
var use_data = null;
|
|
for (var i in this.charge_data) {
|
|
if (this.charge_data[i].fid == this.select_index) {
|
|
use_data = this.charge_data[i];
|
|
break;
|
|
}
|
|
}
|
|
nx.gui.setActive(this.frontBgs, "1", this.select_index == 1);
|
|
// nx.gui.setActive(this.behindBgs,"1",this.select_index == 1);
|
|
nx.gui.setActive(this.frontBgs, "2", this.select_index == 2);
|
|
nx.gui.setActive(this.behindBgs, "2", this.select_index == 2);
|
|
nx.gui.setActive(this.topNd, "ti1", this.select_index == 1);
|
|
nx.gui.setActive(this.topNd, "ti2", this.select_index == 2);
|
|
nx.gui.setActive(this, "tnd1", this.select_index == 1);
|
|
nx.gui.setActive(this, "tnd2", this.select_index == 2);
|
|
nx.gui.setActive(this.role1.node, "", this.select_index == 2);
|
|
nx.gui.setActive(this.role2.node, "", this.select_index == 1);
|
|
if (!use_data) return;
|
|
nx.gui.setSpriteFrame(this.topTar, "", cc.js.formatStr("prefab/acts/firstcharge/ui/%s", FID_TOP_BG[this.select_index]));
|
|
nx.gui.setSpriteFrame(this.chongTar, "", cc.js.formatStr("prefab/acts/firstcharge/ui/%s", FID_CHONG[this.select_index]));
|
|
nx.gui.setSpriteFrame(this.curTar, "", cc.js.formatStr("prefab/acts/firstcharge/ui/%s", FID_CURVAL_BG[this.select_index]));
|
|
var yprice = Payment.getInstance().fmtPrice(use_data.desc1);
|
|
nx.gui.setString(this.totalVal, "", yprice);
|
|
var cprice = Payment.getInstance().fmtPrice(use_data.desc2);
|
|
nx.gui.setString(this.curVal, "", cprice);
|
|
// if( this.select_index == 1 ) {
|
|
// this.curVal.color = new cc.Color( 108, 247, 6 );
|
|
// } else {
|
|
// this.curVal.color = new cc.Color( 108, 247, 6 );
|
|
// }
|
|
|
|
//充值总金额
|
|
var total = nx.bridge.vget("TotalCharge");
|
|
var show = Payment.getInstance().fmtPrice(total);
|
|
nx.gui.setString(this.rechangeVal, "", show);
|
|
},
|
|
onClickBuy: function onClickBuy() {
|
|
var charge_id = null;
|
|
for (var i in this.charge_data) {
|
|
if (this.charge_data[i].fid == this.select_index) {
|
|
charge_id = this.charge_data[i].need_exp;
|
|
break;
|
|
}
|
|
}
|
|
if (charge_id == null) return;
|
|
if (this.select_index == 1) {
|
|
Payment.getInstance().reqPayment(charge_id);
|
|
} else if (this.select_index == 2) {
|
|
Payment.getInstance().reqPayment(charge_id);
|
|
}
|
|
}
|
|
});
|
|
|
|
cc._RF.pop(); |