zouyu
2023-11-17 d8ac6057eaad648687699e25a575f3b7b8c1b102
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
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
<!--
 * @Descripttion:
 * @version:
 * @Author: zt_lc
 * @Date: 2022-06-08 15:49:37
 * @LastEditors: zt_lc
 * @LastEditTime: 2022-08-18 14:07:40
-->
<template>
  <el-dialog
    width="95%"
    title="批量产出"
    :visible.sync="innerVisible"
    append-to-body
    @close="$emit('update:currshowlist', false)"
    :show="currshowlist"
    :close-on-click-modal="false"
    class="batch-product-out-form"
  >
    <div
      style="float: left;width: 15%;box-sizing: border-box;padding-right: 34px;position: relative"
    >
      <el-table
        stripe
        ref="productOutPersonList"
        :data="personBoardList"
        @selection-change="productOutPersonSelectionChange"
        :row-style="{ height: '26px' }"
        :cell-style="{ padding: '0' }"
      >
        <el-table-column type="selection" />
        <el-table-column
          label="人员名称"
          prop="staffName"
          align="center"
          min-width="75px"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="人员编号"
          prop="staffNo"
          align="center"
          min-width="75px"
          :show-overflow-tooltip="true"
        />
      </el-table>
      <div
        style="position: absolute;top:0px;right: 0px;height: 100%;width: 34px;border-left: 1px solid #f4f2ea;border-right: 1px solid #f4f2ea;"
      ></div>
    </div>
    <div style="float: left;width: 85%">
      <el-row style="">
        <el-col :span="1" class="batch-product-out-form-header-col"
          ><span>序号</span></el-col
        ><el-col :span="2" class="batch-product-out-form-header-col"
          ><span>零件编号</span></el-col
        ><el-col :span="2" class="batch-product-out-form-header-col"
          ><span>零件名称</span></el-col
        >
        <el-col :span="4" class="batch-product-out-form-header-col"
          ><span>SN号</span></el-col
        >
        <el-col :span="2" class="batch-product-out-form-header-col"
          ><span>载具编号</span></el-col
        >
        <el-col :span="1" class="batch-product-out-form-header-col"
          ><span>盘数</span></el-col
        >
        <el-col :span="1" class="batch-product-out-form-header-col"
          ><span>每盘产量</span></el-col
        >
        <el-col :span="1" class="batch-product-out-form-header-col"
          ><span>起始米标</span></el-col
        >
        <el-col :span="1" class="batch-product-out-form-header-col"
          ><span>截止米标</span></el-col
        >
        <el-col :span="1" class="batch-product-out-form-header-col"
          ><span>单位</span></el-col
        >
        <el-col :span="1" class="batch-product-out-form-header-col"
          ><span>分段描述</span></el-col
        >
        <el-col :span="1" class="batch-product-out-form-header-col"
          ><span>报废数量</span></el-col
        >
        <el-col :span="1" class="batch-product-out-form-header-col"
          ><span>盘具重量</span></el-col
        >
        <el-col :span="1" class="batch-product-out-form-header-col"
          ><span>毛重</span></el-col
        >
        <!--<el-col :span="1" class="batch-product-out-form-header-col"
          ><span>IFS批次号</span></el-col
        >-->
        <el-col :span="2" class="batch-product-out-form-header-col"
          ><span>生产人员</span></el-col
        ><el-col :span="1" class="batch-product-out-form-header-col"
          ><span>备注</span></el-col
        >
        <el-col :span="1" class="batch-product-out-form-header-col"
          ><span>操作</span></el-col
        >
      </el-row>
      <div class="batch-product-out-form-body-div">
        <el-row v-for="(item, index) in products" :key="item.id">
          <el-col :span="1" class="batch-product-out-form-body-col">
            <span>{{ index + 1 }}</span>
          </el-col>
          <el-col :span="2" class="batch-product-out-form-body-col">
            <el-tooltip
              class="item"
              effect="dark"
              :content="item.partNo"
              placement="top"
            >
              <span class="inline-el-hidden">{{ item.partNo }}</span>
            </el-tooltip>
          </el-col>
          <el-col :span="2" class="batch-product-out-form-body-col">
            <el-tooltip
              class="item"
              effect="dark"
              :content="item.partName"
              placement="top"
            >
              <span class="inline-el-hidden">{{ item.partName }}</span>
            </el-tooltip>
          </el-col>
          <el-col :span="4" class="batch-product-out-form-body-col">
            <span v-show="!item.batchNoEdit">{{ item.outBatchNo }}</span>
            <!--<el-input v-show="item.batchNoEdit" v-model="item.outBatchNo">
              <i
                slot="prefix"
                class="el-input__icon el-icon-search"
                style="cursor:pointer"
                @click="openOutPutBatch(item)"
              ></i>
              <i
                slot="suffix"
                class="el-input__icon el-icon-circle-close"
                style="cursor:pointer"
                @click="cleanOutBatchNo(item)"
              ></i>
            </el-input>-->
          </el-col>
          <el-col :span="2" class="batch-product-out-form-body-col l-mes">
            <el-input v-model="item.reelNumber"></el-input>
          </el-col>
          <el-col :span="1" class="batch-product-out-form-body-col l-mes">
            <el-input v-model="item.disNumber"></el-input>
          </el-col>
          <el-col :span="1" class="batch-product-out-form-body-col l-mes">
            <span>{{ item.productQty }}</span>
          </el-col>
          <el-col :span="1" class="batch-product-out-form-body-col l-mes">
            <el-input v-model="item.startMeterMark"></el-input>
          </el-col>
          <el-col :span="1" class="batch-product-out-form-body-col l-mes">
            <el-input v-model="item.endMeterMark"></el-input>
          </el-col>
          <el-col :span="1" class="batch-product-out-form-body-col">
            <span>{{ item.unit }}</span>
          </el-col>
          <el-col :span="1" class="batch-product-out-form-body-col l-mes">
            <el-input v-model="item.segmentDesc"></el-input>
          </el-col>
          <el-col :span="1" class="batch-product-out-form-body-col l-mes">
            <el-input v-model="item.scrapQty"></el-input>
          </el-col>
          <el-col :span="1" class="batch-product-out-form-body-col l-mes">
            <el-input v-model="item.reelWeight"></el-input>
          </el-col>
          <el-col :span="1" class="batch-product-out-form-body-col l-mes">
            <el-input v-model="item.grossWeight"></el-input>
          </el-col>
          <!--<el-col :span="1" class="batch-product-out-form-body-col l-mes">
            <el-input v-model="item.ifsBatchNo"></el-input>
          </el-col>-->
          <el-col :span="2" class="batch-product-out-form-body-col">
            <el-tooltip
              class="item"
              effect="dark"
              :content="item.staffName"
              placement="top"
            >
              <span class="inline-el-hidden">{{ item.staffName }}</span>
            </el-tooltip>
          </el-col>
          <!--<el-col :span="1" class="batch-product-out-form-body-col l-mes">
            <el-input v-model="item.remark"></el-input>
          </el-col>-->
          <el-col :span="1" class="batch-product-out-form-body-col l-mes">
            <el-input v-model="item.mainRemark"></el-input>
          </el-col>
          <el-col :span="1" class="batch-product-out-form-body-col">
            <span
              v-if="item.status && item.dutyRecordId == currentDutyRecord.id"
              style="cursor: pointer;color: red;"
              @click="delStaff(index)"
              >删除</span
            >
          </el-col>
        </el-row>
      </div>
    </div>
    <div slot="footer" class="dialog-footer">
      <div style="display: inline-block;width: 25%;float: left">
        <el-button
          style="margin-right: 34px"
          type="primary"
          @click="addProductOutForPerson"
          >添加</el-button
        >
      </div>
      <el-button @click="innerVisible = false">取 消</el-button>
      <el-button
        type="primary"
        :disabled="saveDisabled"
        @click="saveProductOuts"
        >确 定</el-button
      >
    </div>
    <OutPutBatch
      :currshowlist.sync="showOutPutBatch"
      @selectOutPutBatch="selectOutPutBatch"
      :optaskId="parentInfo.operationTaskId"
    />
    <TaskSecretForm
      :currshowlist.sync="showTaskSecretForm"
      @confirmSecret="confirmSecret"
      :tackingList="confirmList"
      :tipeInfo="tipeInfo"
    />
  </el-dialog>
