zjk
2026-07-23 b8c65d69788f95d5220b5883a5068b0985d0e061
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
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
<template>
  <view class="page-container" @touchstart="resetInactivityTimer" @click="resetInactivityTimer">
    <!-- 左侧柔光氛围 -->
    <view class="bg-glow"></view>
 
    <!-- 扫码页头部 -->
    <view class="header-area">
      <view class="left-action" @click="goBack">
        <view class="back-btn">
          <image :src="backIconImage" class="back-icon-img" mode="aspectFit"></image>
        </view>
        <text class="page-title">{{ mode === 'online' ? '现场登记' : (mode === 'signout' ? '签离' : '预约登记') }}</text>
      </view>
    </view>
 
    <!-- 步骤卡片组件 -->
    <StepProgress :currentStep="currentStep" :mode="mode" :steps="stepProgressSteps" />
 
    <!-- 步骤: 预约码验证 -->
    <template v-if="currentStepName === 'qr'">
      <view class="main-card">
        <text class="main-title">请将您的预约二维码放置到扫码位置</text>
        <text class="main-desc">保持二维码完整、清晰,距离扫码口约 10-20 厘米</text>
 
        <view class="device-area">
          <image :src="deviceScanImage" class="device-img" mode="aspectFit"></image>
        </view>
 
        <text class="helper-text">若识别失败,请调整手机亮度、避免反光,或联系工作人员协助</text>
      </view>
 
      <view class="bottom-area">
        <view class="help-card">
          <view class="highlight-bar"></view>
          <view class="card-title-row" style="margin-top: 16px;">
            <view class="icon-base">
              <image :src="hintIconImage" class="icon-base-img" mode="aspectFit"></image>
            </view>
            <text class="card-title">扫码小贴士</text>
          </view>
          <text class="help-content">请使用预约成功后收到的二维码,\n保持二维码完整显示后再靠近扫码区域</text>
        </view>
 
        <view class="action-card">
          <view class="highlight-bar"></view>
          <view class="card-title-row">
            <view class="icon-base">
              <image :src="returnIconImage" class="icon-base-img" mode="aspectFit"></image>
            </view>
            <text class="card-title">需要返回?</text>
          </view>
          <view class="main-btn" @click="goBack">
            <text class="btn-text">返回上一步</text>
          </view>
        </view>
      </view>
    </template>
 
    <!-- 步骤: 身份证验证 -->
    <template v-else-if="currentStepName === 'idcard'">
      <template v-if="!isManualInput">
        <view class="main-card">
          <text class="main-title">请将您的身份证放置读卡器位置</text>
          <text class="main-desc">请将身份证贴近设备感应区,系统将自动读取身份信息</text>
 
          <view class="name-hint-row" v-if="mode === 'appointment'">
            <view class="name-icon-box">
              <text class="name-icon-text">人</text>
            </view>
            <text class="name-text">姓名:{{ appointmentVisitorName }}</text>
          </view>
 
          <view class="device-area">
            <image :src="deviceIdScanImage" class="device-img" mode="aspectFit"></image>
          </view>
 
          <text class="helper-text">若识别失败,请联系工作人员协助</text>
        </view>
 
        <view class="bottom-area">
          <view class="help-card">
            <view class="highlight-bar"></view>
            <view class="card-title-row">
              <view class="icon-base">
                <image :src="hintIconImage" class="icon-base-img" mode="aspectFit"></image>
              </view>
              <text class="card-title">读卡小贴士</text>
            </view>
            <text class="help-content">请使用二代身份证原件放至读卡区位置</text>
          </view>
 
          <view class="action-card" v-if="allowManualIdCard">
            <view class="highlight-bar"></view>
            <view class="card-title-row">
              <view class="icon-base">
                <image :src="keyboardIconImage" class="icon-base-img" mode="aspectFit"></image>
              </view>
              <text class="card-title">未携带身份证?</text>
            </view>
            <view class="main-btn" @click="openManualInput">
              <text class="btn-text">手动录入信息</text>
            </view>
          </view>
        </view>
      </template>
 
      <!-- 手动录入信息 UI -->
      <template v-else>
        <view class="main-card manual-card" @click="dismissNameInput">
          <text class="main-title">手动录入身份证号</text>
          <text class="error-hint" v-if="mode === 'signout' && showMissingEntryHint">未检测到您的进场信息,请检查身份证号码是否正确</text>
 
          <view class="input-form-card" @click.stop>
            <template v-if="mode === 'online'">
              <view class="manual-input-box" style="height: 118px;" @touchstart.stop="handleNameInputBoxTouchStart" @click.stop>
                <input
                  type="text"
                  class="input-text real-input"
                  v-model="manualName"
                  :focus="activeManualInputTarget === 'name'"
                  placeholder="请输入您的姓名"
                  placeholder-style="font-size: 24px; font-weight: 500; color: #A0ACC4; letter-spacing: normal;"
                  style="width: 768px; height: 118px; border: none; outline: none; background: transparent; text-align: center;"
                  @focus="handleNameInputFocus"
                  @blur="handleNameInputBlur"
                />
              </view>
            </template>
            <view
              class="manual-input-box"
              style="height: 118px; position: relative;"
              @touchstart.stop="handleIdInputBoxClick"
            >
              <input
                type="text"
                class="input-text real-input"
                :value="idNumber"
                :disabled="true"
                placeholder="请输入您的身份证号码"
                placeholder-style="font-size: 24px; font-weight: 500; color: #A0ACC4; letter-spacing: normal;"
                style="width: 768px; height: 118px; border: none; outline: none; background: transparent; text-align: center;"
              />
              <view style="position: absolute; left: 0; top: 0; right: 0; bottom: 0; background-color: rgba(0,0,0,0);"></view>
            </view>
            <view class="input-helper-row">
              <text class="input-helper-text">请输入 18 位身份证号码,X 需大写</text>
            </view>
          </view>
 
          <view class="form-action-row" v-if="idNumber.length > 0">
            <view class="clear-btn" @click="clearInput">
              <text class="clear-btn-text">清空</text>
            </view>
            <view class="confirm-btn" @click="confirmManualInput">
              <text class="confirm-btn-text">确认</text>
            </view>
          </view>
          <view class="form-action-row" v-else>
            <view class="clear-btn-disabled">
              <text class="clear-btn-text-disabled">清空</text>
            </view>
            <view class="confirm-btn-disabled">
              <text class="confirm-btn-text-disabled">确认</text>
            </view>
          </view>
        </view>
 
        <!-- 自定义键盘 -->
        <view class="custom-keyboard" v-if="showCustomKeyboard">
          <view class="keyboard-grid">
            <view class="keyboard-row">
              <view class="key-btn" @click="inputKey('1')"><text class="key-text">1</text></view>
              <view class="key-btn" @click="inputKey('2')"><text class="key-text">2</text></view>
              <view class="key-btn" @click="inputKey('3')"><text class="key-text">3</text></view>
            </view>
            <view class="keyboard-row">
              <view class="key-btn" @click="inputKey('4')"><text class="key-text">4</text></view>
              <view class="key-btn" @click="inputKey('5')"><text class="key-text">5</text></view>
              <view class="key-btn" @click="inputKey('6')"><text class="key-text">6</text></view>
            </view>
            <view class="keyboard-row">
              <view class="key-btn" @click="inputKey('7')"><text class="key-text">7</text></view>
              <view class="key-btn" @click="inputKey('8')"><text class="key-text">8</text></view>
              <view class="key-btn" @click="inputKey('9')"><text class="key-text">9</text></view>
            </view>
            <view class="keyboard-row">
              <view class="key-btn key-x" @click="inputKey('X')"><text class="key-text-x">X</text></view>
              <view class="key-btn" @click="inputKey('0')"><text class="key-text">0</text></view>
              <view class="key-btn key-delete" @click="deleteKey"><text class="key-text-delete">删除</text></view>
            </view>
          </view>
        </view>
      </template>
    </template>
 
    <!-- 步骤: 人脸验证 -->
    <template v-else-if="currentStepName === 'face'">
      <view class="main-card">
        <view class="title-group">
          <text class="main-title">请面向屏幕完成人脸验证</text>
          <text class="sub-title">请摘下口罩和帽子,保持面部位于取景框内并正视摄像头</text>
          <view class="name-pill">
            <view class="name-icon">
              <text class="name-icon-text">人</text>
            </view>
            <text class="name-text">姓名:{{ identityDisplayName }}</text>
          </view>
        </view>
 
        <view class="face-capture-card">
          <view class="status-pill">
            <view class="status-dot"></view>
            <text class="status-text">{{ faceVerifyStatusText }}</text>
          </view>
 
          <view class="viewfinder-area">
            <view class="viewfinder-box">
              <live-pusher
                id="faceCamera"
                class="face-camera"
                mode="FHD"
                orientation="vertical"
                device-position="back"
                :muted="true"
                local-mirror="disable"
                :enable-camera="true"
                :auto-focus="true"
                :beauty="1"
                :whiteness="2"
                @error="handleFaceCameraError"
              />
              <view class="viewfinder-corner-wrap viewfinder-corner-wrap-tl">
                <view class="corner-donut corner-donut-tl"></view>
              </view>
              <view class="viewfinder-corner-wrap viewfinder-corner-wrap-tr">
                <view class="corner-donut corner-donut-tr"></view>
              </view>
              <view class="viewfinder-corner-wrap viewfinder-corner-wrap-bl">
                <view class="corner-donut corner-donut-bl"></view>
              </view>
              <view class="viewfinder-corner-wrap viewfinder-corner-wrap-br">
                <view class="corner-donut corner-donut-br"></view>
              </view>
              <view class="viewfinder-border-mask"></view>
              <!-- <view class="head-ellipse"></view>
              <view class="shoulder-ellipse"></view> -->
              <view ref="faceScanLineRef" class="scan-line"></view>
            </view>
            <text class="viewfinder-hint">请将脸部置于框内,保持静止</text>
          </view>
 
          <view class="hints-row">
            <view class="hint-item">
              <view class="hint-dot" style="background: #6EA2FF;"></view>
              <text class="hint-text">请正视屏幕</text>
            </view>
            <view class="hint-item">
              <view class="hint-dot" style="background: #86C7FF;"></view>
              <text class="hint-text">保持静止 2 秒</text>
            </view>
            <view class="hint-item">
              <view class="hint-dot" style="background: #FFC36B;"></view>
              <text class="hint-text">避免逆光遮挡</text>
            </view>
          </view>
        </view>
 
        <text class="bottom-subtext">系统将自动完成人脸采集与比对,请勿频繁移动或离开识别区域</text>
      </view>
 
      <view class="bottom-area">
        <view class="help-card">
          <view class="highlight-bar"></view>
          <view class="card-title-row">
            <view class="icon-base">
              <image :src="hintIconImage" class="icon-base-img" mode="aspectFit"></image>
            </view>
            <text class="card-title">识别提示</text>
          </view>
          <text class="help-content">{{ faceVerifyHelpText }}</text>
        </view>
 
        <view class="action-card">
          <view class="highlight-bar"></view>
          <view class="card-title-row">
            <view class="icon-base">
              <image :src="retryIconImage" class="icon-base-img" mode="aspectFit"></image>
            </view>
            <text class="card-title">识别失败?</text>
          </view>
          <view class="main-btn" @click="handleFaceVerifyNextStep">
            <text class="btn-text">重新采集人脸</text>
            <!-- <text class="btn-text">跳过人脸采集</text> -->
          </view>
        </view>
      </view>
    </template>
 
    <!-- 步骤: 接待人验证 -->
    <template v-else-if="currentStepName === 'host'">
      <view class="main-card">
        <view class="title-group">
          <text class="main-title">请接待人面向屏幕</text>
          <text class="sub-title">请接待人站在设备前,正视屏幕完成身份确认</text>
          <view class="name-pill" v-if="mode === 'appointment'">
            <view class="name-icon">
              <text class="name-icon-text">人</text>
            </view>
            <text class="name-text">姓名:{{ appointmentHostName }}</text>
          </view>
        </view>
 
        <view class="face-capture-card">
          <view class="status-pill">
            <view class="status-dot"></view>
            <text class="status-text">{{ hostVerifyStatusText }}</text>
          </view>
 
          <view class="viewfinder-area">
            <view class="viewfinder-box">
              <live-pusher
                id="hostCamera"
                class="face-camera"
                mode="FHD"
                orientation="vertical"
                device-position="back"
                :muted="true"
                local-mirror="disable"
                :enable-camera="true"
                :auto-focus="true"
                :beauty="1"
                :whiteness="2"
                @error="handleFaceCameraError"
              />
              <view class="viewfinder-corner-wrap viewfinder-corner-wrap-tl">
                <view class="corner-donut corner-donut-tl"></view>
              </view>
              <view class="viewfinder-corner-wrap viewfinder-corner-wrap-tr">
                <view class="corner-donut corner-donut-tr"></view>
              </view>
              <view class="viewfinder-corner-wrap viewfinder-corner-wrap-bl">
                <view class="corner-donut corner-donut-bl"></view>
              </view>
              <view class="viewfinder-corner-wrap viewfinder-corner-wrap-br">
                <view class="corner-donut corner-donut-br"></view>
              </view>
              <view class="viewfinder-border-mask"></view>
              <view ref="hostScanLineRef" class="scan-line"></view>
            </view>
            <text class="viewfinder-hint">请将脸部置于框内,保持静止</text>
          </view>
 
          <view class="hints-row">
            <view class="hint-item">
              <view class="hint-dot" style="background: #6EA2FF;"></view>
              <text class="hint-text">请正视屏幕</text>
            </view>
            <view class="hint-item">
              <view class="hint-dot" style="background: #86C7FF;"></view>
              <text class="hint-text">保持静止 2 秒</text>
            </view>
            <view class="hint-item">
              <view class="hint-dot" style="background: #FFC36B;"></view>
              <text class="hint-text">避免逆光遮挡</text>
            </view>
          </view>
        </view>
 
        <text class="bottom-subtext">系统将自动完成人脸采集与比对,请勿频繁移动或离开识别区域</text>
      </view>
 
      <view class="bottom-area">
        <view class="help-card">
          <view class="highlight-bar"></view>
          <view class="card-title-row">
            <view class="icon-base">
              <image :src="hintIconImage" class="icon-base-img" mode="aspectFit"></image>
            </view>
            <text class="card-title">验证提示</text>
          </view>
          <text class="help-content">请由接待人本人操作;\n接待人可以直接使用门禁卡刷卡验证</text>
        </view>
 
        <view class="action-card">
          <view class="highlight-bar" style="background: #6EA2FF;"></view>
          <view class="card-title-row">
            <view class="icon-base">
              <image :src="retryIconImage" class="icon-base-img" mode="aspectFit"></image>
            </view>
            <text class="card-title">验证失败?</text>
          </view>
          <view class="main-btn" @click="retryFaceVerify">
            <text class="btn-text">重新验证接待人</text>
            <!-- <text class="btn-text">跳过人脸采集</text> -->
          </view>
        </view>
      </view>
    </template>
 
    <!-- 步骤: 完善登记信息 (仅现场登记有此步骤) -->
    <template v-else-if="currentStepName === 'form'">
      <view class="form-card">
        <view class="form-row">
          <text class="label">访问结束时间:</text>
          <view class="datetime-group">
            <view class="input-box date-box">
              <image :src="calendarIconImage" class="field-prefix-icon-img" mode="aspectFit"></image>
              <text class="input-value">{{ visitEndDateText }}</text>
            </view>
            <view class="input-box time-box pressable-box" @click="openTimePicker">
              <text class="time-value">{{ selectedTime || '18:00' }}</text>
              <image :src="clockIconImage" class="field-suffix-icon-img" mode="aspectFit"></image>
            </view>
          </view>
        </view>
 
        <view class="form-row">
          <text class="label">车辆进园(选填):</text>
          <view class="input-box full-box pressable-box" @click="openPlateKeyboard">
            <text :class="plateNumber ? 'input-value plate-value' : 'placeholder'">{{ plateNumber || '请输入车牌号' }}</text>
          </view>
        </view>
 
        <view class="form-row">
          <text class="label">访问区域:</text>
          <view class="input-box full-box between-box pressable-box" @click="openAreaPicker">
            <text :class="selectedAreas.length ? 'input-value' : 'placeholder'">{{ selectedAreas.length ? `已选择 ${selectedAreas.length} 项` : '请选择' }}</text>
            <image :src="returnIconImage" class="field-arrow-icon-img reverse-arrow" mode="aspectFit"></image>
          </view>
        </view>
 
        <view class="selected-area-box" v-if="selectedAreas.length">
          <view class="tag-row">
            <view class="tag-item" v-for="areaId in selectedAreas" :key="areaId">
              <text class="tag-text">{{ getAreaNameById(areaId) }}</text>
              <text class="tag-x" @click.stop="removeArea(areaId)">×</text>
            </view>
          </view>
        </view>
 
        <view class="save-btn" @click="nextStep">
          <text class="save-btn-text">保存</text>
        </view>
      </view>
    </template>
 
    <!-- 步骤: 打印凭条 -->
    <template v-else-if="currentStepName === 'print'">
      <view class="main-card">
        <text class="main-title">请等待打印凭条</text>
 
        <view class="print-demo-card">
          <image :src="printTicketDemoImage" class="print-demo-img" mode="aspectFit"></image>
        </view>
      </view>
 
      <view class="bottom-area">
        <view class="help-card">
          <view class="highlight-bar"></view>
          <view class="card-title-row">
            <view class="icon-base">
              <image :src="hintIconImage" class="icon-base-img" mode="aspectFit"></image>
            </view>
            <text class="card-title">取条提示</text>
          </view>
          <text class="help-content">请在凭条完全打印后再取走;\n如长时间未出条,请联系现场工作人员协助</text>
        </view>
 
        <view class="action-card">
          <view class="highlight-bar" style="background: #6EA2FF;"></view>
          <view class="card-title-row">
            <view class="icon-base">
              <image :src="retryIconImage" class="icon-base-img" mode="aspectFit"></image>
            </view>
            <text class="card-title">未打印成功?</text>
          </view>
          <view class="main-btn" @click="startPrintTicket">
            <text class="btn-text">重新打印凭条</text>
          </view>
        </view>
      </view>
    </template>
 
  </view>
  <view class="mask-layer" v-if="showTimePicker || showAreaPicker" @click="closeAllPopups"></view>
  <view class="bottom-sheet time-sheet" v-if="showTimePicker" @click.stop>
      <view class="sheet-head">
        <text class="sheet-title">选择访问结束时间</text>
        <text class="sheet-close" @click="showTimePicker = false">关闭</text>
      </view>
      <view class="time-picker-body">
        <view class="time-column">
          <text class="time-column-title">时</text>
          <scroll-view scroll-y class="time-scroll">
            <view
              v-for="hour in hours"
              :key="hour"
              class="time-item"
              :class="{ 'time-item-active': tempHour === hour }"
              @click="tempHour = hour"
            >
              <text class="time-item-text">{{ hour }}</text>
            </view>
          </scroll-view>
        </view>
        <view class="time-column">
          <text class="time-column-title">分</text>
          <scroll-view scroll-y class="time-scroll">
            <view
              v-for="minute in minutes"
              :key="minute"
              class="time-item"
              :class="{ 'time-item-active': tempMinute === minute }"
              @click="tempMinute = minute"
            >
              <text class="time-item-text">{{ minute }}</text>
            </view>
          </scroll-view>
        </view>
      </view>
      <view class="sheet-confirm-btn" @click="confirmTimePicker">
        <text class="sheet-confirm-text">确定</text>
      </view>
    </view>
 
    <view class="bottom-sheet area-sheet" v-if="showAreaPicker" @click.stop>
      <view class="sheet-head area-sheet-head">
        <view class="sheet-head-placeholder"></view>
        <text class="sheet-title area-title">选择访问区域</text>
        <view class="area-close-btn" @click="showAreaPicker = false">
          x
        </view>
      </view>
      <view class="area-list-card">
        <view class="area-column area-primary-column">
          <view
            v-for="area in primaryAreaOptions"
            :key="area"
            class="primary-area-row"
            :class="{ 'primary-area-row-active': tempPrimaryArea === area }"
            @click="selectPrimaryArea(area)"
          >
            <view class="primary-area-left">
              <view
                class="primary-check"
                :class="{
                  'primary-check-active': getPrimarySelectionState(area) !== 'none',
                  'primary-check-partial': getPrimarySelectionState(area) === 'partial'
                }"
                @click.stop="togglePrimaryCheckbox(area)"
              >
                <image v-if="getPrimarySelectionState(area) === 'full'" :src="successIconImage" class="check-icon-img" mode="aspectFit"></image>
                <view v-else-if="getPrimarySelectionState(area) === 'partial'" class="partial-line"></view>
              </view>
              <text class="primary-area-text" :class="{ 'primary-area-text-active': tempPrimaryArea === area }">{{ area }}</text>
            </view>
            <image :src="returnIconImage" class="field-arrow-icon-img reverse-arrow" mode="aspectFit"></image>
          </view>
        </view>
        <view class="area-column area-secondary-column">
          <view
            v-for="area in currentSecondaryOptions"
            :key="area.id"
            class="secondary-area-row"
            :class="{ 'secondary-area-row-active': tempSelectedAreas.includes(area.id) }"
            @click="toggleTempArea(area.id)"
          >
            <view class="secondary-check" :class="{ 'secondary-check-active': tempSelectedAreas.includes(area.id) }">
              <image v-if="tempSelectedAreas.includes(area.id)" :src="successIconImage" class="check-icon-img" mode="aspectFit"></image>
            </view>
            <text class="secondary-area-text" :class="{ 'secondary-area-text-active': tempSelectedAreas.includes(area.id) }">{{ area.name }}</text>
          </view>
        </view>
      </view>
      <view class="sheet-confirm-btn" @click="confirmAreaPicker">
        <text class="sheet-confirm-text">确定</text>
      </view>
    </view>
 
    <view class="bottom-sheet plate-sheet" v-if="showPlateKeyboard" @click.stop>
      <view class="sheet-head compact-head">
        <text class="sheet-title">录入车牌号</text>
        <text class="sheet-close" @click="showPlateKeyboard = false">关闭</text>
      </view>
      <view class="plate-step-tip">
        <text class="plate-step-tip-text">{{ plateInputStep === 'province' ? '第一步:请选择省份简称' : '第二步:请输入数字字母' }}</text>
      </view>
      <view class="plate-section" v-if="plateInputStep === 'province'">
        <view class="province-grid">
          <view
            v-for="(province, index) in provinceKeys"
            :key="province"
            class="keyboard-key province-key"
            :class="{ 'keyboard-key-active': plateNumber.startsWith(province) }"
            :style="{ marginRight: (index + 1) % 9 === 0 ? '0' : '11px' }"
            @click="inputProvince(province)"
          >
            <text class="keyboard-key-text">{{ province }}</text>
          </view>
        </view>
      </view>
      <view class="plate-section" v-else>
        <view class="plate-grid-row" v-for="(row, rowIndex) in plateKeys" :key="rowIndex">
          <view
            v-for="(key, keyIndex) in row"
            :key="key"
            class="keyboard-key"
            :class="{
              'keyboard-key-disabled': !canInputPlateKey(key),
              'keyboard-key-special': ['学', '警', '港', '澳'].includes(key)
            }"
            :style="{ marginRight: (keyIndex === row.length - 1 && rowIndex !== 3) ? '0' : '12px' }"
            @click="inputPlateKey(key)"
          >
            <text class="keyboard-key-text">{{ key }}</text>
          </view>
          <view v-if="rowIndex === 3" class="keyboard-key delete-key" style="margin-right: 0;" @click="deletePlateKey">
            <image :src="keyboardIconImage" class="delete-key-icon-img" mode="aspectFit"></image>
          </view>
        </view>
      </view>
      <view class="plate-action-row">
        <view class="plate-secondary-btn" @click="clearPlateNumber">
          <text class="plate-secondary-text">清空</text>
        </view>
        <view class="sheet-confirm-btn plate-confirm-btn" @click="showPlateKeyboard = false">
          <text class="sheet-confirm-text">确定</text>
        </view>
      </view>
    </view>
    <view v-if="noticeDialog.visible" class="notice-dialog-wrapper">
      <view class="notice-dialog-mask"></view>
      <view class="notice-dialog-card">
        <view class="notice-dialog-copy">
          <text class="notice-dialog-title">{{ noticeDialog.title }}</text>
          <text v-if="noticeDialog.description" class="notice-dialog-desc">{{ noticeDialog.description }}</text>
        </view>
        <view class="notice-dialog-button-row">
          <view class="notice-dialog-close-btn" @click="closeNoticeDialog">
            <text class="notice-dialog-close-text">{{ noticeDialog.buttonText }}({{ noticeDialog.countdown }})</text>
          </view>
        </view>
      </view>
    </view>
