---@type IDBasePanel local TRBasePanel = require("ui.panel.TRBasePanel") ---@class TRPNewOrder:TRBasePanel 邮件列表 local TRPNewOrder = class("TRPNewOrder", TRBasePanel) local uiobjs = {} local stars = {} -- 初始化,只会调用一次 function TRPNewOrder:init(csObj) TRPNewOrder.super.init(self, csObj) self:initFiledsAttr() self:setEventDelegate() MyUtl.setContentView(getChild(self.transform, "PanelContent"), 132, 0) ---@type UIScrollView uiobjs.scrollView = getCC(self.transform, "PanelContent", "UIScrollView") ---@type UITable uiobjs.Table = getCC(uiobjs.scrollView.transform, "Table", "UITable") ---@type CLUIFormRoot uiobjs.DetailFromRoot = getCC(uiobjs.Table.transform, "DetailRoot", "CLUIFormRoot") uiobjs.DetailRoot = getCC(uiobjs.Table.transform, "DetailRoot", "CLCellLua") ---@type UITable uiobjs.DetailRootTabel = uiobjs.DetailRoot:GetComponent("UITable") uiobjs.ExtendRoot = getCC(uiobjs.Table.transform, "ExtendRoot", "CLCellLua") ---@type CLUIFormRoot uiobjs.ExtendFormRoot = uiobjs.ExtendRoot:GetComponent("CLUIFormRoot") ---@type UITable uiobjs.StepRoot = getCC(uiobjs.Table.transform, "StepRoot", "UITable") ---@type CLUIFormRoot uiobjs.StepFormRoot = uiobjs.StepRoot:GetComponent("CLUIFormRoot") ---@type UIPopupList uiobjs.InputNextLogino = getCC(uiobjs.StepRoot.transform, "InputNextLogino", "UIPopupList") uiobjs.gridProjects = getCC(uiobjs.Table.transform, "InputSelectProduct/Products", "UIGrid") uiobjs.gridProjectsPrefab = getChild(uiobjs.gridProjects.transform, "00000").gameObject uiobjs.InputAttachment = getCC(uiobjs.Table.transform, "InputAttachment", "UIPopupList") uiobjs.gridImages = getCC(uiobjs.InputAttachment.transform, "Grid", "UIGrid") uiobjs.gridImagesPrefab = getChild(uiobjs.gridImages.transform, "00000").gameObject -- uiobjs.elements = uiobjs.DetailRoot.gameObject:GetComponentsInChildren(typeof(CLUIElement), true) uiobjs.ButtonSave = getChild(self.transform, "Top/ButtonSave") end function TRPNewOrder:initFiledsAttr() ---@type _ParamFieldAttr local attr self.baseFiledsAttr = {} attr = {} attr.attrName = "工单模板" attr.id = "templetId" attr.attrType = DBCust.FieldType.popuplist attr.ifMust = 1 attr.donotJoinKey = true local popInfor = DBOrder.getPopupList(DBOrder.PopListGroup.templateList) attr.popOptions = popInfor.options attr.popValues = popInfor.values table.insert(self.baseFiledsAttr, attr) attr = {} attr.attrName = "工单名称" attr.id = "title" attr.attrType = DBCust.FieldType.text attr.ifMust = 1 attr.donotJoinKey = true table.insert(self.baseFiledsAttr, attr) attr = {} attr.attrName = "紧急程序" attr.id = "urgency" attr.attrType = DBCust.FieldType.popuplist attr.ifMust = 0 attr.donotJoinKey = true local popInfor = DBOrder.getPopupList(DBOrder.PopListGroup.urgencyLevels) or {} attr.popOptions = popInfor.options attr.popValues = popInfor.values table.insert(self.baseFiledsAttr, attr) attr = {} attr.attrName = "客户号码" attr.id = "_phoneNo" attr.attrType = DBCust.FieldType.text attr.ifMust = 1 attr.donotJoinKey = true table.insert(self.baseFiledsAttr, attr) attr = {} attr.attrName = "所属任务" attr.id = "taskId" attr.attrType = DBCust.FieldType.popuplist attr.ifMust = 0 attr.donotJoinKey = true local popInfor = DBCust.getFilter4Popup(DBCust.FilterGroup.taskList) attr.popOptions = popInfor.options attr.popValues = popInfor.values table.insert(self.baseFiledsAttr, attr) attr = {} attr.attrName = "客户名称" attr.id = "custName" attr.attrType = DBCust.FieldType.text attr.ifMust = 0 attr.donotJoinKey = true table.insert(self.baseFiledsAttr, attr) attr = {} attr.attrName = "公司名称" attr.id = "companyName" attr.attrType = DBCust.FieldType.text attr.ifMust = 0 attr.donotJoinKey = true table.insert(self.baseFiledsAttr, attr) attr = {} attr.attrName = "联系地址" attr.id = "address" attr.attrType = DBCust.FieldType.text attr.ifMust = 0 attr.donotJoinKey = true table.insert(self.baseFiledsAttr, attr) attr = {} attr.attrName = "订单内容" attr.id = "content" attr.attrType = DBCust.FieldType.multext attr.ifMust = 0 attr.donotJoinKey = true table.insert(self.baseFiledsAttr, attr) end -- 设置数据 ---@param paras _ParamTRPNewOrder function TRPNewOrder:setData(paras) if paras and paras.orderId and paras.orderId > 0 then self.isNewOrder = false self.mdata = paras self.mdata._phoneNo = MyUtl.hidePhone(self.mdata.phoneNo) if type(self.mdata.attrJson) == "string" then self.mdata.attrJson = json.decode(self.mdata.attrJson) end self.mdata.attrJson = self.mdata.attrJson or {} ---@type _DBCust self.cust = nil else -- 初始值 self.isNewOrder = true ---@type _DBCust self.cust = paras self.mdata = {} local popInfor = DBOrder.getPopupList(DBOrder.PopListGroup.templateList) self.mdata.templetId = popInfor.values[0] popInfor = DBOrder.getPopupList(DBOrder.PopListGroup.urgencyLevels) self.mdata.urgency = popInfor.values[0] local templateInfor = DBOrder.getTemplateInfor(self.mdata.templetId) self.mdata.content = templateInfor.content self.selectedProducts = {} self.images = {} end end ---public 当有通用背板显示时的回调 ---@param cs Coolape.CLPanelLua function TRPNewOrder:onShowFrame(cs) if cs.frameObj then ---@type _BGFrame1Param local d = {} if self.isNewOrder then d.title = "新建订单" else d.title = "修改订单" end d.panel = cs cs.frameObj:init(d) end end -- 显示,在c#中。show为调用refresh,show和refresh的区别在于,当页面已经显示了的情况,当页面再次出现在最上层时,只会调用refresh function TRPNewOrder:show() SetActive(uiobjs.gridProjects.transform.parent.gameObject, false) SetActive(uiobjs.StepFormRoot.gameObject, false) SetActive(uiobjs.ExtendRoot.gameObject, false) self:refreshContent() SetActive(uiobjs.ButtonSave.gameObject, self.isNewOrder) uiobjs.scrollView:ResetPosition() end function TRPNewOrder:refreshContent() self:showBaseFields() self:showProducts() self.csSelf:invoke4Lua(self:wrapFunc(self.reposition), 0.1) end function TRPNewOrder:showProducts() local products if self.isNewOrder then products = self.selectedProducts else products = json.decode(self.mdata.prodJson) end CLUIUtl.resetList4Lua(uiobjs.gridProjects, uiobjs.gridProjectsPrefab, products, self:wrapFunc(self.initProductCell)) self:reposition() end function TRPNewOrder:initProductCell(cell, data) cell:init(data, nil) cell.luaTable.onDeleteProduct = self:wrapFunc(self.onDeleteProduct) end function TRPNewOrder:onDeleteProduct(data) for i, v in ipairs(self.selectedProducts) do if v.id == data.id then table.remove(self.selectedProducts, i) break end end self:showProducts() end function TRPNewOrder:showBaseFields() ---@type _ParamCellExtendFiledRoot local param = {} param.data = self.mdata or {} param.onFinish = function(go) local templetId = self.mdata and self.mdata.templetId or nil self:showExtentFiles(templetId) if self.cust then uiobjs.DetailFromRoot:setValue(self.cust, true) end self:setExtendFieldsMode(go) end param.fields = {} ---@type _ParamCellExtendFiled local filedInfor for i, v in ipairs(self.baseFiledsAttr) do -- 工单模板 filedInfor = {} filedInfor.attr = v filedInfor.showMode = self.isNewOrder and _FieldMode.inputOnly or _FieldMode.modifyOnly if filedInfor.attr.attrType == DBCust.FieldType.multext then filedInfor.onMultTextInputChg = self:wrapFunc(self.reposition) end filedInfor.onSelect = self:wrapFunc(self.onPopupFieldValChg) if not self.isNewOrder then filedInfor.onClick = self:wrapFunc(self.onClickInputField) end table.insert(param.fields, filedInfor) end uiobjs.DetailRoot:init(param, nil) end ---public 显示扩展字段 function TRPNewOrder:showExtentFiles(templetId) local cfgInfor = DBOrder.getTemplateInfor(templetId) local fields = DBOrder.getFields(templetId) or {} if #fields > 0 then ---@type _ParamCellExtendFiledRoot local param = {} param.data = self.mdata and self.mdata.attrJson or {} -- param.isEditMode = true param.onFinish = self:wrapFunc(self.setExtendFieldsMode) param.fields = {} ---@type _ParamCellExtendFiled local filedInfor for i, v in ipairs(fields) do filedInfor = {} filedInfor.attr = v filedInfor.showMode = self.isNewOrder and _FieldMode.inputOnly or _FieldMode.modifyOnly if filedInfor.attr.attrType == DBCust.FieldType.multext then filedInfor.onMultTextInputChg = self:wrapFunc(self.reposition) end if not self.isNewOrder then filedInfor.onClick = self:wrapFunc(self.onClickInputField4Extend) filedInfor.onSelect = self:wrapFunc(self.onPopupFieldValChg4Extend) end table.insert(param.fields, filedInfor) end SetActive(uiobjs.ExtendRoot.gameObject, true) uiobjs.ExtendRoot:init(param, nil) else SetActive(uiobjs.ExtendRoot.gameObject, false) end -- next Step local nextStep = DBOrder.getNextHandler(templetId) if nextStep and tonumber(cfgInfor.ifToLoginNo) == 1 then SetActive(uiobjs.StepFormRoot.gameObject, true) uiobjs.InputNextLogino:refreshItems(nextStep.options, nextStep.values) uiobjs.StepFormRoot:setValue(self.mdata) else SetActive(uiobjs.StepFormRoot.gameObject, false) end -- product if tonumber(cfgInfor.ifProduct) == 1 then SetActive(uiobjs.gridProjects.transform.parent.gameObject, true) self.selectedProducts = {} self:showProducts() else SetActive(uiobjs.gridProjects.transform.parent.gameObject, false) end -- refresh content local d = uiobjs.DetailFromRoot:getValue(true) d.content = cfgInfor.content uiobjs.DetailFromRoot:setValue(d) -- 附件 self:showImages() ----------------------------------- uiobjs.StepRoot:Reposition() end function TRPNewOrder:reposition() uiobjs.DetailRootTabel:Reposition() uiobjs.Table:Reposition() uiobjs.DetailRootTabel.repositionNow = true uiobjs.Table.repositionNow = true end function TRPNewOrder:setExtendFieldsMode(root) local elements = root:GetComponentsInChildren(typeof(CLUIElement), true) for i = 0, elements.Length - 1 do self:setElementMode(elements[i]) end self:reposition() end function TRPNewOrder:setElementMode(el) local isPopList = el:GetComponent("UIPopupList") local isPopCheckbox = el:GetComponent("CLUICheckbox") ---@type UIInput local input = el:GetComponent("UIInput") local inputOnGUI = el:GetComponent("UIInputOnGUI") local boxcollider = el:GetComponent("BoxCollider") local ButtonReset = getCC(el.transform, "ButtonReset", "MyInputReset") if ButtonReset then ButtonReset.disabled = (not self.isNewOrder) end if el.jsonKey == "taskId" or el.jsonKey == "_phoneNo" then boxcollider.enabled = false if ButtonReset then ButtonReset.disabled = true end else boxcollider.enabled = true end if input then if isPopList or isPopCheckbox then input.enabled = false if inputOnGUI then inputOnGUI.enabled = false end else if self.isNewOrder then input.enabled = true if inputOnGUI then inputOnGUI.enabled = true end else input.enabled = false if inputOnGUI then inputOnGUI.enabled = false end end end end end -- 刷新 function TRPNewOrder:refresh() end -- 关闭页面 function TRPNewOrder:hide() if uiobjs.DetailRoot.luaTable then uiobjs.DetailRoot.luaTable.release() end if uiobjs.ExtendRoot.luaTable then uiobjs.ExtendRoot.luaTable.release() end end -- 网络请求的回调;cmd:指命,succ:成功失败,msg:消息;paras:服务器下行数据 function TRPNewOrder:procNetwork(cmd, succ, msg, paras) if (succ == NetSuccess) then if cmd == NetProto.cmds.update_customer then self:refreshContent() end end end function TRPNewOrder:onPopupFieldValChg(go) ---@type CLUIElement local el = go:GetComponent("CLUIElement") if self.isNewOrder then if el and el.jsonKey == "templetId" then self:showExtentFiles(el.value) end else if el then local err = el:checkValid() if tostring(el.value) ~= tostring(self.mdata[el.jsonKey]) then if isNilOrEmpty(err) then self:sendModifymsg(el.jsonKey, el.value, false) else MyUtl.toastW(err) end end end end end function TRPNewOrder:onClickInputField(go) if self.isNewOrder then return end ---@type CLUIElement local el = go:GetComponent("CLUIElement") if el then getPanelAsy( "PanelModifyFiled", onLoadedPanelTT, { label = el.labeName.text, key = el.jsonKey, value = el.value, canNull = el.canNull, callback = self:wrapFunc(self.onFinishSetField) } ) end end function TRPNewOrder:onFinishSetField(key, val) if tostring(val) ~= tostring(self.mdata[key]) then self:sendModifymsg(key, val, false) end end function TRPNewOrder:sendModifymsg(key, val, isExtend) local content = {} content.id = self.mdata.custId if isExtend then content.jsonStr = {[key] = val} else content[key] = val end showHotWheel() NetProto.send.update_customer( content, function(result, orgs) hideHotWheel() if result.success then -- 更新本地数据 if isExtend then self.mdata.jsonStr[key] = val else self.mdata[key] = val end MyUtl.toastS("修改成功") end end ) end function TRPNewOrder:onPopupFieldValChg4Extend(go) if self.isNewOrder then return end ---@type CLUIElement local el = go:GetComponent("CLUIElement") if el then local err = el:checkValid() if (not isNilOrEmpty(el.value)) and tostring(el.value) ~= tostring(self.mdata.jsonStr[el.jsonKey]) then if isNilOrEmpty(err) then -- 有修改,发送数据 self:sendModifymsg(el.jsonKey, el.value, true) else MyUtl.toastW(err) end end end end function TRPNewOrder:onClickInputField4Extend(go) if self.isNewOrder then return end ---@type CLUIElement local el = go:GetComponent("CLUIElement") if el then getPanelAsy( "PanelModifyFiled", onLoadedPanelTT, { label = el.labeName.text, key = el.jsonKey, value = el.value, canNull = el.canNull, callback = self:wrapFunc(self.onFinishSetField4Extend) } ) end end function TRPNewOrder:onFinishSetField4Extend(key, val) if tostring(val) ~= tostring(self.mdata.jsonStr[key]) then self:sendModifymsg(key, val, true) end end function TRPNewOrder:setEventDelegate() self.EventDelegate = { ButtonSave = function() local err = uiobjs.DetailFromRoot:checkValid() err = joinStr(err, uiobjs.ExtendFormRoot:checkValid()) if not isNilOrEmpty(err) then MyUtl.toastW(err) return end local order = uiobjs.DetailFromRoot:getValue(true) if self.cust then order.phoneNo = self.cust.phoneNo end order.custId = self.cust.custId if uiobjs.ExtendFormRoot.gameObject.activeInHierarchy then local attrJson = uiobjs.ExtendFormRoot:getValue(true) order.attrJson = attrJson end if uiobjs.StepFormRoot.gameObject.activeInHierarchy then err = joinStr(err, uiobjs.StepFormRoot:checkValid()) if not isNilOrEmpty(err) then MyUtl.toastW(err) return end order = uiobjs.StepFormRoot:getValue(order, true) end local templateInfor = DBOrder.getTemplateInfor(order.templetId) order.ifToLoginNo = templateInfor.ifToLoginNo order.ifMail = templateInfor.ifMail order.ifProduct = templateInfor.ifProduct if uiobjs.gridProjects.gameObject.activeInHierarchy then if self.selectedProducts == nil or #(self.selectedProducts) <= 0 then MyUtl.toastW("请添加产品") return end order.prodJson = self.selectedProducts -- 计算价格 for i, v in ipairs(order.prodJson) do v.totalPrice = tonumber(v.productNum) * tonumber(v.price) v.salePrice = tonumber(v.productNum) * tonumber(v.productPrice) end end order.wfType = "0" -- 0:正常工单,1:退货工单 showHotWheel() NetProto.send.createWfInfo( order, function(content) if content.success then MyUtl.toastS("订单创建成功") hideTopPanel(self.csSelf) end hideHotWheel() end ) end, InputSeachKey = function() local queryKey = uiobjs.InputSeachKey.value NetProto.send.selectProductInfo(queryKey, 1) end, InputSelectProduct = function() -- 选择商品 getPanelAsy( "PanelSelectProduct", onLoadedPanelTT, {selectedProducts = self.selectedProducts, callback = self:wrapFunc(self.onGetSelectedProducts)} ) end, InputAttachment = function(go) -- 添加附件 ---@type UIPopupList local popList = go:GetComponent("UIPopupList") if popList.value == "1" then -- 相机 local permission = MyCamera.getImage(self:wrapFunc(self.onGetImage)) if permission ~= NativeCamera.Permission.Granted then if permission == NativeCamera.Permission.ShouldAsk then NativeCamera.RequestPermission() else CLUIUtl.showConfirm( "没有使用相机的权限,打开设置允许使用相机", function() if not MyCamera.openSetting() then MyUtl.toastW("打开权限设置失败") end end, nil ) end end elseif popList.value == "2" then local permission = MyGallery.getImage(self:wrapFunc(self.onGetImage)) if permission ~= NativeGallery.Permission.Granted then if permission == NativeGallery.Permission.ShouldAsk then NativeGallery.RequestPermission() else CLUIUtl.showConfirm( "没有使用相册的权限,打开设置允许使用相册", function() if not MyGallery.openSetting() then MyUtl.toastW("打开权限设置失败") end end, nil ) end NativeCamera.RequestPermission() end end end } end function TRPNewOrder:onGetImage(path) if isNilOrEmpty(path) then return end for i, v in ipairs(self.images) do if v.path == path then MyUtl.toast("已在列表中") return end end MyUtl.toastW("TODO:上传附件还没有做!!!!") table.insert(self.images, {path = path, onDelete = self:wrapFunc(self.onDelImage)}) self:showImages() end function TRPNewOrder:showImages() CLUIUtl.resetList4Lua(uiobjs.gridImages, uiobjs.gridImagesPrefab, self.images, self:wrapFunc(self.initImageCell)) end function TRPNewOrder:initImageCell(cell, data) cell:init(data, nil) end ---@type _ParamCellImage function TRPNewOrder:onDelImage(data) for i, v in ipairs(self.images) do if v.path == data.path then table.remove(self.images, i) break end end self:showImages() end function TRPNewOrder:onGetSelectedProducts(list) self.selectedProducts = list self:showProducts() end -- 处理ui上的事件,例如点击等 function TRPNewOrder:uiEventDelegate(go) local func = self.EventDelegate[go.name] if func then func(go) end end -- 当顶层页面发生变化时回调 function TRPNewOrder:onTopPanelChange(topPanel) end -------------------------------------------- return TRPNewOrder