</template>
<style>
.batch-product-out-form .el-dialog__body {
  padding-bottom: 0px;
}
 
.batch-product-out-form .el-dialog__body:after {
  content: '';
  clear: both;
  overflow: hidden;
  display: block;
  visibility: hidden;
}
 
.batch-product-out-form .el-dialog__body .el-table__header th {
  padding-top: 0px;
}
 
.batch-product-out-form .el-dialog__body .el-table__body-wrapper {
  height: 260px;
  overflow-y: auto;
}
 
.batch-product-out-form .el-dialog__body .el-table::before {
  height: 0px;
}
.batch-product-out-form .el-dialog__body .add-button span {
}
 
.batch-product-out-form-header-col {
  text-align: center;
  color: rgb(144, 147, 153);
  font-weight: 700;
  line-height: 23px;
  font-size: 12px;
}
 
.batch-product-out-form-body-col {
  text-align: center;
  color: rgb(96, 98, 102);
  font-size: 12px;
  margin-bottom: 1px;
}
 
.batch-product-out-form-body-col .el-input {
  width: 80%;
}
 
.batch-product-out-form-body-col .el-input input {
  text-align: center;
}
 
.batch-product-out-form-body-col span {
  line-height: 32px;
}
 
.batch-product-out-form-body-div {
  height: 260px;
  overflow-y: auto;
}
 