</template>
 
<script setup>
import { ref, computed, onMounted, onUnmounted, watch, nextTick, getCurrentInstance } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import StepProgress from '../../components/StepProgress.vue';
import { HardwareAPI } from '../../utils/visitorDevice';
import { saveImageToLocal, deleteLocalImage } from '../../utils/fs';
import { getVisitAreaTree } from '../../api/visitArea';
import { insertOfflineRecord, findEntryRecordByIdCard, markEntryRecordSignedOut, getOfflineConfig, saveOfflineConfig } from '../../utils/db';
import { buildBaseUrl, getRequestServerConfig } from '../../utils/request';
import { getLocalEmployeeVerifyList } from '../../api/employee';
import { getLocalSystemConfig } from '../../api/visitorConfig';
import { startSyncQueue } from '../../utils/syncEngine';
import {
  parseHikvisionQrcodePayload,
  validateAppointmentQrcodePayload,
} from '../../utils/hikvisionQrcode';
import {
  clearAppointmentIdCardPayload,
  clearAppointmentQrPayload,
  getAppointmentQrPayload,
  saveAppointmentIdCardPayload,
  saveAppointmentQrPayload,
} from '../../utils/appointmentIdentityStore';
import backIconImage from '../../static/appointment-scan/back.png';
import hintIconImage from '../../static/appointment-scan/hint-icon.png';
import returnIconImage from '../../static/appointment-scan/return-icon.png';
import retryIconImage from '../../static/appointment-scan/retry-icon.png';
import keyboardIconImage from '../../static/appointment-scan/keyboard-icon.png';
import successIconImage from '../../static/appointment-scan/success.png';
import calendarIconImage from '../../static/appointment-scan/calendar-icon.png';
import clockIconImage from '../../static/appointment-scan/clock-icon.png';
import printTicketDemoImage from '../../static/appointment-scan/print-ticket-demo.png';
import deviceScanImage from '../../static/appointment-scan/device-scan.png';
import deviceIdScanImage from '../../static/appointment-scan/device-id-scan.png';
 
const appointmentQrcodePayload = ref(null);
const appointmentIdCardPayload = ref(null);
const faceScanLineRef = ref(null);
const hostScanLineRef = ref(null);
const facePreviewReady = ref(false);
const liveFacePhotoPath = ref('');
const hostLiveFacePhotoPath = ref('');
let hasMountedHardwareFlow = false;
const scanLineOffset = 400;
let scanLineAnimationTicket = 0;
 
const getNvueAnimationModule = () => {
  if (typeof weex === 'undefined' || !weex?.requireModule) {
    return null;
  }
 
  return weex.requireModule('animation');
};
 
const getScanLineRefByStep = (stepName) => {
  if (stepName === 'face') {
    return faceScanLineRef.value;
  }
  if (stepName === 'host') {
    return hostScanLineRef.value;
  }
  return null;
};
 
const resetScanLinePosition = (stepName) => {
  const animationModule = getNvueAnimationModule();
  const targetRef = getScanLineRefByStep(stepName);
  if (!animationModule || !targetRef) {
    return;
  }
 
  animationModule.transition(targetRef, {
    styles: {
      transform: 'translateY(0px)',
    },
    duration: 0,
    delay: 0,
    timingFunction: 'linear',
  });
};
 
const runScanLineAnimation = (stepName, ticket, direction) => {
  const animationModule = getNvueAnimationModule();
  const targetRef = getScanLineRefByStep(stepName);
  if (!animationModule || !targetRef || ticket !== scanLineAnimationTicket) {
    return;
  }
 
  const targetOffset = direction > 0 ? scanLineOffset : 0;
  animationModule.transition(targetRef, {
    styles: {
      transform: `translateY(${targetOffset}px)`,
    },
    duration: 1800,
    delay: 0,
    timingFunction: 'ease-in-out',
  }, () => {
    if (ticket !== scanLineAnimationTicket) {
      return;
    }
 
    runScanLineAnimation(stepName, ticket, direction * -1);
  });
};
 
const stopScanLineAnimation = () => {
  scanLineAnimationTicket += 1;
  resetScanLinePosition('face');
  resetScanLinePosition('host');
};
 
const startScanLineAnimation = async (stepName) => {
  scanLineAnimationTicket += 1;
  const currentTicket = scanLineAnimationTicket;
  resetScanLinePosition(stepName);
  await nextTick();
 
  const targetRef = getScanLineRefByStep(stepName);
  if (!targetRef || currentTicket !== scanLineAnimationTicket) {
    return;
  }
 
  runScanLineAnimation(stepName, currentTicket, 1);
};
 
const syncScanLineAnimationByStep = async (stepName) => {
  if (stepName === 'face' || stepName === 'host') {
    await startScanLineAnimation(stepName);
    return;
  }
 
  stopScanLineAnimation();
};
const noticeDialog = ref({
  visible: false,
  title: '',
  description: '',
  buttonText: '关闭',
  duration: 5,
  countdown: 5,
});
let noticeDialogTimer = null;
const INACTIVITY_AUTO_BACK_MS = 60 * 1000;
let inactivityAutoBackTimer = null;
 
const clearInactivityTimer = () => {
  if (inactivityAutoBackTimer) {
    clearTimeout(inactivityAutoBackTimer);
    inactivityAutoBackTimer = null;
  }
};
 
const handleInactivityAutoBack = () => {
  clearInactivityTimer();
  uni.reLaunch({
    url: '/pages/home/index',
  });
};
 
const resetInactivityTimer = () => {
  clearInactivityTimer();
  inactivityAutoBackTimer = setTimeout(() => {
    handleInactivityAutoBack();
  }, INACTIVITY_AUTO_BACK_MS);
};
 
const stopNoticeDialogCountdown = () => {
  if (noticeDialogTimer) {
    clearInterval(noticeDialogTimer);
    noticeDialogTimer = null;
  }
};
 
const startNoticeDialogCountdown = () => {
  stopNoticeDialogCountdown();
  noticeDialog.value.countdown = noticeDialog.value.duration;
 
  noticeDialogTimer = setInterval(() => {
    if (!noticeDialog.value.visible) {
      stopNoticeDialogCountdown();
      return;
    }
 
    noticeDialog.value.countdown -= 1;
    if (noticeDialog.value.countdown <= 0) {
      closeNoticeDialog();
    }
  }, 1000);
};
 
const appointmentVisitorName = computed(() => {
  if (mode.value === 'online') {
    return appointmentIdCardPayload.value?.name
      || appointmentIdCardPayload.value?.visitorName
      || '请读取身份证';
  }
 
  return appointmentQrcodePayload.value?.visitorName || '请使用预约访客本人的身份证';
});
const appointmentHostName = computed(() => {
  if (mode.value === 'online') {
    return '';
  }
 
  return appointmentQrcodePayload.value?.beVisitorName || '请等待接待人完成验证';
});
const formatStandardDateTime = (dateValue) => {
  const date = dateValue instanceof Date ? dateValue : new Date(dateValue);
  if (!(date instanceof Date) || Number.isNaN(date.getTime())) {
    return '';
  }
 
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, '0');
  const day = String(date.getDate()).padStart(2, '0');
  const hour = String(date.getHours()).padStart(2, '0');
  const minute = String(date.getMinutes()).padStart(2, '0');
  const second = String(date.getSeconds()).padStart(2, '0');
  return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
};
const visitEndDateText = computed(() => {
  const today = new Date();
  const year = today.getFullYear();
  const month = String(today.getMonth() + 1).padStart(2, '0');
  const day = String(today.getDate()).padStart(2, '0');
  return `${year}-${month}-${day}`;
});
const identityDisplayName = computed(() => {
  if (mode.value === 'online') {
    return appointmentIdCardPayload.value?.name
      || appointmentIdCardPayload.value?.visitorName
      || '请按提示完成人脸认证';
  }
 
  return appointmentQrcodePayload.value?.visitorName
    || appointmentIdCardPayload.value?.name
    || appointmentIdCardPayload.value?.visitorName
    || '请按提示完成人脸认证';
});
const faceVerifyStatusText = ref('等待开始人证比对');
const hostVerifyStatusText = ref('等待接待人开始验证');
let faceCameraContext = null;
let hostCameraContext = null;
let faceJudgePollTimer = null;
let faceCaptureDelayTimer = null;
let judgeFaceSessionId = 0;
let isJudgeFaceRunning = false;
const currentInstance = getCurrentInstance();
const employeeVerifyList = ref([]);
const hostMatchedEmployee = ref(null);
const FACE_JUDGE_POLL_INTERVAL = 1000;
const FACE_CAPTURE_DELAY = 2000;
const LIVE_PUSHER_READY_DELAY = 0;
 
