bklLiudl
2025-04-07 4e8f58cb41c7b6d570fd1979d80f74ab8a4d00c2
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
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
<!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, minExum-scale=1.0, maxExum-scale=1.0, user-scalable=0">
        <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
        <style>
            .isShow{
                display: block;
            }
            .isNoShow{
                display: none;
            }
        </style>
    </head>
    <body> 
        <div class="layui-form" lay-filter="layuiadmin-app-form-list" style="padding: 20px 0 0 0;">
            <div class="layui-form-item" style="margin-bottom: 0px;">
                <!-- <div class="layui-inline">
                    <label class="layui-form-label">出库仓库</label>
                    <div class="layui-input-inline">
                        <select name="WarehouseId" id="WarehouseId" lay-filter="WarehouseId" lay-verify="required" lay-search>
                            <option value=""></option>
                        </select>
                    </div>
                </div> -->
                <div class="layui-inline">
                    <label class="layui-form-label">单据类型</label>
                    <div class="layui-input-inline">
                        <select name="Type" id="Type" lay-filter="Type" lay-verify="required" lay-search>
                            <!-- <option value=""></option> -->
                            <!-- 24 -->
                            <option value="0">成品出库</option>
                            <option value="1">领料出库</option>
                            <option value="2">抽检出库</option>
                            <option value="3">物料取样出库</option>
                            <option value="4">不合格品出库</option>
                            <option value="5">中间品出库</option>
                            <option value="6">代储出库</option>
                            <option value="7">其它出库</option>
                            <option value="8">寄存出库</option>
                            <!-- 09 -->
                            <!-- <option value="0">标准销售出库</option>
                            <option value="1">非标销售出库</option>
                            <option value="2">标准调拨出库</option>
                            <option value="3">非标调拨出库</option> -->
                            <!-- 08 -->
                            <!-- <option value="0">成品出库</option>
                            <option value="1">原辅料出库</option>
                            <option value="2">不合格品出库</option>
                            <option value="3">取样出库</option> -->
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label" id="CustomerNamep">客户名称</label>
                    <div class="layui-input-inline">
                        <select name="CustomerNo" id="CustomerNo" lay-search>
                            <option value=""></option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline " id="chengyunshang">
                    <label class="layui-form-label">承运商</label>
                    <div class="layui-input-inline">
                        <select name="LogisticsId" id="LogisticsId" lay-search>
                            <option value=""></option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <div style="padding-bottom: 2px;margin-left: 15px;">
                        <button class="layui-btn layui-btn-sm layuiadmin-btn-list" data-type="add">添加明细</button>
                        <button type="submit" class="layui-btn layui-btn-sm layuiadmin-btn-list" lay-submit=""
                        lay-filter="form1">立即提交</button>
                    </div>
                </div>
            </div>
            
            <div class="layui-card">
                <div class="layui-card-body">
                    
                    <table id="LAY-app-content-list" name="LAY-app-content-list" lay-filter="LAY-app-content-list"></table>
                        
                    <!-- <script type="text/html" id="switchTpl">
                        <input type="checkbox" name="IsBale" value="{{d.LAY_TABLE_INDEX}}" lay-skin="switch" lay-text="是|否" lay-filter="IsBaleDemo" {{ d.IsBale == "1" ? 'checked' : '' }}>
                    </script>
                    <script type="text/html" id="checkboxTpl">
                        <input type="checkbox" name="IsBelt" value="{{d.LAY_TABLE_INDEX}}" lay-skin="switch" lay-text="是|否" lay-filter="IsBeltDemo" {{ d.IsBelt == "1" ? 'checked' : '' }}> 
                    </script>     -->
                    <script type="text/html" id="table-content-list">
                        <a class="layui-btn layui-btn-danger layui-btn-xs" 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/public.js"></script>
        <script src="../../js/jquery-3.5.1.min.js"></script>
        <script src="../../js/jquery.cookie.js"></script>
        <script>
            layui.config({
                base: '../../layuiadmin/' //静态资源所在路径
            }).extend({
                index: 'lib/index' //主入口模块
            }).use(['index', 'form', 'layer', 'laydate', 'table','jquery'], function() {
                var $ = layui.$,
                    form = layui.form,
                    table = layui.table,
                    layer = layui.layer;
                     
                // getWareHouseList();
                getCustomerList();
                getLogisticsInfoList();
                
                window.success = function(data) {
                    console.log(data);
                    refreshTable(data);
                };
 
                var arr = []; 
                var TypeValue=$("#Type").val();
                function refreshTable(data) {
                    //table.clear();
                    
                    for (var i in data) {
                        var isHave = false;
                        data[i].ExQty = 0;
                        data[i].IsBale="0";
                        data[i].IsBelt="0";
                        
                        for(var j in arr){
                            if(arr[j].SkuNo == data[i].SkuNo && arr[j].LotNo == data[i].LotNo){
                                isHave = true;
                                break;
                            }
                        }
                        if(isHave){
                            continue;
                        }
                        arr.push(data[i]); //属性
                    }
                    $.extend(infoOptions, {
                        data: arr
                    });
                    infoOptions.page = {
                        curr: 1
                    }
                    table.render(infoOptions);
                    
                }
                var infoOptions = {
                    elem: '#LAY-app-content-list',
                    height: 'full-160',
                    id: 'LAY-app-content-list',
                    page: true,
                    limit: pageCnt,
                    limits: pageLimits,
                    cellMinWidth: 60, //全局定义常规单元格的最小宽度,layui 2.2.1 新增
                    cols: [
                        [{
                            field: 'SkuNo',
                            title: '物品编码', 
                            align: 'center',
                            fixed: 'left',
                            width:140,
                        }, {
                            field: 'SkuName',
                            title: '物品名称', 
                            align: 'center',
                            fixed: 'left',
                        }, {
                            field: 'LotNo',
                            title: '批次',
                            align: 'center', 
                            minWidth:140,
                        }, {
                            field: 'Standard',
                            title: '物品规格',
                            align: 'center', 
                        }, {
                            field: 'Qty',
                            title: '库存数量',  
                            align: 'center',
                            width:100,
                        }, {
                            field: 'ExQty',
                            title: '出库数量',
                            align: 'center',
                            width:100,  
                            edit: 'number',
                            event: 'dataNumber'
                        },  
                        // {
                        //     field:'IsBale', 
                        //     title:'是否裹包',
                        //     width:90,
                        //     templet: '#switchTpl', 
                        //     unresize: true //是否禁用拖拽列宽
                        // }, {
                        //     field:'IsBelt', 
                        //     title:'是否打带',
                        //     width:90,
                        //     templet: '#checkboxTpl', 
                        //     unresize: true //是否禁用拖拽列宽
                        // }, 
                        {
                            title: '操作',
                            align: 'center',
                            width:90,
                            templet: '#table-content-list', 
                            fixed: 'right',
                        }]
                    ],
                };
                // //监听裹包操作
                // form.on('switch(IsBaleDemo)', function(obj){
                //     if (obj.elem.checked) {
                //         for (var k in arr) {
                //             if (arr[k].LAY_TABLE_INDEX == obj.value) {
                //                 arr[k].IsBale = "1";
                //             } 
                //         }
                         
                //     }else{
                //         for (var k in arr) {
                //             if (arr[k].LAY_TABLE_INDEX == obj.value) {
                //                 arr[k].IsBale = "0";
                //             } 
                //         }
                //     }
                // });
                
                // //监听打带操作
                // form.on('switch(IsBeltDemo)', function(obj){ 
                //     if (obj.elem.checked) {
                //         for (var k in arr) {
                //             if (arr[k].LAY_TABLE_INDEX == obj.value) {
                //                 arr[k].IsBelt = "1";
                //             } 
                //         }
                         
                //     }else{
                //         for (var k in arr) {
                //             if (arr[k].LAY_TABLE_INDEX == obj.value) {
                //                 arr[k].IsBelt = "0";
                //             } 
                //         }
                //     }
                // });
                //初始渲染
                refreshTable(null);
                var $ = layui.$;
                var    active = {
                    add: function() { 
                        // if ($("#WarehouseId").val()== "") {
                        //     layer.msg("请选择仓库!", {
                        //         icon: 2,
                        //         time: 2000 //2秒关闭(如果不配置,默认是3秒)
                        //     },function() {});
                        //     return;
                        // }
                        if ($("#Type").val()== "") {
                            layer.msg("请选择单据类型!", {
                                icon: 2,
                                time: 2000 //2秒关闭(如果不配置,默认是3秒)
                            },function() {});
                            return;
                        }
                        if($("#Type").val()=='6'){
                            if($("#CustomerNo").val()==''){
                                layer.msg("代储单据请选择货主!", {
                                    icon: 2,
                                    time: 2000 //2秒关闭(如果不配置,默认是3秒)
                                }, function () {
 
                                });
                                return;
                            }
                        }
                        layer.open({
                            type: 2,
                            title: '选择物品信息',
                            content: 'ExportSelectSkuFrom.html?Type='+$("#Type").val()+'&OwnerNo='+$("#CustomerNo").val(),
                            maxmin: true,
                            area: ['950px', '90%'],
                            fixed: false,
                        });
                    }
                };
                $('.layui-btn.layuiadmin-btn-list').on('click', function() {
                    var type = $(this).data('type');
                    active[type] ? active[type].call(this) : '';
                });
 
                table.on('tool(LAY-app-content-list)', function(obj) {
                    var data = obj.data;
                    if (obj.event === 'del') {
                        var ii = -1;
                        for (var j in arr) {
                            if (obj.data.SkuNo == arr[j].SkuNo && arr[j].LotNo == obj.data.LotNo) {
                                ii = j;
                                break;
                            }
                        }
                        if (ii > -1) {
                            arr.splice(ii, 1);
                            obj.del();
                        }
                    } else if (obj.event === 'dataNumber') {
                        $(".layui-input.layui-table-edit").attr("type", "number"); 
                    }
                });
 
                form.verify({
                    emptyNo: function(value) {
                        if (value == '') {
                            return '';
                        } else {
                            var ver = /^[0-9]+$/;
                            if (!ver.test(value)) {
                                return '只能输入正整数';
                            }
                        }
                    }
                });
                var isrun = 0;
                form.on('submit(form1)', function(data) {
                    if(isrun == 1){
                        return;
                    }
                    isrun = 1; 
                    if (infoOptions.data == 0) {
                        layer.msg("请添加明细!", {
                            icon: 2,
                            time: 2000 //2秒关闭(如果不配置,默认是3秒)
                        }, function() {
 
                        });
                        isrun = 0;
                        return;
                    }
                    var type= $("#Type").val();
                    if(type=='6'){
                        var CustomerNo=$("#CustomerNo").val();
                        if(CustomerNo==''){
                            layer.msg("代储单据请选择货主!", {
                                icon: 2,
                                time: 2000 //2秒关闭(如果不配置,默认是3秒)
                            }, function () {
 
                            });
                            return;
                        }
                    }
                    var DataList = [];
                    console.log(infoOptions.data);
                    var reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,4})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
                    for (var i in infoOptions.data) {
                        console.log(infoOptions.data[i].ExQty);
                        if (infoOptions.data[i].ExQty == "") {
                            layer.msg("请输入出库数量!", {
                                icon: 2,
                                time: 2000 //2秒关闭(如果不配置,默认是3秒)
                            }, function() {});
                            isrun = 0;
                            return;
                        }
                        if (!reg.test(infoOptions.data[i].ExQty)) {
                            layer.msg("出库数量必须大于0(可保留4位小数)", {
                                icon: 2,
                                time: 2000 //2秒关闭(如果不配置,默认是3秒)
                            });
                            isrun = 0;
                            return ;
                        }
                        // if(infoOptions.data[i].ExQty.indexOf('.')>=0){
                        //     layer.msg("出库数量必须是大于0的整数", {
                        //         icon: 2,
                        //         time: 2000 //2秒关闭(如果不配置,默认是3秒)
                        //     }, function() {});
                        //     isrun = 0;
                        //     return;
                        // }
                        // if(infoOptions.data[i].ExQty.indexOf('-')>=0){
                        //     layer.msg("出库数量必须是大于0的整数", {
                        //         icon: 2,
                        //         time: 2000 //2秒关闭(如果不配置,默认是3秒)
                        //     }, function() {});
                        //     isrun = 0;
                        //     return;
                        // }
                        // if(infoOptions.data[i].ExQty.charAt(0)=='0'){ 
                        //     layer.msg("出库数量必须是大于0的整数", {
                        //         icon: 2,
                        //         time: 2000 //2秒关闭(如果不配置,默认是3秒)
                        //     }, function() {});
                        //     isrun = 0;
                        //     return;
                        // }
                        
                        // if (infoOptions.data[i].ExQty <= 0) {
                        //     layer.msg("出库数量必须大于0!", {
                        //         icon: 2,
                        //         time: 2000 //2秒关闭(如果不配置,默认是3秒)
                        //     }, function() {});
                        //     isrun = 0;
                        //     return;
                        // }
                        if (infoOptions.data[i].ExQty > infoOptions.data[i].Qty) {
                            layer.msg("出库数量不能大于库存数量!", {
                                icon: 2,
                                time: 2000 //2秒关闭(如果不配置,默认是3秒)
                            }, function() {});
                            isrun = 0;
                            return;
                        }
                        var item = {
                            SkuNo: infoOptions.data[i].SkuNo,
                            LotNo: infoOptions.data[i].LotNo,
                            Qty: parseFloat(infoOptions.data[i].ExQty),
                            IsBale:infoOptions.data[i].IsBale,
                            IsBelt:infoOptions.data[i].IsBelt,
                        };
                        DataList.push(item); //属性
                    }
                    
                    var param = {
                        Type: data.field.Type,
                        CustomerNo: data.field.CustomerNo,
                        
                        LogisticsId: parseInt(data.field.LogisticsId), 
                        Detail: DataList
                    }
                    sendData(IP + "/BllSo/AddExportNotice", param, 'post', function(res) {
                        console.log(res);
                        if (res.code == 0) { //成功
                            layer.msg(res.msg, {
                                icon: 1,
                                time: 2000 //2秒关闭(如果不配置,默认是3秒)
                            }, function() {
                                parent.location.reload();
                                parent.layer.close(layer.index);
                            });
                            isrun = 0;
                        } else if(res.code == 1) { //不成功
                            layer.msg(res.msg, {
                                icon: 2,
                                time: 2000 //2秒关闭(如果不配置,默认是3秒)
                            }, function() {});
                            isrun = 0;
                        }
                    });
                    return false;
                });
                 
                
                //下拉单据类型选中后事件
                form.on('select(Type)', function(data) {
                    var value = data.value;
                    if(value!=TypeValue){
                        getCustomerList();
                        arr = [];
                        // 渲染Table
                        refreshTable(null);
                        TypeValue=value;
                    }
                });
                //获取仓库下拉框信息
                // function getWareHouseList(){
                //     sendData(IP + "/Sys/GetWarehouseDic", {}, 'get', function(res) {
                        
                //         if (res.code == 0) { //成功
                //             $("#WarehouseId").empty();
                //             // $("#WarehouseId").append('<option value =""></option>');
                //             for (var i = 0; i < res.data.length; i++) {
                //                 $("#WarehouseId").append('<option value =' + res.data[i].WareHouseNo + '>' + 
                //                     res.data[i].WareHouseName + '</option>');
                //             } 
                //             $("#WarehouseId option[value='W01']").attr("selected", "selected")
                //             form.render('select');
                //         } else { //不成功
                //             layer.msg(res.msg, {
                //                 icon: 2,
                //                 time: 2000 //2秒关闭(如果不配置,默认是3秒)
                //             }, function() {});
                //         }
                //     });
                // }
                //获取客户下拉框信息
                function getCustomerList() {
                    sendData(IP + "/Basis/GetCustomerSelect", {}, 'get', function(res) {
                        if (res.code == 0) { //成功
                            $("#CustomerNo").empty();
                            $("#CustomerNo").append('<option value =""></option>');
                            for (var i = 0; i < res.data.length; i++) {
                                var TypeNum = 0;
                                
                                switch($("#Type").val())
                                {                                    
                                    case "0": //成品出库
                                        TypeNum = 0;
                                        console.log(TypeNum)
                                        break;
                                    case "1": //领料出库
                                    case "2": //抽检出库
                                    case "3": //物料取样出库
                                    case "4": //不合格品出库
                                    case "5": //中间品出库
                                    case "6": //代储出库
                                    case "7": //其他出库
                                    case "8": //寄存出库
                                        TypeNum = 2;
                                        console.log(TypeNum)
                                        break;
                                }
                                //判断单据类型
                                if (TypeNum == 0)
                                {
                                    if (res.data[i].Type == 0)
                                    {
                                        $("#CustomerNamep").html("客户");
                                        $("#CustomerNo").append('<option value =' + res.data[i].CustomerNo + '>' +
                                        res.data[i].CustomerName + '</option>');
                                    }
                                }
                                else if (TypeNum == 1)
                                {
                                    if (res.data[i].Type == 1)
                                    {
                                        $("#CustomerNamep").html("供应商");
                                        $("#CustomerNo").append('<option value =' + res.data[i].CustomerNo + '>' +
                                        res.data[i].CustomerName + '</option>');
                                    }
                                }
                                else if (TypeNum == 2)
                                {
                                    if (res.data[i].Type == 2)
                                    {
                                        $("#CustomerNamep").html("货主");
                                        $("#CustomerNo").append('<option value =' + res.data[i].CustomerNo + '>' +
                                        res.data[i].CustomerName + '</option>');
                                    }
                                }
                            }
                            form.render('select');
                        } else { //不成功
                            layer.msg(res.msg, {
                                icon: 2,
                                time: 2000 //2秒关闭(如果不配置,默认是3秒)
                            }, function() {});
                        }
                    });
                }
                //获取物流承运商下拉框信息
                function getLogisticsInfoList() {
                    sendData(IP + "/Basis/GetLogisticsInfoSelect", {}, 'get', function(res) {
                        if (res.code == 0) { //成功
                            $("#LogisticsId").empty();
                            $("#LogisticsId").append('<option value =""></option>');
                            for (var i = 0; i < res.data.length; i++) {
                                $("#LogisticsId").append('<option value =' + res.data[i].Id + '>' + 
                                    res.data[i].CarrierName + '</option>');
                            } 
                            form.render('select');
                        } else { //不成功
                            layer.msg(res.msg, {
                                icon: 2,
                                time: 2000 //2秒关闭(如果不配置,默认是3秒)
                            }, function() {});
                        }
                    });
                }
            })
        </script>
    </body>
</html>