/****************************************************************** * * 日常任务模版 * ******************************************************************/ const ActPage = require( "act.page.base" ); const FxSVC = require( "nx.fx.sv.expand" ); const TipsController = require( "tips_controller" ); const BridgeItemBinder = require( "bridge.binder.item.icon.count" ); cc.Class( { extends: ActPage, properties: { lstTask: { default: null, type: FxSVC }, nodDate: { default: null, type: cc.Node }, nodItem1: { default: null, type: BridgeItemBinder }, nodItem2: { default: null, type: BridgeItemBinder }, }, // 初始化 build: function( _data ) { this._super( _data ); // 活动监听 this.mod.vbind( this, [ ["dailyTasks", this.freshTask.bind( this )], ] ); let items = this.mod.queryItemsConfig(); if( items ) { this.nodItem1.setID( items.item1 ); this.nodItem2.setID( items.item2 ); } }, onEnable: function() { // 更新一下 this.mod.reqBaseData(); // 刷新活动日期 let time = nx.bridge.time.toNeedTime( this.data.end_time ); nx.gui.setString( this.nodDate, "txt", time ); }, // 销毁 onDestroy: function() { // 活动监听解除 if( this.mod ) { this.mod.vunbind( this ); } this._super(); }, // 任务刷新 freshTask: function( _task, _old, _init ) { if( _init ) return; // 空 let cfgs = this.mod.queryTaskCfgs(); if( nx.dt.arrEmpty( _task ) || nx.dt.objEmpty( cfgs ) ) { this.lstTask.rebuild( [] ); return; } // 重建 this.tasks = []; for( let i = 0; i < _task.length; ++i ) { let task = nx.dt.objClone( _task[i] ); let info = cfgs[task.id]; task.day = info.day; task.title = info.title; task.desc = info.desc; task.progress = info.progress; task.award = info.award; task.jump_id = info.jump_id; task.mod = this.mod; this.tasks.push( task ); } // 0:未完成 1:已完成 2:已提交 let PR = [2, 1, 3]; this.tasks.sort( ( a, b ) => { if( a.finish == b.finish ) { return a.id - b.id; } return PR[a.finish] - PR[b.finish]; } ); this.lstTask.rebuild( this.tasks ); }, // 点击规则 onTouchRule: function() { let rule = this.mod ? this.mod.queryRule() : ""; if( nx.dt.strNEmpty( rule ) ) { const TC = TipsController.getInstance(); TC.showTextPanel( "tip", rule ); } }, // 点击商城 onTouchShop: function() { nx.bridge.jumper.jump2Window( 474 ); }, } );