schangxiang@126.com
2025-09-10 3d43ffa3152110b7823f9fa6320c08a6ae02358a
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
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
<template>
  <div class="scan-container">
    <el-card class="scan-card no-print">
      <div slot="header" class="clearfix">
        <span>出库单打包校验</span>
      </div>
      <el-form ref="form" :model="formData" label-width="120px" class="scan-form">
        <el-form-item label="快递号/出库单号">
          <el-input ref="batchCode" v-model="formData.batchCode" autofocus class="input-300" @keyup.native.enter.stop="getData"></el-input>
          <span class="sub-item">
            <span class="sub-label">物料校验:</span>
            <el-switch v-model="formData.isValidateProductCode" @change="onIsValidateProductCodeChange"></el-switch>
          </span>
          <span class="sub-item">
            <span class="sub-label">开启装箱:</span>
            <el-switch v-model="formData.isOpenCase" @change="onIsOpenCase"></el-switch>
          </span>
        </el-form-item>
        <el-form-item v-if="formData.isOpenCase" label="箱号">
          <el-input v-model="formData.caseNumber" class="input-300" @keyup.native.enter.stop="onKeyupCaseNumber"></el-input>
          <el-radio-group v-model="formData.caseMode" @change="onCaseMode">
            <el-radio :label="1">一品一箱</el-radio>
            <el-radio :label="2">多品一箱</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="物料条码">
          <el-input ref="productModel" v-model="formData.productModel" :disabled="!formData.isValidateProductCode" class="input-300" @keyup.native.enter.stop="checkPackingBarcode"></el-input>
        </el-form-item>
        <el-form-item label="包材条码">
          <el-input ref="txtwrapperBarcode" v-model="formData.wrapperBarcode" class="w-300"></el-input>
        </el-form-item>
        <el-form-item label="扫描数量">
          <el-input-number ref="scanQty" v-model="formData.scanQty" :min="0" :disabled="!formData.isValidateProductCode" controls-position="right" class="input-120" @change="changeScanQty"></el-input-number>
          <span class="sub-item">
            <span class="sub-label">称重:</span>
            <el-input-number v-model="formData.weight" :min="0" controls-position="right" class="input-105"></el-input-number>
          </span>
        </el-form-item>
        <el-form-item v-if="formData.isOpenCase" label="选择打印机">
          <el-select v-model="formData.printerName" placeholder="请选择打印机" class="w-300" @change="changePrint">
            <el-option v-for="(item, index) in printList" :key="index" :label="item" :value="item"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button v-if="formData.isOpenCase" @click="changeBox">换箱</el-button>
          <el-button type="success" @click="openPackage">复核提交</el-button>
          <el-button @click="onReset">重置</el-button>
          <el-checkbox v-if="config.outer_printBill" v-model="formData.isOuter_PrintBill">打印面单</el-checkbox>
          <el-checkbox v-if="formData.isOpenCase" v-model="formData.isOuter_Packinglist" @change="outerPacking">打印装箱清单</el-checkbox>
        </el-form-item>
      </el-form>
    </el-card>
    <el-card class="scan-card body-no-padding no-print">
      <div slot="header" class="clearfix">
        <span class="padding-top-10">扫描结果</span>
        <el-button type="text" class="floatRight" @click="setting.visible=true">字段设置</el-button>
      </div>
      <el-table ref="scan-table" :data="tableData" :row-class-name="rowClass" stripe style="width: 100%" class="scan-table" @row-dblclick="setCurrent">
        <template v-for="(item, index) in setting.fields">
          <template v-if="['unFinishedQuantity','finishedQuantity'].indexOf(item.prop)>=0">
            <el-table-column v-if="item.visible" :key="index" :prop="item.prop" :label="item.label" :width="item.width">
              <template slot-scope="scope">
                <template v-if="!formData.isValidateProductCode">
                  <el-input-number v-model="scope.row[item.prop]" :min="0" :max="scope.row['quantityOrder']" size="mini" class="w-100pc" controls-position="right" @change="rowChangeQty(item.prop, scope.row)"></el-input-number>
                </template>
                <template v-else>
                  {{ scope.row[item.prop] }}
                </template>
              </template>
            </el-table-column>
          </template>
          <template v-else-if="'positionName,scanWeight'.indexOf(item.prop)>=0">
            <el-table-column v-if="item.visible" :key="index" :prop="item.prop" :label="item.label" :width="item.width">
              <template slot-scope="scope">
                <template>
                  <el-input v-model="scope.row[item.prop]" size="mini" class="w-100pc"></el-input>
                </template>
              </template>
            </el-table-column>
          </template>
          <template v-else-if="'produceDate,limitDate'.indexOf(item.prop)>=0">
            <el-table-column v-if="item.visible" :key="index" :prop="item.prop" :label="item.label" :width="item.width">
              <template slot-scope="scope">
                <template>
                  <el-date-picker v-model="scope.row[item.prop]" size="mini" type="date" placeholder="选择日期" class="w-110" value-format="yyyy-MM-dd">
                  </el-date-picker>
                </template>
              </template>
            </el-table-column>
          </template>
          <template v-else-if="'caseNumber'.indexOf(item.prop)>=0">
            <el-table-column v-if="item.visible&&formData.isOpenCase" :key="index" :prop="item.prop" :label="item.label" :width="item.width">
            </el-table-column>
          </template>
          <template v-else>
            <el-table-column v-if="item.visible" :key="index" :prop="item.prop" :label="item.label" :width="item.width">
            </el-table-column>
          </template>
        </template>
      </el-table>
    </el-card>
 
    <scan-setting-dialog ref="setting-dialog" :visible.sync="setting.visible" :fields="setting.fields" :name="setting.name">
    </scan-setting-dialog>
    <!-- 显示打印模板 -->
    <print v-if="formData.isOuter_PrintBill" ref="printRef" :ids="''+formData.order_Id" type="express"></print>
    <!-- 显示打印装箱清单模板 -->
    <div id="mount-print"></div>
 
    <!--复核提交-->
    <el-dialog :visible.sync="isOpenPackage" title="复核提交" width="500px">
      <el-form :label-width="formLabelWidth">
        <el-form-item label="合计件数" style="width:320px;">
          <el-input v-model="totalPackage" type="text"></el-input>
        </el-form-item>
        <el-form-item label="合计体积" style="width:320px;">
          <el-input v-model="totalVolume" type="text"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="isOpenPackage=false">取 消</el-button>
        <el-button type="primary" @click="partialSave()">确 定</el-button>
      </div>
    </el-dialog>
 
    <!--声音文件-->
    <audio ref="sound_error" controls="controls" style="display:none;">
      <source src="@/assets/sounds/error2.mp3" type="audio/mpeg" />
    </audio>
    <audio ref="sound_correct" controls="controls" style="display:none;">
      <source src="@/assets/sounds/feixin.mp3" type="audio/mpeg" />
    </audio>
    <audio controls="controls" style="display:none;">
      <source ref="sound_scan" src="@/assets/sounds/saomiao.wav" type="audio/mpeg" />
    </audio>
  </div>
