home.html
95.7 KB
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
<!DOCTYPE html>
<html lang="zh-CN" class="pos-app-root">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/style.css?id=1">
<link rel="stylesheet" href="css/pos-unified.css">
<script src="./js/vue.min.js"></script>
<script src="./axios-1.x/axios-1.x/dist/axios.js"></script>
<script src="./axios-1.x/axios-1.x/dist/axios.min.js"></script>
<script type="text/javascript" src="./js/jquery.min.js"></script>
<style>
/* 弹出层样式 */
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.4);
justify-content: center;
align-items: center;
z-index: 99999;
animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
.modal-content {
background-color: white;
padding: 24px;
border-radius: 8px;
max-width: 500px;
width: 100%;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
animation: slideUp 0.3s ease;
}
@keyframes slideUp {
from {
transform: translateY(20px);
opacity: 0;
}
to {
transform: translateY(0);
opacity: 1;
}
}
.member-search {
display: flex;
gap: 10px;
align-items: stretch;
}
.home-member-picker .member-search input {
flex: 1 1 auto;
min-width: 0;
min-height: 48px;
padding: 12px 14px;
font-size: 14px;
border: 1px solid #e0e0e0;
border-radius: 6px;
box-sizing: border-box;
transition: all 0.3s ease;
font-family: inherit;
line-height: 1.35;
}
.member-search input {
flex-grow: 1;
padding: 12px 14px;
font-size: 14px;
border: 1px solid #e0e0e0;
border-radius: 6px;
box-sizing: border-box;
transition: all 0.3s ease;
font-family: inherit;
}
.member-search input:focus {
border-color: #5b7bfa;
outline: none;
box-shadow: 0 0 0 3px rgba(91, 123, 250, 0.1);
}
.member-search input::placeholder {
color: #999;
}
.home-member-picker .member-search .query-button {
flex-shrink: 0;
margin: 0 !important;
min-height: 48px;
min-width: 88px;
padding: 0 20px;
display: inline-flex;
align-items: center;
justify-content: center;
background: linear-gradient(135deg, #5b7bfa 0%, #6883f4 100%);
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
transition: background 0.2s ease, box-shadow 0.2s ease;
font-size: 14px;
font-weight: 600;
font-family: inherit;
box-shadow: 0 2px 6px rgba(91, 123, 250, 0.2);
}
.home-member-picker .member-search .query-button:hover {
background: linear-gradient(135deg, #4a68f0 0%, #5570e8 100%);
box-shadow: 0 4px 12px rgba(91, 123, 250, 0.3);
}
.member-search .query-button {
padding: 12px 24px;
background: linear-gradient(135deg, #5b7bfa 0%, #6883f4 100%);
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
transition: all 0.3s ease;
font-size: 14px;
font-weight: 500;
box-shadow: 0 2px 6px rgba(91, 123, 250, 0.2);
}
.member-search .query-button:hover {
background: linear-gradient(135deg, #4a68f0 0%, #5570e8 100%);
box-shadow: 0 4px 12px rgba(91, 123, 250, 0.3);
transform: translateY(-1px);
}
.member-list {
max-height: 400px;
overflow-y: auto;
margin-top: 16px;
border: 1px solid #f0f0f0;
border-radius: 6px;
background-color: #fafbff;
}
.member-list > div {
padding: 14px 16px;
border-bottom: 1px solid #f0f0f0;
cursor: pointer;
transition: all 0.2s ease;
color: #333;
font-size: 14px;
}
.member-list > div:last-child {
border-bottom: none;
}
.member-list > div:hover {
background-color: #f2f5fe;
color: #5b7bfa;
font-weight: 500;
}
/* 首页:选择会员弹窗(与新建会员 iframe 联动) */
.home-member-picker__title {
margin: 0 0 8px;
font-size: 18px;
font-weight: 700;
color: #1e293b;
}
.home-member-picker__hint {
margin: 0 0 14px;
font-size: 13px;
line-height: 1.5;
color: #64748b;
}
.home-member-picker__empty {
margin-top: 12px;
padding: 12px 14px;
font-size: 13px;
color: #64748b;
background: #f8fafc;
border: 1px dashed #cbd5e1;
border-radius: 8px;
line-height: 1.5;
}
.home-member-picker__footer {
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: center;
justify-content: flex-end;
gap: 10px;
margin-top: 18px;
padding-top: 16px;
border-top: 1px solid #e2e8f0;
}
.home-member-picker__footer .home-member-picker__btn--ghost {
margin-right: auto;
}
.home-member-picker__btn {
margin: 0 !important;
min-height: 44px;
padding: 0 20px !important;
font-size: 14px !important;
font-weight: 600 !important;
border-radius: 8px !important;
cursor: pointer;
border: none;
}
.home-member-picker__btn--primary {
background: linear-gradient(135deg, #5b7bfa 0%, #6883f4 100%) !important;
color: #fff !important;
box-shadow: 0 2px 8px rgba(91, 123, 250, 0.25) !important;
}
.home-member-picker__btn--ghost {
background: #f1f5f9 !important;
color: #475569 !important;
border: 1px solid #e2e8f0 !important;
box-shadow: none !important;
}
/* 勿作用于「选择会员」:否则会挤压查询行对齐,且 :last-of-type 误伤查询按钮为橙色 */
.modal-content:not(.home-member-picker) button {
margin-top: 20px;
padding: 12px 24px;
background: linear-gradient(135deg, #5b7bfa 0%, #6883f4 100%);
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
transition: all 0.3s ease;
font-size: 14px;
font-weight: 500;
box-shadow: 0 2px 6px rgba(91, 123, 250, 0.2);
margin-right: 12px;
}
.modal-content:not(.home-member-picker) button:hover {
background: linear-gradient(135deg, #4a68f0 0%, #5570e8 100%);
box-shadow: 0 4px 12px rgba(91, 123, 250, 0.3);
transform: translateY(-1px);
}
.modal-content:not(.home-member-picker) button:last-of-type {
background: linear-gradient(135deg, #de532c 0%, #d43d1a 100%);
box-shadow: 0 2px 6px rgba(222, 83, 44, 0.2);
}
.modal-content:not(.home-member-picker) button:last-of-type:hover {
background: linear-gradient(135deg, #d43d1a 0%, #c5300d 100%);
box-shadow: 0 4px 12px rgba(222, 83, 44, 0.3);
}
</style>
</head>
<body class="pos-page">
<div id="app">
<!-- 收银内嵌环境常屏蔽 alert:业务提示用页顶 Toast,保证可见 -->
<div
v-if="posToastMessage"
class="pos-home-toast"
role="alert"
>
<span class="pos-home-toast__text">{{ posToastMessage }}</span>
<button type="button" class="pos-home-toast__close" @click="clearPosToast" aria-label="关闭">×</button>
</div>
<!-- 弹出层 -->
<div
class="modal pos-member-form-modal"
:style="{ display: isModalOpen ? 'flex' : 'none' }"
@click.self="closeModal"
>
<div class="pos-member-form-modal__panel" @click.stop role="dialog" aria-modal="true" aria-label="新建会员">
<iframe
ref="memberFormIframe"
class="pos-member-form-modal__iframe"
:src="memberFormSrc"
title="新建会员"
></iframe>
</div>
</div>
<!-- 序列号选择弹窗(pos-unified 风格) -->
<div
class="pos-serial-modal"
:style="{ display: isSerialNumberModalOpen ? 'flex' : 'none' }"
@click.self="closeSerialNumberModal"
>
<div class="pos-serial-modal__panel" @click.stop role="dialog" aria-modal="true" aria-labelledby="pos-serial-modal-title">
<div class="pos-serial-modal__head">
<h2 id="pos-serial-modal-title" class="pos-serial-modal__title">
序列号选择
<span v-if="currentSerialNumberItem" class="pos-serial-modal__hint">({{ getSerialNumberTypeText(currentSerialNumberItem.spxlhType) }})</span>
</h2>
<button type="button" class="pos-serial-modal__close" @click="closeSerialNumberModal" aria-label="关闭">×</button>
</div>
<div class="pos-serial-modal__body">
<input type="hidden" v-model="serialNumberSearchForm.productCode" />
<!-- 入1出1:查询区 -->
<div class="pos-serial-modal__toolbar" v-if="isSerialNumberModalR1C1 || isSerialNumberModalShowBoth">
<select v-model="serialNumberSearchForm.warehouse" class="pos-select pos-serial-modal__field">
<option value="">全部仓库</option>
<option v-for="wh in warehouseOptions" :key="wh.F_Id" :value="wh.F_Id">{{ wh.F_mdmc }}</option>
</select>
<input
type="text"
class="pos-input pos-serial-modal__field pos-serial-modal__field--grow"
v-model="serialNumberSearchForm.serialNumber"
placeholder="序列号(支持模糊查询)"
/>
<button type="button" class="pos-serial-modal__toolbtn pos-serial-modal__toolbtn--primary" @click="searchSerialNumbers">查询</button>
<button type="button" class="pos-serial-modal__toolbtn pos-serial-modal__toolbtn--muted" @click="resetSerialNumberSearch">重置</button>
</div>
<!-- 入0出1 / 双模式:手动录入 -->
<div class="pos-serial-modal__manual" v-if="isSerialNumberModalR0C1 || isSerialNumberModalShowBoth">
<input
type="text"
class="pos-input pos-serial-modal__manual-input"
v-model="manualSerialNumberInput"
placeholder="手动输入序列号"
@keyup.enter="addManualSerialNumber"
/>
<button type="button" class="pos-serial-modal__toolbtn pos-serial-modal__toolbtn--green" @click="addManualSerialNumber">手动添加</button>
</div>
<!-- 已选 -->
<div class="pos-serial-modal__picked" v-if="selectedSerialNumbersForModal.length > 0">
<div class="pos-serial-modal__picked-title">已选序列号({{ selectedSerialNumbersForModal.length }} 个)</div>
<div class="pos-serial-modal__chips">
<button
type="button"
v-for="(sn, snIndex) in selectedSerialNumbersForModal"
:key="snIndex"
class="pos-serial-modal__chip"
@click="removeSerialNumberFromModal(sn)"
>
{{ sn }}
<span class="pos-serial-modal__chip-x" aria-hidden="true">×</span>
</button>
</div>
</div>
<!-- 表格 -->
<div class="pos-serial-modal__table-wrap" v-if="isSerialNumberModalR1C1 || isSerialNumberModalShowBoth">
<table class="pos-serial-modal__table">
<thead>
<tr>
<th class="pos-serial-modal__th-check">
<input type="checkbox" @change="toggleSelectAllSerialNumbers" :checked="isAllSerialNumbersSelected" />
</th>
<th>序列号</th>
<th>商品编码</th>
<th>商品名称</th>
<th>仓库</th>
<th>入库时间</th>
<th>状态</th>
</tr>
</thead>
<tbody>
<tr v-for="(sn, snIndex) in serialNumberList" :key="snIndex">
<td>
<input
type="checkbox"
:checked="isSerialNumberSelected(sn.serialNumber)"
@change="toggleSerialNumberSelection(sn.serialNumber)"
/>
</td>
<td class="pos-serial-modal__td-sn">
{{ sn.serialNumber }}
<span v-if="sn.isManual" class="pos-serial-modal__badge-manual">手动</span>
</td>
<td>{{ sn.productCodeEncode || '无' }}</td>
<td>{{ sn.productName || '无' }}</td>
<td>{{ getWarehouseName(sn.warehouse) }}</td>
<td>{{ formatDate(sn.inTime) }}</td>
<td>
<span
class="pos-serial-modal__status"
:class="{
'is-instock': sn.status === 0,
'is-muted': sn.status !== 0
}"
>
{{ sn.status === 0 ? '在库' : sn.status === 1 ? '已出库' : sn.status === 2 ? '已报废' : sn.status === 3 ? '已退货' : '未知' }}
</span>
</td>
</tr>
<tr v-if="serialNumberList.length === 0" class="pos-serial-modal__empty-row">
<td colspan="7">暂无数据,可调整仓库或关键词后查询</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="pos-serial-modal__foot">
<button type="button" class="pos-serial-modal__foot-btn pos-serial-modal__foot-btn--ghost" @click="closeSerialNumberModal">取消</button>
<button type="button" class="pos-serial-modal__foot-btn pos-serial-modal__foot-btn--primary" @click="confirmSerialNumberSelection">
确定(已选 {{ selectedSerialNumbersForModal.length }})
</button>
</div>
</div>
</div>
<!-- ... existing code ... -->
<div class="modal" :style="{ display: isModalOpen2 ? 'flex' : 'none' }" @click.self="closeModal2">
<div class="modal-content home-member-picker" @click.stop>
<h3 class="home-member-picker__title">选择会员</h3>
<p class="home-member-picker__hint">请输入会员手机号后点「查询」;若无档案请点底部「新建会员」录入,保存后会自动选中。</p>
<div class="member-search">
<input type="text" v-model="memberSearch" placeholder="会员手机号" @keyup.enter="searchMembers2">
<button type="button" class="query-button" @click="searchMembers2">查询</button>
</div>
<div class="member-list">
<div v-for="(member, index) in filteredMembers" :key="index" @click="selectMember2(member)">
{{ member.xm }} - {{ member.sjh }}
</div>
</div>
<div v-if="memberSearchNoResult" class="home-member-picker__empty" role="status">
未查到该手机号会员。请点底部「新建会员」录入档案,保存后将自动选中并关闭本窗口。
</div>
<div class="home-member-picker__footer">
<button type="button" class="home-member-picker__btn home-member-picker__btn--ghost" @click="closeModal2">关闭</button>
<button type="button" class="home-member-picker__btn home-member-picker__btn--primary" @click="openModalFromPicker">新建会员</button>
</div>
</div>
</div>
<!-- 优惠券赠送弹窗 -->
<div class="modal" :style="{ display: issueCouponModalOpen ? 'flex' : 'none' }">
<div class="modal-content">
<h3 style="text-align:center;margin-bottom:10px;">赠送优惠券给当前会员</h3>
<div v-if="!hyinfo" style="padding:20px;text-align:center;color:#999;">
请先选择会员
</div>
<div v-else>
<div style="margin-bottom:10px;font-size:13px;">
当前会员:<strong>{{ hyinfo.xm || hyinfo.sjh }}</strong>
</div>
<div style="margin-bottom:10px;">
<label style="display:block;margin-bottom:4px;font-size:13px;">选择优惠券模板:</label>
<select v-model="issueSelectedTemplateId" style="width:100%;padding:6px 8px;">
<option v-for="t in issueCouponTemplates" :key="t.id" :value="t.id">
{{ t.qmc }}({{ t.qlx }},面额:{{ t.me }})
</option>
</select>
</div>
<div style="margin-bottom:10px;">
<label style="display:block;margin-bottom:4px;font-size:13px;">发放数量:</label>
<input type="number" v-model.number="issueCount" min="1" max="20" style="width:100%;padding:6px 8px;">
</div>
<div v-if="issueLoading" style="font-size:12px;color:#999;margin-bottom:8px;">加载中...</div>
<div style="display:flex;justify-content:flex-end;gap:10px;margin-top:10px;">
<button @click="issueCouponModalOpen=false" style="padding:6px 14px;">取消</button>
<button @click="confirmIssueCoupon" style="padding:6px 14px;background:#409EFF;color:#fff;border:none;border-radius:4px;cursor:pointer;">确认赠送</button>
</div>
</div>
</div>
</div>
<div class="header settlement-pos-header pos-home-header">
<div class="home-center settlement-pos-title">
<svg class="pos-inline-svg pos-header-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true">
<path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z" />
</svg>
<span>{{ posCashierHeaderTitle }}</span>
</div>
<div class="home-right pos-header-tool-row">
<button type="button" class="pos-header-tool-btn settlement-touch" aria-label="刷新页面" onclick="location.reload()">
<svg class="pos-inline-svg pos-header-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true">
<path stroke-linecap="round" stroke-linejoin="round" d="M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0 3.181 3.183a8.25 8.25 0 0013.803-3.7M4.031 9.865a8.25 8.25 0 0113.803-3.7l3.181 3.182m0-4.991v4.99" />
</svg>
</button>
<a href="login.html" class="pos-header-tool-btn settlement-touch" aria-label="退出登录" style="text-decoration: none;">
<svg class="pos-inline-svg pos-header-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true">
<path stroke-linecap="round" stroke-linejoin="round" d="M15.75 9V5.25A2.25 2.25 0 0013.5 3h-6a2.25 2.25 0 00-2.25 2.25v13.5A2.25 2.25 0 007.5 21h6a2.25 2.25 0 002.25-2.25V15m3 0l3-3m0 0l-3-3m3 3H9" />
</svg>
</a>
</div>
</div>
<div class="content">
<div class="left">
<div class="user-info-container pos-member-strip" v-if="hyinfo">
<div class="pos-member-strip__main">
<div class="pos-member-strip__body">
<div class="user-logo">
<img src="images/head.png" alt="">
</div>
<div class="pos-member-strip__info">
<div class="pos-member-info-name-row">
<span class="pos-member-info-name user-name__xm">{{ hyinfo.xm }}</span>
<span class="vip-tag pos-member-level-tag" :style="memberLevelBadgeStyle">{{ memberLevel }}</span>
</div>
<div class="pos-member-info-phone user-phone">{{ hyinfo.sjh }}</div>
<div class="user-details-bottom pos-member-info-points">
<div class="user-points">积分 {{ memberPoints }}</div>
<div class="user-balance">余额 {{ memberBalance }}</div>
</div>
</div>
</div>
<div v-if="memberBenefitCardsDisplay.length" class="pos-member-benefits-wrap pos-member-benefits-wrap--full">
<div class="pos-member-benefits-hd">权益卡</div>
<ul class="pos-member-benefits-ul">
<li
v-for="row in memberBenefitCardsDisplay"
:key="row.key"
class="pos-member-benefit-li"
>
<span class="pos-member-benefit-name">{{ row.name }}</span>
<span
class="pos-member-benefit-exp"
:class="{ 'pos-member-benefit-exp--gone': row.expired }"
>{{ row.expireText }}</span>
</li>
</ul>
</div>
</div>
<div class="member-buttons pos-member-actions">
<button type="button" class="logout-btn pos-member-action-btn pos-member-action-btn--outline" @click="openModal2">更换会员</button>
<button type="button" class="logout-btn pos-member-action-btn" @click="gohyinfo">会员详情</button>
<button type="button" class="logout-btn pos-member-action-btn pos-member-action-btn--secondary" @click="openIssueCouponModal">赠送优惠券</button>
<button type="button" class="logout-btn pos-member-action-btn pos-member-action-btn--outline" @click="tuic">退出</button>
</div>
</div>
<div class="user-info-container pos-member-strip pos-member-strip--empty" v-else>
<div class="pos-member-strip__main">
<div class="pos-member-strip__body">
<div class="user-logo">
<img src="images/head.png" alt="">
</div>
<div class="pos-member-strip__info">
<div class="user-name">请选择会员</div>
<div class="user-phone pos-member-strip-empty-tip">去结算前需选择会员;没有档案可先新建</div>
</div>
</div>
</div>
<div class="member-buttons pos-member-actions pos-member-strip-empty-actions">
<button type="button" class="logout-btn pos-member-action-btn" @click="openModal2">选择会员</button>
<button type="button" class="logout-btn pos-member-action-btn pos-member-action-btn--secondary" @click="openModal">新建会员</button>
</div>
</div>
<div class="pos-home-cart-scroll">
<div
class="product-container-list pos-cart-item"
v-for="(item, index) in addgoodlist"
:key="index"
:class="{ 'pos-cart-item--presale': item.isPresale }"
>
<div class="product-container">
<div class="product-left">
<div class="pos-cart-name-cluster">
<span v-if="item.isPresale" class="pos-cart-presale-badge">预售</span>
<span class="product-name">{{item.spmc}}</span>
</div>
<span
v-if="item.spxlhType"
:class="'serial-number-type-tag pos-cart-serial-type-tag ' + getSerialNumberTypeTagClass(item.spxlhType)"
>{{ getSerialNumberTypeText(item.spxlhType) }}</span>
</div>
<div class="product-right">
<span class="minus-icon" @click="decreaseQuantity(item,index)">-</span>
<span class="quantity">{{item.quantity}}</span>
<span class="plus-icon" @click="increaseQuantity(item,index)">+</span>
<img class="delete-icon" src="images/del.png" @click.stop="deleteProduct(index)" alt="删除" />
</div>
</div>
<div class="price-container">
<div class="pos-cart-price-row pos-cart-price-row--single-line">
<div class="pos-cart-price-inline">
<span class="pos-cart-muted">单价</span>
<span class="pos-cart-amount-line">¥{{ parseFloat(getItemUnitPrice(item) || 0).toFixed(2) }}</span>
</div>
<div class="pos-cart-price-inline">
<span class="pos-cart-muted">小计</span>
<span class="pos-cart-amount-line">¥{{ getItemLineSubtotal(item).toFixed(2) }}</span>
</div>
</div>
</div>
<!-- 序列号选择区域:预售商品不卡序列号,不显示 -->
<div v-if="item.spbm && !item.isPresale" class="pos-cart-serial-box">
<div v-if="item.selectedSerialNumbers && item.selectedSerialNumbers.length > 0" style="margin-bottom: 5px;">
<div style="font-size: 12px; color: #666; margin-bottom: 5px;">已选序列号 ({{ item.selectedSerialNumbers.length }}/{{ item.quantity }}):</div>
<div>
<span v-for="(sn, snIndex) in item.selectedSerialNumbers" :key="snIndex" class="selected-serial-tag" @click="removeSerialNumber(item, sn)">
{{ sn }} ×
</span>
</div>
</div>
<button
class="serial-number-select-btn"
@click="openSerialNumberSelect(item, index)"
:disabled="!item.spbm || !item.spxlhType"
>
选择序列号
</button>
</div>
</div>
</div>
<div class="amount-price-container">
<div class="left-info">
<div class="left-info-count">共计{{totalQuantity}}件</div>
<div>
<div class="gray-text">原价¥{{totalOriginalPrice}}</div>
<!-- <div class="red-text">优惠¥{{totalDiscount}}<img src="images/down.png" /></div> -->
</div>
</div>
<div class="right-info">
<div class="total-price">合计 <span class="red-text red-big">¥ {{totalFinalPrice}}</span>
</div>
</div>
</div>
</div>
<div class="right pos-home-right">
<div class="pos-home-right-main">
<!-- 商品分类 + 视图切换 -->
<div class="pos-home-category-row">
<div class="pos-category-toolbar">
<a href="#" class="pos-cat-arrow nav-arrow" @click.prevent="scrollCategory(-140)"><img src="images/left-arrow.png" alt="" /></a>
<div class="pos-category-scroll" ref="categoryScroll">
<a href="#" class="pos-category-pill" :class="ontype == item.id ? 'is-active' : ''"
@click.prevent="switchCategory(item.id)" v-for="(item,index) in wtpl" :key="index">{{item.plmc}}</a>
</div>
<a href="#" class="pos-cat-arrow nav-arrow" @click.prevent="scrollCategory(140)"><img src="images/right-arrow.png" alt="" /></a>
</div>
<div class="pos-segmented" role="group" aria-label="商品视图">
<button type="button" class="pos-segmented__btn" :class="{ 'is-active': viewMode === 'product' }" @click="switchViewMode('product')">普通商品</button>
<button type="button" class="pos-segmented__btn" :class="{ 'is-active': viewMode === 'package' }" @click="switchViewMode('package')">套装</button>
</div>
</div>
<div class="search-bar pos-home-search">
<input v-model="keyword" type="text" placeholder="名称 / 条码 / 货号 / 简拼 · Tab">
<button type="button" class="query-button" @click="getGoodsList">查询</button>
</div>
<div class="right-list-box pos-home-product-grid">
<!-- ✅ 根据视图模式显示不同的内容 -->
<!-- 普通商品模式 -->
<div v-if="viewMode === 'product'" style="display: flex; flex-wrap: wrap; gap: 10px; width: 100%;">
<div class="right-product-container" style="width: calc(25% - 8px); min-width: 120px;" v-for="(item, index) in wtsp" :key="index"
@click="selectProduct(item)"
:class="{'out-of-stock': !item.mdkc || item.mdkc <= 0}">
<div class="right-product-img">
<img src="images/good.png" :alt="item.name">
</div>
<div class="right-product-info">
<div class="right-title-info">
<!-- <img class="right-promotion-tag" src="images/cu.png" /> -->
<span class="right-product-name">{{item.spmc || '暂无'}}</span>
</div>
<div class="right-price-info">
<div class="right-original-price">商品编码 : {{item.spbm || '暂无'}}</div>
<div class="right-original-price">本店库存 : {{item.mdkc || 0}}</div>
<!-- <div class="right-original-price">¥{{item.lsj}}</div>
<span class="right-discount-tag">{{item.discount}}</span> -->
<span class="right-discounted-price">¥{{item.lsj}}</span>
</div>
</div>
</div>
</div>
<!-- 套装商品模式 -->
<div v-else-if="viewMode === 'package'" style="display: flex; flex-wrap: wrap; gap: 10px; width: 100%;">
<div class="right-product-container" style="width: calc(25% - 8px); min-width: 120px;" v-for="(item, index) in wtsptz" :key="'package-' + index"
@click="selectPackage(item)">
<div class="right-product-img">
<img src="images/good.png" alt="套装">
</div>
<div class="right-product-info">
<div class="right-title-info">
<span class="right-product-name" style="color: #ff6b6b; font-weight: bold;">【套装】{{item.tzmc || '暂无'}}</span>
</div>
<div class="right-price-info">
<div class="right-original-price">商品数量 : {{getPackageTotalQuantity(item)}}件</div>
<span class="right-discounted-price">¥{{item.tzzj || '0.00'}}</span>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="right-bottom pos-home-settle-bar">
<div class="right-bottom-btn-box">
</div>
<button
type="button"
class="btn-js pos-home-btn-settle"
:disabled="!canSettle"
:aria-disabled="!canSettle"
:title="canSettle ? '结算 F11' : '请先选择商品'"
@click="settleOrder"
>结算 F11</button>
</div>
</div>
</div>
</div>
<script>
var app = new Vue({
el: '#app',
data: {
selectedStore: localStorage.getItem('selectedStore')?JSON.parse(localStorage.getItem('selectedStore')): {},
hyinfo: null, // ✅ 初始化为 null,在 created() 中根据情况决定是否从 localStorage 读取
memberPoints: 0, // 会员积分(从 wtHyJf 汇总)
memberBalance: '0', // 会员余额(从储值消费明细汇总)
memberFormSrc: 'from.html', // ✅ iframe源地址
// ✅ 动态 API 配置:根据当前环境自动切换
// 开发环境:http://localhost:8888 -> http://localhost:2015
// 生产环境:https://www.ponggame.cn -> https://www.ponggame.cn/api
baseUrl: (() => {
const currentOrigin = window.location.origin;
// 判断当前环境
if (currentOrigin.includes('localhost') || currentOrigin.includes('127.0.0.1')) {
// 开发环境
return 'http://localhost:2011';
} else {
// 生产环境 - 替换域名为API域名(如果不同)
// 如果API和前端在同一域名,直接使用当前域名
// 如果不同,需要配置具体的API地址
return currentOrigin.replace(/:\d+$/, ''); // 移除端口号
}
})(),
wtpl: [],
wtsp: [],
keyword: '',
// ✅ 套装相关字段
viewMode: 'product', // 显示模式:'product' 普通商品 或 'package' 套装
wtsptz: [], // 套装列表
isModalOpen2: false,
memberSearch: '',
members: [
// { name: '曹', phone: '18512345123', id: 1 },
// 可以添加更多会员信息
],
filteredMembers: [],
/** 选择会员弹窗:最近一次查询是否无结果(用于展示「新建会员」引导) */
memberSearchNoResult: false,
ontype: '0',
message: 'Hello Vue!',
addgoodlist: [],
goodlist: [{
name: '啤酒1',
price: '4.00',
discount: '8折',
discountPrice: '4.00',
originalPrice: '4.50',
discountInfo: '优惠¥1.00',
img: 'images/1.png',
},
{
name: '啤酒2',
price: '4.00',
discount: '8折',
discountPrice: '4.00',
originalPrice: '4.50',
discountInfo: '优惠¥1.00',
img: 'images/1.png',
},
],
isModalOpen: false,
posToastMessage: '',
posToastTimer: null,
// 序列号选择相关
isSerialNumberModalOpen: false,
serialNumberSearchForm: {
productCode: '',
warehouse: '',
serialNumber: ''
},
serialNumberList: [],
selectedSerialNumbersForModal: [],
manualSerialNumberInput: '',
warehouseOptions: [],
currentSerialNumberItem: null,
currentSerialNumberItemIndex: -1,
productCache: {}, // 商品信息缓存(包含序列号类型)
issueCouponModalOpen: false,
issueCouponTemplates: [],
issueSelectedTemplateId: '',
issueCount: 1,
issueLoading: false
},
// 添加计算属性
computed: {
/** 顶栏标题:登录所选门店名称 + 收银台 */
posCashierHeaderTitle() {
try {
var raw = localStorage.getItem('selectedStore');
if (raw) {
var s = JSON.parse(raw);
var name = String(s.mdmc || s.Mdmc || s.name || '').trim();
if (name) {
var withDian = name.lastIndexOf('店') === name.length - 1 ? name : (name + '店');
return withDian + '收银台';
}
}
} catch (e) {}
return '收银台';
},
// 入0出1:仅手动输入序列号
isSerialNumberModalR0C1() {
return this.currentSerialNumberItem && this.currentSerialNumberItem.spxlhType === '2';
},
// 入1出1:强制从表格选择序列号
isSerialNumberModalR1C1() {
return this.currentSerialNumberItem && this.currentSerialNumberItem.spxlhType === '1';
},
// 其他类型(如入0出0):同时显示手动输入和表格
isSerialNumberModalShowBoth() {
var t = this.currentSerialNumberItem && this.currentSerialNumberItem.spxlhType;
return t && t !== '1' && t !== '2';
},
/** 多权益卡列表(含详情接口 kjqyList;无则主档 kjqyId 兜底一行) */
memberBenefitCardsDisplay() {
if (!this.hyinfo) return [];
var rows = this.hyinfo.kjqyList;
var out = [];
var that = this;
if (Array.isArray(rows) && rows.length) {
rows.forEach(function (c, idx) {
var name = (c.kjmc || c.Kjmc || '').trim() || '权益卡';
var exp = c.dqsj || c.Dqsj;
var expired = false;
var expireText = '有效期未设置';
if (exp) {
var d = new Date(exp);
expired = d < new Date();
var s = that.formatMemberYmd(d);
expireText = expired ? ('已于 ' + s + ' 到期') : ('至 ' + s + ' 有效');
}
out.push({
key: String(c.id || c.kjqyId || idx) + '_' + idx,
name: name,
expireText: expireText,
expired: expired
});
});
return out;
}
var id = this.hyinfo.kjqyId || this.hyinfo.F_KjqyId;
if (!id) return [];
var mc = (this.hyinfo.kjqyMc || '').trim() || '权益卡';
var exp = this.hyinfo.hydjExpire || this.hyinfo.F_HydjExpire;
var expired = false;
var expireText = '有效期未设置';
if (exp) {
var d2 = new Date(exp);
expired = d2 < new Date();
var s2 = this.formatMemberYmd(d2);
expireText = expired ? ('已于 ' + s2 + ' 到期') : ('至 ' + s2 + ' 有效');
}
return [{ key: 'fallback', name: mc, expireText: expireText, expired: expired }];
},
/** 会员等级(与后端 GetInfo 一致:到期后视为普通会员) */
memberLevel() {
if (!this.hyinfo) return '普通会员';
var level = this.hyinfo.hydj || this.hyinfo.F_Hydj || '普通会员';
var expire = this.hyinfo.hydjExpire || this.hyinfo.F_HydjExpire;
if (expire && new Date(expire) < new Date()) return '普通会员';
return level;
},
memberLevelBadgeStyle() {
var lv = this.memberLevel || '普通会员';
var base = {
padding: '2px 8px',
borderRadius: '8px',
fontSize: '11px',
marginLeft: '0',
fontWeight: '600',
verticalAlign: 'middle',
lineHeight: '1.3',
boxSizing: 'border-box',
maxWidth: '100%',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
display: 'inline-block'
};
if (lv === '至尊会员') {
return Object.assign({}, base, { background: '#E6A23C', color: '#fff' });
}
if (lv === '普通会员') {
return Object.assign({}, base, {
background: '#f1f5f9',
color: '#64748b',
border: '1px solid #e2e8f0'
});
}
return Object.assign({}, base, { background: '#409EFF', color: '#fff' });
},
totalQuantity() {
return this.addgoodlist.reduce((sum, item) => sum + item.quantity, 0);
},
totalOriginalPrice() {
return this.addgoodlist.reduce((sum, item) => sum + ((item.originalPrice || item.lsj) * item
.quantity), 0).toFixed(2);
},
totalDiscount() {
return (this.totalOriginalPrice - this.totalFinalPrice).toFixed(2);
},
totalFinalPrice() {
var that = this;
return this.addgoodlist.reduce(function (sum, item) {
return sum + that.getItemLineSubtotal(item);
}, 0).toFixed(2);
},
/** 购物车有商品时才允许点结算(与 settleOrder 首段校验一致) */
canSettle() {
return Array.isArray(this.addgoodlist) && this.addgoodlist.length > 0;
}
},
created() {
const token = localStorage.getItem('token');
if (!token) {
window.location.href = 'login.html';
}
// ✅ 检查是否从登录页跳转过来
const urlParams = new URLSearchParams(window.location.search);
const fromLogin = urlParams.get('fromLogin');
if (fromLogin === 'true') {
// 从登录页跳转过来,清除客户信息
localStorage.removeItem('hyinfo');
this.hyinfo = null;
// 清除 URL 参数,避免刷新时重复清除
window.history.replaceState({}, '', window.location.pathname);
} else {
// 从其他页面返回,恢复客户信息(如果存在)
if(localStorage.getItem('hyinfo')){
this.hyinfo = JSON.parse(localStorage.getItem('hyinfo'));
this.fetchMemberPoints();
}
}
this.gain();
// ✅ 预加载套装(无门店时不请求、不提示,避免打扰)
this.loadPackages(true);
// 加载仓库选项
this.getWarehouseOptions();
// // this.filteredMembers = this.members;
// // 在组件创建时获取当前时间
// this.updateCurrentTime();
// // 每秒更新一次时间
// setInterval(() => {
// this.updateCurrentTime();
// }, 1000);
},
mounted() {
// 监听 message 事件
window.addEventListener('message', this.handleMessage, false);
},
beforeDestroy() {
// 移除事件监听器
window.removeEventListener('message', this.handleMessage, false);
if (this.posToastTimer) {
clearTimeout(this.posToastTimer);
this.posToastTimer = null;
}
},
methods: {
showPosToast(msg) {
var text = msg != null ? String(msg) : '';
var that = this;
if (this.posToastTimer) {
clearTimeout(this.posToastTimer);
this.posToastTimer = null;
}
this.posToastMessage = text;
if (!text) {
return;
}
this.posToastTimer = setTimeout(function () {
that.posToastMessage = '';
that.posToastTimer = null;
}, 10000);
},
clearPosToast() {
if (this.posToastTimer) {
clearTimeout(this.posToastTimer);
this.posToastTimer = null;
}
this.posToastMessage = '';
},
/**
* 商品会员限购校验(单品点击、套装子商品加入购物车共用)。
* @returns {boolean} 允许加入为 true
*/
checkMemberRestrictionForProduct(item) {
if (!item || !item.hyxz || !String(item.hyxz).trim()) {
return true;
}
var allowedIds = item.hyxz.split(',').map(function (s) { return s.trim(); }).filter(Boolean);
var isCardIdFormat = allowedIds.length > 0 && allowedIds.every(function (id) {
return id.length > 10 && /^\d+$/.test(id);
});
var displayNames = item.hyxzDisplay || item.hyxz;
if (isCardIdFormat) {
var memberLevel = this.hyinfo && (this.hyinfo.hydj || this.hyinfo.F_Hydj || '普通会员');
var hyxzLevels = item.hyxzLevels || [];
var levelMatch = hyxzLevels.length > 0 && memberLevel && hyxzLevels.indexOf(memberLevel) >= 0;
var cardMatch = false;
var list = this.hyinfo && this.hyinfo.kjqyList;
if (Array.isArray(list) && list.length) {
cardMatch = list.some(function (c) {
var cid = c.kjqyId || c.KjqyId;
if (!cid || allowedIds.indexOf(cid) < 0) return false;
var dq = c.dqsj || c.Dqsj;
if (dq && new Date(dq) < new Date()) return false;
return true;
});
}
if (!cardMatch && this.hyinfo) {
var mid = this.hyinfo.kjqyId || this.hyinfo.F_KjqyId;
if (mid && allowedIds.indexOf(mid) >= 0) {
var exp = this.hyinfo.hydjExpire || this.hyinfo.F_HydjExpire;
cardMatch = !exp || new Date(exp) >= new Date();
}
}
if (!cardMatch && !levelMatch) {
var hasCard = this.hyinfo && (
(this.hyinfo.kjqyList && this.hyinfo.kjqyList.length) ||
this.hyinfo.kjqyId || this.hyinfo.F_KjqyId
);
this.showPosToast(
'该商品仅限 ' + displayNames + ' 会员购买' +
(!this.hyinfo ? ',请先登录会员' : (!hasCard ? ',您尚未开卡' : ',当前权益卡不符或已过期'))
);
return false;
}
} else {
var memberLevel2 = '';
if (this.hyinfo) {
memberLevel2 = this.hyinfo.hydj || this.hyinfo.F_Hydj || '普通会员';
if (this.hyinfo.hydjExpire || this.hyinfo.F_HydjExpire) {
var expire = new Date(this.hyinfo.hydjExpire || this.hyinfo.F_HydjExpire);
if (expire < new Date()) {
memberLevel2 = '普通会员';
}
}
}
if (!memberLevel2 || allowedIds.indexOf(memberLevel2) === -1) {
this.showPosToast(
'该商品仅限 ' + displayNames + ' 会员购买' +
(memberLevel2 ? ',您当前等级为 ' + memberLevel2 : ',请先登录会员')
);
return false;
}
}
return true;
},
scrollCategory(delta) {
var el = this.$refs.categoryScroll;
if (!el) return;
el.scrollBy({ left: delta, behavior: 'smooth' });
},
/**
* 套装明细里同一商品可能多行:汇总每套装所需件数。
*/
getPackageReqPerSet(pkgItems, spId) {
if (!pkgItems || !pkgItems.length) {
return 1;
}
var sum = 0;
for (var i = 0; i < pkgItems.length; i++) {
if (pkgItems[i].spbh !== spId) {
continue;
}
var q = parseInt(pkgItems[i].spsl, 10);
if (!isNaN(q) && q > 0) {
sum += q;
}
}
return sum > 0 ? sum : 1;
},
/**
* 套装档案明细里该子商品的「零售价」:按行折合为每件单价(行价÷该行 spsl),多行同 spbh 时累加。
* 若该行未维护 lsj(null/undefined)则跳过该行;若整单无可用行价则返回 null,由按比例分摊兜底。
* 套餐整单改价时按 modifiedPackagePrice/packagePrice 缩放。
*/
getPackageDetailRowUnitPrice(item, lineList) {
var lines = lineList || this.addgoodlist;
if (!item.isPackageItem || !item.packageId) {
return null;
}
var pkgItems = item.packageItems;
if (!pkgItems || !pkgItems.length) {
var z = lines.find(function (x) {
return x.isPackageItem && x.packageId === item.packageId && x.packageItems && x.packageItems.length;
});
if (z) {
pkgItems = z.packageItems;
}
}
if (!pkgItems || !pkgItems.length) {
return null;
}
var rows = pkgItems.filter(function (p) {
return p.spbh === item.id;
});
if (!rows.length) {
return null;
}
var sum = 0;
var hasExplicit = false;
for (var i = 0; i < rows.length; i++) {
var mx = rows[i];
if (mx.lsj === null || mx.lsj === undefined) {
continue;
}
hasExplicit = true;
var sp = parseInt(mx.spsl, 10);
if (isNaN(sp) || sp < 1) {
sp = 1;
}
var v = parseFloat(mx.lsj);
if (isNaN(v)) {
v = 0;
}
sum += v / sp;
}
if (!hasExplicit) {
return null;
}
var orig = parseFloat(item.packagePrice);
if (item.modifiedPackagePrice !== null && item.modifiedPackagePrice !== undefined) {
var mod = parseFloat(item.modifiedPackagePrice);
if (!isNaN(orig) && orig > 0 && !isNaN(mod)) {
sum = sum * (mod / orig);
}
}
return sum;
},
/**
* 按套装档案总价(tzzj)在子商品间按「门店零售价×套装内数量」比例分摊,得到本行单价(明细无行价时兜底)。
* 数量不同步导致无法凑整套时返回 null,回退为单品 lsj。
* @param {object} item 购物车行
* @param {Array} [lineList] 可选,默认 this.addgoodlist(结算页传 addgoodlist)
*/
getAllocatedPackageUnitPrice(item, lineList) {
var lines = lineList || this.addgoodlist;
if (!item.isPackageItem || !item.packageId) {
return null;
}
if (item.packagePrice === null || item.packagePrice === undefined || item.packagePrice === '') {
return null;
}
var pkgItems = item.packageItems;
if (!pkgItems || !pkgItems.length) {
var z = lines.find(function (x) {
return x.isPackageItem && x.packageId === item.packageId && x.packageItems && x.packageItems.length;
});
if (z) {
pkgItems = z.packageItems;
}
}
if (!pkgItems || !pkgItems.length) {
return null;
}
var pid = item.packageId;
var group = lines.filter(function (x) {
return x.isPackageItem && x.packageId === pid;
});
var setCandidates = [];
for (var pi = 0; pi < pkgItems.length; pi++) {
var spid = pkgItems[pi].spbh;
var req = this.getPackageReqPerSet(pkgItems, spid);
var line = group.find(function (g) {
return g.id === spid;
});
if (!line || !req) {
setCandidates.push(0);
} else {
setCandidates.push(Math.floor((parseFloat(line.quantity) || 0) / req));
}
}
var sets = setCandidates.length ? Math.min.apply(null, setCandidates) : 0;
if (sets < 1) {
return null;
}
var pkgPrice = parseFloat(item.packagePrice);
if (item.modifiedPackagePrice !== null && item.modifiedPackagePrice !== undefined) {
pkgPrice = parseFloat(item.modifiedPackagePrice);
}
if (isNaN(pkgPrice)) {
pkgPrice = 0;
}
var sumW = 0;
var wi = 0;
var gi;
for (gi = 0; gi < group.length; gi++) {
var gline = group[gi];
var reqG = this.getPackageReqPerSet(pkgItems, gline.id);
var lsjg = parseFloat(gline.lsj || 0);
var w = lsjg * reqG;
sumW += w;
if (gline.id === item.id) {
wi = w;
}
}
var reqI = this.getPackageReqPerSet(pkgItems, item.id);
if (reqI <= 0) {
reqI = 1;
}
var sharePerSet;
if (sumW > 0) {
sharePerSet = pkgPrice * (wi / sumW);
} else {
var n = group.length || 1;
sharePerSet = pkgPrice / n;
}
return sharePerSet / reqI;
},
/** 当前行单价:优先套装明细行价 → 再按比例分摊 → 门店零售价 */
getItemUnitPrice(item) {
if (item.modifiedPrice !== null && item.modifiedPrice !== undefined) {
return parseFloat(item.modifiedPrice || 0);
}
var detailU = this.getPackageDetailRowUnitPrice(item);
if (detailU !== null && !isNaN(detailU)) {
return detailU;
}
var packUnit = this.getAllocatedPackageUnitPrice(item);
if (packUnit !== null && !isNaN(packUnit)) {
return packUnit;
}
return parseFloat(item.lsj || 0);
},
getItemLineSubtotal(item) {
return this.getItemUnitPrice(item) * (parseFloat(item.quantity) || 0);
},
handleMessage(event) {
if (event.data.type === 'formSubmitted') {
this.showPosToast('添加成功');
this.closeModal();
var payload = event.data.data;
if (payload && payload.sjh) {
this.applyCreatedMemberAndSelect(payload);
}
}
if (event.data.type === 'formSubmittedclose') {
this.closeModal();
}
},
formatMemberYmd(d) {
if (!d || !(d instanceof Date) || isNaN(d.getTime())) return '';
var pad = function (n) { return n < 10 ? '0' + n : '' + n; };
return d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate());
},
tuic() {
localStorage.removeItem('hyinfo');
this.hyinfo = null;
this.memberPoints = 0;
this.memberBalance = '0';
},
// 从 wtHyJf 获取会员真实积分(调用会员详情接口,后端已汇总积分)
fetchMemberPoints() {
const memberId = this.hyinfo && (this.hyinfo.id || this.hyinfo.F_Id);
if (!memberId) {
this.memberPoints = 0;
this.memberBalance = '0';
return;
}
axios({
url: this.baseUrl + '/api/Extend/wthy/' + memberId,
method: 'GET',
headers: { Authorization: localStorage.getItem('token') }
}).then(res => {
if (res.data && res.data.code == 200 && res.data.data) {
this.memberPoints = parseInt(res.data.data.jf, 10) || 0;
if (res.data.data.hydj) this.hyinfo.hydj = res.data.data.hydj;
if (res.data.data.hydjExpire) this.hyinfo.hydjExpire = res.data.data.hydjExpire;
if (res.data.data.kjqyId != null) this.hyinfo.kjqyId = res.data.data.kjqyId;
if (res.data.data.kjqyMc != null) this.hyinfo.kjqyMc = res.data.data.kjqyMc;
if (Array.isArray(res.data.data.kjqyList)) {
this.$set(this.hyinfo, 'kjqyList', res.data.data.kjqyList);
}
if (res.data.data.ye != null) this.hyinfo.ye = res.data.data.ye;
if (res.data.data.jf != null) this.hyinfo.jf = res.data.data.jf;
this.memberBalance = (res.data.data.ye != null && res.data.data.ye !== '') ? res.data.data.ye : '0';
localStorage.setItem('hyinfo', JSON.stringify(this.hyinfo));
} else {
this.memberPoints = 0;
this.memberBalance = '0';
}
}).catch(() => {
this.memberPoints = 0;
this.memberBalance = '0';
});
},
gohyinfo() {
localStorage.setItem('hyinfo', JSON.stringify(this.hyinfo));
if (this.hyinfo && this.hyinfo.sjh) {
window.location.href = `orders.html?sjh=${this.hyinfo.sjh}`;
} else {
this.showPosToast('请先选择会员');
}
},
openModal2() {
this.memberSearchNoResult = false;
this.isModalOpen2 = true;
},
closeModal2() {
this.isModalOpen2 = false;
},
/** 选择会员弹窗内打开新建(与顶部 iframe 联通) */
openModalFromPicker() {
this.openModal();
},
/**
* 新建会员提交成功后:按手机号拉取完整档案(含 id),再写入 hyinfo,供结算页使用。
*/
applyCreatedMemberAndSelect(formRow) {
var that = this;
var sjh = (formRow && formRow.sjh) ? String(formRow.sjh).trim() : '';
if (!sjh) {
return;
}
axios({
url: that.baseUrl + '/api/Extend/wthy',
method: 'GET',
headers: { Authorization: localStorage.getItem('token') },
params: { keyword: sjh }
}).then(function (res) {
if (res.data && res.data.code == 200 && res.data.data && res.data.data.list && res.data.data.list.length > 0) {
that.selectMember2(res.data.data.list[0]);
} else {
that.showPosToast('会员已创建,请在「选择会员」中输入手机号再次查询');
that.memberSearch = sjh;
that.openModal2();
}
}).catch(function () {
that.showPosToast('会员已创建,请在「选择会员」中输入手机号再次查询');
that.memberSearch = sjh;
that.openModal2();
});
},
searchMembers2() {
var that = this;
this.memberSearchNoResult = false;
if (!this.memberSearch.trim()) {
this.showPosToast('请输入手机号码');
return;
}
console.log('搜索会员:', this.memberSearch);
axios({
url: that.baseUrl + "/api/Extend/wthy",
method: 'GET',
headers: {
Authorization: localStorage.getItem('token')
},
params: {
"keyword": this.memberSearch
}
}).then((res) => {
console.log('会员查询响应:', res);
if (res.data.code == 200) {
this.filteredMembers = res.data.data.list || [];
this.memberSearchNoResult = this.filteredMembers.length === 0;
} else {
this.filteredMembers = [];
this.memberSearchNoResult = true;
this.showPosToast('查询失败: ' + (res.data.msg || '未知错误'));
}
}).catch((error) => {
console.error('会员查询错误:', error);
this.filteredMembers = [];
this.memberSearchNoResult = true;
this.showPosToast('查询出错: ' + error.message);
});
},
selectMember2(member) {
this.hyinfo = member;
localStorage.setItem('hyinfo', JSON.stringify(member));
this.memberSearchNoResult = false;
this.fetchMemberPoints();
this.closeModal2();
},
openIssueCouponModal() {
if (!this.hyinfo) {
this.showPosToast('请先选择会员');
return;
}
this.issueCouponModalOpen = true;
this.issueLoading = true;
var that = this;
axios({
url: this.baseUrl + '/api/Extend/WtYhqMb',
method: 'GET',
headers: {
Authorization: localStorage.getItem('token')
},
params: {
currentPage: 1,
pageSize: 100,
sort: 'desc',
sidx: '',
zt: '启用'
}
}).then(function (res) {
that.issueLoading = false;
if (res.data && res.data.code == 200 && res.data.data) {
that.issueCouponTemplates = res.data.data.list || [];
if (that.issueCouponTemplates.length > 0) {
that.issueSelectedTemplateId = that.issueCouponTemplates[0].id;
}
} else {
that.issueCouponTemplates = [];
that.showPosToast('加载优惠券模板失败');
}
}).catch(function (e) {
that.issueLoading = false;
that.issueCouponTemplates = [];
console.error('加载优惠券模板失败', e);
that.showPosToast('加载优惠券模板失败');
});
},
confirmIssueCoupon() {
if (!this.hyinfo) {
this.showPosToast('请先选择会员');
return;
}
var memberId = this.hyinfo.id || this.hyinfo.F_Id;
if (!memberId) {
this.showPosToast('会员信息不完整');
return;
}
if (!this.issueSelectedTemplateId) {
this.showPosToast('请选择优惠券模板');
return;
}
var count = this.issueCount || 1;
if (count <= 0) count = 1;
var that = this;
this.issueLoading = true;
axios({
url: this.baseUrl + '/api/Extend/WtYhq/Issue',
method: 'POST',
headers: {
Authorization: localStorage.getItem('token')
},
data: {
MbId: this.issueSelectedTemplateId,
HyId: memberId,
Count: count
}
}).then(function (res) {
that.issueLoading = false;
if (res.data && res.data.code == 200) {
that.showPosToast(res.data.msg || '赠送成功');
that.issueCouponModalOpen = false;
} else {
that.showPosToast(res.data.msg || '赠送失败');
}
}).catch(function (e) {
that.issueLoading = false;
console.error('赠送优惠券失败', e);
that.showPosToast('赠送优惠券失败: ' + e.message);
});
},
gain() {
var that = this
axios({
url: that.baseUrl + "/api/Extend/wtpl?sfmdfl=1",
method: 'GET',
headers: {
Authorization: localStorage.getItem('token')
},
}).then((res) => {
console.error(res)
if (res.data.code == 200) {
that.wtpl = res.data.data.list
if (that.wtpl.length > 0) {
that.ontype = that.wtpl[0].id
that.getGoodsList()
}
} else {
window.location.href = 'login.html';
}
})
},
/** 收银拉取商品档案用的门店主键:与分组可售、库存一致(含 localStorage 与 ckinfo 降级) */
getPosXsmdForQuery() {
return this.getSelectedStoreId() || (this.selectedStore && this.selectedStore.id) || localStorage.getItem('mdId') || ''
},
getGoodsList() {
var that = this
var xsmdForQuery = this.getPosXsmdForQuery()
if (!xsmdForQuery) {
this.showPosToast('请先选择登录门店后再加载商品(未传门店时会列出全部门店可售商品)')
this.wtsp = []
return
}
console.error(this.selectedStore)
if (this.keyword) {
axios({
url: that.baseUrl + "/api/Extend/wtsp/GetListByKeyword",
method: 'GET',
headers: {
Authorization: localStorage.getItem('token')
},
params: {
keyword: that.keyword,
xsmd: xsmdForQuery,
currentPage: 1,
pageSize: 500
}
}).then((res) => {
console.error(res)
if (res.data.code == 200) {
that.wtsp = res.data.data.list
} else {
}
})
// axios({
// url: that.baseUrl + "/api/Extend/wtsp",
// method: 'GET',
// headers: {
// Authorization: localStorage.getItem('token')
// },
// params: {
// keyword: that.keyword,
// pl: that.ontype,
// xsmd: this.selectedStore.id || mdId
// }
// }).then((res) => {
// console.error(res)
// if (res.data.code == 200) {
// that.wtsp = res.data.data.list
// } else {
// }
// })
} else {
axios({
url: that.baseUrl + "/api/Extend/wtsp",
method: 'GET',
headers: {
Authorization: localStorage.getItem('token')
},
params: {
keyword: that.keyword,
pl: that.ontype,
xsmd: xsmdForQuery,
currentPage: 1,
pageSize: 500
}
}).then((res) => {
console.error(res)
if (res.data.code == 200) {
that.wtsp = res.data.data.list
} else {
}
})
}
},
// 添加结算方法
settleOrder() {
if (!this.addgoodlist.length) {
this.showPosToast('请选择商品')
return
}
if (!this.hyinfo) {
this.showPosToast('请选择会员')
return
}
// 验证序列号选择:预售商品不卡序列号;有货商品若序列号类型为入1出1/入0出1,则必须选择序列号
const validationErrors = [];
for (let i = 0; i < this.addgoodlist.length; i++) {
const item = this.addgoodlist[i];
if (item.isPresale) continue; // 预售商品不校验序列号
if (item.spxlhType === '1' || item.spxlhType === '2') {
if (!item.selectedSerialNumbers || item.selectedSerialNumbers.length === 0) {
validationErrors.push(`商品"${item.spmc || item.spbm}"需要选择序列号`);
} else if (item.selectedSerialNumbers.length !== item.quantity) {
validationErrors.push(`商品"${item.spmc || item.spbm}"的数量(${item.quantity})与已选择的序列号数量(${item.selectedSerialNumbers.length})不一致`);
}
}
}
if (validationErrors.length > 0) {
const message = '结算失败,请检查以下问题:\n\n' +
validationErrors.map(e => '- ' + e).join('\n') +
'\n\n提示:序列号类型为"入1出1"或"入0出1"的商品必须选择序列号,且数量需一致。';
this.showPosToast(message);
return;
}
// 将 addgoodlist 缓存到本地存储
localStorage.setItem('addgoodlist', JSON.stringify(this.addgoodlist));
localStorage.setItem('hyinfo', JSON.stringify(this.hyinfo));
// 跳转到 settlement.html 页面
window.location.href = 'settlement.html';
},
selectProduct(item) {
console.log('选中的商品是:', item);
if (!this.checkMemberRestrictionForProduct(item)) {
return;
}
const mdkcNum = parseFloat(item.mdkc);
const isPresale = !item.mdkc ||
item.mdkc === 0 ||
item.mdkc === '0' ||
isNaN(mdkcNum) ||
mdkcNum <= 0;
// ✅ 如果是预售商品,先给出“确认 / 取消”选择
if (isPresale) {
const confirmPresale = window.confirm('该商品库存不足,将作为预售商品处理,是否继续?');
if (!confirmPresale) {
// 用户点击“取消”,不加入购物车
return;
}
}
const existingItem = this.addgoodlist.find((listItem) => listItem.id === item.id);
if (existingItem) {
if (item.mdkc !== undefined && item.mdkc !== null) {
existingItem.mdkc = item.mdkc;
}
existingItem.quantity += 1;
const idx = this.addgoodlist.indexOf(existingItem);
if (!(existingItem.isPackageItem && existingItem.packageId)) {
if (!existingItem.isPresale && this.parseMdkcNumber(existingItem.mdkc) > 0 &&
existingItem.quantity > this.parseMdkcNumber(existingItem.mdkc)) {
if (!this.splitLineIfStockInsufficient(existingItem, idx)) {
existingItem.quantity -= 1;
return;
}
}
}
// 如果之前不是预售,这次又判定为预售,则补上标记
if (isPresale) {
existingItem.isPresale = true;
console.log(`✅ 商品 ${item.spmc || item.spbm} 标记为预售,库存: ${item.mdkc}`);
}
} else {
const newItem = {
quantity: 1,
isPresale: isPresale, // 标记是否为预售商品
selectedSerialNumbers: [], // 初始化序列号数组
...item
};
this.addgoodlist.push(newItem);
if (isPresale) {
console.log(`✅ 新商品 ${newItem.spmc || newItem.spbm} 标记为预售,库存: ${newItem.mdkc}, isPresale=${newItem.isPresale}`);
}
// 加载商品序列号类型
if (newItem.id || newItem.spbm) {
this.loadProductSerialNumberType(newItem);
}
}
},
// 加载商品序列号类型
async loadProductSerialNumberType(item) {
// 优先使用已有的id,如果没有则通过spbm查询
let productId = item.id;
const cacheKey = item.id || item.spbm;
if (!productId && item.spbm) {
// 通过商品编码查询商品档案获取商品编号
try {
const posXsmd = this.getPosXsmdForQuery()
const response = await axios({
url: this.baseUrl + '/api/Extend/wtsp/GetListByKeyword',
method: 'GET',
headers: {
Authorization: localStorage.getItem('token')
},
params: {
keyword: item.spbm,
xsmd: posXsmd || undefined,
currentPage: 1,
pageSize: 1
}
});
let prodRows = null;
const d = response.data.data;
if (d && d.list && d.list.length) prodRows = d.list;
else if (Array.isArray(d) && d.length) prodRows = d;
if (response.data.code === 200 && prodRows && prodRows.length > 0) {
const product = prodRows[0];
productId = product.id; // 获取商品编号(F_Id)
item.id = productId; // 更新item的id
console.log('通过商品编码获取商品编号:', item.spbm, '->', productId);
} else {
console.warn('未找到商品档案:', item.spbm);
return;
}
} catch (error) {
console.error('查询商品档案失败:', error);
return;
}
}
if (!productId) return;
const key = String(productId);
// 检查缓存(使用商品编号作为key)
if (this.productCache[key]) {
item.spxlhType = this.productCache[key].spxlhType;
return;
}
try {
// 使用商品编号(F_Id)查询商品详情
const response = await axios({
url: this.baseUrl + '/api/Extend/WtSp/' + key,
method: 'GET',
headers: {
Authorization: localStorage.getItem('token')
}
});
if (response.data.code === 200 && response.data.data) {
const product = response.data.data;
product.spxlhType = String(product.spxlhType || '');
this.productCache[key] = product;
item.spxlhType = product.spxlhType;
console.log('商品序列号类型加载成功:', key, product.spxlhType);
}
} catch (error) {
console.error('加载商品序列号类型失败:', error);
}
},
// 获取序列号类型显示文本
getSerialNumberTypeText(spxlhType) {
if (!spxlhType) return '';
if (spxlhType === '1') return '入1出1';
if (spxlhType === '2') return '入0出1';
if (spxlhType === '3') return '入0出0';
return spxlhType;
},
// 获取序列号类型标签样式类
getSerialNumberTypeTagClass(spxlhType) {
if (!spxlhType) return 'info';
if (spxlhType === '1' || spxlhType === '2') return 'warning'; // 需要序列号
if (spxlhType === '3') return 'success'; // 不需要序列号
return 'info';
},
// 打开序列号选择弹窗
async openSerialNumberSelect(item, index) {
// 预售商品不卡序列号,不需要弹出序列号提示
if (item.isPresale) {
return;
}
console.log('🔓 打开序列号选择弹窗');
console.log('📦 商品信息:', {
id: item.id,
spbm: item.spbm,
spmc: item.spmc,
quantity: item.quantity,
spxlhType: item.spxlhType
});
if (!item.spbm) {
console.error('❌ 商品编码不存在');
this.showPosToast('商品编码不存在,无法选择序列号');
return;
}
// 先通过商品编码查询商品档案,获取商品编号(F_Id)
let productId = item.id; // 尝试使用已有的id
if (!productId) {
console.log('🔍 商品没有id,通过商品编码查询商品档案...');
try {
const queryUrl = this.baseUrl + '/api/Extend/wtsp/GetListByKeyword';
console.log('🌐 查询商品档案URL:', queryUrl);
console.log('📤 查询参数:', {
keyword: item.spbm,
currentPage: 1,
pageSize: 1
});
const posXsmdSn = this.getPosXsmdForQuery()
const response = await axios({
url: queryUrl,
method: 'GET',
headers: {
Authorization: localStorage.getItem('token')
},
params: {
keyword: item.spbm,
xsmd: posXsmdSn || undefined,
currentPage: 1,
pageSize: 1
}
});
console.log('📥 商品档案查询响应:', response);
console.log('📥 响应数据:', response.data);
if (response.data.code === 200) {
// 处理不同的响应格式
let productList = null;
if (response.data.data && Array.isArray(response.data.data)) {
productList = response.data.data;
} else if (response.data.data && response.data.data.list) {
productList = response.data.data.list;
} else if (response.data.data && response.data.data.pagination && response.data.data.pagination.list) {
productList = response.data.data.pagination.list;
} else if (Array.isArray(response.data.data)) {
productList = response.data.data;
}
if (productList && productList.length > 0) {
const product = productList[0];
productId = product.id || product.F_Id; // 获取商品编号(F_Id)
// 更新item的id,避免下次重复查询
item.id = productId;
console.log('✅ 通过商品编码获取商品编号:', item.spbm, '->', productId);
console.log('📋 商品详情:', product);
} else {
console.error('❌ 未找到对应的商品档案');
this.showPosToast('未找到对应的商品档案,无法选择序列号');
return;
}
} else {
console.error('❌ 商品档案查询失败,响应码:', response.data.code);
this.showPosToast('查询商品档案失败: ' + (response.data.msg || '未知错误'));
return;
}
} catch (error) {
console.error('❌ 查询商品档案异常:', error);
console.error('❌ 错误详情:', {
message: error.message,
response: error.response,
responseData: error.response?.data
});
this.showPosToast('查询商品档案失败,无法选择序列号: ' + (error.response?.data?.message || error.message));
return;
}
} else {
console.log('✅ 使用已有的商品编号:', productId);
}
if (!productId) {
console.error('❌ 无法获取商品编号');
this.showPosToast('无法获取商品编号,无法选择序列号');
return;
}
this.currentSerialNumberItem = item;
this.currentSerialNumberItemIndex = index;
this.serialNumberSearchForm.productCode = productId; // 使用商品编号(F_Id)而不是商品编码(spbm)
// ✅ 确保仓库选项已加载
if (!this.warehouseOptions || this.warehouseOptions.length === 0) {
await this.getWarehouseOptions();
}
// ✅ 自动设置仓库为当前门店对应的仓库,确保与库存显示一致
const selectedStoreId = this.getSelectedStoreId();
if (selectedStoreId) {
const warehouseId = await this.getWarehouseIdByStoreId(selectedStoreId);
if (warehouseId) {
// ✅ 查找仓库选项列表中匹配的仓库(支持 id 和 F_Id 两种格式)
const matchedWarehouse = this.warehouseOptions.find(wh =>
wh.id === warehouseId || wh.F_Id === warehouseId || wh.Id === warehouseId
);
if (matchedWarehouse) {
// 使用仓库选项中的 F_Id(与下拉框格式一致)
this.serialNumberSearchForm.warehouse = matchedWarehouse.F_Id || matchedWarehouse.id || matchedWarehouse.Id || warehouseId;
console.log('✅ 自动设置序列号查询仓库为当前门店对应的仓库:', this.serialNumberSearchForm.warehouse);
} else {
// 如果找不到匹配的,直接使用 warehouseId(可能是 F_Id 格式)
this.serialNumberSearchForm.warehouse = warehouseId;
console.log('✅ 自动设置序列号查询仓库(未在选项中找到匹配):', warehouseId);
}
} else {
console.warn('⚠️ 未找到门店对应的仓库,序列号查询将使用全部仓库');
this.serialNumberSearchForm.warehouse = '';
}
} else {
console.warn('⚠️ 未找到选择的门店,序列号查询将使用全部仓库');
this.serialNumberSearchForm.warehouse = '';
}
this.serialNumberSearchForm.serialNumber = '';
this.selectedSerialNumbersForModal = item.selectedSerialNumbers ? [...item.selectedSerialNumbers] : [];
this.isSerialNumberModalOpen = true;
// ✅ 使用 nextTick 确保 Vue 已更新 DOM
await this.$nextTick();
// 入0出1:仅手动输入,不查询;入1出1:强制从表格选择,需查询
if (item.spxlhType !== '2') {
console.log('✅ 准备查询序列号,商品编号:', productId, '仓库:', this.serialNumberSearchForm.warehouse || '全部仓库');
await this.searchSerialNumbers();
} else {
this.serialNumberList = [];
console.log('✅ 入0出1模式,仅支持手动输入序列号');
}
},
// 关闭序列号选择弹窗
closeSerialNumberModal() {
this.isSerialNumberModalOpen = false;
this.serialNumberList = [];
this.selectedSerialNumbersForModal = [];
this.manualSerialNumberInput = '';
this.currentSerialNumberItem = null;
this.currentSerialNumberItemIndex = -1;
},
// 获取仓库选项
async getWarehouseOptions() {
try {
const response = await axios({
url: this.baseUrl + '/api/Extend/WtCk',
method: 'GET',
headers: {
Authorization: localStorage.getItem('token')
},
params: {
currentPage: 1,
pageSize: 1000
}
});
if (response.data.code === 200) {
const data = response.data.data;
const warehouseList = data.list || data.pagination?.list || [];
// ✅ 统一格式:确保每个仓库对象都有 F_Id 和 F_mdmc 字段(与下拉框格式一致)
this.warehouseOptions = warehouseList.map(wh => ({
...wh,
F_Id: wh.F_Id || wh.id || wh.Id,
F_mdmc: wh.F_mdmc || wh.mdmc || wh.Mdmc || wh.name
}));
console.log('✅ 仓库选项加载完成(从 WtCk API),数量:', this.warehouseOptions.length);
}
} catch (error) {
console.error('获取仓库列表失败:', error);
}
},
// 查询序列号
async searchSerialNumbers() {
if (!this.serialNumberSearchForm.productCode) {
console.error('❌ 商品编号为空');
this.showPosToast('商品编号不能为空');
return;
}
console.log('🔍 开始查询序列号...');
console.log('📦 查询参数:', {
productCode: this.serialNumberSearchForm.productCode,
warehouse: this.serialNumberSearchForm.warehouse,
serialNumber: this.serialNumberSearchForm.serialNumber,
documentType: '销售出库单',
baseUrl: this.baseUrl
});
try {
const params = {
productCode: this.serialNumberSearchForm.productCode,
documentType: '销售出库单'
};
if (this.serialNumberSearchForm.warehouse) {
params.warehouse = this.serialNumberSearchForm.warehouse;
}
if (this.serialNumberSearchForm.serialNumber) {
params.serialNumber = this.serialNumberSearchForm.serialNumber;
}
const apiUrl = this.baseUrl + '/api/Extend/WtXsckd/GetAvailableSerialNumbers';
console.log('🌐 API URL:', apiUrl);
console.log('📤 请求参数:', params);
const response = await axios({
url: apiUrl,
method: 'GET',
headers: {
Authorization: localStorage.getItem('token')
},
params: params
});
console.log('📥 API响应:', response);
console.log('📥 响应数据:', response.data);
if (response.data) {
// 处理不同的响应格式
let serialNumbers = null;
if (response.data.serialNumbers) {
serialNumbers = response.data.serialNumbers;
} else if (response.data.data && response.data.data.serialNumbers) {
serialNumbers = response.data.data.serialNumbers;
} else if (Array.isArray(response.data)) {
serialNumbers = response.data;
}
if (serialNumbers && Array.isArray(serialNumbers) && serialNumbers.length > 0) {
console.log('✅ 查询到序列号:', serialNumbers.length, '个');
console.log('📋 序列号列表:', serialNumbers);
this.serialNumberList = serialNumbers;
} else {
console.warn('⚠️ 未查询到可用序列号,响应数据:', response.data);
this.serialNumberList = [];
this.showPosToast('未查询到可用序列号');
}
} else {
console.warn('⚠️ 响应数据为空');
this.serialNumberList = [];
this.showPosToast('未查询到可用序列号');
}
} catch (error) {
console.error('❌ 查询序列号失败:', error);
console.error('❌ 错误详情:', {
message: error.message,
response: error.response,
responseData: error.response?.data,
status: error.response?.status,
statusText: error.response?.statusText
});
this.serialNumberList = [];
const errorMsg = error.response?.data?.message || error.response?.data?.msg || error.message || '未知错误';
this.showPosToast('查询序列号失败: ' + errorMsg);
}
},
// 重置序列号搜索
resetSerialNumberSearch() {
this.serialNumberSearchForm.warehouse = '';
this.serialNumberSearchForm.serialNumber = '';
this.searchSerialNumbers();
},
// 手动添加序列号
addManualSerialNumber() {
const input = (this.manualSerialNumberInput || '').trim();
if (!input) {
this.showPosToast('请输入序列号');
return;
}
const existsInList = this.serialNumberList.some(
sn => sn.serialNumber === input
);
if (existsInList) {
this.showPosToast('该序列号已存在于列表中,不能重复添加');
return;
}
const existsInSelected = this.selectedSerialNumbersForModal.indexOf(input) > -1;
if (existsInSelected) {
this.showPosToast('该序列号已被选择,不能重复添加');
return;
}
const currentItem = this.currentSerialNumberItem;
this.serialNumberList.unshift({
serialNumber: input,
productCode: this.serialNumberSearchForm.productCode || '',
productCodeEncode: currentItem ? (currentItem.spbm || '') : '',
productName: currentItem ? (currentItem.spmc || '') : '',
warehouse: this.serialNumberSearchForm.warehouse || '',
inTime: new Date().toISOString(),
status: 0,
isManual: true
});
this.selectedSerialNumbersForModal.push(input);
this.manualSerialNumberInput = '';
},
// 切换序列号选择
toggleSerialNumberSelection(serialNumber) {
if (!this.selectedSerialNumbersForModal) {
this.selectedSerialNumbersForModal = [];
}
const index = this.selectedSerialNumbersForModal.indexOf(serialNumber);
if (index > -1) {
this.selectedSerialNumbersForModal.splice(index, 1);
} else {
this.selectedSerialNumbersForModal.push(serialNumber);
}
},
// 全选/取消全选序列号
toggleSelectAllSerialNumbers(event) {
if (event.target.checked) {
if (!this.serialNumberList || !Array.isArray(this.serialNumberList)) {
this.selectedSerialNumbersForModal = [];
return;
}
this.selectedSerialNumbersForModal = this.serialNumberList
.filter(sn => sn.status === 0)
.map(sn => sn.serialNumber);
} else {
this.selectedSerialNumbersForModal = [];
}
},
// 检查序列号是否已选择
isSerialNumberSelected(serialNumber) {
if (!this.selectedSerialNumbersForModal || !Array.isArray(this.selectedSerialNumbersForModal)) {
return false;
}
return this.selectedSerialNumbersForModal.indexOf(serialNumber) > -1;
},
// 检查是否全选
get isAllSerialNumbersSelected() {
if (!this.serialNumberList || !Array.isArray(this.serialNumberList)) {
return false;
}
if (!this.selectedSerialNumbersForModal || !Array.isArray(this.selectedSerialNumbersForModal)) {
return false;
}
const availableSerialNumbers = this.serialNumberList.filter(sn => sn.status === 0).map(sn => sn.serialNumber);
return availableSerialNumbers.length > 0 &&
availableSerialNumbers.every(sn => this.selectedSerialNumbersForModal.indexOf(sn) > -1);
},
// 从弹窗中移除序列号
removeSerialNumberFromModal(serialNumber) {
if (!this.selectedSerialNumbersForModal || !Array.isArray(this.selectedSerialNumbersForModal)) {
return;
}
const index = this.selectedSerialNumbersForModal.indexOf(serialNumber);
if (index > -1) {
this.selectedSerialNumbersForModal.splice(index, 1);
}
},
// 确认序列号选择
confirmSerialNumberSelection() {
if (!this.currentSerialNumberItem) return;
const item = this.currentSerialNumberItem;
const needsSerialNumber = item.spxlhType === '1' || item.spxlhType === '2';
if (needsSerialNumber && this.selectedSerialNumbersForModal.length === 0) {
this.showPosToast('该商品需要选择序列号');
return;
}
if (needsSerialNumber && this.selectedSerialNumbersForModal.length !== item.quantity) {
this.showPosToast(`该商品需要选择 ${item.quantity} 个序列号,当前已选择 ${this.selectedSerialNumbersForModal.length} 个`);
return;
}
item.selectedSerialNumbers = [...this.selectedSerialNumbersForModal];
// 记录哪些是手动录入的序列号,结算时需要先在数据库中创建
var manualSNs = this.serialNumberList
.filter(function(sn) { return sn.isManual; })
.map(function(sn) { return sn.serialNumber; });
item.manualSerialNumbers = manualSNs.filter(function(sn) {
return item.selectedSerialNumbers.indexOf(sn) > -1;
});
this.closeSerialNumberModal();
},
// 移除序列号
removeSerialNumber(item, serialNumber) {
if (!item.selectedSerialNumbers) return;
const index = item.selectedSerialNumbers.indexOf(serialNumber);
if (index > -1) {
item.selectedSerialNumbers.splice(index, 1);
}
},
// ✅ 获取当前选择的门店ID(登录时选择的门店)
getSelectedStoreId() {
try {
const selectedStore = localStorage.getItem('selectedStore');
if (selectedStore) {
const store = JSON.parse(selectedStore);
return store.id;
}
} catch (e) {
console.warn('无法获取 selectedStore:', e);
}
// 降级方案:使用导购员的门店
try {
const ckinfo = localStorage.getItem('ckinfo');
if (ckinfo) {
return JSON.parse(ckinfo).id;
}
} catch (e) {
console.warn('无法获取 ckinfo:', e);
}
return '';
},
// ✅ 根据门店ID获取对应的仓库ID
async getWarehouseIdByStoreId(storeId) {
if (!storeId) {
console.warn('门店ID为空,无法获取仓库');
return '';
}
try {
const response = await axios({
url: this.baseUrl + '/api/Extend/WtCk',
method: 'GET',
params: {
ssmd: storeId,
currentPage: 1,
pageSize: 1
},
headers: {
Authorization: localStorage.getItem('token')
}
});
if (response.data.code === 200 && response.data.data && response.data.data.list && response.data.data.list.length > 0) {
const warehouse = response.data.data.list[0];
// ✅ 优先使用 F_Id,如果没有则使用 id(兼容不同格式)
const warehouseId = warehouse.F_Id || warehouse.id || warehouse.Id;
console.log(`✅ 门店 ${storeId} 对应的仓库ID: ${warehouseId}`, warehouse);
return warehouseId;
} else {
console.warn(`⚠️ 门店 ${storeId} 未找到对应的仓库`);
return '';
}
} catch (error) {
console.error('获取仓库ID失败:', error);
return '';
}
},
// 获取仓库名称
getWarehouseName(warehouseId) {
const warehouse = this.warehouseOptions.find(wh => wh.F_Id === warehouseId);
return warehouse ? warehouse.F_mdmc : warehouseId;
},
// 格式化日期
formatDate(dateStr) {
if (!dateStr) return '';
const date = new Date(dateStr);
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
return `${year}/${month}/${day}`;
},
switchCategory(type) {
this.ontype = type;
this.getGoodsList()
},
/** 解析商品列表上的门店可售库存(与 WtSp mdkc 一致,向下取整) */
parseMdkcNumber(mdkc) {
const n = parseFloat(mdkc);
if (isNaN(n) || n < 0) return 0;
return Math.floor(n);
},
/**
* 同一行 quantity 超过门店库存时拆成两行:现货 + 预售(仅单品,不含套餐子行)。
* @returns {boolean} true 已拆分或无需拆分;false 用户取消确认
*/
splitLineIfStockInsufficient(item, index) {
if (!item || (item.isPackageItem && item.packageId)) return true;
if (item.isPresale) return true;
const cap = this.parseMdkcNumber(item.mdkc);
const q = parseInt(item.quantity, 10) || 0;
if (cap <= 0 || q <= cap) return true;
const over = q - cap;
if (!window.confirm(
`该商品门店现货仅 ${cap} 件,您要了 ${q} 件;多出的 ${over} 件将生成「预售出库单」(到货后再出库)。\n\n是否按此拆分继续?`
)) {
return false;
}
item.quantity = cap;
if (item.selectedSerialNumbers && item.selectedSerialNumbers.length > cap) {
item.selectedSerialNumbers = item.selectedSerialNumbers.slice(0, cap);
}
const presaleLine = Object.assign({}, item, {
quantity: over,
isPresale: true,
selectedSerialNumbers: []
});
this.addgoodlist.splice(index + 1, 0, presaleLine);
this.showPosToast(`已拆分:现货 ${cap} 件 + 预售 ${over} 件`);
return true;
},
decreaseQuantity(item, index) {
if (this.addgoodlist[index].quantity > 1) {
this.addgoodlist[index].quantity--;
}
},
increaseQuantity(item, index) {
this.addgoodlist[index].quantity++;
const row = this.addgoodlist[index];
if (!row.isPackageItem || !row.packageId) {
if (!row.isPresale && this.parseMdkcNumber(row.mdkc) > 0 && row.quantity > this.parseMdkcNumber(row.mdkc)) {
if (!this.splitLineIfStockInsufficient(row, index)) {
this.addgoodlist[index].quantity--;
}
}
}
},
deleteProduct(index) {
var item = this.addgoodlist[index];
if (!item) return;
var delName = item.spmc || '该商品';
var delTip = (item.isPackageItem && item.packageId)
? '确定删除套餐「' + delName + '」及相关套餐商品?'
: '确定从购物车中删除「' + delName + '」?';
if (!confirm(delTip)) return;
if (item.isPackageItem && item.packageId) {
this.addgoodlist = this.addgoodlist.filter(function (it) {
return !(it.isPackageItem && it.packageId === item.packageId);
});
} else {
this.addgoodlist.splice(index, 1);
}
},
openModal() {
this.isModalOpen2 = false;
// ✅ 每次打开时重新加载iframe,确保表单是空的
this.memberFormSrc = 'from.html?t=' + Date.now();
this.isModalOpen = true;
},
closeModal() {
this.isModalOpen = false;
},
// ✅ 切换视图模式(普通商品 vs 套装商品)
switchViewMode(mode) {
this.viewMode = mode;
if (mode === 'package' && this.wtsptz.length === 0) {
this.loadPackages(false);
}
},
// ✅ 加载套装列表(与商品一致:按当前门店解析分组过滤可售套装);silent 为 true 时不弹 Toast
loadPackages(silent) {
var that = this;
var xsmdForQuery = this.getPosXsmdForQuery();
if (!xsmdForQuery) {
this.wtsptz = [];
if (!silent) this.showPosToast('请先选择登录门店后再加载套装');
return;
}
axios({
url: that.baseUrl + "/api/Extend/WtSptz",
method: 'GET',
headers: {
Authorization: localStorage.getItem('token')
},
params: {
currentPage: 1,
pageSize: 1000,
xsmd: xsmdForQuery
}
}).then((res) => {
console.log('套装列表:', res.data);
if (res.data.code == 200) {
that.wtsptz = res.data.data.list || [];
// ✅ 为每个套装加载详情,以便计算商品数量
that.wtsptz.forEach((pkg) => {
if (!pkg.wtSptzMxList) {
that.loadPackageDetailForDisplay(pkg.id);
}
});
} else {
console.error('加载套装列表失败');
}
}).catch((err) => {
console.error('加载套装列表错误:', err);
});
},
// ✅ 获取套装内所有商品的数量总和
getPackageTotalQuantity(packageItem) {
if (!packageItem.wtSptzMxList || packageItem.wtSptzMxList.length === 0) {
return 0;
}
// ✅ 计算所有子商品的数量总和
let totalQuantity = 0;
packageItem.wtSptzMxList.forEach((item) => {
// 解析每个商品的数量
if (item.spsl !== null && item.spsl !== undefined && item.spsl !== '') {
const parsedQty = parseInt(item.spsl);
if (!isNaN(parsedQty) && parsedQty > 0) {
totalQuantity += parsedQty;
} else {
totalQuantity += 1; // 如果无效,默认加1
}
} else {
totalQuantity += 1; // 如果为空,默认加1
}
});
return totalQuantity;
},
// ✅ 为显示目的加载套装详情(不触发选择)
loadPackageDetailForDisplay(packageId) {
var that = this;
axios({
url: that.baseUrl + "/api/Extend/WtSptz/" + packageId,
method: 'GET',
headers: {
Authorization: localStorage.getItem('token')
}
}).then((res) => {
if (res.data.code == 200 && res.data.data) {
const pkg = this.wtsptz.find(p => p.id === packageId);
if (pkg) {
pkg.wtSptzMxList = res.data.data.wtSptzMxList || [];
// ✅ 更新套装总价
if (res.data.data.tzzj !== undefined && res.data.data.tzzj !== null) {
pkg.tzzj = res.data.data.tzzj;
}
// 强制更新视图
this.$forceUpdate();
}
}
}).catch((err) => {
console.error('获取套装详情错误(显示用):', err);
});
},
// ✅ 选择套装并加载套装中的所有商品
selectPackage(packageItem) {
console.log('选中的套装:', packageItem);
if (!packageItem.wtSptzMxList) {
this.loadPackageDetail(packageItem.id);
return;
}
if (packageItem.wtSptzMxList && packageItem.wtSptzMxList.length > 0) {
// 检查套装明细中是否有空的商品名称,如果有则重新加载详情
const hasEmptySpmc = packageItem.wtSptzMxList.some(item => !item.spmc);
if (hasEmptySpmc) {
console.warn('检测到套装明细中有空的商品名称,重新加载详情...');
this.loadPackageDetail(packageItem.id);
return;
}
// ✅ 检查套装中所有商品的库存(基于每个商品的实际数量)
let insufficientStock = [];
let hasPresaleItem = false;
packageItem.wtSptzMxList.forEach((item) => {
// 从 wtsp 中查找商品库存信息
const product = this.wtsp.find(p => p.id === item.spbh);
// ✅ 正确解析每个商品需要的数量
let requiredQty = 1; // 默认数量为1
if (item.spsl !== null && item.spsl !== undefined && item.spsl !== '') {
const parsedQty = parseInt(item.spsl);
if (!isNaN(parsedQty) && parsedQty > 0) {
requiredQty = parsedQty;
}
}
// ✅ 预售判断:如果商品不存在,或库存不足(库存 < 需要的数量),则标记为预售
if (!product || !product.mdkc || product.mdkc < requiredQty) {
hasPresaleItem = true;
console.log(`⚠️ 商品 ${item.spmc || item.spbh} 库存不足,需要 ${requiredQty},库存 ${product ? product.mdkc : 0}`);
}
});
// ✅ 即使有库存不足的商品,也允许添加(作为预售)
if (hasPresaleItem) {
this.showPosToast('套装中存在库存不足的商品,将作为预售单处理');
}
// ✅ 添加到购物车,保存套餐信息
// ✅ 保存套餐内商品列表,用于改价时显示
const packageItemsList = packageItem.wtSptzMxList || [];
for (let pi = 0; pi < packageItemsList.length; pi++) {
const row = packageItemsList[pi];
let p = this.wtsp.find(function (x) { return x.id === row.spbh; });
if (!p || !p.spmc) {
p = {
id: row.spbh,
spmc: row.spmc || '商品名称加载中...',
spbm: row.spbm || '',
lsj: row.lsj || 0,
mdkc: 999
};
}
if (!this.checkMemberRestrictionForProduct(p)) {
return;
}
}
packageItem.wtSptzMxList.forEach((item) => {
// ✅ 调试:打印套装明细项信息
console.log('📦 套装明细项:', {
spbh: item.spbh,
spmc: item.spmc,
spsl: item.spsl,
spslType: typeof item.spsl,
lsj: item.lsj
});
const product = this.wtsp.find(p => p.id === item.spbh);
// ✅ 正确解析数量:优先使用套装明细中的 spsl,如果为0或空则使用1
// spsl 是字符串类型,需要转换为数字
let itemQuantity = 1; // 默认数量为1
if (item.spsl !== null && item.spsl !== undefined && item.spsl !== '') {
const parsedQty = parseInt(item.spsl);
if (!isNaN(parsedQty) && parsedQty > 0) {
itemQuantity = parsedQty;
}
}
console.log(`✅ 解析后的商品数量: ${itemQuantity} (原始值: ${item.spsl})`);
// ✅ 预售判断:基于每个商品的实际数量(spsl)和库存
// 如果商品不存在,或库存不足(库存 < 需要的数量),则标记为预售
const isPresale = !product || !product.mdkc || product.mdkc < itemQuantity;
if (isPresale) {
console.log(`⚠️ 商品 ${item.spmc || item.spbh} 标记为预售,需要 ${itemQuantity},库存 ${product ? product.mdkc : 0}`);
}
const existingItem = this.addgoodlist.find(
(goods) => goods.id === item.spbh && goods.packageId === packageItem.id
);
if (existingItem) {
existingItem.quantity += itemQuantity;
if (isPresale) {
existingItem.isPresale = true; // 标记为预售
}
// ✅ 更新套餐内商品列表(如果还没有)
if (!existingItem.packageItems) {
existingItem.packageItems = packageItemsList;
}
console.log(`商品 ${existingItem.spmc} 数量已更新为: ${existingItem.quantity}`);
} else {
// ✅ 传递正确的数量给 addProductToCart
this.addProductToCart(item, isPresale, packageItem.id, packageItem.tzzj, packageItemsList, itemQuantity);
}
});
this.showPosToast('套装商品已添加到购物车!');
} else {
this.showPosToast('该套装暂无商品');
}
},
// ✅ 获取套装的详细信息
loadPackageDetail(packageId) {
var that = this;
axios({
url: that.baseUrl + "/api/Extend/WtSptz/" + packageId,
method: 'GET',
headers: {
Authorization: localStorage.getItem('token')
}
}).then((res) => {
console.log('套装详情:', res.data);
if (res.data.code == 200 && res.data.data) {
const pkg = this.wtsptz.find(p => p.id === packageId);
if (pkg) {
pkg.wtSptzMxList = res.data.data.wtSptzMxList || [];
// ✅ 更新套装总价
if (res.data.data.tzzj !== undefined && res.data.data.tzzj !== null) {
pkg.tzzj = res.data.data.tzzj;
}
this.selectPackage(pkg);
}
}
}).catch((err) => {
console.error('获取套装详情错误:', err);
this.showPosToast('获取套装详情失败');
});
},
// ✅ 将套装中的商品添加到购物车
addProductToCart(packageItem, isPresale, packageId, packagePrice, packageItemsList, itemQuantity) {
var that = this;
// 首先尝试从 wtsp 找到商品(当前分类)
let product = this.wtsp.find(p => p.id === packageItem.spbh);
// 如果没找到或名称为空,直接使用套装明细中的商品信息
if (!product || !product.spmc) {
product = {
id: packageItem.spbh,
spmc: packageItem.spmc || '商品名称加载中...',
spbm: packageItem.spbm || '',
lsj: packageItem.lsj || 0,
mdkc: 999 // 套装中的商品库存暂设为足够
};
}
// ✅ 会员限购在 selectPackage 中已整包预检,此处不再重复校验
// ✅ 使用传入的数量,如果没有传入则从 packageItem.spsl 解析
let finalQuantity = itemQuantity;
if (finalQuantity === undefined || finalQuantity === null) {
if (packageItem.spsl !== null && packageItem.spsl !== undefined && packageItem.spsl !== '') {
const parsedQty = parseInt(packageItem.spsl);
if (!isNaN(parsedQty) && parsedQty > 0) {
finalQuantity = parsedQty;
} else {
finalQuantity = 1;
}
} else {
finalQuantity = 1;
}
}
console.log(`✅ 添加到购物车的商品数量: ${finalQuantity} (商品: ${product.spmc || packageItem.spmc})`);
const cartItem = {
id: product.id,
spmc: product.spmc,
spbm: product.spbm,
lsj: product.lsj,
mdkc: product.mdkc,
quantity: finalQuantity, // ✅ 使用正确解析的数量
isPresale: isPresale, // 标记是否为预售商品
// ✅ 套餐相关信息
packageId: packageId || null, // 套餐ID
packagePrice: (packagePrice !== undefined && packagePrice !== null) ? packagePrice : null, // 套餐总价(保留0值)
isPackageItem: !!packageId, // 是否为套餐商品
packageItems: packageItemsList || null, // ✅ 套餐内商品列表,用于改价时显示
...product
};
this.addgoodlist.push(cartItem);
console.log(`✅ 商品 ${product.spmc} 已添加到购物车,数量: ${finalQuantity}${packageId ? `,套餐ID: ${packageId},套餐价格: ${packagePrice}` : ''}`); }
}
})
</script>
</body>
</html>