Files
tianrunCRM/Assets/trCRM/upgradeRes4Dev/priority/lua/ui/cell/TRCellExtendField.lua
2020-07-20 22:20:21 +08:00

281 lines
9.4 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 _ParamFieldAttr
---@field id
---@field attrType
---@field ifMust boolean 1:true
---@field ifTime boolean 1:true
---@field cannotEdit
---@field attrName
---@field attrValue
---@field checkMin
---@field checkMax
---@field popOptions
---@field popValues
---@field donotJoinKey boolean 是否要拼接key
---@field height numb 高度只有在emptyspace有用
---@class _ParamCellExtendFiled
---@field showMode _FieldMode
---@field attr _ParamFieldAttr
---@field onSelect function 当选择了poplist
---@field onClick function 当点击了输入框
---@field onInputChange
---@field onMultTextInputChg
-- xx单元
local _cell = {}
---@type Coolape.CLCellLua
local csSelf = nil
local transform = nil
---@type _ParamCellExtendFiled
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
attr.ifMust = attr.ifMust or 0
if uiobjs.spriteBg then
uiobjs.spriteBg.height = mData.attr.height or 160
end
NGUITools.AddWidgetCollider(csSelf.gameObject, false)
local jsonKey
if attr.donotJoinKey then
jsonKey = attr.id
else
jsonKey = joinStr(attr.id, "_", attr.attrName)
end
if uiobjs.element then
uiobjs.element.valueIsNumber = false
uiobjs.element.isPhoneNum = false
uiobjs.element.canNull = (attr.ifMust == 0 and true or false)
uiobjs.element.jsonKey = jsonKey
uiobjs.element.labeName.text = attr.attrName
elseif uiobjs.checkbox then
uiobjs.checkbox.canNull = (attr.ifMust == 0 and true or false)
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
local elementDate = csSelf:GetComponent("CLUIElementDate")
if elementDate then
elementDate.isSetTime = ((attr.ifTime and attr.ifTime == 1) and true or false)
end
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
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)
end
end
-- 设置展示的模式
_cell.setElementMode(mData.showMode or _FieldMode.inputOnly)
end
function _cell.enabeldObj(obj, val)
if obj then
obj.enabled = val
end
end
function _cell.setElementMode(mode)
local isPopList = uiobjs.popList
local isPopCheckbox = uiobjs.checkbox
---@type UIInput
local input = uiobjs.input
local boxcollider = uiobjs.boxCollider
local ButtonReset = uiobjs.ButtonReset
if mode == _FieldMode.inputOnly then
_cell.enabeldObj(boxcollider, 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(input, false)
_cell.enabeldObj(uiobjs.SpriteRight, true)
else
_cell.enabeldObj(uiobjs.SpriteRight, false)
_cell.enabeldObj(input, true)
end
elseif mode == _FieldMode.showOnly then
_cell.enabeldObj(boxcollider, 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(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(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(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
-- 取得数据
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)
Utl.doCallback(mData.onMultTextInputChg, uiobjs.element)
elseif
attr.attrType == DBCust.FieldType.number or attr.attrType == DBCust.FieldType.phone or
attr.attrType == DBCust.FieldType.text
then
Utl.doCallback(mData.onInputChange, uiobjs.element)
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
Utl.doCallback(mData.onSelect, uiobjs.element)
else
Utl.doCallback(mData.onClick, uiobjs.element)
end
end
--------------------------------------------
return _cell