Files
tianrunCRM/Assets/trCRM/upgradeRes4Dev/priority/lua/ui/cell/TRCellExtendField.lua
2020-07-04 14:41:25 +08:00

165 lines
5.3 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 attrType
---@field ifMust
---@field attrName
---@field attrValue
---@field id
---@field checkMin
---@field checkMax
---@class _ParamCellExtendField
---@field
-- xx单元
local _cell = {}
---@type Coolape.CLCellLua
local csSelf = nil
local transform = nil
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
if uiobjs.spriteBg then
uiobjs.spriteBg.width = NumEx.getIntPart(CSPMain.contentRect.z)
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
if data.isEditMode then
_cell.enabeldObj(uiobjs.boxCollider, true)
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)
if uiobjs.ButtonReset then
uiobjs.ButtonReset.disabled = false
end
else
_cell.enabeldObj(uiobjs.boxCollider, false)
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)
if uiobjs.ButtonReset then
uiobjs.ButtonReset.disabled = true
end
end
local jsonKey = joinStr(attr.id, "_", attr.attrName)
if uiobjs.element then
uiobjs.element.valueIsNumber = false
uiobjs.element.isPhoneNum = false
uiobjs.element.canNull = (attr.ifMust == 1 and false or true)
uiobjs.element.jsonKey = jsonKey
uiobjs.element.labeName.text = attr.attrName
elseif uiobjs.checkbox then
uiobjs.checkbox.canNull = (attr.ifMust == 1 and false or true)
uiobjs.checkbox.jsonKey = jsonKey
uiobjs.checkbox.labeName.text = attr.attrName
end
_cell.enabeldObj(uiobjs.input, true)
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
_cell.enabeldObj(uiobjs.input, false)
elseif attr.attrType == DBCust.FieldType.checkbox then
_cell.enabeldObj(uiobjs.input, false)
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
_cell.enabeldObj(uiobjs.input, false)
local strs = strSplit(attr.attrValue, "|")
local array = ArrayList()
array:Add("")
for i, v in ipairs(strs) do
array:Add(v)
end
uiobjs.popList:refreshItems(array, array)
end
end
function _cell.enabeldObj(obj, val)
if obj then
obj.enabled = val
end
end
-- 取得数据
function _cell.getData()
return mData
end
function _cell.uiEventDelegate(go)
if attr.attrType == DBCust.FieldType.multext then
-- 说明大文本框改变了
mData.parent.onMultTextInputChg()
NGUITools.AddWidgetCollider(csSelf.gameObject, false)
uiobjs.Label4.enabled = (uiobjs.element.value == "" and true or false)
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, csSelf.gameObject)
else
Utl.doCallback(mData.onClick, csSelf.gameObject)
end
end
--------------------------------------------
return _cell