Jianw
2025-05-14 29f8b36ebb718d2051bf0e7e701973ec4419ee80
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
--[[
    编码: WMS-23-10
    名称: 发货单明细-显示前
    作者: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 = ''
 
    strDataJson = '['
    for n = 1, nCount do
        obj = arobjs[n]
        attrs = obj.attrs
        nattr_count = #attrs
        id = obj.id
 
        strAttrs = ''
        strRowCtrl = ''
        -- 获取 物料编码 和 库区编码
        for nIndex = 1, nattr_count do
            strAttr = attrs[nIndex].attr
            strValue = attrs[nIndex].value
            strCellBkground = ''
            if (strAttr == 'F_OOS_QTY') then
                oos_qty = lua.StrToNumber( strValue )
                if (oos_qty > 0) then
                    strCellBkground = ', "bk_color":"#FF0000","text_color":"#FFFFFF"'
                end
            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 .. ']'
 
    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