啊鑫
4 天以前 fca192d3c38c5dcfbb6ace8bc71d6078f6a079b2
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
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
<template>
    <view class="inspection-sheet">
        <!-- 头部信息 -->
        <view class="sheet-header">
            <h1>来料检验单</h1>
            <view class="inspection-number">检验单号:{{formData.releaseNo}}</view>
            <!--实验室送检 -->
            <view style="text-align: right;" class="action-buttons">
                <a class="sysLike" v-if="this.current" @click="toSysSubmitFrom(formData.releaseNo)">实验室送检</a>
            </view>
        </view>
 
        <!-- 基本信息区 -->
        <view class="basic-info">
            <view class="info-row">
                <span class="info-label">到货单号:</span>
                <span class="info-value">{{formData.lotNo}}</span>
                <span class="info-label">创建人:</span>
                <span class="info-value">{{formData.createBy}}</span>
            </view>
            <view class="info-row">
                <span class="info-label">创建时间:</span>
                <span class="info-value">{{formData.createDate}}</span>
                <span class="info-label">&nbsp;负责人:</span>
                <span class="info-value">{{formData.userName}}</span>
            </view>
        </view>
 
        <!-- 物料信息区 -->
        <view class="material-info">
            <view class="info-block">
                <view class="info-label">物料编码:</view>
                <view class="info-value">{{formData.itemNo}}</view>
 
            </view>
            <view class="info-block">
                <view class="info-label">物料名称:</view>
                <view class="info-value">{{formData.itemName}}</view>
            </view>
            <view class="info-block">
                <view class="info-label">规格型号:</view>
                <view class="info-value">{{formData.itemModel}}</view>
            </view>
 
            <view class="info-block">
 
                <view class="info-label" v-if="formData.extendNo1!=null">技改状态:</view>
                <view class="info-value" v-if="formData.extendNo1!=null">{{formData.extendNo1}}</view>
 
 
                <view class="info-label">数量:</view>
                <view class="info-value highlight">{{formData.fcovertQty}}</view>
 
            </view>
            <view class="info-block" v-if="formData.fngDesc!=null">
                <view class="info-label">不良描述:</view>
                <view class="info-value">{{formData.fngDesc}}</view>
            </view>
            <view class="info-block" v-if="formData.newFngDesc!=null">
                <view class="info-label">上次不良:</view>
                <view class="info-value">{{formData.newFngDesc}}</view>
            </view>
        </view>
        <view class="dropdown-row">
            <view class="info-label">不良原因:</view>
            <select id="defect-reason" v-model="badreason" v-if="current">
                <option value=""></option>
                <option value="外观不良">外观不良</option>
                <option value="功能不良">功能不良</option>
            </select>
        </view>
        <view class="dropdown-row">
            <view class="info-label">所属车间:</view>
            <select id="defect-reason" v-model="WORKSHOP" v-if="current">
                <option value=""></option>
                <option value="生产一部">生产一部</option>
                <option value="生产二部">生产二部</option>
                <option value="注塑车间">注塑车间</option>
                <option value="其他">其他</option>
            </select>
        </view>
        <view class="dropdown-row">
            <view class="info-label">评审状态:</view>
            <select id="defect-reason" v-model="PSTYPE" v-if="current">
                <option value=""></option>
                <option value="特采/让步使用">特采/让步使用</option>
                <option value="挑选/返工使用">挑选/返工使用</option>
                <option value="退货">退货</option>
 
            </select>
        </view>
                    <view class="info-block" style="margin-top: 10px;">   
            <view class="info-label">备注:</view>
            <input type="text" id="lotNo1" v-model="formData.lotNo1" 
                               placeholder="请输入备注信息" 
                               style="color: red; font-weight: bold;"/> 
        </view>
        <view class="info-block" style="margin-top: 10px;">   
            <view class="info-label">破坏实验数量:</view>
            <view class="info-value highlight">{{formData.phsy}}</view>
        </view>
        
 
 
 
        
 
 
        <!-- 检验项目表格 -->
        <view class="inspection-table">
            <table>
                <thead>
                    <tr>
                        <th width="20%" style="text-align: center;">检验项目</th>
                        <th width="50%" style="text-align: center;">检验描述</th>
                        <th width="15%" style="text-align: center;">记录(点击)</th>
                    </tr>
                </thead>
                <tbody>
                    <tr v-for="(item, index) in tableData" :key="index">
                        <td>{{ item.fcheckItem }}</td>
                        <td>
                            <view v-if="item.fcheckResu=='合格'" class="watermark approved">
                                {{ getStatusText(item.fcheckResu) }}
                            </view>
                            <view v-if="item.fcheckResu=='不合格'" class="watermark rejected">
                                {{ getStatusText(item.fcheckResu) }}
                            </view>
                            <view v-if="item.fcheckResu==null" class="watermark pending">
                                {{ getStatusText(item.fcheckResu) }}
                            </view>
                            <view class="description-text">{{ item.fcheckItemDesc }}</view>
                        </td>
                        <td>
                            <button v-if="item.current" class="record-btn" @click="fillRecord(item,index)">填写</button>
                            <button v-if="!item.current" class="record-btn" @click="fillRecord(item,index)">查看</button>
                        </td>
                        
                    </tr>
                </tbody>
            </table>
        </view>
 
        <!-- 页面内容区域 -->
        <view class="content-wrapper">
            <!-- 为底部按钮留出空间 -->
        </view>
        
        <!-- 固定在底部的操作按钮区 -->
        <view class="fixed-action-buttons">
            <button class="action-btn" @click="handleEmergencyRelease" v-if="this.current">紧急放行</button>
            <button class="action-btn" @click="handleWithdraw" v-if="this.current">撤回</button>
            <button class="action-btn" @click="getInspectionItems" v-if="this.current">获取检验项目</button>
            <button class="action-btn" @click="addDestruction" v-if="this.current">破坏实验</button>
            <button class="action-btn" @click="uploadImages">上传/查看图片</button>
            <button class="action-btn" @click="fetchDrawingNumber">调取PLM图纸</button>
            <button class="action-btn" @click="viewAttachmentInfo">查看附件信息</button>
            <button class="action-btn" @click="addDefectDescription" v-if="this.current">添加不良描述</button>
            <button class="action-btn primary" @click="submitInspection" v-if="this.current">检验提交</button>
        </view>
        <view v-if="remarksPopup" class="overlay">
            <view class="popup">
                <h3>修改不合格描述</h3>
                <form>
                    <view class="form-group">
                        <label class="form-label">不合格描述:</label>
                        <input class="form-input" type="text" v-model="remarks" />
                    </view>
 
                </form>
                <button class="updateBut" @click="editRemarks">修改</button>
                <button @click="remarksPopup = !remarksPopup">取消</button>
            </view>
        </view>
        
        <view v-if="destructionPopup" class="overlay">
            <view class="popup">
                <h3>破坏实验数量</h3>
                <form>
                    <view class="form-group">
                        <label class="form-label">破坏实验数量:</label>
                        <input class="form-input" type="text" v-model="PHSY" placeholder="留空表示清除数量" />
                    </view>
                </form>
                <div v-if="!isInteger" class="error-message">请输入整数值或留空</div>
                <button class="updateBut" @click="editDestruction">修改</button>
                <button @click="clearDestruction">清除</button>
                <button @click="destructionPopup = !destructionPopup">取消</button>
            </view>
        </view>
        
        <view class="barcode">
            <u-modal :show="drawingShow" title="图纸明细" @confirm="drawingConfirm" @cancel="drawingCancel"
                showCancelButton :z-index="1000">
                <uni-table border stripe emptyText="暂无更多数据" style="margin-left: 5px;margin-right: 5px;height: 400px;max-height: 60vh;overflow-y: auto;">
                    <uni-tr>
                        <uni-th align="center">相关文档</uni-th>
                        <uni-th align="center" width="90">有无关联PDF文件</uni-th>
                        <uni-th align="center" width="90">能否打开文件</uni-th>
                        <uni-th align="center" width="150">操作(点击)</uni-th>
                    </uni-tr>
                    <uni-tr v-for="(item,index) in drawing" style="height: 100px;">
                        <uni-td align="center">{{item.fName}}</uni-td>
                        <uni-td align="center" style="font-size:25px;">
                            <div v-if="item.fRelevantObject==' '" style="color: #E47470;">×</div>
                            <div style="color: #90BA87;" v-else>√</div>
                        </uni-td>
                        <uni-td align="center" style="font-size:25px;">
                            <div v-if="item.isSupported || item.fRelevantObject!=' '" style="color: #90BA87;">√</div>
                            <div style="color: #E47470;" v-else>×</div>
                        </uni-td>
                        <uni-td align="center" class="click-wd">
                            <div @click="openDrawings(item)">打开文档</div>
                        </uni-td>
                    </uni-tr>
                </uni-table>
            </u-modal>
        </view>
        <!-- 附件详情弹窗 -->
        <view v-if="showAttachmentDetail" class="overlay">
            <view class="popup attachment-detail-popup">
                <h3 class="attachment-popup-title">附件详情</h3>
                <div class="attachment-popup-divider"></div>
                <div v-if="selectedAttachment" class="attachment-detail-content">
                    <div class="attachment-detail-row"><span class="attachment-label">ID:</span><span>{{ Math.trunc(selectedAttachment.id) }}</span></div>
                    <div class="attachment-detail-row"><span class="attachment-label">附件名:</span><span>{{ selectedAttachment.fattach }}</span></div>
                    <div class="attachment-detail-row"><span class="attachment-label">类型:</span><span>{{ selectedAttachment.ftype }}</span></div>
                    <div class="attachment-detail-row"><span class="attachment-label">版本:</span><span>{{ selectedAttachment.fversion }}</span></div>
                    <div class="attachment-detail-row"><span class="attachment-label">受控日期:</span><span>{{ selectedAttachment.fdate }}</span></div>
                    <div class="attachment-detail-row"><span class="attachment-label">上传人:</span><span>{{ selectedAttachment.createBy }}</span></div>
                    <div class="attachment-detail-row"><span class="attachment-label">上传时间:</span><span>{{ selectedAttachment.createDate }}</span></div>
                    <div class="attachment-actions-detail">
                        <button class="attachment-action-btn preview-btn" 
                            @click="previewFtpFile(selectedAttachment)" 
                            v-if="isPreviewable(selectedAttachment.fattach)">
                            🔍 在线预览
                        </button>
                        <button class="attachment-action-btn download-btn" 
                            @click="downloadAttachment(selectedAttachment)">
                            📥 下载文件
                        </button>
                    </div>
                </div>
                <div v-else class="attachment-detail-empty">暂无附件信息</div>
                <button class="attachment-popup-close" @click="closeAttachmentDetail">返回附件列表</button>
            </view>
        </view>
        <!-- 附件列表弹窗 -->
        <view v-if="showAttachmentPopup" class="overlay">
            <view class="popup" style="width: 60vw; max-width: 500px;">
                <h3>附件列表</h3>
                <div v-if="attachmentsLoading">加载中...</div>
                <div v-else-if="attachments.length === 0">暂无附件</div>
                <ul class="attachment-list" v-else>
                    <li v-for="item in attachments" :key="item.id">
                        <div class="attachment-info">
                            <span class="attachment-name" @click="showAttachmentDetailDialog(item)">
                                {{ item.fattach }}
                            </span>
                            <div class="attachment-meta">
                                <span class="attachment-type">{{ item.ftype || '未知类型' }}</span>
                            </div>
                        </div>
                        <div class="attachment-actions">
                            <button class="secondary-btn" @click="showAttachmentDetailDialog(item)">详情</button>
                            <button class="secondary-btn preview-btn" @click="previewFtpFile(item)" 
                                v-if="isPreviewable(item.fattach)">预览</button>
                            <button class="secondary-btn" @click="downloadAttachment(item)">下载</button>
                        </div>
                    </li>
                </ul>
                <button class="attachment-popup-close" @click="closeAttachmentPopup">关闭</button>
            </view>
        </view>
        
        <!-- 文件预览弹窗 -->
        <view v-if="showFilePreviewPopup" class="overlay">
            <view class="popup file-preview-popup">
                <h3 class="file-preview-title">{{ previewTitle }}</h3>
                <div class="file-preview-divider"></div>
                <div class="file-preview-content">
                    <!-- 文本内容预览 -->
                    <pre v-if="previewType === 'text'">{{ previewContent }}</pre>
                    
                    <!-- 图片内容预览 -->
                    <view v-else-if="previewType === 'image'" class="image-preview-container">
                        <image :src="previewContent" mode="widthFix" style="width: 100%; max-height: 400px;"></image>
                    </view>
                    
                    <!-- Excel 等 Office 文件提示 -->
                    <view v-else-if="previewType === 'excel'" class="unsupported-preview">
                        <view class="unsupported-icon">📊</view>
                        <view class="unsupported-text">Excel 文件暂不支持在线预览</view>
                        <view class="unsupported-hint">请点击下载按钮获取完整文件</view>
                    </view>
                    
                    <!-- 不支持的文件类型 -->
                    <view v-else class="unsupported-preview">
                        <view class="unsupported-icon">📄</view>
                        <view class="unsupported-text">此文件格式暂不支持预览</view>
                        <view class="unsupported-hint">请点击下载按钮获取完整文件</view>
                    </view>
                </div>
                <div class="file-preview-actions">
                    <button v-if="previewType !== 'text'" class="file-preview-btn download-btn" @click="downloadPreviewFile">📥 下载文件</button>
                    <button class="file-preview-btn close-btn" @click="closeFilePreview">关闭</button>
                </div>
            </view>
        </view>
    </view>
    
