#
mrzhssss
2022-03-19 c945a29f5be6b38dd5fb0b398abf3ca3e937dd56
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
var pageCurr;
layui.config({
    base: baseUrl + "/static/layui/lay/modules/"
}).use(['table','laydate', 'form', 'util', 'admin', 'tableMerge'], function(){
    var table = layui.table;
    var $ = layui.jquery;
    var layer = layui.layer;
    var layDate = layui.laydate;
    var form = layui.form;
    var admin = layui.admin;
    var tableMerge = layui.tableMerge;
    var util = layui.util;
 
    /****************************************** 左边表 *************************************************/
 
    /* 渲染表格 */
    var insTb = table.render({
        elem: '#docTypeTable',
        url: baseUrl + '/docType/list/auth',
        height: 'full-100',
        headers: {token: localStorage.getItem('token')},
        request: {
            pageName: 'curr',
            pageSize: 'limit'
        },
        where: {
            doc_class: 2,//出库单
        },
        parseData: function (res) {
            return {
                'code': res.code,
                'msg': res.msg,
                'count': res.data.total,
                'data': res.data.records
            }
        },
        response: {
            statusCode: 200
        },
        toolbar: ['<p>',
            '<button lay-event="add" class="layui-btn layui-btn-sm icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>&nbsp;',
            '<button lay-event="edit" class="layui-btn layui-btn-sm layui-btn-warm icon-btn"><i class="layui-icon">&#xe642;</i>修改</button>&nbsp;',
            '<button lay-event="del" class="layui-btn layui-btn-sm layui-btn-danger icon-btn"><i class="layui-icon">&#xe640;</i>删除</button>',
            '</p>'].join(''),
        defaultToolbar: [],
        cols: [[
            {field: 'docId', title: '编号', width: 70, align: 'center'},
            {field: 'docName', title: '单据类型'}
            ,{field: 'docClass', title: '单据类别', hide:true}
        ]],
        done: function (res, curr, count) {
            $('#dictTable+.layui-table-view .layui-table-body tbody>tr:first').trigger('click');
        }
    });
 
    /* 表格搜索 */
    form.on('submit(docTypeTableSearch)', function (data) {
        insTb.reload({where: {doc_name: data.field.docName,doc_class:2}});
        return false;
    });
 
    /* 表格头工具栏点击事件 */
    table.on('toolbar(docTypeTable)', function (obj) {
        if (obj.event === 'add') { // 添加
            showEditModel();
        } else if (obj.event === 'edit') { // 修改
            if (selObj == null) {
                return;
            }
            showEditModel(selObj.data);
        } else if (obj.event === 'del') { // 删除
            if (selObj == null) {
                return;
            }
            doDel(selObj);
        }
    });
 
    /* 监听行单击事件 */
    var selObj;
    table.on('row(docTypeTable)', function (obj) {
        selObj = obj;
        obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
        insTb2.reload({where: {doc_type: obj.data.docId}, page: {curr: 1}});
    });
 
    /* 显示表单弹窗 */
    function showEditModel(mData) {
        admin.open({
            type: 1,
            title: (mData ? '修改' : '添加') + '单据类型',
            content: $('#docTypeEditDialog').html(),
            success: function (layero, dIndex) {
                // 回显表单数据
                form.val('docTypeEditForm', mData);
                if(mData){
                    // $('#docId').addClass("layui-input").attr("disabled",true);
                    $('input[name="docId"]').addClass("layui-input").attr("disabled",true);
                }
                // 表单提交事件
                form.on('submit(docTypeEditSubmit)', function (data) {
                    var loadIndex = layer.load(2);
                    $.ajax({
                        url: baseUrl+"/docType/"+(mData?'update':'add')+"/auth",
                        headers: {'token': localStorage.getItem('token')},
                        data: data.field,
                        method: 'POST',
                        success: function (res) {
                            layer.close(loadIndex);
                            selObj = null;
                            if (res.code === 200){
                                layer.close(dIndex);
                                layer.msg(res.msg, {icon: 1});
                                insTb.reload();
                            } else if (res.code === 403){
                                top.location.href = baseUrl+"/";
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }
                    })
                    return false;
                });
            }
        });
    }
 
    /* 删除 */
    function doDel(obj) {
        layer.confirm('确定要删除此单据类型吗?', {
            skin: 'layui-layer-admin',
            shade: .1
        }, function (i) {
            layer.close(i);
            var loadIndex = layer.load(2);
            $.ajax({
                url: baseUrl+"/docType/delete/one/auth",
                headers: {'token': localStorage.getItem('token')},
                data: {param: JSON.stringify(obj.data)},
                method: 'POST',
                success: function (res) {
                    selObj = null;
                    layer.close(loadIndex);
                    if (res.code === 200){
                        layer.closeAll();
                        insTb.reload();
                        $('#dictTable+.layui-table-view .layui-table-body tbody>tr:first').trigger('click');
                    } else if (res.code === 403){
                        top.location.href = baseUrl+"/";
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }
            })
        });
    }
 
 
    /****************************************** 右边表 *************************************************/
 
    /* 渲染表格2 */
    var insTb2 = table.render({
        elem: '#orderTable',
        headers: {token: localStorage.getItem('token')},
        url: baseUrl+'/order/list/auth',
        page: true,
        // size: 'lg',
        limit: 15,
        limits: [15, 30, 50, 100, 200, 500],
        toolbar: '#orderToolbar',
        height: 'full-100',
        cols: [[
            {type: 'checkbox'}
            // ,{field: 'uuid', align: 'center',title: '编号'}
            ,{field: 'docType$', align: 'center',title: '类别', templet: '#docTypeTpl', width: 100}
            ,{field: 'orderNo', align: 'center',title: '单据编号', minWidth: 200}
            ,{field: 'orderTime', align: 'center',title: '单据日期', width: 120}
            ,{field: 'itemName', align: 'center',title: '项目'}
            ,{field: 'allotItemId$', align: 'center',title: '调拨项目编号', hide: true}
            ,{field: 'defNumber', align: 'center',title: '初始票据号', hide: true}
            ,{field: 'number', align: 'center',title: '票据号', hide: true}
            ,{field: 'cstmrName', align: 'center',title: '客户'}
            ,{field: 'waveNo', align: 'center', title: '波次编号'}
            ,{align: 'center', title: '明细', toolbar: '#tbLook', minWidth: 140, width: 140}
            ,{field: 'tel', align: 'center',title: '联系方式', hide: true}
            ,{field: 'operMemb', align: 'center',title: '操作人员', hide: true}
            ,{field: 'totalFee', align: 'center',title: '合计金额', hide: true}
            ,{field: 'discount', align: 'center',title: '优惠率', hide: true}
            ,{field: 'discountFee', align: 'center',title: '优惠金额', hide: true}
            ,{field: 'otherFee', align: 'center',title: '销售或采购费用合计', hide: true}
            ,{field: 'actFee', align: 'center',title: '实付金额', hide: true}
            ,{field: 'payType$', align: 'center',title: '付款类型', hide: true}
            ,{field: 'salesman', align: 'center',title: '业务员', hide: true}
            ,{field: 'accountDay', align: 'center',title: '结算天数', hide: true}
            ,{field: 'postFeeType$', align: 'center',title: '邮费支付类型', hide: true}
            ,{field: 'postFee', align: 'center',title: '邮费', hide: true}
            ,{field: 'payTime$', align: 'center',title: '付款时间', hide: true}
            ,{field: 'sendTime$', align: 'center',title: '发货时间', hide: true}
            ,{field: 'shipName', align: 'center',title: '物流名称', hide: true}
            ,{field: 'shipCode', align: 'center',title: '物流单号', hide: true}
            ,{field: 'settle$', align: 'center',title: '订单状态', templet: '#settleTpl', width: 105}
            ,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate',  width: 120}
        ]],
        request: {
            pageName: 'curr',
            pageSize: 'limit'
        },
        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 (res.code === 403) {
                top.location.href = baseUrl+"/";
            }
            pageCurr=curr;
            limit();
        }
    });
    /* 表格2搜索 */
    form.on('submit(orderTbSearch)', function (data) {
        insTb2.reload({where: data.field, page: {curr: 1}});
        return false;
    });
    /* 表格2重置 */
    form.on('submit(orderTbReset)', function (data) {
        insTb2.reload({where: null,page: {curr: 1}});
        return false;
    });
 
    /* 表格2头工具栏点击事件 */
    table.on('toolbar(orderTable)', function (obj) {
        if (obj.event === 'add') { // 添加
            right();
        } else if (obj.event === 'del') { // 删除
            var checkRows = table.checkStatus('orderTable');
            if (checkRows.data.length === 0) {
                layer.msg('请选择要删除的数据', {icon: 2});
                return;
            }
            var ids = checkRows.data.map(function (d) {
                return d.id;
            });
            doDelOrder({ids: ids});
        }else if (obj.event === 'wave'){
            var checkRows = table.checkStatus('orderTable');
            if (checkRows.data.length === 0) {
                layer.msg('请选择要生成波次的数据', {icon: 2});
                return;
            }
            doWaveOrder(checkRows);
        }
    });
 
    /* 表格2工具条点击事件 */
    table.on('tool(orderTable)', function (obj) {
        var data = obj.data;
        switch (obj.event) {
            // 拣货
            case 'stockOut':
                var loadIndex = layer.load(2);
                $.ajax({
                    url: baseUrl + "/work/stock/out/preview",
                    headers: {'token': localStorage.getItem('token')},
                    contentType: 'application/json;charset=UTF-8',
                    data: JSON.stringify({
                        orderNo: data.orderNo
                    }),
                    method: 'POST',
                    success: function (res) {
                        layer.close(loadIndex);
                        if (res.code === 200){
                            layer.open({
                                type: 1
                                ,title: false
                                ,closeBtn: false
                                ,offset: '100px'
                                ,area: '1000px'
                                ,shade: 0.5
                                ,shadeClose: true
                                ,btn: ['立即生成', '稍后处理']
                                ,btnAlign: 'c'
                                ,moveType: 1 //拖拽模式,0或者1
                                ,content: $('#stoukOutPreview')
                                ,success: function(layero, index){
                                    table.render({
                                        elem: '#stoPreTab',
                                        data: res.data,
                                        page: true,
                                        cellMinWidth: 100,
                                        height: 432,
                                        cols: [[
                                            {field: 'title', title: '商品', merge: true, align: 'center'},
                                            {field: 'anfme', title: '总数量', merge: ['title'], align: 'center', style: 'font-weight: bold', width: 90},
                                            {field: 'type', title: '仓库', merge: true, align: 'center', templet: '#typeTpl', width: 90},
                                            {field: 'locNo', title: '货位', align: 'center'},
                                            {field: 'prior$', title: '推荐货位', align: 'center', width: 100},
                                            {field: 'reduce', title: '数量', align: 'center', width: 90, style: 'font-weight: bold'},
                                            // {field: 'remQty', title: '余量', align: 'center', width: 80},
                                            {field: 'total', title: '总量', align: 'center', width: 90},
                                        ]],
                                        done: function () {
                                            tableMerge.render(this);
                                            $('.layui-table-body.layui-table-main').css("overflow", "auto")
                                        }
                                    });
 
                                }
                                ,yes: function(index, layero){
                                    //按钮【马上拣货】的回调
                                    stockOut(data.orderNo);
                                }
                                ,btn2: function(index, layero){
                                    //按钮【稍后处理】的回调
                                    //return false 开启该代码可禁止点击该按钮关闭
                                }
                            });
                        } else if (res.code === 403){
                            top.location.href = baseUrl+"/";
                        } else {
                            layer.msg(res.msg, {icon: 2})
                        }
                    }
                })
                break;
            // 打印
            case 'print':
                layer.confirm('开始打印' +data.orderNo + ' 拣货单?', {shadeClose: true}, function(){
                    layer.closeAll();
                    printPakouts(data.orderNo);
                })
                break;
            // 删除
            case 'del':
                var ids = [obj.id];
                doDelOrder({ids: ids});
                break;
            // 明细
            case 'look':
                var $a = $(obj.tr).find('a[lay-event="look"]');
                var offset = $a.offset();
                layer.open({
                    type: 1,
                    title: false,
                    area: '700px',
                    offset: [offset.top + 'px', (offset.left - 530 + $a.outerWidth()) + 'px'],
                    shade: .01,
                    shadeClose: true,
                    fixed: false,
                    content: '<table id="lookSSXMTable" lay-filter="lookSSXMTable"></table>',
                    success: function (layero) {
                        table.render({
                            elem: '#lookSSXMTable',
                            headers: {token: localStorage.getItem('token')},
                            url: baseUrl+'/orderDetl/list/auth',
                            where: {
                                order_id: data.id
                            },
                            limit: 5,
                            page: true,
                            cellMinWidth: 100,
                            cols: [[
                                {type: 'numbers'},
                                {field: 'matnr', title: '商品编码'},
                                {field: 'maktx', title: '商品名称', width: 200},
                                {field: 'anfme', title: '数量', width: 70},
                                {
                                    field: 'createTime$', title: '创建时间', sort: true, templet: function (d) {
                                        return util.toDateString(d.createTime);
                                    },  width: 180
                                }
                            ]],
                            request: {
                                pageName: 'curr',
                                pageSize: 'limit'
                            },
                            parseData: function (res) {
                                return {
                                    'code': res.code,
                                    'msg': res.msg,
                                    'count': res.data.total,
                                    'data': res.data.records
                                }
                            },
                            response: {
                                statusCode: 200
                            },
                            done: function () {
                                $(layero).find('.layui-table-view').css('margin', '0');
                            },
                            size: ''
                        });
                    }
                });
                break;
 
        }
    });
 
    /* 删除订单 */
    function doDelOrder(obj) {
        layer.confirm('确定要删除选中数据吗?', {
            skin: 'layui-layer-admin',
            shade: .1
        }, function (i) {
            layer.close(i);
            var loadIndex = layer.load(2);
            $.ajax({
                url: baseUrl+"/orders/delete/auth",
                headers: {'token': localStorage.getItem('token')},
                data: {ids: obj.ids},
                method: 'POST',
                success: function (res) {
                    layer.close(loadIndex);
                    if (res.code === 200){
                        layer.msg(res.msg, {icon: 1});
                        $(".layui-laypage-btn")[0].click();
                    } else if (res.code === 403){
                        top.location.href = baseUrl+"/";
                    }else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }
            })
 
        });
    }
    /* 生成波次 */
    function doWaveOrder(obj) {
        console.log(obj.data);
        layer.confirm('确定要生成波次?', {
            skin: 'layui-layer-admin',
            shade: .1
        }, function (i) {
            layer.close(i);
            var loadIndex = layer.load(2);
            $.ajax({
                url: baseUrl+"/orders/wave/auth",
                headers: {'token': localStorage.getItem('token')},
                data: JSON.stringify(obj.data),
                contentType: 'application/json;charset=UTF-8',
                method: 'POST',
                success: function (res) {
                    layer.close(loadIndex);
                    if (res.code === 200){
                        layer.msg(res.msg, {icon: 1});
                        $(".layui-laypage-btn")[0].click();
                    } else if (res.code === 403){
                        top.location.href = baseUrl+"/";
                    }else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }
            })
 
        });
    }
 
    // 生成拣货单
    function stockOut(orderNo) {
        $.ajax({
            url: baseUrl+"/work/stock/out/create",
            headers: {'token': localStorage.getItem('token')},
            contentType:'application/json;charset=UTF-8',
            data: JSON.stringify({
                orderNo: orderNo
            }),
            method: 'POST',
            success: function (res) {
                // 成功
                if (res.code === 200){
                    layer.closeAll();
                    $(".layui-laypage-btn")[0].click();
                    layer.confirm(res.msg, {
                            shadeClose: true
                            , btn: ['打印拣货单']
                        }, function() {
                            layer.closeAll();
                            printPakouts(orderNo);
                        }
                    )
                } else if (res.code === 403){
                    top.location.href = baseUrl+"/";
                } else {
                    layer.msg(res.msg, {icon: 2})
                }
            }
        })
        // });
    }
 
    // 打印拣货单
    function printPakouts(orderNo) {
        $.ajax({
            url: baseUrl+"/work/stock/out/print",
            headers: {'token': localStorage.getItem('token')},
            data: JSON.stringify({
                orderNo: orderNo
            }),
            contentType:'application/json;charset=UTF-8',
            method: 'POST',
            success: function (res) {
                if (res.code === 200){
                    res.data["barcodeUrl"]=baseUrl+"/order/code/auth?type=1&param="+res.data.docNum;
                    var tpl = $('#pakoutPrintTpl').html();
                    var template = Handlebars.compile(tpl);
                    var html = template(res);
                    var box = $("#pakoutPrintBox");
                    box.html(html);box.show();
                    box.print({
                        mediaPrint:true,
                        deferred: $.Deferred().done(function () {
                            layer.confirm('[重要] 打印是否成功?',  {btn: ['Yes', 'No']}, function(){
                                $.ajax({
                                    url: baseUrl+"/pakout/print/auth",
                                    headers: {'token': localStorage.getItem('token')},
                                    data: {
                                        docNumber: orderNo
                                    },
                                    method: 'POST',
                                    success: function (res) {
                                        if (res.code === 200){
                                            layer.closeAll();
                                            $(".layui-laypage-btn")[0].click();
                                            layer.msg(res.msg, {icon: 1})
                                        } else if (res.code === 403){
                                            top.location.href = baseUrl+"/";
                                        } else {
                                            layer.msg(res.msg, {icon: 2})
                                        }
                                    }
                                })
                            });
                        })
                    });
                    box.hide();
                } else if (res.code === 403){
                    top.location.href = baseUrl+"/";
                } else {
                    layer.msg(res.msg, {icon: 2})
                }
            }
        })
    }
 
});
 
function right(){
    top.popupRight = top.layui.admin.popupRight({
        id: 'LAY_adminPopupLayerTest'
        , area: '890px'
        , type: 2
        , shade: [0.5,'#000']
        , content:'order/matQuery.html'
        , success: function(){
            // $('#'+ this.id).html('<div style="padding: 20px;">放入内容</div>');
            //admin.view(this.id).render('system/xxx')
        }
        , end: function () {
            $(".layui-laypage-btn")[0].click();
        }
    });
}
 
function tableReload(child) {
    var searchData = {};
    $.each($('#search-box [name]').serializeArray(), function() {
        searchData[this.name] = this.value;
    });
    (child ? parent.tableIns : tableIns).reload({
        where: searchData,
        page: {
            curr: pageCurr
        }
    });
}