141 lines
3.0 KiB
JavaScript
141 lines
3.0 KiB
JavaScript
const ActBase = require( "act.base" );
|
|
|
|
const ActExchange = cc.Class( {
|
|
|
|
extends: ActBase,
|
|
|
|
// 初始化配置数据
|
|
initConfig: function() {
|
|
|
|
// 视图附着
|
|
nx.plugin.add( this, [ "view" ] );
|
|
this.vattach( "Acts" );
|
|
|
|
},
|
|
|
|
// 注册协议接受事件
|
|
registerProtocals: function() {
|
|
|
|
// // // 前端准备完毕
|
|
this.RegisterProtocal( 14120, this.dealBaseInfoBack.bind( this ) );
|
|
this.RegisterProtocal( 14121, this.dealExchangeDatas.bind( this ) );
|
|
this.RegisterProtocal( 14122, this.getFreeBack.bind( this ) );
|
|
},
|
|
|
|
// 从服务器初始化数据
|
|
reqBaseFromServer: function( _cb ) {
|
|
|
|
let cfgs = [
|
|
this.data.config,//付費活動
|
|
]
|
|
this.loadConfigs( cfgs, ( _ret, _data ) =>{
|
|
|
|
nx.dt.fnInvoke( _cb, true );
|
|
this.reqBaseInfo( this.data.camp_id );
|
|
} )
|
|
|
|
},
|
|
|
|
reqBaseInfo: function( _id ){
|
|
|
|
let protocal = {
|
|
camp_id : _id
|
|
};
|
|
this.SendProtocal( 14120, protocal );
|
|
|
|
},
|
|
|
|
// 請求基礎信息返回
|
|
dealBaseInfoBack: function( _data ){
|
|
|
|
this.vset( "exchangeInfo", _data );
|
|
this.openTip( "reward", _data.is_free == 0 );
|
|
},
|
|
|
|
// 請求兌換
|
|
reqExchange: function( _id ){
|
|
|
|
let info = {
|
|
camp_id : this.data.camp_id,
|
|
id : _id
|
|
}
|
|
this.SendProtocal( 14121, info );
|
|
},
|
|
|
|
// 請求領取免費
|
|
reqGetFree: function(){
|
|
|
|
let info = {
|
|
camp_id : this.data.camp_id,
|
|
}
|
|
this.SendProtocal( 14122, info );
|
|
},
|
|
|
|
getFreeBack: function( _data ){
|
|
|
|
},
|
|
|
|
|
|
|
|
// 處理相關的配置
|
|
dealExchangeDatas: function( _data ){
|
|
|
|
|
|
if( _data.code == 0 ){
|
|
nx.tbox( _data.msg );
|
|
}
|
|
// let cfg = game.configs.exchange_data.data_shop_exchange_gold;
|
|
|
|
},
|
|
|
|
getFreeInfo: function( _data ){
|
|
|
|
let free = null;
|
|
let cfg = gdata( this.data.config, "data_shop_exchange_cost" );
|
|
if( cfg ){
|
|
free = cfg.daily_gift.val;
|
|
}
|
|
|
|
return free;
|
|
},
|
|
|
|
getExchangeInfo: function(){
|
|
|
|
let cfg = gdata( this.data.config, "data_shop_exchange_gold" );
|
|
let list = [];
|
|
|
|
for (let i in cfg ) {
|
|
if( i == this.data.camp_id ){
|
|
let item = cfg[i];
|
|
for (let c in item ) {
|
|
let citem = item[c];
|
|
if( citem.camp_id == this.data.camp_id ){
|
|
list.push( citem );
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
},
|
|
|
|
getExtraInfo: function(){
|
|
|
|
let cfg = gdata( this.data.config, "data_shop_exchange_show" );
|
|
let info = {};
|
|
for (let i in cfg ) {
|
|
let item = cfg[i];
|
|
if( item.camp_id == this.data.camp_id ){
|
|
info = item;
|
|
}
|
|
}
|
|
return info;
|
|
},
|
|
|
|
} );
|
|
|
|
// 模块导出
|
|
module.exports = ActExchange; |