const wait = (delay = 0) => {
  return new Promise((resolve) => {
    setTimeout(resolve, delay);
  });
};
 
const getFirstFilledValue = (source = {}, keys = []) => {
  for (const key of keys) {
    const value = source?.[key];
    if (value !== undefined && value !== null && String(value).trim() !== '') {
      return value;
    }
  }
  return '';
};
 
const normalizeLookupValue = (value = '') => {
  return String(value || '').trim().toLowerCase();
};
 
const normalizeCardNoValue = (value = '') => {
  return String(value || '').trim().toUpperCase();
};
 
const getHostEmployeeLookupCandidates = (payload = {}) => {
  const exactCandidates = [
    payload?.beVisitorId,
    payload?.beVisitorCode,
    payload?.beVisitorNo,
    payload?.beVisitorJobNo,
    payload?.beVisitorWorkNo,
    payload?.beVisitorCardNo,
    payload?.intervieweeId,
    payload?.intervieweeCode,
    payload?.intervieweeNo,
    payload?.receiverId,
    payload?.receiverCode,
    payload?.receiverCardNo,
  ].map(normalizeCardNoValue).filter(Boolean);
 
  const nameCandidates = [
    payload?.beVisitorName,
    payload?.intervieweeName,
    payload?.receiverName,
  ].map(normalizeLookupValue).filter(Boolean);
 
  return {
    exactCandidates: Array.from(new Set(exactCandidates)),
    nameCandidates: Array.from(new Set(nameCandidates)),
  };
};
 
const getEmployeeExactMatchCandidates = (employee = {}) => {
  return [
    employee?.employeeId,
    employee?.employeeCode,
    employee?.employeeNo,
    employee?.jobNo,
    employee?.workNo,
    employee?.staffNo,
    employee?.userId,
    employee?.userCode,
    employee?.cardNo,
    employee?.cardNum,
    employee?.cardId,
    employee?.icCardNo,
    employee?.accessCardNo,
    employee?.employeeCardNo,
  ].map(normalizeCardNoValue).filter(Boolean);
};
 
const getEmployeeNameCandidates = (employee = {}) => {
  return [
    employee?.employeeName,
    employee?.name,
    employee?.userName,
    employee?.staffName,
    employee?.realName,
  ].map(normalizeLookupValue).filter(Boolean);
};
 
const resolveEmployeeFacePhotoAddress = (employee = {}) => {
  const rawPhotoAddress = getFirstFilledValue(employee, [
    'faceImage',
    'faceImageUrl',
    'faceUrl',
    'facePhoto',
    'photoAddress',
    'photoUrl',
    'avatar',
    'avatarUrl',
    'headImg',
    'headImage',
    'imageUrl',
  ]);
 
  const normalizedPhotoAddress = String(rawPhotoAddress || '').trim();
  if (!normalizedPhotoAddress) {
    return '';
  }
 
  // 兼容旧缓存里仍是 base64/dataURL 的员工脸照,避免被误判成“没有照片”
  if (/^data:image\/[a-zA-Z0-9+.-]+;base64,/.test(normalizedPhotoAddress)) {
    return normalizedPhotoAddress;
  }
 
  if (/^(https?:\/\/|file:\/\/|content:|_doc\/|\/storage\/)/.test(normalizedPhotoAddress)) {
    return normalizedPhotoAddress;
  }
 
  if (normalizedPhotoAddress.startsWith('/')) {
    const baseUrl = buildBaseUrl(getRequestServerConfig());
    return baseUrl ? `${baseUrl}${normalizedPhotoAddress}` : normalizedPhotoAddress;
  }
 
  return normalizedPhotoAddress;
};
 
const findMatchedHostEmployee = (payload = appointmentQrcodePayload.value || {}) => {
  if (!Array.isArray(employeeVerifyList.value) || employeeVerifyList.value.length === 0) {
    return null;
  }
 
  const { exactCandidates, nameCandidates } = getHostEmployeeLookupCandidates(payload);
 
  if (exactCandidates.length > 0) {
    const exactMatchedEmployee = employeeVerifyList.value.find((employee) => {
      const employeeCandidates = getEmployeeExactMatchCandidates(employee);
      return employeeCandidates.some((candidate) => exactCandidates.includes(candidate));
    });
 
    if (exactMatchedEmployee) {
      return exactMatchedEmployee;
    }
  }
 
  if (nameCandidates.length > 0) {
    return employeeVerifyList.value.find((employee) => {
      const employeeNameCandidates = getEmployeeNameCandidates(employee);
      return employeeNameCandidates.some((candidate) => nameCandidates.includes(candidate));
    }) || null;
  }
 
  return null;
};
 
const getHostFaceEmployees = () => {
  if (!Array.isArray(employeeVerifyList.value) || employeeVerifyList.value.length === 0) {
    return [];
  }
 
  return employeeVerifyList.value.filter((employee) => Boolean(resolveEmployeeFacePhotoAddress(employee)));
};
 
const findEmployeeByCardNo = (cardNo = '') => {
  const normalizedCardNo = normalizeCardNoValue(cardNo);
  if (!normalizedCardNo || !Array.isArray(employeeVerifyList.value) || employeeVerifyList.value.length === 0) {
    return null;
  }
 
  return employeeVerifyList.value.find((employee) => {
    const employeeCardNo = normalizeCardNoValue(getMatchedHostEmployeeCardNo(employee));
    return Boolean(employeeCardNo) && employeeCardNo === normalizedCardNo;
  }) || null;
};
 
const getMatchedHostEmployeeCardNo = (employee = {}) => {
  return getFirstFilledValue(employee, [
    'cardNo',
    'cardNum',
    'cardId',
    'icCardNo',
    'accessCardNo',
    'employeeCardNo',
  ]);
};
 
const getReaderCardNo = (cardData = {}) => {
  return getFirstFilledValue(cardData, [
    'cardNo',
    'cardNum',
    'cardId',
    'icCardNo',
    'accessCardNo',
    'serialNo',
    'uid',
    'cardSerialNo',
  ]);
};
 
const verifyHostEmployeeCard = (cardData = {}) => {
  const readCardNo = normalizeCardNoValue(getReaderCardNo(cardData));
 
  if (!readCardNo) {
    return {
      passed: false,
      reason: 'card_no_missing',
    };
  }
 
  if (mode.value === 'online') {
    const onsiteMatchedEmployee = findEmployeeByCardNo(readCardNo);
    hostMatchedEmployee.value = onsiteMatchedEmployee;
 
    if (!onsiteMatchedEmployee) {
      return {
        passed: false,
        reason: 'employee_not_found',
        readCardNo,
      };
    }
 
    return {
      passed: true,
      employee: onsiteMatchedEmployee,
      readCardNo,
    };
  }
 
  const matchedEmployee = findMatchedHostEmployee();
  hostMatchedEmployee.value = matchedEmployee;
 
  if (!matchedEmployee) {
    return {
      passed: false,
      reason: 'employee_not_found',
    };
  }
 
  const employeeCardNo = normalizeCardNoValue(getMatchedHostEmployeeCardNo(matchedEmployee));
  if (!employeeCardNo) {
    return {
      passed: false,
      reason: 'employee_card_missing',
      employee: matchedEmployee,
    };
  }
 
  if (employeeCardNo !== readCardNo) {
    return {
      passed: false,
      reason: 'card_no_mismatch',
      employee: matchedEmployee,
      employeeCardNo,
      readCardNo,
    };
  }
 
  return {
    passed: true,
    employee: matchedEmployee,
    readCardNo,
  };
};
 
const compareHostFaceWithEmployee = async (livePhotoAddress, employee = {}) => {
  const employeeFacePhotoAddress = resolveEmployeeFacePhotoAddress(employee);
  if (!employeeFacePhotoAddress) {
    return {
      passed: false,
      employee,
    };
  }
 
  try {
    const faceResult = await new Promise((resolve, reject) => {
      HardwareAPI.startFaceVerify(
        {
          face: livePhotoAddress,
          photo: employeeFacePhotoAddress,
          employeeFacePhotoAddress,
          photoAddress: employeeFacePhotoAddress,
          capturePhotoAddress: livePhotoAddress,
        },
        (result) => resolve(result),
        (error) => reject(error),
      );
    });
 
    return {
      passed: isFaceVerifyPassed(faceResult),
      employee,
      faceResult,
    };
  } catch (error) {
    return {
      passed: false,
      employee,
      error,
    };
  }
};
 
const compareHostFaceWithAllEmployees = async (livePhotoAddress) => {
  const candidateEmployees = getHostFaceEmployees();
  for (const employee of candidateEmployees) {
    const compareResult = await compareHostFaceWithEmployee(livePhotoAddress, employee);
    if (compareResult.passed) {
      return compareResult;
    }
  }
 
  return {
    passed: false,
    employee: null,
  };
};
 
const loadEmployeeVerifyList = async () => {
  try {
    employeeVerifyList.value = await getLocalEmployeeVerifyList();
    hostMatchedEmployee.value = findMatchedHostEmployee();
  } catch (error) {
    console.error('读取本地员工验证列表失败:', error);
    employeeVerifyList.value = [];
    hostMatchedEmployee.value = null;
  }
};
 
const hours = Array.from({ length: 24 }, (_, index) => String(index).padStart(2, '0'));
const minutes = Array.from({ length: 60 }, (_, index) => String(index).padStart(2, '0'));
const provinceKeys = ['京', '津', '晋', '冀', '蒙', '辽', '吉', '黑', '沪', '苏', '浙', '皖', '闽', '赣', '鲁', '豫', '鄂', '湘', '粤', '桂', '琼', '渝', '川', '贵', '云', '藏', '陕', '甘', '青', '宁', '新', '无'];
const plateKeys = [
  ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],
  ['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '军'],
  ['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', '警'],
  ['Z', 'X', 'C', 'V', 'B', 'N', 'M', '港', '澳']
];
 
// 访问区域树数据
const visitAreaTree = ref([]);
 
const primaryAreaOptions = computed(() => {
  return visitAreaTree.value.map(item => item.name || item.areaName || item.label || item.areaId || item.id);
});
 
const secondaryAreaMap = computed(() => {
  const map = {};
  visitAreaTree.value.forEach(item => {
    const key = item.name || item.areaName || item.label || item.areaId || item.id;
 
    // 如果没有子节点,则将自身作为可选项,确保能被选中
    const children = (item.children && item.children.length > 0) ? item.children : [item];
 
    // 提取子节点的 name 和 id
    map[key] = children.map(child => ({
      id: child.areaId || child.id,
      name: child.name || child.areaName || child.label || child.areaId || child.id
    }));
  });
  return map;
});
 
const currentStep = ref(1);
const mode = ref('appointment');
const systemFlowConfig = ref({});
 
const allowManualIdCard = computed(() => {
  return systemFlowConfig.value.manualIdCardEnabled !== false;
});
 
const registerReceiverConfirmEnabled = computed(() => {
  return systemFlowConfig.value.registerReceiverConfirmEnabled !== false;
});
 
const signReceiverConfirmEnabled = computed(() => {
  return systemFlowConfig.value.signReceiverConfirmEnabled !== false;
});
 
const shouldShowHostStep = computed(() => {
  if (mode.value === 'signout') {
    return signReceiverConfirmEnabled.value;
  }
  return registerReceiverConfirmEnabled.value;
});
 
const receiverVerifyMethodValue = computed(() => {
  return shouldShowHostStep.value ? '2' : '';
});
 
const stepProgressSteps = computed(() => {
  if (mode.value === 'appointment') {
    const steps = [
      { text: '预约码验证', icon: 'qr' },
      { text: '身份证验证', icon: 'idcard' },
      { text: '人脸验证', icon: 'face' },
    ];
    if (shouldShowHostStep.value) {
      steps.push({ text: '接待人验证', icon: 'user' });
    }
    steps.push({ text: '打印凭条', icon: 'print' });
    return steps;
  }
 
  if (mode.value === 'online') {
    const steps = [
      { text: '身份证验证', icon: 'idcard' },
      { text: '人脸验证', icon: 'face' },
    ];
    if (shouldShowHostStep.value) {
      steps.push({ text: '接待人验证', icon: 'user' });
    }
    // steps.push({ text: '完善登记信息', icon: 'form' });
    steps.push({ text: '完善信息', icon: 'form' });
    steps.push({ text: '打印凭条', icon: 'print' });
    return steps;
  }
 
  const steps = [
    { text: '身份证验证', icon: 'idcard' },
    { text: '人脸验证', icon: 'face' },
  ];
  if (shouldShowHostStep.value) {
    steps.push({ text: '接待人验证', icon: 'user' });
  }
  return steps;
});
 
const flowStepNames = computed(() => {
  if (mode.value === 'appointment') {
    const steps = ['qr', 'idcard', 'face'];
    if (shouldShowHostStep.value) {
      steps.push('host');
    }
    steps.push('print');
    return steps;
  }
 
  if (mode.value === 'online') {
    const steps = ['idcard', 'face'];
    if (shouldShowHostStep.value) {
      steps.push('host');
    }
    steps.push('form');
    steps.push('print');
    return steps;
  }
 
  const steps = ['idcard', 'face'];
  if (shouldShowHostStep.value) {
    steps.push('host');
  }
  return steps;
});
 
const faceVerifyHelpText = computed(() => {
  if (mode.value === 'signout') {
    return shouldShowHostStep.value
      ? '请确保现场光线适中,面部无遮挡;\n识别成功后系统将自动进入下一步接待人验证'
      : '请确保现场光线适中,面部无遮挡;\n识别成功后系统将自动完成签离流程';
  }
 
  if (mode.value === 'online') {
    return shouldShowHostStep.value
      ? '请确保现场光线适中,面部无遮挡;\n识别成功后系统将自动进入下一步接待人验证'
      : '请确保现场光线适中,面部无遮挡;\n识别成功后系统将自动进入完善登记信息';
  }
 
  return shouldShowHostStep.value
    ? '请确保现场光线适中,面部无遮挡;\n识别成功后系统将自动进入下一步接待人验证'
    : '请确保现场光线适中,面部无遮挡;\n识别成功后系统将自动进入打印凭条';
});
 
const configuredPrintFieldOptions = computed(() => {
  if (Array.isArray(systemFlowConfig.value?.printFieldOptions) && systemFlowConfig.value.printFieldOptions.length > 0) {
    return systemFlowConfig.value.printFieldOptions;
  }
 
  return [
    { fieldCode: 'visitorName', fieldName: '访客姓名' },
    { fieldCode: 'idCard', fieldName: '身份证号' },
    { fieldCode: 'appointmentTimeRange', fieldName: '预约时间范围' },
    { fieldCode: 'interviewee', fieldName: '被访者' },
    { fieldCode: 'visitorFaceImage', fieldName: '访客人脸图片' },
    { fieldCode: 'registerNo', fieldName: '登记编号' },
    { fieldCode: 'plateNo', fieldName: '车牌号' },
    { fieldCode: 'visitReason', fieldName: '来访事由' },
    { fieldCode: 'visitArea', fieldName: '访问区域' },
  ];
});
 
// 手动录入状态
const isManualInput = ref(false);
const idNumber = ref('');
const manualName = ref('');
const showMissingEntryHint = ref(false);
const isNameInputFocused = ref(false); // 记录姓名输入框是否处于聚焦状态
const activeManualInputTarget = ref('id');
 
