--[[
|
编码: WMS-38-05
|
名称: 显示前
|
作者:HAN
|
日期:2025-1-29
|
|
入口函数:BeforeGridShow
|
|
功能说明:
|
如果任务状态=错误,显示红色,显示 任务重置、任务完成 行按钮
|
更改记录:
|
|
--]]
|
json = require ("json")
|
mobox = require ("OILua_JavelinExt")
|
m3 = require("oi_base_mobox")
|
|
function BeforeGridShow ( strLuaDEID )
|
local nRet, strRetInfo
|
|
nRet, strRetInfo = mobox.getCurEditDataPacket(strLuaDEID)
|
if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "无法获取Grid显示数据包!") end
|
if (strRetInfo == '' or strRetInfo == nil) then return end
|
|
-- 解析数据包,数据包格式
|
-- [{"id":"","attrs":[{"attr":"","value":""},..]},..]
|
local arobjs, attrs
|
local n, nCount
|
|
arobjs = json.decode(strRetInfo)
|
nCount = #arobjs
|
if (nCount == 0) then return end
|
|
local obj, attrs, id
|
local strCellBkground, strDataJson
|
local strRowCtrl = ''
|
local nState
|
local strCurYear = os.date("%Y")
|
strCurYear = strCurYear.."--"
|
|
strDataJson = '['
|
for n = 1, nCount do
|
obj = arobjs[n]
|
attrs = obj.attrs
|
nattr_count = #attrs
|
id = obj.id
|
|
strAttrs = ''
|
-- 默认情况是不需要 "重置" 这个行按钮的
|
strRowCtrl = ',"row_button_hidden":"重置;强制完成"'
|
-- 获取 物料编码 和 库区编码
|
for nIndex = 1, nattr_count do
|
strAttr = attrs[nIndex].attr
|
strValue = attrs[nIndex].value
|
strCellBkground = ''
|
if (strAttr == 'N_B_STATE') then
|
nState = lua.StrToNumber( strValue )
|
|
if ( nState == 4 ) then
|
strValue = '错误'
|
strCellBkground = ', "bk_color":"#FF0000","text_color":"#FFFFFF"'
|
strRowCtrl = ',"row_button_hidden":"强制完成"'
|
elseif ( nState == 3 ) then
|
strValue = '完成'
|
strCellBkground = ', "bk_color":"#00FF00","text_color":"#008000"'
|
elseif ( nState == 2 ) then
|
strValue = '执行'
|
strRowCtrl = ',"row_button_hidden":"重置"'
|
elseif ( nState == 1 ) then
|
strValue = '已推送'
|
strCellBkground = ', "bk_color":"#FFE4E1","text_color":"#008000"'
|
strRowCtrl = ',"row_button_hidden":"重置"'
|
elseif ( nState == 0 ) then
|
strValue = '等待'
|
strRowCtrl = ',"row_button_hidden":"重置"'
|
end
|
elseif (strAttr == 'T_START_TIME' or strAttr == 'T_END_TIME' or strAttr == 'T_CREATE') then
|
-- 对时间的处理
|
if (strValue == "1900-1-1 0:0:0") then
|
strValue = ""
|
else
|
-- 如果是本年就不显示 本年年份
|
strValue = string.gsub(strValue, strCurYear, "")
|
end
|
elseif (strAttr == 'S_ERR') then
|
strValue = string.gsub(strValue, "\\", "/")
|
strValue = string.gsub(strValue, '"','\\\"')
|
strValue = string.gsub(strValue, "'",'\\\"')
|
strValue = string.gsub(strValue, " ","")
|
end
|
strItem = '{"attr":"' .. strAttr .. '","value":"' .. strValue .. '"'..strCellBkground..'},'
|
strAttrs = strAttrs .. strItem
|
end
|
strAttrs = lua.trim_laster_char(strAttrs)
|
strRow = '{"id":"'..id..'"'..strRowCtrl..',"attrs":['..strAttrs..']},'
|
strDataJson = strDataJson .. strRow
|
end
|
-- 取消最后一个,号
|
strDataJson = lua.trim_laster_char(strDataJson)
|
strDataJson = strDataJson .. ']'
|
|
local strAction = '[{"action_type":"reset_data_attr","value":' .. strDataJson .. '}]'
|
nRet, strRetInfo = mobox.setAction(strLuaDEID, strAction)
|
if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "setAction错误: "..strRetInfo) end
|
end
|