fy36
2025-05-14 a37aca60ff9914b0abb710f04118b22420f4f398
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
--[[
    编码: 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