319 lines
10 KiB
JavaScript
319 lines
10 KiB
JavaScript
// --------------------------------------------------------------------
|
|
// @author: shiraho@syg.com(必填, 创建模块的人员)
|
|
// @description:
|
|
// 好友主界面
|
|
// <br/>Create: new Date().toISOString()
|
|
// --------------------------------------------------------------------
|
|
var FriendController = require( "friend_controller" );
|
|
var RoleController = require( "role_controller" );
|
|
var FriendConst = require( "friend_const" );
|
|
var FriendEvent = require( "friend_event" );
|
|
const FxSVC = require( "nx.fx.sv.expand" );
|
|
const FxTogs = require( "nx.fx.togs" );
|
|
var BridgeWindow = require( "bridge.window" )
|
|
|
|
cc.Class( {
|
|
extends: BridgeWindow,
|
|
|
|
properties: {
|
|
scrollCon: {
|
|
default: null,
|
|
type: FxSVC
|
|
},
|
|
togs: {
|
|
default: null,
|
|
type: FxTogs
|
|
},
|
|
view: {
|
|
default: null,
|
|
type: cc.Node
|
|
},
|
|
//好友数
|
|
friend_num: {
|
|
default: null,
|
|
type: cc.RichText
|
|
},
|
|
empty_con: {
|
|
default: null,
|
|
type: cc.Node
|
|
},
|
|
friend_views: {
|
|
default: [],
|
|
type: [ cc.Node ]
|
|
},
|
|
cost_panel: {
|
|
default: null,
|
|
type: cc.Node
|
|
},
|
|
cur_type: 0,
|
|
},
|
|
|
|
// LIFE-CYCLE CALLBACKS:
|
|
|
|
onLoad() {
|
|
this.model = FriendController.getInstance().getModel();
|
|
this.ctrl = FriendController.getInstance();
|
|
this.role_vo = RoleController.getInstance().getRoleVo();
|
|
this.rend_list = [];
|
|
|
|
//好友申请列表返回
|
|
this.bindGEvent( FriendEvent.FRIEND_APPLY, this.updateApplyFri.bind( this ) );
|
|
//赠送礼物返回
|
|
this.bindGEvent( FriendEvent.STRENGTH_UPDATE, this.FriendGiftRev.bind( this ) );
|
|
//删除好友
|
|
this.bindGEvent( FriendEvent.FRIEND_DELETE, this.delFriend.bind( this ) );
|
|
//添加好友
|
|
this.bindGEvent( FriendEvent.UPDATE_APPLY, this.addApplyFri.bind( this ) );
|
|
//更新好友数量
|
|
this.bindGEvent( FriendEvent.UPDATE_COUNT, this.updateFriNum.bind( this ) );
|
|
//好友数量变动(删除+被删)
|
|
this.bindGEvent( FriendEvent.UPDATE_GROUP_COUNT, this.changeFriNum.bind( this ) );
|
|
//有人来送礼物
|
|
this.bindGEvent( FriendEvent.FRIEND_LIST, this.revGiftBack.bind( this ) );
|
|
//更新红点
|
|
this.bindGEvent( FriendEvent.Update_Red_Point, this.updateRedPoint.bind( this ) );
|
|
//改变按钮状态
|
|
this.bindGEvent( FriendEvent.IS_DEL_BTN_STATUS, this.delChangeBtnStatus.bind( this ) );
|
|
|
|
//好友搜索和推荐
|
|
this.bindGEvent( FriendEvent.UD_COMMEND_LIST, this.updateFindList.bind( this ) )
|
|
this.bindGEvent( FriendEvent.FRIEND_QUERY_RESULT, this.updateFindList.bind( this ) )
|
|
|
|
this.togs.posTog = this.onTogMenu.bind( this );
|
|
this.togs.togTo( 0 );
|
|
},
|
|
|
|
//当前根节点销毁前进行的预处理操作
|
|
onPreClosed() {
|
|
this.scrollCon.rebuild( [] );
|
|
},
|
|
|
|
updateApplyFri() {
|
|
if( this.cur_type != FriendConst.Type.ApplyList ) return
|
|
this.updateFriendList( false );
|
|
},
|
|
|
|
FriendGiftRev( data ) {
|
|
if( this.cur_type != FriendConst.Type.Award && this.cur_type != FriendConst.Type.MyFriend ) return;
|
|
|
|
var list = data.list || {};
|
|
var id_list = {};
|
|
for( var i in list ) {
|
|
var v = list[ i ];
|
|
id_list[ v.rid + "_" + v.srv_id ] = v
|
|
}
|
|
|
|
this.updateFriendList( false );
|
|
},
|
|
|
|
delFriend() {
|
|
if( this.cur_type != FriendConst.Type.MyFriend && this.cur_type != FriendConst.Type.BlackList )
|
|
return;
|
|
this.updateFriendList( false, true );
|
|
this.changeFriendBtn( true )
|
|
},
|
|
|
|
addApplyFri() {
|
|
if( this.cur_type != FriendConst.Type.MyFriend ) {
|
|
if( this.cur_type == FriendConst.Type.ApplyList ) {
|
|
this.updateFriendList( false );
|
|
}
|
|
} else {
|
|
this.updateFriendList( false );
|
|
}
|
|
|
|
},
|
|
|
|
updateFriNum() {
|
|
this.updateFriendList( false );
|
|
|
|
},
|
|
|
|
changeFriNum() {
|
|
this.updateFriendList( false, true );
|
|
|
|
},
|
|
|
|
revGiftBack() {
|
|
this.updateFriendList( false );
|
|
|
|
},
|
|
|
|
updateRedPoint() {
|
|
|
|
},
|
|
|
|
delChangeBtnStatus( is_del ) {
|
|
if( this.cur_type == FriendConst.Type.MyFriend ) {
|
|
let v = is_del || false;
|
|
this.changeFriendBtn( v );
|
|
}
|
|
},
|
|
|
|
start() {
|
|
|
|
},
|
|
|
|
selectedTabCallBack: function ( type2 ) {
|
|
let type = type2 || FriendConst.Type.MyFriend;
|
|
if( this.cur_type == type )
|
|
return
|
|
this.changeFriendBtn( false );
|
|
// //切换到好友列表就把红点清掉
|
|
// this.setTabTips(false, FriendConst.Type.MyFriend);
|
|
|
|
this.cur_type = type;
|
|
if( this.pre_panel != null ) {
|
|
nx.gui.setActive( this.pre_panel, "", false );
|
|
}
|
|
|
|
this.pre_panel = this.friend_views[ this.cur_type - 1 ];
|
|
if( this.pre_panel != null ) {
|
|
nx.gui.setActive( this.pre_panel, "", true );
|
|
}
|
|
|
|
// //更新列表数据
|
|
this.updateFriendList( true );
|
|
},
|
|
|
|
//变更好友子项的按钮作用,true变为删除好友,false还原为私聊
|
|
changeFriendBtn: function ( bool ) {
|
|
this.del_friend_status = bool;
|
|
for( let i = 0; i < this.rend_list.length; ++i ) {
|
|
this.rend_list[ i ].del_status = bool
|
|
}
|
|
this.scrollCon.svcKey = this.cur_type;
|
|
this.scrollCon.rebuild( this.rend_list );
|
|
// this.item_scrollview.resetAddPosition(this.rend_list, null, this.cur_type);
|
|
},
|
|
|
|
updateFindList( data_list ) {
|
|
var list = [];
|
|
for( var i in data_list ) {
|
|
list.push( data_list[ i ] );
|
|
}
|
|
|
|
this.rend_list = list;
|
|
this.showEmptyIcon( false );
|
|
if( this.rend_list.length <= 0 ) {
|
|
this.scrollCon.rebuild( [] );
|
|
this.showEmptyIcon( true );
|
|
}
|
|
|
|
this.scrollCon.rebuild( this.rend_list )
|
|
},
|
|
|
|
updateFriendList: function ( change_index, is_del ) {
|
|
change_index = change_index || false;
|
|
this.rend_list = [];
|
|
var list = [];
|
|
this.cost_panel.active = true;
|
|
if( this.cur_type == FriendConst.Type.MyFriend ) {
|
|
list = this.ctrl.getModel().getArray() || [];
|
|
nx.mTip.openTip( "bar.friend.rev", false );
|
|
} else if( this.cur_type == FriendConst.Type.ApplyList ) {
|
|
if( change_index ) {
|
|
this.ctrl.apply();
|
|
return
|
|
} else {
|
|
var array = [];
|
|
var apply_list = this.ctrl.getModel().getApplyList() || {};
|
|
for( var i in apply_list ) {
|
|
array.push( apply_list[ i ] );
|
|
}
|
|
list = array;
|
|
}
|
|
this.updateApplyNum();
|
|
|
|
nx.mTip.openTip( "bar.friend.apply", false );
|
|
} else if( this.cur_type == FriendConst.Type.Award ) {
|
|
var array = this.ctrl.getModel().getArray() || [];
|
|
var award_array = [];
|
|
for( var i = 0; i < array.length; i++ ) {
|
|
var vo = array[ i ];
|
|
if( vo && vo.is_draw == 1 ) {
|
|
award_array.push( vo );
|
|
}
|
|
}
|
|
list = award_array;
|
|
} else if( this.cur_type == FriendConst.Type.BlackList ) {
|
|
list = this.ctrl.getModel().getBlackArray() || [];
|
|
} else if( this.cur_type == FriendConst.Type.Find ) {
|
|
this.cost_panel.active = false;
|
|
}
|
|
if( list ) {
|
|
for( var k in list ) {
|
|
if( list[ k ] ) {
|
|
this.rend_list.push( list[ k ] );
|
|
}
|
|
}
|
|
}
|
|
|
|
// console.log( "friendlist====>", this.cur_type, list );
|
|
|
|
this.showEmptyIcon( false );
|
|
if( this.rend_list.length <= 0 ) {
|
|
this.scrollCon.rebuild( [] );
|
|
this.showEmptyIcon( true );
|
|
}
|
|
this.createSubPanel( this.cur_type, this.rend_list );
|
|
if( is_del && !change_index && Utils.next( this.rend_list ) != null ) {
|
|
this.scrollCon.rebuild( this.rend_list );
|
|
} else {
|
|
this.scrollCon.svcKey = this.cur_type;
|
|
this.scrollCon.rebuild( this.rend_list );
|
|
}
|
|
},
|
|
|
|
//更新申请数
|
|
updateApplyNum: function () {
|
|
var num = this.ctrl.getModel().getApplyNum() || 0;
|
|
this.friend_num.string = cc.js.formatStr( ( "<color=#3f3f3f>" + nx.text.getKey( "friend_str9" ) + "</color>" + "<color=#3f3f3f>%s/</color><color=#3f3f3f>%s</color>" ), num, 99 );
|
|
},
|
|
|
|
//显示空白
|
|
showEmptyIcon: function ( bool ) {
|
|
this.empty_con.active = bool;
|
|
},
|
|
|
|
createSubPanel: function ( index, data ) {
|
|
if( index == FriendConst.Type.MyFriend ) {
|
|
var all_num = this.ctrl.getModel().getFriendOnlineAndTotal().total_num;
|
|
var str = cc.js.formatStr( "<color=#3f3f3f>" + nx.text.getKey( "friend_str6" ) + "</color>" + "<color=#3f3f3f>%s/</color><color=#3f3f3f>100</color>", all_num );
|
|
this.friend_num.string = str;
|
|
} else if( index == FriendConst.Type.ApplyList ) {
|
|
this.updateApplyNum();
|
|
} else if( index == FriendConst.Type.Award ) {
|
|
var num = 0;
|
|
if( data ) {
|
|
for( var i in data ) {
|
|
var vo = data[ i ];
|
|
if( vo && vo.is_draw == 1 )
|
|
num = num + 1;
|
|
}
|
|
}
|
|
var str = cc.js.formatStr( "<color=#3f3f3f>" + nx.text.getKey( "friend_str10" ) + "</color>" + "<color=#3f3f3f>%s</color>", num );
|
|
this.friend_num.string = str;
|
|
} else if( index == FriendConst.Type.BlackList ) {
|
|
var all_num = this.ctrl.getModel().getBlackListOnlineAndTotal().total_num;
|
|
this.friend_num.string = cc.js.formatStr( "%s<color=#3f3f3f>%d/</color><color=#3f3f3f>%d</color>", nx.text.getKey( "friend_str11" ), all_num, 50 );
|
|
} else if( index == FriendConst.Type.Find ) {
|
|
var all_num = this.ctrl.getModel().getBlackListOnlineAndTotal().total_num;
|
|
var str = cc.js.formatStr( "<color=#3f3f3f>" + nx.text.getKey( "friend_str6" ) + "</color>" + "<color=#3f3f3f>%s/</color><color=#3f3f3f>100</color>", all_num );
|
|
this.friend_num.string = str;
|
|
}
|
|
},
|
|
|
|
onOpenConfigs( param ) {
|
|
this.selectedTabCallBack( param.type || FriendConst.Type.MyFriend );
|
|
},
|
|
|
|
onTogMenu( _type ) {
|
|
this.selectedTabCallBack( _type + 1 );
|
|
},
|
|
|
|
touchClose() {
|
|
this.close();
|
|
},
|
|
// update (dt) {},
|
|
} ); |