自动化立体仓库 - WMS系统
chen.lin
7 天以前 3c824a50b4894545ecf6ea57b5889444fe77c11c
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
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
<!DOCTYPE html>
<html lang="en">
 
<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, maximum-scale=1">
    <link rel="stylesheet" href="../../static/evn/index.css">
    <style>
        .text-center {
            text-align: center;
        }
        .text-gray-500 {
            width: 100%;
            color: #6b7280;
        }
    </style>
</head>
 
<body>
    <div id="app">
        <el-card>
        <el-form :inline="true" label-width="auto">
            <el-form-item label="开工日期">
 
                    <div>
                        <el-date-picker
                                v-model="tableSearchParam.dateStart"
                                type="date"
                                placeholder="开始日期"
                                style="width: 150px;"
                                :default-time="defaultTime"
                        />
                    </div>
                    <div style="margin-left: 5px;margin-right: 5px">
                        <span >-</span>
                    </div>
                    <div>
                        <el-date-picker
                                v-model="tableSearchParam.dateEnd"
                                type="date"
                                placeholder="结束日期"
                                style="width: 150px;"
                                :default-time="defaultTime"
                        />
                    </div>
            </el-form-item>
 
 
            <el-form-item label="供应商">
                <el-select v-model="tableSearchParam.venId" placeholder="选择供应商" style="width: 150px" >
                    <el-option
                            v-for="item in options"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                    />
                </el-select>
            </el-form-item>
            <el-form-item label="">
                <el-button type="primary" @click="page" circle >
                    <el-icon><Search /></el-icon>
                </el-button>
            </el-form-item>
        </el-form>
        <el-form :inline="true">
            <el-form-item label="">
               <el-button type="primary"  @click="fnPrintView('否')">打印预览</el-button>
            </el-form-item>
            <el-form-item label="">
               <el-button type="primary" @click="fnPrint('是')">打印</el-button>
            </el-form-item>
            <el-form-item label="">
                <el-button type="primary" @click="fnTongBu()">生成委外出库单</el-button>
            </el-form-item>
            <el-form-item label="">
               <el-button type="primary" @click="fnCanelTongBu()">撤销生成</el-button>
            </el-form-item>
            <el-form-item label="">
                <el-button type="primary" @click="dialogVisible = true">数据查询</el-button>
            </el-form-item>
            <el-form-item label="">
               <el-button type="success" @click="manualSync()">手动同步</el-button>
            </el-form-item>
        </el-form>
        <el-table :data="tableData" border style="width: 100%" row-key="id" @selection-change="handleSelectionChange" max-height="650">
            <el-table-column type="selection" >
            </el-table-column>
            <el-table-column type="index" width="50" >
            </el-table-column>
            <el-table-column prop="venName" label="供应商" >
            </el-table-column>
            <el-table-column prop="invCode" label="物料编码">
            </el-table-column>
            <el-table-column prop="invName" label="物料名称" width="250" :show-overflow-tooltip="true">
            </el-table-column>
            <el-table-column prop="invStd" label="规格" width="150" :show-overflow-tooltip="true">
            </el-table-column>
            <el-table-column prop="unit" label="单位" width="70">
            </el-table-column>
            <el-table-column prop="whName" label="仓库" width="90">
            </el-table-column>
            <el-table-column prop="qqty" label="期初数量">
            </el-table-column>
            <el-table-column prop="fqty" label="应发数量">
            </el-table-column>
            <el-table-column prop="yqty" label="已发数量">
            </el-table-column>
            <el-table-column prop="wqty" label="未发数量">
            </el-table-column>
            <el-table-column prop="qty" label="实发数量">
                <template #default="scope">
                    <el-input v-model="scope.row.qty"></el-input>
                </template>
            </el-table-column>
            <el-table-column prop="izSync" label="是否生成">
            </el-table-column>
        </el-table>
 
            <el-dialog v-model="dialogVisible" fullscreen>
                <el-form :inline="true" label-width="auto">
                    <el-form-item label="开工日期">
 
                        <div>
                            <el-date-picker
                                    v-model="tableSearchParamDialog.dateStart"
                                    type="date"
                                    placeholder="开始日期"
                                    style="width: 150px;"
                                    :default-time="defaultTime"
                            />
                        </div>
                        <div style="margin-left: 5px;margin-right: 5px">
                            <span >-</span>
                        </div>
                        <div>
                            <el-date-picker
                                    v-model="tableSearchParamDialog.dateEnd"
                                    type="date"
                                    placeholder="结束日期"
                                    style="width: 150px;"
                                    :default-time="defaultTime"
                            />
                        </div>
                    </el-form-item>
                    <el-form-item label="是否生成">
                        <el-select v-model="tableSearchParamDialog.isSync" placeholder="是否生成" style="width: 150px" >
                            <el-option
                                    v-for="item in printOptions"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                            />
                        </el-select>
                    </el-form-item>
                    <el-form-item label="">
                        <el-button type="primary" @click="dialogPage" circle >
                            <el-icon><Search /></el-icon>
                        </el-button>
                    </el-form-item>
                </el-form>
                <el-table :data="tableDataDialog" border style="width: 100%" row-key="id" @selection-change="handleSelectionChangeDialog" max-height="650">
                    <el-table-column type="selection" >
                    </el-table-column>
                    <el-table-column type="index" width="50" >
                    </el-table-column>
                    <el-table-column prop="dateStart" label="开工日期" >
                    </el-table-column>
                    <el-table-column prop="dateEnd" label="完成日期">
                    </el-table-column>
                    <el-table-column prop="izPrint" label="是否打印">
                    </el-table-column>
                    <el-table-column prop="izSync" label="是否生成">
                    </el-table-column>
                </el-table>
                <template #footer>
                    <div class="dialog-footer" style="text-align: left;">
                        <el-button @click="dialogVisible = false">关闭</el-button>
                    </div>
                </template>
            </el-dialog>
        </el-card>
    </div>
    
    <script type="text/javascript" src="../../static/js/jquery/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="../../static/js/common.js" charset="utf-8"></script>
    <script src="../../static/evn/vue.global.js"></script>
    <script src="../../static/evn/element-plus.js"></script>
    <script src="../../static/evn/icons-vue.js"></script>
    <script src='../../static/js/erp/LodopFuncs.js'></script>
    <script type="module">
        // 导入中文语言包
        import zhCn from '../../static/js/erp/zh-cn.js';
        
        const { createApp, ref, onMounted, onBeforeMount ,watchEffect} = Vue;
       
 
        const app = createApp({
            setup() {
                const currentPage = ref(1)
                const pageSizes = ref([15,20, 30, 50, 100, 200])
                const pageSize = ref(15)
                const pageTotal = ref(0)
                const tableSearchParam = ref({
                    izJb:"否",
                    dateStart:new Date(),
                    dateEnd: new Date(),
                    venId:null,
                    izJs:"否"
                })
                const tableSearchParamDialog = ref({
                    dateStart:new Date(),
                    dateEnd: new Date(),
                    izSync: null
                })
                const tableData = ref([])
                const tableDataDialog = ref([])
                const defaultTime = ref(new Date())
                const fullscreenLoading = ref(false)
 
                const selectData = ref([
                ])
 
                const depName = ref('')
 
                const options = ref([])
 
                const dialogVisible = ref(false)
 
                watchEffect(() =>{
                     options.value.map(item =>{
                        if (item.value === tableSearchParam.value.venId){
                            depName.value = item.label
                        }
                    })
 
                })
 
                const printOptions = [
                    {
                        value: '否',
                        label: '否'
                    },
                    {
                        value: '是',
                        label: '是'
                    },
 
                ]
 
                const selectList = ref([])
                
                function page(){
                    let data = JSON.parse(JSON.stringify(tableSearchParam.value))
                    data.curr = currentPage.value
                    data.limit = pageSize.value
                    if (tableSearchParam.value.datetime != null) {
                        data.datetime = null
                        data.create_time = tableSearchParam.value.datetime[0] + " - " + tableSearchParam.value.datetime[1]
                    }
                    const loading = ElementPlus.ElLoading.service({
                        lock: true,
                        text: 'Loading',
                        background: 'rgba(0, 0, 0, 0.7)',
                    })
                    $.ajax({
                        url: "http://127.0.0.1:8133/mo/materialwwout/getList",
                        headers: {
                            'token': localStorage.getItem('token')
                        },
                        data: data,
                        dataType: 'json',
                        contentType: 'application/json;charset=UTF-8',
                        method: 'GET',
                        success: function(res) {
                            loading.close()
                            if (res.code == 200) {
                                tableData.value = res.data
                                ElementPlus.ElMessage({
                                    message: "拉取数据完成",
                                    type: 'success'
                                });
                            } else if (res.code === 403) {
                                top.location.href = baseUrl + "/";
                            } else {
                                ElementPlus.ElMessage({
                                    message: res.msg,
                                    type: 'error'
                                });
                            }
                        }
                    });
                }
 
                function dialogPage(){
                    let data = JSON.parse(JSON.stringify(tableSearchParamDialog.value))
                    data.curr = currentPage.value
                    data.limit = pageSize.value
                    const loading = ElementPlus.ElLoading.service({
                        lock: true,
                        text: 'Loading',
                        background: 'rgba(0, 0, 0, 0.7)',
                    })
                    $.ajax({
                        url: "http://127.0.0.1:8133/mo/materialwwout/getListView",
                        headers: {
                            'token': localStorage.getItem('token')
                        },
                        data: data,
                        dataType: 'json',
                        contentType: 'application/json;charset=UTF-8',
                        method: 'GET',
                        success: function(res) {
                            loading.close()
                            if (res.code == 200) {
                                tableDataDialog.value = res.data
                                ElementPlus.ElMessage({
                                    message: "拉取数据完成",
                                    type: 'success'
                                });
                            } else if (res.code === 403) {
                                top.location.href = baseUrl + "/";
                            } else {
                                ElementPlus.ElMessage({
                                    message: res.msg,
                                    type: 'error'
                                });
                            }
                        }
                    });
                }
 
                function fnTongBu(){
                    if (selectList.value.length === 0){
                        ElementPlus.ElMessage({
                            message: "请先选择",
                            type: 'error'
                        });
                        return ;
                    }
                    for(let i=0; i<selectList.value.length; i++) {
                        var rowData = selectList.value[i];
                        if(rowData.qty === "" || rowData.qty === null || rowData.qty.replace(" ","") === "")
                        {
                            ElementPlus.ElMessage({
                                message: "请确认数量存在!",
                                type: 'error'
                            });
                            return ;
                        }
                    }
                    const loading = ElementPlus.ElLoading.service({
                        lock: true,
                        text: 'Loading',
                        background: 'rgba(0, 0, 0, 0.7)',
                    })
                    $.ajax({
                        url:"http://127.0.0.1:8133/mo/materialwwout/tongbu",
                        headers: {
                            'token': localStorage.getItem('token')
                        },
                        data: JSON.stringify(selectList.value),
                        dataType: 'json',
                        contentType: 'application/json;charset=UTF-8',
                        method: 'POST',
                        success: function(res) {
                            loading.close();
                            if (res.code == 200) {
                                ElementPlus.ElMessage({
                                    message: "生成成功",
                                    type: 'success'
                                });
                                page()
                            } else if (res.code === 403) {
                                top.location.href = baseUrl + "/";
                            } else {
                                ElementPlus.ElMessage({
                                    message: res.msg,
                                    type: 'error'
                                });
                            }
                        }
                    });
                }
 
                function fnCanelTongBu(){
                    if (selectList.value.length === 0){
                        ElementPlus.ElMessage({
                            message: "请先选择",
                            type: 'error'
                        });
                        return ;
                    }
                    const loading = ElementPlus.ElLoading.service({
                        lock: true,
                        text: 'Loading',
                        background: 'rgba(0, 0, 0, 0.7)',
                    })
                    $.ajax({
                        url:"http://127.0.0.1:8133/mo/materialwwout/caneltongbu",
                        headers: {
                            'token': localStorage.getItem('token')
                        },
                        data: JSON.stringify(selectList.value),
                        dataType: 'json',
                        contentType: 'application/json;charset=UTF-8',
                        method: 'POST',
                        success: function(res) {
                            loading.close();
                            if (res.code == 200) {
                                ElementPlus.ElMessage({
                                    message: "撤销成功",
                                    type: 'success'
                                });
                                page()
                            } else if (res.code === 403) {
                                top.location.href = baseUrl + "/";
                            } else {
                                ElementPlus.ElMessage({
                                    message: res.msg,
                                    type: 'error'
                                });
                            }
                        }
                    });
                }
 
                function fnCanelPrint(){
                    if (selectList.value.length === 0){
                        ElementPlus.ElMessage({
                            message: "请先选择",
                            type: 'error'
                        });
                        return ;
                    }
                    const loading = ElementPlus.ElLoading.service({
                        lock: true,
                        text: 'Loading',
                        background: 'rgba(0, 0, 0, 0.7)',
                    })
                    $.ajax({
                        url:"http://127.0.0.1:8133/mo/materialuse/canelprint",
                        headers: {
                            'token': localStorage.getItem('token')
                        },
                        data: JSON.stringify(selectList.value),
                        dataType: 'json',
                        contentType: 'application/json;charset=UTF-8',
                        method: 'POST',
                        success: function(res) {
                            loading.close();
                            if (res.code == 200) {
                                ElementPlus.ElMessage({
                                    message: "撤销成功",
                                    type: 'success'
                                });
                                page()
                            } else if (res.code === 403) {
                                top.location.href = baseUrl + "/";
                            } else {
                                ElementPlus.ElMessage({
                                    message: res.msg,
                                    type: 'error'
                                });
                            }
                        }
                    });
                }
 
 
 
                function getVendor(){
                    $.ajax({
                        url: "http://127.0.0.1:8133/basicinfo/vendor/getlistfordropdown",
                        contentType: 'application/json;charset=UTF-8',
                        method: 'GET',
                        success: function(res) {
                            if (res.code == 200) {
                                res.data.map(item => {
                                    options.value.push({
                                        value: item.venId, label: item.venName
                                    })
                                })
                            } else {
                                ElementPlus.ElMessage({
                                    message: res.msg,
                                    type: 'error'
                                });
                            }
                        }
                    });
                }
                function fnPrint(izPrint) {
                    if (selectList.value.length === 0){
                        ElementPlus.ElMessage({
                            message: "请先选择",
                            type: 'error'
                        });
                        return ;
                    }
                    // 打印前确认
                    if (izPrint === '是') {
                        ElementPlus.ElMessageBox.confirm('确定打印吗?')
                            .then(() => {
                                print(izPrint, 0);
                            })
                            .catch(() => {
                                // 取消
                            });
                    } else {
                        print(izPrint, 0);
                    }
                }
 
                function fnPrintView(izPrint){
                    if (selectList.value.length === 0){
                        ElementPlus.ElMessage({
                            message: "请先选择",
                            type: 'error'
                        });
                        return ;
                    }
                    // 打印预览直接调用打印接口(后端不校验出库完成状态)
                    print(izPrint, 0);
                }
                
                // 手动同步
                function manualSync() {
                    if (selectList.value.length === 0){
                        ElementPlus.ElMessage({
                            message: "请先选择要同步的数据",
                            type: 'error'
                        });
                        return ;
                    }
                    
                    ElementPlus.ElMessageBox.confirm('确定要同步选中的数据到WMS吗?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        const loading = ElementPlus.ElLoading.service({
                            lock: true,
                            text: '同步中...',
                            background: 'rgba(0, 0, 0, 0.7)',
                        });
                        
                        // 优先使用选中的数据列表进行同步
                        $.ajax({
                            url: "http://127.0.0.1:8133/api/materialWwOut/sync/manual",
                            headers: {
                                'token': localStorage.getItem('token')
                            },
                            data: JSON.stringify({
                                wwRecords: JSON.stringify(selectList.value)
                            }),
                            contentType: 'application/json;charset=UTF-8',
                            method: 'POST',
                            success: function(res) {
                                loading.close();
                                if (res.code == 200) {
                                    ElementPlus.ElMessage({
                                        message: res.data.message || "同步任务已提交",
                                        type: 'success'
                                    });
                                    // 刷新列表
                                    setTimeout(() => {
                                        page();
                                    }, 2000);
                                } else {
                                    ElementPlus.ElMessage({
                                        message: res.msg || "同步失败",
                                        type: 'error'
                                    });
                                }
                            },
                            error: function() {
                                loading.close();
                                ElementPlus.ElMessage({
                                    message: "同步请求失败",
                                    type: 'error'
                                });
                            }
                        });
                    }).catch(() => {
                        // 取消
                    });
                }
 
 
 
                function print(izPrint,izRed){
                    const LODOP = getLodop()
                    const loading = ElementPlus.ElLoading.service({
                        lock: true,
                        text: 'Loading',
                        background: 'rgba(0, 0, 0, 0.7)',
                    })
                    $.ajax({
                        url:"http://127.0.0.1:8133/mo/materialwwout/print",
                        headers: {
                            'token': localStorage.getItem('token')
                        },
                        data: JSON.stringify({
                            wwRecords : JSON.stringify(selectList.value),
                            izPrint : izPrint,
                            izRed : izRed
                        }),
                        dataType: 'json',
                        contentType: 'application/json;charset=UTF-8',
                        method: 'POST',
                        success: function(res) {
                            loading.close()
                            if (res.code == 200) {
                                ElementPlus.ElMessage({
                                    message: "获取数据完成,等待唤起打印",
                                    type: 'success'
                                });
                                page()
                                LODOP.PRINT_INITA(0,0,800,1100,"委外加工出库单");
                                LODOP.SET_PRINT_PAGESIZE(1,0,0,"A4");
                                LODOP.SET_PRINT_MODE("PRINT_NOCOLLATE",1);
                                
                                // 收集二维码供应商:从选中的记录中收集所有供应商,去重后用|连接
                                var venNameSet = new Set();
                                if (selectList.value && selectList.value.length > 0) {
                                    selectList.value.forEach(function(item) {
                                        if (item.venName && item.venName.trim()) {
                                            venNameSet.add(item.venName.trim());
                                        }
                                    });
                                }
                                var venNameStr = Array.from(venNameSet).join('|');
                                
                                // 定义添加二维码的函数
                                function addQrCodeToPrint() {
                                    // 在右上角添加二维码(如果有供应商)
                                    if (venNameStr) {
                                        // 固定二维码尺寸,保持正方形比例,避免挤占打印文本和被拉长
                                        var qrCodeWidth = 130; // 固定宽度130px
                                        var qrCodeHeight = 130; // 固定高度130px,保持正方形比例
                                        var qrCodeUrl = baseUrl + "/file/barcode/qrcode/auth?type=2&param=" + encodeURIComponent(venNameStr) + "&width=" + qrCodeWidth + "&height=" + qrCodeHeight;
                                        
                                        // 创建一个临时img元素加载图片,然后转换为base64
                                        var img = new Image();
                                        img.crossOrigin = 'anonymous';
                                        img.onload = function() {
                                            try {
                                                // 创建canvas将图片转换为base64
                                                var canvas = document.createElement('canvas');
                                                canvas.width = img.width;
                                                canvas.height = img.height;
                                                var ctx = canvas.getContext('2d');
                                                ctx.drawImage(img, 0, 0);
                                                var base64Image = canvas.toDataURL('image/png');
                                                
                                                // LODOP添加图片,使用base64格式
                                                // ADD_PRINT_IMAGE参数:Top, Left, Width, Height, ImageURL或ImageData
                                                // 二维码位置:右上角,Top: 20, Left: 650 (页面宽度800,右边留50像素边距)
                                                var displayWidth = qrCodeWidth; // 固定宽度130px
                                                var displayHeight = qrCodeHeight; // 固定高度130px,保持正方形
                                                var displayLeft = 800 - displayWidth - 20; // 右对齐,留20px边距
                                                try {
                                                    LODOP.ADD_PRINT_IMAGE(20, displayLeft, displayWidth, displayHeight, base64Image);
                                                } catch(e) {
                                                    // 如果ADD_PRINT_IMAGE失败,使用HTML方式
                                                    var htmlContent = '<img src="' + base64Image + '" style="width:' + displayWidth + 'px;height:' + displayHeight + 'px;" />';
                                                    LODOP.ADD_PRINT_HTM(20, displayLeft, displayWidth, displayHeight, htmlContent);
                                                }
                                                
                                                // 图片加载完成后,执行打印
                                                executePrint();
                                            } catch(e) {
                                                console.error("转换图片失败:", e);
                                                // 如果转换失败,只显示文本(供应商名称)
                                                var displayWidth = qrCodeWidth;
                                                var displayHeight = qrCodeHeight;
                                                var displayLeft = 800 - displayWidth - 20;
                                                LODOP.ADD_PRINT_TEXT(20, displayLeft, displayWidth, displayHeight, venNameStr);
                                                LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
                                                LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
                                                executePrint();
                                            }
                                        };
                                        img.onerror = function() {
                                            console.error("加载二维码图片失败");
                                            // 如果加载失败,只显示文本(供应商名称)
                                            var displayWidth = qrCodeWidth;
                                            var displayHeight = qrCodeHeight;
                                            var displayLeft = 800 - displayWidth - 20;
                                            LODOP.ADD_PRINT_TEXT(20, displayLeft, displayWidth, displayHeight, venNameStr);
                                            LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
                                            LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
                                            executePrint();
                                        };
                                        img.src = qrCodeUrl;
                                    } else {
                                        // 没有供应商,直接执行打印
                                        executePrint();
                                    }
                                }
                                
                                // 定义执行打印的函数
                                function executePrint() {
                                    // 计算表格的起始位置:如果有二维码,表格需要向下移动
                                    var tableTop = 96; // 默认表格起始位置
                                    var qrCodeTop = 20; // 二维码顶部位置
                                    var qrCodeHeight = 130; // 二维码高度
                                    var qrCodeBottom = qrCodeTop + qrCodeHeight; // 二维码底部位置:150
                                    var spacing = 10; // 二维码和表格之间的间距
                                    
                                    // 如果有二维码,且表格原始位置会被二维码覆盖,则向下移动表格
                                    if (venNameStr && tableTop < qrCodeBottom) {
                                        tableTop = qrCodeBottom + spacing; // 表格从二维码下方开始,留10px间距
                                    }
                                    
                                    if(izRed==1)
                                    {
                                        LODOP.ADD_PRINT_TEXT(28,268,331,36,"委外加工出库单(红字)");
                                    }
                                    else{
                                        LODOP.ADD_PRINT_TEXT(28,268,331,36,"委外加工出库单");
                                    }
                                    LODOP.SET_PRINT_STYLEA(0,"FontSize",20);
                                    LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
                                    LODOP.ADD_PRINT_TEXT(69,21,213,25,"供应商:"+depName.value);
                                    LODOP.SET_PRINT_STYLEA(0,"FontSize",12);
                                    LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
                                    LODOP.ADD_PRINT_TEXT(70,268,213,25,"开工日期:"+dateFormat("YYYY-mm-dd", tableSearchParam.value.dateStart)+" 到 "+dateFormat("YYYY-mm-dd", tableSearchParam.value.dateEnd));
                                    LODOP.SET_PRINT_STYLEA(0,"FontSize",12);
                                    LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
                                    LODOP.ADD_PRINT_TABLE(tableTop,16,2000,960,CreateTable(res.data));
                                    LODOP.SET_PRINT_STYLEA(0,"TableHeightScope",1);
                                    LODOP.SET_PRINT_MODE("FULL_WIDTH_FOR_OVERFLOW",true);
                                    // 根据izPrint参数决定是打印还是预览
                                    // izPrint=="是":直接打印,弹出打印对话框(不弹出预览窗口)
                                    // izPrint=="否":打印预览,弹出预览窗口
                                    if(izPrint=="是")
                                    {
                                        LODOP.PRINT();
                                    }
                                    else{
                                        // 打印预览,弹出预览窗口
                                        LODOP.PREVIEW();
                                    }
                                }
                                
                                // 先添加二维码,然后执行打印
                                addQrCodeToPrint();
                            } else if (res.code === 403) {
                                top.location.href = baseUrl + "/";
                            } else {
                                // 后端返回错误信息(校验失败)
                                ElementPlus.ElMessageBox.alert(res.msg || "打印失败", '错误', {
                                    confirmButtonText: '确定',
                                    type: 'error'
                                });
                            }
                        },
                        error: function(xhr, status, error) {
                            loading.close()
                            ElementPlus.ElMessage({
                                message: "打印请求失败,请稍后重试",
                                type: 'error'
                            });
                        }
                    });
                }
 
                function dateFormat(fmt, date) {
                    let ret;
                    const opt = {
                        "Y+": date.getFullYear().toString(),        // 年
                        "m+": (date.getMonth() + 1).toString(),     // 月
                        "d+": date.getDate().toString(),            // 日
                        "H+": date.getHours().toString(),           // 时
                        "M+": date.getMinutes().toString(),         // 分
                        "S+": date.getSeconds().toString()          // 秒
                        // 有其他格式化字符需求可以继续添加,必须转化成字符串
                    };
                    for (let k in opt) {
                        ret = new RegExp("(" + k + ")").exec(fmt);
                        if (ret) {
                            fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
                        };
                    };
                    return fmt;
                }
 
                function  CreateTable(result) {
                    var css = "<style> table,td,th {table-layout: fixed;border: 1px black solid;border-collapse: collapse;font-size: 13px;}</style><table>";
                    //第一行
                    var th = "<thead><tr style='height:20px'>" +
                        "<th  >序号</th>" +
                        "<th  >供应商</th>" +
                        "<th  >物料编码</th>" +
                        "<th  >物料名称</th>" +
                        "<th >规格</th>" +
                        "<th  >单位</th>" +
                        "<th  >仓库</th>" +
                        "<th  >应发数量</th>" +
                        "<th  >实发数量</th>" +
                        "</tr></thead>";
 
                    var td="";
                    var row=1;
                    for (var i = 0; i <result.length; i++) {
                        td = td+"<tr style='height:20px'><td style='width:30px;' align='center' >"+(row)+"</td><td style='width:170px;word-wrap:break-word;word-break:break-all;'  align='left'  >" + (result[i].venName || '') + "</td><td style='width:80px;'  align='left'  >" + (result[i].invCode || '') + "</td><td style='width:250px;word-wrap:break-word;word-break:break-all;'  align='left'  >" + (result[i].invName || '') + "</td>  <td style='width:50px;'  align='left'  >" + (result[i].invStd || '') + "</td> <td style='width:35px;'  align='left'  >" + (result[i].unit || '') + "</td><td style='width:80px;'  align='left'  >" + (result[i].whName || '') + "</td><td style='width:60px;'  align='left'  >" + (result[i].fqty || 0) + "</td><td style='width:60px;'  align='left'  ></td>   </tr>"
                        row++;
                    }
 
                    var txt = css +th+ td +"</table>";
                    return txt;
 
                }
 
 
                
                function handleSizeChange(val) {
                    pageSize.value = val
                    currentPage.value = 1 // 重置到第一页
                    page()
                }
                
                function handleCurrentChange(val) {
                    currentPage.value = val
                    page()
                }
                function handleSelectionChange(val) {
                    selectList.value = val
                }
                function handleSelectionChangeDialog(val) {
                    selectList.value = val
                }
 
                onMounted(() => {
                    page()
                })
 
                onBeforeMount(() => {
                    getVendor()
 
                })
 
                return {
                    tableData,
                    tableDataDialog,
                    currentPage,
                    pageSizes,
                    pageSize,
                    pageTotal,
                    tableSearchParam,
                    tableSearchParamDialog,
                    defaultTime,
                    selectData,
                    options,
                    printOptions,
                    dialogVisible,
                    page,
                    dialogPage,
                    fnPrint,
                    fnPrintView,
                    fnCanelPrint,
                    fnTongBu,
                    fnCanelTongBu,
                    manualSync,
                    handleSizeChange,
                    handleCurrentChange,
                    handleSelectionChange,
                    handleSelectionChangeDialog
                    
                }
            }
        });
        
        app.use(ElementPlus, {
            locale: zhCn.default || zhCn
        });
        for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
            app.component(key, component)
        }
        app.mount('#app');
    </script>
 
</body>
 
</html>