// -------------------------------------------------------------------- // @author: xxx@syg.com(必填, 创建模块的人员) // @description: // 这里填写详细说明,主要填写该模块的功能简要 //
Create: 2019-03-06 20:33:19 // -------------------------------------------------------------------- const BridgeController = require( "bridge.controller" ); const DispatchConst = require( "dispatch.const" ); const DispatchMod = cc.Class( { extends: BridgeController, ctor: function() { }, // 初始化配置数据 initConfig: function() { var DispatchModel = require( "dispatch.model" ); this.model = new DispatchModel(); this.model.initConfig(); }, // 返回当前的model getModel: function() { return this.model; }, // 注册协议接受事件 registerProtocals: function() { this.RegisterProtocal( 23800, this.handle23800 ) // 远航数据(订单、刷新次数等) this.RegisterProtocal( 23801, this.handle23801 ) // 远航订单数据 this.RegisterProtocal( 23802, this.handle23802 ) // 远航接取订单 this.RegisterProtocal( 23803, this.handle23803 ) // 远航完成订单 this.RegisterProtocal( 23804, this.handle23804 ) // 远航刷新订单 this.RegisterProtocal( 23805, this.handle23805 ) // 远航活动状态 this.RegisterProtocal( 23820, this.handle23820 ) // 远航记录返回 this.RegisterProtocal( 23821, this.handle23821 ) // 第一次弹出特权提示 this.RegisterProtocal( 23806, this.handle23806 ) // 一键领取 }, // 注册监听事件 registerEvents: function() { }, // 从服务器初始化数据 reqBaseFromServer: function( _cb ) { // 配置加载 let cfgs = [ "shipping_data", // 家园派遣 ]; this.loadConfigs( cfgs, ( _ret, _data ) => { nx.dt.fnInvoke( _cb, true ); this.requestActivityStatus(); this.reqData(); } ); }, // 请求远航数据 reqData: function( _cb ) { this.SendProtocal( 23800, {}, _cb ); }, // 远航数据(订单、刷新次数等) handle23800: function( _data ) { if( _data.order_list ) { this.model.setOrderList( _data.order_list ); } if( _data.free_times ) { this.model.setFreeTimes( _data.free_times ); } if( _data.coin_times ) { this.model.setCoinTimes( _data.coin_times ); } gcore.GlobalEvent.fire( DispatchConst.FreshData ); // 更新提示 this.freshViewTips(); }, // 请求接取订单 requestReceiveOrder: function( order_id, assign_ids, _cb ) { this.CB23802 = _cb; this.SendProtocal( 23802, { order_id: order_id, assign_ids: assign_ids, } ); }, // 接取订单返回 handle23802: function( _data ) { // 失败 if( nx.dt.objEmpty( _data ) || nx.dt.strNEmpty( _data.msg ) ) { nx.dt.fnInvoke( this.CB23802, false, _data ? _data.msg : "ErrFailed" ); this.CB23802 = null; return; } nx.dt.fnInvoke( this.CB23802, true ); this.CB23802 = null; }, // 请求完成订单 requestFinishOrder: function( order_id, type, _cb ) { this.CB23803 = _cb; this.SendProtocal( 23803, { order_id: order_id, type: type, } ); }, // 完成订单返回 handle23803: function( _data ) { // 失败 if( nx.dt.objEmpty( _data ) || nx.dt.strNEmpty( _data.msg ) ) { nx.dt.fnInvoke( this.CB23803, false, _data ? _data.msg : "ErrFailed" ); this.CB23803 = null; return; } if( _data.flag == 1 && _data.order_id ) { this.model.deleteOneOrderData( _data.order_id ); } nx.dt.fnInvoke( this.CB23803, true, this.stepData ); this.CB23803 = null; gcore.GlobalEvent.fire( DispatchConst.DeleteOrder ); // 更新提示 this.freshViewTips(); }, // 请求刷新 requestRefreshOrder: function() { this.SendProtocal( 23804, {} ) }, // 刷新订单返回 handle23804: function( _data ) { nx.tbox( _data.msg ); }, // 请求远航活动状态 requestActivityStatus: function() { var protocal = {}; this.SendProtocal( 23805, protocal ); }, //远航订单数据更新 handle23801: function( _data ) { this.model.updateOneOrderData( _data ); // 更新提示 this.freshViewTips(); }, //远航活动状态 handle23805: function( _data ) { if( _data.flag ) { this.model.setActivityStatus( _data.flag ); gcore.GlobalEvent.fire( DispatchConst.UpdateActivityStatusEvent ); this.freshViewTips(); } }, //远航第一次点击特权记录 send23820: function() { this.SendProtocal( 23820, {} ) }, handle23820: function( _data ) { }, //请求特权记录情况 send23821: function() { this.SendProtocal( 23821, {} ) }, handle23821: function( _data ) { this.model.setFirstFresh( _data.flag != 1 ); }, // 一键领取 requestQuickReceiveOrder: function( _cb ) { this.CB23806 = _cb; this.SendProtocal( 23806, {} ) }, // 一键领取 handle23806: function( _data ) { // 失败 if( nx.dt.objEmpty( _data ) || nx.dt.strNEmpty( _data.msg ) ) { nx.dt.fnInvoke( this.CB23806, false, _data ? _data.msg : "ErrFailed" ); this.CB23806 = null; return; } if( _data.flag ) { this.model.deleteSomeOrderData( _data.order_list ); } nx.dt.fnInvoke( this.CB23806, true ); this.CB23806 = null; gcore.GlobalEvent.fire( DispatchConst.DeleteOrder ); gcore.GlobalEvent.fire( DispatchConst.FreshData ); // 更新提示 this.freshViewTips(); }, // 提示刷新 freshViewTips: function() { let tip = false; let list = this.model.getAllOrderList(); for( let i in list ) { let order = list[i]; if( order && order.status == DispatchConst.Order_Status.Finish ) { tip = true; break; } } nx.mTip.openTip( "home.dispatch.reward", tip ); }, } ); module.exports = DispatchMod;