Files
tianrunCRM/Assets/trCRM/upgradeRes4Dev/priority/lua/ui/panel/TRPNewOrder.lua
2020-07-11 20:53:21 +08:00

460 lines
14 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.

---@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")
-- 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 = ""
attr.attrType = DBCust.FieldType.popuplist
attr.ifMust = 1
attr.donotJoinKey = true
table.insert(self.baseFiledsAttr, attr)
attr = {}
attr.attrName = "工单名称"
attr.id = ""
attr.attrType = DBCust.FieldType.text
attr.ifMust = 1
attr.donotJoinKey = true
table.insert(self.baseFiledsAttr, attr)
attr = {}
attr.attrName = "紧急程序"
attr.id = ""
attr.attrType = DBCust.FieldType.popuplist
attr.ifMust = 0
attr.donotJoinKey = true
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 = ""
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
if type(self.mdata.jsonStr) == "string" then
self.mdata.jsonStr = json.decode(self.mdata.jsonStr)
end
self.mdata.jsonStr = self.mdata.jsonStr or {}
self.cust = nil
else
--//TODO:初始值
self.isNewOrder = true
self.cust = paras
self.mdata = {}
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为调用refreshshow和refresh的区别在于当页面已经显示了的情况当页面再次出现在最上层时只会调用refresh
function TRPNewOrder:show()
self:refreshContent()
SetActive(uiobjs.ButtonSave.gameObject, self.isNewOrder)
uiobjs.scrollView:ResetPosition()
end
function TRPNewOrder:refreshContent()
self:showBaseFields()
local taskId = self.mdata and self.mdata.taskId or nil
self:showExtentFiles(taskId)
self.csSelf:invoke4Lua(self:wrapFunc(self.reposition), 0.1)
end
function TRPNewOrder:showBaseFields()
---@type _ParamCellExtendFiledRoot
local param = {}
param.data = self.mdata or {}
param.onFinish = function(go)
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.isEditMode = true
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.onClickInputField)
filedInfor.onSelect = self:wrapFunc(self.onPopupFieldValChg)
end
table.insert(param.fields, filedInfor)
end
uiobjs.DetailRoot:init(param, nil)
end
---public 显示扩展字段
function TRPNewOrder:showExtentFiles(taskId)
---@type _ParamCellExtendFiledRoot
local param = {}
param.data = self.mdata and self.mdata.jsonStr or {}
-- param.isEditMode = true
param.onFinish = self:wrapFunc(self.setExtendFieldsMode)
param.fields = {}
local fields = DBCust.getFieldsByTask(taskId) or {}
---@type _ParamCellExtendFiled
local filedInfor
for i, v in ipairs(fields) do
filedInfor = {}
filedInfor.attr = v
filedInfor.isEditMode = true
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
uiobjs.ExtendRoot:init(param, nil)
end
function TRPNewOrder: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 (not self.isNewOrder) and (el.jsonKey == "taskId" or el.jsonKey == "phoneNo") then
boxcollider.enabled = false
else
boxcollider.enabled = true
end
if ButtonReset then
ButtonReset.disabled = (not self.isNewOrder)
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)
if self.isNewOrder then
return
end
---@type CLUIElement
local el = go:GetComponent("CLUIElement")
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
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.DetailRoot:checkValid()
err = joinStr(err, uiobjs.ExtendFormRoot:checkValid())
if not isNilOrEmpty(err) then
MyUtl.toastW(err)
return
end
local cust = uiobjs.DetailRoot:getValue(true)
cust.customerLabel = self.mdata.customerLabel
local jsonStr = uiobjs.ExtendFormRoot:getValue(true)
cust.jsonStr = jsonStr
showHotWheel()
NetProto.send.save_customer(
cust,
function(content)
if content.success then
getPanelAsy("PanelCustDetail", onLoadedPanel, cust)
end
hideHotWheel()
end
)
end,
InputTask = function()
self:showExtentFiles(uiobjs.InputTask.value)
end
}
end
-- 处理ui上的事件例如点击等
function TRPNewOrder:uiEventDelegate(go)
local func = self.EventDelegate[go.name]
if func then
func()
end
end
-- 当顶层页面发生变化时回调
function TRPNewOrder:onTopPanelChange(topPanel)
end
--------------------------------------------
return TRPNewOrder