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

279 lines
9.5 KiB
Lua
Raw Normal View History

2020-07-04 14:41:25 +08:00
---@class _ParamFieldAttr
2020-07-18 21:12:14 +08:00
---@field id
2020-07-04 14:41:25 +08:00
---@field attrType
2020-07-10 13:22:24 +08:00
---@field ifMust boolean 1:true
2020-07-18 21:12:14 +08:00
---@field ifTime boolean 1:true
---@field cannotEdit
2020-07-04 14:41:25 +08:00
---@field attrName
---@field attrValue
---@field checkMin
---@field checkMax
2020-07-10 13:22:24 +08:00
---@field popOptions
---@field popValues
---@field donotJoinKey boolean 是否要拼接key
2020-07-18 21:12:14 +08:00
---@field height numb 高度只有在emptyspace有用
2020-07-04 14:41:25 +08:00
2020-07-10 13:22:24 +08:00
---@class _ParamCellExtendFiled
2020-07-18 21:12:14 +08:00
---@field showMode _FieldMode
2020-07-10 13:22:24 +08:00
---@field attr _ParamFieldAttr
---@field onSelect function 当选择了poplist
---@field onClick function 当点击了输入框
---@field onInputChange
---@field onMultTextInputChg
2020-07-04 14:41:25 +08:00
-- xx单元
local _cell = {}
---@type Coolape.CLCellLua
local csSelf = nil
local transform = nil
2020-07-10 13:22:24 +08:00
---@type _ParamCellExtendFiled
2020-07-04 14:41:25 +08:00
local mData = nil
---@type _ParamFieldAttr
local attr
local uiobjs = {}
-- 初始化,只调用一次
function _cell.init(csObj)
csSelf = csObj
transform = csSelf.transform
---@type UISprite
uiobjs.spriteBg = csSelf:GetComponent("UISprite")
if uiobjs.spriteBg == nil then
uiobjs.spriteBg = getCC(transform, "Background", "UISprite")
end
uiobjs.boxCollider = csSelf:GetComponent("BoxCollider")
---@type UIInput
uiobjs.input = csSelf:GetComponent("UIInput")
---@type CLUIElement
uiobjs.element = csSelf:GetComponent("CLUIElement")
---@type UIPopupList
uiobjs.popList = csSelf:GetComponent("UIPopupList")
---@type CLUICheckbox
uiobjs.checkbox = csSelf:GetComponent("CLUICheckbox")
uiobjs.Label = getCC(transform, "Label", "UILabel")
uiobjs.inputLabel = uiobjs.Label and uiobjs.Label.text or ""
uiobjs.Label2 = getCC(transform, "Label2", "UILabel")
uiobjs.Label4 = getCC(transform, "Label4", "UILabel")
uiobjs.SpriteRight = getCC(transform, "SpriteRight", "UISprite")
uiobjs.ButtonReset = getCC(transform, "ButtonReset", "MyInputReset")
end
-- 显示,
-- 注意c#侧不会在调用show时调用refresh
function _cell.show(go, data)
mData = data
attr = mData.attr
2020-07-10 13:22:24 +08:00
attr.ifMust = attr.ifMust or 0
2020-07-04 14:41:25 +08:00
2020-07-10 13:22:24 +08:00
local jsonKey
if attr.donotJoinKey then
jsonKey = attr.id
else
jsonKey = joinStr(attr.id, "_", attr.attrName)
end
2020-07-04 14:41:25 +08:00
if uiobjs.element then
uiobjs.element.valueIsNumber = false
uiobjs.element.isPhoneNum = false
2020-07-10 13:22:24 +08:00
uiobjs.element.canNull = (attr.ifMust == 0 and true or false)
2020-07-04 14:41:25 +08:00
uiobjs.element.jsonKey = jsonKey
uiobjs.element.labeName.text = attr.attrName
elseif uiobjs.checkbox then
2020-07-10 13:22:24 +08:00
uiobjs.checkbox.canNull = (attr.ifMust == 0 and true or false)
2020-07-04 14:41:25 +08:00
uiobjs.checkbox.jsonKey = jsonKey
uiobjs.checkbox.labeName.text = attr.attrName
end
if attr.attrType == DBCust.FieldType.text then
uiobjs.input.keyboardType = UIInput.KeyboardType.Default
elseif attr.attrType == DBCust.FieldType.number then
uiobjs.input.keyboardType = UIInput.KeyboardType.NumberPad
uiobjs.element.valueIsNumber = true
elseif attr.attrType == DBCust.FieldType.phone then
uiobjs.input.keyboardType = UIInput.KeyboardType.PhonePad
uiobjs.element.isPhoneNum = true
elseif attr.attrType == DBCust.FieldType.multext then
uiobjs.input.keyboardType = UIInput.KeyboardType.Default
elseif attr.attrType == DBCust.FieldType.dateTime then
2020-07-18 21:12:14 +08:00
local elementDate = csSelf:GetComponent("CLUIElementDate")
if elementDate then
elementDate.isSetTime = ((attr.ifTime and attr.ifTime == 1) and true or false)
end
2020-07-04 14:41:25 +08:00
elseif attr.attrType == DBCust.FieldType.checkbox then
local max = tonumber(attr.checkMax) or 0
uiobjs.checkbox.isMultMode = (max > 1) or (max == 0)
uiobjs.checkbox:init(attr)
elseif attr.attrType == DBCust.FieldType.popuplist then
2020-07-10 13:22:24 +08:00
if attr.popOptions then
uiobjs.popList:refreshItems(attr.popOptions, attr.popValues)
else
local strs = strSplit((attr.attrValue or ""), "|")
local array = ArrayList()
-- array:Add("")
for i, v in ipairs(strs) do
array:Add(v)
end
uiobjs.popList:refreshItems(array, array)
2020-07-04 14:41:25 +08:00
end
end
2020-07-18 21:12:14 +08:00
-- 设置展示的模式
_cell.setElementMode(mData.showMode or _FieldMode.inputOnly)
2020-07-04 14:41:25 +08:00
end
function _cell.enabeldObj(obj, val)
if obj then
obj.enabled = val
end
end
2020-07-18 21:12:14 +08:00
function _cell.setElementMode(mode)
local isPopList = uiobjs.popList
local isPopCheckbox = uiobjs.checkbox
---@type UIInput
local input = uiobjs.input
local inputOnGUI = csSelf:GetComponent("UIInputOnGUI")
local boxcollider = uiobjs.boxCollider
local ButtonReset = uiobjs.ButtonReset
if mode == _FieldMode.inputOnly then
_cell.enabeldObj(boxcollider, true)
_cell.enabeldObj(inputOnGUI, true)
_cell.enabeldObj(input, true)
if uiobjs.Label2 then
uiobjs.Label2.color = ColorEx.getColor(0xff999999)
end
if uiobjs.ButtonReset then
uiobjs.ButtonReset.disabled = false
end
if uiobjs.Label then
uiobjs.Label.text = uiobjs.inputLabel
end
if uiobjs.input then
uiobjs.input.defaultText = uiobjs.inputLabel
end
_cell.enabeldObj(uiobjs.Label4, true) -- multext
if
attr.attrType == DBCust.FieldType.dateTime or attr.attrType == DBCust.FieldType.checkbox or
attr.attrType == DBCust.FieldType.popuplist
then
_cell.enabeldObj(uiobjs.SpriteRight, true)
else
_cell.enabeldObj(uiobjs.SpriteRight, false)
end
elseif mode == _FieldMode.showOnly then
_cell.enabeldObj(boxcollider, false)
_cell.enabeldObj(inputOnGUI, false)
_cell.enabeldObj(input, false)
if uiobjs.Label2 then
uiobjs.Label2.color = ColorEx.getColor(0xff999999)
end
if uiobjs.ButtonReset then
uiobjs.ButtonReset.disabled = true
end
if uiobjs.Label then
uiobjs.Label.text = ""
end
if uiobjs.input then
uiobjs.input.defaultText = ""
end
_cell.enabeldObj(uiobjs.Label4, false)
_cell.enabeldObj(uiobjs.SpriteRight, false)
elseif mode == _FieldMode.modifyOnly then
_cell.enabeldObj(boxcollider, true)
_cell.enabeldObj(inputOnGUI, false)
_cell.enabeldObj(input, false)
if uiobjs.Label2 then
uiobjs.Label2.color = ColorEx.getColor(0xff999999)
end
if uiobjs.ButtonReset then
uiobjs.ButtonReset.disabled = true
end
if uiobjs.Label then
uiobjs.Label.text = uiobjs.inputLabel
end
if uiobjs.input then
uiobjs.input.defaultText = uiobjs.inputLabel
end
_cell.enabeldObj(uiobjs.Label4, true)
_cell.enabeldObj(uiobjs.SpriteRight, true)
elseif mode == _FieldMode.showAndModify then
_cell.enabeldObj(boxcollider, true)
_cell.enabeldObj(inputOnGUI, false)
_cell.enabeldObj(input, false)
if uiobjs.Label2 then
uiobjs.Label2.color = ColorEx.getColor(0xff999999)
end
if uiobjs.ButtonReset then
uiobjs.ButtonReset.disabled = true
end
if uiobjs.Label then
uiobjs.Label.text = ""
end
if uiobjs.input then
uiobjs.input.defaultText = ""
end
_cell.enabeldObj(uiobjs.Label4, false)
_cell.enabeldObj(uiobjs.SpriteRight, true)
elseif mode == _FieldMode.button then
_cell.enabeldObj(boxcollider, true)
_cell.enabeldObj(inputOnGUI, false)
_cell.enabeldObj(input, false)
if uiobjs.Label2 then
uiobjs.Label2.color = ColorEx.getColor(0xff363636)
end
if uiobjs.ButtonReset then
uiobjs.ButtonReset.disabled = true
end
if uiobjs.Label then
uiobjs.Label.text = ""
end
if uiobjs.input then
uiobjs.input.defaultText = ""
end
_cell.enabeldObj(uiobjs.Label4, false)
_cell.enabeldObj(uiobjs.SpriteRight, true)
end
-- 再次修正input
if
attr.attrType == DBCust.FieldType.dateTime or attr.attrType == DBCust.FieldType.checkbox or
attr.attrType == DBCust.FieldType.popuplist
then
_cell.enabeldObj(input, false)
end
end
2020-07-04 14:41:25 +08:00
-- 取得数据
function _cell.getData()
return mData
end
function _cell.uiEventDelegate(go)
if attr.attrType == DBCust.FieldType.multext then
-- 说明大文本框改变了
NGUITools.AddWidgetCollider(csSelf.gameObject, false)
uiobjs.Label4.enabled = (uiobjs.element.value == "" and true or false)
2020-07-18 21:12:14 +08:00
Utl.doCallback(mData.onMultTextInputChg, uiobjs.element)
2020-07-10 13:22:24 +08:00
elseif
attr.attrType == DBCust.FieldType.number or attr.attrType == DBCust.FieldType.phone or
attr.attrType == DBCust.FieldType.text
then
2020-07-18 21:12:14 +08:00
Utl.doCallback(mData.onInputChange, uiobjs.element)
2020-07-04 14:41:25 +08:00
end
end
function _cell.onNotifyLua(go)
if
attr.attrType == DBCust.FieldType.popuplist or attr.attrType == DBCust.FieldType.checkbox or
attr.attrType == DBCust.FieldType.dateTime
then
2020-07-18 21:12:14 +08:00
Utl.doCallback(mData.onSelect, uiobjs.element)
2020-07-04 14:41:25 +08:00
else
2020-07-18 21:12:14 +08:00
Utl.doCallback(mData.onClick, uiobjs.element)
2020-07-04 14:41:25 +08:00
end
end
--------------------------------------------
return _cell