-- 成员列表Layout local ClubPlayerMatchHeHuoRen = class("ClubPlayerMatchHeHuoRen" , cc.UIView); local ClubDefine = require("luaScript.Protocol.Club.ClubDefine") --一页30个 local PAGE_COUNT = 30 --创始人和管理员会进入这里,分别是一级和二级查看权限 --一级也会进入这里,查看二级 --clubid 俱乐部ID --player 当前查询的玩家 --lastOpId 上级ID function ClubPlayerMatchHeHuoRen:ctor(clubId,player,lastOpId,searchData) ClubPlayerMatchHeHuoRen.super.ctor(self) --单个茶馆数据 self.clubInfo = app.club_php.clubList[clubId] --只用于是否播放标签页按钮音效 self.touchIdx = 1; self.curPage = 1 self.totolPage = 1 self.player = player --上级ID self.lastOpId = lastOpId self.playersCorpartner = {} self.isUpdate = false self.searchData = searchData self.isEnterBack = false self:loadUI() end function ClubPlayerMatchHeHuoRen:loadUI() local ui = loadUI("res/ui/ui_club/ui_club_player_match_hehuoren.ui") self.ui = ui; self:addChild(ui); end function ClubPlayerMatchHeHuoRen:onEnter() ClubPlayerMatchHeHuoRen.super.onEnter(self) self:initView() self:initButton() self.ui.Items.ScrollView_Member:hideAllBar() self:initBindEvent() self.viewType = self.player.role == ClubDefine.Job.LevelOneCopartner and ClubDefine.PlayListType.MATCH_LV_1_COPARTNER_MEMBER or ClubDefine.PlayListType.MATCH_LV_2_COPARTNER_MEMBER if self.searchData and not self.searchData.isIgnore then self.ui.Items.TextField_search:setText(tostring(self.searchData.uid)) self:onUpdatePlayerListEvent({type = ClubDefine.PlayListType.MATCH_MEMBER}) else if self.clubInfo then local playerJson = { clubId = self.clubInfo.clubId, viewType = self.viewType, muid = self.player.uid, status = ClubDefine.PlayListType.MATCH_MEMBER, } app.club_php:requestPlayerList(playerJson) end end end function ClubPlayerMatchHeHuoRen:initView() local role = self.player.role if role then self.ui.Items.ImageView_title:loadTexture(string.format("res/ui/zy_club/club_room/club_match/club_match_xinxi_title_level_%d.png",role)) end --日记追踪 if self.clubInfo.role and role then logD("当前角色是:",ClubDefine.Role[self.clubInfo.role]) logD("查看角色是:",ClubDefine.Role[role]) logD("当前界面是比赛成员界面") end end function ClubPlayerMatchHeHuoRen:initButton() --关闭 self.ui.Items.Button_close:registerClick(handler(self , self.onClose)) --搜索 self.ui.Items.Button_search:registerClick(handler(self , self.onSearchPlayer)) --翻页 self.ui.Items.Button_page_up:registerClick(handler(self , self.onClickUpPage)) self.ui.Items.Button_page_next:registerClick(handler(self , self.onClickNextPage)) --调配下属成员 self.ui.Items.Button_adjustMember:setVisible(self.clubInfo.role == ClubDefine.Job.Creator) self.ui.Items.Button_adjustMember:registerClick(function() playBtnEffect() local view = import("luaScript.Views.Club.ClubPlayerMatchSetMember"):new(self.clubInfo,self.player,self.viewType) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end) --比赛场排序 self.ui.Items.Button_status:registerClick(handler(self , self.onStatuSort)) self.ui.Items.Layout_status:registerClick(handler(self , self.onStatuSort)) self.ui.Items.Button_redNum:registerClick(handler(self , self.onStatuRedNum)) self.ui.Items.Layout_redNum:registerClick(handler(self , self.onStatuRedNum)) end function ClubPlayerMatchHeHuoRen:initBindEvent() --绑定请求成员列表成功回调事件 self:bindEvent(app.club_php , GAME_EVENT.CLUB_PLAYER_LIST , handler(self , self.onUpdatePlayerListEvent)) --权限发生改变 self:bindEvent(app.club_php , GAME_EVENT.CLUB_CHANGE_ROLE , handler(self , self.onChangeRole)); --绑定比赛开关回调 self:bindEvent(app.club_php , GAME_EVENT.CLUB_SET , handler(self , self.onSetSuccess)); --绑定请求禁止同桌列表成功回调事件 self:bindEvent(app.club_php , GAME_EVENT.CLUB_PLAYER_BAN_LIST , handler(self , self.onPlayerBanList)); --是否退出需要更新上一级 --self:bindEvent(app.club_php , GAME_EVENT.CLUB_NOTICE_LV1_2UPDATE , handler(self , self.onUpateData)); --通知界面刷新当前列表 self:bindEvent(app.club_php, GAME_EVENT.NOTICE_REQUEST_PLAYER_LIST, handler(self, self.onReuqestPlayerList)) --搜素 self:bindEvent(app.club_php , GAME_EVENT.CLUB_PLAYER_SEARCH , handler(self , self.onSearchPlayerSuccess)); self:bindEvent(app, "applicationDidEnterBackground", handler(self, self.onApplicationDidEnterBackground)) self:bindTextFildTouch() end --[[function ClubPlayerMatchHeHuoRen:onUpateData() self.isUpdate = true end--]] -- 角色权限修改 function ClubPlayerMatchHeHuoRen:onChangeRole() self:removeFromParent() end -- 当比赛一关,其他和比赛有关的界面需要关闭 function ClubPlayerMatchHeHuoRen:onSetSuccess(data) if not data or not data.setType then return end if data.setType == GAME_CLUB_SET_STATE.Math_Switch then self:removeFromParent() end end function ClubPlayerMatchHeHuoRen:onClose() playBtnCloseEffect() if self.player.role == ClubDefine.Job.LevelOneCopartner or (self.player.role == ClubDefine.Job.LevelTwoCopartner and self.clubInfo.role == ClubDefine.Job.LevelOneCopartner)then --showTooltip("新创建成员界面") --如果是一级返回到成员界面 local view = import( "luaScript.Views.Club.ClubPlayerMatch"):new(self.clubInfo.clubId) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) elseif self.player.role == ClubDefine.Job.LevelTwoCopartner then --showTooltip("新创建一级界面") --如果是二级,返回到一级去 local lvOnePlayer = {} lvOnePlayer.role = ClubDefine.Job.LevelOneCopartner lvOnePlayer.uid = self.lastOpId lvOnePlayer.isIgnore = true local view = import("luaScript.Views.Club.ClubPlayerMatchHeHuoRen"):new(self.clubInfo.clubId,lvOnePlayer,app.user.loginInfo.uid,lvOnePlayer) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end self:removeFromParent() end --下一页 function ClubPlayerMatchHeHuoRen:onClickNextPage() playBtnEffect() self.curPage = self.curPage + 1 if self.curPage>self.totolPage then self.curPage = self.totolPage end self:updatePlayerList() end --上一页 function ClubPlayerMatchHeHuoRen:onClickUpPage() playBtnEffect() self.curPage = self.curPage - 1 if self.curPage<1 then self.curPage = 1 end self:updatePlayerList() end function ClubPlayerMatchHeHuoRen:onUpdatePlayerListEvent(data) if not data or not data.type or self.isEnterBack then self.isEnterBack = false return end local mType = data.type if mType == self.viewType then if mType == ClubDefine.PlayListType.MATCH_LV_1_COPARTNER_MEMBER then self.playersCorpartner = self.clubInfo.playersLevelOne else self.playersCorpartner = self.clubInfo.playersLevelTwo end elseif mType == ClubDefine.PlayListType.MATCH_MEMBER then self.playersCorpartner = self.clubInfo.players else return end local players = {} for k,v in pairs(self.playersCorpartner) do table.insert(players,v) end local function sortFunc(a, b) local aRole = tonumber(a.role) local bRole = tonumber(b.role) if aRole ~= bRole and (aRole == ClubDefine.Job.LevelOneCopartner or aRole == ClubDefine.Job.LevelTwoCopartner or bRole == ClubDefine.Job.LevelOneCopartner or bRole == ClubDefine.Job.LevelTwoCopartner) then if (aRole == ClubDefine.Job.LevelTwoCopartner and bRole == ClubDefine.Job.LevelOneCopartner) or (bRole == ClubDefine.Job.LevelTwoCopartner and aRole == ClubDefine.Job.LevelOneCopartner)then return aRole < bRole elseif aRole == ClubDefine.Job.LevelTwoCopartner or aRole == ClubDefine.Job.LevelOneCopartner then return bRole ~= ClubDefine.Job.Manager and bRole ~= ClubDefine.Job.Creator else return aRole == ClubDefine.Job.Manager or aRole == ClubDefine.Job.Creator end end return aRole > bRole end table.sort(players,sortFunc) self:updatePlayerList(players) self.ui.Items.Text_online_num:setText(tostring(self.clubInfo.onlinePlayerNum)) self.ui.Items.Text_total_num:setText("/"..tostring(self.clubInfo.totalPlayerNum)) end function ClubPlayerMatchHeHuoRen:updatePlayerList(data) local mListView = self.ui.Items.ScrollView_Member mListView:getInnerContainer():setAutoSize(true) mListView:removeAllChildren() local players = {} if data then players = data --记录上一次排序后的players数组,点上一页下一页时用 self.lastSortPlayer = players else if self.lastSortPlayer and #self.lastSortPlayer >0 then players = self.lastSortPlayer else for k,v in pairs(self.playersCorpartner) do table.insert(players,v) end end end self.totolPage = math.ceil(table.nums(players)/PAGE_COUNT) local startIndex = (self.curPage-1) * PAGE_COUNT + 1 local endIndex = startIndex + PAGE_COUNT - 1 for i=startIndex,endIndex do local v = players[i] if v then item = import("luaScript.Views.Club.ClubPlayerMatchHeHuoRenItem"):new(v,self.clubInfo.clubId,i,self.player,function () self:removeFromParent() end) mListView:addChild(item.ui) end end mListView:jumpToTopOnSizeChanged() self.ui.Items.Text_Cur_page:setString(self.curPage) self.ui.Items.Text_Total_page:setString("/"..self.totolPage) end --搜索玩家 function ClubPlayerMatchHeHuoRen:onSearchPlayer() playBtnEffect() if not self.clubInfo then return end local searchCont = self.ui.Items.TextField_search:getText(); if searchCont == "" then showTooltip("请输入玩家ID!"); return; end local playerJson = { clubId = self.clubInfo.clubId, viewType = ClubDefine.PlayListType.SEARCH_PLAYER, status = ClubDefine.PlayListType.MATCH_MEMBER, suid = searchCont } app.club_php:requestPlayerList(playerJson) end function ClubPlayerMatchHeHuoRen:onSearchPlayerSuccess(data) if not data then return end local result = data.result --logD("result:",table.tostring(result)) if result then local tt = {} for k,v in pairs(result.list) do table.insert(tt,v) end local player = tt[1] if player then player.isMatchMember = true local parentPlayer = {} parentPlayer.role = player.parentRole local lastOpId = 0 player.copartner = toNumber(player.copartner) player.copartner5 = toNumber(player.copartner5) if player.role == ClubDefine.Job.LevelOneCopartner then lastOpId = app.user.loginInfo.uid parentPlayer.uid = app.user.loginInfo.uid elseif player.role == ClubDefine.Job.LevelTwoCopartner then lastOpId = player.copartner5 --一级 parentPlayer.uid = player.copartner5 elseif player.role == ClubDefine.Job.Member then if player.copartner == 0 and player.copartner5 == 0 then --一级和二级的ID为0,则是自己的名下 lastOpId = app.user.loginInfo.uid parentPlayer.uid = app.user.loginInfo.uid elseif player.copartner == 0 and player.copartner5 > 0 then --一级名下成员 lastOpId = app.user.loginInfo.uid parentPlayer.uid = player.copartner5 elseif player.copartner > 0 and player.copartner5 > 0 then --二级名下成员 lastOpId = player.copartner5 parentPlayer.uid = player.copartner end end self.lastOpId = lastOpId if parentPlayer.role == self.player.role and parentPlayer.uid == self.player.uid then self.curPage = 1 self.totolPage = 1 local mListView = self.ui.Items.ScrollView_Member mListView:getInnerContainer():setAutoSize(true) mListView:removeAllChildren() local newPlayerList = {} for k,playerInfo in pairsByKeys(self.clubInfo.players) do --id查找 local findIdEnd = string.find(playerInfo.uid, tostring(player.uid)); if findIdEnd then local playerItem = import("luaScript.Views.Club.ClubPlayerMatchHeHuoRenItem"):new(playerInfo,self.clubInfo.clubId,1,self.player,function () self:removeFromParent() end) mListView:addChild(playerItem.ui); end table.insert(newPlayerList,playerInfo) end self.lastSortPlayer = newPlayerList mListView:jumpToTopOnSizeChanged() self.ui.Items.Text_Cur_page:setString(self.curPage) self.ui.Items.Text_Total_page:setString("/"..self.totolPage) elseif player.parentRole == ClubDefine.Job.Creator then local view = import( "luaScript.Views.Club.ClubPlayerMatch"):new(self.clubInfo.clubId,player) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) self:removeFromParent() else local view = import("luaScript.Views.Club.ClubPlayerMatchHeHuoRen"):new(self.clubInfo.clubId,parentPlayer,self.lastOpId,player) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) self:removeFromParent() end else showConfirmDialog("输入的ID错误或权限不足,请重新输入!") end end end function ClubPlayerMatchHeHuoRen:bindTextFildTouch() local nodeName = self.ui.Items.TextField_search; local function onTouchEnded(touch , event) local searchCont = nodeName:getText(); if searchCont == "" then if self.viewType == ClubDefine.PlayListType.MATCH_LV_1_COPARTNER_MEMBER then if table.nums(self.clubInfo.playersLevelOne) == 0 then local playerJson = { clubId = self.clubInfo.clubId, viewType = self.viewType, muid = self.player.uid, status = ClubDefine.PlayListType.MATCH_MEMBER, } app.club_php:requestPlayerList(playerJson) else if self.curPage == 1 then self:onUpdatePlayerListEvent({type = self.viewType}) else self:updatePlayerList() end end elseif self.viewType == ClubDefine.PlayListType.MATCH_LV_2_COPARTNER_MEMBER then local bFind = false if self.clubInfo.playersLevelTwo then for k,v in pairs(self.clubInfo.playersLevelTwo) do if tonumber(v.uid) == self.player.uid then bFind = true break end end end if bFind then if table.nums(self.clubInfo.playersLevelTwo) == 0 then local playerJson = { clubId = self.clubInfo.clubId, viewType = self.viewType, muid = self.player.uid, status = ClubDefine.PlayListType.MATCH_MEMBER, } app.club_php:requestPlayerList(playerJson) else if self.curPage == 1 then self:onUpdatePlayerListEvent({type = self.viewType}) else self:updatePlayerList() end end else local playerJson = { clubId = self.clubInfo.clubId, viewType = self.viewType, muid = self.player.uid, status = ClubDefine.PlayListType.MATCH_MEMBER, } app.club_php:requestPlayerList(playerJson) end end end end nodeName:addEventListener(onTouchEnded) end --当前选中的人禁止同桌列表显示 function ClubPlayerMatchHeHuoRen:onPlayerBanList(event) if event and event.viewType == self.viewType then local view = import("luaScript.Views.Club.ClubPlayerBanList"):new(self.clubInfo.clubId,event.uid,event.banList) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view, 180, false) end end --玩家状态排序 function ClubPlayerMatchHeHuoRen:onStatuSort() playBtnEffect() if self.sort then --升序 self:sortOnline("asc"); self.sort = false; else --降序 self:sortOnline("desc"); self.sort = true; end end --状态排序 function ClubPlayerMatchHeHuoRen:sortOnline(sortType) local playerList = self.lastSortPlayer; if playerList then local lT = {}; for k,v in pairs(playerList) do table.insert(lT,v) end if sortType == "asc" then --升序 local function sortFunc(a,b) return a.online < b.online end table.sort(lT, sortFunc); elseif sortType == "desc" then --降序 local function sortFunc(a,b) return a.online > b.online end table.sort(lT, sortFunc); end self:updatePlayerList(lT) end end function ClubPlayerMatchHeHuoRen:onStatuRedNum() playBtnEffect() if self.sort then --升序 self:sortRedNum("asc"); self.sort = false; else --降序 self:sortRedNum("desc"); self.sort = true; end end function ClubPlayerMatchHeHuoRen:sortRedNum(sortType) local playerList = self.lastSortPlayer; if playerList then local lT = {}; for k,v in pairs(playerList) do table.insert(lT,v) end if sortType == "asc" then --升序 local function sortFunc(a,b) return a.useRedFlower < b.useRedFlower end table.sort(lT, sortFunc); elseif sortType == "desc" then --降序 local function sortFunc(a,b) return a.useRedFlower > b.useRedFlower end table.sort(lT, sortFunc); end self:updatePlayerList(lT) end end function ClubPlayerMatchHeHuoRen:onReuqestPlayerList() --请求茶馆成员列表 if self.clubInfo then local playerJson = { clubId = self.clubInfo.clubId, viewType = self.viewType, muid = self.player.uid, status = ClubDefine.PlayListType.MATCH_MEMBER, } logD("playerJson:",table.tostring(playerJson)) app.club_php:requestPlayerList(playerJson) end end function ClubPlayerMatchHeHuoRen:onApplicationDidEnterBackground() self.isEnterBack = true end return ClubPlayerMatchHeHuoRen