-- 消息ItemLayout local ClubDefine = require("luaScript.Protocol.Club.ClubDefine") local ClubMessageItem = class("ClubMessageItem"); function ClubMessageItem:ctor(data, msgType, clubId) self.ui = loadUI("res/ui/ui_club/ui_club_message_item.ui"); local uiSize = self.ui:getSize(); local realSize = {width = uiSize.width * g_radio_x,height = uiSize.height * g_radio_y} self.ui:setSize(realSize) --消息内容 self.msgInfo = data; --消息类型 self.msgType = msgType; --茶馆id self.clubId = clubId; self:showInfo() end function ClubMessageItem:showInfo() self.ui.Items.Layout_msg:setVisible(false); self.ui.Items.Layout_apply_msg:setVisible(false); self.ui.Items.Layout_activity:setVisible(false); self.ui.Items.Layout_coapply_msg:setVisible(false); self.ui.Items.Layout_match_coapply_msg:setVisible(false); if self.msgType == "msg" then self.ui.Items.Layout_msg:setVisible(true); --设置普通消息内容 self:showMsg(); elseif self.msgType == "applyMsg" then self.ui.Items.Layout_apply_msg:setVisible(true); --设置申请消息内容 self:showApplyMsg(); elseif self.msgType == "coapplyMsg" then self.ui.Items.Layout_coapply_msg:setVisible(true); --设置合伙人申请消息内容 self:showCoApplyMsg(); elseif self.msgType == "awardListMsg" then self.ui.Items.Layout_activity:setVisible(true); --设置奖励内容列表 self:showAwardListMsg(); elseif self.msgType == "coapplyMatchMsg" then self.ui.Items.Layout_match_coapply_msg:setVisible(true); --设置合伙人申请消息内容 self:showCoApplyMatchMsg(); end end function ClubMessageItem:showMsg() --消息内容 local strCont = self.msgInfo.content --统一处理以前的老消息,未加颜色标签 if not string.find(self.msgInfo.content, "font") then strCont = '' .. self.msgInfo.content .. '' end self.ui.Items.HtmlCtrl_msg:setText(strCont) --收到消息时间 local time = os.date("%m.%d %H:%M:%S",self.msgInfo.date); self.ui.Items.Text_time:setText(time); end function ClubMessageItem:showApplyMsg() --头像 local nodeHead = self.ui.Items.ImageView_head; local headSize = nodeHead:getContentSize() setPlayerHeadImage(self.msgInfo.uid, self.msgInfo.strHeadUrl, nodeHead); --名字 local nickname = getSubStringNickname(self.msgInfo.nick or self.msgInfo.name or "", self.ui.Items.Text_name) self.ui.Items.Text_name:setText(nickname); --id self.ui.Items.Text_id:setText(self.msgInfo.uid); --申请时间 local time = os.date("%m.%d %H:%M:%S",self.msgInfo.applyTime); self.ui.Items.Text_apply_time:setText(time); -- --茶馆名 -- local str = getShortNameByLength(self.msgInfo.clubName,5) -- self.ui.Items.Text_club_name:setText(str); --申请类型 self.ui.Items.Text_apply_type:setText(self.msgInfo.msgType == 1 and "加入" or "退出"); --同意 self.ui.Items.Button_agree:registerClick(handler(self,self.onAgree)); --不同意 self.ui.Items.Button_disagree:registerClick(handler(self,self.onDisAgree)); self:updateStatus(self.msgInfo.status); end function ClubMessageItem:showCoApplyMsg() --头像 local nodeHead = self.ui.Items.ImageView_head_1; local headSize = nodeHead:getContentSize() setPlayerHeadImage(self.msgInfo.uid, self.msgInfo.strHeadUrl, nodeHead); --名字 local nickname = getSubStringNickname(self.msgInfo.nick or self.msgInfo.name or "") self.ui.Items.Text_name_1:setText(nickname); self.ui.Items.Text_uid:setText("("..self.msgInfo.uid..")"); --职位 local costr = "成员" if self.msgInfo.role == '3' then costr = string.format("创始人") elseif self.msgInfo.role == '2' then costr = string.format("管理员") elseif self.msgInfo.role == '4' then costr = string.format(ClubDefine.heHuoRenText) else costr = string.format("成员") end self.ui.Items.Text_id_1:setText(costr); --申请时间 local time = os.date("%m.%d %H:%M:%S",self.msgInfo.applyTime); self.ui.Items.Text_apply_time_1:setText(time); --茶馆名 -- local str = getShortNameByLength(self.msgInfo.clubName,5) -- self.ui.Items.Text_club_name:setText(str); --申请类型 -- self.ui.Items.Text_apply_type:setText(self.msgInfo.msgType == 1 and "加入" or "退出"); self.ui.Items.Text_club_name_1:setText(self.msgInfo.msgType == 1 and "加入" or "退出"); --备注 local conickname = getSubStringNickname(self.msgInfo.copartner_nick) self.ui.Items.Text_apply_type_1:setText(conickname); self.ui.Items.Text_apply_type_2:setText("("..self.msgInfo.copartner..")"); --同意 self.ui.Items.Button_agree_1:registerClick(handler(self,self.onAgree)); --不同意 self.ui.Items.Button_disagree_1:registerClick(handler(self,self.onDisAgree)); self:updateStatus(self.msgInfo.status); end function ClubMessageItem:showCoApplyMatchMsg() --头像 local nodeHead = self.ui.Items.ImageView_head_2; local headSize = nodeHead:getContentSize() setPlayerHeadImage(self.msgInfo.uid, self.msgInfo.strHeadUrl, nodeHead); --名字 local nickname = getSubStringNickname(self.msgInfo.nick or self.msgInfo.name or "") self.ui.Items.Text_name_2:setText(nickname); self.ui.Items.Text_uid_1:setText("("..self.msgInfo.uid..")"); --申请时间 local time = os.date("%m.%d %H:%M:%S",self.msgInfo.applyTime); self.ui.Items.Text_apply_time_2:setText(time); --申请类型 self.ui.Items.Text_club_name_2:setText(self.msgInfo.msgType == 1 and "加入" or "退出"); --二级 if self.msgInfo.copartner ~= 0 and self.msgInfo.copartner_nick then local conickname = getSubStringNickname(self.msgInfo.copartner_nick) self.ui.Items.Text_2_name:setText(conickname); self.ui.Items.Text_2_id:setText("("..self.msgInfo.copartner..")"); else self.ui.Items.Text_2_name:setText("/"); self.ui.Items.Text_2_name:setPositionPercent(cc.p(0.519,0.5)) self.ui.Items.Text_2_id:setVisible(false) end --一级 if self.msgInfo.copartner5 and self.msgInfo.copartner5_nick then local conickname = getSubStringNickname(self.msgInfo.copartner5_nick) self.ui.Items.Text_1_name:setText(conickname); self.ui.Items.Text_1_id:setText("("..self.msgInfo.copartner5..")"); else self.ui.Items.Text_1_name:setText("/"); self.ui.Items.Text_1_name:setPositionPercent(cc.p(0.519,0.5)) self.ui.Items.Text_1_id:setVisible(false) end --同意 self.ui.Items.Button_agree_2:registerClick(handler(self,self.onAgree)); --不同意 self.ui.Items.Button_disagree_2:registerClick(handler(self,self.onDisAgree)); self.ui.Items.Text_belong:registerClick(handler(self,self.onClickBelong)); self:updateStatus(self.msgInfo.status); end function ClubMessageItem:showAwardListMsg() --内容 local strCont = '' .. self.msgInfo.content .. '' self.ui.Items.HtmlCtrl_activity_content:setText(strCont) --领取状态(0:未领取,1:已领取,2:已过期) if self.msgInfo.status == 0 then self.ui.Items.Button_get_reward:setVisible(true) self.ui.Items.Button_get_reward:registerClick(handler(self,self.onGetReward)) self.ui.Items.ImageView_received:setVisible(false) self.ui.Items.ImageView_overtake:setVisible(false) elseif self.msgInfo.status == 2 then self.ui.Items.ImageView_received:setVisible(false) self.ui.Items.Button_get_reward:setVisible(false) self.ui.Items.ImageView_overtake:setVisible(true) else self.ui.Items.ImageView_received:setVisible(true) self.ui.Items.Button_get_reward:setVisible(false) self.ui.Items.ImageView_overtake:setVisible(false) end end --更新状态 function ClubMessageItem:updateStatus(msgStatus) --申请状态:0申请1通过2拒绝 if self.msgType == "coapplyMsg" then if msgStatus == 0 then --同意 self.ui.Items.Button_agree_1:setVisible(true); --不同意 self.ui.Items.Button_disagree_1:setVisible(true); --申请状态 self.ui.Items.Text_statues_1:setVisible(false); else --同意 self.ui.Items.Button_agree_1:setVisible(false); --不同意 self.ui.Items.Button_disagree_1:setVisible(false); --申请状态 self.ui.Items.Text_statues_1:setVisible(true); if msgStatus == 1 then --申请状态 self.ui.Items.Text_statues_1:setText("已同意"); self.ui.Items.Text_statues_1:setColor(cc.c3b(0,150,4)) elseif msgStatus == 2 then --申请状态 self.ui.Items.Text_statues_1:setText("已拒绝"); self.ui.Items.Text_statues_1:setColor(cc.c3b(218,57,34)) end end elseif self.msgType == "coapplyMatchMsg" then if msgStatus == 0 then --同意 self.ui.Items.Button_agree_2:setVisible(true); --不同意 self.ui.Items.Button_disagree_2:setVisible(true); --申请状态 self.ui.Items.Text_statues_2:setVisible(false); self.ui.Items.Text_belong:setVisible(false); else --同意 self.ui.Items.Button_agree_2:setVisible(false); --不同意 self.ui.Items.Button_disagree_2:setVisible(false); --申请状态 self.ui.Items.Text_statues_2:setVisible(true); self.ui.Items.Text_belong:setVisible(true); if self.msgInfo.operuid and self.msgInfo.operuid == 0 then self.ui.Items.Text_belong:setText("/"); else if self.msgInfo.opernick then local name = getShortNameByLength(self.msgInfo.opernick,3) self.ui.Items.Text_belong:setText(tostring(name)); end end if msgStatus == 1 then --申请状态 self.ui.Items.Text_statues_2:setText("已同意"); self.ui.Items.Text_statues_2:setColor(cc.c3b(0,150,4)) elseif msgStatus == 2 then --申请状态 self.ui.Items.Text_statues_2:setText("已拒绝"); self.ui.Items.Text_statues_2:setColor(cc.c3b(235,72,15)) end end else if msgStatus == 0 then --同意 self.ui.Items.Button_agree:setVisible(true); --不同意 self.ui.Items.Button_disagree:setVisible(true); --申请状态 self.ui.Items.Text_statues:setVisible(false); else --同意 self.ui.Items.Button_agree:setVisible(false); --不同意 self.ui.Items.Button_disagree:setVisible(false); --申请状态 self.ui.Items.Text_statues:setVisible(true); if msgStatus == 1 then --申请状态 self.ui.Items.Text_statues:setText("已同意"); self.ui.Items.Text_statues:setColor(cc.c3b(0,150,4)) elseif msgStatus == 2 then --申请状态 self.ui.Items.Text_statues:setText("已拒绝"); self.ui.Items.Text_statues:setColor(cc.c3b(235,72,15)) end end end end --同意 function ClubMessageItem:onAgree() playBtnEffect() --参数1:申请的群id 参数2:申请的用户id 参数3:1同意,2拒绝, 3全部同意(无需applyUid) if self.msgInfo.msgType == 1 then app.club_php:requestChangeApplyStatus(self.clubId,self.msgInfo.uid,1,self.msgInfo.index) else app.club_php:requestChangeExitApplyStatus(self.clubId, self.msgInfo.uid, 1, self.msgInfo.index) end end --拒绝 function ClubMessageItem:onDisAgree() playBtnEffect() --参数1:申请的群id 参数2:申请的用户id 参数3:1同意,2拒绝, 3全部同意(无需applyUid) if self.msgInfo.msgType == 1 then app.club_php:requestChangeApplyStatus(self.clubId,self.msgInfo.uid,2,self.msgInfo.index) else app.club_php:requestChangeExitApplyStatus(self.clubId, self.msgInfo.uid, 2, self.msgInfo.index) end end --消息处理成功回调 function ClubMessageItem:onChangeMsgSuccess(event) --重新请求消息数据 app.club_php:requestApplyMsg(tonumber(event.gid)); end --领取奖励 function ClubMessageItem:onGetReward() playBtnEffect() app.club_php:requestReward(self.clubId, self.msgInfo.awardId, self.msgInfo.awardSN) end function ClubMessageItem:onClickBelong() local isPlayEffect = true local txt = self.ui.Items.Text_belong:getText() if tonumber(txt) then --昵称 local name = getShortNameByLength(self.msgInfo.opernick,3) self.ui.Items.Text_belong:setText(name) else local id = self.msgInfo.operuid if tonumber(id) == 0 then isPlayEffect = false else self.ui.Items.Text_belong:setText(tostring(id)) end end if isPlayEffect then playBtnEffect() end end return ClubMessageItem