pubgv3/assets/scripts/UI/UIFriend/UIFriendNew.js
guoqing.zhu 568a9c6310 update
2022-05-22 16:41:27 +08:00

183 lines
4.7 KiB
JavaScript

var SDKManage = require("SDKManage");
const NetManage = require("../../manages/NetManage");
cc.Class({
extends: cc.Component,
properties: {
nd_friend: {
default: null,
type: cc.Node,
},
nd_apply: {
default: null,
type: cc.Node,
},
nd_blacklist: {
default: null,
type: cc.Node,
},
edit_find: {
default: null,
type: cc.EditBox,
},
pb_oneFriend: {
default: null,
type: cc.Prefab,
},
// contents
content_friend: {
default: null,
type: cc.Node,
},
friendScrollview: {
default: null,
type: cc.ScrollView,
},
// content_apply: {
// default: null,
// type: cc.Node,
// },
// content_blacklist: {
// default: null,
// type: cc.Node,
// },
},
onLoad() {
// get friendlist
cc.chatMgr.sendmsg("CMFriendList");
cc.Notifier.on("friendlist", this, this.getFriendList.bind(this));
cc.Notifier.on("selectUserByName", this, this.searchFriend.bind(this));
cc.Notifier.on("dirtywordcheck", this, this.dirtywordcheck.bind(this));
this.setToFriend();
},
start() {},
setToNone() {
this.edit_find.string = "";
this.nd_friend.active = false;
this.nd_apply.active = false;
this.nd_blacklist.active = false;
this.content_friend.destroyAllChildren();
this.friendScrollview.stopAutoScroll();
this.friendScrollview.scrollToTop();
},
testinitOne(index) {
for (let i = 0; i < 50; i += 1) {
const node = cc.instantiate(this.pb_oneFriend);
switch (index) {
case 0:
node.getComponent("SingleFriendList").setToFriendList();
this.content_friend.addChild(node);
break;
case 1:
node.getComponent("SingleFriendList").setToApplyList();
this.content_friend.addChild(node);
break;
case 2:
node.getComponent("SingleFriendList").setToBlackList();
this.content_friend.addChild(node);
break;
}
}
},
setToFriend() {
cc.chatMgr.sendmsg("CMFriendList");
this.setToNone();
this.nd_friend.active = true;
this.testinitOne(0);
},
setToApply() {
this.setToNone();
this.nd_apply.active = true;
this.testinitOne(1);
},
setToBlackList() {
this.setToNone();
this.nd_blacklist.active = true;
this.testinitOne(2);
},
onClose() {
this.node.destroy();
},
onSearch() {
if (this.edit_find.string != "" && this.edit_find.string) {
NetManage.dirtyWordCheck(this.edit_find.string);
} else {
cc.uiHelper.showTips("User not found!");
}
},
dirtywordcheck(obj) {
if (obj.errcode == 0) {
if (this.edit_find.string != "" && this.edit_find.string) {
console.log("search user:" + this.edit_find.string);
}
} else {
cc.uiHelper.showTips("User not found!");
this.edit_find.string = "";
}
},
onClickToggle(event, data) {
switch (data) {
case "0":
this.setToFriend();
break;
case "1":
this.setToApply();
break;
case "2":
this.setToBlackList();
break;
}
},
searchFriend(obj) {
if (obj.errcode == 0) {
//cc.uiHelper.showTips('已经向对方发送好友申请');
this.editbox.string = "";
cc.chatMgr.sendmsg("CMFriendApply", {
friend_id: obj.fri_accountid,
msg: "",
});
} else {
cc.uiHelper.showTips(cc.language.stringformat("notplayer"));
this.edit_find.string = "";
}
},
getFriendList(msg) {
this.friend_list = [];
for (var m = 0; m < msg.friend_list.length; m++) {
this.friend_list.push(msg.friend_list[m]);
}
for (var i = this.friend_list.length - 1; i >= 0; i--) {
if (
this.friend_list[i].base_data["account_id"] ==
SDKManage.account_id
) {
this.friend_list.splice(i, 1);
break;
}
}
console.log(this.friend_list);
},
});