Fixiaobai
2023-10-13 e8308ddac0ba4a1f406e8f63d7e6b6f2541cb770
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
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
<template>
  <div style="padding:0px 14px;height: 100%;overflow: auto;">
    <div class="tabDivClass">
      <div style="height:28px;line-height:28px;">
        <el-divider class="pane-divider" direction="vertical"></el-divider
        ><span style="font-size:14px;font-weight:bold">报告列表</span>
      </div>
    </div>
    <div style="text-align: left;display:flex;justify-content:space-between;">
      <div style="width: 500px;">
        <tselect
          v-model="currProductMainId"
          :columns="productMainColumn"
          :data="productMainList"
          :formatter="labelFormatter"
          @selectChange="changeProductMain()"
        ></tselect>
      </div>
      <!--<el-select
        v-model="currProductMainId"
        placeholder="请选择"
        style="width: 450px;"
        @change="changeProductMain()"
        clearable
      >
        <el-option
          v-for="item in productMainList"
          :key="item.id"
          :label="item.productNo"
          :value="item.id"
        >
          <div style="display: table;width: 450px;">
            <div style="display: table-row;">
              <div style="display: table-cell;width:21%;text-align: center;">
                {{ item.productNo }}
              </div>
              <div style="display: table-cell;width:21%;text-align: center;">
                {{ item.createUser }}
              </div>
              <div style="display: table-cell;width:42%;text-align: center;">
                {{ item.createTime }}
              </div>
              <div style="display: table-cell;text-align: center;">
                {{ item.state == '02submitted' ? '已提交' : '草稿' }}
              </div>
            </div>
          </div>
        </el-option>
      </el-select>-->
      <div style="" class="tracking-change-state-div">
        <el-button
          v-if="
            currProductMainId &&
              currProductMainState == '01draft' &&
              !currentDutyRecord.isConfirm
          "
          type="info"
          class="cancel-btn"
          icon="tracking-btn-cancel"
          @click="cancelProductMain"
          >删除报告</el-button
        >
        <el-button
          v-if="
            currProductMainId &&
              currProductMainState == '01draft' &&
              !currentDutyRecord.isConfirm
          "
          type="success"
          class="submit-btn"
          icon="tracking-btn-submit"
          :disabled="changeStateDisabled"
          @click="changeState('提交报告', 'SUBMIT')"
          >提交报告</el-button
        >
        <el-button
          v-if="
            currProductMainId &&
              currProductMainState == '02submitted' &&
              permissions.product_main_revoke &&
              !currentDutyRecord.isConfirm
          "
          type="danger"
          class="revoke-btn"
          icon="tracking-btn-revoke"
          :disabled="changeStateDisabled"
          @click="changeState('撤销报告', 'REVOKE')"
          >撤销</el-button
        >
      </div>
    </div>
    <el-divider class="tracking-divider"></el-divider>
    <div class="product-out-header">
      <div class="product-out-header-left">
        <el-divider class="pane-divider" direction="vertical"></el-divider
        ><span style="font-size:14px;font-weight:bold">产出</span>
        <div style="margin-left: 50px">
          <el-radio-group v-model="groupStatus">
            <el-radio :label="false">按组报工</el-radio>
            <el-radio :label="true">按人员报工</el-radio>
          </el-radio-group>
        </div>
      </div>
      <div>
        <el-button
          class="out-btn"
          type="primary"
          icon="tracking-btn-out"
          :disabled="currProductMainDisable || currentDutyRecord.isConfirm"
          @click="addProductOut()"
          >新增产出</el-button
        >
        <el-button
          class="batch-out-btn"
          type="primary"
          icon="tracking-btn-out"
          :disabled="currProductMainDisable || currentDutyRecord.isConfirm"
          @click="addBatchProductOut()"
          >批量产出</el-button
        >
        <el-button
          class="submit-out-btn"
          type="primary"
          icon="el-icon-finished"
          v-if="
            currProductMainId &&
              currProductMainState == '01draft' &&
              !currentDutyRecord.isConfirm
          "
          @click="changeProductOutPutState('提交产出', '0')"
          >提交产出</el-button
        >
        <el-button
          class="change-shift-out-btn"
          type="primary"
          icon="el-icon-sort"
          v-if="
            productOutputList.length > 0 &&
              currProductMainState == '01draft' &&
              !currentDutyRecord.isConfirm
          "
          @click="changeProductOutPutState('产出交班', '1')"
          >产出交班</el-button
        >
        <el-button
          class="tracking-out-revoke-btn"
          type="primary"
          icon="el-icon-back"
          v-if="
            currProductMainId &&
              currProductMainState == '01draft' &&
              !currentDutyRecord.isConfirm
          "
          @click="changeProductOutPutState('产出撤回', '2')"
          >产出撤回</el-button
        >
        <el-button
          class="batch-out-del-btn"
          type="primary"
          icon="el-icon-delete"
          v-if="
            productOutputList.length > 0 &&
              currProductMainState == '01draft' &&
              !currentDutyRecord.isConfirm
          "
          @click="batchDelProductOut()"
          >批量删除</el-button
        >
      </div>
    </div>
    <el-table
      ref="productOutTable"
      :data="productOutputList"
      height="320px"
      :header-cell-style="productOutTableHeaderCellStyle"
      :row-class-name="productOutTableRowClassName"
      class="tracking-table"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55"> </el-table-column>
 
      <el-table-column label="序号" width="50px">
        <template slot-scope="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
 
      <el-table-column label="报工单号" prop="productNo" align="center">
      </el-table-column>
      <el-table-column
        label="零件编号"
        prop="partNo"
        align="center"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        label="零件名称"
        prop="partName"
        align="center"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        label="SN号"
        prop="outBatchNo"
        align="center"
        width="120"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        label="载具编号"
        prop="reelNumber"
        align="center"
        width="120"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        label="IFS批次号"
        prop="ifsBatchNo"
        align="center"
        width="120"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        label="起始米标"
        prop="startMeterMark"
        align="center"
        width="100"
      >
      </el-table-column>
      <el-table-column
        label="截止米标"
        prop="endMeterMark"
        align="center"
        width="100"
      >
      </el-table-column>
      <el-table-column
        label="生产数量"
        prop="productQty"
        align="center"
        width="100"
      >
      </el-table-column>
      <el-table-column label="系统号" prop="systemNo" align="center">
      </el-table-column>
      <el-table-column label="工序名称" prop="operationName" align="center">
      </el-table-column>
      <el-table-column
        label="状态"
        prop="state"
        align="center"
        :formatter="formatState"
      >
      </el-table-column>
      <el-table-column label="单位" prop="unit" align="center">
      </el-table-column>
      <el-table-column
        label="生产数量2"
        prop="sproductQty"
        align="center"
        width="100"
      >
      </el-table-column>
      <el-table-column label="单位2" prop="sunit" align="center">
      </el-table-column>
      <el-table-column label="分段描述" prop="segmentDesc" align="center">
      </el-table-column>
      <el-table-column label="报废数量" prop="scrapQty" align="center">
      </el-table-column>
      <el-table-column label="备注" prop="remark" align="center">
      </el-table-column>
      <el-table-column label="操作" align="center" width="150px" fixed="right">
        <template slot-scope="scope">
          <el-tooltip effect="dark" content="编辑" placement="top-start">
            <el-button
              type="text"
              size="small"
              class="blue-but"
              @click="editProductOut(scope.$index, scope.row)"
              :disabled="
                scope.row.state !== '01draft' ||
                  currProductMainDisable ||
                  currentDutyRecord.isConfirm
              "
              >编辑</el-button
            >
          </el-tooltip>
          <el-tooltip effect="dark" content="删除" placement="top-start">
            <el-button
              type="text"
              size="small"
              class="red-but"
              @click="delProductOut(scope.$index, scope.row)"
              :disabled="
                scope.row.state !== '01draft' ||
                  currProductMainDisable ||
                  currentDutyRecord.isConfirm
              "
              >删除</el-button
            >
          </el-tooltip>
          <el-tooltip effect="dark" content="标签" placement="top-start">
            <el-button
              type="text"
              size="small"
              class="blue-but"
              @click="printLabel(scope.row)"
              >标签</el-button
            >
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>
    <div class="product-in-header">
      <div>
        <el-divider class="pane-divider" direction="vertical"></el-divider
        ><span style="font-size:14px;font-weight:bold">投入</span>
      </div>
      <div>
        <el-button
          class="in-btn"
          type="primary"
          icon="tracking-btn-in"
          :disabled="currProductMainDisable || currentDutyRecord.isConfirm"
          @click="openProductInDialog()"
          >投入</el-button
        >
      </div>
    </div>
    <el-table
      ref="productInTable"
      :data="productInputList"
      height="320px"
      :header-cell-style="productInTableHeaderCellStyle"
      :row-class-name="productInTableRowClassName"
      class="tracking-table"
    >
      <el-table-column label="报工单号" prop="productNo" align="center">
      </el-table-column>
      <el-table-column
        label="SN号"
        prop="partBatchNo"
        align="center"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        label="IFS批次号"
        prop="ifsBatchNo"
        align="center"
        width="120"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        label="零件编号"
        prop="partNo"
        align="center"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        label="零件名称"
        prop="partName"
        align="center"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        label="投入数量"
        prop="inputQuantity"
        align="center"
        width="100"
      >
        <template scope="scope">
          <el-input
            size="small"
            v-model="scope.row.inputQuantity"
            placeholder="投入数量"
            :disabled="currProductMainDisable || currentDutyRecord.isConfirm"
          ></el-input>
        </template>
      </el-table-column>
      <el-table-column
        label="可用数量"
        prop="availableStockQuantity"
        align="center"
      >
      </el-table-column>
      <el-table-column label="单位" prop="unit" align="center">
      </el-table-column>
      <el-table-column align="center" width="120px" fixed="right">
        <template slot-scope="scope">
          <el-tooltip effect="dark" content="全投" placement="top-start">
            <el-button
              type="text"
              size="small"
              @click="allIn(scope.$index, scope.row)"
              >全投</el-button
            >
          </el-tooltip>
          <el-tooltip effect="dark" content="保存" placement="top-start">
            <el-button
              type="text"
              size="small"
              @click="addOrUpdateProductIn(scope.row)"
              :disabled="currProductMainDisable || currentDutyRecord.isConfirm"
              >保存</el-button
            >
          </el-tooltip>
          <el-tooltip effect="dark" content="删除" placement="top-start">
            <el-button
              type="text"
              size="small"
              class="red-but"
              @click="delProductIn(scope.$index, scope.row)"
              :disabled="currProductMainDisable || currentDutyRecord.isConfirm"
              >删除</el-button
            >
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>
    <productInDialog
      :currshowlist.sync="showProductInDialog"
      :workstationId="workstationId"
      @handleSelectionChange="selectWorkstationFeed"
    />
    <productOutFormDialog
      :currshowlist.sync="showProductForm"
      :productList="productList"
      :parentInfo="parentInfo"
      :currentDutyRecord="currentDutyRecord"
      :personBoardList="personBoardList"
      @refreshProductOutputList="refreshProductOutputList"
    />
    <batchProductOutFormDialog
      :currshowlist.sync="showBatchProductForm"
      :productList="productList"
      :parentInfo="parentInfo"
      :currentDutyRecord="currentDutyRecord"
      :personBoardList="personBoardList"
      @refreshProductOutputList="refreshProductOutputList"
    />
  </div>
