/****************************************************************** * * 派遣任务项 * ******************************************************************/ const SVCItem = require( "nx.fx.sv.expand.item" ); const ItemBase = require( "cmp.item.base" ); const DispatchConst = require( "dispatch.const" ); const DispatchMod = require( "dispatch.mod" ); // 订单状态 const DSOS = DispatchConst.Order_Status; cc.Class( { extends: SVCItem, properties: { nodQA: { default: null, type: cc.Node }, nodDesc: { default: null, type: cc.Node }, nodCost: { default: null, type: cc.Node }, nodOps: { default: null, type: cc.Node }, icoReward: { default: null, type: ItemBase }, }, // 数据重置 rebind: function( _idx, _data, _key ) { this.unscheduleAllCallbacks(); // 订单监听解除 if( this.mdata && this.binder ) { this.mdata.unbind( this.binder ); this.binder = null; } this._super( _idx, _data, _key ); if( nx.dt.objEmpty( _data ) ) { return; } // 刷新 this.freshBase(); this.freshStatus(); // 订单监听 this.binder = this.mdata.bind( DispatchConst.UpdateOrder, this.freshStatus.bind( this ) ); }, // 隐藏 onDisable: function() { // 订单监听解除 if( this.mdata && this.binder ) { this.mdata.unbind( this.binder ); this.binder = null; } }, // 刷新基本信息 freshBase: function() { let cfgs = this.mdata.config; // 名字 let key = nx.text.getKey( cfgs.name ); nx.gui.setString( this.nodDesc, "", key ); // 底板 let path = cc.path.join( "prefab/home/dispatch/ui", "bg" + cfgs.quality ); nx.gui.setSpriteFrame( this, "bg", path ); // 图标底 path = cc.path.join( "prefab/home/dispatch/ui", "box" + cfgs.quality ); nx.gui.setSpriteFrame( this.nodQA, "", path ); // 图标 path = cc.path.join( "prefab/home/dispatch/ui", "qa" + cfgs.quality ); nx.gui.setSpriteFrame( this.nodQA, "icon", path ); // 奖励 let item = cfgs.award[ 0 ]; this.icoReward.setData( item ); // 消耗 let cost = cfgs.expend[ 0 ]; let info = gitemdata( cost[ 0 ] ); nx.bridge.setIconS( this.nodCost, "icon", info.icon ); nx.gui.setString( this.nodCost, "txt", cost[ 1 ] ); }, // 刷新状态 freshStatus: function() { // 操作隐藏 nx.gui.hideAllChildren( this.nodOps, "" ); this.unscheduleAllCallbacks(); switch( this.mdata.status ) { // 已完成 case DSOS.Finish: { nx.gui.setActive( this.nodOps, "get", true ); } break; // 进行中 case DSOS.Underway: { let btn = nx.gui.setActive( this.nodOps, "quick", true ); // 剩余时间 this.left_time = this.mdata.end_time - client.socket.getTime(); if( this.left_time < 0 ) { this.left_time = 0; } let self = this; let tick = function() { let txt = ""; if( self.left_time > 0 ) { txt = nx.bridge.time.cdSeconds( self.left_time ); self.left_time -= 1; } nx.gui.setString( btn, "cd", txt ); }; this.schedule( tick, 1, cc.macro.REPEAT_FOREVER ); tick(); // 花费 let DM = DispatchMod.getInstance().getModel(); let need = DM.getQuickFinishNeedGoldByTime( this.left_time ); nx.bridge.setIconS( btn, "btn/cost/icon", gitemdata( 3 ).icon ); nx.gui.setString( btn, "btn/cost/txt", need ); } break; // 未截取 default: { nx.gui.setActive( this.nodOps, "dispatch", true ); } break; } }, // 点击派遣 onTouchDispatch: function() { nx.bridge.createPanel( "WndDispatchPartnerSelector", this.mdata ); }, // 点击领取 onTouchReward: function() { let DC = DispatchMod.getInstance(); DC.requestFinishOrder( this.mdata.order_id, 0, ( _ret, _data ) => { if( !_ret ) { nx.tbox( _data ); return; } } ); }, // 点击快速完成 onTouchQuickDone: function() { let DC = DispatchMod.getInstance(); DC.requestFinishOrder( this.mdata.order_id, 1, ( _ret, _data ) => { if( !_ret ) { nx.tbox( _data ); return; } } ); }, } );