114 lines
3.1 KiB
Lua
114 lines
3.1 KiB
Lua
---@type IDBasePanel
|
||
local TRBasePanel = require("ui.panel.TRBasePanel")
|
||
---@class TRPCheckBoxs:TRBasePanel 邮件列表
|
||
local TRPCheckBoxs = class("TRPCheckBoxs", TRBasePanel)
|
||
|
||
local uiobjs = {}
|
||
local toggles = {}
|
||
-- 初始化,只会调用一次
|
||
function TRPCheckBoxs:init(csObj)
|
||
TRPCheckBoxs.super.init(self, csObj)
|
||
|
||
self:setEventDelegate()
|
||
local offset = getChild(self.transform, "Bottom/offset")
|
||
uiobjs.Grid = getCC(offset, "Content/Grid", "CLUILoopGrid")
|
||
uiobjs.LabelSelected = getCC(offset, "LabelSelected", "UILabel")
|
||
end
|
||
|
||
-- 设置数据
|
||
---@param paras _ParamTRPCheckBoxs
|
||
function TRPCheckBoxs:setData(paras)
|
||
self.mdata = paras[0]
|
||
self.defaultValue = paras[1]
|
||
self.selecteds = {}
|
||
local strs = strSplit(self.defaultValue, "|")
|
||
for i, v in ipairs(strs) do
|
||
self.selecteds[v] = true
|
||
end
|
||
self.isMultMode = paras[2]
|
||
self.callback = paras[3]
|
||
end
|
||
|
||
-- 显示,在c#中。show为调用refresh,show和refresh的区别在于,当页面已经显示了的情况,当页面再次出现在最上层时,只会调用refresh
|
||
function TRPCheckBoxs:show()
|
||
uiobjs.LabelSelected.text = "请选择"
|
||
local strs = strSplit(self.mdata.attrValue, "|")
|
||
toggles = {}
|
||
for i, v in ipairs(strs) do
|
||
local d = {label = v, isMultMode = self.isMultMode, checked = self.selecteds[v], panel = self}
|
||
table.insert(toggles, d)
|
||
end
|
||
uiobjs.Grid:setList(toggles, self:wrapFunc(self.initCell))
|
||
self:onClickToggle()
|
||
end
|
||
|
||
function TRPCheckBoxs:initCell(cell, data)
|
||
cell:init(data, nil)
|
||
end
|
||
|
||
-- 刷新
|
||
function TRPCheckBoxs:refresh()
|
||
end
|
||
|
||
function TRPCheckBoxs:onClickToggle()
|
||
local val = self:getValue()
|
||
if isNilOrEmpty(val) then
|
||
uiobjs.LabelSelected.text = "请选择"
|
||
else
|
||
uiobjs.LabelSelected.text = joinStr("已选择:", val)
|
||
end
|
||
end
|
||
|
||
-- 关闭页面
|
||
function TRPCheckBoxs:hide()
|
||
end
|
||
|
||
-- 网络请求的回调;cmd:指命,succ:成功失败,msg:消息;paras:服务器下行数据
|
||
function TRPCheckBoxs:procNetwork(cmd, succ, msg, paras)
|
||
if (succ == NetSuccess) then
|
||
--[[
|
||
if cmd == xx then
|
||
end
|
||
]]
|
||
end
|
||
end
|
||
|
||
function TRPCheckBoxs:getValue()
|
||
local values = {}
|
||
for i, v in ipairs(toggles) do
|
||
if v.checked then
|
||
table.insert(values, v.label)
|
||
end
|
||
end
|
||
return table.concat(values, "|")
|
||
end
|
||
|
||
function TRPCheckBoxs:setEventDelegate()
|
||
self.EventDelegate = {
|
||
SpriteBg = function()
|
||
hideTopPanel(self.csSelf)
|
||
end,
|
||
ButtonClose = function()
|
||
hideTopPanel(self.csSelf)
|
||
end,
|
||
ButtonOkay = function()
|
||
Utl.doCallback(self.callback, self:getValue())
|
||
hideTopPanel(self.csSelf)
|
||
end
|
||
}
|
||
end
|
||
-- 处理ui上的事件,例如点击等
|
||
function TRPCheckBoxs:uiEventDelegate(go)
|
||
local func = self.EventDelegate[go.name]
|
||
if func then
|
||
func()
|
||
end
|
||
end
|
||
|
||
-- 当顶层页面发生变化时回调
|
||
function TRPCheckBoxs:onTopPanelChange(topPanel)
|
||
end
|
||
|
||
--------------------------------------------
|
||
return TRPCheckBoxs
|