---@class _ParamFieldAttr ---@field attrType ---@field ifMust boolean 1:true ---@field attrName ---@field attrValue ---@field id ---@field checkMin ---@field checkMax ---@field popOptions ---@field popValues ---@field donotJoinKey boolean 是否要拼接key ---@class _ParamCellExtendFiled ---@field isEditMode boolean ---@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 -- 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 attr.ifMust = attr.ifMust or 0 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 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 _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) 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 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 -- 说明大文本框改变了 NGUITools.AddWidgetCollider(csSelf.gameObject, false) uiobjs.Label4.enabled = (uiobjs.element.value == "" and true or false) Utl.doCallback(mData.onMultTextInputChg, csSelf.gameObject) elseif attr.attrType == DBCust.FieldType.number or attr.attrType == DBCust.FieldType.phone or attr.attrType == DBCust.FieldType.text then Utl.doCallback(mData.onInputChange, csSelf.gameObject) 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