const loadSystemFlowConfig = async () => {
  try {
    const config = await getLocalSystemConfig();
    systemFlowConfig.value = config || {};
    if (!allowManualIdCard.value) {
      isManualInput.value = false;
    }
  } catch (error) {
    console.error('读取登记流程系统配置失败:', error);
    systemFlowConfig.value = {};
  }
};
 
const showCustomKeyboard = computed(() => {
  if (mode.value === 'online') {
    // 现场登记:只在身份证输入态显示自定义键盘
    return activeManualInputTarget.value === 'id';
  }
  // 预约登记/签离等其他模式:长显
  return true;
});
 
// 完善登记信息表单状态
const showTimePicker = ref(false);
const showPlateKeyboard = ref(false);
const showAreaPicker = ref(false);
const plateInputStep = ref('province');
const selectedTime = ref('18:00');
const tempHour = ref('18');
const tempMinute = ref('00');
const plateNumber = ref('');
const selectedAreas = ref([]); // 存储选中的区域 ID
const tempPrimaryArea = ref('');
const tempSelectedAreas = ref([]); // 存储临时选中的区域 ID
const currentSecondaryOptions = computed(() => secondaryAreaMap.value[tempPrimaryArea.value] || []);
const normalizedPlateLength = computed(() => plateNumber.value.length);
 
// 获取选中区域的名称用于展示
const getAreaNameById = (id) => {
  for (const key in secondaryAreaMap.value) {
    const found = secondaryAreaMap.value[key].find(child => String(child.id) === String(id));
    if (found) return found.name;
  }
  return id;
};
 
// 获取区域完整数据,用于后续提交和打印
const getSelectedAreaNames = () => {
  return selectedAreas.value.map(id => getAreaNameById(id)).join(',');
};
 
const inputKey = (key) => {
  resetInactivityTimer();
  if (idNumber.value.length < 18) {
    idNumber.value += key;
  }
};
 
const deleteKey = () => {
  resetInactivityTimer();
  if (idNumber.value.length > 0) {
    idNumber.value = idNumber.value.slice(0, -1);
  }
};
 
const openManualInput = () => {
  resetInactivityTimer();
  isManualInput.value = true;
  activeManualInputTarget.value = 'id';
  isNameInputFocused.value = false;
};
 
const clearInput = () => {
  resetInactivityTimer();
  idNumber.value = '';
  manualName.value = '';
  showMissingEntryHint.value = false;
  activeManualInputTarget.value = 'id';
};
 
const dismissNameInput = () => {
  resetInactivityTimer();
  activeManualInputTarget.value = 'id';
  isNameInputFocused.value = false;
  uni.hideKeyboard();
};
 
const handleNameInputBoxTouchStart = () => {
  resetInactivityTimer();
  // 提前切回姓名输入态,避免原生 focus 事件慢半拍导致自定义键盘残留
  activeManualInputTarget.value = 'name';
  isNameInputFocused.value = true;
};
 
const handleNameInputFocus = () => {
  resetInactivityTimer();
  activeManualInputTarget.value = 'name';
  isNameInputFocused.value = true;
};
 
const handleNameInputBlur = () => {
  isNameInputFocused.value = false;
};
 
const handleIdInputBoxClick = () => {
  resetInactivityTimer();
  dismissNameInput();
};
 
// 完善登记信息相关方法
const closeAllPopups = () => {
  showTimePicker.value = false;
  showPlateKeyboard.value = false;
  showAreaPicker.value = false;
};
 
const openTimePicker = () => {
  tempHour.value = selectedTime.value.split(':')[0];
  tempMinute.value = selectedTime.value.split(':')[1];
  showTimePicker.value = true;
  showPlateKeyboard.value = false;
  showAreaPicker.value = false;
};
 
const confirmTimePicker = () => {
  selectedTime.value = `${tempHour.value}:${tempMinute.value}`;
  showTimePicker.value = false;
};
 
const openPlateKeyboard = () => {
  showPlateKeyboard.value = true;
  plateInputStep.value = plateNumber.value ? 'alnum' : 'province';
  showTimePicker.value = false;
  showAreaPicker.value = false;
};
 
const inputProvince = (province) => {
  plateNumber.value = province;
  plateInputStep.value = 'alnum';
};
 
const canInputPlateKey = (key) => {
  if (normalizedPlateLength.value === 0) return false;
  if (normalizedPlateLength.value >= 8) return false;
  return true;
};
 
const inputPlateKey = (key) => {
  if (!canInputPlateKey(key)) return;
  plateNumber.value += key;
};
 
const deletePlateKey = () => {
  if (!plateNumber.value) return;
  plateNumber.value = plateNumber.value.slice(0, -1);
  if (!plateNumber.value) {
    plateInputStep.value = 'province';
  }
};
 
const clearPlateNumber = () => {
  plateNumber.value = '';
  plateInputStep.value = 'province';
};
 
const openAreaPicker = () => {
  tempPrimaryArea.value = primaryAreaOptions.value.length ? primaryAreaOptions.value[0] : '';
  tempSelectedAreas.value = [...selectedAreas.value];
  showAreaPicker.value = true;
  showTimePicker.value = false;
  showPlateKeyboard.value = false;
};
 
const selectPrimaryArea = (area) => {
  tempPrimaryArea.value = area;
};
 
const getPrimarySelectionState = (area) => {
  const childAreas = secondaryAreaMap.value[area] || [];
  const childIds = childAreas.map(c => c.id);
  if (childIds.length === 0) return 'none';
  const selectedCount = childIds.filter((id) => tempSelectedAreas.value.includes(id)).length;
  if (selectedCount === 0) return 'none';
  if (selectedCount === childIds.length) return 'full';
  return 'partial';
};
 
const togglePrimaryCheckbox = (area) => {
  tempPrimaryArea.value = area;
  const childAreas = secondaryAreaMap.value[area] || [];
  const childIds = childAreas.map(c => c.id);
  const currentStatus = getPrimarySelectionState(area);
 
  if (currentStatus === 'full') {
    tempSelectedAreas.value = tempSelectedAreas.value.filter((id) => !childIds.includes(id));
    return;
  }
  tempSelectedAreas.value = Array.from(new Set([...tempSelectedAreas.value, ...childIds]));
};
 
const toggleTempArea = (area) => {
  if (tempSelectedAreas.value.includes(area)) {
    tempSelectedAreas.value = tempSelectedAreas.value.filter((item) => item !== area);
    return;
  }
  tempSelectedAreas.value = [...tempSelectedAreas.value, area];
};
 
const confirmAreaPicker = () => {
  selectedAreas.value = [...tempSelectedAreas.value];
  showAreaPicker.value = false;
};
 
const removeArea = (area) => {
  selectedAreas.value = selectedAreas.value.filter((item) => item !== area);
};
 
const openNoticeDialog = (title, description = '') => {
  // 页面内直接维护弹窗状态与倒计时,避免额外组件通信带来的不确定性
  stopNoticeDialogCountdown();
  noticeDialog.value = {
    visible: true,
    title,
    description,
    buttonText: '关闭',
    duration: 5,
    countdown: 5,
  };
  startNoticeDialogCountdown();
};
 
const closeNoticeDialog = () => {
  stopNoticeDialogCountdown();
  noticeDialog.value = {
    ...noticeDialog.value,
    visible: false,
    countdown: noticeDialog.value.duration,
  };
};
 
const normalizeIdentityCardNo = (value) => {
  return String(value || '').trim().toUpperCase();
};
 
const validateIdentityCardNo = (value) => {
  const normalizedValue = normalizeIdentityCardNo(value);
 
  // 手动录入场景统一只接受 18 位二代身份证,末位允许数字或 X。
  if (!/^\d{17}[\dX]$/.test(normalizedValue)) {
    return {
      valid: false,
      normalizedValue,
      message: '请输入正确的18位身份证号码',
    };
  }
 
  // 身份证中的出生日期必须是真实存在的日期,避免仅靠正则放过非法日期。
  const birthYear = Number(normalizedValue.slice(6, 10));
  const birthMonth = Number(normalizedValue.slice(10, 12));
  const birthDay = Number(normalizedValue.slice(12, 14));
  const birthDate = new Date(birthYear, birthMonth - 1, birthDay);
  const isValidBirthDate = birthDate.getFullYear() === birthYear
    && birthDate.getMonth() === birthMonth - 1
    && birthDate.getDate() === birthDay;
 
  if (!isValidBirthDate) {
    return {
      valid: false,
      normalizedValue,
      message: '身份证号码中的出生日期无效',
    };
  }
 
  // 校验最后一位校验码,避免录入了位数正确但内容错误的号码。
  const weightFactors = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
  const checksumMap = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
  const checksum = normalizedValue
    .slice(0, 17)
    .split('')
    .reduce((sum, current, index) => sum + (Number(current) * weightFactors[index]), 0);
  const expectedCode = checksumMap[checksum % 11];
 
  if (normalizedValue.slice(-1) !== expectedCode) {
    return {
      valid: false,
      normalizedValue,
      message: '请输入正确的身份证号码',
    };
  }
 
  return {
    valid: true,
    normalizedValue,
    message: '',
  };
};
 
const getAppointmentQrIdentityCandidates = () => {
  const payload = appointmentQrcodePayload.value || {};
  const candidateKeys = [
    'visitorIdCard',
    'idCard',
    'licId',
    'visitorIdNo',
    'visitorIdentityNo',
    'identityNo',
    'certificateNo',
    'certNo',
    'idCardMask',
  ];
 
  return candidateKeys
    .map((key) => normalizeIdentityCardNo(payload?.[key]))
    .filter(Boolean);
};
 
const isSameIdentityCard = (sourceIdentityNo, targetIdentityNo) => {
  const source = normalizeIdentityCardNo(sourceIdentityNo);
  const target = normalizeIdentityCardNo(targetIdentityNo);
 
  if (!source || !target) {
    return false;
  }
 
  if (source === target) {
    return true;
  }
 
  // 二维码里如果返回了脱敏身份证号,则兜底按后 4 位比对
  const sourceLast4 = source.slice(-4);
  const targetLast4 = target.slice(-4);
  if (sourceLast4 && targetLast4 && sourceLast4 === targetLast4) {
    return true;
  }
 
  return false;
};
 
const getIdentityPhotoAddress = () => {
  return String(appointmentIdCardPayload.value?.photoAddress || '').trim();
};
 
// 统一更新当前步骤对应的状态文案,避免 face/host 两套状态分支重复判断
const updateVerifyStatusText = (stepName, text) => {
  if (stepName === 'host') {
    hostVerifyStatusText.value = text;
    return;
  }
 
  faceVerifyStatusText.value = text;
};
 
// 清理“每秒轮询判脸”的定时器
const clearJudgeFacePollTimer = () => {
  if (faceJudgePollTimer) {
    clearTimeout(faceJudgePollTimer);
    faceJudgePollTimer = null;
  }
};
 
// 清理人脸相关的所有延时任务,避免步骤切换后旧回调串到新步骤
const clearFaceCaptureTimer = () => {
  clearJudgeFacePollTimer();
  if (faceCaptureDelayTimer) {
    clearTimeout(faceCaptureDelayTimer);
    faceCaptureDelayTimer = null;
  }
};
 
// 安全停止 live-pusher 预览,失败也不阻塞后续流程
const stopLivePreview = (cameraContext) => {
  return new Promise((resolve) => {
    if (!cameraContext || typeof cameraContext.stopPreview !== 'function') {
      resolve();
      return;
    }
 
    cameraContext.stopPreview({
      success: () => resolve(),
      fail: () => resolve(),
    });
  });
};
 
// 清理访客现场抓拍图,避免本地临时图片堆积
const cleanupLiveFacePhoto = async (options = {}) => {
  const { preserveIdentityLivePhoto = false } = options;
  if (!liveFacePhotoPath.value) {
    return;
  }
 
  const currentPath = liveFacePhotoPath.value;
  liveFacePhotoPath.value = '';
 
  // 人脸验证通过后,这张现场抓拍图还要继续用于后续打印,
  // 步骤切换时只清理引用,不删除实体文件;真正离开页面时再统一删除。
  if (preserveIdentityLivePhoto && currentPath === appointmentIdCardPayload.value?.livePhotoAddress) {
    return;
  }
 
  try {
    await deleteLocalImage(currentPath);
  } catch (error) {
    console.error('清理现场抓拍照片失败:', error);
  }
};
 
// 清理接待人现场抓拍图,和访客抓拍图分开管理
const cleanupHostLiveFacePhoto = async () => {
  if (!hostLiveFacePhotoPath.value) {
    return;
  }
 
  const currentPath = hostLiveFacePhotoPath.value;
  hostLiveFacePhotoPath.value = '';
 
  try {
    await deleteLocalImage(currentPath);
  } catch (error) {
    console.error('清理接待人抓拍照片失败:', error);
  }
};
 
// 统一重置人脸预览相关状态。
// 这里只清理页面内的本地状态和定时器,不主动调用任何插件 stop 方法,
// 避免在步骤切换或流程中途把硬件能力提前停掉。
const resetFacePreviewState = async () => {
  // sessionId 自增后,旧的判脸轮询和延迟抓拍都会自动失效
  judgeFaceSessionId += 1;
  isJudgeFaceRunning = false;
  clearFaceCaptureTimer();
  facePreviewReady.value = false;
  // 中途只清理临时图片和上下文引用,真正的 stop 动作统一放到页面销毁时
  await Promise.allSettled([
    cleanupLiveFacePhoto({ preserveIdentityLivePhoto: true }),
    cleanupHostLiveFacePhoto(),
  ]);
  faceCameraContext = null;
  hostCameraContext = null;
};
 
// 创建访客人脸步骤的 live-pusher 上下文,并在原生视图可用后开启预览
const ensureFaceCameraContext = async () => {
  await nextTick();
  // 打包环境下原生视图挂载通常慢于本地调试,这里预留一点缓冲时间
  await wait(LIVE_PUSHER_READY_DELAY);
 
  const currentPageContext = currentInstance?.proxy;
  faceCameraContext = currentPageContext
    ? uni.createLivePusherContext('faceCamera', currentPageContext)
    : uni.createLivePusherContext('faceCamera');
 
  if (!faceCameraContext) {
    throw new Error('当前环境不支持摄像头拍照(LivePusher)');
  }
 
  return new Promise((resolve, reject) => {
    faceCameraContext.startPreview({
      success: () => {
        facePreviewReady.value = true;
        faceVerifyStatusText.value = '请将脸部置于框内';
        resolve();
      },
      fail: (err) => {
        reject(new Error('LivePusher 预览开启失败: ' + JSON.stringify(err)));
      }
    });
  });
};
 
// 接收访客摄像头组件初始化成功事件,同步页面状态
const handleFaceCameraInit = () => {
  facePreviewReady.value = true;
  faceVerifyStatusText.value = '请保持面部位于取景框内';
};
 
// 摄像头初始化失败时统一弹窗,方便真机联调定位问题
const handleFaceCameraError = (error) => {
  facePreviewReady.value = false;
  faceVerifyStatusText.value = '摄像头预览初始化失败';
 
  const errorMsg = error && error.detail ? JSON.stringify(error.detail) : JSON.stringify(error);
 
  uni.showModal({
    title: '摄像头报错调试',
    content: errorMsg || '未知摄像头错误',
    showCancel: false
  });
 
  console.error('摄像头预览初始化失败,详细错误信息:', JSON.stringify(error));
  if (error && error.detail) {
      console.error('摄像头错误 detail:', error.detail);
  }
};
 
// 创建接待人人脸步骤的 live-pusher 上下文,并开启预览
const ensureHostCameraContext = async () => {
  await nextTick();
  await wait(LIVE_PUSHER_READY_DELAY);
 
  const currentPageContext = currentInstance?.proxy;
  hostCameraContext = currentPageContext
    ? uni.createLivePusherContext('hostCamera', currentPageContext)
    : uni.createLivePusherContext('hostCamera');
 
  if (!hostCameraContext) {
    throw new Error('当前环境不支持摄像头拍照(LivePusher)');
  }
 
  return new Promise((resolve, reject) => {
    hostCameraContext.startPreview({
      success: () => {
        hostVerifyStatusText.value = '请将脸部置于框内';
        resolve();
      },
      fail: (err) => {
        reject(new Error('LivePusher 预览开启失败: ' + JSON.stringify(err)));
      }
    });
  });
};
 