</template>
 
<script>
    export default {
        data() {
            return {
                formData: {
                    id: "",
                    releaseNo: "",
                    createBy: "",
                    createDate: "",
                    lotNo: "",
                    itemNo: "",
                    billNo: "",
                    fcovertQty: "",
                    detailMem: "",
                    taskNo: "",
                    fcheckResu: "",
                    boardModel: "",
                    planQty: "",
                    mocode: "",
                    boardStyle: "",
                    itemId: "",
                    emergencyStatus: false,
                    lotNo1: '', 
                    emergency:'',
                    permissionModalVisible: false,
                    permissionAccount: '',
                    hasEmergencyPermission: false,
                    showPopup: false,
                    PHSY:'',
                    EMERGENCY: '0',
                    
                },
                tableData: [],
                remarksPopup: false,
                meomPopup: false,
                current: true,
                drawing: [],
                drawingShow: false,
                badreason: '',
                PSTYPE: '',
                WORKSHOP: '',
                REMARK: '',
                checkState: false,
                writeStatu: true,
                fileName:'',
                originalRemarks: '',
                hasEmergencyPermission: false,
                destructionPopup: false,
                PHSY: '',
                isInteger: true,
                attachments: [],
                showAttachmentPopup: false,
                attachmentsLoading: false,
                selectedAttachment: null,
                showAttachmentDetail: false,
                showFilePreviewPopup: false,
                previewContent: '',
                previewTitle: '',
                previewItemNo: '',
                previewType: '', // 'text', 'image', 'excel', 'unsupported'
                
            }
        },
        onLoad(options) {
            //options中包含了url附带的参数
            let params = options;
            
            
                
            if (params["id"]) {
                this.formData.id = params["id"];
                this.formData.releaseNo = params["releaseNo"];
                this.formData.lotNo = params["lotNo"];
                this.msgId = params["msgId"];
                this.emergency = params["emergency"]
                this.meom = params["meom"]
 
                if (params["current"] === 'A') {
                    this.current = true;
                } else if (params["current"] === 'B') {
                    this.current = false;
                }
 
                if (this.msgId > 0) {
                    this.msgRead();
                }
 
            } else {
                //初始化检验单号
                this.$post({
                    url: "/LLJ/getMaxReleaseNo"
                }).then(res => {
                    this.formData.releaseNo = res.data.tbBillList;
                    this.formData.createBy = this.$loginInfo.account;
                    this.formData.createDate = this.$getDate("yyyy-mm-dd");
                });
 
            }
             if (this.$loginInfo.account === 'PL017') {this.hasEmergencyPermission = true;}
 
             // 测试附件服务器连接
             
 
 
        },
        methods: {
            getStatusText(status) {
                const statusMap = {
                    approved: '合格',
                    rejected: '不合格',
                    pending: '待确认'
                }
                if (status == null) {
                    return statusMap['pending'] || ''
                } else if (status == '合格') {
                    return statusMap['approved'] || ''
                } else {
                    return statusMap['rejected'] || ''
                }
 
            },
            getInspectionItems() {
                // 获取检验项目的逻辑
                this.$post({
                    url: "/LLJ/setJYItem",
                    data: {
                        itemNo: this.formData.itemId,
                        quantity: this.formData.fcovertQty,
                        releaseNo: this.formData.releaseNo,
                        PHSY: this.formData.PHSY
                    }
                }).then(res => {
                    if (res.status == 0) {
                        uni.showToast({
                            title: res.message.toString(),
                            //将值设置为 success 或者直接不用写icon这个参数
                            icon: 'success',
                            //显示持续时间为 2秒
                            duration: 2000
                        })
                        // 如果有页面跳转,需要用定时器延迟
                        setTimeout(() => {
                            this.init();
                        }, 2000);
 
                    } else {
                        uni.showToast({
                            title: res.message.toString(),
                            //将值设置为 success 或者直接不用写icon这个参数
                            icon: 'error',
                            //显示持续时间为 2秒
                            duration: 2000
                        })
                    }
                });
            },
            
            fillRecord(item, index) {
                // 填写记录的逻辑
                uni.navigateTo({
                    url: 'detail?mainId=' + item.id + '&formID=' + this.formData.id + '&releaseNo=' + this.formData
                        .releaseNo + '&index=' + index + '&current=' + this.current
                });
            },
            uploadImages() {
                // 上传/查看图片的逻辑
                uni.navigateTo({
                    url: 'ImageItem?id=' + this.formData.id
                });
            },
            addDefectDescription() {
                // 添加不良描述的逻辑
                this.remarksPopup = !this.remarksPopup;
                this.remarks = this.formData.remarks;
            },
            submitInspection() {
                if (this.PSTYPE == '') {
                    this.writeStatu = false
                }
                if (this.badreason == '') {
                    this.writeStatu = false
                }
                if (this.DEPARTMENT == '') {
                    this.writeStatu = false
                }
 
                console.log(this.tableData)
                this.checkState = false;
                this.tableData.forEach((item) => {
                    if (item.fcheckResu == "不合格") {
                        this.checkState = true;
                    }
                })
                if (this.checkState) {
 
                    if (this.formData.fngDesc == '' || this.writeStatu == false) {
                        uni.showToast({
                            title: '未填写不良描述或不良原因或所属车间或评审状态',
                            icon: 'none'
                        });
                    } else {
                        // 检验提交的逻辑
                        this.$post({
                            url: "/LLJ/IqcQaSubmit",
                            data: {
                                userNo: this.$loginInfo.account,
                                releaseNo: this.formData.releaseNo
                            }
                        }).then(res => {
                            if (res.status == 0) {
 
                                if(this.$loginInfo.account == 'PL017'){
                                    this.QcIssueResultDetailes = {
                                        fbatchQty: this.formData.fbatchQty,
                                        itemName: this.formData.itemName,
                                        itemNo: this.formData.itemNo,
                                        suppName: this.formData.suppName,
                                        appicationReason: this.formData.fngDesc,
                                        badReason: this.badreason,
                                        remark: this.REMARK,
                                        workShop: this.WORKSHOP,
                                        releaseNo: this.formData.releaseNo,
                                        staffNo: 'HMCS',
                                        // staffNo: this.$loginInfo.account,
                                        iqcStatus: this.PSTYPE,
                                        department: this.DEPARTMENT,
                                        EMERGENCY: this.formData.emergencyStatus ? "1" : "0" // 确保紧急放行状态正确传递
                                    };
                                }
                                else{
                                    this.QcIssueResultDetailes = {
                                        fbatchQty: this.formData.fbatchQty,
                                        itemName: this.formData.itemName,
                                        itemNo: this.formData.itemNo,
                                        suppName: this.formData.suppName,
                                        appicationReason: this.formData.fngDesc,
                                        badReason: this.badreason,
                                        remark: this.REMARK,
                                        workShop: this.WORKSHOP,
                                        releaseNo: this.formData.releaseNo,
                                        // staffNo: 'HMCS',
                                        staffNo: this.$loginInfo.account,
                                        iqcStatus: this.PSTYPE,
                                        department: this.DEPARTMENT,
                                        EMERGENCY: this.formData.emergencyStatus ? "1" : "0" // 确保紧急放行状态正确传递
                                    };
                                }
 
                                console.log("提交的紧急放行状态:", this.formData.emergencyStatus ? "1" : "0");
                                console.log("完整的提交数据:", this.QcIssueResultDetailes);
 
                                const url = this.$store.state.serverInfo.serverAPI+`/QcIssueResult/GetProcessNo`;
                                if (this.PSTYPE === '特采/让步使用') {// 发送 POST 请求
                                uni.request({
                                    url: url, // 请求地址
                                    method: 'POST', // 请求方法
                                    data: this.QcIssueResultDetailes, // 请求体数据
                                    header: {
                                        'content-type': 'application/json' // 设置请求头,确保发送 JSON 格式的数据
                                    },
                                    success: (response) => {
                                        // 请求成功
                                        uni.showToast({
                                            title: '推送异常处置单成功',
                                            icon: 'none'
                                        });
 
                                        // 如果有页面跳转,需要用定时器延迟
                                        setTimeout(() => {
                                            // 设置一个标记,告诉List页面需要刷新
                                            getApp().globalData = getApp().globalData || {};
                                            getApp().globalData.needRefreshList = true;
                                            uni.redirectTo({
                                                url: 'List'
                                            });
                                        }, 2000); // 保持与 duration 相同的时长
 
                                    },
                                    fail: (error) => {
                                        // 请求失败
                                        console.log('请求失败:', error);
                                        uni.showToast({
                                            title: '推送异常处置单失败',
                                            icon: 'none'
                                        });
                                    }
                                });
                            }
                                uni.showToast({
                                    title: res.message.toString(),
                                    icon: 'success',
                                    duration: 2000
                                })
 
 
                            } else {
                                uni.showModal({
                                    title: "提示",
                                    content: res.message.toString(),
                                    confirmText: "确定",
                                    showCancel: false,
                                    success: (res) => {
 
                                    }
                                })
                            }
                        })
                    }
                } else {
                    // 检验提交的逻辑
                    this.$post({
                        url: "/LLJ/IqcQaSubmit",
                        data: {
                            userNo: this.$loginInfo.account,
                            releaseNo: this.formData.releaseNo
                        }
                    }).then(res => {
                        if (res.status == 0) {
 
                            uni.showToast({
                                title: res.message.toString(),
                                icon: 'success',
                                duration: 2000
                            })
                            // 如果有页面跳转,需要用定时器延迟
                            setTimeout(() => {
                                // 设置一个标记,告诉List页面需要刷新
                                getApp().globalData = getApp().globalData || {};
                                getApp().globalData.needRefreshList = true;
                                uni.navigateBack();
                            }, 2000); // 保持与 duration 相同的时长
                        } else {
                            uni.showModal({
                                title: "提示",
                                content: res.message.toString(),
                                confirmText: "确定",
                                showCancel: false,
                                success: (res) => {
 
                                }
                            })
                        }
                    })
                }
            },
            onShow() {
                //每次进入页面都会执行的方法
                if (this.formData.id) {
                    this.init();
                }
            },
            init() {
                let userName = this.$loginInfo.account;
 
                this.$post({
                    url: "/LLJ/getPage",
                    data: {
                        id: this.formData.id,
                        createUser: userName,
                        pageIndex: 1,
                        limit: 1,
                    }
                }).then(res => {
                    let data = res.data.tbBillList[0];
                    if (data) {
                        this.formData = {
                            ...data,
                            emergencyStatus: data.emergency === 1 || data.emergency === "1" || data.emergency === true
                        };
                        
                        // 确保PHSY字段被正确设置
                        this.formData.PHSY = data.PHSY;
                        
                        console.log("加载的紧急放行状态:", this.formData.emergencyStatus);
                        
                        this.$post({
                            url: "/LLJ/getJYItem",
                            data: {
                                id: this.formData.id,
                                releaseNo: this.formData.releaseNo
                            }
                        }).then(res1 => {
                            let tableData = res1.data.tbBillList
                            //当已检验个数都不为空时按照检测结构排序
                            tableData.sort((a, b) => {
                                if (a.result === '合格' && b.result === '未完成') {
                                    return -1;
                                } else if (a.result === '未完成' && b.result === '合格') {
                                    return 1;
                                } else {
                                    return 0;
                                }
                            });
                            this.tableData = tableData;
                            if (this.tableData.length === 0) {
                                this.isShowTable = true;
                            }
                            this.tableData.forEach((item, index) => {
                                this.$set(item, 'current', this.current);
 
                            });
 
                        })
                    }
                });
            },
            msgRead() {
                msgRead(this.msgId, this.$loginInfo.account);
            },
            //去文件列表页面(文件类型,物料编号)
            toFileUrlByU9List(type, u9No) {
                if (type === 1) {
                    uni.navigateTo({
                        url: 'FileUrlByU9List?type=' + type + '&itemID=' + u9No
                    });
                } else {
                    uni.navigateTo({
                        url: 'FileUrlByU9List2?type=' + type + '&itemID=' + u9No
                    });
                }
            },
            toSysSubmitFrom(releaseNo) {
                uni.navigateTo({
                    url: 'SysSubmitFrom?releaseNo=' + releaseNo + '&userID=' + this.$loginInfo.account
                });
            },
            editRemarks() {
                // 保存不良描述
                this.$post({
                    url: "/LLJ/saveRemarksGid",
                    data: {
                        gid: this.formData.id,
                        remarks: this.remarks || '',
                        releaseNo: this.formData.releaseNo
                        // 不再包含PHSY字段
                    }
                }).then(res => {
                    if (res.data.tbBillList > 0) {
                        this.formData.remarks = this.remarks;
                        this.remarksPopup = !this.remarksPopup;
                        this.$showMessage("保存成功");
                        setTimeout(() => {
                            this.init();
                        }, 2000);
                    }
                })
            },
 
            drawingConfirm() {
                this.drawingShow = false
                this.imageShow = false
                this.productionShow = false
            },
            drawingCancel() {
                this.drawingShow = false
                this.imageShow = false
                this.productionShow = false
            },
 
            fetchDrawingNumber() {
                // const item = '83040700101'
                const item = this.formData.itemNo;
                console.log(this.formData.itemNo)
                // console.log(item)
                const url = this.$store.state.serverInfo.serverAPI +"/PLM/RetrieveDrawings?ItemNo=" + item
 
                // const item = '5.06.04.4002';
                // const url = "http://192.168.0.100:10054/api/PLM/RetrieveDrawings?ItemNo=" + item
                
                let _this = this;
                
                uni.request({
                    url: url,
                    method: 'POST',
                    success: (response) => {
                        console.log(response)
                        if (response.data.data == '返回结果为空') {
                            _this.drawing = null
                        } else {
                            _this.drawing = response.data.data
                            // 遍历数据,判断文件后缀并添加字段
                            _this.drawing.forEach((file) => {
                                // 获取文件名的后缀
                                const fileExtension = file.fName.split('.').pop()
                                    .toLowerCase();
 
                                // 定义支持的文件类型
                                const supportedExtensions = ['jpg', 'pdf', 'xlsx', 'doc',
                                    'docx',
                                    'xls'
                                ];
 
                                // 判断是否支持该文件类型
                                file.isSupported = supportedExtensions.includes(fileExtension);
                            });
                        }
                    },
                    fail: (error) => {
                        uni.showToast({
                            title: '请求图纸链接失败',
                            icon: 'none'
                        });
                    }
                });
                this.drawingShow = true
            },
 
 
            //图纸相关文档
            openDrawings(item) {
                console.log("jkjoi", item)
                if (item.fRelevantObject.length > 2) {
                    // 生成请求URL(简化编码逻辑)
                    const encodedName = encodeURIComponent(item.fName); 
                    const url = this.$store.state.serverInfo.serverAPI+`/PLM/OpenDrawingsGet?fileId=${item.fRelevantObject}&fName=${encodedName}`;
                    console.log('请求URL:', url);
                    
                    const now = new Date();
                    const timestamp = [
                      now.getFullYear(),
                      String(now.getMonth() + 1).padStart(2, '0'),
                      String(now.getDate()).padStart(2, '0'),
                      String(now.getHours()).padStart(2, '0'),
                      String(now.getMinutes()).padStart(2, '0'),
                      String(now.getSeconds()).padStart(2, '0')
                    ].join('');
                                    
                    // 生成新文件名(基础名_时间戳.后缀)
                    this.fileName = `${item.fName}_${timestamp}.pdf`;
                    console.log('新文件名:', this.fileName);
                    
                    uni.downloadFile({
                        url: url,
                        success: (res) => {
                            console.log(res);
                            let fileName = this.fileName;
                            let fileExt = fileName.split('.').pop();
                            // let newFilePath = "_doc/uniapp_temp_1742877118745/download" + "/" + fileName;
                            // console.log('newFilePath', newFilePath)
                            if (fileExt === 'xls' || fileExt === 'xlsx' || fileExt === 'pdf'|| fileExt === 'jpg'|| fileExt === 'png') {
                                plus.io.resolveLocalFileSystemURL(res.tempFilePath, (entry) => {
                                        // 获取文件所在的目录
                                        entry.getParent((parentEntry) => {
                                          let newFileName = this.fileName; // 新的文件名
                                
                                          // 移动并重命名文件
                                          entry.moveTo(
                                            parentEntry,
                                            newFileName,
                                            (newEntry) => {
                                              console.log('重命名成功:', newEntry.fullPath);
                                
                                              // 打开 Excel 文件
                                              plus.runtime.openFile(newEntry.fullPath, {}, (e) => {
                                                console.error('无法打开 Excel 文件:', e);
                                              });
                                              
                                              // let pages = getCurrentPages();
                                              // let beforePage = pages[pages.length - 2];
                                              // uni.navigateBack({
                                              //     delta: 1, //返回的页面数,如果为1表示返回上一页
                                              //     success: (event) => {
                                              //         beforePage.$vm.reload()
                                              //     }
                                              // });
                                              
                                            },
                                            (err) => {
                                              console.error('重命名失败:', err);
                                            }
                                          );
                                        }, (err) => {
                                          console.error('获取父目录失败:', err);
                                        });
                                      }, (err) => {
                                        console.error('获取文件失败:', err);
                                      });
                            } else {
                                console.error('文件格式不匹配:', fileExt);
                                uni.showToast({
                                    title: '文件格式不支持',
                                    icon: 'none'
                                });
                            }
                        }
                    })
                    
                    
                    // uni.downloadFile({
                    //     url: url,
                    //     responseType: 'arraybuffer', // 关键:指定响应数据类型为 ArrayBuffer
                    //     success: (res) => {
                    //         console.log(res)
                    //         if (res.statusCode === 200) {
                    //             // 获取 ArrayBuffer 数据
                    //             const arrayBuffer = res.data;
 
                    //             // 可选:验证文件类型(例如检查 PDF 文件头)
                    //             const header = new Uint8Array(arrayBuffer).subarray(0, 4);
                    //             const headerStr = Array.from(header).map(byte => byte.toString(16).padStart(2,
                    //                 '0')).join('').toUpperCase();
                    //             if (headerStr !== '25504446') { // PDF 文件头为 "%PDF" 的十六进制表示
                    //                 console.error('文件格式无效,非 PDF 文件');
                    //                 return;
                    //             }
 
                    //             // 保存为临时文件(确保扩展名为 .pdf)
                    //             const tempPath = `${wx.env.USER_DATA_PATH}/${Date.now()}.pdf`; // 微信小程序路径
                    //             uni.saveFile({
                    //                 tempFilePath: arrayBuffer, // 注意:部分平台可能需要转换 ArrayBuffer 为 Base64
                    //                 filePath: tempPath,
                    //                 success: () => {
                    //                     uni.openDocument({
                    //                         filePath: tempPath,
                    //                         fileType: 'pdf',
                    //                         success: () => console.log('文档打开成功'),
                    //                         fail: (err) => console.error('打开失败:', err)
                    //                     });
                    //                 },
                    //                 fail: (saveErr) => console.error('保存文件失败:', saveErr)
                    //             });
                    //         } else {
                    //             console.error('下载失败,状态码:', res.statusCode);
                    //         }
                    //     },
                    //     fail: (error) => {
                    //         console.error('下载请求失败:', error.errMsg);
                    //     }
                    // });
                    uni.request({
                        url: url,
                        method: 'POST',
                        responseType: 'arraybuffer',
                        success: (response) => {
                            console.log(response.data)
                            if (!response) {
                                uni.showToast({
                                    title: "协议预览失败",
                                    duration: 2000
                                });
                            }
                            
                            
                            
                            // const base64Data = uni.arrayBufferToBase64(response.data);
 
                            // // 构造一个可以用于预览的 Data URL
                            // const pdfUrl = `data:application/pdf;base64,${base64Data}`;
 
                            // // 使用 pdfUrl 作为预览路径
                            // console.log("PDF 预览路径:", pdfUrl);
 
                            // // 将 Base64 数据传递给另一个页面进行预览
                            // // 注意:直接传递 pdfUrl 可能会导致 URL 过长,建议使用其他方式传递
                            // uni.navigateTo({
                            //     url: `/pages/fileView/pdfView?url=${encodeURIComponent(pdfUrl)}`
                            // });
 
                            // const base64Data = uni.arrayBufferToBase64(response.data);
 
                            //     // 存储到全局变量(在App.vue中定义)
                            //     getApp().globalData.tempPDF = base64Data;
 
                            //     uni.navigateTo({
                            //       url: '/pages/fileView/pdfView'
                            //     });
 
                        },
                        fail: (error) => {
                            console.log(error)
                            uni.showToast({
                                title: '请求预览链接失败',
                                icon: 'none'
                            });
                        }
                    });
                } else if (item.fName && item.fName.toLowerCase().endsWith('.jpg')) {
                    const url = "http://192.168.1.22:10054/api/PLM/OpenDrawings?fileId=" + item.fFileId +
                        '&fName=' +
                        encodeURIComponent(item.fName.replace(/\%/g, '%25').replace(/\ /g, '%20').replace(
                                /\#/g,
                                '%23')
                            .replace(/\?/g, '%3F').replace(/\+/g, '%2B').replace(/\//g, '%2F').replace(/\&/g,
                                '%26'))
                    console.log('jpgurl: ' + url);
                    uni.request({
                        url: url,
                        method: 'POST',
                        responseType: 'arraybuffer',
                        success: (response) => {
                            console.log(response.data)
                            if (!response) {
                                uni.showToast({
                                    title: "协议预览失败",
                                    duration: 2000
                                });
                            }
                            const base64Data = uni.arrayBufferToBase64(response.data);
 
                            // 构造一个可以用于预览的 Data URL
                            const jpgUrl = `data:image/jpeg;base64,${base64Data}`;
 
                            // 使用 pdfUrl 作为预览路径
                            console.log("PDF 预览路径:", jpgUrl);
 
                            // 将 Base64 数据传递给另一个页面进行预览
                            // 注意:直接传递 jpgUrl 可能会导致 URL 过长,建议使用其他方式传递
                            uni.navigateTo({
                                url: `/pages/fileView/jpgView?url=${encodeURIComponent(jpgUrl)}`
                            });
                        },
                        fail: (error) => {
                            console.log(error)
                            uni.showToast({
                                title: '请求预览链接失败',
                                icon: 'none'
                            });
                        }
                    });
                } else if (item.fName && item.fName.toLowerCase().endsWith('.xlsx')) {
                    console.log(item);
                    const url = "http://192.168.1.22:10054/api/PLM/OpenDrawings?fileId=" + item.fFileId +
                        '&fName=' +
                        encodeURIComponent(item.fName.replace(/\%/g, '%25').replace(/\ /g, '%20').replace(
                                /\#/g,
                                '%23')
                            .replace(/\?/g, '%3F').replace(/\+/g, '%2B').replace(/\//g, '%2F').replace(/\&/g,
                                '%26'))
                    console.log('jpgurl: ' + url);
                    uni.request({
                        url: url,
                        method: 'POST',
                        responseType: 'arraybuffer',
                        success: (response) => {
                            console.log(response.data)
                            if (!response) {
                                uni.showToast({
                                    title: "协议预览失败",
                                    duration: 2000
                                });
                            }
                            // const base64Data = uni.arrayBufferToBase64(response.data);
 
                            // const excelUrl =
                            //     `data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,${base64Data}`;
 
                            // // 使用 pdfUrl 作为预览路径
                            // console.log("PDF 预览路径:", excelUrl);
 
                            // 将 ArrayBuffer 转换为 Base64 数据
                            const base64Data = uni.arrayBufferToBase64(response.data);
 
                            // 存储 Base64 数据到本地存储
                            uni.setStorageSync('excelBase64Data', base64Data);
                            // 将 Base64 数据传递给另一个页面进行预览
                            // 注意:直接传递 excelUrl 可能会导致 URL 过长,建议使用其他方式传递
                            // uni.navigateTo({
                            //     url: `/pages/fileView/excelView?url=${encodeURIComponent(excelUrl)}`
                            // });
                            uni.navigateTo({
                                url: `/pages/fileView/excelView`
                            });
                        },
                        fail: (error) => {
                            console.log(error)
                            uni.showToast({
                                title: '请求预览链接失败',
                                icon: 'none'
                            });
                        }
                    });
                }
                // else if (item.fName && item.fName.toLowerCase().endsWith('.doc') || item.fName && item.fName
                //     .toLowerCase().endsWith('.docx')) {
                // console.log(item);
                // const url = "http://192.168.0.100:10054/api/PLM/OpenDrawings?fileId=" + item.fFileId + '&fName=' +
                //     encodeURIComponent(item.fName.replace(/\%/g, '%25').replace(/\ /g, '%20').replace(/\#/g, '%23')
                //         .replace(/\?/g, '%3F').replace(/\+/g, '%2B').replace(/\//g, '%2F').replace(/\&/g, '%26'));
                // console.log('Word 文档 URL:' + url);
                // uni.request({
                //     url: url,
                //     method: 'POST',
                //     responseType: 'arraybuffer',
                //     success: (response) => {
                //         console.log(response.data);
                //         if (!response) {
                //             uni.showToast({
                //                 title: "文档预览失败",
                //                 duration: 2000
                //             });
                //         }
                //         const base64Data = uni.arrayBufferToBase64(response.data);
 
                //         // 构造一个可以用于预览的 Data URL
                //         const wordUrl = `data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;base64,${base64Data}`;
 
                //         // 使用 wordUrl 作为预览路径
                //         console.log("Word 文档预览路径:", wordUrl);
 
                //         // 将 Base64 数据传递给另一个页面进行预览
                //         // 注意:直接传递 wordUrl 可能会导致 URL 过长,建议使用其他方式传递
                //         uni.navigateTo({
                //             url: `/pages/fileView/wordView?url=${encodeURIComponent(wordUrl)}`
                //         });
                //     },
                //         fail: (error) => {
                //             console.log(error)
                //             uni.showToast({
                //                 title: '请求预览链接失败',
                //                 icon: 'none'
                //             });
                //         }
                //     });
                // } else {
                //     uni.showToast({
                //         title: '无对应PDF文件,打开失败',
                //         icon: 'none'
                //     });                // }
            },
            // 处理紧急放行
            handleEmergencyRelease() {
                        if (this.formData.emergencyStatus) {
                            uni.showModal({
                                title: "提示",
                                content: '该单已紧急放行,请勿重复操作',
                                showCancel: false
                            });
                            return;
                        }
            
                        uni.showModal({
                            title: '确认',
                            content: '确定要执行紧急放行吗?',
                            success: (res) => {
                                if (res.confirm) {
                                    // 调用新的后端接口
                                    this.$post({
                                        url: "/LLJ/EmergencyRelease",
                                        data: {
                                            id: this.formData.id
                                        }
                                    }).then(res => {
                                        if (res.data && res.status === 0) {
                                            const result = res.data.tbBillList[0];
                                            const message = res.data.tbBillList[1];
                                            const lotNo1 = res.data.tbBillList[2] || "";
            
                                            if (result === "0") {
                                                this.formData.emergencyStatus = true;
                                                this.originalLotNo1 = lotNo1; 
                                                this.formData.lotNo1 = lotNo1;
                                                // 更新紧急放行状态,确保提交时能正确传递
                                                this.formData.EMERGENCY = "1";
                                                
                                                uni.showToast({
                                                    title: message || '紧急放行成功',
                                                    icon: 'success',
                                                    duration: 2000
                                                });
                                                this.init();
                                            } else {
                                                uni.showModal({
                                                    title: "提示",
                                                    content: message || '操作失败',
                                                    showCancel: false
                                                });
                                            }
                                        }
                                    }).catch(error => {
                                        uni.showModal({
                                            title: "错误",
                                            content: '网络错误,请检查网络连接',
                                            showCancel: false
                                        });
                                    });
                                }
                            }
                        });
                    },
            
                    // 处理撤回
                    handleWithdraw() {
                        uni.showModal({
                            title: '确认',
                            content: '确定要撤回紧急放行吗?',
                            success: (res) => {
                                if (res.confirm) {
                                    // 调用新的后端接口
                                    this.$post({
                                        url: "/LLJ/WithdrawEmergencyRelease",
                                        data: {
                                            id: this.formData.id
                                        }
                                    }).then(res => {
                                        if (res.data && res.status === 0) {
                                            const result = res.data.tbBillList[0];
                                            const message = res.data.tbBillList[1];
            
                                            if (result === "0") {
                                                this.formData.emergencyStatus = false;
                                                // 更新紧急放行状态,确保提交时能正确传递
                                                this.formData.EMERGENCY = "0";
                                                
                                                uni.showToast({
                                                    title: message || '撤回成功',
                                                    icon: 'success',
                                                    duration: 2000
                                                });
                                                this.init();
                                            } else {
                                                uni.showModal({
                                                    title: "提示",
                                                    content: message || '操作失败',
                                                    showCancel: false
                                                });
                                            }
                                        }
                                    }).catch(error => {
                                        uni.showModal({
                                            title: "错误",
                                            content: '网络错误,请检查网络连接',
                                            showCancel: false
                                        });
                                    });
                                }
                            }
                        });
                    },
                    editRemarks() {
                        // 保存不良描述
                        this.$post({
                            url: "/LLJ/saveRemarksGid",
                            data: {
                                gid: this.formData.id,
                                remarks: this.remarks || '',
                                releaseNo: this.formData.releaseNo
                                // 不再包含PHSY字段
                            }
                        }).then(res => {
                            if (res.data.tbBillList > 0) {
                                this.formData.remarks = this.remarks;
                                this.remarksPopup = !this.remarksPopup;
                                this.$showMessage("保存成功");
                                setTimeout(() => {
                                    this.init();
                                }, 2000);
                            }
                        })
                    },
            addDestruction() {
                // 添加破坏实验的逻辑
                this.destructionPopup = !this.destructionPopup;
                this.PHSY = this.formData.PHSY || '';
                this.isInteger = true;
            },
            editDestruction() {
                // 验证输入是否为整数
                if(this.PHSY === '') {
                    this.isInteger = true;
                    // 如果为空,传递空字符串,后端会处理为null
                } else {
                    const isInteger = /^-?\d+$/.test(this.PHSY);
                    this.isInteger = isInteger;
                    if (!isInteger) {
                        return;
                    }
                }
                
                // 保存破坏实验数量
                this.$post({
                    url: "/LLJ/saveRemarksGid",
                    data: {
                        gid: this.formData.id,
                        releaseNo: this.formData.releaseNo,
                        PHSY: this.PHSY // 可以是空字符串或有效整数
                        // 不再包含remarks字段
                    }
                }).then(res => {
                    if (res.data.tbBillList > 0) {
                        // 如果输入为空,设置为null以便不显示
                        this.formData.PHSY = this.PHSY === '' ? null : this.PHSY;
                        this.destructionPopup = false;
                        this.$showMessage("保存成功");
                        setTimeout(() => {
                            this.init();
                        }, 2000);
                    }
                })
            },
            clearDestruction() {
                // 清除破坏实验数量
                this.PHSY = '';
                this.$post({
                    url: "/LLJ/saveRemarksGid",
                    data: {
                        gid: this.formData.id,
                        releaseNo: this.formData.releaseNo,
                        PHSY: '' // 空字符串,后端会处理为null
                    }
                }).then(res => {
                    if (res.data.tbBillList > 0) {
                        this.formData.PHSY = null; // 确保前端也为null,不显示
                        this.destructionPopup = false;
                        this.$showMessage("清除成功");
                        setTimeout(() => {
                            this.init();
                        }, 2000);
                    }
                })
            },
            viewAttachmentInfo() {
                this.showAttachmentPopup = true; // 先弹窗
                this.attachmentsLoading = true;
                this.attachments = [];
                this.$post({
                    url: "/LLJ/getAttachments",
                    data: { releaseNo: this.formData.releaseNo }
                }).then(res => {
                    this.attachmentsLoading = false;
                    if (res.status === 0) {
                        this.attachments = res.data.tbBillList;
                        // 为每个附件设置默认可用状态
                        this.attachments.forEach((item, index) => {
                            this.$set(item, 'ftpAvailable', true); // 默认认为文件可用
                            this.$set(item, 'checking', false);
                        });
                    } else if (res.status === 1 && res.message === "该检验单未上传附件信息!") {
                        uni.showToast({ title: res.message, icon: "none" });
                    } else {
                        uni.showToast({ title: "获取附件失败", icon: "none" });
                    }
                });
            },
            closeAttachmentPopup() {
                this.showAttachmentPopup = false;
            },
            getAttachmentUrl(item) {
                // 去除所有空白字符(包括中英文空格、制表符等)
                let fileName = item.fattach.replace(/[\s\u3000\r\n]+/g, '').trim();
                // 统一使用FTP下载接口,包含FTP服务器地址
                return this.$store.state.serverInfo.serverAPI + "/LLJ/DownloadFtpFile?itemNo=" + encodeURIComponent(item.itemNo) + "&fileName=" + encodeURIComponent(fileName) + "&ftpServer=" + encodeURIComponent(this.$store.state.serverInfo.ftpServer);
            },
            showAttachmentDetailDialog(item) {
                console.log('查看详情', item);
                this.selectedAttachment = item;
                this.showAttachmentPopup = false;
                this.showAttachmentDetail = true;
                console.log('showAttachmentDetail:', this.showAttachmentDetail);
            },
            closeAttachmentDetail() {
                this.showAttachmentDetail = false;
                this.selectedAttachment = null;
                this.showAttachmentPopup = true;
            },
            isPreviewable(filename) {
                if (!filename) return false;
                const ext = filename.trim().split('.').pop().toLowerCase();
                // 支持在线预览的文件类型
                return [
                    'pdf',           // PDF文件
                    'jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp',  // 图片文件
                    'txt', 'log', 'md',  // 文本文件
                    'doc', 'docx',   // Word文档
                    'xls', 'xlsx',   // Excel表格
                    'ppt', 'pptx',   // PowerPoint演示文稿
                    'csv'            // CSV文件
                ].includes(ext);
            },
            // 处理附件下载错误
            handleAttachmentError(item) {
                uni.showModal({
                    title: '下载失败',
                    content: `无法下载附件:${item.fattach}\n请检查网络连接或联系管理员`,
                    showCancel: false
                });
            },
            // 预览FTP文件
            previewFtpFile(item) {
                const fileName = item.fattach.replace(/[\s\u3000\r\n]+/g, '').trim();
                const fileExt = fileName.split('.').pop().toLowerCase();
                
                // 检查文件类型是否支持预览
                if (!this.isPreviewable(fileName)) {
                    uni.showModal({
                        title: '不支持预览',
                        content: '该文件类型不支持在线预览,请下载后查看',
                        showCancel: false
                    });
                    return;
                }
                
                const previewUrl = this.$store.state.serverInfo.serverAPI + "/LLJ/PreviewFtpFile?itemNo=" + encodeURIComponent(item.itemNo) + "&fileName=" + encodeURIComponent(fileName) + "&ftpServer=" + encodeURIComponent(this.$store.state.serverInfo.ftpServer);
                
                // 根据文件类型进行不同的预览处理
                if (['pdf'].includes(fileExt)) {
                    this.previewPdfFile(previewUrl, fileName);
                } else if (['jpg', 'jpeg', 'png', 'gif', 'bmp'].includes(fileExt)) {
                    this.previewImageFile(previewUrl, fileName);
                } else if (['txt'].includes(fileExt)) {
                    this.previewTextFile(previewUrl, fileName);
                } else if (['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx'].includes(fileExt)) {
                    this.previewOfficeFile(previewUrl, fileName);
                } else {
                    // 尝试通用预览
                    this.previewGenericFile(previewUrl, fileName);
                }
            },
            
            // 预览PDF文件
            previewPdfFile(url, fileName) {
                // 先下载PDF文件,转为base64后预览
                uni.request({
                    url: url,
                    method: 'GET',
                    responseType: 'arraybuffer',
                    success: (res) => {
                        if (res.statusCode === 200) {
                            const base64Data = uni.arrayBufferToBase64(res.data);
                            // 存储到全局变量
                            getApp().globalData.tempPDF = base64Data;
                            uni.navigateTo({
                                url: `/pages/fileView/pdfView`
                            });
                        } else {
                            this.handlePreviewError(res.statusCode, fileName);
                        }
                    },
                    fail: (error) => {
                        this.handlePreviewError(0, fileName, error.errMsg);
                    }
                });
            },
            
            // 预览图片文件
            previewImageFile(url, fileName) {
                // #ifdef APP-PLUS
                // APP环境:先下载到本地再预览,避免网络图片加载问题
                uni.showLoading({ title: '加载图片...' });
                uni.downloadFile({
                    url: url,
                    success: (res) => {
                        uni.hideLoading();
                        if (res.statusCode === 200) {
                            // 使用本地临时路径
                            uni.navigateTo({
                                url: `/pages/fileView/imageView?url=${encodeURIComponent(res.tempFilePath)}`
                            });
                        } else {
                            this.handlePreviewError(res.statusCode, fileName);
                        }
                    },
                    fail: (error) => {
                        uni.hideLoading();
                        this.handlePreviewError(0, fileName, error.errMsg);
                    }
                });
                // #endif
                
                // #ifdef H5 || MP
                // H5和小程序:直接使用网络URL
                uni.navigateTo({
                    url: `/pages/fileView/imageView?url=${encodeURIComponent(url)}`
                });
                // #endif
            },
            
            // 预览文本文件
            previewTextFile(url, fileName) {
                // 文本文件直接显示在弹窗中
                uni.showLoading({ title: '加载文件内容...' });
                uni.request({
                    url: url,
                    method: 'GET',
                    success: (res) => {
                        uni.hideLoading();
                        if (res.statusCode === 200) {
                            const fileType = this.getFileType(fileName);
                            
                            if (fileType === 'text') {
                                // 文本文件:显示内容
                                this.showFilePreview(res.data, fileName);
                            } else if (fileType === 'image') {
                                // 图片文件:显示图片URL
                                this.showFilePreview(url, fileName);
                            } else {
                                // 其他文件类型:显示提示信息
                                this.showFilePreview('', fileName);
                            }
                        } else {
                            this.handlePreviewError(res.statusCode, fileName);
                        }
                    },
                    fail: (error) => {
                        uni.hideLoading();
                        this.handlePreviewError(0, fileName, error.errMsg);
                    }
                });
            },
            
            // 检测文件类型
            getFileType(fileName) {
                const fileExt = fileName.split('.').pop().toLowerCase();
                
                if (['txt', 'log', 'md', 'csv', 'json', 'xml'].includes(fileExt)) {
                    return 'text';
                } else if (['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'].includes(fileExt)) {
                    return 'image';
                } else if (['xls', 'xlsx', 'doc', 'docx', 'ppt', 'pptx'].includes(fileExt)) {
                    return 'excel';
                } else {
                    return 'unsupported';
                }
            },
            
            // 显示文件预览弹窗
            showFilePreview(content, fileName) {
                this.previewContent = content;
                this.previewTitle = fileName;
                this.previewItemNo = this.selectedAttachment?.itemNo || '';
                this.previewType = this.getFileType(fileName);
                this.showFilePreviewPopup = true;
            },
            
            // 关闭文件预览弹窗
            closeFilePreview() {
                this.showFilePreviewPopup = false;
                this.previewContent = '';
                this.previewTitle = '';
                this.previewItemNo = '';
                this.previewType = '';
            },
            
            // 下载预览文件
            downloadPreviewFile() {
                const item = { fattach: this.previewTitle, itemNo: this.previewItemNo };
                this.downloadAttachment(item);
                this.closeFilePreview();
            },
            
            // 预览Office文件
            previewOfficeFile(url, fileName) {
                // 先检查Excel文件,使用专门的Excel预览页面
                const fileExt = fileName.split('.').pop().toLowerCase();
                if (['xls', 'xlsx'].includes(fileExt)) {
                    // Excel文件预览
                    uni.request({
                        url: url,
                        method: 'GET',
                        responseType: 'arraybuffer',
                        success: (res) => {
                            if (res.statusCode === 200) {
                                const base64Data = uni.arrayBufferToBase64(res.data);
                                // 存储 Base64 数据到本地存储
                                uni.setStorageSync('excelBase64Data', base64Data);
                                uni.navigateTo({
                                    url: `/pages/fileView/excelView`
                                });
                            } else {
                                this.handlePreviewError(res.statusCode, fileName);
                            }
                        },
                        fail: (error) => {
                            this.handlePreviewError(0, fileName, error.errMsg);
                        }
                    });
                } else if (['doc', 'docx'].includes(fileExt)) {
                    // Word文件,尝试使用Word预览页面或者微软在线预览
                    try {
                        const officePreviewUrl = `https://view.officeapps.live.com/op/view.aspx?src=${encodeURIComponent(url)}`;
                        // 如果有webView页面,使用webView预览
                        this.previewGenericFile(officePreviewUrl, fileName);
                    } catch (error) {
                        this.handlePreviewError(0, fileName, '不支持此Office文件类型的预览');
                    }
                } else {
                    // 其他Office文件,使用微软在线预览服务
                    const officePreviewUrl = `https://view.officeapps.live.com/op/view.aspx?src=${encodeURIComponent(url)}`;
                    this.previewGenericFile(officePreviewUrl, fileName);
                }
            },
            
            // 通用文件预览
            previewGenericFile(url, fileName) {
                // 由于没有通用的webView页面,显示提示并提供下载
                uni.showModal({
                    title: '文件预览',
                    content: `文件 "${fileName}" 需要下载后查看,是否立即下载?`,
                    showCancel: true,
                    confirmText: '下载',
                    cancelText: '取消',
                    success: (res) => {
                        if (res.confirm) {
                            const item = { fattach: fileName, itemNo: this.selectedAttachment.itemNo };
                            this.downloadAttachment(item);
                        }
                    }
                });
            },
            
            // 处理预览错误
            handlePreviewError(statusCode, fileName, errorMsg = '') {
                let message = '';
                if (statusCode === 404) {
                    message = `文件 ${fileName} 在FTP服务器上不存在`;
                } else if (statusCode === 0) {
                    message = `预览失败:${errorMsg}`;
                } else {
                    message = `预览失败,状态码:${statusCode}`;
                }
                
                uni.showModal({
                    title: '预览失败',
                    content: message,
                    showCancel: true,
                    confirmText: '下载',
                    cancelText: '取消',
                    success: (res) => {
                        if (res.confirm) {
                            // 用户选择下载文件
                            const item = { fattach: fileName, itemNo: this.selectedAttachment.itemNo };
                            this.downloadAttachment(item);
                        }
                    }
                });
            },
            
            downloadAttachment(item) {
                // 去除所有空格、全角空格、回车、换行
                const fileName = item.fattach.replace(/[\s\u3000\r\n]+/g, '').trim();
                // 使用配置的服务器地址和FTP服务器地址
                const url = this.$store.state.serverInfo.serverAPI + "/LLJ/DownloadFtpFile?itemNo=" + encodeURIComponent(item.itemNo) + "&fileName=" + encodeURIComponent(fileName) + "&ftpServer=" + encodeURIComponent(this.$store.state.serverInfo.ftpServer);
                
                // 检查运行环境
                // #ifdef H5
                // H5环境:使用浏览器下载
                this.downloadFileInBrowser(url, fileName);
                // #endif
                
                // #ifdef APP-PLUS
                // APP环境:使用uni.downloadFile
                this.downloadFileInApp(url, fileName);
                // #endif
                
                // #ifdef MP
                // 小程序环境:使用uni.downloadFile
                this.downloadFileInApp(url, fileName);
                // #endif
            },
            
            // 在浏览器中下载文件
            downloadFileInBrowser(url, fileName) {
                uni.showLoading({ title: '正在准备下载...' });
                
                // 方法1:创建隐藏的a标签下载
                try {
                    const link = document.createElement('a');
                    link.href = url;
                    link.download = fileName;
                    link.style.display = 'none';
                    document.body.appendChild(link);
                    link.click();
                    document.body.removeChild(link);
                    
                    uni.hideLoading();
                    uni.showToast({ 
                        title: '下载已开始', 
                        icon: 'success',
                        duration: 2000
                    });
                } catch (error) {
                    console.log('a标签下载失败,尝试window.open方式:', error);
                    // 方法2:使用window.open
                    try {
                        window.open(url, '_blank');
                        uni.hideLoading();
                        uni.showToast({ 
                            title: '下载已开始', 
                            icon: 'success',
                            duration: 2000
                        });
                    } catch (error2) {
                        console.log('window.open下载失败,尝试fetch方式:', error2);
                        // 方法3:使用fetch下载
                        this.downloadFileWithFetch(url, fileName);
                    }
                }
            },
            
            // 使用fetch下载文件
            downloadFileWithFetch(url, fileName) {
                fetch(url)
                    .then(response => {
                        if (!response.ok) {
                            throw new Error(`HTTP error! status: ${response.status}`);
                        }
                        return response.blob();
                    })
                    .then(blob => {
                        // 创建blob URL
                        const blobUrl = window.URL.createObjectURL(blob);
                        
                        // 创建下载链接
                        const link = document.createElement('a');
                        link.href = blobUrl;
                        link.download = fileName;
                        link.style.display = 'none';
                        document.body.appendChild(link);
                        link.click();
                        document.body.removeChild(link);
                        
                        // 释放blob URL
                        window.URL.revokeObjectURL(blobUrl);
                        
                        uni.hideLoading();
                        uni.showToast({ 
                            title: '下载成功', 
                            icon: 'success',
                            duration: 2000
                        });
                    })
                    .catch(error => {
                        console.error('Fetch下载失败:', error);
                        uni.hideLoading();
                        if (error.message.includes('404')) {
                            uni.showModal({ 
                                title: '文件不存在', 
                                content: `该附件在FTP服务器上不存在`,
                                showCancel: false 
                            });
                        } else {
                            uni.showModal({ 
                                title: '下载失败', 
                                content: `下载失败: ${error.message}`,
                                showCancel: false 
                            });
                        }
                    });
            },
            
            // 在APP中下载文件
            downloadFileInApp(url, fileName) {
                // #ifdef APP-PLUS
                uni.showLoading({ title: '从FTP服务器下载中...' });
                
                // Android 获取存储路径
                const saveDir = plus.os.name === 'Android' ? plus.io.convertLocalFileSystemURL('_downloads/') : plus.io.convertLocalFileSystemURL('_documents/');
                const filePath = `${saveDir}${fileName}`;
                
                const downloadTask = uni.downloadFile({
                    url: url,
                    filePath: filePath, // 指定保存路径
                    success: (res) => {
                        uni.hideLoading();
                        if (res.statusCode === 200) {
                            const fileInfo = {
                                name: fileName,
                                path: res.filePath || filePath,
                                tempPath: res.tempFilePath
                            };
                            
                            uni.showModal({
                                title: '下载成功',
                                content: `文件已保存到:${fileInfo.path}`,
                                showCancel: true,
                                confirmText: '打开文件',
                                cancelText: '确定',
                                success: (modalRes) => {
                                    if (modalRes.confirm) {
                                        // 用户选择打开文件
                                        this.openFileInApp(fileInfo);
                                    }
                                }
                            });
                        } else if (res.statusCode === 404) {
                            uni.showModal({ 
                                title: '文件不存在', 
                                content: `该附件在FTP服务器上不存在`,
                                showCancel: false 
                            });
                        } else {
                            uni.showModal({ 
                                title: '下载失败', 
                                content: `状态码:${res.statusCode}`,
                                showCancel: false 
                            });
                        }
                    },
                    fail: (error) => {
                        uni.hideLoading();
                        console.error('下载失败:', error);
                        uni.showModal({ 
                            title: '下载失败', 
                            content: `网络错误:${error.errMsg}`,
                            showCancel: false 
                        });
                    }
                });
                
                // 监听下载进度
                downloadTask.onProgressUpdate((res) => {
                    const progress = Math.round(res.progress);
                    uni.showLoading({ 
                        title: `下载中 ${progress}%`,
                        mask: true 
                    });
                });
                // #endif
                
                // #ifdef MP
                // 小程序环境的简化实现
                uni.showLoading({ title: '下载中...' });
                uni.downloadFile({
                    url: url,
                    success: (res) => {
                        uni.hideLoading();
                        if (res.statusCode === 200) {
                            uni.showToast({ title: '下载完成', icon: 'success' });
                        }
                    },
                    fail: (error) => {
                        uni.hideLoading();
                        uni.showModal({ title: '下载失败', content: error.errMsg, showCancel: false });
                    }
                });
                // #endif
            },
            
            // APP中打开文件
            openFileInApp(fileInfo) {
                // #ifdef APP-PLUS
                if (typeof plus !== 'undefined') {
                    const filePath = fileInfo.path || fileInfo.tempPath;
                    
                    // 尝试打开文件
                    plus.runtime.openFile(filePath, {}, (error) => {
                        console.error('打开文件失败:', error);
                        uni.showModal({
                            title: '无法打开',
                            content: '系统中没有找到能打开此文件的应用程序',
                            showCancel: false
                        });
                    });
                }
                // #endif
            },
 
        }
    }
