/****************************************************************** * * VIP页面 * ******************************************************************/ const MenuPage = require( "cmp.com.menu.page" ); const VipController = require( "vip_controller" ); const TipsController = require( "tips_controller" ); const Payment = require( "payment.mod" ); const NxSpine = require( "nx.fx.spine" ); cc.Class( { extends: MenuPage, properties: { nodGifts: { default: null, type: cc.Node }, nodScores: { default: null, type: cc.Node }, nodOp: {default: null, type: cc.Node }, spRole: { default: null, type: NxSpine }, nodCloseAllDesc : {default: null, type: cc.Node }, }, onLoad: function(){ this.cfg = game.configs.daily_charge_data; this.spRole.load( "resDB/models/H30098/show", ( _e ) => { if( !_e ) { this.spRole.action( "drama1", true ); } else { this.spRole.stop(); } } ); // let let count = Object.keys( this.cfg.data_gift_info ).length; let rewards = nx.gui.find( this.nodScores, "rewards" ).children; let len = Object.keys( this.cfg.data_reward ).length; this.total = this.cfg.data_reward[len].num; nx.gui.setString( this.nodScores, "point/num", 0 ); nx.gui.getComponent( this.nodScores, "prog", cc.ProgressBar ).progress = 0; nx.gui.gocChildren( this.nodGifts, "", count ); // nx.gui.setString( this.nodOp, "now/cost", Payment.getInstance().fmtPrice(this.cfg.data_constant.sevenday_charge_price.val ) ); // nx.gui.setString( this.nodOp, "now/before", Payment.getInstance().fmtPrice( 147 ) ); for (let i = 0; i < rewards.length; i++) { let nod = this.nodGifts.children[i]; let giftinfo = this.cfg.data_gift_info[ i+1 ]; if( giftinfo ){ let cmp = nx.gui.getComponent( nod, "items", "cmp.common.itemlayout" ); if( cmp ){ cmp.rebuild( giftinfo.reward ); } nx.gui.find( nod, "buy" ).zIndex = giftinfo.id; nx.gui.setString( nod, "buy/cost", giftinfo.money == 0 ? nx.text.getKey( "Free" ) : nx.text.format( "CostDay", Payment.getInstance().fmtPrice( giftinfo.money ) ) ); nx.gui.setActive( nod, "sold", false ); } let reward = rewards[i]; let rewardinfo = this.cfg.data_reward[ i+1 ]; if( reward && rewardinfo ){ nx.gui.setString( reward, "point", rewardinfo.num ); //payment.daily.free let cmp = nx.gui.getComponent( reward, "show/rewards", "cmp.common.itemlayout" ); if( cmp ){ cmp.rebuild( rewardinfo.reward ); } nx.gui.find( reward, "touch" ).zIndex = rewardinfo.id; nx.gui.setActive( reward, "get", false ); nx.gui.find( reward, "get" ).zIndex = rewardinfo.id; nx.gui.setActive( reward, "ico_open", false ); nx.gui.setActive( reward, "show", false ); // nx.gui.setActive( reward, "tip", giftinfo.money == 0 ); } } nx.gui.setActive( this.nodCloseAllDesc, "", false ); this.vbind( [ [ "DailySpGift", this.onFreshBuyInfo.bind( this ) ], ] ); }, onEnable: function(){ VipController.getInstance().reqDailySpGift(); }, onTouchHideAllDesc: function(){ let chd = nx.gui.find( this.nodScores, "rewards" ).children; for (let i = 0; i < chd.length; i++) { let nod = chd[i]; nx.gui.setActive( nod, "show", false ); } nx.gui.setActive( this.nodCloseAllDesc, "", false ); }, onTouchShow: function( _btn ){ let index = parseInt( _btn.zIndex - 1); let chd = nx.gui.find( this.nodScores, "rewards" ).children; for (let i = 0; i < chd.length; i++) { let nod = chd[i]; if( i != index ){ nx.gui.setActive( nod, "show", false ); } } let nodShow = nx.gui.find( chd[index], "show" ); nx.gui.setActive( nodShow, "", !nodShow.active ); nx.gui.setActive( this.nodCloseAllDesc, "", nodShow.active == true ); }, /*** * [21041]:{"gift":[{"id":1,"status":2},{"id":2,"status":0},{"id":3,"status":0}],"num":0,"ids":[],"is_activate":0} */ onFreshBuyInfo: function( _buyinfo ){ if( !_buyinfo ){ return; } this.gifts = _buyinfo.gift; this.chargestatus = _buyinfo.is_activate; if( nx.dt.arrNEmpty( this.gifts ) ){ this.gifts.forEach( _gift =>{ if( _gift ){ nx.gui.setString( this.nodGifts.children[ _gift.id - 1 ], "buy/cost", _gift.status != 0 ? nx.text.getKey( "Get" ) : nx.text.format( "CostDay", Payment.getInstance().fmtPrice( this.cfg.data_gift_info[ _gift.id ].money ) ) ); nx.gui.setActive( this.nodGifts.children[ _gift.id - 1 ], "buy", _gift.status != 2 ); nx.gui.setActive( this.nodGifts.children[ _gift.id - 1 ], "buy/tip", _gift.status != 2 && ( _gift.id - 1 == 0 ) ); nx.gui.setActive( this.nodGifts.children[ _gift.id - 1 ], "sold", _gift.status == 2 ); if( _gift.id == 2 ){ nx.gui.setString( this.nodGifts.children[ _gift.id - 1 ], "sold/txt", nx.text.format( "RemainDay", _buyinfo.is_activate ) ); }else if( _gift.id == 3 ){ nx.gui.setString( this.nodGifts.children[ _gift.id - 1 ], "sold/txt", nx.text.format( "RemainDay", _buyinfo.end_day ) ); }else{ nx.gui.setString( this.nodGifts.children[ _gift.id - 1 ], "sold/txt", nx.text.getKey( "Got" ) ); } } } ) } nx.gui.setString( this.nodScores, "point/num", _buyinfo.num ); // nx.gui.setActive( this.nodOp, "charged", _buyinfo.is_activate == 1 ); // nx.gui.setActive( this.nodOp, "now", _buyinfo.is_activate == 0 ); nx.gui.getComponent( this.nodScores, "prog", cc.ProgressBar ).progress = _buyinfo.num / ( this.total ); this.freshReward( _buyinfo.ids, _buyinfo.num ); // nx.gui.setActive(); // console.log( "購買信息" + JSON.stringify( _buyinfo ) ); }, freshReward: function( _rewards, _num ){ let rewards = _rewards; let num = _num; let rewardinfo = this.cfg.data_reward; let nodrewards = nx.gui.find( this.nodScores, "rewards" ).children; if( nx.dt.arrEmpty( rewards ) ){ for (let i in rewardinfo ) { let reward = rewardinfo[i]; if( reward ){ nx.gui.setActive( nodrewards[reward.id - 1] , "get", num >= reward.num ); } } }else{ for (let i in rewardinfo ) { let reward = rewardinfo[i]; if( reward ){ nx.gui.setActive( nodrewards[reward.id - 1] , "get", num >= reward.num ); } rewards.forEach( _re =>{ nx.gui.setActive( nodrewards[ _re.id - 1 ] , "get", false ); } ) } } }, //[21041]:{"gift":[{"id":1,"status":0},{"id":2,"status":0},{"id":3,"status":0}],"num":0,"ids":[],"is_activate":0} onTouchBuy: function( _btn ){ let id = _btn.zIndex; let chargeid = this.cfg.data_gift_info[ id ].charge_id; if( this.gifts[id-1].status == 0 ){ if( id != 1 ){ let msg = "pay " + chargeid; Payment.getInstance().reqPayment( chargeid ); }else{ VipController.getInstance().reqGetDailySpGift( id ); } }else{ VipController.getInstance().reqGetDailySpGift( id ); } }, onTouchBuyOnce: function( _btn ){ if( this.chargestatus != 0 ){ nx.tbox( "Charged" ); return; } let chargeid = this.cfg.data_constant.sevenday_charge.val let msg = "pay " + chargeid; Payment.getInstance().reqPayment( chargeid ); }, onTouchGet: function( _btn ){ let id = _btn.zIndex; VipController.getInstance().reqGetDailyReward( id ); }, onTouchHelp: function(){ let TC = TipsController.getInstance(); let explain = this.cfg.data_desc[1]; TC.showTextPanel( explain.name, explain.desc ); }, } );