You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

566 lines
17 KiB

  1. -- 成员列表Layout
  2. local ClubPlayerMatchHeHuoRen = class("ClubPlayerMatchHeHuoRen" , cc.UIView);
  3. local ClubDefine = require("luaScript.Protocol.Club.ClubDefine")
  4. --一页30个
  5. local PAGE_COUNT = 30
  6. --创始人和管理员会进入这里,分别是一级和二级查看权限
  7. --一级也会进入这里,查看二级
  8. --clubid 俱乐部ID
  9. --player 当前查询的玩家
  10. --lastOpId 上级ID
  11. function ClubPlayerMatchHeHuoRen:ctor(clubId,player,lastOpId,searchData)
  12. ClubPlayerMatchHeHuoRen.super.ctor(self)
  13. --单个茶馆数据
  14. self.clubInfo = app.club_php.clubList[clubId]
  15. --只用于是否播放标签页按钮音效
  16. self.touchIdx = 1;
  17. self.curPage = 1
  18. self.totolPage = 1
  19. self.player = player
  20. --上级ID
  21. self.lastOpId = lastOpId
  22. self.playersCorpartner = {}
  23. self.isUpdate = false
  24. self.searchData = searchData
  25. self.isEnterBack = false
  26. self:loadUI()
  27. end
  28. function ClubPlayerMatchHeHuoRen:loadUI()
  29. local ui = loadUI("res/ui/ui_club/ui_club_player_match_hehuoren.ui")
  30. self.ui = ui;
  31. self:addChild(ui);
  32. end
  33. function ClubPlayerMatchHeHuoRen:onEnter()
  34. ClubPlayerMatchHeHuoRen.super.onEnter(self)
  35. self:initView()
  36. self:initButton()
  37. self.ui.Items.ScrollView_Member:hideAllBar()
  38. self:initBindEvent()
  39. self.viewType = self.player.role == ClubDefine.Job.LevelOneCopartner and ClubDefine.PlayListType.MATCH_LV_1_COPARTNER_MEMBER or ClubDefine.PlayListType.MATCH_LV_2_COPARTNER_MEMBER
  40. if self.searchData and not self.searchData.isIgnore then
  41. self.ui.Items.TextField_search:setText(tostring(self.searchData.uid))
  42. self:onUpdatePlayerListEvent({type = ClubDefine.PlayListType.MATCH_MEMBER})
  43. else
  44. if self.clubInfo then
  45. local playerJson = {
  46. clubId = self.clubInfo.clubId,
  47. viewType = self.viewType,
  48. muid = self.player.uid,
  49. status = ClubDefine.PlayListType.MATCH_MEMBER,
  50. }
  51. app.club_php:requestPlayerList(playerJson)
  52. end
  53. end
  54. end
  55. function ClubPlayerMatchHeHuoRen:initView()
  56. local role = self.player.role
  57. if role then
  58. self.ui.Items.ImageView_title:loadTexture(string.format("res/ui/zy_club/club_room/club_match/club_match_xinxi_title_level_%d.png",role))
  59. end
  60. --日记追踪
  61. if self.clubInfo.role and role then
  62. logD("当前角色是:",ClubDefine.Role[self.clubInfo.role])
  63. logD("查看角色是:",ClubDefine.Role[role])
  64. logD("当前界面是比赛成员界面")
  65. end
  66. end
  67. function ClubPlayerMatchHeHuoRen:initButton()
  68. --关闭
  69. self.ui.Items.Button_close:registerClick(handler(self , self.onClose))
  70. --搜索
  71. self.ui.Items.Button_search:registerClick(handler(self , self.onSearchPlayer))
  72. --翻页
  73. self.ui.Items.Button_page_up:registerClick(handler(self , self.onClickUpPage))
  74. self.ui.Items.Button_page_next:registerClick(handler(self , self.onClickNextPage))
  75. --调配下属成员
  76. self.ui.Items.Button_adjustMember:setVisible(self.clubInfo.role == ClubDefine.Job.Creator)
  77. self.ui.Items.Button_adjustMember:registerClick(function()
  78. playBtnEffect()
  79. local view = import("luaScript.Views.Club.ClubPlayerMatchSetMember"):new(self.clubInfo,self.player,self.viewType)
  80. view:setAnchorPoint(cc.p(0.5, 0.5))
  81. app:showWaitDialog(view)
  82. end)
  83. --比赛场排序
  84. self.ui.Items.Button_status:registerClick(handler(self , self.onStatuSort))
  85. self.ui.Items.Layout_status:registerClick(handler(self , self.onStatuSort))
  86. self.ui.Items.Button_redNum:registerClick(handler(self , self.onStatuRedNum))
  87. self.ui.Items.Layout_redNum:registerClick(handler(self , self.onStatuRedNum))
  88. end
  89. function ClubPlayerMatchHeHuoRen:initBindEvent()
  90. --绑定请求成员列表成功回调事件
  91. self:bindEvent(app.club_php , GAME_EVENT.CLUB_PLAYER_LIST , handler(self , self.onUpdatePlayerListEvent))
  92. --权限发生改变
  93. self:bindEvent(app.club_php , GAME_EVENT.CLUB_CHANGE_ROLE , handler(self , self.onChangeRole));
  94. --绑定比赛开关回调
  95. self:bindEvent(app.club_php , GAME_EVENT.CLUB_SET , handler(self , self.onSetSuccess));
  96. --绑定请求禁止同桌列表成功回调事件
  97. self:bindEvent(app.club_php , GAME_EVENT.CLUB_PLAYER_BAN_LIST , handler(self , self.onPlayerBanList));
  98. --是否退出需要更新上一级
  99. --self:bindEvent(app.club_php , GAME_EVENT.CLUB_NOTICE_LV1_2UPDATE , handler(self , self.onUpateData));
  100. --通知界面刷新当前列表
  101. self:bindEvent(app.club_php, GAME_EVENT.NOTICE_REQUEST_PLAYER_LIST, handler(self, self.onReuqestPlayerList))
  102. --搜素
  103. self:bindEvent(app.club_php , GAME_EVENT.CLUB_PLAYER_SEARCH , handler(self , self.onSearchPlayerSuccess));
  104. self:bindEvent(app, "applicationDidEnterBackground", handler(self, self.onApplicationDidEnterBackground))
  105. self:bindTextFildTouch()
  106. end
  107. --[[function ClubPlayerMatchHeHuoRen:onUpateData()
  108. self.isUpdate = true
  109. end--]]
  110. -- 角色权限修改
  111. function ClubPlayerMatchHeHuoRen:onChangeRole()
  112. self:removeFromParent()
  113. end
  114. -- 当比赛一关,其他和比赛有关的界面需要关闭
  115. function ClubPlayerMatchHeHuoRen:onSetSuccess(data)
  116. if not data or not data.setType then
  117. return
  118. end
  119. if data.setType == GAME_CLUB_SET_STATE.Math_Switch then
  120. self:removeFromParent()
  121. end
  122. end
  123. function ClubPlayerMatchHeHuoRen:onClose()
  124. playBtnCloseEffect()
  125. if self.player.role == ClubDefine.Job.LevelOneCopartner or (self.player.role == ClubDefine.Job.LevelTwoCopartner and self.clubInfo.role == ClubDefine.Job.LevelOneCopartner)then
  126. --showTooltip("新创建成员界面")
  127. --如果是一级返回到成员界面
  128. local view = import( "luaScript.Views.Club.ClubPlayerMatch"):new(self.clubInfo.clubId)
  129. view:setAnchorPoint(cc.p(0.5, 0.5))
  130. app:showWaitDialog(view)
  131. elseif self.player.role == ClubDefine.Job.LevelTwoCopartner then
  132. --showTooltip("新创建一级界面")
  133. --如果是二级,返回到一级去
  134. local lvOnePlayer = {}
  135. lvOnePlayer.role = ClubDefine.Job.LevelOneCopartner
  136. lvOnePlayer.uid = self.lastOpId
  137. lvOnePlayer.isIgnore = true
  138. local view = import("luaScript.Views.Club.ClubPlayerMatchHeHuoRen"):new(self.clubInfo.clubId,lvOnePlayer,app.user.loginInfo.uid,lvOnePlayer)
  139. view:setAnchorPoint(cc.p(0.5, 0.5))
  140. app:showWaitDialog(view)
  141. end
  142. self:removeFromParent()
  143. end
  144. --下一页
  145. function ClubPlayerMatchHeHuoRen:onClickNextPage()
  146. playBtnEffect()
  147. self.curPage = self.curPage + 1
  148. if self.curPage>self.totolPage then
  149. self.curPage = self.totolPage
  150. end
  151. self:updatePlayerList()
  152. end
  153. --上一页
  154. function ClubPlayerMatchHeHuoRen:onClickUpPage()
  155. playBtnEffect()
  156. self.curPage = self.curPage - 1
  157. if self.curPage<1 then
  158. self.curPage = 1
  159. end
  160. self:updatePlayerList()
  161. end
  162. function ClubPlayerMatchHeHuoRen:onUpdatePlayerListEvent(data)
  163. if not data or not data.type or self.isEnterBack then
  164. self.isEnterBack = false
  165. return
  166. end
  167. local mType = data.type
  168. if mType == self.viewType then
  169. if mType == ClubDefine.PlayListType.MATCH_LV_1_COPARTNER_MEMBER then
  170. self.playersCorpartner = self.clubInfo.playersLevelOne
  171. else
  172. self.playersCorpartner = self.clubInfo.playersLevelTwo
  173. end
  174. elseif mType == ClubDefine.PlayListType.MATCH_MEMBER then
  175. self.playersCorpartner = self.clubInfo.players
  176. else
  177. return
  178. end
  179. local players = {}
  180. for k,v in pairs(self.playersCorpartner) do
  181. table.insert(players,v)
  182. end
  183. local function sortFunc(a, b)
  184. local aRole = tonumber(a.role)
  185. local bRole = tonumber(b.role)
  186. if aRole ~= bRole and (aRole == ClubDefine.Job.LevelOneCopartner or aRole == ClubDefine.Job.LevelTwoCopartner
  187. or bRole == ClubDefine.Job.LevelOneCopartner or bRole == ClubDefine.Job.LevelTwoCopartner) then
  188. if (aRole == ClubDefine.Job.LevelTwoCopartner and bRole == ClubDefine.Job.LevelOneCopartner) or (bRole == ClubDefine.Job.LevelTwoCopartner and aRole == ClubDefine.Job.LevelOneCopartner)then
  189. return aRole < bRole
  190. elseif aRole == ClubDefine.Job.LevelTwoCopartner or aRole == ClubDefine.Job.LevelOneCopartner then
  191. return bRole ~= ClubDefine.Job.Manager and bRole ~= ClubDefine.Job.Creator
  192. else
  193. return aRole == ClubDefine.Job.Manager or aRole == ClubDefine.Job.Creator
  194. end
  195. end
  196. return aRole > bRole
  197. end
  198. table.sort(players,sortFunc)
  199. self:updatePlayerList(players)
  200. self.ui.Items.Text_online_num:setText(tostring(self.clubInfo.onlinePlayerNum))
  201. self.ui.Items.Text_total_num:setText("/"..tostring(self.clubInfo.totalPlayerNum))
  202. end
  203. function ClubPlayerMatchHeHuoRen:updatePlayerList(data)
  204. local mListView = self.ui.Items.ScrollView_Member
  205. mListView:getInnerContainer():setAutoSize(true)
  206. mListView:removeAllChildren()
  207. local players = {}
  208. if data then
  209. players = data
  210. --记录上一次排序后的players数组,点上一页下一页时用
  211. self.lastSortPlayer = players
  212. else
  213. if self.lastSortPlayer and #self.lastSortPlayer >0 then
  214. players = self.lastSortPlayer
  215. else
  216. for k,v in pairs(self.playersCorpartner) do
  217. table.insert(players,v)
  218. end
  219. end
  220. end
  221. self.totolPage = math.ceil(table.nums(players)/PAGE_COUNT)
  222. local startIndex = (self.curPage-1) * PAGE_COUNT + 1
  223. local endIndex = startIndex + PAGE_COUNT - 1
  224. for i=startIndex,endIndex do
  225. local v = players[i]
  226. if v then
  227. item = import("luaScript.Views.Club.ClubPlayerMatchHeHuoRenItem"):new(v,self.clubInfo.clubId,i,self.player,function ()
  228. self:removeFromParent()
  229. end)
  230. mListView:addChild(item.ui)
  231. end
  232. end
  233. mListView:jumpToTopOnSizeChanged()
  234. self.ui.Items.Text_Cur_page:setString(self.curPage)
  235. self.ui.Items.Text_Total_page:setString("/"..self.totolPage)
  236. end
  237. --搜索玩家
  238. function ClubPlayerMatchHeHuoRen:onSearchPlayer()
  239. playBtnEffect()
  240. if not self.clubInfo then
  241. return
  242. end
  243. local searchCont = self.ui.Items.TextField_search:getText();
  244. if searchCont == "" then
  245. showTooltip("请输入玩家ID!");
  246. return;
  247. end
  248. local playerJson = {
  249. clubId = self.clubInfo.clubId,
  250. viewType = ClubDefine.PlayListType.SEARCH_PLAYER,
  251. status = ClubDefine.PlayListType.MATCH_MEMBER,
  252. suid = searchCont
  253. }
  254. app.club_php:requestPlayerList(playerJson)
  255. end
  256. function ClubPlayerMatchHeHuoRen:onSearchPlayerSuccess(data)
  257. if not data then
  258. return
  259. end
  260. local result = data.result
  261. --logD("result:",table.tostring(result))
  262. if result then
  263. local tt = {}
  264. for k,v in pairs(result.list) do
  265. table.insert(tt,v)
  266. end
  267. local player = tt[1]
  268. if player then
  269. player.isMatchMember = true
  270. local parentPlayer = {}
  271. parentPlayer.role = player.parentRole
  272. local lastOpId = 0
  273. player.copartner = toNumber(player.copartner)
  274. player.copartner5 = toNumber(player.copartner5)
  275. if player.role == ClubDefine.Job.LevelOneCopartner then
  276. lastOpId = app.user.loginInfo.uid
  277. parentPlayer.uid = app.user.loginInfo.uid
  278. elseif player.role == ClubDefine.Job.LevelTwoCopartner then
  279. lastOpId = player.copartner5 --一级
  280. parentPlayer.uid = player.copartner5
  281. elseif player.role == ClubDefine.Job.Member then
  282. if player.copartner == 0 and player.copartner5 == 0 then --一级和二级的ID为0,则是自己的名下
  283. lastOpId = app.user.loginInfo.uid
  284. parentPlayer.uid = app.user.loginInfo.uid
  285. elseif player.copartner == 0 and player.copartner5 > 0 then --一级名下成员
  286. lastOpId = app.user.loginInfo.uid
  287. parentPlayer.uid = player.copartner5
  288. elseif player.copartner > 0 and player.copartner5 > 0 then --二级名下成员
  289. lastOpId = player.copartner5
  290. parentPlayer.uid = player.copartner
  291. end
  292. end
  293. self.lastOpId = lastOpId
  294. if parentPlayer.role == self.player.role and parentPlayer.uid == self.player.uid then
  295. self.curPage = 1
  296. self.totolPage = 1
  297. local mListView = self.ui.Items.ScrollView_Member
  298. mListView:getInnerContainer():setAutoSize(true)
  299. mListView:removeAllChildren()
  300. local newPlayerList = {}
  301. for k,playerInfo in pairsByKeys(self.clubInfo.players) do
  302. --id查找
  303. local findIdEnd = string.find(playerInfo.uid, tostring(player.uid));
  304. if findIdEnd then
  305. local playerItem = import("luaScript.Views.Club.ClubPlayerMatchHeHuoRenItem"):new(playerInfo,self.clubInfo.clubId,1,self.player,function ()
  306. self:removeFromParent()
  307. end)
  308. mListView:addChild(playerItem.ui);
  309. end
  310. table.insert(newPlayerList,playerInfo)
  311. end
  312. self.lastSortPlayer = newPlayerList
  313. mListView:jumpToTopOnSizeChanged()
  314. self.ui.Items.Text_Cur_page:setString(self.curPage)
  315. self.ui.Items.Text_Total_page:setString("/"..self.totolPage)
  316. elseif player.parentRole == ClubDefine.Job.Creator then
  317. local view = import( "luaScript.Views.Club.ClubPlayerMatch"):new(self.clubInfo.clubId,player)
  318. view:setAnchorPoint(cc.p(0.5, 0.5))
  319. app:showWaitDialog(view)
  320. self:removeFromParent()
  321. else
  322. local view = import("luaScript.Views.Club.ClubPlayerMatchHeHuoRen"):new(self.clubInfo.clubId,parentPlayer,self.lastOpId,player)
  323. view:setAnchorPoint(cc.p(0.5, 0.5))
  324. app:showWaitDialog(view)
  325. self:removeFromParent()
  326. end
  327. else
  328. showConfirmDialog("输入的ID错误或权限不足,请重新输入!")
  329. end
  330. end
  331. end
  332. function ClubPlayerMatchHeHuoRen:bindTextFildTouch()
  333. local nodeName = self.ui.Items.TextField_search;
  334. local function onTouchEnded(touch , event)
  335. local searchCont = nodeName:getText();
  336. if searchCont == "" then
  337. if self.viewType == ClubDefine.PlayListType.MATCH_LV_1_COPARTNER_MEMBER then
  338. if table.nums(self.clubInfo.playersLevelOne) == 0 then
  339. local playerJson = {
  340. clubId = self.clubInfo.clubId,
  341. viewType = self.viewType,
  342. muid = self.player.uid,
  343. status = ClubDefine.PlayListType.MATCH_MEMBER,
  344. }
  345. app.club_php:requestPlayerList(playerJson)
  346. else
  347. if self.curPage == 1 then
  348. self:onUpdatePlayerListEvent({type = self.viewType})
  349. else
  350. self:updatePlayerList()
  351. end
  352. end
  353. elseif self.viewType == ClubDefine.PlayListType.MATCH_LV_2_COPARTNER_MEMBER then
  354. local bFind = false
  355. if self.clubInfo.playersLevelTwo then
  356. for k,v in pairs(self.clubInfo.playersLevelTwo) do
  357. if tonumber(v.uid) == self.player.uid then
  358. bFind = true
  359. break
  360. end
  361. end
  362. end
  363. if bFind then
  364. if table.nums(self.clubInfo.playersLevelTwo) == 0 then
  365. local playerJson = {
  366. clubId = self.clubInfo.clubId,
  367. viewType = self.viewType,
  368. muid = self.player.uid,
  369. status = ClubDefine.PlayListType.MATCH_MEMBER,
  370. }
  371. app.club_php:requestPlayerList(playerJson)
  372. else
  373. if self.curPage == 1 then
  374. self:onUpdatePlayerListEvent({type = self.viewType})
  375. else
  376. self:updatePlayerList()
  377. end
  378. end
  379. else
  380. local playerJson = {
  381. clubId = self.clubInfo.clubId,
  382. viewType = self.viewType,
  383. muid = self.player.uid,
  384. status = ClubDefine.PlayListType.MATCH_MEMBER,
  385. }
  386. app.club_php:requestPlayerList(playerJson)
  387. end
  388. end
  389. end
  390. end
  391. nodeName:addEventListener(onTouchEnded)
  392. end
  393. --当前选中的人禁止同桌列表显示
  394. function ClubPlayerMatchHeHuoRen:onPlayerBanList(event)
  395. if event and event.viewType == self.viewType then
  396. local view = import("luaScript.Views.Club.ClubPlayerBanList"):new(self.clubInfo.clubId,event.uid,event.banList)
  397. view:setAnchorPoint(cc.p(0.5, 0.5))
  398. app:showWaitDialog(view, 180, false)
  399. end
  400. end
  401. --玩家状态排序
  402. function ClubPlayerMatchHeHuoRen:onStatuSort()
  403. playBtnEffect()
  404. if self.sort then
  405. --升序
  406. self:sortOnline("asc");
  407. self.sort = false;
  408. else
  409. --降序
  410. self:sortOnline("desc");
  411. self.sort = true;
  412. end
  413. end
  414. --状态排序
  415. function ClubPlayerMatchHeHuoRen:sortOnline(sortType)
  416. local playerList = self.lastSortPlayer;
  417. if playerList then
  418. local lT = {};
  419. for k,v in pairs(playerList) do
  420. table.insert(lT,v)
  421. end
  422. if sortType == "asc" then
  423. --升序
  424. local function sortFunc(a,b)
  425. return a.online < b.online
  426. end
  427. table.sort(lT, sortFunc);
  428. elseif sortType == "desc" then
  429. --降序
  430. local function sortFunc(a,b)
  431. return a.online > b.online
  432. end
  433. table.sort(lT, sortFunc);
  434. end
  435. self:updatePlayerList(lT)
  436. end
  437. end
  438. function ClubPlayerMatchHeHuoRen:onStatuRedNum()
  439. playBtnEffect()
  440. if self.sort then
  441. --升序
  442. self:sortRedNum("asc");
  443. self.sort = false;
  444. else
  445. --降序
  446. self:sortRedNum("desc");
  447. self.sort = true;
  448. end
  449. end
  450. function ClubPlayerMatchHeHuoRen:sortRedNum(sortType)
  451. local playerList = self.lastSortPlayer;
  452. if playerList then
  453. local lT = {};
  454. for k,v in pairs(playerList) do
  455. table.insert(lT,v)
  456. end
  457. if sortType == "asc" then
  458. --升序
  459. local function sortFunc(a,b)
  460. return a.useRedFlower < b.useRedFlower
  461. end
  462. table.sort(lT, sortFunc);
  463. elseif sortType == "desc" then
  464. --降序
  465. local function sortFunc(a,b)
  466. return a.useRedFlower > b.useRedFlower
  467. end
  468. table.sort(lT, sortFunc);
  469. end
  470. self:updatePlayerList(lT)
  471. end
  472. end
  473. function ClubPlayerMatchHeHuoRen:onReuqestPlayerList()
  474. --请求茶馆成员列表
  475. if self.clubInfo then
  476. local playerJson = {
  477. clubId = self.clubInfo.clubId,
  478. viewType = self.viewType,
  479. muid = self.player.uid,
  480. status = ClubDefine.PlayListType.MATCH_MEMBER,
  481. }
  482. logD("playerJson:",table.tostring(playerJson))
  483. app.club_php:requestPlayerList(playerJson)
  484. end
  485. end
  486. function ClubPlayerMatchHeHuoRen:onApplicationDidEnterBackground()
  487. self.isEnterBack = true
  488. end
  489. return ClubPlayerMatchHeHuoRen