wxw
2025-05-12 c7c2f7aa20427204944ba80a2704232b2f281582
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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
<!DOCTYPE html>
<html>
 
<head>
    <meta charset="utf-8">
    <title>添加托盘绑定</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
    <style>
        .rightMargin {
            margin-right: 0px;
        }
 
        .buJu {
            margin-top: 10px;
            display: flex;
            flex-direction: row-reverse;
        }
 
        .beiJing {
            background-color: #fafafa;
            padding-top: 5px;
            border-radius: 3px;
            box-shadow: inset 0 0 3px 1px #ccc;
        }
    </style>
</head>
 
<body>
 
    <div class="layui-fluid" style="padding: 3px;">
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <div class="layui-inline" style="margin-right: 0;">
                        <label class="layui-form-label" style="width: 60px;">入库单</label>
                        <div class="layui-input-inline" style="margin-right: 0;">
                            <select name="BillCode" id="BillCode" lay-verify="required" lay-filter="BillCode"
                                lay-search>
                                <option value=""></option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline" style="margin-right: 0;">
                        <label class="layui-form-label" style="width: 70px;">物料-批次</label>
                        <div class="layui-input-inline" style="margin-right: 0;">
                            <select name="detail" id="detail" lay-verify="required" lay-filter="detail" lay-search>
                                <option value=""></option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline" style="margin-right: 0;">
                        <label class="layui-form-label" style="width: 60px;">托盘条码</label>
                        <div class="layui-input-inline" style="margin-right: 0;">
                            <div class="layui-input-inline" style="margin-right: 0;">
                                <input type="text" id="palletNo" name="palletNo" placeholder="托盘条码" autocomplete="off"
                                    class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-inline" style="margin-right: 0;">
                        <label class="layui-form-label" style="width: 40px;">箱码</label>
                        <div class="layui-input-inline" style="margin-right: 0;">
                            <div class="layui-input-inline" style="margin-right: 0;">
                                <input type="text" id="palletNo" name="palletNo" placeholder="箱码" autocomplete="off"
                                    class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-sm layuiadmin-btn-list" lay-submit
                            lay-filter="confirm">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>搜索
                        </button>
                        <!-- <button type="button" class="layui-btn layui-btn-sm" id="daoru">
                            导入
                        </button> -->
                        <button style="margin-right: 15px;" class="layui-btn layui-btn-sm layuiadmin-btn-list"
                            lay-submit id="Create" lay-filter="Create">提交</button>
                    </div>
                </div>
            </div>
            <div class="layui-card-body">
                <table id="Box-list" lay-filter="Box-list"></table>
                <script type="text/html" id="bulkTank">
                       <p>{{d.BulkTank == 0? '否':'是'}}</p>
                    </script>
                <script type="text/html" id="table-content-list">
                    <a class="layui-btn layui-btn-danger layui-btn-xs delClass" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>    
                </script>
            </div>
 
        </div>
    </div>
 
 
    <script src="../../layuiadmin/layui/layui.js"></script>
    <script src="../../js/jquery-3.5.1.min.js"></script>
    <script src="../../js/jquery.cookie.js"></script>
    <script src="../../js/public.js"></script>
    <script>
        layui.extend({
            excel: '../../layuiadmin/layui/layui_exts/excel' // {/}的意思即代表采用自有路径,即不跟随 base 路径
        })
 
        layui.config({
            base: '../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'form', 'layer', 'table', 'laydate', 'upload', 'excel'], function () {
            var form = layui.form,
                table = layui.table,
                layer = layui.layer;
            laydate = layui.laydate;
 
            var param = {
                Type: "0"
            };
            sendData(IP + "/PdaAsn/GetArrivalNotices", param, 'post', function (res) {
                if (res.code == 0) { //成功
                    $("#BillCode").empty();
                    $("#BillCode").append("<option value =''></option>");
                    for (var i = 0; i < res.data.length; i++) {
                        $("#BillCode").append('<option value =' + res.data[i].ASNNo + '>' + res.data[i].ASNNo +
                            '</option>');
                    }
                    form.render('select');
                } else { //不成功
                    layer.msg(res.msg, {
                        icon: 2,
                        time: 2000 //2秒关闭(如果不配置,默认是3秒)
                    }, function () { });
                }
            });
            // 绑定入库单物料及批次
            function updateGoodList() {
 
                $("#detail").empty()
                $("#detail").append('<option value =>' + '</option>');
 
                var param = {
                    AsnNo: $("#BillCode").val(),
                };
                synData(IP + "/PdaAsn/GetArrivalNoticeDetails", param, 'post', function (res) {
                    if (res.code == 0) { //成功
                        asnDetails = res.data;
                        for (var i = 0; i < res.data.length; i++) {
                            if (i == 0) {
                                $("#detail").append('<option value =' + res.data[i].Id + ' selected>' + res.data[i]
                                    .SkuName + "-" + res.data[i].LotNo +
                                    '</option>');
                            } else {
                                $("#detail").append('<option value =' + res.data[i].Id + '>' + res.data[i]
                                    .SkuName + "-" + res.data[i].LotNo +
                                    '</option>');
                            }
 
                        }
                        form.render('select');
                    } else {
                        layer.msg(res.msg, {
                            icon: 2,
                            time: 2000 //2秒关闭(如果不配置,默认是3秒)
                        }, function () { });
                    }
                });
            }
            form.on('select(BillCode)', function (data) {
                updateGoodList();
            });
 
 
            //#endregion
            laydate.render({
                elem: '#StartTime'
                , format: 'yyyy-MM-dd' //可任意组合
            });
            laydate.render({
                elem: '#EndTime'
                , format: 'yyyy-MM-dd' //可任意组合
            });
            renderTable();
 
            function renderTable() {
                var tableIns = table.render({
                    elem: '#Box-list',
                    height: 'full-195',
                    id: 'Box-list',
                    data: list,
                    page: true,
                    limit: 10,  //默认多少页
                    limits: [10, 15],    //默认数组[10,20,30,40,50]
                    cellMinWidth: 80, //全局定义常规单元格的最小宽度,layui 2.2.1 新增
                    even: true, //隔行换色
                    cols: [
                    [
                        {field: 'boxNo',title: '箱码',align: 'center',fixed: 'left',width:150},
                        {field: 'SkuNo',title: '物料编号',align: 'center',width:150},
                        {field: 'SkuName',title: '物料名称',align: 'center',width:150},
                        {field: 'LotNo',templet: '#buttonTpl',title: '批次号',align: 'center',width:150}, 
                        {field: 'Qty',title: '实际数量',align: 'center',width:150}, 
                        {field: 'Standard',title: '物品规格',align: 'center'}, 
                        {title: '操作',fixed: 'right',width: 100,align: 'center',toolbar: '#table-content-list'}
                    ]],
 
                });
            }
            
 
            //添加箱码集合
            form.on('submit(confirm)', function (data) {
 
                 
                var result = true;
                // str.replace(/\s/g,"")  js去除string字符串左右中间的空格
                list.forEach(item => {
                    if (item.GoodCode.replace(/\s/g, "") === data.field.GoodCode.replace(/\s/g, "") && item.LotNo.replace(/\s/g, "") === data.field.LotNo.replace(/\s/g, "")) {
                        layer.msg('物品和批次号已存在');
                        result = false;
                        return;
                    }
                })
                 
                if (result) {
                    var param = {
                        boxNo: data.field.boxNo,
                    };
                    sendData(IP + "/ImportOrder/GetGoodsByCode", param, 'post', function (res) {
                        console.log(res);
                        if (res.code == 1) { //成功
                            
                            list.push({
                                GoodCode: data.field.GoodCode,
                                GoodsName: res.data.GoodsName,
                                GoodsStandard: res.data.GoodsStandard,
                                UnitName: res.data.UnitName,
                                LotNo: data.field.LotNo,
                                Qty: data.field.Qty
                            })
                            console.log(list);
                            $("#GoodCode").val("");
                            $("#LotNo").val("");
                            $("#Qty").val("");
 
                            tableIns2.reload({
                                data: list,
                                page: {
                                    curr: 1 //重新从第 1 页开始
                                }
                            });
                        } else { //不成功
                            layer.msg(res.msg, {
                                icon: 2,
                                time: 2000 //2秒关闭(如果不配置,默认是3秒)
                            }, function () { });
                        }
                    });
                }
 
                return false;
 
            });
 
            table.on('tool(Box-list)', function (obj) {
                var data = obj.data;
                // console.log(obj.event);
                if (obj.event === 'del') {
                    layer.confirm('确定删除箱码信息?', { offset: ['20%', '35%'] }, function (index) {
                        console.log(data);
                        console.log(index);
                        for (let i = 0; i < list.length; i++) {
                            const ele = list[i];
                            if (ele.BoxCode == data.BoxCode) {
                                list.splice(i, 1)
                            }
                        }
                        console.log(list);
 
                        tableIns2.reload({
                            data: list,
                            page: {
                                curr: 1 //重新从第 1 页开始
                            }
                        });
                        layer.close(index);
                    });
 
                }
            });
            var doing = true;
            //提交箱码托盘关系
            form.on('submit(Create)', function () {
 
 
                if (!$.cookie('userId')) {
                    layer.msg('登陆失效,请重新登陆', {
                        icon: 2,
                        time: 2000 //2秒关闭(如果不配置,默认是3秒)
                    }, function () {
                        window.parent.location.href =
                            "../Login.html";
                    });
                }
                var result = true;
                if ($("#BillCode").val().replace(/\s/g, "") == "") {
                    layer.msg("请填写入库单");
                    result = false;
                    return;
                }
                if ($("#StockCode").val().replace(/\s/g, "") == "") {
                    layer.msg("请填写托盘码");
                    result = false;
                    return;
                }
 
                // if (list.length == 0) {
                //     layer.msg('请填写箱码信息');
                //     result = false;
                //     return;
 
                // }
                if (result) {
                    var param = {
                        BillCode: $("#BillCode").val(),
                        StockCode: $("#StockCode").val(),
                        UserId: $.cookie('userId'), //当前登录人
                        List: list
                    }
 
                    if (doing) {
                        doing = false;
                        sendData(IP + "/ImportOrder/CreateBoxInfoNew2", param, 'post', function (res) {
                            console.log(res);
                            if (res.code == 1) { //成功
                                layer.msg(res.msg, {
                                    icon: 1,
                                    time: 2000 //2秒关闭(如果不配置,默认是3秒)
                                }, function () {
                                    var index = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(index); //关闭弹层
                                    parent.layui.table.reload('LAY-app-content-list');
                                    doing = true;
                                });
                            } else { //不成功
                                layer.msg(res.msg, {
                                    icon: 2,
                                    time: 2000 //2秒关闭(如果不配置,默认是3秒)
                                }, function () { doing = true; });
                            }
                        });
 
                    }
                }
 
                return false;
 
            });
 
            // //关闭弹窗
            // form.on('submit(Close)', function () {
 
            //     var index = parent.layer.getFrameIndex(window.name);
            //     parent.layer.close(index); //关闭弹层
 
            //     return false;
 
            // });
 
            var list = [
                // {
                //     "BoxCode":"XM20220328001",
                //     "GoodCode":"100007",
                //     "LotNo":"PC1001",
                //     "Quant":100,
                //     "Qty":100,
                //     "BulkTank":0,
                //     "ProductionDate":"2022-03-14",
                //     "ValidateDay":"2022-09-14"
                // }
            ];
 
            //#region  导入文件测试
 
            var upload = layui.upload;
 
            //执行实例
            var uploadInst = upload.render({
                elem: '#daoru' //绑定元素
                , url: '' //上传接口
                , auto: false  //是否选完文件后自动上传。如果设定 false,那么需要设置 bindAction 参数来指向一个其它按钮提交上传
                , exts: 'slx|excel|xlsx'  //允许上传的文件后缀 
                , accept: 'file' //指定允许上传时校验的文件类型
                , bindAction: '#Create' //指向一个按钮触发上传
                , choose: function (obj) {// 选择文件回调
                    console.log(obj);
                    var files = obj.pushFile(); //将每次选择的文件追加到文件队列
                    var fileArr = Object.values(files);// 注意这里的数据需要是数组,所以需要转换一下
                    console.log(fileArr)
                    // 用完就清理掉,避免多次选中相同文件时出现问题
                    for (var index in files) {
                        console.log(index);
                        if (files.hasOwnProperty(index)) {
                            delete files[index];
                        }
                    }
                    uploadExcel(fileArr); // 如果只需要最新选择的文件,可以这样写: uploadExcel([files.pop()])
                }
                , done: function (res) {
                    console.log(res);
                    //上传完毕回调
                }
                , error: function () {
                    //请求异常回调
                }
            });
 
            function uploadExcel(files) {
                try {
                    var excel = layui.excel;
                    excel.importExcel(files, {
                        // 读取数据的同时梳理数据
                        fields: {
                            'BoxCode': 'A',
                            'GoodCode': 'B',
                            'LotNo': 'C',
                            'Quant': 'D',
                            'Qty': 'E',
                            'BulkTank': 'F',
                            ProductionDate: 'G',
                            ValidateDay: 'H'
                        }
                    },
                        function (data) {
                            console.log(data);
                            // var arr = new Array();
                            //excel第一行不读取、设置为标题
                            for (i = 1; i < data[0].Sheet1.length; i++) {
                                var tt = {
                                    BoxCode: data[0].Sheet1[i].BoxCode,
                                    GoodCode: data[0].Sheet1[i].GoodCode,
                                    LotNo: data[0].Sheet1[i].LotNo,
                                    Quant: data[0].Sheet1[i].Quant,
                                    Qty: data[0].Sheet1[i].Qty,
                                    BulkTank: data[0].Sheet1[i].BulkTank,
                                    ProductionDate: data[0].Sheet1[i].ProductionDate,
                                    ValidateDay: data[0].Sheet1[i].ValidateDay,
                                };
                                list.push(tt);
                            }
                            // list.push(arr);
                            // console.log(list);
                            tableIns2.reload({
                                data: list,
                                page: {
                                    curr: 1 //重新从第 1 页开始
                                }
                            });
                        });
                } catch (e) {
                    layer.alert(e.message);
                }
 
            }
 
 
 
        })
    </script>
</body>
 
</html>