lzh
2025-06-19 3a6436e0c88042c6ce8dca2fe8adb0109f0ad9e4
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
--[[
   编码: GT-103-13
   名称:
   作者:
   日期:2025-05-20
 
   函数: BeforeGridShow
   功能:
 
   更改记录:
 
--]]
json  = require("json")
m3    = require("oi_base_mobox")
mobox = require("OILua_JavelinExt")
function BeforeGridShow(strLuaDEID)
    local nRet, strRetInfo
    local arobjs, attrs
    local n, nCount
 
    nRet, arobjs = m3.GetSysDataJson(strLuaDEID)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), arobjs) end
    nCount = #arobjs
    if (nCount == 0) then return end
 
    local obj, attrs, id
    local strDataJson
    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
 
        local str = m3.KeyValueAttrsToObjAttr(attrs)
        lua.Debug(strLuaDEID, debug.getinfo(1), "str", str)
 
        local strAttrs = ''
        -- 获取 物料编码 和 库区编码
        for nIndex = 1, nattr_count do
            local strAttr = attrs[nIndex].attr
            local strValue = attrs[nIndex].value
            local strItem = '{"attr":"' .. strAttr .. '","value":"' .. strValue .. '"},'
            strAttrs = strAttrs .. strItem
        end
        -- 流水号未绑定容器状态为未绑定,绑定了容器状态为已绑定
        local cg_detail
        local strValue
        local strCondition = "S_SERIAL_NO = '"..str.S_SERIAL_NO.."'"
        nRet, cg_detail = m3.GetDataObjByCondition(strLuaDEID, "CG_Detail", strCondition, "T_CREATE DESC")
        lua.Debug(strLuaDEID, debug.getinfo(1), "cg_detail", cg_detail)
        if (nRet == 1) then
            strValue = '未绑定'
        elseif (nRet == 0) then
            strValue = '已绑定'
        elseif (nRet > 1) then
            lua.Error(strLuaDEID, debug.getinfo(1), "获取流水号信息失败!" .. cg_detail)
        end
        local strItem = '{"attr":"CUSTOM_STATE","value":"' .. strValue .. '"},'
        strAttrs = strAttrs .. strItem
        strAttrs = lua.trim_laster_char(strAttrs)
        local strRow = '{"id":"' .. id .. '","attrs":[' .. strAttrs .. ']},'
        strDataJson = strDataJson .. strRow
    end
    -- 取消最后一个,号
    strDataJson = lua.trim_laster_char(strDataJson)
    strDataJson = strDataJson .. ']'
 
    local strAction = '[{"action_type":"reset_data_attr","value":' .. strDataJson .. '}]'
    lua.Debug(strLuaDEID, debug.getinfo(1), "strAction", strAction)
    nRet, strRetInfo = mobox.setAction(strLuaDEID, strAction)
    if (nRet ~= 0) then
        lua.Warning(strLuaDEID, debug.getinfo(1), strAction)
        lua.Error(strLuaDEID, debug.getinfo(1), "setAction错误: " .. strRetInfo)
    end
end