</template>
<style lang="scss" scoped>
.cancel-btn {
  background-image: -webkit-linear-gradient(
    90deg,
    rgba(254, 100, 84, 0.8) 0%,
    rgba(252, 84, 75, 0.8) 50%,
    rgba(250, 69, 65, 0.8) 100%
  );
  background-image: -moz-linear-gradient(
    90deg,
    rgba(254, 100, 84, 0.8) 0%,
    rgba(252, 84, 75, 0.8) 50%,
    rgba(250, 69, 65, 0.8) 100%
  );
  background-image: linear-gradient(
    90deg,
    rgba(254, 100, 84, 0.8) 0%,
    rgba(252, 84, 75, 0.8) 50%,
    rgba(250, 69, 65, 0.8) 100%
  );
  color: #fff;
  border-color: #fbecec;
  border-radius: 10px;
  padding: 6px 15px;
  height: 32px;
}
.cancel-btn >>> span {
  margin-left: 3px;
}
.tracking-change-state-div >>> .tracking-btn-cancel {
  background: url('/img/workbench/icon_cancel.png') center center no-repeat;
  background-size: cover;
}
.tracking-change-state-div >>> .tracking-btn-cancel:before {
  content: '消';
  font-size: 14px;
  visibility: hidden;
}
.submit-btn {
  background-image: -webkit-linear-gradient(
    90deg,
    rgba(80, 213, 118, 0.8) 0%,
    rgba(73, 209, 87, 0.8) 50%,
    rgba(65, 205, 58, 0.8) 100%
  );
  background-image: -moz-linear-gradient(
    90deg,
    rgba(80, 213, 118, 0.8) 0%,
    rgba(73, 209, 87, 0.8) 50%,
    rgba(65, 205, 58, 0.8) 100%
  );
  background-image: linear-gradient(
    90deg,
    rgba(80, 213, 118, 0.8) 0%,
    rgba(73, 209, 87, 0.8) 50%,
    rgba(65, 205, 58, 0.8) 100%
  );
  color: #fff;
  border-color: #fbecec;
  border-radius: 10px;
  padding: 6px 15px;
  height: 32px;
}
.submit-btn >>> span {
  margin-left: 3px;
}
.tracking-change-state-div >>> .tracking-btn-submit {
  background: url('/img/workbench/icon_tracking_submit.png') center center
    no-repeat;
  background-size: cover;
}
.tracking-change-state-div >>> .tracking-btn-submit:before {
  content: '交';
  font-size: 14px;
  visibility: hidden;
}
.revoke-btn {
  background-image: -webkit-linear-gradient(
    90deg,
    rgba(254, 91, 53, 0.8) 0%,
    rgba(245, 68, 50, 0.8) 100%
  );
  background-image: -moz-linear-gradient(
    90deg,
    rgba(254, 91, 53, 0.8) 0%,
    rgba(245, 68, 50, 0.8) 100%
  );
  background-image: linear-gradient(
    90deg,
    rgba(254, 91, 53, 0.8) 0%,
    rgba(245, 68, 50, 0.8) 100%
  );
  color: #fff;
  border-color: #fbecec;
  border-radius: 10px;
  padding: 6px 15px;
  height: 32px;
}
.revoke-btn >>> span {
  margin-left: 3px;
}
.tracking-change-state-div >>> .tracking-btn-revoke {
  background: url('/img/workbench/icon_back.png') center center no-repeat;
  background-size: cover;
}
.tracking-change-state-div >>> .tracking-btn-revoke:before {
  content: '撤';
  font-size: 14px;
  visibility: hidden;
}
.tracking-divider.el-divider {
  margin: 12px 0px 18px;
}
.product-out-header {
  margin-top: 10px;
  margin-bottom: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.product-out-header-left {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.product-out-header >>> .tracking-btn-out {
  background: url('/img/workbench/icon_bgcc.png') center center no-repeat;
  background-size: cover;
  font-size: 14px;
}
 
.product-out-header >>> .tracking-btn-out:before {
  content: '产';
  font-size: 14px;
  visibility: hidden;
}
 
.pane-divider {
  width: 4px;
  background-color: #4283ee;
}
.out-btn {
  background-image: -webkit-linear-gradient(139deg, #5f6eef 0%, #2783ff 100%);
  background-image: -moz-linear-gradient(139deg, #5f6eef 0%, #2783ff 100%);
  background-image: linear-gradient(139deg, #5f6eef 0%, #2783ff 100%);
  color: #fff;
  border-color: #fbecec;
  border-radius: 15px;
  padding: 6px 15px;
}
.out-btn >>> span {
  margin-left: 3px;
}
.batch-out-btn {
  background-image: -webkit-linear-gradient(139deg, #ff8c00 0%, #ffa500 100%);
  background-image: -moz-linear-gradient(139deg, #ff8c00 0%, #ffa500 100%);
  background-image: linear-gradient(139deg, #ff8c00 0%, #ffa500 100%);
  color: #fff;
  border-color: #fbecec;
  border-radius: 15px;
  padding: 6px 15px;
}
.batch-out-btn >>> span {
  margin-left: 3px;
}
.submit-out-btn {
  background-image: -webkit-linear-gradient(139deg, #54d167 0%, #49cb3b 100%);
  background-image: -moz-linear-gradient(139deg, #54d167 0%, #49cb3b 100%);
  background-image: linear-gradient(139deg, #54d167 0%, #49cb3b 100%);
  color: #fff;
  border-color: #fbecec;
  border-radius: 15px;
  padding: 6px 15px;
  font-size: 14px;
}
.submit-out-btn >>> span {
  margin-left: 3px;
  font-size: 12px;
}
.change-shift-out-btn {
  background-image: -webkit-linear-gradient(139deg, #5f6eef 0%, #2783ff 100%);
  background-image: -moz-linear-gradient(139deg, #5f6eef 0%, #2783ff 100%);
  background-image: linear-gradient(139deg, #5f6eef 0%, #2783ff 100%);
  color: #fff;
  border-color: #fbecec;
  border-radius: 15px;
  padding: 6px 15px;
  font-size: 14px;
}
.change-shift-out-btn >>> span {
  margin-left: 3px;
  font-size: 12px;
}
.tracking-out-revoke-btn {
  background-image: -webkit-linear-gradient(139deg, #fc5e40 0%, #f54c3d 100%);
  background-image: -moz-linear-gradient(139deg, #fc5e40 0%, #f54c3d 100%);
  background-image: linear-gradient(139deg, #fc5e40 0%, #f54c3d 100%);
  color: #fff;
  border-color: #fbecec;
  border-radius: 15px;
  padding: 6px 15px;
  font-size: 14px;
}
.tracking-out-revoke-btn >>> span {
  margin-left: 3px;
  font-size: 12px;
}
.batch-out-del-btn {
  background-image: -webkit-linear-gradient(139deg, #e86d61 0%, #e45552 100%);
  background-image: -moz-linear-gradient(139deg, #e86d61 0%, #e45552 100%);
  background-image: linear-gradient(139deg, #e86d61 0%, #e45552 100%);
  color: #fff;
  border-color: #fbecec;
  border-radius: 15px;
  padding: 6px 15px;
  font-size: 14px;
}
.batch-out-del-btn >>> span {
  margin-left: 3px;
  font-size: 12px;
}
.tracking-table >>> .stripe-row {
  background: #f6f9fe;
}
.tracking-table >>> td {
  padding: 3px 0px;
}
.tracking-table >>> .el-button {
  padding: 5px 0px;
}
.tracking-table >>> .el-input .el-input__inner {
  height: 24px;
  line-height: 24px;
}
.product-in-header {
  margin-top: 10px;
  margin-bottom: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.product-in-header-left {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.product-in-header >>> .tracking-btn-in {
  background: url('/img/workbench/icon_bgtr.png') center center no-repeat;
  background-size: cover;
  font-size: 14px;
}
 
.product-in-header >>> .tracking-btn-in:before {
  content: '投';
  font-size: 14px;
  visibility: hidden;
}
.in-btn {
  background-image: -webkit-linear-gradient(139deg, #5f6eef 0%, #2783ff 100%);
  background-image: -moz-linear-gradient(139deg, #5f6eef 0%, #2783ff 100%);
  background-image: linear-gradient(139deg, #5f6eef 0%, #2783ff 100%);
  color: #fff;
  border-color: #fbecec;
  border-radius: 15px;
  padding: 6px 15px;
}
.in-btn >>> span {
  margin-left: 3px;
}
.tabDivClass {
  margin-top: 20px;
  margin-bottom: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
 
.red-but.is-disabled {
  color: #fab6b6;
}
 
.red-but {
  color: red;
}
 
.blue-but.is-disabled {
  color: #aacfff;
}
 
.blue-but {
  color: #006eff;
}
.white-but {
  color: white;
  font-weight: bolder;
}
</style>
<script>
import {
  queryProductMain,
  queryProductMainDetail,
  delProductMain,
  productMainChangeState,
  updateProductInput,
  saveProductInput,
  deleteProductInputById,
  getProductOutInfoById,
  deleteProductOutputById,
  getPrintUrl
} from '@/api/product/personboard'
import productInDialog from './productInDialog.vue'
import productOutFormDialog from './productout-form.vue'
import batchProductOutFormDialog from './batchproductout-form.vue'
import tselect from '@/views/common/ztt-select.vue'
import { mapGetters } from 'vuex'
import {
  changeProductOutPutState,
  deleteProductOutputByIds,
  changeProductOutShiftStatus,
  getShiftProductOutByOpIdAndWsId
} from '../../../api/product/personboard'
import { changeState } from '../../../api/plan/manufacturingorder'
import { value2label } from '../../../util/formatUtil'
export default {
  components: {
    productInDialog,
    productOutFormDialog,
    batchProductOutFormDialog,
    tselect
  },
  props: {
    workstationId: {
      type: Number
    },
    currOperateTask: {
      type: Object,
      default: () => {
        return {}
      }
    },
    currentDutyRecord: {
      type: Object,
      default: () => {
        return {}
      }
    },
    personBoardList: {
      type: Array,
      default: () => {
        return []
      }
    }
  },
  data() {
    return {
      stateTagArr: [
        { value: '01draft', label: '草稿' },
        { value: '02submitted', label: '已提交' },
        { value: '03changeshift', label: '交班' }
      ],
      tableData: [],
      multipleSelection: [],
      productMainColumn: [
        {
          prop: 'productNo',
          label: '报工单号'
        },
        { prop: 'createUser', label: '创建人' },
        { prop: 'createTime', label: '创建时间' },
        {
          prop: 'state',
          label: '状态',
          formatter: (colValue) => {
            var formatVal
            if (colValue === '01draft') {
              formatVal = '草稿'
            } else if (colValue === '02submitted') {
              formatVal = '已提交'
            }
            return formatVal
          }
        }
      ],
      productMainList: [],
      productOutputList: [],
      productInputList: [],
      currProductMainId: null,
      currProductMainNo: null,
      currProductMainState: null,
      currProductMainDisable: false,
      showProductInDialog: false,
      secondTableHeight: null,
      groupStatus: false,
      productList: [],
      parentInfo: {
        workstationId: null,
        operationTaskId: null,
        currProductMainId: null,
        productOutId: null,
        currProductMainNo: null,
        partId: null,
        partNo: null,
        partName: null,
        unit: null,
        sunit: null
      },
      showProductForm: false,
      showBatchProductForm: false,
      changeStateDisabled: false,
      clickChangeStateArr: []
    }
  },
  created() {},
  computed: {
    ...mapGetters(['permissions'])
  },
  methods: {
    labelFormatter(ele) {
      let productMainLabel
      const productMain = this.productMainList.find(
        (item) => ele.id === item.id
      )
      if (productMain !== undefined) {
        productMainLabel =
          '报工单号:' +
          productMain.productNo +
          '       ' +
          '创建人:' +
          productMain.createUser +
          '       ' +
          '状态:' +
          (productMain.state === '02submitted' ? '已提交' : '草稿')
      }
      return productMainLabel
    },
    formatState(row, column, cellValue) {
      return value2label(cellValue, this.stateTagArr)
    },
    productOutTableHeaderCellStyle({ row, column, rowIndex, columnIndex }) {
      let headerStyle = 'background:#599ef4;color:#fff;'
      if (columnIndex === 0) {
        headerStyle += 'border-radius: 6px 0px 0px 0px;'
      } else if (columnIndex === 20) {
        headerStyle += 'border-radius: 0px 6px 0px 0px;'
      }
      return headerStyle
    },
    productOutTableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 === 1) {
        return 'stripe-row'
      } else {
        return ''
      }
    },
    productInTableHeaderCellStyle({ row, column, rowIndex, columnIndex }) {
      let headerStyle = 'background:#599ef4;color:#fff;'
      if (columnIndex === 0) {
        headerStyle += 'border-radius: 6px 0px 0px 0px;'
      } else if (columnIndex === 8) {
        headerStyle += 'border-radius: 0px 6px 0px 0px;'
      }
      return headerStyle
    },
    productInTableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 === 1) {
        return 'stripe-row'
      } else {
        return ''
      }
    },
    // 根据工作站和工单,获取报告列表
    queryProductMain(operationTaskId) {
      return new Promise((resolve, reject) => {
        this.productMainList = []
        if (this.workstationId && this.workstationId != null) {
          var query = {
            workstationId: this.workstationId,
            operationTaskId: operationTaskId
          }
          queryProductMain(query)
            .then((response) => {
              var data = response.data
              if (data.code == 0) {
                this.productMainList = data.data
                resolve()
              } else {
                this.$message.error('获取报告列表失败')
                reject()
              }
            })
            .catch((error) => {
              reject()
            })
        }
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
      console.info(this.multipleSelection)
    },
    // 选中报告
    changeProductMain() {
      if (this.currProductMainId) {
        var currProductMain = this.productMainList.find(
          (item) => item.id === this.currProductMainId
        )
        if (currProductMain != null) {
          this.currProductMainNo = currProductMain.productNo
          this.currProductMainState = currProductMain.state
          // 若报告状态为已提交,则不可修改报告信息
          if (this.currProductMainState == '02submitted') {
            this.currProductMainDisable = true
          } else {
            this.currProductMainDisable = false
          }
          this.queryProductMainDetail(this.currProductMainId)
        } else {
          this.currProductMainNo = null
          this.currProductMainState = null
          this.currProductMainDisable = false
          // 清空投入、产出明细
          this.productOutputList = []
          this.productInputList = []
        }
      } else {
        // 清除当前报工记录时
        this.currProductMainNo = null
        this.currProductMainState = null
        this.currProductMainDisable = false
        // 清空投入、产出明细
        this.productOutputList = []
        this.productInputList = []
        // 获取最新的报告列表
        this.queryProductMain(this.currOperateTask.id)
      }
      this.$emit('spreadParam', this.currProductMainId)
    },
    // 根据报工主表id获取投入、产出明细
    queryProductMainDetail(id) {
      return new Promise((resolve, reject) => {
        this.productOutputList = []
        this.productInputList = []
        queryProductMainDetail(id)
          .then((response) => {
            var code = response.data.code
            if (code == 0) {
              var productMainInfo = response.data.data
              this.productOutputList = productMainInfo.productOutputList
              const productInputs = productMainInfo.productInputList
              if (productInputs != null && productInputs.length > 0) {
                productInputs.forEach((item) => {
                  if (item.availableStockQuantity == null) {
                    item.availableStockQuantity = 0
                  }
                })
              }
              this.productInputList = productInputs
              resolve()
            } else {
              this.$message.error('获取投入产出明细失败')
              reject()
            }
          })
          .catch((error) => {
            reject()
          })
      })
    },
    // 删除报告
    cancelProductMain() {
      if (this.productOutputList.length <= 0) {
        this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            delProductMain(this.currProductMainId)
              .then((response) => {
                var data = response.data
                if (data.code == 0) {
                  this.$message.success('删除报告成功')
                  // 刷新工单报工记录列表、清空页面投入和产出、将当前报工设置为null
                  this.queryProductMain(this.currOperateTask.id)
                  this.productOutputList = []
                  this.productInputList = []
                  this.currProductMainId = null
                  this.currProductMainNo = null
                  this.currProductMainState = null
                  this.currProductMainDisable = false
                  // 刷新人工信息
                  this.$emit('refreshArtificial')
                  // 刷新产出记录
                  this.$emit('refreshProductOutput')
                  // 刷新投料信息
                  this.$emit('refreshFeedsForDel')
                } else {
                  this.$message.error('删除报告失败')
                }
              })
              .catch((error) => {})
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消删除'
            })
          })
      } else {
        this.$message.error('请先删除报告下的产出,再进行【删除报告】操作')
      }
    },
    // 变更报工记录状态
    changeState(desc, event) {
      let canClickFlag = true
      this.clickChangeStateArr.push(new Date().getTime())
      if (this.clickChangeStateArr.length > 1) {
        if (
          this.clickChangeStateArr[this.clickChangeStateArr.length - 1] -
            this.clickChangeStateArr[this.clickChangeStateArr.length - 2] <
          2000
        ) {
          // 小于2秒则认为重复提交
          canClickFlag = false
        }
      }
      if (canClickFlag) {
        // 若是提交报告,则校验当前报工下所有草稿状态的产出的生产数量是否为0,若为0,则需要限制
        let zeroProductFlag = true
        if (event === 'SUBMIT') {
          const zeroProductOutput = this.productOutputList.find((item) => {
            return item.state === '01draft' && Number(item.productQty) === 0
          })
 
          if (zeroProductOutput) {
            zeroProductFlag = false
            // 存在为0的产出,此时进行限制提醒
            this.$message.error(
              'SN号:' +
                zeroProductOutput.outBatchNo +
                ',生产数量为0,不可进行提交!'
            )
          }
        }
        if (zeroProductFlag) {
          this.changeStateDisabled = true
          productMainChangeState(this.currProductMainId, event)
            .then((response) => {
              var data = response.data
              if (data.code == 0) {
                // 刷新工单报工记录列表、选中当前报工记录、刷新工单列表、刷新当前工单信息
                Promise.all([
                  // 刷新工单报工记录列表
                  this.queryProductMain(this.currOperateTask.id)
                ]).then((res) => {
                  // 选中当前报工记录
                  this.changeProductMain()
                  // 刷新工单列表
                  this.$emit('refreshOperateTasks')
                  // 刷新产出记录
                  this.$emit('refreshProductOutput')
                })
                this.$message.success(desc + '成功')
              } else {
                this.$message.error(desc + '失败')
              }
              this.changeStateDisabled = false
            })
            .catch((error) => {
              this.changeStateDisabled = false
            })
        }
      }
    },
    // 弹出投料列表,供报工投入使用
    openProductInDialog() {
      if (this.currProductMainId != null && this.currProductMainId != '') {
        this.showProductInDialog = true
      } else {
        this.$message.warning('请先选择报告或者先填写产出!')
      }
    },
    // 变更产出状态并且进库,
    changeProductOutPutState(desc, type) {
      //
      if (this.multipleSelection.length > 0) {
        // 找出multipleSelection中,生产数量为0的产出,若存在则提醒
        const multipleSelect = this.multipleSelection.find((item) => {
          return Number(item.productQty) === 0
        })
        if (multipleSelect) {
          // 存在为0的产出,此时进行限制提醒
          this.$message.error(
            'SN号:' +
              multipleSelect.outBatchNo +
              ',生产数量为0,不可进行提交!'
          )
        } else {
          let outIds
          let event
          let returnFlag = true
          let changeShiftFlag = true
          let changeShiftNotEmptyFlag = true
          if (type === '0') {
            // 提交产出
            event = 'SUBMIT'
            outIds = this.multipleSelection
              .filter((item) => {
                return item.state === '01draft'
              })
              .map((ele) => {
                return ele.id
              })
          } else if (type === '1') {
            // 产出交班
            event = 'DRAFTTOCHANGESHIFT'
            outIds = this.multipleSelection
              .filter((item) => {
                return item.state === '01draft'
              })
              .map((ele) => {
                return ele.id
              })
            if (outIds.length > 1) {
              changeShiftFlag = false
            }
            if (outIds.length === 0) {
              changeShiftNotEmptyFlag = false
            }
          } else {
            // 产出撤回,产出撤回分2种,一种是交班的撤回、一种是已提交的撤回
 
            const subOutIds = this.multipleSelection
              .filter((item) => {
                return item.state === '02submitted'
              })
              .map((ele) => {
                return ele.id
              })
            const changeOutIds = this.multipleSelection
              .filter((item) => {
                return item.state === '03changeshift'
              })
              .map((ele) => {
                return ele.id
              })
            if (subOutIds.length > 0 && changeOutIds.length <= 0) {
              // 已提交的撤回
              outIds = subOutIds
              event = 'REVOKE'
            } else if (subOutIds.length <= 0 && changeOutIds.length > 0) {
              // 交班的撤回
              outIds = changeOutIds
              event = 'CHANGESHIFTTODRAFT'
            } else {
              returnFlag = false
            }
          }
          if (changeShiftNotEmptyFlag) {
            if (changeShiftFlag) {
              if (returnFlag) {
                changeProductOutPutState(outIds, event)
                  .then((response) => {
                    var data = response.data
                    if (data.code == 0) {
                      this.queryProductMainDetail(this.currProductMainId)
                      this.$message.success(desc + '成功')
                    } else {
                      this.$message.error(desc + '失败')
                    }
                  })
                  .catch((error) => {})
              } else {
                this.$message.error(
                  '只有交班、已提交的产出可进行【产出撤回】,且交班和已提交的产出不能同时进行撤回!'
                )
              }
            } else {
              this.$message.error('只能对一条产出,进行交班!')
            }
          } else {
            this.$message.error('只有草稿状态的产出,才能进行交班操作!')
          }
        }
      } else {
        this.$message.error('请选择' + desc + '的对象')
      }
    },
 
    // 选中需要的投料
    selectWorkstationFeed(val) {
      if (val != null && val.length > 0) {
        for (var i = 0; i < val.length; i++) {
          this.addProductIn(val[i])
        }
      }
      this.showProductInDialog = false
    },
    // 页面新增投入
    addProductIn(inPartInfo) {
      var productInput = {}
      productInput.id = null
      productInput.stockId = inPartInfo.id
      productInput.inputQuantity = null
      productInput.productMainId = this.currProductMainId
      productInput.productNo = this.currProductMainNo
      productInput.partNo = inPartInfo.partNo
      productInput.partName = inPartInfo.partName
      productInput.partDescription = null
      productInput.unit = inPartInfo.unit
      productInput.partBatchNo = inPartInfo.partBatchNo
      productInput.availableStockQuantity = inPartInfo.availableStockQuantity
      this.productInputList.push(productInput)
    },
    // 新增或更新投入信息,若存在id则更新、不存在则新增
    addOrUpdateProductIn(currRow) {
      if (currRow.inputQuantity != null && currRow.inputQuantity.trim != '') {
        if (currRow.id != null) {
          // 修改
          const productIn = {}
          productIn.id = currRow.id
          productIn.inputQuantity = currRow.inputQuantity
          updateProductInput(productIn)
            .then((response) => {
              var data = response.data
              if (data.code == 0) {
                this.$message.success('更新投入成功')
                // 刷新投料信息
                this.$emit('refreshFeedsForDel')
              } else {
                this.$message.error('更新投入失败')
              }
            })
            .catch((error) => {})
        } else {
          // 新增
          const productIn = {}
          productIn.stockId = currRow.stockId
          productIn.productMainId = currRow.productMainId
          productIn.inputQuantity = currRow.inputQuantity
          saveProductInput(productIn)
            .then((response) => {
              var data = response.data
              if (data.code == 0) {
                this.$message.success('添加投入成功')
                currRow.id = data.data
                // 刷新投料信息
                this.$emit('refreshFeedsForDel')
              } else {
                this.$message.error('添加投入失败')
              }
            })
            .catch((error) => {})
        }
      } else {
        this.$message.error('投入不能为空')
      }
    },
    // 删除投入信息,若存在投入id,则需调用后台删除并删除前端投入,若不存在,则只需删除前端投入
    delProductIn(index, currRow) {
      if (currRow.id != null) {
        // 则需调用后台删除并删除前端投入
        deleteProductInputById(currRow.id)
          .then((response) => {
            var data = response.data
            if (data.code == 0) {
              this.productInputList.splice(index, 1)
              this.$message.success('删除投入成功')
              // 刷新投料信息
              this.$emit('refreshFeedsForDel')
            } else {
              this.$message.error('删除投入失败')
            }
          })
          .catch((error) => {})
      } else {
        // 删除前端投入
        this.productInputList.splice(index, 1)
        this.$message.success('删除投入成功')
      }
    },
    // 添加产出
    addProductOut() {
      var productStaffs = []
      var productStaffIds = []
      if (this.currOperateTask.id != null) {
        if (
          this.currentDutyRecord != null &&
          this.currentDutyRecord.id != null
        ) {
          if (this.personBoardList != null && this.personBoardList.length > 0) {
            this.parentInfo.workstationId = this.workstationId
            this.parentInfo.operationTaskId = this.currOperateTask.id
            this.parentInfo.currProductMainId = this.currProductMainId
            this.parentInfo.currProductMainNo = this.currProductMainNo
            this.parentInfo.partId = this.currOperateTask.partId
            this.parentInfo.partNo = this.currOperateTask.partNo
            this.parentInfo.partName = this.currOperateTask.partName
            this.parentInfo.unit = this.currOperateTask.unit
            this.parentInfo.sunit = this.currOperateTask.sunit
            this.parentInfo.productOutId = null
            // 给弹出框产量列表productList赋值
            this.productList = []
            var product
            if (this.groupStatus) {
              // 按人员报工,多条或一条记录
              for (var i = 0; i < this.personBoardList.length; i++) {
                product = {}
                // cxf 0807 不清空会导致n次方的数据
                productStaffs = []
                productStaffIds = []
                productStaffIds.push(this.personBoardList[i].staffId)
                productStaffs.push(this.personBoardList[i].staffNo)
                product.staffName = this.personBoardList[i].staffName
                product.staffNo = this.personBoardList[i].staffNo
                product.productNo = this.currProductMainNo
                product.partId = this.currOperateTask.partId
                product.partNo = this.currOperateTask.partNo
                product.partName = this.currOperateTask.partName
                // product.outBatchNo = this.getDayStr()
                product.outBatchNo = null
                product.reelNumber = null
                product.startMeterMark = 0
                product.endMeterMark = 0
                product.productQty = 0
                product.ifsBatchNo = null
                product.unit = this.currOperateTask.unit
                product.productStaffs = JSON.parse(
                  JSON.stringify(productStaffs)
                )
                product.productStaffIds = JSON.parse(
                  JSON.stringify(productStaffIds)
                )
                product.status = this.groupStatus
                product.systemNo = null
                product.date = null
                product.dutyRecordId = this.currentDutyRecord.id
 
                product.scrapQty = null
                product.segmentDesc = null
                product.remark = null
 
                product.sproductQty = 0
                product.sunit = this.currOperateTask.sunit
 
                this.productList.push(product)
              }
            } else {
              // 按班组报工,一条记录
              var staffName = ''
              var staffNo = ''
              var staffId = ''
              for (let i = 0; i < this.personBoardList.length; i++) {
                staffName += this.personBoardList[i].staffName + ','
              }
              for (let i = 0; i < this.personBoardList.length; i++) {
                staffNo += this.personBoardList[i].staffNo + ','
                productStaffs.push(this.personBoardList[i].staffNo)
              }
              for (let i = 0; i < this.personBoardList.length; i++) {
                staffId += this.personBoardList[i].staffId + ','
                productStaffIds.push(this.personBoardList[i].staffId)
              }
              staffName = staffName.substring(0, staffName.length - 1)
              staffNo = staffNo.substring(0, staffNo.length - 1)
 
              product = {}
              product.staffName = staffName
              product.staffNo = staffNo
              product.productNo = this.currProductMainNo
              product.partId = this.currOperateTask.partId
              product.partNo = this.currOperateTask.partNo
              product.partName = this.currOperateTask.partName
              // product.outBatchNo = this.getDayStr()
              product.outBatchNo = null
              product.reelNumber = null
              product.startMeterMark = 0
              product.endMeterMark = 0
              product.productQty = 0
              product.ifsBatchNo = null
              product.unit = this.currOperateTask.unit
              product.productStaffs = productStaffs
              product.productStaffIds = productStaffIds
              product.status = this.groupStatus
              product.systemNo = null
              product.date = null
              product.dutyRecordId = this.currentDutyRecord.id
 
              product.scrapQty = null
              product.segmentDesc = null
              product.remark = null
 
              product.sproductQty = 0
              product.sunit = this.currOperateTask.sunit
 
              this.productList.push(product)
            }
            // 弹出产量填写的dialog
            this.showProductForm = true
          } else {
            this.$message.warning('当前没有人员,不可进行报工!')
          }
        } else {
          this.$message.warning('当前没有上班记录,不可进行报工!')
        }
      } else {
        this.$message.warning('请先选择工单')
      }
    },
    // 添加批量产出
    addBatchProductOut() {
      if (!this.currOperateTask.id) {
        this.$message.error('请选择工单!')
        return
      }
      // 先判断,是否存在需要交接的产出
      getShiftProductOutByOpIdAndWsId(
        this.workstationId,
        this.currOperateTask.id
      ).then((response) => {
        var data = response.data
        if (data.code === 0) {
          if (data.data != null) {
            // 是交班的新增
            const lastShiftProductOut = data.data
            if (
              this.currentDutyRecord.id !== lastShiftProductOut.dutyRecordId
            ) {
              this.$message.warning(
                '工单下存在交班的产出,不可进行【批量产出】'
              )
            } else {
              let productStaffs = []
              let productStaffIds = []
              if (this.currOperateTask.id != null) {
                if (
                  this.currentDutyRecord != null &&
                  this.currentDutyRecord.id != null
                ) {
                  if (
                    this.personBoardList != null &&
                    this.personBoardList.length > 0
                  ) {
                    this.parentInfo.workstationId = this.workstationId
                    this.parentInfo.operationTaskId = this.currOperateTask.id
                    this.parentInfo.currProductMainId = this.currProductMainId
                    this.parentInfo.currProductMainNo = this.currProductMainNo
                    this.parentInfo.partId = this.currOperateTask.partId
                    this.parentInfo.partNo = this.currOperateTask.partNo
                    this.parentInfo.partName = this.currOperateTask.partName
                    this.parentInfo.unit = this.currOperateTask.unit
                    this.parentInfo.sunit = this.currOperateTask.sunit
                    this.parentInfo.productOutId = null
                    // 给弹出框产量列表productList赋值
                    this.productList = []
                    let product
                    if (this.groupStatus) {
                      // 按人员报工,多条或一条记录
                      for (let i = 0; i < this.personBoardList.length; i++) {
                        product = {}
                        // cxf 0807 不清空会导致n次方的数据
                        productStaffs = []
                        productStaffIds = []
                        productStaffIds.push(this.personBoardList[i].staffId)
                        productStaffs.push(this.personBoardList[i].staffNo)
                        product.staffName = this.personBoardList[i].staffName
                        product.staffNo = this.personBoardList[i].staffNo
                        product.productNo = this.currProductMainNo
                        product.partId = this.currOperateTask.partId
                        product.partNo = this.currOperateTask.partNo
                        product.partName = this.currOperateTask.partName
                        // product.outBatchNo = this.getDayStr()
                        product.outBatchNo = null
                        product.disNumber = null
                        product.productQty = 0
                        product.ifsBatchNo = null
                        product.unit = this.currOperateTask.unit
                        product.productStaffs = JSON.parse(
                          JSON.stringify(productStaffs)
                        )
                        product.productStaffIds = JSON.parse(
                          JSON.stringify(productStaffIds)
                        )
                        product.status = this.groupStatus
                        product.systemNo = null
                        product.date = null
                        product.dutyRecordId = this.currentDutyRecord.id
 
                        product.scrapQty = null
                        product.segmentDesc = null
                        product.remark = null
                        product.outBatchNo = null
                        product.reelNumber = null
 
                        product.sproductQty = 0
                        product.sunit = this.currOperateTask.sunit
 
                        this.productList.push(product)
                      }
                    } else {
                      // 按班组报工,一条记录
                      let staffName = ''
                      let staffNo = ''
                      let staffId = ''
                      for (let i = 0; i < this.personBoardList.length; i++) {
                        staffName += this.personBoardList[i].staffName + ','
                      }
                      for (let i = 0; i < this.personBoardList.length; i++) {
                        staffNo += this.personBoardList[i].staffNo + ','
                        productStaffs.push(this.personBoardList[i].staffNo)
                      }
                      for (let i = 0; i < this.personBoardList.length; i++) {
                        staffId += this.personBoardList[i].staffId + ','
                        productStaffIds.push(this.personBoardList[i].staffId)
                      }
                      staffName = staffName.substring(0, staffName.length - 1)
                      staffNo = staffNo.substring(0, staffNo.length - 1)
 
                      product = {}
                      product.staffName = staffName
                      product.staffNo = staffNo
                      product.productNo = this.currProductMainNo
                      product.partId = this.currOperateTask.partId
                      product.partNo = this.currOperateTask.partNo
                      product.partName = this.currOperateTask.partName
                      // product.outBatchNo = this.getDayStr()
                      product.outBatchNo = null
                      product.disNumber = null
                      product.productQty = 0
                      product.ifsBatchNo = null
                      product.unit = this.currOperateTask.unit
                      product.productStaffs = productStaffs
                      product.productStaffIds = productStaffIds
                      product.status = this.groupStatus
                      product.systemNo = null
                      product.date = null
                      product.dutyRecordId = this.currentDutyRecord.id
 
                      product.scrapQty = null
                      product.segmentDesc = null
                      product.remark = null
                      product.outBatchNo = null
                      product.reelNumber = null
 
                      product.sproductQty = 0
                      product.sunit = this.currOperateTask.sunit
 
                      this.productList.push(product)
                    }
                    // 弹出产量填写的dialog
                    this.showBatchProductForm = true
                  } else {
                    this.$message.warning('当前没有人员,不可进行报工!')
                  }
                } else {
                  this.$message.warning('当前没有上班记录,不可进行报工!')
                }
              } else {
                this.$message.warning('请先选择工单')
              }
            }
          } else {
            let productStaffs = []
            let productStaffIds = []
            if (this.currOperateTask.id != null) {
              if (
                this.currentDutyRecord != null &&
                this.currentDutyRecord.id != null
              ) {
                if (
                  this.personBoardList != null &&
                  this.personBoardList.length > 0
                ) {
                  this.parentInfo.workstationId = this.workstationId
                  this.parentInfo.operationTaskId = this.currOperateTask.id
                  this.parentInfo.currProductMainId = this.currProductMainId
                  this.parentInfo.currProductMainNo = this.currProductMainNo
                  this.parentInfo.partId = this.currOperateTask.partId
                  this.parentInfo.partNo = this.currOperateTask.partNo
                  this.parentInfo.partName = this.currOperateTask.partName
                  this.parentInfo.unit = this.currOperateTask.unit
                  this.parentInfo.sunit = this.currOperateTask.sunit
                  this.parentInfo.productOutId = null
                  // 给弹出框产量列表productList赋值
                  this.productList = []
                  let product
                  if (this.groupStatus) {
                    // 按人员报工,多条或一条记录
                    for (let i = 0; i < this.personBoardList.length; i++) {
                      product = {}
                      // cxf 0807 不清空会导致n次方的数据
                      productStaffs = []
                      productStaffIds = []
                      productStaffIds.push(this.personBoardList[i].staffId)
                      productStaffs.push(this.personBoardList[i].staffNo)
                      product.staffName = this.personBoardList[i].staffName
                      product.staffNo = this.personBoardList[i].staffNo
                      product.productNo = this.currProductMainNo
                      product.partId = this.currOperateTask.partId
                      product.partNo = this.currOperateTask.partNo
                      product.partName = this.currOperateTask.partName
                      // product.outBatchNo = this.getDayStr()
                      product.outBatchNo = null
                      product.disNumber = null
                      product.productQty = 0
                      product.ifsBatchNo = null
                      product.unit = this.currOperateTask.unit
                      product.productStaffs = JSON.parse(
                        JSON.stringify(productStaffs)
                      )
                      product.productStaffIds = JSON.parse(
                        JSON.stringify(productStaffIds)
                      )
                      product.status = this.groupStatus
                      product.systemNo = null
                      product.date = null
                      product.dutyRecordId = this.currentDutyRecord.id
 
                      product.scrapQty = null
                      product.segmentDesc = null
                      product.remark = null
                      product.outBatchNo = null
                      product.reelNumber = null
 
                      product.sproductQty = 0
                      product.sunit = this.currOperateTask.sunit
 
                      this.productList.push(product)
                    }
                  } else {
                    // 按班组报工,一条记录
                    let staffName = ''
                    let staffNo = ''
                    let staffId = ''
                    for (let i = 0; i < this.personBoardList.length; i++) {
                      staffName += this.personBoardList[i].staffName + ','
                    }
                    for (let i = 0; i < this.personBoardList.length; i++) {
                      staffNo += this.personBoardList[i].staffNo + ','
                      productStaffs.push(this.personBoardList[i].staffNo)
                    }
                    for (let i = 0; i < this.personBoardList.length; i++) {
                      staffId += this.personBoardList[i].staffId + ','
                      productStaffIds.push(this.personBoardList[i].staffId)
                    }
                    staffName = staffName.substring(0, staffName.length - 1)
                    staffNo = staffNo.substring(0, staffNo.length - 1)
 
                    product = {}
                    product.staffName = staffName
                    product.staffNo = staffNo
                    product.productNo = this.currProductMainNo
                    product.partId = this.currOperateTask.partId
                    product.partNo = this.currOperateTask.partNo
                    product.partName = this.currOperateTask.partName
                    // product.outBatchNo = this.getDayStr()
                    product.outBatchNo = null
                    product.disNumber = null
                    product.productQty = 0
                    product.ifsBatchNo = null
                    product.unit = this.currOperateTask.unit
                    product.productStaffs = productStaffs
                    product.productStaffIds = productStaffIds
                    product.status = this.groupStatus
                    product.systemNo = null
                    product.date = null
                    product.dutyRecordId = this.currentDutyRecord.id
 
                    product.scrapQty = null
                    product.segmentDesc = null
                    product.remark = null
                    product.outBatchNo = null
                    product.reelNumber = null
 
                    product.sproductQty = 0
                    product.sunit = this.currOperateTask.sunit
 
                    this.productList.push(product)
                  }
                  // 弹出产量填写的dialog
                  this.showBatchProductForm = true
                } else {
                  this.$message.warning('当前没有人员,不可进行报工!')
                }
              } else {
                this.$message.warning('当前没有上班记录,不可进行报工!')
              }
            } else {
              this.$message.warning('请先选择工单')
            }
          }
        }
      })
    },
    // 产出保存之后,刷新页面
    refreshProductOutputList(val) {
      var productMainId = val
      if (productMainId) {
        Promise.all([
          // 刷新报告列表、投入零件列表、产出零件列表
          this.queryProductMain(this.currOperateTask.id),
          this.queryProductMainDetail(productMainId)
        ]).then((res) => {
          // 选中报告列表值
          if (this.productMainList.length > 0) {
            this.currProductMainId = productMainId
            var currProductMain = this.productMainList.find(
              (item) => item.id === this.currProductMainId
            )
            if (currProductMain != null) {
              this.currProductMainNo = currProductMain.productNo
              this.currProductMainState = currProductMain.state
              if (this.currProductMainState == '02submitted') {
                this.currProductMainDisable = true
              } else {
                this.currProductMainDisable = false
              }
            } else {
              this.currProductMainNo = null
            }
          }
          // 刷新投料信息
          this.$emit('refreshFeeds')
          // 刷新人工信息
          this.$emit('refreshArtificial')
          // 刷新产出记录
          this.$emit('refreshProductOutput')
          // 刷新当前工单状态
          this.$emit('refreshCurrOpTask')
        })
      }
    },
    // 编辑修改产出
    editProductOut(index, currRow) {
      // 查询当前产出信息的详情
      getProductOutInfoById(currRow.id)
        .then((response) => {
          var data = response.data
          if (data.code == 0) {
            var productOutInfos = data.data
            if (productOutInfos != null && productOutInfos.length > 0) {
              this.parentInfo.workstationId = this.workstationId
              this.parentInfo.operationTaskId = this.currOperateTask.id
              this.parentInfo.currProductMainId = this.currProductMainId
              this.parentInfo.currProductMainNo = this.currProductMainNo
              this.parentInfo.partId = this.currOperateTask.partId
              this.parentInfo.partNo = this.currOperateTask.partNo
              this.parentInfo.partName = this.currOperateTask.partName
              this.parentInfo.unit = this.currOperateTask.unit
              this.parentInfo.sunit = this.currOperateTask.sunit
              this.parentInfo.productOutId = currRow.id
              this.productList = []
              var product
              for (var i = 0; i < productOutInfos.length; i++) {
                product = {}
                product.staffName = productOutInfos[i].staffName
                product.staffNo = productOutInfos[i].staffNo
                product.staffId = productOutInfos[i].staffId
                product.productNo = this.currProductMainNo
                product.partId = productOutInfos[i].partId
                product.partNo = productOutInfos[i].partNo
                product.partName = productOutInfos[i].partName
                product.outBatchNo = productOutInfos[i].outBatchNo
                product.reelNumber = productOutInfos[i].reelNumber
                product.startMeterMark = productOutInfos[i].startMeterMark
                product.endMeterMark = productOutInfos[i].endMeterMark
                product.productQty = productOutInfos[i].quantity
                product.unit = productOutInfos[i].unit
                product.systemNo = productOutInfos[i].systemNo
                product.status = productOutInfos[i].status
                product.date = productOutInfos[i].date
                product.dutyRecordId = productOutInfos[i].dutyRecordId
                product.productStaffs = productOutInfos[i].staffNo.split(',')
                product.productStaffIds = productOutInfos[i].staffId.split(',')
                product.ifsBatchNo = productOutInfos[i].ifsBatchNo
 
                product.scrapQty = productOutInfos[i].scrapQty
                product.segmentDesc = productOutInfos[i].segmentDesc
                product.remark = productOutInfos[i].remark
                product.sproductQty = productOutInfos[i].sproductQty
                product.sunit = this.currOperateTask.sunit
 
                this.productList.push(product)
              }
              // 弹出产量填写的dialog
              this.showProductForm = true
            } else {
              this.$message.error('未找到产出详情!')
            }
          } else {
            this.$message.error('未找到产出详情!')
          }
        })
        .catch((error) => {
          console.log('产出信息详情查询异常')
        })
    },
    // 删除产出,若存在产出id,则需调用后台删除并刷新列表,若不存在,则只需删除前端产出
    delProductOut(index, currRow) {
      if (currRow.id != null) {
        // 则需调用后台删除并刷新列表deleteProductOutputById
        this.$confirm('此操作将永久删除该产出, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            deleteProductOutputById(currRow.id)
              .then((response) => {
                var data = response.data
                if (data.code == 0) {
                  this.$message.success('删除产出成功')
                  this.queryProductMainDetail(currRow.productMainId)
                  // 刷新投料信息
                  this.$emit('refreshFeedsForDel')
                  // 刷新人工信息
                  this.$emit('refreshArtificial')
                  // 刷新产出记录
                  this.$emit('refreshProductOutput')
                } else {
                  this.$message.error('删除产出失败')
                }
              })
              .catch((error) => {})
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消删除'
            })
          })
      } else {
        // 删除前端产出
        this.productOutputList.splice(index, 1)
        this.$message.success('删除产出成功')
      }
    },
    // 批量删除产出,只有草稿状态的才能删除01draft state
    batchDelProductOut() {
      if (this.multipleSelection.length > 0) {
        const outIds = this.multipleSelection
          .filter((item) => {
            return item.state === '01draft'
          })
          .map((ele) => {
            return ele.id
          })
        if (outIds.length > 0) {
          deleteProductOutputByIds(outIds)
            .then((response) => {
              var data = response.data
              if (data.code == 0) {
                this.queryProductMainDetail(this.currProductMainId)
                this.$message.success('批量删除成功')
                // 刷新投料信息
                this.$emit('refreshFeedsForDel')
                // 刷新人工信息
                this.$emit('refreshArtificial')
                // 刷新产出记录
                this.$emit('refreshProductOutput')
              } else {
                this.$message.error('批量删除失败')
              }
            })
            .catch((error) => {})
        } else {
          this.$message.error('只有草稿状态的产出,才能进行删除操作')
        }
      } else {
        this.$message.error('请选择批量删除的对象')
      }
    },
    // 获取年月日字符串
    getDayStr() {
      var date = new Date()
      var fullYear = date.getFullYear()
      var month = date.getMonth()
      var day = date.getDate()
      month = month + 1
      var monthStr
      var dayStr
      if (month <= 9) {
        monthStr = '0' + month
      } else {
        monthStr = '' + month
      }
      if (day <= 9) {
        dayStr = '0' + day
      } else {
        dayStr = '' + day
      }
      return fullYear + monthStr + dayStr
    },
    // 初始化页面变量
    initTracking() {
      this.productMainList = []
      this.productOutputList = []
      this.productInputList = []
      this.currProductMainId = null
      this.currProductMainNo = null
      this.currProductMainState = null
      this.currProductMainDisable = null
      this.showProductInDialog = false
      this.secondTableHeight = null
      this.groupStatus = false
      this.productList = []
      this.parentInfo = {
        workstationId: null,
        operationTaskId: null,
        currProductMainId: null,
        productOutId: null,
        currProductMainNo: null,
        partId: null,
        partNo: null,
        partName: null,
        unit: null,
        sunit: null
      }
      this.showProductForm = false
      this.showBatchProductForm = false
    },
    printLabel(row) {
      const queryParam = {
        type: 1,
        id: row.id
      }
      getPrintUrl(queryParam).then((response) => {
        const resData = response.data
        if (resData.code === 0) {
          const url = resData.data
          window.open(url)
        } else {
          this.$message.error('获取积木报表url失败')
        }
      })
    },
    // 全投
    allIn(index, currRow) {
      if (currRow.inputQuantity != null && currRow.inputQuantity != '') {
        currRow.inputQuantity =
          currRow.inputQuantity + currRow.availableStockQuantity
        currRow.inputQuantity = Number(currRow.inputQuantity.toFixed(6))
        currRow.availableStockQuantity = 0
      } else {
        currRow.inputQuantity = currRow.availableStockQuantity
        currRow.availableStockQuantity = 0
      }
    }
  },
  watch: {
    currOperateTask: {
      handler(newValue, oldValue) {
        if (newValue.id) {
          // 查询工单下所有报工productMainList
          this.queryProductMain(newValue.id)
        } else {
          // 清空productMainList
          this.productMainList = []
        }
        // 置空明细、置空当前报工
        this.productOutputList = []
        this.productInputList = []
        this.currProductMainId = null
        this.currProductMainNo = null
        this.currProductMainState = null
        this.currProductMainDisable = false
      },
      deep: true
    },
    workstationId() {
      this.initTracking()
    }
  }
}
</script>