hao
2025-05-07 feef207cddc10b94f195e3ed9ca2348479c17941
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
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
<template>
    <view class="container">
        <!-- <view class="title">注塑生产报工</view> -->
 
        <!-- 头 -->
        <view class="head">
            <view class="head-left">
                <view class="head-top">
                    <view class="ry">
                        <view class="ryxx">
 
                            <input class="input-box" type="number" v-model="personCode"
                                @keypress.enter="fetchPersonInfo" placeholder="人员编码">
                            <text v-if="!personCode" class="error-star">*</text>
                            </input>
                        </view>
                        <button @click="fetchPersonInfo" class="confirm-btn">确认</button>
 
                    </view>
                    <view class="cx">
                        <picker mode="selector" :range="lineOptions" v-model="selectedLine" @change="updateLine">
                            <view class=" picker2">
                                {{ lineCode ? lineCode : '选择产线' }}
                                <text v-if="!lineCode" class="error-star">*</text>
                            </view>
                        </picker>
                    </view>
                </view>
                <view class="head-but">
                    <!-- 工单信息 -->
                    <view class="form-group">
                        <label for="orderSelect">工单信息:</label>
                        <picker mode="selector" :range="orderOptions" v-model="selectedOrder"
                            @change="loadOrderDetails">
                            <view class="picker">{{ selectedOrder ? selectedOrder : '请选择工单' }}
                                <text v-if="!selectedOrder" class="error-star">*</text>
                            </view>
 
                        </picker>
                    </view>
                </view>
            </view>
            <view class="head-right">
 
                <text class="capacity-title">当日产能</text>
                <view class="capacity-content">
                    <text>{{ dailyCapacity || 0 }}</text> <!-- 默认值为0 -->
                </view>
            </view>
        </view>
        <!-- 新增的人员信息和产线信息展示区域 -->
        <view class="xzxx">
            <view class="person-info">
                <label>人员信息:</label>
                <text>{{ selectedPerson ? selectedPerson : '暂无人员信息' }}</text>
            </view>
            <view class="line-info">
                <label>产线信息:</label>
                <text>{{ selectedLine ? selectedLine : '暂无产线信息' }}</text>
            </view>
        </view>
        <!-- 工单详情 -->
        <view class="order-details">
            <view class="order-details-row">
                <view class="order-details-column">
                    <text>需求单据:</text>
                    <text>{{ orderDetails.requirementDoc }}</text>
                </view>
                <view class="order-details-column">
                    <text>推荐包装数:</text>
                    <text>{{ orderDetails.bzsl }}</text>
                </view>
            </view>
            <view class="order-details-row">
                <view class="order-details-column">
                    <text>物料编码:</text>
                    <text>{{ orderDetails.itemNo }}</text>
                </view>
                <view class="order-details-column">
                    <text>实际开工时间:</text>
                    <text>{{ orderDetails.productionOrder }}</text>
                </view>
            </view>
            <view class="order-details-row">
                <view class="order-details-column">
                    <text>物料名称:</text>
                    <text>{{ orderDetails.itemname }}</text>
                </view>
                <view class="order-details-column">
                    <text>已生产数:</text>
                    <text>{{ orderDetails.producedQuantity }}</text>
                </view>
            </view>
            <view class="order-details-row">
                <view class="order-details-column">
                    <text>规格型号:</text>
                    <text>{{ orderDetails.itemmodel }}</text>
                </view>
                <view class="order-details-column">
                    <text>订单数量:</text>
                    <text>{{ orderDetails.orderQuantity }}</text>
                </view>
            </view>
        </view>
        <!-- 报工模块 -->
        <view class="baogong">
 
 
            <!--  <view class="baogong-right">
    <view :class="['capacity-content2', checkFirstPass ? 'green-text' : 'red-text']">
       <text :style="{ color: checkFirstPass ? 'green' : 'red' }">{{ checkFirstPass ? '首检合格' : '首检不合格' }}</text>
    </view>
    <view :class="['capacity-content2', checkXJ ? 'green-text' : 'red-text']">
       <text :style="{ color: checkXJ ? 'green' : 'red' }">{{ checkXJ ? '巡检合格' : '巡检不合格' }}</text>
    </view>
    <view :class="['capacity-content2', checkedInspection ? 'green-text' : 'red-text']">
       <text :style="{ color: checkedInspection ? 'green' : 'red' }">{{ checkedInspection ? '设备已点检√' : '设备未点检X' }}</text>
    </view>
    <view class="capacity-content2">
        <text :style="{ color: checkedMaintenance ? 'green' : 'red' }">{{ checkedMaintenance ? '设备已保养√' : '设备未保养X' }}</text>  
       </view>
  </view> -->
            <view class="baogong-right">
                <!-- 首检状态 -->
                <view
                    :class="['capacity-content2', checkFirstPass === null ? 'black-text' : (checkFirstPass ? 'green-text' : 'red-text')]">
                    <text :style="{ color: checkFirstPass === null ? 'black' : (checkFirstPass ? 'green' : 'red') }">
                        {{ checkFirstPass === null ? '首检未做' : (checkFirstPass ? '首检合格' : '首检不合格') }}
                    </text>
                </view>
 
                <!-- 巡检状态 -->
                <view
                    :class="['capacity-content2', checkXJ === null ? 'black-text' : (checkXJ ? 'green-text' : 'red-text')]">
                    <text :style="{ color: checkXJ === null ? 'black' : (checkXJ ? 'green' : 'red') }">
                        {{ checkXJ === null ? '巡检未做' : (checkXJ ? '巡检合格' : '巡检不合格') }}
                    </text>
                </view>
 
                <!-- 设备点检状态 -->
                <view
                    :class="['capacity-content2', checkedInspection === null ? 'black-text' : (checkedInspection ? 'green-text' : 'red-text')]">
                    <text
                        :style="{ color: checkedInspection === null ? 'black' : (checkedInspection ? 'green' : 'red') }">
                        {{ checkedInspection === null ? '设备未点检' : (checkedInspection ? '设备已点检√' : '设备未点检X') }}
                    </text>
                </view>
 
                <!-- 设备保养状态 -->
                <view
                    :class="['capacity-content2', checkedMaintenance === null ? 'black-text' : (checkedMaintenance ? 'green-text' : 'red-text')]">
                    <text
                        :style="{ color: checkedMaintenance === null ? 'black' : (checkedMaintenance ? 'green' : 'red') }">
                        {{ checkedMaintenance === null ? '设备未保养' : (checkedMaintenance ? '设备已保养√' : '设备未保养X') }}
                    </text>
                </view>
            </view>
 
 
            <view class="baogong-left">
                <view class="right-column">
                    <text class="capacity-title"> 报工数量</text>
                    <view class="capacity-contencapacity-contentt">
                        <input class="capacity-content" type="number" v-model="reportedQuantity" placeholder="报工数量" />
                        <text v-if="!reportedQuantity" class="error-star">*</text>
                    </view>
                </view>
 
                <view class="print-button">
                    <button @click="printBarcode" :disabled="isButtonDisabled"
                        class="uni-btn1">{{ isButtonDisabled ? '请稍后...' : '确认打印' }}</button>
 
                </view>
 
                <view class="history-record">
                    <button @click="viewHistory" class="lsjl">历史记录</button <!-- 弹出窗口显示历史记录 -->
                    <view v-if="showHistoryPopup" class="history-popup">
                        <!-- 弹窗头部 -->
                        <view class="popup-header">
                            <text class="popup-title">历史打印信息</text>
                            <!-- 关闭按钮 -->
                            <button class="close-btn" @click="closePopup">×</button>
                        </view>
 
                        <!-- 弹窗内容 -->
                        <view class="popup-content">
                            <!-- 表头 -->
                            <view class="history-header">
                                <view class="header-item" id="tm">打印条码</view>
                                <view class="header-item" id="sl">打印数量</view>
                                <view class="header-item" id="sj">打印时间</view>
                                <view class="header-item" id="ry">打印人</view>
                            </view>
 
                            <!-- 表格内容 -->
                            <scroll-view scroll-y="true" class="history-scroll">
                                <view v-for="(record, index) in historyList" :key="index" class="history-record">
                                    <view class="record-item">{{ record.itemBarcode }}</view>
                                    <view class="record-item">{{ record.quantity }}</view>
                                    <view class="record-item">{{ record.printDate }}</view>
                                    <view class="record-item">{{ record.printedBy }}</view>
                                </view>
                            </scroll-view>
                        </view>
                    </view>
 
                <!--     <button @click="reprintLast" :disabled="isButtonDisabled2" class="uni-btn">{{ isButtonDisabled2 ? '请稍后...' : '补打上一张' }}</button>
                 --></view>
            </view>
 
        </view>
        <!-- 新增的左右布局模块 -->
        <view class="usb-printer-section">
            <!-- 左边的按钮组 -->
            <view class="button-group">
                <!-- <button @click="refreshStatus()" class="refreshStatus">刷新</button> -->
                <!-- <button @click="usbConnect()" class="qrdy">USB连接打印机</button> -->
                <!-- <button @click="isConnect()" class="bd">获取连接状态</button> -->
                <view>
                    <!-- 使用 Flexbox 布局将两个状态文本放在同一行 -->
                    <view class="status-container">
                        <view :class="[networkState.includes('无网络') ? 'error' : 'normal', 'status-item']">
                            {{ networkState }}
                        </view>
                        <view :class="[deviceState.includes('失败') ? 'error' : 'normal', 'status-item']">
                            {{ deviceState }}
                        </view>
                    </view>
    <button @click="reprintLast" :disabled="isButtonDisabled2" class="uni-btn">{{ isButtonDisabled2 ? '请稍后...' : '补打上一张' }}</button>
                
                    <!-- 按钮放在状态文本的下方 -->
                    <!-- <button @click="manualCheck" class="check-button">手动检测</button> -->
                    <view class="version" v-if="version">
                      版本号:{{ version }}
                    </view>
                </view>
 
                <!-- <button @click="createLabel()" class="dycs">打印测试</button> -->
            </view>
 
            <!-- 右边的圆形按钮 -->
            <view class="circle-button">
                <button @click="sendForFirstInspection" class="round-btn">首检送检</button>
            </view>
        </view>
    
    </view>