</script>
 
<style>
    /* 基础样式 */
    .inspection-sheet {
        font-family: 'Microsoft YaHei', 'Segoe UI', sans-serif;
        max-width: 1000px;
        margin: 0 auto;
        padding: 20px 20px 160px 20px; /* 底部增加padding为固定按钮留空间 */
        background-color: #fff;
        box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        min-height: 100vh;
        position: relative;
    }
 
    /* 头部样式 */
    .sheet-header {
        text-align: center;
        margin-bottom: 20px;
        padding-bottom: 15px;
        border-bottom: 2px solid #e0e0e0;
    }
 
    .sheet-header h1 {
        color: #2c3e50;
        font-size: 24px;
        margin-bottom: 5px;
    }
 
    .inspection-number {
        font-size: 16px;
        font-weight: bold;
        color: #3498db;
    }
 
    /* 基本信息区样式 */
    .basic-info,
    .material-info {
        margin-bottom: 20px;
    }
 
    .info-row {
        display: flex;
        margin-bottom: 10px;
        flex-wrap: wrap;
    }
 
    .info-label {
        font-weight: bold;
        color: #34495e;
        min-width: 80px;
        margin-right: 5px;
    }
 
    .info-value {
        color: #2c3e50;
        margin-right: 20px;
    }
 
    .highlight {
        font-weight: bold;
        color: #e74c3c;
    }
 
    /* 物料信息区样式 */
    .material-info {
        border: 1px solid #eee;
        padding: 15px;
        border-radius: 5px;
    }
 
    .info-block {
        display: flex;
        align-items: center;
        margin-bottom: 10px;
        flex-wrap: wrap;
    }
 
    .doc-links {
        margin-left: auto;
    }
 
    .doc-link {
        color: #3498db;
        text-decoration: none;
        margin-left: 15px;
        padding: 3px 8px;
        border: 1px solid #3498db;
        border-radius: 3px;
        font-size: 12px;
    }
 
    .sysLike {
        color: #1890ff;
        text-decoration: none;
        cursor: pointer;
    }
 
    .doc-link:hover {
        background-color: #f0f8ff;
    }
 
    /* 表格样式 */
    .inspection-table {
        margin: 25px 0;
    }
 
    .inspection-table table {
        width: 100%;
        border-collapse: collapse;
    }
 
    .inspection-table th,
    .inspection-table td {
        padding: 12px 15px;
        border: 1px solid #ddd;
        text-align: left;
    }
 
    .inspection-table th {
        background-color: #f8f9fa;
        font-weight: bold;
        color: #34495e;
    }
 
    .inspection-table tr:nth-child(even) {
        background-color: #f9f9f9;
    }
 
    .inspection-table tr:hover {
        background-color: #f1f5f9;
    }
 
    /* 固定底部按钮样式 */
    .fixed-action-buttons {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background-color: #fff;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
        padding: 10px 15px 20px 15px;
        z-index: 100;
        display: flex;
        flex-direction: column;
        gap: 8px;
        max-height: 150px;
        overflow-y: auto;
    }
 
    .action-btn {
        background-color: #ecf0f1;
        color: #34495e;
        padding: 12px 15px;
        border: none;
        border-radius: 6px;
        cursor: pointer;
        font-size: 14px;
        font-weight: 500;
        transition: all 0.3s ease;
        text-align: center;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
 
    .action-btn:hover {
        background-color: #d5dbdb;
        transform: translateY(-1px);
    }
 
    .action-btn.primary {
        background-color: #3498db;
        color: #fff;
    }
 
    .action-btn.primary:hover {
        background-color: #2980b9;
    }
 
    /* 内容包装器,为底部按钮留出空间 */
    .content-wrapper {
        height: 20px; /* 额外的空白区域 */
    }
 
    /* 原有按钮样式保持兼容 */
    .action-buttons {
        display: flex;
        gap: 10px;
        margin: 15px 0;
        justify-content: flex-end;
    }
 
    .secondary-btn {
        background-color: #ecf0f1;
        color: #7f8c8d;
        padding: 8px 15px;
        border: none;
        border-radius: 4px;
        cursor: pointer;
    }
 
    .secondary-btn:hover {
        background-color: #d5dbdb;
    }
 
    .secondary-btn:disabled {
        background-color: #d9d9d9;
        cursor: not-allowed;
        opacity: 0.7;
    }
 
    .primary-btn {
        padding: 10px 20px;
        border: none;
        border-radius: 4px;
        font-size: 14px;
        cursor: pointer;
        transition: all 0.3s;
    }
 
    .primary-btn:hover {
        background-color: #2980b9;
    }
 
    .record-btn {
        padding: 6px 12px;
        background-color: #f8f9fa;
        border: 1px solid #ddd;
        /* border-radius: 3px; */
        cursor: pointer;
        transition: all 0.2s;
    }
 
    .record-btn:hover {
        background-color: #e9ecef;
    }
 
    /* 水印样式 */
    .watermark {
        position: absolute;
        font-size: 40px;
        font-weight: bold;
        opacity: 1;
        z-index: 1;
        pointer-events: none;
        transform: rotate(-15deg);
        width: 100%;
        text-align: center;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%) rotate(-15deg);
    }
 
    .watermark.approved {
        color: #2ecc71;
        /* 绿色 */
    }
 
    .watermark.rejected {
        color: #e74c3c;
        /* 红色 */
    }
 
    .watermark.pending {
        color: #f39c12;
        /* 橙色 */
    }
 
    /* 描述文本容器 */
    .description-text {
        position: relative;
        z-index: 2;
        padding: 25px;
        background-color: rgba(255, 255, 255, 0.7);
    }
 
    /* 调整表格单元格 */
    .inspection-table td:nth-child(2) {
        position: relative;
        overflow: hidden;
        padding: 0;
    }
 
    .overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
        display: flex;
        justify-content: center;
        align-items: center;
        z-index: 1000; /* 提高层级,确保在固定按钮上方 */
    }
 
    /* 弹窗整体美化 */
    .popup, .attachment-detail-popup {
        background: #fff;
        border-radius: 16px;
        box-shadow: 0 8px 32px rgba(60,60,60,0.18);
        padding: 28px 28px 18px 28px;
        border: none;
        position: relative;
        min-width: 260px;
        z-index: 1001; /* 确保弹窗内容在最上层 */
        max-height: 80vh; /* 限制最大高度,避免被底部按钮遮挡 */
        overflow-y: auto; /* 内容过多时可滚动 */
    }
    .attachment-popup-title {
        font-size: 22px;
        font-weight: 700;
        color: #222;
        margin-bottom: 8px;
        letter-spacing: 1px;
        text-align: center;
    }
    .attachment-popup-divider {
        height: 1px;
        background: linear-gradient(90deg,#e0e7ef 0%,#f5f7fa 100%);
        margin-bottom: 18px;
    }
    .attachment-detail-content {
        margin-bottom: 18px;
    }
    .attachment-detail-row {
        display: flex;
        align-items: center;
        margin-bottom: 8px;
        font-size: 15px;
    }
    .attachment-label {
        min-width: 80px;
        color: #1976d2;
        font-weight: 500;
        margin-right: 8px;
    }
    .attachment-preview-area {
        margin: 18px 0 8px 0;
        border-radius: 10px;
        background: #f8fafc;
        padding: 10px;
        box-shadow: 0 2px 8px rgba(60,60,60,0.06);
    }
    .attachment-download-area {
        margin: 18px 0 8px 0;
        text-align: center;
    }
    .attachment-download-link {
        display: inline-block;
        padding: 7px 18px;
        background: linear-gradient(90deg,#4f8cff 0%,#1976d2 100%);
        color: #fff;
        border-radius: 6px;
        font-weight: 500;
        text-decoration: none;
        transition: background 0.2s;
        box-shadow: 0 2px 8px rgba(60,60,60,0.08);
    }
    .attachment-download-link:hover {
        background: linear-gradient(90deg,#1976d2 0%,#4f8cff 100%);
    }
    .attachment-detail-empty {
        color: #888;
        text-align: center;
        margin: 30px 0;
        font-size: 16px;
    }
    .attachment-popup-close {
        margin-top: 18px;
        width: 100%;
        background: linear-gradient(90deg,#e0e0e0 0%,#f5f7fa 100%);
        color: #444;
        border-radius: 8px;
        font-size: 16px;
        padding: 10px 0;
        border: none;
        font-weight: 600;
        letter-spacing: 1px;
        transition: background 0.2s, color 0.2s;
        box-shadow: 0 2px 8px rgba(60,60,60,0.06);
    }
    .attachment-popup-close:hover {
        background: linear-gradient(90deg,#bdbdbd 0%,#e0e0e0 100%);
        color: #1976d2;
    }
    
    /* 附件详情页面的操作按钮 */
    .attachment-actions-detail {
        margin: 20px 0;
        display: flex;
        gap: 12px;
        justify-content: center;
        flex-wrap: wrap;
    }
    .attachment-action-btn {
        padding: 10px 20px;
        border: none;
        border-radius: 8px;
        font-size: 14px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.3s ease;
        display: flex;
        align-items: center;
        justify-content: center;
        min-width: 120px;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
    .attachment-action-btn.preview-btn {
        background: linear-gradient(135deg, #4CAF50, #45a049);
        color: white;
    }
    .attachment-action-btn.preview-btn:hover {
        background: linear-gradient(135deg, #45a049, #3d8b40);
        transform: translateY(-1px);
        box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    }
    .attachment-action-btn.download-btn {
        background: linear-gradient(135deg, #2196F3, #1976D2);
        color: white;
    }
    .attachment-action-btn.download-btn:hover {
        background: linear-gradient(135deg, #1976D2, #1565C0);
        transform: translateY(-1px);
        box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    }
    
    /* 文件预览弹窗样式 */
    .file-preview-popup {
        width: 80vw;
        max-width: 600px;
        max-height: 70vh;
        display: flex;
        flex-direction: column;
    }
    
    /* APP环境适配 */
    /* #ifdef APP-PLUS */
    .file-preview-popup {
        width: 85vw;
        max-height: 75vh;
    }
    .file-preview-content {
        max-height: 350px;
    }
    /* #endif */
    .file-preview-title {
        font-size: 18px;
        font-weight: 700;
        color: #222;
        margin-bottom: 8px;
        text-align: center;
        word-break: break-all;
    }
    .file-preview-divider {
        height: 1px;
        background: linear-gradient(90deg,#e0e7ef 0%,#f5f7fa 100%);
        margin-bottom: 16px;
    }
    .file-preview-content {
        flex: 1;
        max-height: 400px;
        overflow-y: auto;
        background: #f8fafc;
        border-radius: 8px;
        padding: 16px;
        margin-bottom: 16px;
        border: 1px solid #e2e8f0;
    }
    .file-preview-content pre {
        font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
        font-size: 12px;
        line-height: 1.5;
        color: #2d3748;
        white-space: pre-wrap;
        word-wrap: break-word;
        margin: 0;
    }
    
    /* 图片预览样式 */
    .image-preview-container {
        display: flex;
        justify-content: center;
        align-items: center;
        min-height: 200px;
    }
    
    /* 不支持文件类型的提示样式 */
    .unsupported-preview {
        text-align: center;
        padding: 40px 20px;
        color: #666;
    }
    .unsupported-icon {
        font-size: 48px;
        margin-bottom: 16px;
    }
    .unsupported-text {
        font-size: 16px;
        font-weight: 600;
        color: #333;
        margin-bottom: 8px;
    }
    .unsupported-hint {
        font-size: 14px;
        color: #999;
        line-height: 1.4;
    }
    
    .file-preview-actions {
        display: flex;
        gap: 12px;
        justify-content: center;
    }
    .file-preview-btn {
        padding: 8px 20px;
        border: none;
        border-radius: 6px;
        font-size: 14px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.3s ease;
        display: flex;
        align-items: center;
        justify-content: center;
        min-width: 120px;
    }
    .file-preview-btn.download-btn {
        background: linear-gradient(135deg, #2196F3, #1976D2);
        color: white;
    }
    .file-preview-btn.download-btn:hover {
        background: linear-gradient(135deg, #1976D2, #1565C0);
        transform: translateY(-1px);
    }
    .file-preview-btn.close-btn {
        background: linear-gradient(135deg, #e0e0e0, #bdbdbd);
        color: #444;
    }
    .file-preview-btn.close-btn:hover {
        background: linear-gradient(135deg, #bdbdbd, #9e9e9e);
        transform: translateY(-1px);
    }
    /* 列表弹窗美化(保留原有) */
    .attachment-list {
        padding: 0;
        margin: 0;
        list-style: none;
        max-height: 300px;
        overflow-y: auto;
    }
    .attachment-list li {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 12px 0;
        border-bottom: 1px solid #f0f0f0;
    }
    .attachment-info {
        flex: 1;
        margin-right: 10px;
    }
    .attachment-name {
        color: #3498db;
        cursor: pointer;
        font-weight: 500;
        transition: color 0.2s;
        display: block;
        margin-bottom: 4px;
    }
    .attachment-name:hover {
        color: #217dbb;
        text-decoration: underline;
    }
    .attachment-meta {
        font-size: 12px;
    }
    .attachment-type {
        color: #7f8c8d;
        font-style: italic;
    }
    .attachment-actions {
        display: flex;
        gap: 8px;
        flex-shrink: 0;
    }
    .attachment-list .secondary-btn {
        padding: 4px 10px;
        font-size: 13px;
        border-radius: 3px;
        background: #f5f7fa;
        color: #333;
        border: 1px solid #dbe2ea;
        transition: background 0.2s, color 0.2s;
    }
    .attachment-list .secondary-btn:hover {
        background: #e6f0fa;
        color: #1976d2;
    }
    .preview-btn {
        background: #e8f5e8 !important;
        color: #2e7d2e !important;
        border-color: #a5d6a5 !important;
    }
    .preview-btn:hover {
        background: #d4eecc !important;
        color: #1e5f1e !important;
    }
    .attachment-popup-close {
        margin-top: 18px;
        width: 100%;
        background: #e0e0e0;
        color: #444;
        border-radius: 4px;
        font-size: 15px;
        padding: 8px 0;
        border: none;
        transition: background 0.2s;
    }
    .attachment-popup-close:hover {
        background: #bdbdbd;
    }
</style>