Jianw
2025-05-13 3b39fe3810c3ee2ec9ec97236c1769c5c85e062c
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
--[[ 
    编码: JX-108-26 
    名称: 显示前
    作者:
    日期:2025-1-29
 
    入口函数:BeforeGridShow
 
    功能说明:
        显示业务状态(N_B_STATE 和 N_CR_STATE),并控制行按钮显示逻辑
--]]
 
json  = require("json")
mobox = require("OILua_JavelinExt")
m3 = require("oi_base_mobox")
 
function BeforeGridShow(strLuaDEID)
    local nRet, strRetInfo
    local data_objs
    local nCount
 
    -- 定义业务状态和完工回报状态映射表
    local state_names = {"等待", "作业启动", "完成", "错误", "执行失败", "出库到站台", "开始回库", "取消"}
    local cr_state_names = {"没回报", "回报成功", "调接口错误","接口反馈错误"}
 
    nRet, data_objs = m3.GetSysDataJson(strLuaDEID)
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "获取网格数据失败: " .. data_objs)
    end
 
    nCount = #data_objs
    if (nCount == 0) then return end
 
    local row_data_set = {}
    local obj, attr, attr_name, attr_value
    local state_index, cr_state_index
 
    for i = 1, nCount do
        local row_item = {}
 
        obj = data_objs[i]
        row_item.id = obj.id
        row_item.attrs = {}
        row_item.row_button_hidden = "再次回报"
 
        -- 遍历行的属性进行处理
        for j = 1, #obj.attrs do
            local attr = {}
 
            attr.attr  = obj.attrs[j].attr
            attr.value = obj.attrs[j].value
            if (attr.attr == "N_B_STATE") then
                state_index = lua.StrToNumber(attr.value)
                if ( state_index >= 0 and state_index <= 7 ) then
                    attr.value = state_names[state_index + 1]
                end
            elseif (attr.attr == "N_CR_STATE") then
                cr_state_index = lua.StrToNumber(attr.value)
                if cr_state_index >= 0 and cr_state_index <= 3 then
                    attr.value = cr_state_names[cr_state_index + 1]
                    if ( cr_state_index == 2 or cr_state_index == 3 ) then
                        row_item.row_button_hidden = ""
                    end
                end
            end
            table.insert(row_item.attrs, attr)
        end
        table.insert(row_data_set, row_item)
    end
 
    -- 更新界面数据
    local action = {
        {
            action_type = "reset_data_attr",
            value = row_data_set
        }
    }
 
    nRet, strRetInfo = mobox.setAction(strLuaDEID, lua.table2str(action))
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "更新数据失败: " .. strRetInfo)
    end    
end