自动化立体仓库 - WMS系统
dubin
2026-01-20 67826a2c51bbc013db409dd1a5e29dd4ba52fd72
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, target-densitydpi=high-dpi, initial-scale=1.0, user-scalable=no"/>
    <title>盘点</title>
    <link rel="stylesheet" href="../../static/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../static/css/pda.css" media="all">
    <script type="text/javascript" src="../../static/js/jquery/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="../../static/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../static/js/common.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../static/js/cool.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../static/js/handlebars/handlebars-v4.5.3.js"></script>
    <style>
        .quantity-input {
            width: 100%;
            height: 100%;
            border: none;
            text-align: center;
            background-color: transparent;
            color: blue;
        }
    </style>
</head>
<body>
<!-- 头部 -->
<header>
    <div class="layui-input-inline">
        <label class="layui-form-label">托盘条码</label>
        <input class="layui-input" type="number" id="code" onkeyup="findCode(this)" oninput="if(value.length>8)value=value.slice(0,8)" placeholder="扫码 / 输入" autocomplete="off">
    </div>
    <div style="margin: 5px 5px">
        <button id="mat-btn" type="button" class="layui-btn layui-btn-normal" onclick="getMat()"><i class="layui-icon">+</i>提取</button>
    </div>
</header>
 
<!-- 主体 -->
<main>
    <table class="layui-table" id="chooseData" lay-filter="chooseData"></table>
</main>
 
<!-- 尾部 -->
<footer>
    <div class="layui-btn-container">
        <button type="button" id="reset-btn" class="layui-btn layui-btn-primary" onclick="reset()">重置</button>
        <button type="button" id="submit-btn" class="layui-btn layui-btn-normal " onclick="submitCheck()" style="margin-left: 20px">盘点</button>
        <span id="tips"></span>
    </div>
