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
--[[
    编码: WMS-19-04
    名称: 容器货品明细-码盘-确定
    作者:HAN  
    日期:2025-1-29
 
    级别:固定 (说明本段代码在项目中不太会变化)
    
    函数: ClickOK
 
    功能:
        -- 在码盘界面,点确定
        -- 获取 "正在码盘" 页签中的货品, 创建【容器货品明细】码盘操作
    更改记录:
 
--]]
 
wms_base = require( "wms_base" )
 
function ClickOK ( strLuaDEID )
    local nRet, strRetInfo
    local attrs
 
    -- step1  获取5600码盘界面中表头界面的输入参数(容器编号/托盘号)
    nRet, attrs = m3.GetSysInputParameter( strLuaDEID ) 
    if ( nRet ~= 0 )  then lua.Error( strLuaDEID, debug.getinfo(1), "获取当前输入面板里的属性失败! "..attrs ) end 
    local input_attr = m3.KeyValueAttrsToObjAttr(attrs)
    local cntr_code = input_attr.S_CNTR_CODE
    if (cntr_code == nil or cntr_code == '') then lua.Error( strLuaDEID, debug.getinfo(1), "容器编码不能为空!" ) end
 
    local strDataJson
    -- step2  获取"正在码盘"中的数据对象(一条),这些数据保存在 DataJson中 格式如下:
    --        {"id":"","attrs":[{"attr":"x1","value":"xx"},...]}
    nRet, obj = m3.GetSysDataJson( strLuaDEID )
    if ( nRet ~=0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "无法获取数据包!"..obj ) end
    -- 把 attrs 中的 [{"attr":"S_ITEM_CODE","value":"123"},..] 转化为
    -- {"S_ITEM_CODE":"123",...} 这样方便访问
    local input_obj = m3.KeyValueAttrsToObjAttr(obj.attrs)
 
    -- step3 创建【容器货品明细】
    local cg_detail = m3.AllocObject(strLuaDEID,"CG_Detail")
    cg_detail.cntr_code = cntr_code
    cg_detail.serial_no = lua.Get_StrAttrValue( input_obj.S_SERIAL_NO )
    cg_detail.batch_no = lua.Get_StrAttrValue( input_obj.S_BATCH_NO )
    cg_detail.item_code = lua.Get_StrAttrValue( input_obj.S_ITEM_CODE )
    cg_detail.item_name = lua.Get_StrAttrValue( input_obj.S_ITEM_NAME )
    cg_detail.item_spec = lua.Get_StrAttrValue( input_obj.S_ITEM_SPEC )
    --cg_detail.putaway_no = lua.Get_StrAttrValue( input_obj.S_PUTAWAY_NO )
    cg_detail.bs_no = lua.Get_StrAttrValue( input_obj.S_BS_NO )
    cg_detail.qty = lua.Get_NumAttrValue( input_obj.F_QTY )
    cg_detail.uom = lua.Get_StrAttrValue( input_obj.S_UOM )
    cg_detail.net_weight = lua.Get_StrAttrValue( input_obj.F_NET_WEIGHT )
    cg_detail.gross_weight = lua.Get_StrAttrValue( input_obj.F_GROSS_WEIGHT )
    cg_detail.wu = lua.Get_StrAttrValue( input_obj.S_WU )
    nRet, cg_detail = m3.CreateDataObj( strLuaDEID, cg_detail )
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), 'mobox 创建【容器货品明细】对象失败!'..cg_detail ) end 
 
    -- 创建成功需要告诉前端 在"已码盘"插入一条码盘记录
    local row = {}
    local attr_array = {}
    attr_array[1] = lua.KeyValueObj( "S_PUTAWAY_NO", cg_detail.putaway_no )
    attr_array[2] = lua.KeyValueObj( "S_ITEM_CODE", cg_detail.item_code )
    attr_array[3] = lua.KeyValueObj( "S_ITEM_NAME", cg_detail.item_name )
    attr_array[4] = lua.KeyValueObj( "S_SERIAL_NO", cg_detail.serial_no )
    attr_array[5] = lua.KeyValueObj( "S_BS_NO", cg_detail.bs_no )
    attr_array[6] = lua.KeyValueObj( "F_QTY", cg_detail.qty )
    row.id = cg_detail.id
    row.attrs = attr_array
 
    -- 设置action的value
    local value = {}
    value.page_name = "已码盘"
    value.row[1] = row
 
    local action = {}
    action.action_type = "insert_subtable_page_row"
    action.value = value
 
    nRet, strRetInfo = mobox.setAction( strLuaDEID, '['..lua.table2str(action)..']'  )
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "setAction失败! "..strRetInfo..' action = '..strAction ) end         
end