</template>
 
<script>
    // import JsBarcode from 'jsbarcode'; // 引入 JsBarcode 库
    // import printTemplate from '../../print.js'; // 导入路径向上两级
    // import util from '@/components/kk-printer/utils/util.js';
    // import * as blesdk from '@/components/kk-printer/utils/bluetoolth.js';
    // import kkPrinter from '@/components/kk-printer/index.vue';
    //import CustomToast from '../../CustomToast/CustomToast.vue';
 
    let tsc = require('../../components/gprint/tsc.js')
    let esc = require('../../components/gprint/esc.js')
    let UsbModule = uni.requireNativePlugin("gp-usb")
 
    export default {
        data() {
            return {
                showHistoryPopup: false, // 控制弹出框显示
                selectedPerson: '',
                selectedLine: '',
                selectedOrder: '',
                personOptions: [],
                personList: [], // 存储从后端获取的人员数据
                personIndex: -1,
                personCode: '', //人员编码
                lineCode: '', //产线编码
                lineOptions: [], // 存储产线数据
                lineList: [], // 存储从后端获取的产线数据
                orderOptions: [], // 存储工单数据
                orderList: [], // 存储从后端获取的工单数据
                historyRecords: [], // 用于弹窗中显示的历史打印记录
                dailyList: [],
                version: '1.0.0', // 默认值,如果无法获取则显示此值
                orderDetails: {
                    requirementDoc: '', // 需求单据
                    productionOrder: '', // 生产订单
                    orderQuantity: '', // 订单数量
                    producedQuantity: '', // 已生产数
                    bzsl: '', // 推荐包装数
                    itemId: '', // 物料ID
                    itemNo: '', // 物料编码
                    itemname: '', // 物料名称
                    itemmodel: '' // 规格型号
                },
                lastRequestData: null, // 用于保存最后一次打印的 requestData
                bgs: null,
                reportedQuantity: '',
                dailyCapacity: '0', // 每日产能
                checkedInspection: null, // 默认为未点检
                checkedMaintenance: null, // 默认为未维护
                checkXJ: null,
                checkFirstPass: null,
 
                printData: {
                    STRP1: "001",
                    STRP2: "供应商A",
                    STRP3: "物料编码12345",
                    STRP4: "物料名称ABC",
                    STRP5: "100",
                    STRP6: "2024-09-11",
                    STRP7: "规格型号描述",
                    STRP8: "条码内容",
                    STRP13: "需求单据123"
                },
                historyList: [], // 存储历史打印记录
                personName: '', // 用于显示选中的人员名称
                personId: 0,
                materialInfo: {}, // 存储物料信息
                sendData: '',
                isButtonDisabled: false, // 控制按钮状态
                isButtonDisabled2: false, // 控制按钮状态
                networkState: "检测中...",
                deviceState: "检测中...",
                networkCheckInterval: null,
                usbCheckInterval: null,
                refreshTimer: null, // 存储定时器ID
                networkState: "检测中...",
                deviceState: "检测中...",
                networkModalVisible: false, // 控制网络弹窗是否已显示
                usbModalVisible: false ,// 控制 USB 弹窗是否已显示
                 updateChecked: false,
            };
        },
        // components:{
        //     kkPrinter
        // },
        onReady() {
            setTimeout(() => {
                this.checkUsbStatus(); // 延迟检测 USB 状态,避免初始化未完成
            }, 1000);
        },
 
        mounted() {
            this.startUsbCheck(); // 定时检查 USB 连接状态
            this.startRandomRefresh(); // 进入页面开始随机刷新
            this.loadPersons(); // 在组件挂载时加载人员信息
            this.loadLines(); // 在组件挂载时加载产线信息          
            console.log("页面加载,开始检测 USB 和网络...");
            console.log("UsbModule:", UsbModule); // 打印 UsbModule 是否可用
            console.log("UsbModule.isUsbConnect:", UsbModule?.isUsbConnect); // 打印方法是否存在
 if (typeof plus !== 'undefined') {
    this.version = plus.runtime.version;
  }
 
            this.checkForUpdate(); // 启动时检查版本更新
            //this.startAutoUpdateCheck(); // 开始定时检查版本更新
            this.listenNetworkStatus(); // 实时监听网络变化
 
            this.manualCheck(); // 进入页面先检测一次
            this.startNetworkCheck(); // 定时检查网络状态 
 
            this.usbConnect();
 
 
        },
        methods: {
            // 开启自动更新检测
            startAutoUpdateCheck() {
                this.updateCheckInterval = setInterval(() => {
                    this.checkForUpdate(); // 每隔一段时间检查更新
                }, 1 * 60 * 1000); // 10 分钟自动检测一次
            },
            beforeDestroy() {
                this.stopAutoUpdateCheck(); // 页面销毁时停止定时器,防止内存泄漏
            },
            checkForUpdate() {
                  if (this.updateChecked) return; 
                uni.request({
                    url: "http://192.168.0.107:10086/update.json", // 你的服务器 JSON 文件地址
                    success: (res) => {
                        let newVersion = res.data.version;
                        let currentVersion = plus.runtime.version; // 获取当前 APK 版本号
                        console.log("当前版本:", currentVersion, "最新版本:", newVersion);
 
                        if (newVersion > currentVersion) {
                            // uni.showModal({
                            //     title: "发现新版本",
                            //     content: "是否下载最新版本?",
                            //     success: (modalRes) => {
                            //         if (modalRes.confirm) {
                            //             this.downloadNewApk(res.data.apkUrl);
                            //         }
                            //     }
                            // });
                            this.downloadNewApk(res.data.apkUrl);
                             this.updateChecked = true; // 标记更新已检查过
                            //      // 如果有新版本,开始下载
                          //download(res.data.apkUrl);
                        }
                    },
                    fail: (err) => {
                        console.error("更新检查失败:", err);
                    }
                });
            },
 
 
            downloadNewApk(apkUrl) {
                uni.showToast({
                    title: "开始下载更新...",
                    icon: "none",
                    duration: 2000
                });
 
                uni.downloadFile({
                    url: apkUrl,
                    success: (res) => {
                        if (res.statusCode === 200) {
                            plus.runtime.install(res.tempFilePath, {
                                force: true
                            }, function() {
                                console.log("安装成功,重启应用");
                                //plus.runtime.restart();
                                   //plus.runtime.quit();
                                // uni.navigateBack()
                            }, function(e) {
                                console.error("安装失败:", e);
                            });
                        }
                    },
                    fail: (err) => {
                        console.error("下载失败:", err);
                        uni.showToast({
                            title: "下载失败,请检查网络",
                            icon: "none",
                            duration: 2000
                        });
                    }
                });
            },
            // 启动随机刷新
            startRandomRefresh() {
                const randomInterval = Math.floor(Math.random() * (30000 - 10000 + 1)) + 10000; // 10~30秒随机时间
                console.log(`下次刷新将在 ${randomInterval / 1000} 秒后执行`);
 
                this.refreshTimer = setTimeout(() => {
                    this.refreshStatus(); // 执行刷新
                    this.startRandomRefresh(); // 递归调用,确保持续刷新
                }, randomInterval);
            },
            // 1. 实时监听网络变化
            listenNetworkStatus() {
                uni.onNetworkStatusChange((res) => {
                    this.networkState = res.isConnected ? "网络连接正常" : "无网络连接";
                    console.log("网络状态变更:", this.networkState);
                    uni.showToast({
                        title: `网络状态: ${this.networkState}`,
                        duration: 1500
                    });
                });
            },
 
            // 2. 每 5 秒检查网络状态
            checkNetworkStatus() {
                uni.getNetworkType({
                    success: (res) => {
                        this.networkState = res.networkType !== "none" ? "网络连接正常" : "无网络连接";
                        console.log("网络检测结果:", this.networkState);
                        if (this.networkState == "无网络连接") {
                            uni.showToast({
                                title: ` ${this.networkState}`,
                                duration: 1500,
                                icon: "none"
                            });
                            // uni.showModal({
                            //         title: ` ${this.networkState}`,
                            //         content: "请检查网络 连接连接",
                            //         showCancel: false,
                            //     success: () => {
                            //             this.modalVisible = false;
 
                            //                                                 }
                            //     });
                        }
 
                    }
                });
            },
 
            startNetworkCheck() {
                this.networkCheckInterval = setInterval(() => {
                    this.checkNetworkStatus();
                }, 5000);
            },
 
            // 3. 每 5 秒检查 USB 连接状态
            checkUsbStatus() {
                try {
                    if (!UsbModule || !UsbModule.isUsbConnect) {
                        throw new Error("UsbModule 未定义或方法不存在");
                    }
 
                    let res = UsbModule.isUsbConnect();
                    this.deviceState = res ? "打印机 连接正常" : "打印机 连接失败";
                    console.log("打印机 检测结果:", this.deviceState);
                    if (this.deviceState == "打印机 连接失败") {
 
                        uni.showToast({
                            title: ` ${this.deviceState}`,
                            duration: 1500,
                            icon: "none"
                        });
                        this.usbConnect();
                        // uni.showModal({
                        //         title: ` ${this.deviceState}`,
                        //         content: "请检查USB 连接连接",
                        //         showCancel: false,
                        //      success: () => {
                        //              this.modalVisible = false;
                        //                  this.usbConnect();
                        //             }
                        //     });
 
                    }
 
                } catch (error) {
 
                    console.error("打印机 检测错误:", error);
                    this.deviceState = "打印机 检测失败";
                    uni.showToast({
                        title: "打印机 检测失败,请检查插件",
                        duration: 2000,
                        icon: "none"
                    });
                    // uni.showModal({
                    //         title: ` ${this.deviceState}`,
                    //         content: "请检查USB 连接连接",
                    //         showCancel: false,
                    //      success: () => {
                    //              this.modalVisible = false;
                    //                 this.usbConnect();
                    //             }
                    //     });
                    this.usbConnect();
 
                }
            },
 
            startUsbCheck() {
                this.usbCheckInterval = setInterval(() => {
                    this.checkUsbStatus();
                    console.log("定时启动成功")
                }, 5000);
            },
 
            // 4. 手动触发检测
            manualCheck() {
                console.log("手动检测执行...");
                this.checkNetworkStatus();
                this.checkUsbStatus();
            },
 
 
 
 
            senUSBData() {
                if (this.sendData == null) {
                    uni.showToast({
                        title: "请先生成指令",
                        duration: 1500
                    })
                    return
                }
                var hexStr = ''
                var data = Array.from(this.sendData)
                for (var i = 0; i < data.length; i++) {
                    var str = Number(data[i]).toString(16)
                    str = str.length == 1 ? "0" + str : str
                    hexStr += str
                }
                //console.log(hexStr)
                var printNum = 1 // 打印次数
                var hexPrintData = ''
                for (var n = 0; n < printNum; n++) {
                    hexPrintData += hexStr
                }
                let res = UsbModule.write(hexPrintData)
                uni.showToast({
                    title: res.msg,
                    duration: 1500
                })
                this.result = '发送长度:' + hexPrintData.length + ";返回结果:" + JSON.stringify(res)
            },
            usbConnect() {
                console.log("111", UsbModule)
                let res = UsbModule.initUsbDevice();
                if (res) {
                    this.deviceState = "打印机 连接正常"
                } else {
                    this.deviceState = "打印机 连接失败"
                }
                uni.showToast({
                    title: this.deviceState,
                    duration: 1500
                })
            },
            isConnect() {
                let res = UsbModule.isUsbConnect();
                if (res) {
                    this.deviceState = "链接状态正常"
                } else {
                    this.deviceState = "链接状态失败"
                }
                uni.showToast({
                    title: this.deviceState,
                    duration: 1500
                })
            },
            disConnect() {
                let res = UsbModule.disUsbConnect();
                if (res) {
                    this.deviceState = ""
                }
                uni.showToast({
                    title: "断开连接成功",
                    duration: 1500
                })
            },
 
            createLabel() {
                var command = tsc.jpPrinter.createNew()
                command.setSize(40, 30)
                command.setGap(2)
                command.setCls()
                command.setText(50, 10, "TSS24.BF2", 1, 1, "打印测试") // 文本
                command.setQR(50, 50, "L", 5, "A", "www.poscom.cn") // 二维码
                command.setBar(50, 180, "128", 64, 1, 2, 4, "200902125410") // 条码
                command.setPagePrint()
                this.sendData = command.getData();
                uni.showToast({
                    title: '标签指令生成成功',
                    duration: 1500
                });
            },
            // onPrint(opt){
            //     let strCmd =blesdk.CreatCPCLPage(560,500,1,0);  
            //     strCmd += blesdk.addCPCLLine(0,210,560,210,3);
            //     strCmd += blesdk.addCPCLText(10,0,'4','3',0,'8.14');
            //     strCmd += blesdk.addCPCLBarCode(270,0,'128',80,0,1,1,'00051');
            //     strCmd += blesdk.addCPCLText(290,80,'7','2',0,'00051');
            //     strCmd += blesdk.addCPCLText(40,110,'3','0',0,'CHICKEN FEET (BONELESS)-Copy-Copy');
            //     strCmd += blesdk.addCPCLSETMAG(2,2);
            //     strCmd += blesdk.addCPCLText(40,150,'55','0',0,'无骨鸡爪 一盒(约1.5磅)');
            //     strCmd += blesdk.addCPCLSETMAG(0,0);
            //     strCmd += blesdk.addCPCLText(350,180,'7','2',0,'2019-08-12');
 
            //     strCmd += blesdk.addCPCLLocation(2);
            //     strCmd += blesdk.addCPCLQRCode(0,220,'M', 2, 6, 'qr code test');
            //     strCmd += blesdk.addCPCLPrint();
            //     this.bufferData = strCmd;
            // },  
            // 加载人员信息
            fetchPersonInfo() {
                console.log('Fetching person info for:', this.personCode); // 检查事件是否触发
 
                if (this.personCode.trim()) {
                    uni.request({
                        url: `http://192.168.0.107:44380/api/persons/${encodeURIComponent(this.personCode)}`, // 修改后的请求路径
                        method: 'GET',
                        header: {
                            'Content-Type': 'application/json'
                        },
                        success: (res) => {
                            if (res.statusCode === 200) {
                                console.log(res.data.personnelName);
                                this.selectedPerson = res.data.personnelName; // 设置人员信息
                                console.log('Person info loaded:', this.selectedPerson);
                            } else {
                                console.error('Failed to fetch person info:', res);
                            }
                        },
                        fail: (err) => {
                            uni.showToast({
                                title: res,
                                icon: 'none',
                                duration: 2000
                            });
                        }
                    });
                }
            },
 
 
            // 加载产线信息
            fetchLineInfo() {
                console.log('Fetching line info for:', this.lineCode); // 检查事件是否触发
 
                if (this.lineCode.trim()) {
                    uni.request({
                        url: `http://192.168.0.107:44380/api/lines/${encodeURIComponent(this.lineCode.trim())}`, // 修改后的请求路径
                        method: 'GET',
                        header: {
                            'Content-Type': 'application/json'
                        },
                        success: (res) => {
                            if (res.statusCode === 200) {
                                console.log('Line info loaded:', res.data.lineNo);
                                this.selectedLine = res.data.lineName; // 设置产线信息
                                console.log('Line info loaded:', this.selectedLine);
                                // 选择完产线后加载对应的工单信息
                                this.loadOrders(this.lineCode);
                                // 选择完产线后加载对应的每日产能信息
                                this.loadDailyCapacity(this.lineCode);
                            } else {
                                console.error('Failed to fetch line info:', res);
                            }
                        },
                        fail: (err) => {
                            uni.showToast({
                                title: res,
                                icon: 'none',
                                duration: 2000
                            });
                        }
                    });
                }
            },
 
            viewHistory() {
                this.fetchHistoryRecords(this.selectedOrder);
                this.showHistoryPopup = true;
 
            },
            // 关闭弹窗
            closePopup() {
                this.showHistoryPopup = false;
            },
            // 获取历史打印记录
            fetchHistoryRecords(orderNo) {
                uni.request({
                    url: `http://192.168.0.107:44380/api/print/printHistory?orderNo=${encodeURIComponent(orderNo)}`,
                    method: 'GET',
                    header: {
                        'Content-Type': 'application/json'
                    },
                    success: (res) => {
                        if (res.statusCode === 200) {
                            // 正确解析后端返回的数据
                            console.log('123', res.data.historyRecords);
                            //获取最新条码
                            this.lastRequestData = res.data.historyRecords[0].itemBarcode;
                            this.oldbgs = res.data.historyRecords[0].quantity;
                            console.log(this.lastRequestData);
                            // 将后端数据映射到前端使用的格式
                            this.historyList = (res.data.historyRecords || []).map(record => ({
                                itemBarcode: record.itemBarcode || '未知条码', // 确保解析字段
                                quantity: record.quantity || '未知数量', // 打印数量字段
                                printDate: record.printDate || '未知时间', // 打印时间
                                printedBy: record.printedBy || '未知用户' // 打印人
                            }));
                            console.log('History records loaded:', this.historyList);
                        } else {
                            console.error('Failed to fetch history records:', res);
                        }
                    },
                    fail: (err) => {
                        console.error('Error fetching history records:', err);
                    }
                });
            },
            // 加载人员信息
            loadPersons() {
                uni.request({
                    url: "http://192.168.0.107:44380/api/persons", // 替换为你的 ASP.NET Core API 地址
                    method: 'GET',
                    header: {
                        'Content-Type': 'application/json'
                    },
                    success: (res) => {
                        if (res.statusCode === 200) {
                            // 过滤掉有空值或无效数据的项
                            //  this.personOptions = res.data.filter(person => person.personName && person.personName.trim());
 
 
                            this.personList = res.data.filter(person =>
                                person.personName && person.personName.trim().length > 0
                            );
                            this.personOptions = this.personList.map(it => it.personName);
                            this.personIndex = -1;
                        } else {
                            console.error('Failed to fetch persons:', res);
                        }
                    },
                    fail: (err) => {
                        console.error('Error fetching persons:', err);
                    }
                });
            },
            // 更新选中的人员名称
            updatePersonName(e) {
                this.personIndex = e.detail.value;
 
                if (this.personIndex == -1) {
                    return;
                }
 
                this.selectedPerson = this.personList[this.personIndex].personName;
                this.personId = this.personList[this.personIndex].personId;
                console.log(this.personId + " :" + this.selectedPerson);
            },
            //加载产线信息
            loadLines() {
                uni.request({
                    url: "http://192.168.0.107:44380/api/lines", // 替换为你的 API 地址
                    method: 'GET',
                    header: {
                        'Content-Type': 'application/json'
                    },
                    success: (res) => {
                        if (res.statusCode === 200) {
                            this.lineList = res.data.filter(line =>
                                line.lineName && line.lineName.trim().length > 0
                            );
                            this.lineOptions = this.lineList.map(it => it.lineName);
                            console.log('Line options loaded:', this.lineOptions);
                        } else {
                            console.error('Failed to fetch lines:', res);
                        }
                    },
                    fail: (err) => {
                        console.error('Error fetching lines:', err);
                    }
                });
            },
            // 更新选中的产线
            updateLine(e) {
                const selectedIndex = e.detail.value; //数组下标
                this.selectedLine = this.lineOptions[selectedIndex];
                this.lineCode = this.lineList[selectedIndex].lineNo; // 保存选中的产线编号
                console.log('Selected line:', this.selectedLine);
                console.log('Selected lineNo:', this.lineNo);
                this.selectedOrder = null;
                // 选择完产线后加载对应的工单信息
                this.loadOrders(this.lineCode);
                // 选择完产线后加载对应的每日产能信息
                this.loadDailyCapacity(this.lineCode);
            },
            // 加载每日产能信息
            loadDailyCapacity(lineNo) {
                uni.request({
                    url: `http://192.168.0.107:44380/api/capacity?lineNo=${encodeURIComponent(lineNo)}`, // 假设你有一个获取每日产能的API
                    method: 'GET',
                    header: {
                        'Content-Type': 'application/json'
                    },
                    success: (res) => {
                        if (res.statusCode === 200 && Array.isArray(res.data) && res.data.length > 0) {
                            // 取出返回数组中的第一个对象的 daily 值
                            console.log(res.data);
                            this.dailyCapacity = res.data[0].daily; // 直接保存每日产能
                            this.checkedInspection = res.data[0].is_DJ == 1;
                            this.checkedMaintenance = res.data[0].is_WH == 1;
                            this.checkXJ = null;
                            this.checkFirstPass = null;
                            console.log('Daily capacity loaded:', this.dailyCapacity);
                        } else {
                            this.dailyCapacity = '暂无数据'; // 或者设置为其他默认值
                            this.checkedInspection = null; // 重置点检状态
                            this.checkedMaintenance = null; // 重置保养状态
                            this.checkXJ = null;
                            this.checkFirstPass = null;
 
                            console.error('Failed to fetch daily capacity or no data:', res);
                        }
                    },
 
                    fail: (err) => {
                        console.error('Error fetching daily capacity:', err);
                    }
                });
            },
            // 加载工单信息
            loadOrders(lineNo) {
                uni.request({
                    url: `http://192.168.0.107:44380/api/orders?lineNo=${encodeURIComponent(lineNo)}`, // 使用存储的lineNo
                    method: 'GET',
                    header: {
                        'Content-Type': 'application/json'
                    },
                    success: (res) => {
                        if (res.statusCode === 200) {
                            this.orderList = res.data.filter(order =>
                                order.orderNo && order.orderNo.trim().length > 0
                            );
                            this.orderOptions = this.orderList.map(it => it.orderNo);
 
                            console.log('Order options loaded:', this.orderOptions);
                        } else {
                            console.error('Failed to fetch orders:', res);
                        }
                    },
                    fail: (err) => {
                        console.error('Error fetching orders:', err);
                    }
                });
            },
            // 更新选中的工单
            loadOrderDetails(e) {
                const selectedIndex = e.detail.value; // 获取选择的索引
                this.selectedOrder = this.orderOptions[selectedIndex]; // 获取选中的工单编号
                this.orderNo = this.orderList[selectedIndex].orderNo; // 保存选中的工单编号
                console.log('tiaoma', this.selectedOrder);
                console.log('Selected orderNo:', this.orderNo);
                this.orderDetails = {
                    requirementDoc: '', // 需求单据
                    productionOrder: '', // 生产订单
                    orderQuantity: '', // 订单数量
                    bzsl: '', // 推荐包装数
                    producedQuantity: '', // 已生产数
                    itemId: '', // 物料ID
                    itemNo: '', // 物料编码
                    itemname: '', // 物料名称
                    itemmodel: '', // 规格型号
 
 
                };
                //20250213 修改历史打印记录为null 
                lastRequestData: null;
                console.log('lastRequestData:', this.lastRequestData);
                // 调用开工工单方法
                this.startProduction();
                // 调用 API 获取工单详情
                uni.request({
                    url: `http://192.168.0.107:44380/api/orderDetails?orderNo=${encodeURIComponent(this.orderNo)}`, // 使用存储的orderNo
                    method: 'GET',
                    header: {
                        'Content-Type': 'application/json'
                    },
                    success: (res) => {
                        console.log('gongdanxinx', res.data);
                        if (res.statusCode === 200) {
                            this.orderDetails = {
                                requirementDoc: res.data.requirementDoc, // 需求单据
                                productionOrder: res.data.productionOrder, // 生产订单
                                orderQuantity: res.data.orderQuantity, // 订单数量
                                bzsl: res.data.bzsl, // 推荐包装数
                                producedQuantity: res.data.producedQuantity, // 已生产数
                                itemId: res.data.itemId, // 物料ID
                                itemNo: res.data.itemNO, // 物料编码
                                itemname: res.data.itemname, // 物料名称
                                itemmodel: res.data.itemmodel, // 规格型号
 
 
                            };
                            // 根据 sj 和 xj 的值来设置首检和巡检状态
                            // 根据 sj 和 xj 的值来设置首检和巡检状态
                            if (res.data.sj === 1) {
                                this.checkFirstPass = true; // 首检合格
                            } else if (res.data.sj === 2) {
                                this.checkFirstPass = false; // 首检不合格
                            } else {
                                this.checkFirstPass = null; // 首检未做
                            }
 
                            if (res.data.xj === 1) {
                                this.checkXJ = true; // 巡检合格
                            } else if (res.data.xj === 2) {
                                this.checkXJ = false; // 巡检不合格
                            } else {
                                this.checkXJ = null; // 巡检未做
                            }
 
 
                            console.log('Order details loaded:', this.orderDetails);
 
                        } else {
                            console.error('Failed to fetch order details:', res);
                        }
                    },
                    fail: (err) => {
                        console.error('Error fetching order details:', err);
                    }
                });
                // 获取历史打印记录
                console.log('12355', this.orderNo);
                this.historyList = [];
                this.fetchHistoryRecords(this.orderNo);
 
 
            },
            //刷新
            refreshStatus() {
                if (!this.lineCode) {
                    console.warn("未选择产线:设备点检和保养状态设置为未做");
                    this.checkedInspection = 0;
                    this.checkedMaintenance = 0;
                }
 
                if (!this.selectedOrder) {
                    console.warn("未选择工单:首检和巡检状态设置为未做");
                    this.checkFirstPass = null;
                    this.checkXJ = null;
                }
                console.log(this.lineCode);
                console.log(this.selectedOrder);
                uni.request({
                    url: `http://192.168.0.107:44380/api/refresh`,
                    method: 'POST',
                    header: {
                        'Content-Type': 'application/json'
                    },
                    data: {
                        lineNo: this.lineCode,
                        orderNo: this.selectedOrder || "N/A" // 未选择工单时使用占位符
                    },
                    success: (res) => {
                        if (res.statusCode === 200 && res.data) {
                            console.log("刷新成功:", res.data);
 
                            // 解析后端返回的数字状态
                            this.checkFirstPass = this.mapStatus(res.data.checkFirstPass); // 映射首检状态
                            this.checkXJ = this.mapStatus(res.data.checkXJ); // 映射巡检状态
                            this.checkedInspection = res.data.checkedInspection === 1; // 点检:1=true, 2=false
                            this.checkedMaintenance = res.data.checkedMaintenance === 1; // 保养:1=true, 2=false
                            console.log("刷新成功:首检", this.checkFirstPass);
                            console.log("刷新成功:巡检", this.checkXJ);
 
 
                            uni.showToast({
                                title: '刷新成功',
                                icon: 'success'
                            });
                        } else {
                            console.error("刷新失败:", res);
                            uni.showToast({
                                title: '刷新失败,数据异常',
                                icon: 'none'
                            });
                        }
                    },
                    fail: (err) => {
                        console.error("刷新接口请求失败:", err);
                        uni.showToast({
                            title: '刷新失败,网络异常',
                            icon: 'none'
                        });
                    }
                });
            },
            mapStatus(status) {
                if (status === 3) {
                    return null; // 未做
                } else if (status === 1) {
                    return true; // 合格
                } else if (status === 2) {
                    return false; // 不合格
                }
                return null; // 默认未做
            },
 
            //开工工单
            startProduction() {
                if (!this.selectedOrder) {
                    uni.showToast({
                        title: '请先选择工单',
                        icon: 'none'
                    });
                    return;
                }
 
                uni.request({
                    url: 'http://192.168.0.107:44380/api/Inspection/startProduction',
                    method: 'POST',
                    header: {
                        'Content-Type': 'application/json'
                    },
                    data: {
                        orderNo: this.selectedOrder, // 传入工单号
                        UserId: this.selectedPerson,
                    },
                    success: (res) => {
                        if (res.statusCode === 200) {
                            uni.showToast({
                                title: res.data.message,
                                icon: 'success'
                            });
                        } else {
                            uni.showToast({
                                title: res.data.message || '开工失败',
                                icon: 'none'
                            });
                        }
                    },
                    fail: (err) => {
                        console.error('开工请求失败:', err);
                        uni.showToast({
                            title: '开工请求失败',
                            icon: 'none'
                        });
                    }
                });
            },
 
            // 格式化日期函数
            formatDate(date) {
                const year = date.getFullYear();
                const month = String(date.getMonth() + 1).padStart(2, '0');
                const day = String(date.getDate()).padStart(2, '0');
                const hours = String(date.getHours()).padStart(2, '0');
                const minutes = String(date.getMinutes()).padStart(2, '0');
                const seconds = String(date.getSeconds()).padStart(2, '0');
                const milliseconds = String(date.getMilliseconds()).padStart(3, '0'); // 毫秒
                return `${year}${month}${day}${hours}${minutes}${seconds}${milliseconds}`;
            },
            formatDate2(date) {
                const year = date.getFullYear();
                const month = String(date.getMonth() + 1).padStart(2, '0');
                const day = String(date.getDate()).padStart(2, '0');
                const hours = String(date.getHours()).padStart(2, '0');
                const minutes = String(date.getMinutes()).padStart(2, '0');
                const seconds = String(date.getSeconds()).padStart(2, '0');
                const milliseconds = String(date.getMilliseconds()).padStart(3, '0'); // 毫秒
 
                //return `${year}/${month}/${day} ${hours}:${minutes}:${seconds}`; // 使用统一的格式:YYYY/MM/DD HH:mm:ss
                return `${year}${month}${day}${hours}${minutes}${seconds}${milliseconds}`;
 
            },
            // 首检送检功能
            sendForFirstInspection() {
                const orderNumber = this.selectedOrder; // 从组件状态中获取工单号
                console.log('Sending for first inspection with order number:', orderNumber);
                console.log('Sending for first inspection with personCode:', this.personCode);
 
                if (orderNumber.trim()) {
                    const requestData = {
                        ReleaseNo: orderNumber, // 使用传入的工单号
                        UserId: this.personCode, // 确保这里有对应的用户ID
 
                    };
                    console.log(requestData);
 
                    uni.request({
                        url: 'http://192.168.0.107:44380/api/Inspection/firstinspection', // 确保请求路径正确
                        method: 'POST',
                        header: {
                            'Content-Type': 'application/json'
                        },
                        data: requestData, // 发送请求数据
                        success: (res) => {
                            if (res.statusCode === 200) {
                                console.log('First inspection submitted successfully:', res.data);
                                uni.showToast({
                                    title: '首检送检成功',
                                    icon: 'success',
                                    duration: 2000
                                });
                            } else {
                                console.error('Failed to send for first inspection:', res);
                                console.error('res.data.message:', res.data.message);
                                uni.showToast({
                                    title: res.data.message,
                                    icon: 'none',
                                    duration: 2000
                                });
                            }
                        },
                        fail: (err) => {
                            console.error('Request failed:', err);
                            uni.showToast({
                                title: '网络错误',
                                icon: 'none',
                                duration: 2000
                            });
                        }
                    });
                } else {
                    uni.showToast({
                        title: '工单号不能为空',
                        icon: 'none',
                        duration: 2000
                    });
                }
            },
 
 
            // 提交报工信息的方法
            printBarcode() {
                // **先检查 USB 连接状态**
                if (!UsbModule || !UsbModule.isUsbConnect || !UsbModule.isUsbConnect()) {
                    uni.showModal({
                        title: ` ${this.networkState}`,
                        content: "请检查打印机连接",
                        showCancel: false,
                        success: () => {
                            this.modalVisible = false;
 
                        }
                    });
                    return; // **USB 连接失败,直接返回,防止执行打印**
                }
                
                uni.request({
                    url: `http://192.168.0.107:44380/api/persons/${encodeURIComponent(this.personCode)}`, // 修改后的请求路径
                    method: 'GET',
                    header: {
                        'Content-Type': 'application/json'
                    },
                    success: (res) => {
                        if (res.statusCode === 200) {
                            console.log(res.data.personnelName);
                            this.selectedPerson = res.data.personnelName; // 设置人员信息
                            console.log('Person info loaded:', this.selectedPerson);
                        } else {
                            console.error('Failed to fetch person info:', res);
                        }
                    },
                    fail: (err) => {
                        uni.showToast({
                            title: res,
                            icon: 'none',
                            duration: 2000
                        });
                    }
                });
 
                // 禁用按钮5秒
                this.isButtonDisabled = true;
                setTimeout(() => {
                    this.isButtonDisabled = false;
                }, 5000);
                // 校验报工数
                if (this.reportedQuantity <= 0 ||
                    Number(this.reportedQuantity) + Number(this.orderDetails.producedQuantity) > Number(this
                        .orderDetails.orderQuantity)) {
                    uni.showToast({
                        title: '报工数无效或超出订单数量,请检查。',
                        icon: 'none',
                        duration: 2000
                    });
                    // 显示自定义的红色背景、白色字体的提示框
                    //   this.$refs.customToast.showToast('报工数无效或超出订单数量,请检查。');
 
 
                    return;
                }
                       
                // 格式化当前时间为"年月日时分秒"格式
                const currentTime = new Date();
                const formattedTime = this.formatDate(currentTime);
                // 构造请求数据
                const requestData = {
                    orderNo: this.selectedOrder,
                    p_person: this.personCode,
                    //reportedQuantity: this.reportedQuantity,
                    itemId: this.orderDetails.itemId,
                    uniqueValue: `${this.orderDetails.itemNo}-${formattedTime}`, // 使用格式化后的时间
                    //itemCode: this.orderDetails.itemNo, // 假设物料编码为itemId
                    //itemSpec: '规格型号', // 这里可改成实际数据
                    quantity: Number(this.reportedQuantity) // 确保是整数
 
                }; 
                this.logPrintEvent("打印前", "打印条码前",requestData.uniqueValue);
                // 将 requestData 保存到 lastRequestData 中
                this.lastRequestData = requestData;
                console.log(requestData);
                console.log(this.selectedPerson);
                try {
                    // 调用后端 API
                    uni.request({
                        url: "http://192.168.0.107:44380/api/print",
                        method: 'POST',
                        header: {
                            'Content-Type': 'application/json'
                        },
                        data: requestData,
                        success: (response) => {
                            if (response.statusCode === 200) {
                                uni.showToast({
                                    title: '数据提交成功',
                                    icon: 'success',
                                    duration: 2000
                                });
                                const currentTime = new Date();
                                const formattedTime2 = this.formatDate2(currentTime);
                                this.lastRequestData = requestData.uniqueValue;
                                // 将打印的条码记录添加到历史记录中
                                this.historyList.push({
                                    itemBarcode: requestData.uniqueValue,
                                    printDate: formattedTime2.toLocaleString(),
                                    printedBy: this.selectedPerson
                                });
                                //显示生产数添加
                                this.orderDetails.producedQuantity = Number(this.orderDetails
                                    .producedQuantity) + Number(this.reportedQuantity);
                                //显示报工数添加
                                this.dailyCapacity = Number(this.dailyCapacity) + Number(this
                                    .reportedQuantity);
                                this.logPrintEvent("打印前", "报工成功", requestData.uniqueValue);
 
                            } else {
                                console.log(response.data.message);
                                uni.showToast({
                                    title: response.data.message,
                                    icon: 'none',
                                    duration: 2000
                                });
                                console.error("Print failed:", response);
                                this.logPrintEvent("打印前", "异常且返回", requestData.uniqueValue);
                                //打印条码
                                return;
                            }
         // **先记录 "打印前" 事件**
                            this.logPrintEvent("打印前", "打印", requestData.uniqueValue);
                            //打印条码
                            console.log('tiaoma', requestData.uniqueValue);
                            console.log('gd', this.orderDetails.productionOrder);
                            console.log('tiaoma', this.selectedOrder);
                            console.log('gys', this.orderDetails.requirementDoc);
                            console.log('wlbm', this.orderDetails.itemNo);
                            console.log('wlmc', this.orderDetails.itemname);
                            console.log('ggxh', this.orderDetails.itemmodel);
                            console.log('sl', this.reportedQuantity);
 
                            // 打印内容样式设置
                            const command = tsc.jpPrinter.createNew();
 
                            // 设置宽度 100mm 和高度 80mm(换算后大约 799x639 像素)
                            command.setSize(100, 80);
 
                            //command.setBackFeed(2.5);
 
                            // 外框线条
                            command.setCls();
                            command.setBox(10, 10, 789, 629); // 外框,距离页面边缘 10px
 
                            // 第一部分:条码、工单号、供应商信息 + 大二维码
                            command.setBar(20, 40, "128", 100, 1, 0, 2, requestData.uniqueValue); // 条码
                            command.setText(20, 40, "TSS24.BF2", 1, 1, "物料条码: ");
                            command.setText(150, 40, "TSS24.BF2", 1, 1, requestData.uniqueValue);
 
                            // 工单号
                            command.setText(20, 100, "TSS24.BF2", 1, 1, "工单号: ");
                            command.setText(150, 100, "TSS24.BF2", 1, 1, this.selectedOrder);
 
                            // 供应商信息
                            command.setText(20, 160, "TSS24.BF2", 1, 1, "需求单据号: ");
                            command.setText(150, 160, "TSS24.BF2", 1, 1, this.orderDetails.requirementDoc);
 
                            // 右侧大二维码
                            command.setQR(550, 100, "L", 6, "A", requestData.uniqueValue); // 大二维码
 
                            // 第二部分:物料编码
                            command.setText(20, 220, "TSS24.BF2", 1, 1, "物料编码: ");
                            command.setText(150, 220, "TSS24.BF2", 1, 1, this.orderDetails.itemNo);
 
 
                            // 第三部分:物料名称
                            command.setText(20, 280, "TSS24.BF2", 1, 1, "物料名称: ");
                            command.setText(150, 280, "TSS24.BF2", 1, 1, this.orderDetails.itemname);
 
                            // 第四部分:数量与需求单据号
                            command.setText(20, 340, "TSS24.BF2", 1, 1, "数量: ");
                            command.setText(120, 340, "TSS24.BF2", 1, 1, this.reportedQuantity);
                            command.setText(200, 340, "TSS24.BF2", 1, 1, "打印人: ");
                            command.setText(290, 340, "TSS24.BF2", 1, 1, this.selectedPerson);
 
 
 
                            // command.setText(290, 340, "FONT 3", 1, 1, this.selectedPerson);
                            // command.setText(290, 340, "TSS24.BF2", 1, 1, encodeURI(this.selectedPerson));
                            command.setText(400, 340, "TSS24.BF2", 1, 1, "打印时间: ");
                            command.setText(530, 340, "TSS24.BF2", 1, 1, this.formatDate2(new Date()));
                            // 第五部分:左侧二维码 + 规格型号
                            command.setQR(20, 400, "L", 5, "A", requestData.uniqueValue); // 左侧二维码
                            command.setText(200, 400, "TSS24.BF2", 1, 1, "规格型号: ");
                            command.setText(200, 440, "TSS24.BF2", 1, 1, this.orderDetails.itemmodel);
 
 
                            command.setText(200, 535, "TSS24.BF2", 1, 1, "慈溪市夏蒙电器有限公司丨注塑车间");
                            command.setText(201, 536, "TSS24.BF2", 1, 1, "慈溪市夏蒙电器有限公司丨注塑车间");
                            // 打印指令
                            command.setPagePrint();
 
                            // command.setFeed(30);
                            this.sendData = command.getData();
 
                    // 1. 执行发送
                    let printResult = this.senUSBData();
                    
                    // 2. 判断发送是否成功
                    if (printResult.success) {
                      // ✅ 发送成功,记录打印日志
                      this.logPrintEvent("打印后", "打印", requestData.uniqueValue);
                    } else {
                      // ❌ 发送失败,提示用户,不记录日志
                      uni.showToast({
                        title: "打印失败,未记录日志",
                        duration: 2000
                      });
                    }
 
                                    this.oldbgs =  this.reportedQuantity;
                            //从新刷新工单信息
                            loadOrderDetails();
                            //从新刷新历史记录
                    
                            this.fetchHistoryRecords(this.orderNo);
 
                        },
                        fail: (err) => {
                            console.error("Error during print request:", err);
                        }
                    });
 
 
                } catch (err) {
                    console.error('Error during print request:', err);
                }
            },
            //  splitTextByWidth(text, maxCharsPerLine) {
            //   const lines = [];
            //   while (text.length > maxCharsPerLine) {
            //     lines.push(text.slice(0, maxCharsPerLine)); // 截取最大长度
            //     text = text.slice(maxCharsPerLine); // 剩下的继续截取
            //   }
            //   lines.push(text); // 最后一行
            //   return lines;
            // },
            
            // 补打上一张记录
            reprintLast() {
                
                // 禁用按钮5秒
                this.isButtonDisabled2 = true;
                setTimeout(() => {
                    this.isButtonDisabled2 = false;
                }, 5000);
                // **先检查 USB 连接状态**
                if (!UsbModule || !UsbModule.isUsbConnect || !UsbModule.isUsbConnect()) {
                    uni.showModal({
                        title: ` ${this.networkState}`,
                        content: "请检查打印机连接",
                        showCancel: false,
                        success: () => {
                            this.modalVisible = false;
                        }
                    });
                    //return; // **USB 连接失败,直接返回,防止执行打印**
                }
                uni.request({
                    url: `http://192.168.0.107:44380/api/persons/${encodeURIComponent(this.personCode)}`, // 修改后的请求路径
                    method: 'GET',
                    header: {
                        'Content-Type': 'application/json'
                    },
                    success: (res) => {
                        if (res.statusCode === 200) {
                            console.log(res.data.personnelName);
                            this.selectedPerson = res.data.personnelName; // 设置人员信息
                            console.log('Person info loaded:', this.selectedPerson);
                        } else {
                            console.error('Failed to fetch person info:', res);
                        }
                    },
                    fail: (err) => {
                        uni.showToast({
                            title: res,
                            icon: 'none',
                            duration: 2000
                        });
                    }
                });
 
                // 补打上一张记录
                this.fetchHistoryRecords(this.orderNo);
                if (!this.lastRequestData) {
                    uni.showToast({
                        title: '没有可补打的记录',
                        icon: 'none',
                        duration: 2000
                    });
                    return;
                }
                console.log("老条码", this.oldbgs);
                // 重新打印上一张记录
                // async reprintLast() {
                //     // 清空上次的数据,确保获取到最新数据
                //     this.lastRequestData = null;
                //     this.bgs = null;
 
                //     // 等待 fetchHistoryRecords 请求完成
                //     await this.fetchHistoryRecords(this.orderNo);
                // console.log("刷新", this.lastRequestData);
                //     // 检查是否有历史记录,如果没有则提示
                //     if (!this.lastRequestData || this.bgs == null) {
                //         uni.showToast({
                //             title: '没有可补打的记录',
                //             icon: 'none',
                //             duration: 2000
                //         });
                //         return;  // 退出,避免继续执行打印
                //     }
              // **记录 "补打前" 事件**
                this.logPrintEvent("打印前", "补打", this.lastRequestData);
                // 打印内容样式设置
                const command = tsc.jpPrinter.createNew();
 
                // 设置宽度 100mm 和高度 80mm(换算后大约 799x639 像素)
                command.setSize(100, 80);
                //command.setBackFeed(2.5);
                // 外框线条
                command.setCls();
                command.setBox(10, 10, 789, 629); // 外框,距离页面边缘 10px
 
                // 第一部分:条码、工单号、供应商信息 + 大二维码
                command.setBar(20, 40, "128", 100, 1, 0, 2, this.lastRequestData); // 条码
                command.setText(20, 40, "TSS24.BF2", 1, 1, "物料条码: ");
                command.setText(150, 40, "TSS24.BF2", 1, 1, this.lastRequestData);
 
                // 工单号
                command.setText(20, 100, "TSS24.BF2", 1, 1, "工单号: ");
                command.setText(150, 100, "TSS24.BF2", 1, 1, this.selectedOrder);
 
                // 供应商信息
                command.setText(20, 160, "TSS24.BF2", 1, 1, "需求单据号: ");
                command.setText(150, 160, "TSS24.BF2", 1, 1, this.orderDetails.requirementDoc);
 
                // 右侧大二维码
                command.setQR(550, 100, "L", 6, "A", this.lastRequestData); // 大二维码
 
                // 第二部分:物料编码
                command.setText(20, 220, "TSS24.BF2", 1, 1, "物料编码: ");
                command.setText(150, 220, "TSS24.BF2", 1, 1, this.orderDetails.itemNo);
 
 
                // 第三部分:物料名称
                command.setText(20, 280, "TSS24.BF2", 1, 1, "物料名称: ");
                command.setText(150, 280, "TSS24.BF2", 1, 1, this.orderDetails.itemname);
 
                // 第四部分:数量与需求单据号
                command.setText(20, 340, "TSS24.BF2", 1, 1, "数量: ");
                command.setText(120, 340, "TSS24.BF2", 1, 1, this.oldbgs);
                command.setText(200, 340, "TSS24.BF2", 1, 1, "打印人: ");
 
 
                command.setText(290, 340, "TSS24.BF2", 1, 1, this.selectedPerson);
                command.setText(400, 340, "TSS24.BF2", 1, 1, "打印时间: ");
                command.setText(530, 340, "TSS24.BF2", 1, 1, this.formatDate2(new Date()));
                // 第五部分:左侧二维码 + 规格型号
                command.setQR(20, 400, "L", 5, "A", this.lastRequestData); // 左侧二维码
                command.setText(200, 400, "TSS24.BF2", 1, 1, "规格型号: ");
                command.setText(200, 440, "TSS24.BF2", 1, 1, this.orderDetails.itemmodel);
 
                // command.setText(350, 510, "TSS24.BF2", 1, 1, "注塑车间");
                // command.setText(351, 511, "TSS24.BF2", 1, 1, "注塑车间");
                command.setText(200, 535, "TSS24.BF2", 1, 1, "慈溪市夏蒙电器有限公司丨注塑车间");
                command.setText(201, 536, "TSS24.BF2", 1, 1, "慈溪市夏蒙电器有限公司丨注塑车间");
 
                // 打印指令
                command.setPagePrint();
                command.setFeed(3);
                this.sendData = command.getData();
            // 1. 执行发送
            let printResult = this.senUSBData();
            
            // 2. 判断发送是否成功
            if (printResult.success) {
            // 发送成功,记录打印日志
              this.logPrintEvent("打印后", "补打", this.lastRequestData);
            } else {
            // 发送失败,提示用户,不记录日志
            uni.showToast({
                title: "打印失败,未记录日志",
                duration: 2000
            });
            }
F
                // 发送数据
                this.senUSBData();
            // **记录 "补打后" 事件**
          
            }
        ,
    logPrintEvent(eventType, printType, barcodeValue) {
          
             
        const requestData = {
            barcode: barcodeValue,  // 条码
            worker: this.personCode,  // 报工人
            eventType: eventType, // "打印前" 或 "打印后"
            printType: printType,  // "打印" 或 "补打"
            orderNo: this.selectedOrder, // 工单号
            line: this.selectedLine ,
            version:this.version// 线体
        };
        console.log(requestData);
        uni.request({
            url: "http://192.168.0.107:44380/api/LogPrintEvent/logEvent",
            method: 'POST',
            header: {
                'Content-Type': 'application/json'
            },
            data: requestData,
            success: (response) => {
                if (response.statusCode === 200) {
                    console.log(`${eventType} - ${printType} 记录成功`);
                } else {
                    console.error(`${eventType} - ${printType} 记录失败:`, response);
                }
            },
            fail: (err) => {
                console.error("请求失败:", err);
            }
        });
    }
        }
    };