.item {
  margin: 4px;
}
/*
  字符串过长时,隐藏显示省略号
   */
.inline-el-hidden {
  display: block;
  width: 93%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin: 0 auto;
}
</style>
<script>
import {
  batchSaveProductMain,
  getShiftProductOutByOpIdAndWsId,
  validateOverProduction,
  validateOverFeed
} from '@/api/product/personboard'
import ElButton from '../../../../node_modules/element-ui/packages/button/src/button.vue'
import OutPutBatch from './outputbatch.vue'
import TaskSecretForm from './task-secret-form.vue'
export default {
  components: { ElButton, OutPutBatch, TaskSecretForm },
  props: {
    currshowlist: {
      type: Boolean,
      default: false
    },
    productList: {
      type: Array,
      default: () => {
        return []
      }
    },
    parentInfo: {
      type: Object,
      default: () => {
        return {}
      }
    },
    currentDutyRecord: {
      type: Object,
      default: () => {
        return {}
      }
    },
    personBoardList: {
      type: Array,
      default: () => {
        return []
      }
    },
    groupStatus: {
      type: Boolean,
      default: false // true是按人员报工,false是按组报工
    }
  },
  data() {
    return {
      innerVisible: false,
      personSelection: [],
      saveDisabled: false,
      currDutyInitproducts: [], // 用于缓存页面中原有的staff产出记录,并且是属于当前班次下的,用于勾选人员时作为原数据参照
      products: [],
      clickDateArr: [],
      isChangeShift: false,
      showOutPutBatch: false,
      currOutPut: null,
      showTaskSecretForm: false,
      confirmList: [],
      tipeInfo: null,
      messageMap: {}
    }
  },
  methods: {
    isNumber(value) {
      var reg = /^[0-9]+(.[0-9]{1,4})?$/
      if (
        value == undefined ||
        value == null ||
        value === '' ||
        value.trim === ''
      ) {
        return false
      } else {
        if (!reg.test(value)) {
          return false
        } else {
          return true
        }
      }
    },
    isPositiveIntegerNumber(value) {
      var reg = /^[1-9]\d*$/
      if (
        value == undefined ||
        value == null ||
        value === '' ||
        value.trim === ''
      ) {
        return false
      } else {
        if (!reg.test(value)) {
          return false
        } else {
          return true
        }
      }
    },
    setOutBatchNo(val) {
      this.products.forEach(function(el) {
        el.outBatchNo = val
      })
    },
    // 选中人员,人员变动时,去更新products
    productOutPersonSelectionChange(val) {
      // 已选中人员集合val为准,去currDutyInitproducts寻找相同人员(且同班次、按人员,已进行过滤)的信息,若currDutyInitproducts中不存在,则自行组装信息。选中人员信息组合完毕后,
      // 再去与products(此为页面的实时数据,用户有改动即更新)对比,将其中存在的相同人员的生产数量和生产批次同步过来,若products中生产数量或生产批次不存在值,则不进行同步,沿用原来的。
      // 最后,将组装好的选中人员信息,更新到products(按照班次进行),注意更新之后选中人员信息在products位置顺序
      this.personSelection = val
    },
    // 根据选中的人员,生成人员产出信息,并且放在右边列表的最前面
    addProductOutForPerson() {
      if (this.personSelection != null && this.personSelection.length > 0) {
        // 理论上来说,products的长度肯定大于0
        var productCopyList = this.products
        this.products = []
        // 获取第一条的生产批次,用于继承
        var oriOutBatchNo = ''
        if (productCopyList != null && productCopyList.length > 0) {
          oriOutBatchNo = productCopyList[0].outBatchNo
        }
        var newProduct
        for (let i = 0; i < this.personSelection.length; i++) {
          newProduct = {}
          var productStaffs = []
          var productStaffIds = []
          productStaffIds.push(this.personSelection[i].staffId)
          productStaffs.push(this.personSelection[i].staffNo)
          newProduct.staffName = this.personSelection[i].staffName
          newProduct.staffNo = this.personSelection[i].staffNo
          newProduct.productNo = this.parentInfo.currProductMainNo
          newProduct.partId = this.parentInfo.partId
          newProduct.partNo = this.parentInfo.partNo
          newProduct.partName = this.parentInfo.partName
          newProduct.outBatchNo = oriOutBatchNo
          newProduct.productQty = 0
          newProduct.unit = this.parentInfo.unit
          newProduct.productStaffs = productStaffs
          newProduct.productStaffIds = productStaffIds
          newProduct.status = true
          newProduct.systemNo = null
          newProduct.date = null
          newProduct.dutyRecordId = this.currentDutyRecord.id
          newProduct.startMeterMark = 0
          newProduct.endMeterMark = 0
          newProduct.reelNumber = null
          newProduct.ifsBatchNo = null
          newProduct.scrapQty = null
          newProduct.reelWeight = null
          newProduct.grossWeight = null
          newProduct.segmentDesc = null
          newProduct.remark = null
          newProduct.sproductQty = 0
          newProduct.batchNoEdit = false
          newProduct.mainRemark = null
          this.products.push(newProduct)
        }
        if (productCopyList != null && productCopyList.length > 0) {
          for (let i = 0; i < productCopyList.length; i++) {
            this.products.push(productCopyList[i])
          }
        }
      } else {
        this.$message.warning('若想添加产出,请先选中人员!')
      }
    },
    delStaff(index) {
      this.products.splice(index, 1)
      this.$message.success('删除成功')
    },
    // 打开产出批次列表
    openOutPutBatch(row) {
      this.currOutPut = row
      this.showOutPutBatch = true
    },
    selectOutPutBatch(param) {
      this.currOutPut.outBatchNo = param.snNo
    },
    cleanOutBatchNo(row) {
      row.outBatchNo = null
    },
    setOutBatchNoMode(row) {
      if (Number(row.disNumber) == 1) {
        row.batchNoEdit = false
      } else {
        row.batchNoEdit = false
        // row.outBatchNo = null
      }
    },
    saveProductOuts() {
      var canClickFlag = true
      this.clickDateArr.push(new Date().getTime())
      if (this.clickDateArr.length > 1) {
        if (
          this.clickDateArr[this.clickDateArr.length - 1] -
            this.clickDateArr[this.clickDateArr.length - 2] <
          2000
        ) {
          // 小于2秒则认为重复提交
          canClickFlag = false
        }
      }
 
      if (canClickFlag) {
        this.saveDisabled = true
        if (this.products != null && this.products.length > 0) {
          // 校验生产批次、生产数量
          var validateMsg = ''
          var validateFlag = true
 
          let s_list = [] // 需要保存的数据
          const p_list = JSON.parse(JSON.stringify(this.products))
 
          /**
           * 按人员新增产出时,只对盘数大于等于1的产出新增报工单。过滤掉未填写的行即可
           * 按组报工保持不变
           **/
          if (this.groupStatus) {
            // 按人员报工,过滤填写盘数的
            p_list.forEach((el) => {
              if (el.disNumber) {
                s_list.push(el)
              }
            })
          } else {
            // 按组报工
            s_list = JSON.parse(JSON.stringify(p_list))
          }
 
          if (s_list.length <= 0) {
            this.$message.error('报工,请填写盘数!')
            this.saveDisabled = false
            return
          }
          let totalDisNumber = 0
          for (let i = 0; i < s_list.length; i++) {
            // 盘数校验
            if (!this.isPositiveIntegerNumber(s_list[i].disNumber)) {
              validateFlag = false
              if (this.groupStatus) {
                validateMsg =
                  '人员:' +
                  s_list[i].staffName +
                  ',所在行,【盘数】请输入正整数!'
              } else {
                validateMsg = '第' + (i + 1) + '行,【盘数】请输入正整数!'
              }
              break
            }
            totalDisNumber += s_list[i].disNumber - 0
            // 起始米标校验
            if (!this.isNumber(s_list[i].startMeterMark)) {
              validateFlag = false
              validateMsg =
                '第' + (i + 1) + '行,【起始米标】请输入非负数,小数位最多4位!'
              break
            }
            // 截止米标校验
            if (!this.isNumber(s_list[i].endMeterMark)) {
              validateFlag = false
              validateMsg =
                '第' + (i + 1) + '行,【截止米标】请输入非负数,小数位最多4位!'
              break
            }
            // 截止米标需大于开始米标
            if (
              Number(s_list[i].endMeterMark) < Number(s_list[i].startMeterMark)
            ) {
              validateFlag = false
              validateMsg =
                '第' + (i + 1) + '行,【截止米标】需大于【起始米标】'
              break
            }
          }
          const maxDisNumber = 2000 // 最大盘数
          if (totalDisNumber > maxDisNumber) {
            validateMsg = '总盘数不能大于' + maxDisNumber + '!'
            validateFlag = false
          }
          if (validateFlag) {
            if (this.parentInfo.productOutId == null) {
              // 当前是产出的新增
              const list = []
              for (let i = 0; i < s_list.length; i++) {
                var productVo = {}
                productVo.isChangeShift = this.isChangeShift
                productVo.id = this.parentInfo.currProductMainId
                productVo.workstationId = this.parentInfo.workstationId
                productVo.operationTaskId = this.parentInfo.operationTaskId
                productVo.discsNumber = s_list[i].disNumber
                productVo.mainRemark = s_list[i].mainRemark
                var productOuts = []
                var productOut = {}
                productOut.workstationId = this.parentInfo.workstationId
                productOut.operationTaskId = this.parentInfo.operationTaskId
                productOut.partId = s_list[i].partId
                productOut.disNumber = s_list[i].disNumber
                productOut.productQty = s_list[i].productQty
                productOut.productStaffs = s_list[i].productStaffs
                productOut.productStaffIds = s_list[i].productStaffIds
                productOut.outBatchNo = s_list[i].outBatchNo
                productOut.status = s_list[i].status
                productOut.dutyRecordId = s_list[i].dutyRecordId
                productOut.startMeterMark = s_list[i].startMeterMark
                productOut.endMeterMark = s_list[i].endMeterMark
 
                productOut.outBatchNo = s_list[i].outBatchNo
                productOut.reelNumber = s_list[i].reelNumber
                productOut.ifsBatchNo = s_list[i].ifsBatchNo
                productOut.scrapQty = s_list[i].scrapQty
                productOut.reelWeight = s_list[i].reelWeight
                productOut.grossWeight = s_list[i].grossWeight
                productOut.segmentDesc = s_list[i].segmentDesc
                productOut.remark = s_list[i].remark
                productOut.sproductQty = s_list[i].sproductQty
                productOut.mainRemark = s_list[i].mainRemark
                productOut.unit = s_list[i].unit
 
                productOuts.push(productOut)
                productVo.productOutputList = productOuts
                list.push(productVo)
              }
              // 先去校验当前工单是否已生产超量,若超量则弹出密码输入框,若不超量,继续报工
              // 分量提交-每次100条
              const listDisNumber = [] // 原始盘数
              for (let i = 0; i < list.length; i++) {
                listDisNumber.push(list[i].discsNumber)
              }
              this.messageMap = {}
 
              validateOverProduction(list)
                .then((response) => {
                  const resData = response.data
                  if (resData.code === 0) {
                    if (resData.data.success) {
                      // 校验投料是否充足
                      validateOverFeed(list)
                        .then((resp) => {
                          const respData = resp.data
                          if (respData.code == 0) {
                            if (respData.data.success) {
                              // 分段提交
                              this.pieceSubmit(list, 0, listDisNumber, 0)
                              // 投料充足
                              // batchSaveProductMain(list)
                              //   .then((res) => {
                              //     var data = res.data
                              //     if (data.code == 0) {
                              //       // 返回报工主表id,用于刷新页面
                              //       var productMainId = data.data
                              //       this.$message.success('新增成功')
                              //       this.$emit(
                              //         'refreshProductOutputList',
                              //         productMainId
                              //       )
                              //       this.innerVisible = false
                              //     } else {
                              //       this.$message.error('新增失败')
                              //     }
                              //     this.saveDisabled = false
                              //   })
                              //   .catch((error) => {
                              //     console.log('失败' + new Date().getTime())
                              //     this.saveDisabled = false
                              //   })
                            } else {
                              // 投料不足,提示人工选择
                              // respData.data.message
                              let confirmInfo = ''
                              const confirmMessage = respData.data.message
                              confirmMessage.forEach((item) => {
                                confirmInfo = confirmInfo + item + ';<br>'
                              })
                              this.$confirm(
                                confirmInfo +
                                  '<span style="color:red;">是否继续报工?</span>',
                                '提示',
                                {
                                  confirmButtonText: '确定',
                                  cancelButtonText: '取消',
                                  type: 'warning',
                                  customClass: 'validate-over-feed-message',
                                  dangerouslyUseHTMLString: true,
                                  closeOnClickModal: false
                                }
                              )
                                .then(() => {
                                  // 分段提交
                                  this.pieceSubmit(list, 0, listDisNumber, 0)
                                  // batchSaveProductMain(list)
                                  //   .then((res) => {
                                  //     var data = res.data
                                  //     if (data.code == 0) {
                                  //       // 返回报工主表id,用于刷新页面
                                  //       var productMainId = data.data
                                  //       this.$message.success('新增成功')
                                  //       this.$emit(
                                  //         'refreshProductOutputList',
                                  //         productMainId
                                  //       )
                                  //       this.innerVisible = false
                                  //     } else {
                                  //       this.$message.error('新增失败')
                                  //     }
                                  //     this.saveDisabled = false
                                  //   })
                                  //   .catch((error) => {
                                  //     console.log('失败' + new Date().getTime())
                                  //     this.saveDisabled = false
                                  //   })
                                })
                                .catch(() => {
                                  this.$message({
                                    type: 'info',
                                    message: '已取消报工'
                                  })
                                  this.saveDisabled = false
                                })
                            }
                          } else {
                            this.$message.error('投料是否充足校验失败')
                            this.saveDisabled = false
                          }
                        })
                        .catch((error) => {
                          console.log('失败' + new Date().getTime())
                          this.saveDisabled = false
                        })
                    } else {
                      // 弹出密码框
                      this.tipeInfo = resData.data.message
                      this.showTaskSecretForm = true
                      this.confirmList = list
                      this.saveDisabled = false
                    }
                  } else {
                    this.$message.error('工单数量校验失败')
                    this.saveDisabled = false
                  }
                })
                .catch((error) => {
                  console.log('失败' + new Date().getTime())
                  this.saveDisabled = false
                })
            }
          } else {
            this.$message.error(validateMsg)
            this.saveDisabled = false
          }
        } else {
          this.$message.warning('无产出数据可提交!')
          this.saveDisabled = false
        }
      }
    },
    // 分段提交
    pieceSubmit(oriList, idx, listDisNumber, nowListIndex) {
      // let maxDisNumber = 0 // 最大盘数
      // for (let j = 0; j < listDisNumber.length; j++) {
      //   maxDisNumber = Math.max(maxDisNumber, listDisNumber[j])
      // }
 
      const disNumber = listDisNumber[nowListIndex]
      const once = 100 // 每次提交数量
      const submitCount = Math.ceil(disNumber / once) // 该条总提交次数
      const count = idx + 1 // 当前第几次
      const loading = this.$loading({
        lock: true,
        text:
          '正在处理序号' +
          (nowListIndex + 1) +
          ' (' +
          (idx * once + 1) +
          '~' +
          Math.min(count * once, disNumber) +
          ')/' +
          disNumber,
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
      // console.log('==========')
      // console.log(nowListIndex)
      // console.log(oriList[nowListIndex])
      const list = []
      list.push(oriList[nowListIndex])
      // 将数据的盘数 分成段后 更新此次盘数
      const thisNumber = Math.min(once, disNumber - idx * once)
      if (thisNumber > 0) {
        // 修改盘数
        list[0].discsNumber = thisNumber
        for (let i = 0; i < list[0].productOutputList.length; i++) {
          list[0].productOutputList[i].disNumber = thisNumber
        }
      }
 
      // console.log(idx)
      // console.log(submitCount)
      // console.log(list)
      // console.log(listDisNumber)
      //
      // setTimeout(() => {
      //   loading.close()
      //   if (nowListIndex < listDisNumber.length - 1 || idx < submitCount - 1) {
      //     idx++
      //     if (disNumber <= idx * once) {
      //       // 下一个序号的
      //       nowListIndex++
      //       idx = 0
      //     }
      //     this.pieceSubmit(oriList, idx, listDisNumber, nowListIndex)
      //   } else {
      //     // 批量提交完成,刷新报工页面数据
      //     this.$message.success('新增成功')
      //     this.innerVisible = false
      //   }
      // }, 2000)
      // 提交
      batchSaveProductMain(list)
        .then((res) => {
          var data = res.data
          if (data.code == 0) {
            // 返回报工主表id,用于刷新页面
            var productMainId = data.data
            // console.log(idx)
            // console.log(submitCount)
            // console.log(listDisNumber)
            loading.close()
            // 已完成数据 消息记录
            this.messageMap['' + nowListIndex] =
              (this.messageMap['' + nowListIndex] || 0) + thisNumber
            if (
              nowListIndex < listDisNumber.length - 1 ||
              idx < submitCount - 1
            ) {
              idx++
              if (disNumber <= idx * once) {
                // 下一个序号的
                nowListIndex++
                idx = 0
              }
              this.pieceSubmit(oriList, idx, listDisNumber, nowListIndex)
            } else {
              // 批量提交完成,刷新报工页面数据
              this.$emit('refreshProductOutputList', productMainId)
              console.log(this.messageMap)
              this.$message.success('新增成功')
              this.innerVisible = false
            }
          } else {
            this.$message.error('新增失败')
          }
          this.saveDisabled = false
          loading.close()
        })
        .catch((error) => {
          loading.close()
          console.log('失败' + new Date().getTime())
          this.saveDisabled = false
          this.showError()
        })
    },
 
    showError() {
      const msg = Object.keys(this.messageMap)
        .map((item, i) => {
          return '序号' + (i + 1) + '已成功新增' + this.messageMap[item] + '条'
        })
        .join(';')
      if (msg) {
        this.$message.error('发生错误! ' + msg)
      }
    },
    confirmSecret() {
      // 准备分量提交-每次100条
      const listDisNumber = [] // 原始盘数
      for (let i = 0; i < this.confirmList.length; i++) {
        listDisNumber.push(this.confirmList[i].discsNumber)
      }
      // 校验投料是否充足
      validateOverFeed(this.confirmList)
        .then((resp) => {
          const respData = resp.data
          if (respData.code == 0) {
            if (respData.data.success) {
              // 分段提交
              this.pieceSubmit(this.confirmList, 0, listDisNumber, 0)
              // batchSaveProductMain(this.confirmList)
              //   .then((response) => {
              //     var data = response.data
              //     if (data.code == 0) {
              //       // 返回报工主表id,用于刷新页面
              //       var productMainId = data.data
              //       this.$message.success('新增成功')
              //       this.$emit('refreshProductOutputList', productMainId)
              //       this.innerVisible = false
              //     } else {
              //       this.$message.error('新增失败')
              //     }
              //     this.saveDisabled = false
              //   })
              //   .catch((error) => {
              //     console.log('失败' + new Date().getTime())
              //     this.saveDisabled = false
              //   })
            } else {
              // 投料不足,提示人工选择
              // respData.data.message
              let confirmInfo = ''
              const confirmMessage = respData.data.message
              confirmMessage.forEach((item) => {
                confirmInfo = confirmInfo + item + ';<br>'
              })
              this.$confirm(
                confirmInfo + '<span style="color:red;">是否继续报工?</span>',
                '提示',
                {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消',
                  type: 'warning',
                  customClass: 'validate-over-feed-message',
                  dangerouslyUseHTMLString: true,
                  closeOnClickModal: false
                }
              )
                .then(() => {
                  // 分段提交
                  this.pieceSubmit(this.confirmList, 0, listDisNumber, 0)
                  // batchSaveProductMain(this.confirmList)
                  //   .then((response) => {
                  //     var data = response.data
                  //     if (data.code == 0) {
                  //       // 返回报工主表id,用于刷新页面
                  //       var productMainId = data.data
                  //       this.$message.success('新增成功')
                  //       this.$emit('refreshProductOutputList', productMainId)
                  //       this.innerVisible = false
                  //     } else {
                  //       this.$message.error('新增失败')
                  //     }
                  //     this.saveDisabled = false
                  //   })
                  //   .catch((error) => {
                  //     console.log('失败' + new Date().getTime())
                  //     this.saveDisabled = false
                  //   })
                })
                .catch(() => {
                  this.$message({
                    type: 'info',
                    message: '已取消报工'
                  })
                  this.saveDisabled = false
                })
            }
          } else {
            this.$message.error('投料是否充足校验失败')
            this.saveDisabled = false
          }
        })
        .catch((error) => {
          console.log('失败' + new Date().getTime())
          this.saveDisabled = false
        })
    }
  },
  watch: {
    currshowlist() {
      this.innerVisible = this.currshowlist
      if (this.currshowlist) {
        this.clickDateArr = []
        this.products = []
        this.isChangeShift = false
        if (this.parentInfo.productOutId == null) {
          // 若是新增时,根据工单、机台去查询当前工单机台下未完成的产出,即存在交接,并且未做完的盘
          /* getShiftProductOutByOpIdAndWsId(
            this.parentInfo.workstationId,
            this.parentInfo.operationTaskId
          ).then((response) => {
            var data = response.data
            if (data.code === 0) {
              if (data.data != null) {
                // 是交班的新增
                const lastShiftProductOut = data.data
                for (let i = 0; i < this.productList.length; i++) {
                  if (
                    this.currentDutyRecord.id !==
                    lastShiftProductOut.dutyRecordId
                  ) {
                    this.productList[i].outBatchNo =
                      lastShiftProductOut.outBatchNo
                    this.productList[i].startMeterMark =
                      lastShiftProductOut.endMeterMark
                    this.productList[i].endMeterMark =
                      lastShiftProductOut.endMeterMark
                    this.isChangeShift = true
                  }
 
                  this.products.push(this.productList[i])
                }
                this.$nextTick(() => {
                  this.$refs.productOutPersonList.clearSelection()
                })
              } else {
                for (let i = 0; i < this.productList.length; i++) {
                  this.products.push(this.productList[i])
                }
                this.$nextTick(() => {
                  this.$refs.productOutPersonList.clearSelection()
                })
              }
            }
          }) */
          for (let i = 0; i < this.productList.length; i++) {
            this.products.push(this.productList[i])
          }
          this.$nextTick(() => {
            this.$refs.productOutPersonList.clearSelection()
          })
        } else {
          for (let i = 0; i < this.productList.length; i++) {
            this.products.push(this.productList[i])
          }
          this.$nextTick(() => {
            this.$refs.productOutPersonList.clearSelection()
          })
        }
      }
    }
  }
}
</script>