// 对 live-pusher 的抓拍做统一封装,兼容不同环境下的返回结构
const takeCameraSnapshot = async (cameraContext, errorMessage) => {
  if (!cameraContext) {
    throw new Error(errorMessage);
  }
 
  const tempImagePath = await new Promise((resolve, reject) => {
    cameraContext.snapshot({
      success: (result) => resolve(result?.message?.tempImagePath || result?.tempImagePath || ''),
      fail: (error) => reject(error),
    });
  });
 
  if (!tempImagePath) {
    throw new Error(errorMessage);
  }
 
  return tempImagePath;
};
 
// 判脸阶段只需要临时抓拍图,不需要落库
const captureJudgeFacePhoto = async (stepName) => {
  const cameraContext = stepName === 'host' ? hostCameraContext : faceCameraContext;
  return await takeCameraSnapshot(cameraContext, '判脸抓拍失败,请重试');
};
 
// 接待人正式比对前抓拍现场照片,并保存到本地临时路径
const captureHostLiveFacePhoto = async () => {
  const tempImagePath = await takeCameraSnapshot(hostCameraContext, '接待人抓拍失败,未获取到图片路径');
  hostLiveFacePhotoPath.value = await saveImageToLocal(tempImagePath);
  return hostLiveFacePhotoPath.value;
};
 
// 轮询判脸:每秒抓拍一张图,检测到人脸后再等待 2 秒进行正式抓拍
const startJudgeFacePolling = ({ stepName, onFaceDetected }) => {
  const currentSessionId = ++judgeFaceSessionId;
  clearFaceCaptureTimer();
  isJudgeFaceRunning = false;
  updateVerifyStatusText(stepName, '请将脸部置于框内');
 
  const pollJudgeFace = async () => {
    // sessionId 不一致说明步骤已切换,直接放弃旧轮询
    if (currentSessionId !== judgeFaceSessionId) {
      return;
    }
 
    // 上一轮判脸尚未结束时,不重复并发调用插件
    if (isJudgeFaceRunning) {
      faceJudgePollTimer = setTimeout(pollJudgeFace, FACE_JUDGE_POLL_INTERVAL);
      return;
    }
 
    isJudgeFaceRunning = true;
    try {
      const judgePhotoPath = await captureJudgeFacePhoto(stepName);
      // 插件只负责判断“图片里有没有人脸”,不做正式比对
      await new Promise((resolve, reject) => {
        HardwareAPI.startJudgeFace(
          { face: judgePhotoPath },
          (result) => resolve(result),
          (error) => reject(error),
        );
      });
 
      if (currentSessionId !== judgeFaceSessionId) {
        return;
      }
 
      // 判到人脸后不在流程中途调用 stopJudgeFace,只做稳定等待后正式抓拍
      updateVerifyStatusText(stepName, '已检测到人脸,请保持不动');
      faceCaptureDelayTimer = setTimeout(async () => {
        faceCaptureDelayTimer = null;
        if (currentSessionId !== judgeFaceSessionId) {
          return;
        }
 
        await onFaceDetected(currentSessionId);
      }, FACE_CAPTURE_DELAY);
      return;
    } catch (error) {
      if (currentSessionId !== judgeFaceSessionId) {
        return;
      }
 
      updateVerifyStatusText(stepName, '请将脸部置于框内');
    } finally {
      isJudgeFaceRunning = false;
    }
 
    if (currentSessionId !== judgeFaceSessionId) {
      return;
    }
 
    // 未检测到人脸时继续下一轮轮询
    faceJudgePollTimer = setTimeout(pollJudgeFace, FACE_JUDGE_POLL_INTERVAL);
  };
 
  faceJudgePollTimer = setTimeout(pollJudgeFace, 0);
  return currentSessionId;
};
 
// 接待人人脸验证:
// - 预约/签离:按预约中的接待人信息精确匹配员工后做人脸比对
// - 现场登记:没有默认接待人,按所有带人脸照片的员工依次轮询比对,直到成功或全部失败
const startHostVerify = async () => {
  // 接待人验证不再此处阻塞拉取员工列表,改为直接使用最新缓存
  // (在进入该页面前的 onLoad 或前置页面静默完成拉取)
  employeeVerifyList.value = await getLocalEmployeeVerifyList();
  hostMatchedEmployee.value = findMatchedHostEmployee();
 
  const isOnsiteHostVerify = mode.value === 'online';
  const matchedEmployee = isOnsiteHostVerify ? null : findMatchedHostEmployee();
  const candidateFaceEmployees = isOnsiteHostVerify ? getHostFaceEmployees() : [];
  hostMatchedEmployee.value = matchedEmployee;
 
  if (!isOnsiteHostVerify && !matchedEmployee) {
    openNoticeDialog(
      '未找到接待人员工信息',
      '请确认接待人信息与员工档案一致'
    );
    return;
  }
 
  const employeeFacePhotoAddress = isOnsiteHostVerify ? '' : resolveEmployeeFacePhotoAddress(matchedEmployee);
  if (!isOnsiteHostVerify && !employeeFacePhotoAddress) {
    openNoticeDialog(
      '未获取到接待人人脸照片',
      '当前接待人员工档案未配置人脸照片,请先完善员工资料'
    );
    return;
  }
 
  if (isOnsiteHostVerify && candidateFaceEmployees.length === 0) {
    openNoticeDialog(
      '未获取到员工人脸照片',
      '当前员工列表中没有可用于比对的人脸照片,请先同步员工档案'
    );
    return;
  }
 
  resetFacePreviewState().then(async () => {
    try {
      hostVerifyStatusText.value = '正在开启摄像头...';
      await ensureHostCameraContext();
      // 只有判到人脸后,才进入正式抓拍和人脸比对
      startJudgeFacePolling({
        stepName: 'host',
        onFaceDetected: async (sessionId) => {
          try {
            hostVerifyStatusText.value = '正在采集接待人人脸...';
            const livePhotoAddress = await captureHostLiveFacePhoto();
            // 步骤若已变化,直接丢弃这次异步结果
            if (sessionId !== judgeFaceSessionId) {
              return;
            }
 
            hostVerifyStatusText.value = '人脸比对中...';
            let hostCompareResult = null;
            if (isOnsiteHostVerify) {
              hostCompareResult = await compareHostFaceWithAllEmployees(livePhotoAddress);
            } else {
              hostCompareResult = await compareHostFaceWithEmployee(livePhotoAddress, matchedEmployee);
            }
 
            if (sessionId !== judgeFaceSessionId) {
              return;
            }
 
            if (!hostCompareResult?.passed) {
              hostVerifyStatusText.value = '接待人验证失败';
              openNoticeDialog(
                '接待人验证失败,请重新验证',
                isOnsiteHostVerify
                  ? '未匹配到现场接待人员工,请重新验证'
                  : '请正视屏幕重新进行人脸认证'
              );
              return;
            }
 
            hostMatchedEmployee.value = hostCompareResult.employee || null;
            hostVerifyStatusText.value = '接待人验证成功';
            nextStep();
          } catch (error) {
            if (sessionId !== judgeFaceSessionId) {
              return;
            }
 
            hostVerifyStatusText.value = '接待人验证失败';
            openNoticeDialog(
              resolveFaceVerifyErrorMessage(error),
              '请正视屏幕重新进行人脸认证'
            );
          }
        },
      });
    } catch (err) {
      hostVerifyStatusText.value = '摄像头启动失败';
      openNoticeDialog('摄像头预览失败,请重新验证', err.message);
    }
  }).catch((err) => {
    hostVerifyStatusText.value = '摄像头初始化失败';
    openNoticeDialog('摄像头初始化失败,请重新验证', err.message);
  });
};
 
// 访客正式抓拍现场人脸图,并落到本地临时路径供后续比对/保存
const captureLiveFacePhoto = async () => {
  const tempImagePath = await takeCameraSnapshot(faceCameraContext, '未获取到现场人脸照片');
  liveFacePhotoPath.value = await saveImageToLocal(tempImagePath);
  return liveFacePhotoPath.value;
};
 
// 将现场抓拍图写回身份 payload,方便后续打印或接口复用
const saveLiveFacePhotoToIdentityPayload = (livePhotoAddress) => {
  const nextIdentityPayload = {
    ...(appointmentIdCardPayload.value || {}),
    livePhotoAddress,
  };
 
  appointmentIdCardPayload.value = nextIdentityPayload;
  saveAppointmentIdCardPayload(nextIdentityPayload);
};
 
// 身份核验通过后统一推进到人脸步骤,并顺手重置手动录入状态
const advanceToFaceStep = () => {
  dismissNameInput();
  faceVerifyStatusText.value = '等待开始人证比对';
  showMissingEntryHint.value = false;
  isManualInput.value = false;
 
  nextStep();
};
 
const isAppointmentIdentityMatched = (cardData) => {
  if (mode.value !== 'appointment') {
    return true;
  }
 
  const currentIdentityNo = normalizeIdentityCardNo(cardData?.licId);
  const qrIdentityCandidates = getAppointmentQrIdentityCandidates();
 
  if (!currentIdentityNo || qrIdentityCandidates.length === 0) {
    return false;
  }
 
  return qrIdentityCandidates.some((candidate) => isSameIdentityCard(candidate, currentIdentityNo));
};
 
const resolveFaceVerifyErrorMessage = (error) => {
  return error?.msg || error?.message || '人证照片比对失败,请联系工作人员';
};
 
const isFaceVerifyPassed = (faceResult) => {
  if (!faceResult || typeof faceResult !== 'object') {
    return true;
  }
 
  const failKeys = ['matched', 'pass', 'success', 'verified', 'compareResult'];
  for (const key of failKeys) {
    if (Object.prototype.hasOwnProperty.call(faceResult, key) && faceResult[key] === false) {
      return false;
    }
  }
 
  if (Object.prototype.hasOwnProperty.call(faceResult, 'score')) {
    const score = Number(faceResult.score);
    const threshold = Number(faceResult.threshold ?? faceResult.passScore ?? 0);
    if (!Number.isNaN(score) && !Number.isNaN(threshold) && threshold > 0) {
      return score >= threshold;
    }
  }
 
  return true;
};
 
const handleFaceVerifyNextStep = () => {
  clearFaceCaptureTimer();
  startFaceVerify();
};
 
// 访客人脸验证:先判脸,再正式抓拍,最后根据是否有身份证照片决定是否做人证比对
const startFaceVerify = () => {
  const currentIdentityPayload = appointmentIdCardPayload.value || {};
  const isManualIdentityInput = currentIdentityPayload.inputType === 'manual';
  const idCardPhotoAddress = getIdentityPhotoAddress();
 
  if (!isManualIdentityInput && !idCardPhotoAddress) {
    faceVerifyStatusText.value = '未获取到身份证照片';
    openNoticeDialog(
      '未获取到身份证照片,请重新读取身份证',
      '手动输入身份证后无法进行人证照片比对'
    );
    return;
  }
 
  resetFacePreviewState().then(async () => {
    try {
      faceVerifyStatusText.value = '正在开启摄像头...';
      await ensureFaceCameraContext();
      // 访客和接待人共用一套“先判脸,再正式抓拍”的流程
      startJudgeFacePolling({
        stepName: 'face',
        onFaceDetected: async (sessionId) => {
          try {
            faceVerifyStatusText.value = '正在采集人脸...';
            const livePhotoAddress = await captureLiveFacePhoto();
            if (sessionId !== judgeFaceSessionId) {
              return;
            }
 
            saveLiveFacePhotoToIdentityPayload(livePhotoAddress);
 
            // 手动录入身份证时没有证件照,跳过人证比对,仅保留现场人脸图
            if (isManualIdentityInput) {
              faceVerifyStatusText.value = '人脸采集成功';
              await waitBeforeEnterHostStep();
              nextStep();
              return;
            }
 
            faceVerifyStatusText.value = '人证比对中...';
            const faceResult = await new Promise((resolve, reject) => {
              HardwareAPI.startFaceVerify(
                {
                  face: livePhotoAddress,
                  photo: idCardPhotoAddress,
                  idCardPhotoAddress,
                  livePhotoAddress,
                  // 兼容现有原生参数命名
                  photoAddress: idCardPhotoAddress,
                  capturePhotoAddress: livePhotoAddress,
                },
                (result) => resolve(result),
                (error) => reject(error),
              );
            });
 
            if (sessionId !== judgeFaceSessionId) {
              return;
            }
 
            if (!isFaceVerifyPassed(faceResult)) {
              faceVerifyStatusText.value = '人证比对失败';
              openNoticeDialog(
                '人证照片比对失败,请重新采集',
                '请正视屏幕重新进行人脸认证'
              );
              return;
            }
 
            faceVerifyStatusText.value = '人证比对成功';
            await waitBeforeEnterHostStep();
            nextStep();
          } catch (error) {
            if (sessionId !== judgeFaceSessionId) {
              return;
            }
 
            faceVerifyStatusText.value = '人证比对失败';
            openNoticeDialog(
              resolveFaceVerifyErrorMessage(error),
              '请正视屏幕重新进行人脸认证'
            );
          }
        },
      });
    } catch (error) {
      faceVerifyStatusText.value = '摄像头启动失败';
 
    //   uni.showModal({
    //     title: '启动捕获异常调试',
    //     content: error?.message || JSON.stringify(error) || '未知异常',
    //     showCancel: false
    //   });
 
      openNoticeDialog(
        '摄像头启动失败',
        '请检查摄像头权限'
      );
    }
  });
};
 
const retryFaceVerify = () => {
  startHostVerify();
};
 
const waitBeforeEnterHostStep = async () => {
  // 访客人脸验证成功后,统一停留 1 秒再进入接待人验证,给现场一个明确的成功反馈。
  if (currentStepName.value !== 'face' || !shouldShowHostStep.value) {
    return;
  }
 
  await new Promise((resolve) => {
    setTimeout(resolve, 1000);
  });
};
 
const showQrcodeParseDebugModal = (scanData, decryptedResult = {}) => {
  return new Promise((resolve) => {
    uni.showModal({
      title: '二维码解析结果',
      content: `原始内容:${scanData}\n\n解密结果:${decryptedResult.plainText || '无'}\n\n解析对象:${JSON.stringify(decryptedResult.payload || {}, null, 2)}`,
      showCancel: false,
      success: () => resolve(),
      fail: () => resolve(),
    });
  });
};
 
const handleAppointmentQrcodeValidation = (payload) => {
  const validationResult = validateAppointmentQrcodePayload(payload);
  if (validationResult.valid) {
    return true;
  }
 
  if (validationResult.reason === 'out_of_time_range') {
    openNoticeDialog(
      '预约码不在进场时间内,请联系工作人员',
      '请检查您的预约时间'
    );
    return false;
  }
 
  if (validationResult.reason === 'already_entered') {
    openNoticeDialog(
      '该预约码已进场',
      '您已进场,请签离'
    );
    return false;
  }
 
  openNoticeDialog(
    '未识别二维码,请联系工作人员',
    ''
  );
  return false;
};
 
