自动化立体仓库 - WMS系统
lty
2026-03-24 00929a147aa125a617f5ec28597bf355356f65f8
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
var insTb, insTb2;
layui.config({
    base: baseUrl + "/static/layui/lay/modules/"
}).extend({
    notice: 'notice/notice',
    tableMerge: 'tableMerge'
}).use(['table', 'laydate', 'form', 'util', 'admin', 'notice', 'xmSelect', 'tableMerge', 'tableX'], function(){
    var table = layui.table;
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var admin = layui.admin;
    var notice = layui.notice;
    var tableMerge = layui.tableMerge;
    var tableX = layui.tableX;
 
    /****************************************** 左侧检验订单表 *************************************************/
    function getLeftCols() {
        return [[
            {field: 'orderTime', title: typeof I18n !== 'undefined' ? I18n.t('date') : '日期', width: 100},
            {field: 'orderNo', title: typeof I18n !== 'undefined' ? I18n.t('order_no') : '单据编号', align: 'center'}
        ]];
    }
 
    var initLeftTable = function() {
        insTb = table.render({
            elem: '#originTable',
            url: baseUrl + '/order/inspect/list/auth',
            headers: {token: localStorage.getItem('token')},
            height: 'full-180',
            page: false,
            request: { pageName: 'curr', pageSize: 'limit' },
            parseData: function (res) {
                return { 'code': res.code, 'msg': res.msg, 'data': res.data };
            },
            response: { statusCode: 200 },
            text: { none: typeof I18n !== 'undefined' ? I18n.t('no_data') : '暂无数据' },
            cols: getLeftCols(),
            done: function (res, curr, count) {
                if (typeof I18n !== 'undefined' && I18n.isReady()) {
                    I18n.updatePage();
                    if (count === 0) { $('.layui-table-empty').text(I18n.t('no_data')); }
                }
                // 默认选中第一行
                $('#originTable+.layui-table-view .layui-table-body tbody>tr:first').trigger('click');
                
                // 绑定右键一键出库
                tableX.bindCtxMenu('originTable', function (d) {
                    return [{
                        icon: 'layui-icon layui-icon-ok',
                        name: typeof I18n !== 'undefined' ? I18n.t('one_click_outbound') : '一键出库',
                        click: function (d) { autoOut(d.id); }
                    }]
                });
            }
        });
    };
 
    /****************************************** 右侧订单明细表 *************************************************/
    function getRightCols() {
        return [[
            {type: 'checkbox', merge: 'origin'},
            {field: 'origin', align: 'center', title: typeof I18n !== 'undefined' ? I18n.t('pallet_code') : '托盘码', merge: true, width: 140},
            {field: 'matnr', align: 'center', title: typeof I18n !== 'undefined' ? I18n.t('mat_code') : '商品编码', width: 140},
            {field: 'maktx', align: 'center', title: typeof I18n !== 'undefined' ? I18n.t('mat_name') : '商品名称', width: 180},
            {field: 'batch', align: 'center', title: typeof I18n !== 'undefined' ? I18n.t('serial_code') : '批号'},
            {field: 'specs', align: 'center', title: typeof I18n !== 'undefined' ? I18n.t('spec') : '规格'},
            {field: 'color', align: 'center', title: typeof I18n !== 'undefined' ? I18n.t('color') : '颜色'},
            // {field: 'origin', align: 'center', title: typeof I18n !== 'undefined' ? I18n.t('locationNo') : '库位号'},
            {field: 'enableQty', align: 'center', title: typeof I18n !== 'undefined' ? I18n.t('outbound_pending_qty') : '待出库数量', style: 'font-weight: bold'},
            {fixed: 'right', title: typeof I18n !== 'undefined' ? I18n.t('operation') : '操作', align: 'center', toolbar: '#operate', width: 120, merge: 'origin'}
        ]];
    }
 
    var initRightTable = function() {
        insTb2 = table.render({
            elem: '#orderDetlTable',
            headers: {token: localStorage.getItem('token')},
            url: baseUrl + '/orderDetl/pakout/inspectionList/auth',
            page: true,
            limit: 15,
            height: 'full-180',
            toolbar: '#orderDetToolbar',
            text: { none: typeof I18n !== 'undefined' ? I18n.t('no_data') : '暂无数据' },
            where: { order_id: -1 },
            cols: getRightCols(),
            parseData: function (res) {
                return { 'code': res.code, 'msg': res.msg, 'count': res.data.total, 'data': res.data.records };
            },
            response: { statusCode: 200 },
            done: function(res, curr, count) {
                if (typeof I18n !== 'undefined' && I18n.isReady()) {
                    I18n.updatePage();
                    I18n.updateLayuiPagination();
                }
                tableMerge.render(this);
            }
        });
    };
 
    // 监听语言切换事件
    $(document).on('i18n:languageChanged', function() {
        if (typeof I18n !== 'undefined') {
            I18n.updatePage();
        }
        if (insTb) {
            insTb.reload({
                cols: getLeftCols(),
                text: { none: typeof I18n !== 'undefined' ? I18n.t('no_data') : '暂无数据' }
            });
        }
        if (insTb2) {
            insTb2.reload({
                cols: getRightCols(),
                text: { none: typeof I18n !== 'undefined' ? I18n.t('no_data') : '暂无数据' }
            });
        }
    });
 
    // 初始化加载
    if (typeof I18n !== 'undefined' && I18n.isReady()) {
        initLeftTable();
        initRightTable();
    } else {
        $(document).on('i18n:ready', function() {
            initLeftTable();
            initRightTable();
        });
    }
 
    // 监听左侧行单击
    var currentOrderId = -1;
    table.on('row(originTable)', function (obj) {
        currentOrderId = obj.data.id;
        obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
        insTb2.reload({ where: { order_id: currentOrderId }, page: { curr: 1 } });
    });
 
    // 搜索与重置
    form.on('submit(originTableSearch)', function (data) {
        insTb.reload({ where: data.field });
        return false;
    });
 
    form.on('submit(sensorTbSearch)', function (data) {
        insTb2.reload({ where: data.field, page: { curr: 1 } });
        return false;
    });
 
    // 表格操作
    table.on('toolbar(orderDetlTable)', function (obj) {
        var checkStatus = table.checkStatus(obj.config.id).data;
        if (obj.event === 'pakoutPreview') {
            if (checkStatus.length === 0) {
                layer.msg(typeof I18n !== 'undefined' ? I18n.t('select_at_least_one_outbound_detail') : '请至少选择一条出库明细', {icon: 2});
                return;
            }
            pakoutPreview(checkStatus.map(d => d.id));
        } else if (obj.event === 'oneClickOut') {
            if (currentOrderId === -1) {
                layer.msg(typeof I18n !== 'undefined' ? I18n.t('please_select_order') : '请先选择订单', {icon: 2});
                return;
            }
            autoOut(currentOrderId);
        } else if (obj.event === 'inspectPass') {
            if (currentOrderId === -1) {
                layer.msg(typeof I18n !== 'undefined' ? I18n.t('please_select_order') : '请先选择订单', {icon: 2});
                return;
            }
            inspectPass(currentOrderId);
        } else if (obj.event === 'inspectFail') {
            if (currentOrderId === -1) {
                layer.msg(typeof I18n !== 'undefined' ? I18n.t('please_select_order') : '请先选择订单', {icon: 2});
                return;
            }
            inspectFail(currentOrderId);
        }
    });
 
    table.on('tool(orderDetlTable)', function (obj) {
        if (obj.event === 'pakoutPreview') {
            // 获取当前 origin 分组的所有明细 ID
            var origin = obj.data.origin;
            var tableData = table.cache['orderDetlTable'];
            var groupIds = [];
            if (origin) {
                for (var i = 0; i < tableData.length; i++) {
                    if (tableData[i].origin === origin && tableData[i].enableQty > 0) {
                        groupIds.push(tableData[i].id);
                    }
                }
            } else {
                groupIds = [obj.data.id];
            }
            
            if (groupIds.length === 0) {
                layer.msg(typeof I18n !== 'undefined' ? I18n.t('no_available_qty') : '没有可出库数量', {icon: 2});
                return;
            }
            pakoutPreview(groupIds);
        }
    });
 
    // 出库预览与确认逻辑
    function pakoutPreview(ids) {
        let loadIndex = layer.load(2);
        $.ajax({
            url: baseUrl + "/out/pakout/preview/auth",
            headers: {'token': localStorage.getItem('token')},
            contentType: 'application/json;charset=UTF-8',
            data: JSON.stringify(ids),
            method: 'POST',
            success: function (res) {
                layer.close(loadIndex);
                if (res.code === 200) {
                    var tableCache;
                    layer.open({
                        type: 1, title: false, closeBtn: false, offset: '50px', area: ['1000px', '600px'], shade: 0.5,
                        btn: [I18n.t('immediate_outbound'), I18n.t('process_later')], btnAlign: 'c',
                        content: $('#pakoutPreviewBox').html(),
                        success: function(layero, index) {
                            I18n.updatePage($(layero));
                            var stoPreTabIdx = table.render({
                                elem: '#stoPreTab', data: res.data, height: 420, page: false, limit: 1000,
                                cols: [[
                                    {field: 'orderNo', title: I18n.t('order_no'), align: 'center'},
                                    {field: 'batch', title: I18n.t('serial_code'), align: 'center'},
                                    {field: 'anfme', title: I18n.t('quantity'), align: 'center', width: 90},
                                    {field: 'locNo', title: I18n.t('location'), align: 'center', width: 120, templet: '#locNoTpl', merge: true},
                                    {field: 'staNos', align: 'center', title: I18n.t('station_outbound'), templet: '#tbBasicTbStaNos', merge: 'locNo'},
                                    {type: 'checkbox', merge: 'locNo'}
                                ]],
                                done: function() {
                                    tableCache = table.cache.stoPreTab;
                                    I18n.updatePage($('.layui-table-view[lay-id="stoPreTab"]'));
                                    form.render('select');
                                    tableMerge.render(this);
                                }
                            });
                            
                            form.on('select(tbBasicTbStaNos)', function (obj) {
                                let idx = obj.othis.parents('tr').attr("data-index");
                                let currentLocNo = tableCache[idx]['locNo'];
                                let selectedStaNo = Number(obj.elem.value);
                                
                                // 同一库位的所有记录同步选择相同的站点
                                for (let i = 0; i < tableCache.length; i++) {
                                    if (tableCache[i]['locNo'] === currentLocNo) {
                                        tableCache[i]['staNo'] = selectedStaNo;
                                        // 同时更新界面上该库位对应的所有下拉框(如果有多个的话)
                                        let $selects = $(layero).find('tr[data-index="' + i + '"] select.order-sta-select');
                                        if ($selects.length > 0) {
                                            $selects.val(obj.elem.value);
                                        }
                                    }
                                }
                                form.render('select');
                            });
 
                            form.on('submit(batchModifySta)', function (data) {
                                let checkStatus = table.checkStatus('stoPreTab').data;
                                if (checkStatus.length === 0) {
                                    layer.msg(typeof I18n !== 'undefined' ? I18n.t('select_at_least_one_outbound_detail') : '请至少选择一条记录', {icon: 2});
                                    return false;
                                }
                                
                                // 获取第一个选中的有效站点作为基准
                                let baseStaNo = null;
                                for (let i = 0; i < checkStatus.length; i++) {
                                    if (checkStatus[i].staNo) {
                                        baseStaNo = checkStatus[i].staNo;
                                        break;
                                    }
                                }
                                
                                if (!baseStaNo) {
                                    layer.msg('请先为其中一个选中项选择站点', {icon: 2});
                                    return false;
                                }
                                
                                // 应用到所有选中的行,并同步同库位的行
                                for (let i = 0; i < checkStatus.length; i++) {
                                    let targetLocNo = checkStatus[i].locNo;
                                    for (let j = 0; j < tableCache.length; j++) {
                                        if (tableCache[j].locNo === targetLocNo) {
                                            tableCache[j].staNo = baseStaNo;
                                            $(layero).find('tr[data-index="' + j + '"] select.order-sta-select').val(baseStaNo);
                                        }
                                    }
                                }
                                form.render('select');
                                return false;
                            });
                        },
                        yes: function(index) { pakout(tableCache, index); },
                        btn2: function(index) { layer.close(index); }
                    });
                } else {
                    layer.msg(typeof I18n !== 'undefined' ? I18n.t(res.msg) : res.msg, {icon: 2});
                }
            }
        });
    }
 
    function pakout(tableCache, layerIndex) {
        notice.msg(typeof I18n !== 'undefined' ? I18n.t('generating_outbound_task') : '正在生成出库任务...', {icon: 4});
        $.ajax({
            url: baseUrl + "/out/pakout/auth",
            headers: {'token': localStorage.getItem('token')},
            contentType: 'application/json;charset=UTF-8',
            data: JSON.stringify(tableCache),
            method: 'POST',
            success: function (res) {
                notice.destroy();
                if (res.code === 200) {
                    layer.close(layerIndex);
                    layer.msg(typeof I18n !== 'undefined' ? I18n.t(res.msg) : res.msg, {icon: 1});
                    insTb.reload();
                    insTb2.reload({ page: { curr: 1 } });
                } else {
                    layer.msg(typeof I18n !== 'undefined' ? I18n.t(res.msg) : res.msg, {icon: 2});
                }
            }
        });
    }
 
    function autoOut(orderId) {
        let loadIndex = layer.msg(typeof I18n !== 'undefined' ? I18n.t('requesting') : '请求中...', {icon: 16, shade: 0.01, time: false});
        $.ajax({
            url: baseUrl + "/out/pakout/orderDetlIds/auth",
            headers: {'token': localStorage.getItem('token')},
            data: { orderId : orderId },
            method: 'POST',
            success: function (res) {
                layer.close(loadIndex);
                if (res.code === 200) { pakoutPreview(res.data); }
                else { layer.msg(typeof I18n !== 'undefined' ? I18n.t(res.msg) : res.msg, {icon: 2}); }
            }
        });
    }
 
    function inspectPass(orderId) {
        var data = table.cache['originTable'];
        var orderNo = "";
        for (var i = 0; i < data.length; i++) {
            if (data[i].id == orderId) {
                orderNo = data[i].orderNo;
                break;
            }
        }
        
        layer.confirm(typeof I18n !== 'undefined' ? I18n.t('confirm_inspect_pass') : '确认检验通过?', {icon: 3}, function (index) {
            layer.close(index);
            let loadIndex = layer.msg(typeof I18n !== 'undefined' ? I18n.t('processing') : '处理中...', {icon: 16, shade: 0.01, time: false});
            $.ajax({
                url: baseUrl + "/order/checkInspection/auth",
                headers: {'token': localStorage.getItem('token')},
                data: { orderNo: orderNo, inspectNumber: 1 },
                method: 'POST',
                success: function (res) {
                    layer.close(loadIndex);
                    if (res.code === 200) {
                        layer.msg(typeof I18n !== 'undefined' ? I18n.t(res.msg) : res.msg, {icon: 1});
                        insTb.reload();
                        insTb2.reload({ where: { order_id: -1 }, page: { curr: 1 } });
                        currentOrderId = -1;
                    } else {
                        layer.msg(typeof I18n !== 'undefined' ? I18n.t(res.msg) : res.msg, {icon: 2});
                    }
                }
            });
        });
    }
 
    function inspectFail(orderId) {
        var data = table.cache['originTable'];
        var orderNo = "";
        for (var i = 0; i < data.length; i++) {
            if (data[i].id == orderId) {
                orderNo = data[i].orderNo;
                break;
            }
        }
 
        layer.confirm(typeof I18n !== 'undefined' ? I18n.t('confirm_inspect_fail') : '确认检验不通过?', {icon: 3}, function (index) {
            layer.close(index);
            let loadIndex = layer.msg(typeof I18n !== 'undefined' ? I18n.t('processing') : '处理中...', {icon: 16, shade: 0.01, time: false});
            $.ajax({
                url: baseUrl + "/order/checkInspection/auth",
                headers: {'token': localStorage.getItem('token')},
                data: { orderNo: orderNo, inspectNumber: 2 },
                method: 'POST',
                success: function (res) {
                    layer.close(loadIndex);
                    if (res.code === 200) {
                        layer.msg(typeof I18n !== 'undefined' ? I18n.t(res.msg) : res.msg, {icon: 1});
                        insTb.reload();
                        insTb2.reload({ where: { order_id: -1 }, page: { curr: 1 } });
                        currentOrderId = -1;
                    } else {
                        layer.msg(typeof I18n !== 'undefined' ? I18n.t(res.msg) : res.msg, {icon: 2});
                    }
                }
            });
        });
    }
 
    // 暴露函数
    window.autoOut = autoOut;
    window.inspectPass = inspectPass;
    window.inspectFail = inspectFail;
});