hengyang_client/lua_probject/base_project/Game/View/NewGroup/GroupMailView.lua

109 lines
3.6 KiB
Lua

--牌友圈邮件View
local GroupMailView = {}
local M = GroupMailView
function GroupMailView.new(blur_view, curGroup)
setmetatable(M, { __index = BaseWindow })
local self = setmetatable({}, { __index = M })
self.class = "GroupMailView"
self._close_destroy = true
self._blur_view = blur_view
self.curGroup = curGroup
self.mail_data = {}
self._full = true
self:init("ui://NewGroup/Win_Mail")
self:FillView()
return self
end
function M:FillView()
self.lst_mail = self._view:GetChild("lst_mail")
self.lst_mail:SetVirtual()
self.lst_mail.itemRenderer = function(index, obj)
self:OnRenderItem(index, obj)
end
self.lst_mail.scrollPane.onPullUpRelease:Set(function()
self:GetMailData(#self.mail_data)
end)
self:GetMailData(#self.mail_data)
local btn_delete = self._view:GetChild("btn_delete")
btn_delete.onClick:Set(function()
local msg_tip = MsgWindow.new(self._root_view, "确定要删除所有邮件吗?", MsgWindow.MsgMode.OkAndCancel)
msg_tip.onOk:Add(function()
self:DelAllMail()
end)
msg_tip:Show()
end)
end
function M:GetMailData(index)
ViewUtil.ShowModalWait2(nil)
local fgCtr = ControllerManager.GetController(NewGroupController)
fgCtr:FG_GetMailList(self.curGroup.id, DataManager.SelfUser.account_id, index, 20, function(res)
ViewUtil.CloseModalWait2()
if res.ReturnCode == 0 then
if #res.Data.mail_list > 0 then
list_concat(self.mail_data, res.Data.mail_list)
self.lst_mail.numItems = #self.mail_data
end
else
ViewUtil.ErrorTip(res.ReturnCode, "获取邮件列表失败")
end
end)
end
function M:DelAllMail()
ViewUtil.ShowModalWait2(nil)
local fgCtr = ControllerManager.GetController(NewGroupController)
fgCtr:FG_DelAllMail(self.curGroup.id, DataManager.SelfUser.account_id, function(res)
ViewUtil.CloseModalWait2()
if res.ReturnCode == 0 then
self.mail_data = {}
self.lst_mail.numItems = 0
else
ViewUtil.ErrorTip(res.ReturnCode, "删除邮件失败")
end
end)
end
function M:OnRenderItem(index, obj)
local tex_title = obj:GetChild("tex_title")
local tex_content = obj:GetChild("tex_content")
local data = json.decode(self.mail_data[index + 1])
ImageLoad.Load(data.headurl, obj:GetChild("btn_head")._iconObject, self.class)
local nick = data.nick
local id = data.mgr_id
local hp = d2ad(data.hp)
if data.type == 1 then
local str_lev = data.lev == 3 and "合伙人" or "管理员"
local act = hp >= 0 and "给您增加了" or "扣除了您"
tex_title.text = "消息内容为:" --string.format("%s(%s) %s%s积分", nick, id, act, math.abs(hp))
tex_content.text = string.format("%s [color=#08a446]%s[/color](%s) %s[color=#08a446] %s [/color]积分", str_lev,
nick, id, act, math.abs(hp))
else
tex_title.text = "消息内容为:" --string.format("%s(%s) 转账给您%s积分", nick, id, math.abs(hp))
tex_content.text = string.format("[color=#08a446]%s[/color](%s) 转账给您[color=#08a446] %s [/color]积分", nick, id,
math.abs(hp))
end
obj:GetChild("tex_data").text = os.date("%Y-%m-%d %H:%M", data.time)
end
function M:SetCallback(callback)
self.callback = callback
end
-- 销毁窗口
function M:Destroy(remove_map)
if self.callback then
self.callback()
end
BaseWindow.Destroy(self, remove_map)
ImageLoad.Clear(self.class)
end
return M