// -------------------- 区域数据加载 --------------------
const loadVisitAreas = async () => {
  try {
    // 简单判断网络
    const networkType = await new Promise(resolve => {
      uni.getNetworkType({
        success: (res) => resolve(res.networkType)
      });
    });
 
    if (networkType !== 'none') {
      const res = await getVisitAreaTree();
      if (res && res.code === 200 && Array.isArray(res.data)) {
        visitAreaTree.value = res.data;
        // 在线获取成功后,同步到本地配置表
        await saveOfflineConfig('visit_area_tree', res.data);
        return;
      }
    }
  } catch (err) {
    console.error('获取在线区域树失败:', err);
  }
 
  // 离线或获取失败时,尝试读取本地缓存
  const cachedData = await getOfflineConfig('visit_area_tree');
  if (cachedData && Array.isArray(cachedData)) {
    visitAreaTree.value = cachedData;
  }
};
// ----------------------------------------------------
onMounted(async () => {
  resetInactivityTimer();
  await loadSystemFlowConfig();
  await loadEmployeeVerifyList();
  await loadVisitAreas();
  clearAppointmentIdCardPayload();
 
  // 首页扫码成功后会直接跳到预约登记的身份证步骤,这里需要保留并恢复之前已缓存的二维码数据,
  // 否则后续身份证一致性校验会因为拿不到 visitorIdCard 而被误判为不一致。
  if (mode.value === 'appointment' && currentStep.value > 1) {
    appointmentQrcodePayload.value = getAppointmentQrPayload();
  } else {
    clearAppointmentQrPayload();
    appointmentQrcodePayload.value = null;
  }
 
  hasMountedHardwareFlow = true;
 
  // 页面加载后立即开启身份证读卡监听。
  // 只有当前处于身份证读卡步骤或接待人验证步骤时,才消费回调结果。
  HardwareAPI.startReadCard(async (cardData) => {
    resetInactivityTimer();
    if (currentStepName.value === 'host') {
      const hostCardVerifyResult = verifyHostEmployeeCard(cardData);
 
      if (hostCardVerifyResult.reason === 'card_no_missing') {
        return;
      }
 
      if (!hostCardVerifyResult.passed) {
        if (hostCardVerifyResult.reason === 'employee_not_found') {
          openNoticeDialog(
            '未找到接待人员工信息',
            '请确认首页已成功同步员工列表,且预约中的接待人信息与员工档案一致'
          );
          return;
        }
 
        if (hostCardVerifyResult.reason === 'employee_card_missing') {
          openNoticeDialog(
            '接待人员工未配置卡号',
            '当前员工档案缺少卡号,无法完成刷卡校验,请改用人脸验证'
          );
          return;
        }
 
        openNoticeDialog(
          '接待人卡号不匹配',
          '当前刷卡结果与接待人员工卡号不一致,请重新刷卡或改用人脸验证'
        );
        return;
      }
 
      await resetFacePreviewState();
      nextStep();
      return;
    }
 
    if (currentStepName.value !== 'idcard' || isManualInput.value) {
      return;
    }
 
    console.log('读卡成功,拿到身份证信息:', cardData);
 
    if (mode.value === 'signout') {
      const hasEntry = await verifySignoutEntry(cardData?.licId);
      if (!hasEntry) return;
    }
 
    if (mode.value === 'appointment' && !isAppointmentIdentityMatched(cardData)) {
      openNoticeDialog(
        '身份信息不一致',
        '请使用预约访客本人的身份证完成核验'
      );
      return;
    }
 
    if (mode.value === 'online' || mode.value === 'appointment') {
      const hasEntry = await verifyOnsiteEntry(cardData?.licId);
      if (hasEntry) return;
    }
 
    // 保存身份证识别结果,后续可用于身份校验和人脸照片比对
    appointmentIdCardPayload.value = cardData;
    saveAppointmentIdCardPayload(cardData);
 
    advanceToFaceStep();
  });
 
  // 首屏硬件动作不要依赖 init 回调,否则 init 卡住时扫码第一步不会触发
  triggerHardwareByStep(currentStepName.value);
  await syncScanLineAnimationByStep(currentStepName.value);
 
  // 初始化硬件插件
  HardwareAPI.init().then(() => {
    console.log('硬件插件初始化完成');
  }).catch(err => {
    console.error('硬件插件初始化失败:', err);
  });
});
 
onUnmounted(() => {
  clearInactivityTimer();
  dismissNameInput();
  stopScanLineAnimation();
  stopNoticeDialogCountdown();
  // 扫码停止统一收口到应用关闭时调用,页面销毁时不主动 stop
  HardwareAPI.stopReadCard();
  HardwareAPI.stopJudgeFace();
  HardwareAPI.stopFaceVerify();
  stopLivePreview(faceCameraContext);
  stopLivePreview(hostCameraContext);
  resetFacePreviewState();
});
 
onLoad((options) => {
  if (options.step) {
    currentStep.value = parseInt(options.step, 10);
  }
  if (options.mode) {
    mode.value = options.mode;
  }
  if (options.scanCase === 'no-entry') {
    openNoticeDialog(
      '未检测到您的进场信息',
      '请核对证件信息,或联系工作人员协助处理'
    );
  }
});
 
const currentStepName = computed(() => {
  return flowStepNames.value[currentStep.value - 1] || '';
});
 
watch(flowStepNames, (newFlowStepNames) => {
  if (currentStep.value > newFlowStepNames.length) {
    currentStep.value = newFlowStepNames.length || 1;
  }
});
 
watch(currentStepName, () => {
  resetInactivityTimer();
});
 
// 监听步骤变化,步骤切换时只做状态清理,不在中途调用插件 stop 方法
watch(currentStepName, async (newStep, oldStep) => {
  // onLoad 修改 mode / step 时会先触发一次 watch,这里等页面挂载后再处理,
  // 避免现场登记和签离首屏读卡被 onLoad + onMounted 重复触发两次。
  if (!hasMountedHardwareFlow) {
    return;
  }
  dismissNameInput();
 
  if (oldStep === 'face' || oldStep === 'host') {
    // 离开人脸相关步骤时,只让旧的异步和定时器失效,真正的 stop 留到页面销毁
    resetFacePreviewState();
  }
 
  await nextTick();
  await wait(50);
 
  // 启动新一步的硬件
  triggerHardwareByStep(newStep);
  syncScanLineAnimationByStep(newStep);
}, {
  flush: 'post',
});
 
// 按步骤统一拉起对应的硬件动作,避免逻辑散落在多个 watch / onMounted 里
const triggerHardwareByStep = (stepName) => {
  // 只有预约登记第一步才需要扫码
  if (mode.value === 'appointment' && stepName === 'qr') {
    // 二次进入扫码步骤前先复位扫码硬件,避免沿用上一次扫码残留状态。
    HardwareAPI.stopScan();
    HardwareAPI.startScan(async (scanData) => {
      // 不再在步骤切换时主动 stopScan,所以这里只允许二维码步骤消费扫码结果
      if (currentStepName.value !== 'qr' || mode.value !== 'appointment') {
        return;
      }
 
      resetInactivityTimer();
 
      try {
        const decryptedResult = await parseHikvisionQrcodePayload(scanData);
        await showQrcodeParseDebugModal(scanData, decryptedResult);
 
        // 保存解密后的预约码数据,后续身份证读卡和接口校验都直接复用
        appointmentQrcodePayload.value = decryptedResult.payload;
        saveAppointmentQrPayload(decryptedResult.payload);
 
        console.log('扫码成功,原始预约码:', scanData);
        console.log('预约码解密结果:', decryptedResult.plainText);
        console.log('预约码解析对象:', decryptedResult.payload);
 
        // await new Promise((resolve) => {
        //   uni.showModal({
        //     title: '二维码解析结果',
        //     content: `解析对象:${JSON.stringify(decryptedResult.payload || {}, null, 2)}`,
        //     showCancel: false,
        //     success: () => resolve(),
        //     fail: () => resolve(),
        //   });
        // });
 
        if (!handleAppointmentQrcodeValidation(decryptedResult.payload)) {
          return;
        }
 
        // 扫码成功进入下一步前主动停止扫码,避免后续步骤继续收到扫码回调。
        await HardwareAPI.stopScan();
        nextStep();
      } catch (error) {
        console.error('预约码解密失败:', error);
        openNoticeDialog(
          '未识别二维码,请联系工作人员',
          ''
        );
      }
    });
    return;
  }
 
  if (stepName === 'face') {
    // 访客进入人脸步骤后自动开始判脸和比对
    startFaceVerify();
  }
 
  if (stepName === 'host') {
    // 接待人进入验证步骤后自动开始员工匹配和人脸比对
    startHostVerify();
  }
 
  if (stepName === 'print') {
    // 延迟 500ms 调用打印机,确保 UI 已经切换到打印步骤
    setTimeout(() => {
      startPrintTicket();
    }, 500);
  }
};
 
const goBack = () => {
  resetInactivityTimer();
  dismissNameInput();
  if (isManualInput.value) {
    isManualInput.value = false;
    return;
  }
  if (currentStep.value > 1) {
    currentStep.value--;
 
    // 页面内回退时不主动 stop 插件,只依赖步骤状态让旧流程失效
  } else {
    uni.navigateBack({
      fail: () => {
        uni.redirectTo({
          url: '/pages/home/index'
        });
      }
    });
  }
};
 
const nextStep = () => {
  resetInactivityTimer();
  if (currentStepName.value === 'form' && mode.value === 'online') {
    if (selectedAreas.value.length === 0) {
      uni.showToast({ title: '请选择访问区域', icon: 'none' });
      return;
    }
  }
 
  const maxStep = flowStepNames.value.length;
  if (currentStep.value < maxStep) {
    currentStep.value++;
  } else if (currentStepName.value !== 'print') {
    // 只有非打印步骤到达最大步数时才直接跳转
    // 打印步骤到达最大步数时,由 startPrintTicket 的成功回调来触发 goNext
    goNext();
  }
};
 
const verifySignoutEntry = async (idCard) => {
  if (mode.value !== 'signout') return true;
 
  if (!idCard) {
    if (!isManualInput.value) {
      openNoticeDialog('未检测到您的进场信息', '');
    }
    return false;
  }
 
  // 直接查询本地数据库中的进场记录
  const hasEntry = await findEntryRecordByIdCard(idCard);
 
  if (!hasEntry) {
    // 只有在非手动输入(即硬件读卡)时,才弹出全局对话框
    // 手动输入时直接在输入框上方展示红色提示字,不弹窗
    if (!isManualInput.value) {
      openNoticeDialog('未检测到您的进场信息', '');
    }
    return false;
  }
 
  return true;
};
 
const verifyOnsiteEntry = async (idCard) => {
  if (mode.value !== 'online' && mode.value !== 'appointment') return false;
 
  if (!idCard) {
    return false;
  }
 
  const hasEntry = await findEntryRecordByIdCard(idCard);
 
  if (hasEntry) {
    openNoticeDialog('该身份已进场', '您已进场,请签离');
    return true;
  }
 
  return false;
};
 
const confirmManualInput = async () => {
  if (idNumber.value.length > 0) {
    showMissingEntryHint.value = false;
 
    if (mode.value === 'online' && !manualName.value.trim()) {
      uni.showToast({ title: '请输入姓名', icon: 'none' });
      return;
    }
 
    const identityValidationResult = validateIdentityCardNo(idNumber.value);
    if (!identityValidationResult.valid) {
      uni.showToast({ title: identityValidationResult.message, icon: 'none' });
      return;
    }
 
    // 统一把末位 x 转成大写 X,避免后续查库、比对和打印链路出现大小写不一致。
    const normalizedIdNumber = identityValidationResult.normalizedValue;
    idNumber.value = normalizedIdNumber;
 
    if (mode.value === 'signout') {
      const hasEntry = await verifySignoutEntry(normalizedIdNumber);
      if (!hasEntry) {
        showMissingEntryHint.value = true;
        return;
      }
    }
 
    if (mode.value === 'online' || mode.value === 'appointment') {
      const manualIdCardPayload = {
        licId: normalizedIdNumber,
        name: mode.value === 'online' ? manualName.value.trim() : '',
        visitorName: mode.value === 'online' ? manualName.value.trim() : '', // 同时赋值给 visitorName 以防其他地方读取
        photoAddress: '',
        inputType: 'manual',
      };
 
      if (mode.value === 'appointment' && !isAppointmentIdentityMatched(manualIdCardPayload)) {
        openNoticeDialog(
          '身份信息不一致',
          '请使用预约访客本人的身份证完成核验'
        );
        return;
      }
 
      const hasEntry = await verifyOnsiteEntry(normalizedIdNumber);
      if (hasEntry) {
        return;
      }
 
      // 保存手动录入的身份证信息,后续流程统一从公共存储读取
      appointmentIdCardPayload.value = manualIdCardPayload;
      saveAppointmentIdCardPayload(manualIdCardPayload);
 
      // 身份比对通过后,自动进入下一步人脸认证
      advanceToFaceStep();
      return;
    }
 
    const manualIdCardPayload = {
      licId: normalizedIdNumber,
      name: mode.value === 'online' ? manualName.value.trim() : '',
      visitorName: mode.value === 'online' ? manualName.value.trim() : '', // 同时赋值给 visitorName 以防其他地方读取
      photoAddress: '',
      inputType: 'manual',
    };
 
    // 保存手动录入的身份证信息,后续流程统一从公共存储读取
    appointmentIdCardPayload.value = manualIdCardPayload;
    saveAppointmentIdCardPayload(manualIdCardPayload);
 
    // 身份比对通过后,自动进入下一步人脸认证
    advanceToFaceStep();
  }
};
 
const saveCheckInRecord = async () => {
  try {
    const idCard = idNumber.value || appointmentIdCardPayload.value?.licId || '';
    let visitorName = appointmentIdCardPayload.value?.name || appointmentIdCardPayload.value?.visitorName || appointmentQrcodePayload.value?.visitorName || '';
    const matchedHostName = getFirstFilledValue(hostMatchedEmployee.value || {}, [
      'employeeName',
      'name',
      'userName',
      'staffName',
      'realName',
    ]);
 
    // 如果是现场登记且有手动输入的姓名,优先使用
    if (mode.value === 'online' && manualName.value.trim()) {
      visitorName = manualName.value.trim();
    }
    const intervieweeName = mode.value === 'online'
      ? (matchedHostName || '')
      : (appointmentQrcodePayload.value?.beVisitorName || '');
    const plateNo = plateNumber.value || '';
    const receiverVerifyMethod = receiverVerifyMethodValue.value;
 
    let validEndTime = '';
    if (mode.value === 'online') {
      validEndTime = `${visitEndDateText.value} ${selectedTime.value}:00`;
    } else {
      validEndTime = appointmentQrcodePayload.value?.endTime || '';
    }
 
    const validStartTime = appointmentQrcodePayload.value?.startTime || '';
    const visitAreaIds = mode.value === 'online' ? selectedAreas.value.join(',') : '';
    const visitAreaNames = mode.value === 'appointment' ? (appointmentQrcodePayload.value?.areas || '') : '';
    const visitReason = appointmentQrcodePayload.value?.visitPurpose || '';
    const registerType = mode.value === 'appointment' ? 'APPOINTMENT' : 'ONSITE';
 
    let formData = {};
    // 统一使用本地时间格式,避免 toISOString() 转成 UTC 后导致时区偏差
    const nowFormat = formatStandardDateTime(new Date());
 
    if (mode.value === 'signout') {
      formData = {
        idCard,
        intervieweeName,
        receiverVerifyMethod,
        signImageUrl: '', // 由 syncEngine 负责上传并回填
        signReceiverName: shouldShowHostStep.value ? (intervieweeName || appointmentHostName.value) : '',
        signVerifyMethod: receiverVerifyMethod,
        signTime: nowFormat // 增加签离时间字段供离线接口使用
      };
 
      // 标记本地进场记录为已签离,避免下次重复签离
      if (idCard) {
        await markEntryRecordSignedOut(idCard);
      }
    } else {
      formData = {
        // deviceId: visitorDevice.getDeviceInfo().deviceSn || 'unknown',
        faceImageUrl: '', // 由 syncEngine 负责上传并回填
        idCard,
        intervieweeName,
        plateNo,
        receiverVerifyMethod,
        validEndTime,
        validStartTime,
        visitAreaIds,
        visitAreaNames,
        visitReason,
        visitorName,
        registerType,
        registerTime: nowFormat // 增加签到时间字段供离线接口使用
      };
    }
 
    // 1. 存入本地离线数据库
    const offlineRecord = {
      id: `record_${Date.now()}`,
      type: mode.value,
      localImgPath: liveFacePhotoPath.value || '',
      payload: formData,
    };
 
    await insertOfflineRecord(offlineRecord);
    console.log('离线记录保存成功');
    // uni.showModal({
    //   title: '离线保存诊断',
    //   content: `离线记录已存入本地数据库\nID: ${offlineRecord.id}\n类型: ${offlineRecord.type}`,
    //   showCancel: false
    // });
 
    // 2. 触发同步队列(联网时会自动上传图片并调用接口)
    startSyncQueue();
    return true;
  } catch (error) {
    console.error('保存记录失败:', error);
    uni.showModal({
      title: '离线保存失败',
      content: `存入数据库报错: ${error.message || JSON.stringify(error)}`,
      showCancel: false
    });
    return false;
  }
};
 
const goNext = async () => {
  const saveSuccess = await saveCheckInRecord();
  if (!saveSuccess) {
    return;
  }
 
  if (mode.value === 'signout') {
    uni.navigateTo({
      url: '/pages/signout-complete/index'
    });
  } else {
    uni.navigateTo({
      url: `/pages/online-complete/index?mode=${mode.value}`
    });
  }
};
 
