Files
tianrunCRM/Assets/trCRM/upgradeRes4Dev/priority/lua/ui/cell/TRCellExtendFieldRoot.lua
2020-07-28 21:02:59 +08:00

152 lines
4.2 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---@class _ParamCellExtendFiledRoot
---@field data any
---@field fields table _ParamCellExtendFiled的list
---@field onLoadOneField function 当加载完成一个字段时
---@field onFinish function 当加载完成
-- xx单元
local _cell = {}
---@type Coolape.CLCellLua
local csSelf = nil
local transform = nil
---@type _ParamCellExtendFiledRoot
local mData = nil
local uiobjs = {}
local fieldsObjs = {}
local queue = CLLQueue.new()
local isLoading = false
local count = 0
-- 初始化,只调用一次
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)
queue:enQueue(data)
if not isLoading then
_cell.refresh()
end
end
function _cell.refresh()
if queue:size() == 0 then
return
end
_cell.release()
isLoading = true
mData = queue:deQueue()
if mData.fields and #(mData.fields) > 0 then
showHotWheel()
for i, v in ipairs(mData.fields) do
_cell.initField(i)
end
else
_cell.onFinisInitFields()
end
end
function _cell.initField(index)
local fileAttr = mData.fields[index].attr
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"
elseif fileAttr.attrType == DBCust.FieldType.empty then
name = "EmptySpace"
else
name = "InputText"
end
CLUIOtherObjPool.borrowObjAsyn(name, _cell.onLoadField, index)
end
---@param go UnityEngine.GameObject
function _cell.onLoadField(name, go, orgs)
local index = orgs
---@type _ParamCellExtendFiled
local param = mData.fields[index]
local cell = go:GetComponent("CLCellLua")
if param.attr.attrType == DBCust.FieldType.multext then
-- 要设置一次
param.orgOnMultTextInputChg = param.onMultTextInputChg
param.onMultTextInputChg = _cell.onMultTextInputChg
end
cell:init(param, nil)
fieldsObjs[index] = cell
count = count + 1
Utl.doCallback(mData.onLoadOneField, cell)
if count == #(mData.fields) then
_cell.onFinisInitFields()
end
end
function _cell.onFinisInitFields()
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
uiobjs.formRoot:setValue(mData.data)
uiobjs.Table.repositionNow = true
hideHotWheel()
csSelf:invoke4Lua(
function()
Utl.doCallback(mData.onFinish, csSelf.gameObject)
isLoading = false
-- 再次处理
_cell.refresh()
end,
0.1
)
end
function _cell.release()
for i, v in ipairs(fieldsObjs) do
SetActive(v.gameObject, false)
CLUIOtherObjPool.returnObj(v.gameObject)
end
fieldsObjs = {}
count = 0
end
function _cell.onMultTextInputChg(go)
uiobjs.Table.repositionNow = true
---@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
end
-- 取得数据
function _cell.getData()
return mData
end
function _cell.OnDisable()
if #(fieldsObjs) > 0 then
printe("动态加载的字段没有释放" .. csSelf.name)
end
end
--------------------------------------------
return _cell