Files
tianrunCRM/Assets/trCRM/upgradeRes4Dev/priority/lua/ui/cell/TRCellExtendFieldRoot.lua

152 lines
4.2 KiB
Lua
Raw Normal View History

2020-07-10 13:22:24 +08:00
---@class _ParamCellExtendFiledRoot
---@field data any
---@field fields table _ParamCellExtendFiled的list
2020-07-15 20:53:37 +08:00
---@field onLoadOneField function 当加载完成一个字段时
2020-07-10 13:22:24 +08:00
---@field onFinish function 当加载完成
-- xx单元
2020-07-04 14:41:25 +08:00
local _cell = {}
---@type Coolape.CLCellLua
local csSelf = nil
local transform = nil
2020-07-10 13:22:24 +08:00
---@type _ParamCellExtendFiledRoot
2020-07-04 14:41:25 +08:00
local mData = nil
local uiobjs = {}
local fieldsObjs = {}
2020-07-10 13:22:24 +08:00
local queue = CLLQueue.new()
local isLoading = false
2020-07-18 21:12:14 +08:00
local count = 0
2020-07-04 14:41:25 +08:00
-- 初始化,只调用一次
function _cell.init(csObj)
csSelf = csObj
transform = csSelf.transform
---@type CLUIFormRoot
uiobjs.formRoot = csSelf:GetComponent("CLUIFormRoot")
---@type UITable
uiobjs.Table = csSelf:GetComponent("UITable")
end
-- 显示,
-- 注意c#侧不会在调用show时调用refresh
function _cell.show(go, data)
2020-07-10 13:22:24 +08:00
queue:enQueue(data)
if not isLoading then
_cell.refresh()
end
end
function _cell.refresh()
if queue:size() == 0 then
2020-07-04 14:41:25 +08:00
return
end
2020-07-10 13:22:24 +08:00
_cell.release()
isLoading = true
mData = queue:deQueue()
if mData.fields and #(mData.fields) > 0 then
showHotWheel()
2020-07-18 21:12:14 +08:00
for i, v in ipairs(mData.fields) do
_cell.initField(i)
end
2020-07-10 13:22:24 +08:00
else
_cell.onFinisInitFields()
end
end
function _cell.initField(index)
local fileAttr = mData.fields[index].attr
2020-07-04 14:41:25 +08:00
local name = ""
if fileAttr.attrType == DBCust.FieldType.popuplist then
name = "InputPoplist"
elseif fileAttr.attrType == DBCust.FieldType.dateTime then
name = "InputDate"
elseif fileAttr.attrType == DBCust.FieldType.multext then
name = "InputMultText"
elseif fileAttr.attrType == DBCust.FieldType.checkbox then
name = "InputCheckboxs"
2020-07-18 21:12:14 +08:00
elseif fileAttr.attrType == DBCust.FieldType.empty then
name = "EmptySpace"
2020-07-04 14:41:25 +08:00
else
name = "InputText"
end
2020-07-10 13:22:24 +08:00
CLUIOtherObjPool.borrowObjAsyn(name, _cell.onLoadField, index)
2020-07-04 14:41:25 +08:00
end
---@param go UnityEngine.GameObject
function _cell.onLoadField(name, go, orgs)
2020-07-10 13:22:24 +08:00
local index = orgs
---@type _ParamCellExtendFiled
local param = mData.fields[index]
2020-07-04 14:41:25 +08:00
local cell = go:GetComponent("CLCellLua")
2020-07-10 13:22:24 +08:00
if param.attr.attrType == DBCust.FieldType.multext then
-- 要设置一次
param.orgOnMultTextInputChg = param.onMultTextInputChg
param.onMultTextInputChg = _cell.onMultTextInputChg
end
cell:init(param, nil)
2020-07-18 21:12:14 +08:00
fieldsObjs[index] = cell
count = count + 1
2020-07-15 20:53:37 +08:00
Utl.doCallback(mData.onLoadOneField, cell)
2020-07-18 21:12:14 +08:00
if count == #(mData.fields) then
2020-07-04 14:41:25 +08:00
_cell.onFinisInitFields()
end
end
function _cell.onFinisInitFields()
2020-07-18 21:12:14 +08:00
for i, cell in ipairs(fieldsObjs) do
-- 在完成的时候时候再处理,是为了保证加进去的顺序不变
cell.transform.parent = transform
cell.transform.localScale = Vector3.one
cell.transform.localEulerAngles = Vector3.zero
SetActive(cell.gameObject, true)
uiobjs.Table:Reposition()
end
2020-07-10 13:22:24 +08:00
uiobjs.formRoot:setValue(mData.data)
2020-07-18 21:12:14 +08:00
uiobjs.Table.repositionNow = true
2020-07-04 14:41:25 +08:00
hideHotWheel()
2020-07-18 21:12:14 +08:00
csSelf:invoke4Lua(
function()
Utl.doCallback(mData.onFinish, csSelf.gameObject)
isLoading = false
-- 再次处理
_cell.refresh()
end,
0.1
)
2020-07-04 14:41:25 +08:00
end
function _cell.release()
for i, v in ipairs(fieldsObjs) do
SetActive(v.gameObject, false)
CLUIOtherObjPool.returnObj(v.gameObject)
end
fieldsObjs = {}
2020-07-18 21:12:14 +08:00
count = 0
2020-07-04 14:41:25 +08:00
end
2020-07-10 13:22:24 +08:00
function _cell.onMultTextInputChg(go)
2020-07-04 14:41:25 +08:00
uiobjs.Table.repositionNow = true
2020-07-10 13:22:24 +08:00
---@param v _ParamCellExtendFiled
if mData then
for i, v in ipairs(mData.fields) do
if v.attr.attrType == DBCust.FieldType.multext then
Utl.doCallback(v.orgOnMultTextInputChg, go)
end
end
end
2020-07-04 14:41:25 +08:00
end
-- 取得数据
function _cell.getData()
return mData
end
2020-07-18 21:12:14 +08:00
function _cell.OnDisable()
if #(fieldsObjs) > 0 then
2020-07-28 21:02:59 +08:00
printe("动态加载的字段没有释放" .. csSelf.name)
2020-07-18 21:12:14 +08:00
end
end
2020-07-04 14:41:25 +08:00
--------------------------------------------
return _cell