// 打印凭条辅助函数
const getPrintPair = (key, value) => {
  return {
    textLineHeight: 40,
    alignment: 0,
    textUnderline: 0,
    textBold: 1,
    textWidthScale: 0,
    textHeightScale: 0,
    text: key,
    lineStroke: 0,
    lineStartPosition: 0,
    lineEndPosition: 0,
    feedLine: 1,
    qrcode: null,
    barcodeHeight: 60,
    barcodeUnitWidth: 3,
    barcode: null,
    imageWidth: 384,
    url: null,
    path: null,
    sub: {
      textLineHeight: 40,
      alignment: 2,
      textUnderline: 0,
      textBold: 0,
      textWidthScale: 0,
      textHeightScale: 0,
      text: value || '',
      lineStroke: 0,
      lineStartPosition: 0,
      lineEndPosition: 0,
      feedLine: 0,
      qrcode: null,
      barcodeHeight: 60,
      barcodeUnitWidth: 3,
      barcode: null,
      imageWidth: 384,
      url: null,
      path: null,
      sub: null
    }
  };
};
 
const createEmptyPrintLine = () => {
  return {
    textLineHeight: 40,
    alignment: 1,
    textUnderline: 0,
    textBold: 0,
    textWidthScale: 0,
    textHeightScale: 0,
    text: null,
    lineStroke: 0,
    lineStartPosition: 0,
    lineEndPosition: 0,
    feedLine: 1,
    qrcode: null,
    barcodeHeight: 60,
    barcodeUnitWidth: 3,
    barcode: null,
    imageWidth: 384,
    url: null,
    path: null,
    sub: null
  };
};
 
const getPrintVisitorName = () => {
  let printVisitorName = appointmentIdCardPayload.value?.name || appointmentIdCardPayload.value?.visitorName || appointmentQrcodePayload.value?.visitorName || '无';
  if (mode.value === 'online' && manualName.value.trim()) {
    printVisitorName = manualName.value.trim();
  }
  return printVisitorName || '无';
};
 
const getPrintAppointmentTimeRange = () => {
  if (mode.value === 'online') {
    return `${visitEndDateText.value} ${selectedTime.value}`;
  }
 
  if (appointmentQrcodePayload.value) {
    return `${appointmentQrcodePayload.value.startTime || ''} 至 ${appointmentQrcodePayload.value.endTime || ''}` || '无';
  }
 
  return '无';
};
 
const getPrintFieldValueMap = () => {
  const hostName = appointmentQrcodePayload.value?.beVisitorName || '无';
  const areas = mode.value === 'online' ? getSelectedAreaNames() : (appointmentQrcodePayload.value?.areas || '无');
  // 打印时优先使用已采集到的现场人脸图,只有没有抓拍图时才回退到身份证照片
  const photoPath = appointmentIdCardPayload.value?.livePhotoAddress
    || liveFacePhotoPath.value
    || appointmentIdCardPayload.value?.photoAddress
    || '';
 
  return {
    visitorName: {
      type: 'text',
      value: getPrintVisitorName(),
    },
    idCard: {
      type: 'text',
      value: idNumber.value || appointmentIdCardPayload.value?.licId || '无',
    },
    appointmentTimeRange: {
      type: 'text',
      value: getPrintAppointmentTimeRange(),
    },
    interviewee: {
      type: 'text',
      value: hostName,
    },
    visitorFaceImage: {
      type: 'image',
      value: photoPath,
      emptyText: '无',
    },
    registerNo: {
      type: 'text',
      value: appointmentQrcodePayload.value?.registerNo || appointmentQrcodePayload.value?.appointmentNo || appointmentQrcodePayload.value?.reservationNo || '无',
    },
    plateNo: {
      type: 'text',
      value: plateNumber.value || '无',
    },
    visitReason: {
      type: 'text',
      value: appointmentQrcodePayload.value?.visitPurpose || '无',
    },
    visitArea: {
      type: 'text',
      value: areas || '无',
    },
  };
};
 
const pushPrintFieldByOption = (list, fieldOption, fieldValueMap) => {
  const fieldCode = fieldOption?.fieldCode;
  const fieldName = fieldOption?.fieldName || fieldCode || '未知字段';
  const fieldConfig = fieldValueMap[fieldCode];
 
  if (!fieldConfig) {
    return;
  }
 
  if (fieldConfig.type === 'image') {
    list.push(getPrintPair(fieldName, fieldConfig.value ? '已采集' : (fieldConfig.emptyText || '无')));
    if (fieldConfig.value) {
      const imageLine = createEmptyPrintLine();
      imageLine.path = fieldConfig.value;
      imageLine.alignment = 2;
      imageLine.imageWidth = 240;
      imageLine.feedLine = 1;
      list.push(imageLine);
    }
    return;
  }
 
  list.push(getPrintPair(fieldName, fieldConfig.value || '无'));
};
 
const startPrintTicket = async () => {
  try {
    const list = [];
 
    // 空行
    list.push(createEmptyPrintLine());
 
    const titleLine = createEmptyPrintLine();
    titleLine.text = "登记凭证";
    titleLine.alignment = 1;
    titleLine.textWidthScale = 1;
    titleLine.textHeightScale = 1;
    titleLine.textBold = 1;
    list.push(titleLine);
 
    const subTitleLine = createEmptyPrintLine();
    subTitleLine.text = "*****";
    subTitleLine.alignment = 1;
    subTitleLine.textBold = 1;
    list.push(subTitleLine);
 
    // 空行
    list.push(createEmptyPrintLine());
 
    const fieldValueMap = getPrintFieldValueMap();
    configuredPrintFieldOptions.value.forEach((fieldOption) => {
      pushPrintFieldByOption(list, fieldOption, fieldValueMap);
    });
 
    console.log('开始打印凭条,参数:', list);
    const data = JSON.stringify(list);
    const printRes = await HardwareAPI.startPrint(data);
    console.log('打印成功:', printRes);
 
    // 打印成功后自动跳转到完成页面
    goNext();
  } catch (error) {
    console.error('打印失败:', error);
    openNoticeDialog('打印失败', '请检查打印机状态或纸张是否充足');
  }
};
</script>
 