</script>
 
<style>
    /* 头 */
    .head {
        display: flex;
        /* 左右布局 */
        background-color: #fff;
        /* 主背景色 */
        padding: 10px;
        /* 整体内边距 */
        gap: 10px;
        /* 间隙 */
        height: 280px;
 
    }
 
    .head-left {
        display: flex;
        height: 280x;
        flex-direction: column;
        width: 60%;
        /* 左侧占40% */
        background-color: #fff;
        /* 左侧背景色 */
        padding: 10px;
        border-radius: 5px;
        /* background-color: #0069d9; */
    }
 
    .head-top {
        display: flex;
        justify-content: space-between;
        /* 左右对齐 */
        background-color: #fff;
        /* 上部背景色 */
        /* padding: 10px; */
        border-radius: 5px;
        height: 100px;
        /* 设置头部区域的固定高度 */
 
    }
 
    .ry {
        width: 48%;
        /* 设置为48%,保证两个输入框并排时不超出宽度 */
        /* background-color: #aaffff; /* 控件背景色 */
 
        border-radius: 3px;
        display: flex;
        margin-bottom: 10px;
        height: 100px;
    }
 
    .cx {
        width: 48%;
        /* 设置为48%,保证两个输入框并排时不超出宽度 */
        /* background-color: #ffff7f; /* 控件背景色 */
        /*        background-color: #8fdd83; */
        border: 1px solid #ddd;
        border-radius: 10px;
        margin-bottom: 10px;
        height: 100%;
        /* 高度填充父容器 */
    }
 
    .ryxx {
        width: 70%;
        /* 确保输入框占满父元素 */
        height: 100%;
        /* 输入框高度填充父元素 */
        display: flex;
        font-size: 35px;
        font-weight: bold;
        border: 1px solid #ddd;
        border-radius: 10px;
        align-items: center;
        /* 垂直居中对齐 */
 
    }
 
    .input-box {
        font-size: 30px;
        font-weight: bold;
    }
 
    .input-box2 {
        width: 100%;
        height: 100%;
        font-size: 20px;
        font-weight: bold;
        background-color: #8fdd83;
        /* 控件背景色 */
        border: 1px solid #ddd;
        border-radius: 10px;
        margin-right: 0;
        /* 去除右侧间距 */
 
    }
 
    .confirm-btn {
        background-color: #ffffff;
        /* 按钮背景色 */
        border: 1px solid #ddd;
        width: 40%;
        border: none;
        /* 无边框 */
        border-radius: 10px;
        /* 圆角 */
        cursor: pointer;
        /* 鼠标悬停时显示手型 */
        font-size: 20px;
        /* 字体大小 */
        font-weight: bold;
        height: 100%;
        /* 按钮高度与输入框一致 */
        display: flex;
        align-items: center;
        /* 垂直居中 */
        justify-content: center;
        /* 水平居中 */
        border: 1px solid #ddd;
 
    }
 
    .confirm-btn:hover {
        background-color: #45a049;
        /* 鼠标悬停时变深 */
    }
 
    .head-but {
        margin-top: 10px;
        width: 100%;
        height: 180px;
 
 
    }
 
 
 
 
 
    .head-right {
        width: 40%;
        /* 右侧占60% */
        background-color: #8fdd83;
        /* 右侧背景色 */
        /* padding: 10px; */
        height: 280px;
        border-radius: 10px;
        /* background-color: #333; */
    }
 
    .capacity-title {
        font-size: 20px;
        font-weight: bold;
 
        height: 15%;
    }
 
    .picker {
        width: 100%;
        font-size: 35px;
        height: 100px;
 
        font-weight: bold;
        display: flex;
        align-items: center;
        /* 垂直居中 */
        justify-content: center;
        /* 水平居中 */
    }
 
    .picker2 {
        width: 100%;
        font-size: 35px;
        height: 100px;
        font-weight: bold;
        display: flex;
        align-items: center;
        /* 垂直居中 */
        justify-content: center;
        /* 水平居中 */
    }
 
    .error-star {
        color: red;
        margin-left: 5px;
        /* 可以根据需要调整位置 */
        font-size: 35px;
        /* 也可以调整大小 */
    }
 
    .capacity-content {
        font-weight: bold;
        font-size: 100px;
        height: 80%;
        display: flex;
        align-items: center;
        /* 垂直居中 */
        justify-content: center;
        /* 水平居中 */
 
        /* color: #fff; */
 
    }
 
    .form-group {
        display: flex;
        flex-direction: column;
        /* 改为纵向排列 */
        border: 1px solid #ddd;
        border-radius: 10px;
        font-size: 20px;
        font-weight: bold;
        height: 155px;
    }
 
 
 
 
 
    .label {
        font-weight: bold;
    }
 
    .text {
        margin-left: 5px;
    }
 
    /* 人员信息和产线信息 */
    .xzxx {
 
        padding: 10px;
        background-color: #FFF;
        /* 背景色 */
        border-radius: 5px;
        /* 圆角 */
        display: flex;
        /* 左右布局 */
    }
 
    .person-line-info {
        display: flex;
        /* 左右布局 */
        justify-content: space-between;
        /* 两边对齐 */
    }
 
    .person-info,
    .line-info {
        font-size: 20px;
        font-weight: bold;
        margin-left: 5px;
        width: 48%;
        /* 各占一半 */
        background-color: #fff;
        /* 背景色 */
        padding: 10px;
        border-radius: 5px;
    }
 
    .order-label {
        margin-bottom: 10px;
        /* 标签和选择器之间的间距 */
    }
 
 
    /* 工单信息 */
    .order-details {
 
        padding: 10px;
        border: 1px solid #ddd;
        /* 添加边框 */
        border-radius: 4px;
        /* 圆角 */
        background-color: #FFF;
        /* 淡灰色背景 */
    }
 
    .order-details text {
        display: block;
        /* 每条信息占一行 */
        margin-bottom: 8px;
        /* 每条信息之间增加间距 */
        font-size: 18px;
        /* 调整字体大小 */
        color: #333;
        /* 字体颜色 */
    }
 
 
    .order-details-row {
        display: flex;
        justify-content: space-between;
        margin-bottom: 10px;
    }
 
 
    .order-details-row {
        display: flex;
        justify-content: space-between;
        margin-bottom: 10px;
    }
 
    .order-details-column {
        flex: 1;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        padding: 0 10px;
    }
 
    .order-details-column text:first-child {
        font-weight: bold;
        margin-right: 10px;
    }
 
    /* 报工模块 */
    .baogong {
        display: flex;
        /* 左右布局 */
 
        background-color: #FFF;
        padding: 10px;
        border-radius: 5px;
    }
 
    .capacity-contencapacity-contentt {
        display: flex;
        /* 左右布局 */
    }
 
    .baogong-left {
        width: 50%;
        /* 左边占50% */
        display: flex;
        flex-direction: column;
        gap: 10px;
        /* 每个元素间的间隙 */
        height: 300px;
        justify-content: space-between;
        /* 上中下均匀分布 */
        margin-left: 5%;
 
    }
 
    .right-column {
        border: 1px solid #ddd;
        border-radius: 10px;
        width: 100%;
        height: 50%;
        display: flex;
        flex-direction: column;
        justify-content: center;
        /* 内容垂直居中 */
    }
 
    .print-button {
        height: 20%;
        /* 中间占20% */
    }
 
    .print-button button {
        width: 100%;
        height: 100%;
        background-color: #3a8a1d;
        color: white;
        border: none;
        border-radius: 10px;
        font-size: 18px;
        display: flex;
        align-items: center;
        /* 垂直居中 */
        justify-content: center;
        /* 水平居中 */
    }
 
    .history-record {
        display: flex;
        justify-content: space-between;
        /* 按钮之间左右对齐 */
        height: 20%;
        width: 100%;
 
    }
 
 
 
    .uni-btn,
    .lsjl {
        font-size: 15px;
        /* 设置字体大小 */
        border: none;
        /* 去掉边框 */
        border-radius: 5px;
        /* 圆角 */
        padding: 10px 20px;
        /* 内边距 */
        cursor: pointer;
        /* 鼠标悬停时显示为手指 */
    }
 
    .uni-btn:hover,
    .lsjl:hover {
        background-color: #ddd;
        /* 悬停时的背景颜色 */
    }
 
    .baogong-right {
        width: 45%;
        /* 右边占50% */
        display: flex;
        height: 300px;
        flex-direction: column;
        gap: 10px;
        /* 每个按钮间的间隙 */
 
 
    }
 
    .black-text text {
        color: black;
    }
 
    .green-text text {
        color: green;
    }
 
    .red-text text {
        color: red;
    }
 
 
    .capacity-content2 {
        width: 95%;
        border-radius: 5px;
        /* border: 1px solid #ddd; */
        background-color: #fff;
        border-radius: 8px;
        text-align: center;
        height: 60px;
        margin-top: 25px;
    }
 
    .capacity-content2 text {
        font-size: 30px;
        color: white;
    }
 
    /* USB 打印机和首检送检按钮的左右布局 */
    .usb-printer-section {
        display: flex;
        /* 左右布局 */
        justify-content: space-between;
        /* 左右两块对齐 */
        margin-top: 20px;
        /* 与上面的内容保持距离 */
        padding: 10px;
        background-color: #fff;
        /* 背景色 */
        border-radius: 5px;
        /* 圆角 */
    }
 
    /* 左边的按钮组 */
    .button-group {
        width: 48%;
        /* 左边占一半 */
    }
 
 
 
    .button-group button {
        width: 100%;
        /* 按钮宽度占满父元素 */
        padding: 10px;
        /* 按钮内边距 */
        margin-bottom: 10px;
        /* 按钮间距 */
        /* background-color: #ddd; */
        /* color: white; */
        border: none;
        /* 去除边框 */
        border-radius: 8px;
        /* 圆角按钮 */
        font-size: 16px;
        /* 字体大小 */
        cursor: pointer;
        /* 鼠标悬浮时显示手型 */
    }
 
    .button-group button:hover {
        background-color: #ddd;
        /* 悬浮时颜色稍微变深 */
    }
 
    /* 右边的圆形按钮 */
    .circle-button {
        width: 48%;
        /* 右边占一半 */
        display: flex;
        justify-content: center;
        align-items: center;
        /* 垂直居中 */
    }
 
    .round-btn {
        width: 200px;
        /* 固定宽度 */
        height: 200px;
        /* 固定高度,保证按钮是圆形 */
        background-color: #8fdd83;
        /* 蓝色背景 */
        /* color: white;*/
        border: none;
        border-radius: 50%;
        /* 圆形按钮 */
        font-size: 25px;
        cursor: pointer;
        /* 使按钮内的文字居中 */
        display: flex;
        /* 使用 flexbox */
        justify-content: center;
        /* 水平居中 */
        align-items: center;
        /* 垂直居中 */
    }
 
    .round-btn:hover {
        background-color: #0069d9;
        /* 悬浮时颜色稍微变深 */
    }
 
    /* 弹出框样式 */
    .history-popup {
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 80%;
        height: 70%;
        background-color: #fff;
        border-radius: 8px;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
        z-index: 1000;
        display: flex;
        flex-direction: column;
    }
 
    .popup-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 10px;
        border-bottom: 1px solid #ccc;
    }
 
    .popup-title {
        font-size: 18px;
        font-weight: bold;
    }
 
    .close-btn {
        background-color: red;
        color: white;
        border: none;
        border-radius: 50%;
        width: 25px;
        height: 25px;
        text-align: center;
        line-height: 25px;
        cursor: pointer;
        display: flex;
        /* 使用 flexbox */
        justify-content: center;
        /* 水平居中 */
        align-items: center;
        /* 垂直居中 */
 
    }
 
 
    .popup-content {
        flex: 1;
        padding: 10px;
        overflow-y: auto;
    }
 
    /* 表头样式 */
    .history-header {
        display: flex;
        justify-content: space-between;
        font-weight: bold;
        border-bottom: 1px solid #ccc;
        padding-bottom: 5px;
        margin-bottom: 5px;
    }
 
    /* 表头和表格内容的每列样式 */
    .header-item,
    .record-item {
        flex: 1;
        /* 每列占据相同的宽度 */
        text-align: center;
        /* 内容居中 */
        padding: 5px;
        word-wrap: break-word;
        /* 允许内容换行 */
        overflow: hidden;
        /* 防止内容溢出 */
        text-overflow: ellipsis;
        /* 溢出时显示省略号 */
    }
 
    /* 表格内容行样式 */
    .history-record {
        display: flex;
        justify-content: space-between;
        border-bottom: 1px solid #eee;
        padding: 5px 0;
        font-size: 14px;
    }
 
    /* 滚动区域 */
    .history-scroll {
        max-height: 300px;
        /* 根据需要调整滚动区域的高度 */
        overflow-y: auto;
    }
 
 
 
    .record-item {
        flex: 1;
        text-align: center;
    }
 
    .status-container {
        display: flex;
 
        justify-content: space-between;
        /* 使两个状态项之间有适当间距 */
        margin-bottom: 10px;
        /* 给按钮留出一些空间 */
    }
 
    .status-item {
        flex: 1;
        /* 让每个状态项占据相等的空间 */
        padding: 10px;
        /* 内边距 */
        margin-right: 10px;
        /* 在两个状态项之间添加一些间距 */
 
        color: white;
        /* 文字颜色 */
        border: none;
        /* 去除边框 */
        border-radius: 8px;
        /* 圆角 */
        font-size: 20px;
        /* 字体大小 */
        display: flex;
        align-items: center;
        /* 垂直居中对齐 */
        justify-content: center;
        /* 水平居中对齐 */
        transition: background-color 0.3s ease;
        /* 添加平滑过渡效果 */
    }
 
    .status-item:last-child {
        margin-right: 0;
        /* 移除最后一个状态项的右边距 */
    }
 
    .normal {
        color: green;
    }
 
    .error {
        color: red;
    }
 
    .check-button {
        width: 100%;
        /* 使按钮宽度与容器宽度一致 */
        box-sizing: border-box;
        /* 确保内边距和边框包含在宽度内 */
    }
</style>