</footer>
</body>
<script>
    var tableIns;
    var matData = [];
    var currentBarcode = '';
    var currentWrkNo = null;
 
    layui.use(['table','laydate', 'form'], function() {
        var table = layui.table;
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
 
        tableIns = table.render({
            elem: '#chooseData',
            data: matData,
            limit: 500,
            cellMinWidth: 50,
            cols: [[
                {fixed: 'left', align: 'center', field: 'anfme', title: '数量', style:'color: blue', width: 50, templet: function(d){
                        return '<input type="number" class="quantity-input" value="' + (d.anfme || 0) + '" ' +
                            'data-index="' + d.LAY_TABLE_INDEX + '" onblur="updateQuantity(this)" style="width: 100%">';
                    }},
                {field: 'matnr', align: 'center', title: '商品编号'},
                {field: 'maktx', align: 'center', title: '商品名称'},
                {field: 'specs', align: 'center', title: '规格'},
                {field: 'unit', align: 'center', title: '单位'},
                {field: 'barcode', align: 'center', title: '条码'},
                {field: 'stock', align: 'center', title: '托盘数量', style:'color: green', templet: function(d){
                        return d.stock || d.anfme || 0;
                    }}
            ]],
            done: function (res, curr, anfme) {
                // 绑定数量输入框事件
                bindQuantityEvents();
            }
        });
 
        function bindQuantityEvents() {
            // 绑定输入框点击事件
            $('.quantity-input').off('click').on('click', function(e){
                e.stopPropagation();
                $(this).select();
            });
 
            // 绑定回车键事件
            $('.quantity-input').off('keydown').on('keydown', function(e){
                if(e.keyCode === 13) {
                    e.preventDefault();
                    updateQuantity(this);
                    $(this).blur();
                }
            });
        }
    });
 
    window.onload = function(){
        document.getElementById("code").focus();
    }
 
    function findCode(el) {
        if (el.value.length === 8) {
            currentBarcode = el.value;
            getCheckDetails(currentBarcode);
        }
    }
 
    var matCodeLayerIdx;
    function getMat() {
        matCodeLayerIdx = layer.open({
            type: 2,
            title: '提取物料',
            shade: [0.3,'#000'],
            area: ['90%', '80%'],
            content: 'matQuery.html',
            success: function(layero, index){
                $('.layui-layer-title').css('font-size', '16px');
            },
            end: function () {
                $('#mat-btn').focus();
            }
        });
    }
 
    // 添加表格数据 - 来自物料选择弹窗
    function addTableData(data) {
        if (isEmpty(data.maktx)){
            tips("提取失败", true);
            return;
        }
        let toPush = true;
        for (var j=0; j<matData.length; j++){
            if (data.matnr === matData[j].matnr) {
                // 如果是同一个物料,累加数量
                matData[j].anfme = Number(matData[j].anfme) + Number(data.anfme);
                toPush = false;
                break;
            }
        }
        if (toPush) {
            // 新增物料,添加库存字段
            var newItem = {
                LAY_TABLE_INDEX: matData.length,
                anfme: data.anfme || 0,
                matnr: data.matnr || '',
                maktx: data.maktx || '',
                specs: data.specs || '',
                unit: data.unit || '',
                barcode: data.barcode || '',
                stock: 0 // 手动添加的物料,库存为0
            };
            matData.push(newItem);
        }
        tips("提取成功");
        tableIns.reload({data: matData});
    }
 
    // 获取盘点明细
    function getCheckDetails(barcode) {
        if (!barcode || barcode.length !== 8) {
            tips("托盘条码必须为8位", true);
            return;
        }
 
        if (!barcode.startsWith("5") &&
            !barcode.startsWith("6") &&
            !barcode.startsWith("7") &&
            !barcode.startsWith("8")){
            tips("托盘条码格式错误", true);
            return;
        }
 
        tips("正在查询...", false);
 
        $.ajax({
            url: baseUrl + "/mobile/checkDetl/auth/v2?barcode=" + encodeURIComponent(barcode),
            headers: {'token': localStorage.getItem('token')},
            method: 'GET',
            success: function (res) {
                if (res.code === 200) {
                    if (res.data && res.data.wrkDetls && res.data.wrkDetls.length > 0) {
                        var result = res.data;
                        currentWrkNo = result.wrkNo;
 
                        matData = result.wrkDetls.map(function(item, index) {
                            return {
                                LAY_TABLE_INDEX: index,
                                anfme: item.anfme || 0,
                                matnr: item.matnr || '',
                                maktx: item.maktx || '',
                                specs: item.specs || '',
                                unit: item.unit || '',
                                barcode: item.barcode || '',
                                stock: item.anfme || 0,
                                detlNo: item.detlNo || '',
                                wrkNo: item.wrkNo || '',
                                detlId: item.detlId || null,
                                locno: item.locno || '',
                                batch: item.batch || '',
                                itemBatch: item.itemBatch || ''
                            };
                        });
 
                        tableIns.reload({data: matData});
                        tips("查询成功,共 " + matData.length + " 条记录");
                    } else {
                        matData = [];
                        tableIns.reload({data: matData});
                        tips("该托盘暂无盘点数据", false);
                    }
                } else if (res.code === 403) {
                    tips("登录已过期,请重新登录", true);
                    setTimeout(function() {
                        top.location.href = baseUrl + "/pda";
                    }, 1500);
                } else {
                    tips(res.msg || "查询失败,错误码:" + res.code, true);
                }
            },
            error: function(xhr, status, error) {
                if (xhr.responseJSON && xhr.responseJSON.code) {
                    var res = xhr.responseJSON;
                    if (res.code === 403) {
                        tips("登录已过期,请重新登录", true);
                        setTimeout(function() {
                            top.location.href = baseUrl + "/pda";
                        }, 1500);
                    } else {
                        tips(res.msg || "接口返回错误,错误码:" + res.code, true);
                    }
                } else {
                    if (xhr.status === 404) {
                        tips("接口不存在(404),请检查URL路径", true);
                    } else if (xhr.status === 500) {
                        tips("服务器内部错误(500)", true);
                    } else if (xhr.status === 0) {
                        tips("无法连接到服务器,请检查网络", true);
                    } else {
                        tips("请求失败,状态码:" + xhr.status, true);
                    }
                }
            }
        });
    }
 
    // 更新数量
    function updateQuantity(input) {
        var value = $(input).val();
        var index = $(input).data('index');
 
        if (value === '' || value === null) {
            value = 0;
            $(input).val(0);
        }
 
        value = parseFloat(value);
        if (isNaN(value) || value < 0) {
            value = 0;
            $(input).val(0);
        }
 
        if (matData[index]) {
            matData[index].anfme = value;
 
            // 更新输入框的值
            $(input).val(value);
 
            // 高亮显示差异
            var stock = matData[index].stock || 0;
            if (value !== stock) {
                $(input).css('color', '#ff5722'); // 橙色表示有差异
            } else {
                $(input).css('color', 'blue'); // 蓝色表示无差异
            }
        }
    }
 
    // 重置
    function reset() {
        $('#code').val("");
        currentBarcode = '';
        currentWrkNo = null;
        matData = [];
        tableIns.reload({data: matData});
        document.getElementById("code").focus();
    }
 
    // 盘点提交 - 调用 /inventory/auth 接口
    function submitCheck() {
        let barcode = $('#code').val();
        if (isEmpty(barcode)) {
            tips("托盘条码为空", true);
            return;
        }
        if (barcode.length !== 8) {
            tips("条码必须为8位", true);
            return;
        }
        if (!barcode.startsWith("5") &&
            !barcode.startsWith("6") &&
            !barcode.startsWith("7") &&
            !barcode.startsWith("8")){
            tips("托盘条码格式错误", true);
            return;
        }
        if (matData.length === 0) {
            tips("请盘点物料", true);
            return;
        }
 
        // 构建 CombParam 数据结构
        var combMats = matData.map(function(item) {
            var combMat = {
                detlId: item.detlId || null,
                detId: item.detlNo || null,
                matnr: item.matnr || '',
                anfme: item.anfme || 0,
                maktx: item.maktx || '',
                specs: item.specs || '',
                batch: item.batch || '',
                itemBatch: item.itemBatch || ''
            };
 
            // 如果有其他字段也一并提交
            if (item.proType) combMat.proType = item.proType;
            if (item.temp2) combMat.temp2 = item.temp2;
            if (item.outOrderNo) combMat.outOrderNo = item.outOrderNo;
            if (item.memo) combMat.memo = item.memo;
 
            return combMat;
        });
 
        // 构建完整的请求数据
        var requestData = {
            barcode: barcode,
            locno: matData[0]?.locno || '', // 如果有库位信息
            combMats: combMats
        };
 
        // 如果有单据编号,也一并提交
        if (currentWrkNo) {
            requestData.orderNo = currentWrkNo.toString();
            requestData.billNo = currentWrkNo.toString();
        }
 
        console.log("提交数据:", JSON.stringify(requestData, null, 2));
 
        tips("正在提交盘点数据...", false);
 
        $.ajax({
            url: baseUrl + "/mobile/inventory/auth",
            headers: {'token': localStorage.getItem('token')},
            data: JSON.stringify(requestData),
            contentType:'application/json;charset=UTF-8',
            method: 'POST',
            success: function (res) {
                if (res.code === 200) {
                    reset();
                    tips("盘点成功");
                } else if (res.code === 403) {
                    tips("登录已过期,请重新登录", true);
                    setTimeout(function() {
                        top.location.href = baseUrl + "/pda";
                    }, 1500);
                } else {
                    tips(res.msg || "盘点失败", true);
                }
            },
            error: function(xhr, status, error) {
                if (xhr.responseJSON && xhr.responseJSON.code) {
                    tips(xhr.responseJSON.msg || "提交失败", true);
                } else {
                    tips("提交失败,状态码:" + xhr.status, true);
                }
            }
        });
    }
 
    function tips(msg, warn) {
        layer.msg(msg, {icon: warn?2:1})
    }
 
    document.onkeyup = function (e) {
        if (window.event)
            e = window.event;
        var key = e.charCode || e.keyCode;
        if (key === 115) { // F4键
            $("#submit-btn").focus();
            submitCheck();
        } else if (key === 113) { // F2键
            $("#code").val("");
            $("#code").focus();
        } else if (key === 114) { // F3键
            getMat();
        } else if (key === 116) { // F5键
            if (currentBarcode) {
                getCheckDetails(currentBarcode);
            }
        }
    }
</script>
</html>