<style scoped>
.page-container {
  width: 1080px;
  height: 1920px;
 
  background: linear-gradient(180deg, #3B78FF 0%, #2860E8 50%, #163EBC 100%);
  padding: 30px 36px 40px 36px;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}
 
.notice-dialog-wrapper {
  position: fixed;
  left: 0;
  top: 0;
  width: 1080px;
  height: 1920px;
  z-index: 999;
}
 
.notice-dialog-mask {
  position: absolute;
  left: 0;
  top: 0;
  width: 1080px;
  height: 1920px;
  background: rgba(31, 42, 68, 0.6);
}
 
.notice-dialog-card {
  position: absolute;
  left: 165px;
  top: 808px;
  width: 750px;
  padding: 52px 40px;
  border-radius: 28px;
  background: #FFFFFF;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
 
.notice-dialog-copy {
  width: 670px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
 
.notice-dialog-title {
  font-family: Inter, sans-serif;
  font-size: 34px;
  font-weight: 700;
  color: #1F2A44;
  text-align: center;
  margin-bottom: 16px;
}
 
.notice-dialog-desc {
  font-family: Inter, sans-serif;
  font-size: 20px;
  font-weight: 500;
  color: #7B88A8;
  text-align: center;
  line-height: 32px;
}
 
.notice-dialog-button-row {
  width: 670px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 40px;
}
 
.notice-dialog-close-btn {
  width: 220px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 20px;
  background: #F5F5F5;
}
 
.notice-dialog-close-text {
  font-family: Inter, sans-serif;
  font-size: 20px;
  font-weight: 700;
  color: #666666;
}
 
.bg-glow {
  position: absolute;
  width: 300px;
  height: 300px;
  border-radius: 300px;
  background: rgba(127, 177, 255, 0.1);
  left: -128px;
  top: 412px;
  filter: blur(50px);
  pointer-events: none;
}
 
/* 头部 */
.header-area {
  width: 1008px;
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  z-index: 1;
}
 
.left-action {
  display: flex;
  align-items: center;
  flex-direction: row;
  width: 1008px;
  height: 88px;
  /* cursor: pointer; */
}
 
.back-btn {
  width: 44px;
  height: 44px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.26);
  box-shadow: 0px 10px 22px rgba(15, 46, 133, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
}
 
.back-icon-img {
  width: 20px;
  height: 20px;
}
 
.page-title {
  font-family: Inter, sans-serif;
  font-size: 30px;
  font-weight: 700;
  color: #FFFFFF;
  margin-left: 16px;
  line-height: 44px;
  height: 44px;
}
 
/* 主体区 */
.main-card {
  width: 1008px;
  height: 1200px;
  border-radius: 34px;
  background: linear-gradient(180deg, #FFFFFF 0%, #F7FAFF 100%);
  border: 1px solid #DEE9FF;
  box-shadow: 0px 22px 52px rgba(13, 46, 134, 0.25);
  padding: 32px;
 
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 24px;
  z-index: 1;
}
 
.main-title {
  font-family: Inter, sans-serif;
  font-size: 42px;
  font-weight: 800;
  color: #1F2A44;
  text-align: center;
  height: 50px;
}
 
.error-hint {
  margin-top: -20px;
  font-family: Inter, sans-serif;
  font-size: 22px;
  font-weight: 700;
  color: #F05A67;
  text-align: center;
  height: 32px;
  margin-bottom: 24px;
}
 
.main-desc {
  font-family: Inter, sans-serif;
  font-size: 22px;
  font-weight: 500;
  color: #4A5672;
  text-align: center;
  margin-bottom: 24px;
  margin-top: 24px;
}
 
/* 设备展示区 */
.device-area {
  width: 942px;
  height: 820px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 24px;
}
 
.device-img {
  width: 942px;
  height: 820px;
}
 
.helper-text {
  font-family: Inter, sans-serif;
  font-size: 18px;
  font-weight: 500;
  color: #7B88A8;
  text-align: center;
}
 
/* 身份证信息特有样式 */
.name-hint-row {
  display: flex;
  align-items: center;
  flex-direction: row;
  height: 26px;
}
 
.name-icon-box {
  width: 18px;
  height: 18px;
  border-radius: 9px;
  background: #F3F6FC;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 8px;
}
 
.name-icon-text {
  font-family: Inter, sans-serif;
  font-size: 10px;
  font-weight: 700;
  color: #7B88A8;
}
 
.name-text {
  font-family: Inter, sans-serif;
  font-size: 18px;
  font-weight: 500;
  color: #7B88A8;
}
 
/* 手动录入信息特有样式 */
.manual-card {
  height: 720px;
  padding: 38px 32px 28px 32px;
}
 
.input-form-card {
  width: 820px;
  /* height: 230px; */
  border-radius: 28px;
  background: #F8FAFF;
  border: 1px solid #D9E1F2;
  padding: 26px;
 
  display: flex;
  flex-direction: column;
  margin-top: 40px;
}
 
.manual-input-box {
  width: 768px;
  height: 118px;
  border-radius: 22px;
  background: #FFFFFF;
  border: 1px solid #D9E1F2;
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
}
 
.input-text {
  font-family: Inter, sans-serif;
  font-size: 40px;
  font-weight: 700;
  color: #1F2A44;
  letter-spacing: 2px;
}
 
.input-text.placeholder {
  font-size: 24px;
  font-weight: 500;
  color: #A0ACC4;
  letter-spacing: normal;
}
 
.input-helper-row {
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
}
 
.input-helper-text {
  font-family: Inter, sans-serif;
  font-size: 17px;
  font-weight: 500;
  color: #7B88A8;
}
 
.form-action-row {
  width: 820px;
  height: 112px;
  display: flex;
  flex-direction: row;
  margin-top: 40px;
}
 
.clear-btn {
  width: 232px;
  height: 112px;
  border-radius: 24px;
  background: #EEF4FF;
  border: 1px solid #D6E3FF;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 16px;
}
 
.clear-btn-text {
  font-family: Inter, sans-serif;
  font-size: 24px;
  font-weight: 700;
  color: #2F6BFF;
}
 
.confirm-btn {
  flex: 1;
  height: 112px;
  border-radius: 24px;
  background: linear-gradient(to bottom, #5A8FFF, #2F6BFF);
  border: 1px solid rgba(255, 255, 255, 0.33);
  box-shadow: 0px 10px 22px rgba(47, 107, 255, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
}
 
.confirm-btn-text {
  font-family: Inter, sans-serif;
  font-size: 24px;
  font-weight: 700;
  color: #FFFFFF;
}
 
.clear-btn-disabled {
  width: 232px;
  height: 112px;
  border-radius: 24px;
  background: #F3F6FB;
  border: 1px solid #E1E7F0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 16px;
}
 
.clear-btn-text-disabled {
  font-family: Inter, sans-serif;
  font-size: 24px;
  font-weight: 700;
  color: #A8B3C4;
}
 
.confirm-btn-disabled {
  flex: 1;
  height: 112px;
  border-radius: 24px;
  background: #E5EAF2;
  border: 1px solid #D8DEE8;
  display: flex;
  align-items: center;
  justify-content: center;
}
 
.confirm-btn-text-disabled {
  font-family: Inter, sans-serif;
  font-size: 24px;
  font-weight: 700;
  color: #9AA6B8;
}
 
/* 自定义键盘 */
.custom-keyboard {
  width: 1008px;
  height: 796px;
  background: #FFFFFF;
  border-radius: 30px;
  border: 1px solid #D9E6FF;
  box-shadow: 0px -8px 24px 0px rgba(13, 46, 134, 0.08);
  padding: 22px 16px 24px 16px;
 
  display: flex;
  flex-direction: column;
  z-index: 10;
}
 
.keyboard-grid {
  display: flex;
  flex-direction: column;
  flex: 1;
  width: 976px;
}
 
.keyboard-row {
  display: flex;
  flex-direction: row;
  flex: 1;
  width: 976px;
}
 
.key-btn {
  flex: 1;
  background: #FFFFFF;
  border-radius: 26px;
  border: 1px solid #D9E1F2;
  display: flex;
  align-items: center;
  justify-content: center;
 
  margin: 0 18px 18px 0;
}
 
.key-btn:last-child {
  margin-right: 0;
}
 
.keyboard-row:last-child .key-btn{
  margin-bottom: 0;
}
 
.key-btn:active {
  background: #E5EAF2;
}
 
.key-text {
  font-family: Inter, sans-serif;
  font-size: 38px;
  font-weight: 700;
  color: #1F2A44;
}
 
.key-x {
  background: #EEF4FF;
  border: 1px solid #D6E3FF;
}
 
.key-text-x {
  font-family: Inter, sans-serif;
  font-size: 38px;
  font-weight: 700;
  color: #2F6BFF;
}
 
.key-delete {
  background: #FFF5E4;
  border: 1px solid #FFDDA8;
}
 
.key-text-delete {
  font-family: Inter, sans-serif;
  font-size: 34px;
  font-weight: 700;
  color: #C47A00;
}
 
.keyboard-close {
  position: absolute;
  top: -60px;
  right: 20px;
  width: 80px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 10px rgba(0,0,0,0.05);
}
 
/* 人脸验证特有样式 */
.title-group {
  display: flex;
  flex-direction: column;
  align-items: center;
}
 
.sub-title {
  font-family: Inter, sans-serif;
  font-size: 22px;
  font-weight: 500;
  color: #4A5672;
  margin-top: 12px;
}
 
.name-pill {
  display: flex;
  align-items: center;
  flex-direction: row;
  margin-top: 16px;
}
 
.name-icon {
  width: 18px;
  height: 18px;
  border-radius: 9px;
  background: #F3F6FC;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 8px;
}
 
.face-capture-card {
  width: 880px;
  height: 876px;
  border-radius: 36px;
  background: linear-gradient(to bottom, #101C3D, #0A132B);
  border: 1px solid #243B72;
  box-shadow: 0px 14px 34px rgba(8, 17, 38, 0.23);
  padding: 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 24px;
}
 
.status-pill {
  /* width: 236px; */
  height: 52px;
  border-radius: 26px;
  background: #132852;
  border: 1px solid #2D4F8D;
  box-shadow: 0px 6px 16px rgba(11, 23, 48, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: row;
  padding: 0 24px;
}
 
.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 12px;
  background: #55D6FF;
  box-shadow: 0px 0px 10px rgba(85, 214, 255, 0.4);
  margin-right: 10px;
}
 
.status-text {
  font-family: Inter, sans-serif;
  font-size: 20px;
  font-weight: 700;
  color: #F4F8FF;
}
 
.viewfinder-area {
  width: 760px;
  height: 652px;
  border-radius: 32px;
  background: linear-gradient(to bottom, #07111F , #050A15);
  /* background-color: #07111F; */
  border: 1px solid #223B71;
  box-shadow: 0px 10px 24px rgba(5, 10, 21, 0.2);
  padding: 24px 24px 28px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-top: 26px;
}
 
.viewfinder-box {
  width: 536px;
  height: 528px;
  border-radius: 30px;
  background: #0A1427;
  /* border: 2px solid #3B66B8; */
  /* box-shadow: 0px 10px 24px rgba(10, 20, 39, 0.27); */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  margin-bottom: 28px;
}
 
.face-camera {
  position: absolute;
  left: 0;
  top: 0;
  width: 536px;
  height: 528px;
  z-index: 0;
  /* background: #fff; */
}
 
.viewfinder-corner-wrap {
  position: absolute;
  width: 30px;
  height: 30px;
  overflow: hidden;
  z-index: 1;
}
 
.viewfinder-corner-wrap-tl { left: 0; top: 0; }
.viewfinder-corner-wrap-tr { right: 0; top: 0; }
.viewfinder-corner-wrap-bl { left: 0; bottom: 0; }
.viewfinder-corner-wrap-br { right: 0; bottom: 0; }
 
.corner-donut {
  position: absolute;
  width: 122px;
  height: 122px;
  border-radius: 61px;
  border-width: 32px;
  border-style: solid;
  /* border-color: #0A1427; */
  border-color: #050A15;
  background-color: rgba(0, 0, 0, 0);
}
 
.corner-donut-tl { left: -31px; top: -31px; border-color: #07111F; }
.corner-donut-tr { left: -61px; top: -31px; border-color: #07111F;}
.corner-donut-bl { left: -31px; top: -61px; }
.corner-donut-br { left: -61px; top: -61px; }
 
.viewfinder-border-mask {
  position: absolute;
  left: 0;
  top: 0;
  width: 536px;
  height: 528px;
  border-radius: 30px;
  border: 2px solid #3B66B8;
  /* box-sizing: border-box; */
  background-color: rgba(0, 0, 0, 0);
  z-index: 2;
  pointer-events: none;
}
 
.head-ellipse {
  width: 128px;
  height: 150px;
  border-radius: 50%;
  background: #F7FAFF;
  position: absolute;
  top: 100px;
  opacity: 0.15;
  z-index: 1;
  pointer-events: none;
}
 
.shoulder-ellipse {
  width: 300px;
  height: 176px;
  border-radius: 50%;
  background: #F7FAFF;
  position: absolute;
  bottom: 0px;
  opacity: 0.15;
  z-index: 1;
  pointer-events: none;
}
 
.scan-line {
  width: 372px;
  height: 5px;
  border-radius: 3px;
  background: #55D6FF;
  box-shadow: 0px 0px 12px rgba(85, 214, 255, 0.33);
  position: absolute;
  top: 50px;
  z-index: 2;
  pointer-events: none;
}
 
.viewfinder-hint {
  font-family: Inter, sans-serif;
  font-size: 17px;
  font-weight: 600;
  color: #D8E7FF;
}
 
.hints-row {
  width: 818px;
  height: 34px;
  display: flex;
  justify-content: center;
  flex-direction: row;
  margin-top: 26px;
}
 
.hint-item {
  display: flex;
  align-items: center;
  justify-content: center;
   flex-direction: row;
  margin-right: 18px;
}
 
.hint-item:last-child {
  margin-right: 0;
}
 
.hint-dot {
  width: 8px;
  height: 8px;
  border-radius: 8px;
  margin-right: 8px;
}
 
.hint-text {
  font-family: Inter, sans-serif;
  font-size: 16px;
  font-weight: 700;
  color: #DCE6FF;
}
 
.bottom-subtext {
  font-family: Inter, sans-serif;
  font-size: 18px;
  font-weight: 500;
  color: #7B88A8;
  text-align: center;
  margin-top: 24px;
}
 
.placeholder {
  color: #A0AFC0;
}
 
/* 打印凭条特有样式 */
.print-demo-card {
  width: 880px;
  height: 860px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 20px;
}
 
.print-demo-img {
  width: 880px;
  height: 860px;
}
 
/* 底部区域 */
.bottom-area {
  width: 1008px;
  height: 176px;
  display: flex;
  flex-direction: row;
  z-index: 1;
}
 
.help-card {
  width: 388px;
  height: 176px;
  border-radius: 26px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.11) 0%, rgba(234, 242, 255, 0.08) 100%);
  border: 2px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0px 14px 30px rgba(10, 36, 107, 0.21);
  padding: 22px;
  display: flex;
  flex-direction: column;
  position: relative;
  margin-right: 18px;
}
 
.action-card {
  flex: 1;
  height: 176px;
  border-radius: 26px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.11) 0%, rgba(234, 242, 255, 0.08) 100%);
  border: 2px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0px 14px 30px rgba(10, 36, 107, 0.21);
  padding: 20px 22px 22px 22px;
  display: flex;
  flex-direction: column;
  position: relative;
}
 
.highlight-bar {
  /* position: absolute;
  top: 20px;
  left: 22px; */
  width: 108px;
  height: 6px;
  border-radius: 2px;
  background: #A8CBFF;
}
 
.card-title-row {
  display: flex;
  align-items: center;
  flex-direction: row;
  margin-top: 12px;
}
 
.icon-base {
  width: 38px;
  height: 38px;
  border-radius: 19px;
  background: rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 10px;
}
 
.icon-base-img {
  width: 20px;
  height: 20px;
}
 
.card-title {
  font-family: Inter, sans-serif;
  font-size: 21px;
  font-weight: 800;
  color: #FFFFFF;
}
 
.help-content {
  font-family: Inter, sans-serif;
  font-size: 16px;
  font-weight: 500;
  color: #EAF1FF;
  /* white-space: pre-line; */
  margin-top: 16px;
}
 
.main-btn {
  width: 556px;
  height: 56px;
  border-radius: 18px;
  background: linear-gradient(180deg, #FFFFFF 0%, #F4F8FF 100%);
  border: 1px solid rgba(255, 255, 255, 0.5);
  box-shadow: 0px 8px 18px rgba(7, 29, 90, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  /* cursor: pointer; */
  margin-top: 12px;
}
 
.btn-text {
  font-family: Inter, sans-serif;
  font-size: 19px;
  font-weight: 800;
  color: #1F49D8;
}
/* ================= 完善登记信息样式 ================= */
.form-card {
  width: 1008px;
  height: 1200px;
  border-radius: 32px;
  background: #FFFFFF;
  padding: 32px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 22px 52px rgba(13, 46, 134, 0.25);
  z-index: 1;
}
 
.form-row {
  width: 944px;
  height: 56px;
  display: flex;
  align-items: center;
  flex-direction: row;
  margin-bottom: 24px;
}
 
.label {
  width: 220px;
  font-family: Inter, sans-serif;
  font-size: 18px;
  font-weight: 600;
  color: #1F2A44;
  margin-right: 16px;
}
 
.datetime-group {
  flex: 1;
  display: flex;
  align-items: center;
  flex-direction: row;
}
 
.input-box {
  height: 56px;
  border-radius: 14px;
  border: 1px solid #D9E1F2;
  background: #FFFFFF;
  padding: 0 16px;
  display: flex;
  align-items: center;
  flex-direction: row;
}
 
.pressable-box {
  /* cursor: pointer; */
}
 
.date-box {
  width: 440px; /* 变长 */
  justify-content: flex-start;
  margin-right: 14px;
}
 
.time-box {
  width: 200px;
  flex: 1; /* 占据剩余空间 */
  justify-content: space-between;
}
 
.field-prefix-icon-img,
.field-suffix-icon-img {
  width: 20px;
  height: 20px;
  /* flex-shrink: 0; */
  opacity: 0.6; /* 让图标稍微弱化一点,更贴近设计图的灰色线条感 */
}
 
.full-box {
  flex: 1;
}
 
.between-box {
  justify-content: space-between;
}
 
.field-arrow-icon-img {
  width: 20px;
  height: 20px;
  /* flex-shrink: 0; */
}
 
.reverse-arrow {
  transform: rotate(180deg);
}
 
.input-value {
  font-family: Inter, sans-serif;
  font-size: 18px;
  font-weight: 600;
  color: #1F2A44;
  margin-left: 12px;
}
 
.time-value {
  font-family: Inter, sans-serif;
  font-size: 18px;
  font-weight: 600;
  color: #7B88A8;
}
 
.muted-value {
  font-family: Inter, sans-serif;
  font-size: 18px;
  font-weight: 600;
  color: #7B88A8;
}
 
.plate-value {
  /* letter-spacing: 1px; */
}
 
.selected-area-box {
  width: 944px;
  border-radius: 16px;
  background: #F3F6FC;
  padding: 16px;
 
  display: flex;
  flex-direction: column;
}
 
.tag-row {
  width: 912px;
  display: flex;
  align-items: center;
  flex-direction: row;
  flex-wrap: wrap;
}
 
.tag-item {
  height: 36px;
  border-radius: 18px;
  border: 1px solid #D9E1F2;
  background: #FFFFFF;
  padding: 0 12px;
  display: flex;
  align-items: center;
  flex-direction: row;
  margin-right: 10px;
}
 
.tag-text {
  font-family: Inter, sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: #1F2A44;
  margin-right: 8px;
}
 
.tag-x {
  font-family: Inter, sans-serif;
  font-size: 18px;
  font-weight: 700;
  color: #A0ACC4;
  /* cursor: pointer; */
}
 
.save-btn {
  width: 944px;
  height: 78px;
  border-radius: 18px;
  background: #2F6BFF;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 24px;
}
 
.save-btn-text {
  font-family: Inter, sans-serif;
  font-size: 22px;
  font-weight: 700;
  color: #FFFFFF;
}
 
/* 底部弹窗相关 */
.mask-layer {
  position: fixed;
  left: 0;
  top: 0;
  width: 1080px;
  height: 1920px;
  background: rgba(11, 18, 32, 0.5);
  z-index: 20;
}
 
.bottom-sheet {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 1080px;
  background: #FFFFFF;
  border-radius: 28px 28px 0 0;
  padding: 28px 28px 36px 28px;
  z-index: 21;
}
 
.time-sheet { height: 800px; }
.area-sheet { height: 1200px; }
.plate-sheet { height: 960px; }
 
.sheet-head {
  width: 1024px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-direction: row;
  margin-bottom: 24px;
}
 
.compact-head { margin-bottom: 18px; }
 
.sheet-title {
  font-family: Inter, sans-serif;
  font-size: 30px;
  font-weight: 700;
  color: #1F2A44;
}
 
.area-sheet-head { justify-content: space-between; }
.sheet-head-placeholder { width: 44px; height: 44px; }
.area-title { font-size: 22px; text-align: center; }
 
.area-close-btn {
  width: 44px;
  height: 44px;
  border-radius: 22px;
  border: 1px solid #EEF2FA;
  background: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}
 
.rotate-45 {
  transform: rotate(45deg);
}
 
.sheet-close {
  font-family: Inter, sans-serif;
  font-size: 18px;
  font-weight: 600;
  color: #1F2A44;
}
 
.time-picker-body {
  width: 1024px;
  display: flex;
  flex-direction: row;
  margin-bottom: 30px;
}
 
.time-column {
  flex: 1;
  height: 560px;
  border-radius: 24px;
  background: #F7FAFF;
  border: 1px solid #EEF2FA;
  padding: 24px;
  margin-right: 24px;
}
 
.time-column:last-child { margin-right: 0; }
 
.time-column-title {
  /* display: block; */
  margin-bottom: 18px;
  font-family: Inter, sans-serif;
  font-size: 24px;
  font-weight: 700;
  color: #1F2A44;
}
 
.time-scroll { height: 460px; }
 
.time-item {
  width: 438px;
  height: 68px;
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  background: #FFFFFF;
  border: 1px solid #E5ECF8;
}
 
.time-item-active {
  background: #EAF1FF;
  border-color: #BFD4FF;
}
 
.time-item-text {
  font-family: Inter, sans-serif;
  font-size: 24px;
  font-weight: 700;
  color: #1F2A44;
}
 
.area-list-card {
  width: 1024px;
  height: 520px;
  border-radius: 24px;
  background: #FFFFFF;
  border: 1px solid #EEF2FA;
  padding: 16px;
 
  display: flex;
  flex-direction: row;
  margin-bottom: 430px;
}
 
.area-column {
  height: 520px;
  display: flex;
  flex-direction: column;
  margin-right: 16px;
}
 
.area-primary-column { width: 470px; }
.area-secondary-column { flex: 1; }
 
.primary-area-row,
.secondary-area-row {
  width: 480px;
  height: 64px;
  border-radius: 16px;
  padding: 0 16px;
 
  display: flex;
  align-items: center;
  margin-bottom: 12px;
  flex-direction: row;
}
 
.primary-area-row {
    width: 470px;
  justify-content: space-between;
  height: 64px;
  background: #FFFFFF;
}
 
.primary-area-row-active,
.secondary-area-row-active {
  background: #EAF1FF;
}
 
.primary-area-left {
  display: flex;
  align-items: center;
  flex-direction: row;
}
 
.primary-check,
.secondary-check {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid #D9E1F2;
  background: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
 
  flex-direction: row;
  margin-right: 12px;
}
 
.primary-check-active,
.secondary-check-active {
  background: #2F6BFF;
  border-color: #2F6BFF;
}
 
.partial-line {
  width: 14px;
  height: 3px;
  border-radius: 999px;
  background: #FFFFFF;
}
 
.check-icon-img {
  width: 16px;
  height: 16px;
}
 
.primary-area-text,
.secondary-area-text {
  font-family: Inter, sans-serif;
  font-size: 18px;
  font-weight: 600;
  color: #1F2A44;
}
 
.primary-area-text { font-weight: 600; color: #1F2A44; }
 
.primary-area-text-active,
.secondary-area-text-active { font-weight: 700; color: #2F6BFF; }
 
.sheet-confirm-btn {
  width: 1024px;
  height: 78px;
  border-radius: 18px;
  background: #2F6BFF;
  display: flex;
  align-items: center;
  justify-content: center;
}
 
.sheet-confirm-text {
  font-family: Inter, sans-serif;
  font-size: 22px;
  font-weight: 700;
  color: #FFFFFF;
}
 
.plate-section { width: 1024px; margin-bottom: 16px; }
.plate-step-tip { width: 1024px; margin-bottom: 14px; }
.plate-step-tip-text { font-family: Inter, sans-serif; font-size: 18px; font-weight: 600; color: #7B88A8; }
 
.province-grid {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
}
 
.plate-grid-row {
  display: flex;
  flex-direction: row;
  margin-bottom: 12px;
}
 
.keyboard-key {
  width: 82px;
  height: 58px;
  border-radius: 10px;
  background: #F5F5F5;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}
 
 
.province-key {
  width: 103px;
  height: 68px;
}
.keyboard-key-active { background: #EAF1FF; }
.keyboard-key-disabled { opacity: 0.45; }
.keyboard-key-special { background: #ECECEC; }
.delete-key {
  width: 68px;
  background: #F0F0F0;
}
 
.delete-key-icon-img {
  width: 22px;
  height: 22px;
}
 
.keyboard-key-text {
  font-family: Inter, sans-serif;
  font-size: 20px;
  font-weight: 700;
  color: #4D4D4D;
}
 
.plate-action-row {
  display: flex;
  flex-direction: row;
  margin-top: 10px;
}
 
.plate-secondary-btn {
  width: 180px;
  height: 78px;
  border-radius: 18px;
  background: #EEF4FF;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 16px;
}
 
.plate-secondary-text {
  font-family: Inter, sans-serif;
  font-size: 22px;
  font-weight: 700;
  color: #2F6BFF;
}
 
.plate-confirm-btn { flex: 1; }
 
</style>