</template>
 
<script>
import { getLodop } from "@/utils/LodopFuncs";
import Vue from "vue";
import print from "@/views/sys/print/base2";
import PrintPacking from "@/views/sys/print/base3";
import YrtScanMixins from "@/components/common/yrtScanMixins.vue";
import PrintCase from "@/views/sys/print/base-fenjianji";
import ScanSettingDialog from "@/components/common/components/scanSettingDialog.vue";
 
export default {
  name: "outbound-scan-out",
  components: {
    ScanSettingDialog,
    print,
    PrintPacking,
    PrintCase
  },
  mixins: [YrtScanMixins],
  data() {
    return {
      // 配置参数
      config: {
        // 自动生成上架单
        in_generateShelve: true,
        // 是否启用装箱操作
        in_caseNumber: false,
        // 支持一品多码
        sku_productToMultiBarcode: true,
        // 打印面单
        outer_printBill: true,
        // 打印装箱清单
        outer_Packinglist: true,
        // 称重阈值
        outer_weightWhreshold: 0,
        // 是否体积,件数
        outer_openPackage: false
      },
      formData: {
        order_Id: 0,
        orderCode: null,
        batchCode: null,
        caseNumber: null,
        productModel: null, // 包装条码
        scanQty: 0, // 扫描数量
        weight: 0, // 称重
        isValidateProductCode: false, // 是否校验物料
        isOpenCase: false, // 开启装箱
        // 装箱方式:0:常规扫描,1:一品一箱,2:多品一箱
        caseMode: 2,
        // 打印面单
        isOuter_PrintBill: false,
        // 打印装箱清单
        isOuter_Packinglist: false,
        wrapperBarcode: ""
      },
      // 订单信息
      orderInfo: null,
      // 扫描数据
      tableData: [],
      // 当前正在扫描的数据
      currentRow: {},
      // 已经找到的数据
      existRows: [],
      // 一次扫描的数量
      scanCount: 1,
      // 装箱打印模板
      printCaseVueData: {},
      // 打印机设备列表
      printList: [],
      // // 当前正在扫描的数据
      // currentRow: {},
      // 扫描列设置对话框参数
      setting: {
        visible: false,
        name: "outbound-scan-out",
        fields: [
          {
            prop: "productModel",
            label: "条形码",
            visible: true,
            width: 130,
            order: 1
          },
          {
            prop: "quantityOrder",
            label: "物料数量",
            visible: true,
            width: 90,
            order: 2
          },
          {
            prop: "quantityOuter",
            label: "已出库数量",
            visible: true,
            width: 90,
            order: 3
          },
          {
            prop: "finishedQuantity",
            label: "当前扫描数量",
            visible: true,
            width: 120,
            order: 4
          },
          {
            prop: "unFinishedQuantity",
            label: "未扫描数量",
            visible: true,
            width: 130,
            order: 5
          },
          {
            prop: "productCode",
            label: "物料编号",
            visible: true,
            width: 130,
            order: 6
          },
          {
            prop: "salePrice",
            label: "单价",
            visible: true,
            width: 90,
            order: 6
          },
          {
            prop: "caseNumber",
            label: "箱号",
            visible: true,
            width: 90,
            order: 7
          },
          {
            prop: "productSpec",
            label: "物料规格",
            visible: true,
            width: 130,
            order: 8
          },
          {
            prop: "weight",
            label: "单位毛重",
            visible: false,
            width: 90,
            order: 9
          },
          {
            prop: "totalWeight",
            label: "合计重量",
            visible: false,
            width: 80,
            order: 10
          },
          {
            prop: "scanWeight",
            label: "已扫重量",
            visible: false,
            width: 80,
            order: 11
          },
          {
            prop: "productName",
            label: "物料名称",
            visible: true,
            width: null,
            order: 12
          }
        ]
      },
      // 弹出框
      isOpenPackage: false,
      formLabelWidth: "120px",
      totalPackage: null, // 合计件数
      totalVolume: null // 合计体积
    };
  },
  activated() {
    // 校验条码
    const isValidateProductCode = localStorage["out_isValidateProductCode"];
    if (isValidateProductCode) {
      this.formData.isValidateProductCode = isValidateProductCode === "true";
    }
    // 开启装箱
    const isOpenCase = localStorage["out_isOpenCase"];
    if (isOpenCase) {
      this.formData.isOpenCase = isOpenCase === "true";
      const caseMode = localStorage["out_caseMode"] || "0";
      this.formData.caseMode = parseInt(caseMode);
    }
    // 勾选打印装箱
    const isOuter_Packinglist = localStorage["isOuter_Packinglist"];
    if (isOuter_Packinglist) {
      this.formData.isOuter_Packinglist = isOuter_Packinglist === "true";
    }
  },
 
  mounted() {
    // 获取配置参数
    this.getConfig();
    // 获得打印模板
    this.getPrintTemplate();
    // 获取打印机
    this.getPrintList();
    // 字段设置
    const setting = localStorage[this.setting.name + "-setting"];
    if (setting) {
      this.setting.fields = JSON.parse(setting);
    }
  },
  methods: {
    // 是否校验物料切换
    onIsValidateProductCodeChange() {
      localStorage["out_isValidateProductCode"] = this.formData.isValidateProductCode;
 
      this.tableData = this.tableData.map(row => {
        let unFinishedQuantity = Math.Round(row.quantityOrder - row.quantityOuter, 4);
        row.scanWeight = 0;
        let finishedQuantity = 0;
        if (!this.formData.isValidateProductCode) {
          unFinishedQuantity = 0;
          finishedQuantity = Math.Round(row.quantityOrder - row.quantityOuter, 4);
          row.scanWeight = row.totalWeight;
        }
        row.unFinishedQuantity = unFinishedQuantity;
        row.finishedQuantity = finishedQuantity;
        row.sortIndex = 0;
        return row;
      });
    },
    // 是否开启装箱
    onIsOpenCase() {
      localStorage["out_isOpenCase"] = this.formData.isOpenCase;
      if (this.formData.isOpenCase) {
        const caseMode = localStorage["out_caseMode"] || "0";
        this.formData.caseMode = parseInt(caseMode);
      } else {
        this.formData.caseMode = 0;
      }
    },
    // 切换装箱模式
    onCaseMode() {
      localStorage["out_caseMode"] = this.formData.caseMode;
    },
    // 箱号回车
    onKeyupCaseNumber() {
      this.focus("productModel");
    },
    // 获得配置参数
    getConfig() {
      var keys = Object.keys(this.config).join(",");
      var url = "/api/sys/param/getConfig";
      var params = {
        openNodeApi: true,
        keys: keys
      };
      var callback = res => {
        this.common.showMsg(res);
        this.valueList = res.data;
        // 获得参数值列表,将数字转换为对象
        res.data.forEach(item => {
          var value02 = item.value02; // 字段名称
          var value03 = item.value03;
 
          if (this.common.isNumber(item.value03)) {
            value03 = parseInt(item.value03);
          }
          // 称重阈值不需要转为boolean
          if (value02 !== "outer_weightWhreshold") {
            this.$set(this.config, item.value02, !!value03);
          }
        });
      };
      var target = this.$refs["settings"];
      this.common.ajax(url, params, callback, target);
    },
    // 获取扫描数据
    getData() {
      var batchCode = this.formData.batchCode;
      if (!batchCode) {
        this.$message.error("快递单号不能为空!");
        return;
      }
      batchCode = batchCode.trim();
      this.formData.batchCode = batchCode;
 
      var url = "/api/outbound/outScan/getData";
      var params = {
        openNodeApi: true,
        expressCode: batchCode,
        batchCode: batchCode
      };
      var callBack = res => {
        this.common.showMsg(res);
        if (res.result) {
          this.orderInfo = res.data2;
          this.tableData = res.data.map(row => {
            let unFinishedQuantity = Math.Round(row.quantityOrder - row.quantityOuter, 4);
            let finishedQuantity = 0;
            let scanWeight = 0;
            if (!this.formData.isValidateProductCode) {
              unFinishedQuantity = 0;
              finishedQuantity = Math.Round(row.quantityOrder - row.quantityOuter, 4);
              scanWeight = row.totalWeight;
            }
            row.unFinishedQuantity = unFinishedQuantity;
            row.finishedQuantity = finishedQuantity;
            row.scanWeight = scanWeight;
            row.sortIndex = 0;
            return row;
          });
          if (this.config.outer_printBill === true) {
            this.formData.order_Id = this.tableData[0].order_Id;
          }
          this.formData.caseNumber = res.dynamic;
          // 条码框获得焦点
          if (this.formData.isValidateProductCode) {
            this.$refs.productModel.focus();
            this.$refs.productModel.select();
          } else {
            this.$refs.txtwrapperBarcode.focus();
            this.$refs.txtwrapperBarcode.select();
          }
        } else {
          this.onReset();
        }
      };
      this.common.ajax(url, params, callBack, true);
    },
    // 判断扫描包装条码
    checkPackingBarcode() {
      var code = this.formData.productModel;
      if (!code) {
        this.focus("productModel");
        this.$message.error("物料条码不能为空!");
        return;
      }
      if (this.formData.isOpenCase && this.formData.caseMode <= 0) {
        this.focus("productModel");
        this.$message.error("请选择装箱方式!");
        return;
      }
 
      // 装箱操作
      if (this.formData.isOpenCase) {
        if (this.formData.caseMode === 1) {
          // 一品一箱
          this.addRow_1();
        } else if (this.formData.caseMode === 2) {
          // 多品一箱
          this.addRow_2();
        }
      } else {
        // 常规扫描
        this.checkPackingProductModel(this.tableData);
      }
      this.focus("productModel");
      if (this.currentRow) {
        this.formData.scanQty = this.currentRow.finishedQuantity;
      }
    },
    // 设置扫描数量
    setScanCount(barcode, count, isAdd) {
      if (!count || count < 0) {
        this.$message({
          showClose: true,
          message: '"数量不正确',
          type: "warning"
        });
        return;
      }
      if (!barcode) {
        this.$message({
          showClose: true,
          message: '"条码不能为空',
          type: "warning"
        });
        return;
      }
    },
    // 行样式
    rowClass({ row, rowIndex }) {
      if (this.currentRow === row) {
        return "row-active";
      }
    },
    // 扫描数量手工改变
    changeScanQty() {
      if (this.currentRow) {
        let finishedQuantity = 0; // 当前物料所有分箱的出库数量求和
        this.tableData
          .filter(item => {
            return item.orderList_Id === this.currentRow.orderList_Id;
          })
          .forEach(item => {
            finishedQuantity += item.finishedQuantity;
          });
 
        // 不包含当前行完成数量
        finishedQuantity -= this.currentRow.finishedQuantity;
        const unFinishedQuantity = Math.Round(this.currentRow.quantityOrder - this.currentRow.quantityOuter - finishedQuantity, 4);
        if (this.formData.scanQty <= unFinishedQuantity) {
          this.currentRow.unFinishedQuantity = Math.Round(unFinishedQuantity - this.formData.scanQty, 4);
          this.currentRow.finishedQuantity = this.formData.scanQty;
          this.currentRow.scanWeight = Math.Round(this.currentRow.weight * this.currentRow.finishedQuantity, 2);
        } else {
          this.$message({
            showClose: true,
            message: "没有足够的数量!",
            type: "warning"
          });
        }
      }
    },
    // 校验是否显示弹出框
    openPackage() {
      if (this.config.outer_openPackage) {
        this.isOpenPackage = true;
      } else {
        this.partialSave();
      }
    },
    // 复核提交,封箱(部分打包),然后计算已打包数量,设置 新快递单号为 “可用”
    partialSave() {
      if (this.config.outer_openPackage) {
        if (!this.totalPackage || !this.totalVolume) {
          this.$message({
            message: "合计件数、合计体积不能为空!",
            type: "warning"
          });
          return false;
        }
      }
      var expressCode = this.formData.batchCode; // 快递单号
      var wrapperBarcode = this.formData.wrapperBarcode; // 包材条码
      var newExpressCode = ""; // 新快递单号
      var weight = this.formData.weight; // 重量
      if (!expressCode) {
        this.$message({
          showClose: true,
          message: "快递单号不能为空!",
          type: "warning"
        });
        return;
      }
      var dataArray = this.tableData
        .filter(item => {
          return item.finishedQuantity > 0;
        })
        .map(rowData => {
          return {
            caseNumber: rowData.caseNumber,
            order_Id: rowData.order_Id,
            orderCode: rowData.orderCode,
            orderList_Id: rowData.orderList_Id,
            scanCount: rowData.finishedQuantity,
            totalWeight: rowData.scanWeight,
            weight: rowData.weight
          };
        });
      if (!dataArray.length) {
        this.$message({
          showClose: true,
          message: "请先扫描条码!",
          type: "error"
        });
        return;
      }
      // 明细理论求和值
      let theoryweight = 0;
      // 明细实际求和值
      let scanWeight = 0;
      // 得到设置的阈值,阈值大于0进行校验
      const outer_weightWhreshold = this.config.outer_weightWhreshold;
      // 对明细已扫描数量求和算出理论值
      dataArray.forEach(item => {
        theoryweight += item.scanCount * item.weight;
      });
      // 直接扫描重量
      dataArray.forEach(item => {
        scanWeight += Math.Round(item.totalWeight, 2);
      });
      const absWeight = Math.abs(theoryweight - scanWeight);
      if (outer_weightWhreshold > 0 && absWeight > outer_weightWhreshold) {
        this.$message.error("物料实际重量与物料理论重量差值超过设定阈值" + outer_weightWhreshold + ",不允许出库");
        return;
      }
      const url = "/api/outbound/outScan/orderPartialSaveScan";
      const params = {
        openNodeApi: true,
        expressCode: expressCode,
        wrapperBarcode: wrapperBarcode,
        newExpressCode: newExpressCode,
        data: dataArray,
        weight: weight,
        totalPackage: this.totalPackage,
        totalVolume: this.totalVolume
      };
      const callBack = res => {
        this.common.showMsg(res);
        if (res.result) {
          this.onReset();
          // 自动打印,系统配置中心开启,且勾选打印复选框
          if (this.config.outer_printBill === true && this.formData.isOuter_PrintBill) {
            this.$refs.printRef.lodopPrint();
          }
        }
      };
      this.common.ajax(url, params, callBack, true);
    },
    // 重置
    onReset() {
      const isValidateProductCode = localStorage["out_isValidateProductCode"];
 
      this.formData = {
        order_Id: 0,
        orderCode: null,
        batchCode: null,
        caseNumber: null,
        productModel: null, // 包装条码
        scanQty: 0, // 扫描数量
        weight: 0, // 称重
        isValidateProductCode: isValidateProductCode === "true", // 是否校验物料
        isOuter_PrintBill: false,
        isOuter_Packinglist: false,
        wrapperBarcode: ""
      };
      // 扫描数据
      this.tableData = [];
      // 当前正在扫描的数据
      this.currentRow = {};
      // 已经找到的数据
      this.existRows = [];
      // 一次扫描的数量
      this.scanCount = 1;
      // 配置参数
      this.config = {
        // 自动生成上架单
        in_generateShelve: true,
        // 是否启用装箱操作
        in_caseNumber: false,
        // 支持一品多码
        sku_productToMultiBarcode: true,
        // 打印面单
        outer_printBill: true,
        // 打印装箱清单
        outer_Packinglist: true,
        // 称重阈值
        outer_weightWhreshold: 0,
        // 是否体积,件数
        outer_openPackage: 0
      };
      // 弹出框
      this.isOpenPackage = false;
      this.formLabelWidth = "120px";
      this.totalPackage = null;
      this.totalVolume = null;
      this.$refs.batchCode.focus();
    },
    // 勾选装箱清单
    outerPacking() {
      localStorage["isOuter_Packinglist"] = this.formData.isOuter_Packinglist;
    },
    // 换箱
    changeBox() {
      var batchNo = this.formData.batchCode;
      if (batchNo === null) {
        this.$message({
          message: "请先扫描出库单号!",
          type: "warning"
        });
        return;
      }
      var currentRow = JSON.stringify(this.currentRow);
      if (currentRow === "{}") {
        this.$message({
          message: "请先扫描物料信息!",
          type: "warning"
        });
        return;
      }
      if (this.formData.isOuter_Packinglist) {
        // 打印装箱单
        this.printCase();
        // 重新生成箱号
        this.generateCaseNumber();
      } else {
        this.$message({
          message: "请勾选打印装箱清单!",
          type: "warning"
        });
        return;
      }
    },
    // 生成箱号
    generateCaseNumber() {
      var batchNo = this.formData.batchCode;
      var max = 1;
      var num = this.formData.caseNumber;
      if (num.indexOf("-") >= 0) {
        var nums = num.split("-");
        num = nums[nums.length - 1];
      } else {
        num = num.substr(num.length - 4);
      }
      num = parseInt(num);
      ++num;
      if (num > max) max = num;
      max = "00000" + max;
      max = max.substr(max.length - 2);
      var caseNumber = batchNo + "-" + max;
      this.formData.caseNumber = caseNumber;
    },
    // 一品一箱
    addRow_1() {
      const rowData = this.tableData.find(item => {
        const exist = this.checkProductModelExist(this.formData.productModel, item);
        return exist && item.unFinishedQuantity > 0;
      });
      if (!rowData) {
        this.$message.error("没有可扫描的物料条码");
        this.playError();
        return;
      }
 
      // 箱号存在
      var existCaseRow = this.tableData.find(item => {
        return item.caseNumber === this.formData.caseNumber && item.unFinishedQuantity > 0;
      });
      if (!existCaseRow) {
        var newRow = JSON.parse(JSON.stringify(rowData));
        rowData.unFinishedQuantity = 0;
 
        const scanQty = this.getScanQty(); // 默认扫描数量为1
        newRow.finishedQuantity = scanQty;
        newRow.unFinishedQuantity -= scanQty;
        newRow.caseNumber = this.formData.caseNumber;
        this.tableData.splice(0, 0, newRow);
        this.currentRow = newRow;
      }
      this.currentRow.scanWeight = Math.Round(this.currentRow.weight * this.currentRow.finishedQuantity, 2);
      this.generateCaseNumber();
      this.play();
    },
    // 多品一箱
    addRow_2() {
      const rowData = this.tableData.find(item => {
        const exist = this.checkProductModelExist(this.formData.productModel, item);
        return exist && item.unFinishedQuantity > 0;
      });
      if (!rowData) {
        this.$message.error("没有可扫描的物料条码");
        this.playError();
        return;
      }
 
      const scanQty = this.getScanQty(); // 默认扫描数量为1
      if (rowData.caseNumber === this.formData.caseNumber) {
        rowData.unFinishedQuantity -= scanQty;
        rowData.finishedQuantity += scanQty;
        this.currentRow = rowData;
      } else {
        if (!rowData.caseNumber) {
          rowData.unFinishedQuantity -= scanQty;
          rowData.finishedQuantity += scanQty;
          rowData.caseNumber = this.formData.caseNumber;
          this.currentRow = rowData;
        } else {
          var newRow = JSON.parse(JSON.stringify(rowData));
          rowData.unFinishedQuantity = 0;
 
          newRow.finishedQuantity = scanQty;
          newRow.unFinishedQuantity -= scanQty;
          newRow.caseNumber = this.formData.caseNumber;
          this.tableData.splice(0, 0, newRow);
          this.currentRow = newRow;
        }
      }
      this.currentRow.scanWeight = Math.Round(this.currentRow.weight * this.currentRow.finishedQuantity, 2);
      this.play();
 
      this.currentRow.sortIndex = 1;
      // 置顶排序
      this.tableData.sort(function(a, b) {
        return b.sortIndex - a.sortIndex;
      });
 
      this.tableData.forEach(element => {
        element.sortIndex = 0;
      });
    },
    // 获得打印模板
    // 获取运单信息和打印机名称
    getPrintTemplate() {
      var url = "/api/sys/printTemplate/getPrintTemplate";
      var params = {
        openNodeApi: true,
        menu_Id: 200013 // 打印模板MenuID
      };
      this.common.ajax(
        url,
        params,
        res => {
          this.common.showMsg(res);
          if (res.result) {
            this.printCaseVueData = res.data;
          }
        },
        true
      );
    },
    // 打印装箱单
    printCase() {
      // 获取装箱数据
      const caseDataList = this.tableData.filter(item => {
        item.rowTotal = item.finishedQuantity * item.salePrice;
        return item.caseNumber === this.formData.caseNumber;
      });
      if (!caseDataList.length) {
        this.$message.error("没有可打印的数据");
        return;
      }
      // 箱号
      this.orderInfo.caseNumber = this.formData.caseNumber;
      const billDataInfo = {
        mainInfo: this.orderInfo,
        detailList: {
          total: caseDataList.length,
          rows: caseDataList
        }
      };
      var Profile = Vue.extend(PrintCase);
      var m = new Profile({
        propsData: {
          vueData: this.printCaseVueData,
          billDataInfo: billDataInfo,
          printInfo: {
            printerName: this.formData.printerName
          },
          billCodeField: "orderCode"
        }
      }).$mount();
      var mountPrint = document.getElementById("mount-print");
      var firstChild = mountPrint.firstChild;
      mountPrint.insertBefore(m.$el, firstChild);
      m.lodopPrint();
      window.setTimeout(() => {
        document.getElementById(this.orderInfo.orderCode).remove();
      }, 2 * 60 * 1000);
    },
    // 打印机改变
    changePrint() {
      localStorage["printerName"] = this.formData.printerName;
    },
    // 获得打印机列表
    getPrintList() {
      window.setTimeout(() => {
        const LODOP = getLodop();
        var iPrinterCount = LODOP.GET_PRINTER_COUNT();
        for (var i = 0; i < iPrinterCount; i++) {
          this.printList.push(LODOP.GET_PRINTER_NAME(i));
        }
        // 设置默认打印机
        const printerName = localStorage["printerName"];
        if (printerName) {
          this.formData.printerName = printerName;
        }
      }, 1000);
    }
  }
};
</script>
 
<style lang="scss" scoped>
@import "../../../styles/scan.scss";
</style>