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.

389 lines
12 KiB

  1. -- 消息ItemLayout
  2. local ClubDefine = require("luaScript.Protocol.Club.ClubDefine")
  3. local ClubMessageItem = class("ClubMessageItem");
  4. function ClubMessageItem:ctor(data, msgType, clubId)
  5. self.ui = loadUI("res/ui/ui_club/ui_club_message_item.ui");
  6. local uiSize = self.ui:getSize();
  7. local realSize = {width = uiSize.width * g_radio_x,height = uiSize.height * g_radio_y}
  8. self.ui:setSize(realSize)
  9. --消息内容
  10. self.msgInfo = data;
  11. --消息类型
  12. self.msgType = msgType;
  13. --茶馆id
  14. self.clubId = clubId;
  15. self:showInfo()
  16. end
  17. function ClubMessageItem:showInfo()
  18. self.ui.Items.Layout_msg:setVisible(false);
  19. self.ui.Items.Layout_apply_msg:setVisible(false);
  20. self.ui.Items.Layout_activity:setVisible(false);
  21. self.ui.Items.Layout_coapply_msg:setVisible(false);
  22. self.ui.Items.Layout_match_coapply_msg:setVisible(false);
  23. if self.msgType == "msg" then
  24. self.ui.Items.Layout_msg:setVisible(true);
  25. --设置普通消息内容
  26. self:showMsg();
  27. elseif self.msgType == "applyMsg" then
  28. self.ui.Items.Layout_apply_msg:setVisible(true);
  29. --设置申请消息内容
  30. self:showApplyMsg();
  31. elseif self.msgType == "coapplyMsg" then
  32. self.ui.Items.Layout_coapply_msg:setVisible(true);
  33. --设置合伙人申请消息内容
  34. self:showCoApplyMsg();
  35. elseif self.msgType == "awardListMsg" then
  36. self.ui.Items.Layout_activity:setVisible(true);
  37. --设置奖励内容列表
  38. self:showAwardListMsg();
  39. elseif self.msgType == "coapplyMatchMsg" then
  40. self.ui.Items.Layout_match_coapply_msg:setVisible(true);
  41. --设置合伙人申请消息内容
  42. self:showCoApplyMatchMsg();
  43. end
  44. end
  45. function ClubMessageItem:showMsg()
  46. --消息内容
  47. local strCont = self.msgInfo.content
  48. --统一处理以前的老消息,未加颜色标签
  49. if not string.find(self.msgInfo.content, "font") then
  50. strCont = '<font size="28" color="9b2b0f" stroke="size:0;color:#000000">' .. self.msgInfo.content .. '</font>'
  51. end
  52. self.ui.Items.HtmlCtrl_msg:setText(strCont)
  53. --收到消息时间
  54. local time = os.date("%m.%d %H:%M:%S",self.msgInfo.date);
  55. self.ui.Items.Text_time:setText(time);
  56. end
  57. function ClubMessageItem:showApplyMsg()
  58. --头像
  59. local nodeHead = self.ui.Items.ImageView_head;
  60. local headSize = nodeHead:getContentSize()
  61. setPlayerHeadImage(self.msgInfo.uid, self.msgInfo.strHeadUrl, nodeHead);
  62. --名字
  63. local nickname = getSubStringNickname(self.msgInfo.nick or self.msgInfo.name or "", self.ui.Items.Text_name)
  64. self.ui.Items.Text_name:setText(nickname);
  65. --id
  66. self.ui.Items.Text_id:setText(self.msgInfo.uid);
  67. --申请时间
  68. local time = os.date("%m.%d %H:%M:%S",self.msgInfo.applyTime);
  69. self.ui.Items.Text_apply_time:setText(time);
  70. -- --茶馆名
  71. -- local str = getShortNameByLength(self.msgInfo.clubName,5)
  72. -- self.ui.Items.Text_club_name:setText(str);
  73. --申请类型
  74. self.ui.Items.Text_apply_type:setText(self.msgInfo.msgType == 1 and "加入" or "退出");
  75. --同意
  76. self.ui.Items.Button_agree:registerClick(handler(self,self.onAgree));
  77. --不同意
  78. self.ui.Items.Button_disagree:registerClick(handler(self,self.onDisAgree));
  79. self:updateStatus(self.msgInfo.status);
  80. end
  81. function ClubMessageItem:showCoApplyMsg()
  82. --头像
  83. local nodeHead = self.ui.Items.ImageView_head_1;
  84. local headSize = nodeHead:getContentSize()
  85. setPlayerHeadImage(self.msgInfo.uid, self.msgInfo.strHeadUrl, nodeHead);
  86. --名字
  87. local nickname = getSubStringNickname(self.msgInfo.nick or self.msgInfo.name or "")
  88. self.ui.Items.Text_name_1:setText(nickname);
  89. self.ui.Items.Text_uid:setText("("..self.msgInfo.uid..")");
  90. --职位
  91. local costr = "成员"
  92. if self.msgInfo.role == '3' then
  93. costr = string.format("创始人")
  94. elseif self.msgInfo.role == '2' then
  95. costr = string.format("管理员")
  96. elseif self.msgInfo.role == '4' then
  97. costr = string.format(ClubDefine.heHuoRenText)
  98. else
  99. costr = string.format("成员")
  100. end
  101. self.ui.Items.Text_id_1:setText(costr);
  102. --申请时间
  103. local time = os.date("%m.%d %H:%M:%S",self.msgInfo.applyTime);
  104. self.ui.Items.Text_apply_time_1:setText(time);
  105. --茶馆名
  106. -- local str = getShortNameByLength(self.msgInfo.clubName,5)
  107. -- self.ui.Items.Text_club_name:setText(str);
  108. --申请类型
  109. -- self.ui.Items.Text_apply_type:setText(self.msgInfo.msgType == 1 and "加入" or "退出");
  110. self.ui.Items.Text_club_name_1:setText(self.msgInfo.msgType == 1 and "加入" or "退出");
  111. --备注
  112. local conickname = getSubStringNickname(self.msgInfo.copartner_nick)
  113. self.ui.Items.Text_apply_type_1:setText(conickname);
  114. self.ui.Items.Text_apply_type_2:setText("("..self.msgInfo.copartner..")");
  115. --同意
  116. self.ui.Items.Button_agree_1:registerClick(handler(self,self.onAgree));
  117. --不同意
  118. self.ui.Items.Button_disagree_1:registerClick(handler(self,self.onDisAgree));
  119. self:updateStatus(self.msgInfo.status);
  120. end
  121. function ClubMessageItem:showCoApplyMatchMsg()
  122. --头像
  123. local nodeHead = self.ui.Items.ImageView_head_2;
  124. local headSize = nodeHead:getContentSize()
  125. setPlayerHeadImage(self.msgInfo.uid, self.msgInfo.strHeadUrl, nodeHead);
  126. --名字
  127. local nickname = getSubStringNickname(self.msgInfo.nick or self.msgInfo.name or "")
  128. self.ui.Items.Text_name_2:setText(nickname);
  129. self.ui.Items.Text_uid_1:setText("("..self.msgInfo.uid..")");
  130. --申请时间
  131. local time = os.date("%m.%d %H:%M:%S",self.msgInfo.applyTime);
  132. self.ui.Items.Text_apply_time_2:setText(time);
  133. --申请类型
  134. self.ui.Items.Text_club_name_2:setText(self.msgInfo.msgType == 1 and "加入" or "退出");
  135. --二级
  136. if self.msgInfo.copartner ~= 0 and self.msgInfo.copartner_nick then
  137. local conickname = getSubStringNickname(self.msgInfo.copartner_nick)
  138. self.ui.Items.Text_2_name:setText(conickname);
  139. self.ui.Items.Text_2_id:setText("("..self.msgInfo.copartner..")");
  140. else
  141. self.ui.Items.Text_2_name:setText("/");
  142. self.ui.Items.Text_2_name:setPositionPercent(cc.p(0.519,0.5))
  143. self.ui.Items.Text_2_id:setVisible(false)
  144. end
  145. --一级
  146. if self.msgInfo.copartner5 and self.msgInfo.copartner5_nick then
  147. local conickname = getSubStringNickname(self.msgInfo.copartner5_nick)
  148. self.ui.Items.Text_1_name:setText(conickname);
  149. self.ui.Items.Text_1_id:setText("("..self.msgInfo.copartner5..")");
  150. else
  151. self.ui.Items.Text_1_name:setText("/");
  152. self.ui.Items.Text_1_name:setPositionPercent(cc.p(0.519,0.5))
  153. self.ui.Items.Text_1_id:setVisible(false)
  154. end
  155. --同意
  156. self.ui.Items.Button_agree_2:registerClick(handler(self,self.onAgree));
  157. --不同意
  158. self.ui.Items.Button_disagree_2:registerClick(handler(self,self.onDisAgree));
  159. self.ui.Items.Text_belong:registerClick(handler(self,self.onClickBelong));
  160. self:updateStatus(self.msgInfo.status);
  161. end
  162. function ClubMessageItem:showAwardListMsg()
  163. --内容
  164. local strCont = '<font size="28" color="562915" stroke="size:0;color:#000000">' .. self.msgInfo.content .. '</font>'
  165. self.ui.Items.HtmlCtrl_activity_content:setText(strCont)
  166. --领取状态(0:未领取,1:已领取,2:已过期)
  167. if self.msgInfo.status == 0 then
  168. self.ui.Items.Button_get_reward:setVisible(true)
  169. self.ui.Items.Button_get_reward:registerClick(handler(self,self.onGetReward))
  170. self.ui.Items.ImageView_received:setVisible(false)
  171. self.ui.Items.ImageView_overtake:setVisible(false)
  172. elseif self.msgInfo.status == 2 then
  173. self.ui.Items.ImageView_received:setVisible(false)
  174. self.ui.Items.Button_get_reward:setVisible(false)
  175. self.ui.Items.ImageView_overtake:setVisible(true)
  176. else
  177. self.ui.Items.ImageView_received:setVisible(true)
  178. self.ui.Items.Button_get_reward:setVisible(false)
  179. self.ui.Items.ImageView_overtake:setVisible(false)
  180. end
  181. end
  182. --更新状态
  183. function ClubMessageItem:updateStatus(msgStatus)
  184. --申请状态:0申请1通过2拒绝
  185. if self.msgType == "coapplyMsg" then
  186. if msgStatus == 0 then
  187. --同意
  188. self.ui.Items.Button_agree_1:setVisible(true);
  189. --不同意
  190. self.ui.Items.Button_disagree_1:setVisible(true);
  191. --申请状态
  192. self.ui.Items.Text_statues_1:setVisible(false);
  193. else
  194. --同意
  195. self.ui.Items.Button_agree_1:setVisible(false);
  196. --不同意
  197. self.ui.Items.Button_disagree_1:setVisible(false);
  198. --申请状态
  199. self.ui.Items.Text_statues_1:setVisible(true);
  200. if msgStatus == 1 then
  201. --申请状态
  202. self.ui.Items.Text_statues_1:setText("已同意");
  203. self.ui.Items.Text_statues_1:setColor(cc.c3b(0,150,4))
  204. elseif msgStatus == 2 then
  205. --申请状态
  206. self.ui.Items.Text_statues_1:setText("已拒绝");
  207. self.ui.Items.Text_statues_1:setColor(cc.c3b(218,57,34))
  208. end
  209. end
  210. elseif self.msgType == "coapplyMatchMsg" then
  211. if msgStatus == 0 then
  212. --同意
  213. self.ui.Items.Button_agree_2:setVisible(true);
  214. --不同意
  215. self.ui.Items.Button_disagree_2:setVisible(true);
  216. --申请状态
  217. self.ui.Items.Text_statues_2:setVisible(false);
  218. self.ui.Items.Text_belong:setVisible(false);
  219. else
  220. --同意
  221. self.ui.Items.Button_agree_2:setVisible(false);
  222. --不同意
  223. self.ui.Items.Button_disagree_2:setVisible(false);
  224. --申请状态
  225. self.ui.Items.Text_statues_2:setVisible(true);
  226. self.ui.Items.Text_belong:setVisible(true);
  227. if self.msgInfo.operuid and self.msgInfo.operuid == 0 then
  228. self.ui.Items.Text_belong:setText("/");
  229. else
  230. if self.msgInfo.opernick then
  231. local name = getShortNameByLength(self.msgInfo.opernick,3)
  232. self.ui.Items.Text_belong:setText(tostring(name));
  233. end
  234. end
  235. if msgStatus == 1 then
  236. --申请状态
  237. self.ui.Items.Text_statues_2:setText("已同意");
  238. self.ui.Items.Text_statues_2:setColor(cc.c3b(0,150,4))
  239. elseif msgStatus == 2 then
  240. --申请状态
  241. self.ui.Items.Text_statues_2:setText("已拒绝");
  242. self.ui.Items.Text_statues_2:setColor(cc.c3b(235,72,15))
  243. end
  244. end
  245. else
  246. if msgStatus == 0 then
  247. --同意
  248. self.ui.Items.Button_agree:setVisible(true);
  249. --不同意
  250. self.ui.Items.Button_disagree:setVisible(true);
  251. --申请状态
  252. self.ui.Items.Text_statues:setVisible(false);
  253. else
  254. --同意
  255. self.ui.Items.Button_agree:setVisible(false);
  256. --不同意
  257. self.ui.Items.Button_disagree:setVisible(false);
  258. --申请状态
  259. self.ui.Items.Text_statues:setVisible(true);
  260. if msgStatus == 1 then
  261. --申请状态
  262. self.ui.Items.Text_statues:setText("已同意");
  263. self.ui.Items.Text_statues:setColor(cc.c3b(0,150,4))
  264. elseif msgStatus == 2 then
  265. --申请状态
  266. self.ui.Items.Text_statues:setText("已拒绝");
  267. self.ui.Items.Text_statues:setColor(cc.c3b(235,72,15))
  268. end
  269. end
  270. end
  271. end
  272. --同意
  273. function ClubMessageItem:onAgree()
  274. playBtnEffect()
  275. --参数1:申请的群id 参数2:申请的用户id 参数3:1同意,2拒绝, 3全部同意(无需applyUid)
  276. if self.msgInfo.msgType == 1 then
  277. app.club_php:requestChangeApplyStatus(self.clubId,self.msgInfo.uid,1,self.msgInfo.index)
  278. else
  279. app.club_php:requestChangeExitApplyStatus(self.clubId, self.msgInfo.uid, 1, self.msgInfo.index)
  280. end
  281. end
  282. --拒绝
  283. function ClubMessageItem:onDisAgree()
  284. playBtnEffect()
  285. --参数1:申请的群id 参数2:申请的用户id 参数3:1同意,2拒绝, 3全部同意(无需applyUid)
  286. if self.msgInfo.msgType == 1 then
  287. app.club_php:requestChangeApplyStatus(self.clubId,self.msgInfo.uid,2,self.msgInfo.index)
  288. else
  289. app.club_php:requestChangeExitApplyStatus(self.clubId, self.msgInfo.uid, 2, self.msgInfo.index)
  290. end
  291. end
  292. --消息处理成功回调
  293. function ClubMessageItem:onChangeMsgSuccess(event)
  294. --重新请求消息数据
  295. app.club_php:requestApplyMsg(tonumber(event.gid));
  296. end
  297. --领取奖励
  298. function ClubMessageItem:onGetReward()
  299. playBtnEffect()
  300. app.club_php:requestReward(self.clubId, self.msgInfo.awardId, self.msgInfo.awardSN)
  301. end
  302. function ClubMessageItem:onClickBelong()
  303. local isPlayEffect = true
  304. local txt = self.ui.Items.Text_belong:getText()
  305. if tonumber(txt) then
  306. --昵称
  307. local name = getShortNameByLength(self.msgInfo.opernick,3)
  308. self.ui.Items.Text_belong:setText(name)
  309. else
  310. local id = self.msgInfo.operuid
  311. if tonumber(id) == 0 then
  312. isPlayEffect = false
  313. else
  314. self.ui.Items.Text_belong:setText(tostring(id))
  315. end
  316. end
  317. if isPlayEffect then
  318. playBtnEffect()
  319. end
  320. end
  321. return ClubMessageItem