index.vue 83 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 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

<template>
  <clashDriverDispatch ref="clashDriverDispatchRef" :valueKey="'licensePlateNumber'"
                       :onconfirm="handleDriverDispatchConfirm" :dataList="driverPersonnelList">
  </clashDriverDispatch>
  <clashDisposalDispatch ref="clashDisposalDispatchRef" :valueKey="'companyName'"
                         :onconfirm="handleDisposalDispatchConfirm" :dataList="driverPersonnelList">
  </clashDisposalDispatch>
  <u-popup :zIndex="10074" closeOnClickOverlay :show="carPopupShowFlag" :round="10" @close="handlePopupClick(false)"
           @open="handlePopupClick(true)">
    <view class="company-clean-container-car-popup">
      <!-- 主要内容 -->
      <view class="company-clean-container-car-popup-content">
        <view class="company-clean-container-car-popup-content-title">
          <view style="text-align: center;">
            车辆类型
          </view>
        </view>
        <view class="company-clean-container-car-popup-content-box">
          <view class="company-clean-container-car-popup-content-box-item"
                v-for="(item, index) in garCarInfoList" :key="index">
            <view class="company-clean-container-car-popup-content-box-item-text">
              {{ item.garOrderCarType }}
            </view>
            <view class="company-clean-container-car-popup-content-box-item-number"
                  hover-class="hoverClickStyle">
              <u-number-box :min="1" :max="9999" integer buttonSize="46" :inputWidth="100"
                            v-model="garCarInfoList[item.garOrderCarType].garOrderCarNumber"
                            :disabledInput="true"></u-number-box>
            </view>
          </view>
        </view>
      </view>
      <!-- 占位盒子 -->
      <view class="company-clean-container-car-popup-button-safe">
        <view class="company-clean-container-car-popup-button-safe-btn">
          <u-button type="primary" color="#19a97c" @click="submitUpdateCarInfo">确定</u-button>
        </view>
      </view>
    </view>
  </u-popup>
  <view class="order-detail-container" v-if="dataGram != null || dataGram != undefined">
    <view class="order-detail-container-box">
      <view class="order-detail-top">
        <view class="order-detail-top-box">
          <view class="order-detail-top-box-step">
            <u-steps :current="currentStep(dataGram.garOrderHandlerStatus)" dot>
              <u-steps-item title="待清运"></u-steps-item>
              <u-steps-item title="清运中"></u-steps-item>
              <u-steps-item title="已完成"></u-steps-item>
            </u-steps>
          </view>
        </view>
      </view>
      <!-- 信息提示 -->
      <view class="order-detail-container-box-card">
        <text v-if="dataGram.garCancelFlag == 0" style="color: red;">请于交易完成后线下支付!!</text>
        <view v-else style="display: flex; color:red;">
          <u-icon name="close-circle" color="red"></u-icon>
          <text> &nbsp;&nbsp;订单已被取消!原因:{{ dataGram.garReason }}</text>
        </view>
      </view>
      <!-- 订单信息 -->
      <view class="order-detail-container-box-card order-info-section">
        <view class="order-info-header">
          <view class="order-detail-container-header-card-uicon"></view>
          <u-icon name="file-text" size="22" color="#fff" style="margin-right: 8rpx;"></u-icon>
          <text class="title-text">订单信息</text>
        </view>

        <view class="info-item">
          <view class="info-label">
            <u-icon name="map" size="16" color="#19a97c" style="margin-right: 8rpx;"></u-icon>
            <text>清运地点:</text>
          </view>
          <view class="info-content" @click.stop="showNavDialog(dataGram.garLongitude,dataGram.garLatitude, dataGram.garOrderAddressDetails)">
            <text class="content-text" selectable='true'>{{ dataGram.garOrderAddress + dataGram.garOrderAddressDetails }}</text>
          </view>
        </view>

        <view class="info-item">
          <view class="info-label">
            <u-icon name="photo" size="16" color="#19a97c" style="margin-right: 8rpx;"></u-icon>
            <text>现场图片:</text>
          </view>
          <view class="info-content">
            <u-upload width="180" height="130" :fileList="currentImages" name="3" multiple :maxCount="10"
                      :previewFullImage="true" :isReadOnly="true"></u-upload>
          </view>
        </view>

        <view class="info-item">
          <view class="info-label">
            <u-icon name="account" size="16" color="#19a97c" style="margin-right: 8rpx;"></u-icon>
            <text>负责单位:</text>
          </view>
          <view class="info-content">
            <text class="content-text">{{ dataGram.garOrderCompanyName }}</text>
          </view>
        </view>

        <view class="info-item">
          <view class="info-label">
            <u-icon name="trash" size="16" color="#19a97c" style="margin-right: 8rpx;"></u-icon>
            <text>垃圾类型:</text>
          </view>
          <view class="info-content">
            <text class="content-text">{{ dataGram.garOrderTrashType }}</text>
          </view>
        </view>

        <view class="info-item" v-for="(disposal,index) in dataGram.disposalSites" :key="index">
          <view class="info-label">
            <u-icon name="location" size="16" color="#19a97c" style="margin-right: 8rpx;"></u-icon>
            <text v-if="index == 0">处置场地:</text>
            <text v-else></text>
          </view>
          <view class="info-content" @click.stop="handlerJumpOtherApp(disposal.latitude, disposal.longitude, dataGram.garCoordinate)">
            <text class="content-text">{{ disposal.addrStr }}</text>
          </view>
        </view>

        <view class="info-item">
          <view class="info-label">
            <u-icon name="order" size="16" color="#19a97c" style="margin-right: 8rpx;"></u-icon>
            <text>订单号:</text>
          </view>
          <view class="info-content">
            <text class="content-text" selectable="true">{{ orderId }}</text>
            <!-- 生成二维码 -->
            <view class="qr-code-icon" @click="handleQrCodeClick(orderId)">
              <view class="iconfont icon-erweima-xian" style="font-size: 20px; color: #19a97c;"></view>
            </view>
          </view>
        </view>
      </view>
      <!-- 车辆信息 -->

      <view class="order-detail-container-box-card vehicle-section" v-if="dataGram.garOrderHandlerStatus !== 3">
        <view class="section-header">
          <view class="header-icon-bar"></view>
          <u-icon name="car" size="22" color="#fff" style="margin-right: 10rpx;"></u-icon>
          <text class="header-title">车辆信息</text>
        </view>

        <view class="trip-summary-card">
          <view class="summary-content">
            <u-icon name="info-circle" size="18" color="#19a97c" style="margin-right: 10rpx;"></u-icon>
            <text class="summary-label">当前订单总计需发车次数:</text>
            <text class="summary-value">{{ realCarCount }}</text>
            <text class="summary-unit">次</text>
          </view>
          <view v-if="userType === '用户'" class="reduce-trip-section">
            <text class="reduce-label">减少发车次数:</text>
            <view class="right-controls">
              <u-number-box
                  v-model="reduceTripCount"
                  :min="1"
                  :max="realCarCount - 1"
                  integer
                  buttonSize="30"
                  inputWidth="50"
                  style="margin: 0 20rpx;">
              </u-number-box>
              <u-button
                  type="primary"
                  size="mini"
                  @click="handleReduceTrips"
                  :disabled="reduceTripCount <= 0 || realCarCount <= 1"
                  style="background-color: #19a97c; max-width: 120rpx; font-size: 20rpx; padding: 0 10rpx;">
                确认减少
              </u-button>
            </view>
          </view>
        </view>

        <view class="vehicle-info-card" v-if="dataGram.garCarInfoList && dataGram.garCarInfoList.length > 0 &&userType !== '用户'">
          <view class="card-header">
            <u-icon name="file-text" size="18" color="#19a97c"></u-icon>
            <text class="card-title">车辆类型详情</text>
          </view>
          <view class="car-type-list">
            <view class="car-type-item" v-for="(car, index) in garCarTypeList" :key="index">
              <view class="car-type-info">
                <u-icon name="car-fill" size="16" color="#19a97c"></u-icon>
                <text class="info-label">车型:</text>
                <text class="info-value">{{ car.garOrderCarType }}</text>
              </view>
              <view class="car-count-info">
                <u-icon name="order" size="16" color="#19a97c"></u-icon>
                <text class="info-label">数量:</text>
                <text class="info-value">{{ car.count }}辆</text>
              </view>
            </view>
          </view>
        </view>

        <view class="handler-list-card"  v-if=" userType !== '用户'">
          <view class="card-header">
            <u-icon name="list" size="18" color="#19a97c"></u-icon>
            <text class="card-title">处理人员信息</text>
          </view>
          <view class="handler-item" v-for="(item, index) in handlerList" :key="index">
            <view class="handler-basic-info">
              <text class="handler-name">{{ item.garOrderHandlerName }}</text>
              <text class="handler-car">{{ item.garHandlerCarCode }}</text>
              <text class="handler-volume">{{ item.garOrderContainerVolume }}</text>
            </view>
            <view class="handler-trip-controls">
              <u-number-box
                  v-model="item.carCountInput"
                  :min="0"
                  :max="999"
                  integer
                  buttonSize="30"
                  inputWidth="50">
              </u-number-box>
              <u-button
                  type="success"
                  size="mini"
                  class="assign-button"
                  @click="assignTripToHandler(item)">
                {{ item.garCarCount && item.garCarCount > 0 ? '保存' : '分配' }}
              </u-button>
              <u-button
                  type="error"
                  size="mini"
                  class="delete-button"
                  @click="deleteHandler(item)">
                删除
              </u-button>
            </view>
          </view>
        </view>
      </view>



      <!-- 订单人员 -->
      <view class="order-detail-container-box-card order-person-section" v-if="userType !== '用户'">
        <view class="section-header">
          <view class="header-icon-bar"></view>
          <u-icon name="account" size="22" color="#fff" style="margin-right: 8rpx;"></u-icon>
          <text class="header-title">订单信息</text>
        </view>


        <view class="info-item">
          <view class="info-label">
            <u-icon name="clock" size="16" color="#19a97c" style="margin-right: 8rpx;"></u-icon>
            <text>预约时间:</text>
          </view>
          <view class="info-content">
            <text class="content-text">{{ dataGram.garOrderAgreementTime }}</text>
          </view>
        </view>

        <view class="info-item">
          <view class="info-label">
            <u-icon name="phone" size="16" color="#19a97c" style="margin-right: 8rpx;"></u-icon>
            <text>联系电话:</text>
          </view>
          <view class="info-content">
            <text class="content-text" selectable="true">{{ dataGram.garOrderContactTel }}</text>
            <view class="icon-box" v-if="dataGram.handleFlag" @click="handleContactClick(dataGram.garOrderContactTel)">
              <u-icon name="phone-fill" size="20" color="#19a97c"></u-icon>
            </view>
          </view>
        </view>

        <view class="info-item">
          <view class="info-label">
            <u-icon name="account" size="16" color="#19a97c" style="margin-right: 8rpx;"></u-icon>
            <text>订单人:</text>
          </view>
          <view class="info-content">
            <text class="content-text">{{ dataGram.garOrderContactName }}</text>
          </view>
        </view>

        <view class="info-item">
          <view class="info-label">
            <u-icon name="map" size="16" color="#19a97c" style="margin-right: 8rpx;"></u-icon>
            <text>处理场所:</text>
          </view>
          <!-- 修改后 -->
          <view class="info-content" v-if="selectedDisposalSites.length > 0" style="flex-direction: column; align-items: flex-start;">
            <view v-for="(site, index) in selectedDisposalSites" :key="index" style="margin-bottom: 15rpx; width: 100%;">
              <text class="content-text">{{ site.companyName }}</text>
              <view v-if="site.contactName" style="margin-top: 5rpx;">
                <text class="content-text">联系人: {{ site.contactName }}</text>
              </view>
              <!-- 修改后 -->
              <view v-if="site.contactPhone" style="margin-top: 5rpx; display: flex; align-items: center;">
                <text style="flex: 1;">联系电话: {{ site.contactPhone }}</text>
                <view style="margin-left: 10rpx;" v-if="dataGram.handleFlag" @click="handleContactClick(site.contactPhone)">
                  <u-icon name="phone-fill" size="20" color="#19a97c"></u-icon>
                </view>
              </view>
            </view>
          </view>
        </view>

        <view class="info-item">
          <view class="info-label">
            <u-icon name="file-text" size="16" color="#19a97c" style="margin-right: 8rpx;"></u-icon>
            <text>备注:</text>
          </view>
          <view class="info-content">
            <text class="content-text">{{ dataGram.garRemark }}</text>
          </view>
        </view>
      </view>

      <!-- 处理信息 -->
      <view class="order-detail-container-box-card process-info-section">
        <view class="section-header">
          <view class="header-icon-bar"></view>
          <u-icon name="setting" size="22" color="#fff" style="margin-right: 8rpx;"></u-icon>
          <text class="header-title">处理信息</text>
        </view>

        <view v-if="putDownImages.length || putOnImages.length" class="photo-section">
          <view class="info-item">
            <view class="info-label">
              <u-icon name="photo" size="16" color="#19a97c" style="margin-right: 8rpx;"></u-icon>
              <text>装车照片:</text>
            </view>
          </view>

          <view class="image-groups">
            <view v-for="group in putOnImagesGrouped" :key="group.index" class="image-group">
              <view class="image-group-header">
                <view class="image-group-title">{{ group.carName}}第 {{ group.index }} 趟</view>
                <view class="car-status" :class="{
                  'in-transit': group.carStatus === '0',
                  'completed': group.carStatus === '1' || group.carStatus === '2'
                }">
                  {{ (group.carStatus === '1'||group.carStatus === '2') ? '已运完' : '正在清运' }}
                </view>
              </view>
              <u-upload width="180" height="130" :fileList="group.images" name="3" multiple :maxCount="20"
                        :previewFullImage="true" :isReadOnly="true"></u-upload>
            </view>
          </view>
        </view>

        <view v-else class="empty-image-section">
          <image class="image-style" style="width: 200rpx; height: 200rpx;" :src="emptyBase64Image"></image>
          <text class="empty-text">暂无处理照片</text>
        </view>
      </view>
      <view class="space-box">{{ spaceStr }}</view>
    </view>

    <!-- 占位符 -->
    <view class="order-detail-bottom">
      <view class="order-detail-bottom-box">
        <!-- 上方按钮行 -->
        <view class="order-detail-top-buttons" v-show="showTopButtons">
          <!-- 修改按钮组容器类名和结构 -->
          <view class="button-group-wrap" v-if="dataGram.garOrderHandlerStatus === 0 && userType == '运输企业负责人' && dataGram.handleFlag && dataGram.garCancelFlag === 0">
            <u-button @click="handleOrderDispatchClick(orderId)" shape="square" color="#19a97c" text="分配驾驶员"></u-button>
            <u-button @click="handleDisposalDispatchClick(orderId)" shape="square" color="#19a97c" text="分配处置场所"></u-button>
            <u-button
                @click="handleOrder(orderId)"
                shape="square"
                color="#19a97c"
                text="开始运输"
                :disabled="!isDriverAndDisposalAssigned()">
            </u-button>
          </view>

          <view class="button-group-spread" v-else-if="!isAllTripsCompleted()">
            <u-button class="btn-left" @click="handleOrderDispatchClick(orderId)" shape="square" color="#19a97c" text="重新分配驾驶员"></u-button>
            <u-button class="btn-right" @click="handleDisposalDispatchClick(orderId)" shape="square" color="#19a97c" text="重新分配处置场所"></u-button>
          </view>

          <view v-else-if="dataGram.garOrderHandlerStatus === 1 && userType == '运输企业负责人' && isAllTripsCompleted()">
            <u-button @click="handleSubmitSuccess(orderId)" shape="square" color="#19a97c" text="完成订单"></u-button>
          </view>
        </view>

        <!-- 下方按钮行 -->
        <view class="order-detail-bottom-buttons">
          <view class="cancel-button-container">
            <u-button
                v-if="dataGram.garOrderHandlerStatus === 0 && userType == '运输企业负责人' && dataGram.garCancelFlag === 0"
                @click="handleOderCancelClick()" shape="square" color="#19a97c" text="取消订单"></u-button>
            <u-button
                v-if="dataGram.garOrderHandlerStatus === 0 && userType == '用户' && dataGram.garCancelFlag === 0"
                @click="handleOderCancelClick()" shape="square" color="#19a97c" text="取消订单"></u-button>
          </view>

          <view class="evaluation-buttons-container" v-show="showRightButtons">
            <u-button @click="handleEvaluate(orderId, userType)"
                      v-if="dataGram.garEvaluateFlag === 0 && userType === '用户'" shape="square" color="#19a97c"
                      text="去评价"></u-button>
            <u-button @click="handleEvaluateDetail(orderId, userType)"
                      v-if="dataGram.garHandlerEvaluateFlag === 0 && userType === '运输企业负责人'  && dataGram.haveEvaluateOfClient==1"
                      shape="square" color="#19a97c" text="查看评价"></u-button>
            <u-button @click="handleEvaluateDetail(orderId, userType)"
                      v-if="dataGram.garHandlerEvaluateFlag === 1 && userType === '运输企业负责人'  && dataGram.haveEvaluateOfClient==1"
                      shape="square" color="#19a97c" text="查看评价"></u-button>
            <u-button @click="handleEvaluateDetail(orderId, userType)"
                      v-if="dataGram.garEvaluateFlag === 1 && userType === '用户'" shape="square" color="#19a97c"
                      text="查看评价"></u-button>
          </view>
        </view>
      </view>
    </view>
    <u-action-sheet :closeOnClickOverlay="true" :closeOnClickAction="false" @actionSheetClose="handleClose"
                    @submitFunction="submitFunction" @select="selectClick" :actions="list" round="15" title="取消订单"
                    :show="cancelShow">
    </u-action-sheet>
  </view>
  <view v-if="showUQRcode" class="mask-container" @click="showUQRcode = false">
    <uqrcode :h5SaveIsDownload="true" ref="qrCodeRef" canvas-id="qrcode" :value="qrCodeText"
             :options="{ margin: 10, boxSizing: borderBox }"></uqrcode>
  </view>

  <u-popup :zIndex="10075" closeOnClickOverlay :show="driverListPopupShowFlag" :round="10" @close="driverListPopupShowFlag = false">
    <view class="driver-list-popup">
      <view class="driver-list-popup-header">
        <text class="driver-list-popup-title">司机信息列表</text>
      </view>
      <view class="driver-list-popup-content">
        <view class="driver-item" v-for="(driver, index) in driverListForAssignment" :key="index">
          <view class="driver-info">
            <text class="driver-name">{{ driver.garOrderHandlerName }}</text>
            <text class="driver-phone">{{driver.garOrderHandlerTel }}</text>
          </view>
          <u-button type="primary" size="mini" color="#19a97c" @click="assignTripToDriver()" style="width: 120rpx; height: 50rpx; font-size: 24rpx; padding: 0 10rpx; margin-right: 0;">分配趟次</u-button>
        </view>
      </view>
      <view class="driver-list-popup-footer">
        <u-button @click="driverListPopupShowFlag = false">关闭</u-button>
      </view>
    </view>
  </u-popup>
</template>

<script setup>import {
  queryCarList
} from '@/apis/carinfo.js';
import {
  dispatchDisposalOrders,
  dispatchOrders,
  getGarOrderMatchHandlers,
  queryDisposalDispatch,
  queryOrderDetail,
  queryOrderDispatch,
  sendToDriver,
  updateGarRealCarCount,
  updateOrder,
  queryCarCode,
  queryByOrderNo,
  updateCarCount,
  queryGarRealCarCountByGarOrderNo,
  selectGarOrderCar,
  insertRandomCopyByTypeAndOrderId, deleteDriverByOrderNo
} from "@/apis/order.js";
import {
  createQrCode
} from '@/apis/qrcode.js';
import uqrcode from '@/components/Sansnn-uQRCode_4.0.6/components/uqrcode/uqrcode.vue';
import clashDisposalDispatch from '@/components/clash-disposal-dispatch/index.vue';
import clashDriverDispatch from '@/components/clash-driver-dispatch/index.vue';
import zStatic from '@/components/z-paging/js/z-paging-static';
import {
  useMainStore
} from '@/stores/index.js';
import {
  onLoad,
  onShow
} from '@dcloudio/uni-app';
import {
  computed, watch
} from 'vue';
import { ref } from 'vue';
const paramFrom = ref({
  carNumber: 0,
  carType: ""
})
const totalCarNumber = ref(0);
const driverListPopupShowFlag = ref(false);
const driverListForAssignment = ref([]);
const garCarInfoList = ref({})
const carPopupShowFlag = ref(false)
const driverList = ref([]);
const isOnloadIn = ref(false)
const clashDriverDispatchRef = ref()
const clashDisposalDispatchRef = ref()
const driverPersonnelList = ref([])
const disposalPersonnelList = ref([])
const handlerList = ref([])
const orderNo = ref(null)
const carCount = ref(null)
const tel = ref(null)
const selectedHandlerTel = ref("")
const realCarCount = ref(null)
const reduceTripCount = ref(1) // 要减少的发车次数
const store = useMainStore();
const userType = computed(() => store.userType)
const dataGram = ref();
const orderId = ref(null)
const currentImages = ref([])
const putOnImages = ref([])
const putOnImagesGrouped = ref([])  // 新增这个变量
const putDownImages = ref([])
const emptyBase64Image = ref(zStatic.base64Empty)
const showUQRcode = ref(false)
const spaceStr = ref("")
const cancelShow = ref(false)
const currentCancelName = ref("")
const qrCodeRef = ref()
const qrCodeText = ref()
const candidates = ref([])
const garCarLabelInfoList = ref({})
const garCarLabelInfoNow = ref()
const selectedHandlerTels = ref("")
const garCarTypeList = ref([])
const driverAssigned = ref(false);  // 添加这行,跟踪驾驶员是否已分配
const disposalAssigned = ref(false);  // 添加这行,跟踪处置场所是否已分配
const selectedDisposalSites = ref([]);
// 新增:用于存储待分配的驾驶员列表
const pendingDriverAssignments = ref({})
const pendingDisposalAssignments = ref({})


const isInTransit = (index) => {
  // 如果订单已完成,所有趟次都不是"清运中"
  if (dataGram.value.garOrderHandlerStatus === 3) {
    return false;
  }

  // 当前正在清运的趟次索引(从1开始)
  const currentTransitIndex = putOnImagesGrouped.value.length;

  // 只有当前趟次是"清运中"
  return index === currentTransitIndex;
};

const isCompleted = (index) => {
  // 如果订单已完成,所有趟次都是"已运完"
  if (dataGram.value.garOrderHandlerStatus === 3) {
    return true;
  }

  // 已完成的趟次索引小于当前正在清运的趟次索引
  const currentTransitIndex = putOnImagesGrouped.value.length;

  return index < currentTransitIndex;
};

const getStatusText = (index) => {
  // 如果订单已完成,显示"已运完"
  if (dataGram.value.garOrderHandlerStatus === 3) {
    return '已运完';
  }

  // 当前正在清运的趟次索引(从1开始)
  const currentTransitIndex = putOnImagesGrouped.value.length;

  if (index === currentTransitIndex) {
    return '正在清运';
  } else if (index < currentTransitIndex) {
    return '已运完';
  } else {
    return '正在清运';
  }
};

const list = computed(() => {
  let reason = [{
    name: '订单信息填写有误',
  },
    {
      name: '线下协商有问题',
    },
    {
      name: '不需要清运了',
    },
    {
      name: '其他',
    },
    {
      name: '提交',
    }
  ]
  if (userType.value === '用户') {
    reason.unshift({
      name: '长时间无人接单',
    })
  }
  return reason
})

const handleReduceTrips = () => {
  if (!reduceTripCount.value || reduceTripCount.value <= 0) {
    uni.$u.toast('请输入有效的减少次数');
    return;
  }

  if (realCarCount.value <= reduceTripCount.value) {
    uni.$u.toast('减少次数不能超过当前总次数');
    return;
  }

  // 调用接口,传递负数表示减少
  updateGarRealCarCount(orderId.value, -reduceTripCount.value)
      .then(res => {
        if (res.data.success) {
          uni.$u.toast(`减少${reduceTripCount.value}次成功!`);
          // 刷新订单详情
          handleOrderDetail(orderId.value);
          refreshOrderData();
          // 重置减少次数
          reduceTripCount.value = 1;
        } else {
          uni.$u.toast(`减少次数失败!`);
        }
      })
      .catch(err => {
        uni.$u.toast('减少次数请求失败');
        console.error('减少次数失败:', err);
      });
}

const isDriverAssigned = computed(() => {
  // 检查是否有分配的驾驶员
  return handlerList.value && handlerList.value.length > 0;
});
const isDriverAndDisposalAssigned = () => {
  // 直接使用已有的响应式变量来判断分配状态
  const hasDrivers = driverAssigned.value || (pendingDriverAssignments.value && Object.keys(pendingDriverAssignments.value).length > 0);
  const hasDisposalSites = disposalAssigned.value || (pendingDisposalAssignments.value && Object.keys(pendingDisposalAssignments.value).length > 0);

  return hasDrivers && hasDisposalSites;
};

const isAllTripsCompleted = () => {
  // 检查所有趟次是否已完成
  if (!dataGram.value || !dataGram.value.garCarInfoList || !putOnImagesGrouped.value) {
    return false;
  }

  // 获取订单要求的趟次数
  const requiredTrips = dataGram.value.garCarInfoList.length;

  // 获取实际完成的趟次数
  const completedTrips = putOnImagesGrouped.value.length;

  // 如果完成的趟次数大于等于要求的趟次数,则表示全部运完
  console.log("实际完成次数" + completedTrips + "要求次数" + requiredTrips)
  return completedTrips >= requiredTrips;
}

const assignTripToDriver = ()=>{
  sendToDriver(orderId.value).then(res=>{
    if (res.data.success) {
      uni.$u.toast('分配成功');
    }
  })
}
// 获取驾驶员列表的方法
const fetchDriverList = (orderId) => {
  queryCarCode(orderId).then(res => {
    if (res.data.success) {
      driverList.value = res.data.data;
    }
  });
};

watch(selectedHandlerTel, (newVal) => {
  tel.value = newVal;
});

const refreshOrderData = () => {
  // 刷新处理人员列表
  queryByOrderNo(orderNo.value).then(res => {
    if (res.data.success) {
      handlerList.value = res.data.data
      // 为每个处理人员初始化输入框的值
      handlerList.value.forEach(handler => {
        // 将已分配的趟次数量作为初始值
        handler.carCountInput = handler.garCarCount || 0;
      });
    }
  }).catch(err => {
    console.error('获取订单信息失败:', err);
  })

  // 刷新总趟次数
  queryGarRealCarCountByGarOrderNo(orderNo.value).then(res => {
    if (res.data.success) {
      realCarCount.value = res.data.data
    }
  })

  selectGarOrderCar(orderNo.value).then(res => {
    if (res.data.success) {
      garCarTypeList.value = res.data.data
    }
  })
};

const onCarCountChange = (e, handler) => {
  handler.carCountInput = e.value;
};

const assignTripToHandler = (handler) => {
  // 检查必填字段
  if (handler.carCountInput === undefined || handler.carCountInput === null) {
    uni.$u.toast(`请输入分配的趟次!`);
    return;
  }

  // 确保输入的是非负整数
  if (handler.carCountInput < 0) {
    uni.$u.toast(`分配趟次不能为负数!`);
    handler.carCountInput = handler.garCarCount || 0;
    return;
  }

  // 获取当前已分配的趟次数
  const currentAllocated = handler.garCarCount || 0;

  // 计算需要增加或减少的趟次数
  let delta = handler.carCountInput - currentAllocated;

  // 如果没有变化则不处理
  if (delta === 0) {
    uni.$u.toast('分配数量未发生变化');
    return;
  }

  // 检查如果是增加操作,是否会超过总需求趟次
  if (delta > 0) {
    // 检查已分配趟次总和是否超过订单要求的总发车次数(排除当前正在修改的人员)
    const allocatedTrips = handlerList.value.reduce((sum, h) => {
      // 如果是当前正在操作的handler,就不要把它已有的趟次算进去
      if (h.garOrderHandlerTel === handler.garOrderHandlerTel) {
        return sum;
      }
      return sum + parseInt(h.garCarCount || 0);
    }, 0);

    const totalRequiredTrips = realCarCount.value || 0;

    if (allocatedTrips + handler.carCountInput > totalRequiredTrips) {
      uni.$u.toast(`分配趟次过多,最多只能再分配${totalRequiredTrips - allocatedTrips}趟!`);
      // 将输入框重置为之前的值
      handler.carCountInput = handler.garCarCount || 0;
      return;
    }
  }

  // 调用API传递订单ID和车辆数量(传递差值,可能是负数)
  const params = {
    carCount: delta, // 传递差值,可能是正数(增加)或负数(减少)
    tel: handler.garOrderHandlerTel,
    orderNo : orderNo.value
  };

  updateCarCount(params)
      .then(res => {
        if (res.data.success) {
          if (delta === 0) {
            uni.$u.toast('取消分配成功!');
          } else if (delta > 0) {
            uni.$u.toast('增加分配成功!');
          } else {
            uni.$u.toast('减少分配成功!');
          }
          // 刷新订单详情
          handleOrderDetail(orderId.value);
          refreshOrderData()
        } else {
          uni.$u.toast('操作失败!');
          // 将输入框重置为之前的值
          handler.carCountInput = handler.garCarCount || 0;
        }
      })
      .catch(err => {
        uni.$u.toast('操作失败');
        console.error('操作失败:', err);
        // 将输入框重置为之前的值
        handler.carCountInput = handler.garCarCount || 0;
      });
};

const confirmAddVehicles = () =>{
  const params = {
    carCount: carCount.value,
    tel: tel.value,
    orderNo : orderNo.value,
    orderCarType :selectedHandlerTels.value
  };
  if(selectedHandlerTels.value === ""){
    uni.$u.toast(`请选择车型!`);
    return;
  }
  insertRandomCopyByTypeAndOrderId(params).then(res => {
    if (res.data.success) {
      uni.$u.toast(`添加成功!`);
      // 刷新订单详情
      handleOrderDetail(orderId.value);
      refreshOrderData()
    } else {
      uni.$u.toast(`添加失败!`);
    }
  })
}



const confirmAddVehicle = () => {

  // 检查必填字段
  if (!carCount.value) {
    uni.$u.toast(`请选择分配的趟次!`);
    return;
  }
  if (!tel.value) {
    uni.$u.toast(`请选择分配人员!`);
    return;
  }


  if (selectedHandlerTel.value === 'ADD_TOTAL_TRIPS') {
    updateGarRealCarCount(orderId.value, carCount.value)
        .then(res => {
          if (res.data.success) {
            uni.$u.toast(`总趟次更新成功!`);
            // 刷新订单详情
            handleOrderDetail(orderId.value);
            refreshOrderData()
          } else {
            uni.$u.toast(`总趟次更新失败!`);
          }
        })
        .catch(err => {
          uni.$u.toast('总趟次更新请求失败');
          console.error('总趟次更新失败:', err);
        });
    return;
  }

  // 检查已分配趟次总和是否超过订单要求的总发车次数
  const allocatedTrips = handlerList.value.reduce((sum, handler) => sum + parseInt(handler.garCarCount || 0), 0);
  const totalRequiredTrips = realCarCount.value || 0;

  console.log('已分配趟次总和:', allocatedTrips);
  console.log('总需求趟次:', totalRequiredTrips);

  if (allocatedTrips >= totalRequiredTrips) {
    uni.$u.toast(`全部趟次已分配完成,无需再分配!`);
    return;
  }

  // 检查本次分配后是否会超过总发车次数
  if (allocatedTrips + carCount.value > totalRequiredTrips) {
    uni.$u.toast(`分配趟次过多,最多只能再分配${totalRequiredTrips - allocatedTrips}趟!`);
    return;
  }

  // 调用API传递订单ID和新增车辆数量
  const params = {
    carCount: carCount.value,
    tel: tel.value,
    orderNo : orderNo.value
  };

  updateCarCount(params)
      .then(res => {
        if (res.data.success) {
          uni.$u.toast(`分配成功!`);
          // 刷新订单详情
          handleOrderDetail(orderId.value);
          queryByOrderNo(orderNo.value).then(res => {
            if (res.data.success) {
              handlerList.value = res.data.data
            }
          }).catch(err => {
            console.error('获取订单信息失败:', err);
          })
        } else {
          uni.$u.toast(`分配失败!`);
        }
      })
      .catch(err => {
        uni.$u.toast('新增车辆请求失败');
        console.error('新增车辆失败:', err);
      });
};

const handlePopupClick = (val) => {
  carPopupShowFlag.value = val
}
// 创建二维码
const createQrCodeLocal = (orderId) => {
  // 获取本地地址拼接订单id
  showUQRcode.value = true;
  const hostname = window.location.hostname;
  const port = window.location.port;
  const protocol = window.location.protocol;
  const localAddress = `${protocol}//${hostname}:${port}`;
  // const localAddress = `http://localhost:5173`;
  qrCodeText.value = localAddress + "/pages/order-info/order-other/guest/index?orderId=" + orderId;
  console.log(qrCodeRef.value);
}
// 获取二维码
const handleQrCodeClick = (orderId) => {
  // 微信小程序可用
  // #ifdef MP-WEIXIN
  createQrCode(orderId).then((res) => {
    if (res.data.success) {
      uni.previewImage({
        urls: [res.data.data],
        longPressActions: {
          itemList: ['发送给朋友', '保存图片', '收藏'],
          success: function(res) {
            console.log('选中了第' + (res.tapIndex + 1) + '个按钮');
          },
          fail: function(res) {
            console.log(res);
          }
        }
      })
    }
  })
  // #endif
  // H5
  // #ifdef H5
  createQrCodeLocal(orderId)
  // #endif
}

const handleOrderDispatchClick = (orderId) => {
  // 获取订单车辆数量
  const orderCarCount = dataGram.value?.garCarInfoList?.length || 0;

  // 在调用API前验证token有效性
  const validateTokenAndCallAPI = async () => {
    try {
      // 检查当前token是否存在
      if (!store.token) {
        uni.$u.toast("登录已过期,请重新登录");
        // 跳转到登录页面
        uni.reLaunch({
          url: "/pages/login/code",
        });
        return;
      }

      // 获取驾驶员人员 - 添加时间戳避免缓存
      const timestamp = new Date().getTime();

      // 添加重试机制
      let retryCount = 0;
      const maxRetries = 2;

      const attemptRequest = async () => {
        try {
          const res = await queryOrderDispatch(`${orderId}?t=${timestamp}`);

          if (res.data.success) {
            // 过滤车辆  非用户选择的车辆无法选中
            driverPersonnelList.value = res.data.data;
            // 恢复原始的open调用方式,只传递dataList
            clashDriverDispatchRef.value.open(res.data.data);
            refreshOrderData();
          } else {
            uni.$u.toast("驾驶员分配成功!");
            refreshOrderData();
          }
        } catch (error) {
          console.error('获取驾驶员信息失败:', error);

          // 检查是否是token相关错误
          if (error.response && (error.response.status === 401 || error.response.status === 403)) {
            retryCount++;

            if (retryCount <= maxRetries) {
              console.log(`token可能已过期,正在进行第${retryCount}次重试`);

              // 清除当前token
              store.token = null;
              setRequestToken(null);
              uni.removeStorageSync("Authorization");

              // 跳转重新登录
              uni.$u.toast("登录已过期,请重新登录");
              setTimeout(() => {
                uni.reLaunch({
                  url: "/pages/login/code",
                });
              }, 1500);
              return;
            }
          }

          // 其他错误或重试次数用完
          uni.$u.toast("获取驾驶员信息失败,请稍后重试");
        }
      };

      await attemptRequest();

    } catch (error) {
      console.error('验证token时发生错误:', error);
      uni.$u.toast("系统错误,请重新登录");
      uni.reLaunch({
        url: "/pages/login/code",
      });
    }
  };

  // 执行验证和API调用
  validateTokenAndCallAPI();
}
const handleDisposalDispatchClick = (orderId) => {
  // 获取处置场所人员
  queryDisposalDispatch(orderId).then(res => {
    if (res.data.success) {
      disposalPersonnelList.value = res.data.data
      clashDisposalDispatchRef.value.open(res.data.data)
      refreshOrderData()
    } else {
      uni.$u.toast("处理场所分配成功!")
      refreshOrderData()
    }
  })
}



const handleClose = (e) => {
  cancelShow.value = false
}
const handleEvaluateDetail = (orderId, userType) => {
  uni.$u.route(`pages/order-info/order-other/evaluate-info/index`, {
    orderId: orderId,
    userType: userType
  })
}
const selectClick = (index) => {
  currentCancelName.value = index.name;
}
const handleOrderDetail = (orderId) => {
  queryOrderDetail(orderId).then(res => {
    dataGram.value = res.data.data;
    fetchDriverList(orderId);
    currentImages.value = res.data.data.currentImages.map(item => {
      return {
        url: import.meta.env.VITE_BASE_URL + item
      };
    });

    // 同时调用queryDisposalDispatch接口获取处理场所信息
    queryDisposalDispatch(orderId).then(disposalRes => {
      if (disposalRes.data.success && disposalRes.data.data && disposalRes.data.data.length > 0) {
        // 根据实际返回数据结构提取处理场所信息,只显示选中的联系人
        selectedDisposalSites.value = disposalRes.data.data
            .map(site => {
              // 筛选出personnelInfo中checked为true的联系人
              const selectedPerson = site.personnelInfo && site.personnelInfo.length > 0 ?
                  site.personnelInfo.find(person => person.checked) : null;

              return {
                companyName: site.garOrderDisposalCompanyName,
                contactName: selectedPerson ? selectedPerson.personName : '',
                contactPhone: selectedPerson ? selectedPerson.tel : ''
              };
            })
            // 过滤掉没有选中联系人的处理场所
            .filter(site => site.contactName && site.contactPhone);

        // 设置已分配状态
        disposalAssigned.value = selectedDisposalSites.value.length > 0;
        console.log('从queryDisposalDispatch获取的处理场所信息:', selectedDisposalSites.value);
      } else {
        selectedDisposalSites.value = [];
        disposalAssigned.value = false;
      }
    });

    putOnImages.value = res.data.data.putOnImages.map(item => {
      let processedItem = item;
      let carName = '';
      let carStatus = '';

      // 提取name后面的字符串作为carName并从item中移除
      if (item.includes('name')) {
        const nameIndex = item.indexOf('name');
        carName = item.substring(nameIndex + 4);

        // 检查carName末尾是否包含状态值(0或1)
        if (carName.endsWith('0') || carName.endsWith('1') || carName.endsWith('2')) {
          carStatus = carName.slice(-1);
          carName = carName.slice(0, -1);
        }

        processedItem = item.substring(0, nameIndex);
      }

      // 保持原有逻辑不变,但添加carName和carStatus到返回对象
      const newItem = processedItem.substring(0, processedItem.length - 6);
      const newIndex = processedItem.substring(processedItem.length - 6);
      return { url: import.meta.env.VITE_BASE_URL + newItem, newIndex, carName, carStatus };
    });

    // 按照newIndex升序排序
    putOnImages.value.sort((a, b) => {
      return parseInt(a.newIndex) - parseInt(b.newIndex);
    });

    // 重新组织数据,将相同newIndex的图片放在一起
    const groupedImages = {};
    putOnImages.value.forEach(item => {
      if (!groupedImages[item.newIndex]) {
        groupedImages[item.newIndex] = [];
      }
      groupedImages[item.newIndex].push(item);
    });

    // 转换newIndex为1,2,3的连续数字
    const sortedKeys = Object.keys(groupedImages).sort((a, b) => parseInt(a) - parseInt(b));
    const newGroupedImages = {};
    sortedKeys.forEach((key, index) => {
      newGroupedImages[index + 1] = groupedImages[key];
    });

    // 转换为数组形式,方便在模板中遍历
    putOnImagesGrouped.value = Object.keys(newGroupedImages).map(key => ({
      index: key,
      images: newGroupedImages[key],
      carName: newGroupedImages[key] && newGroupedImages[key].length > 0 ? newGroupedImages[key][0].carName : '',
      carStatus: newGroupedImages[key] && newGroupedImages[key].length > 0 ? newGroupedImages[key][0].carStatus : ''
    }));
    console.log('putOnImagesGrouped.value:', putOnImagesGrouped.value);
    putDownImages.value = res.data.data.putDownImages.map(item => {
      return {
        url: import.meta.env.VITE_BASE_URL + item
      };
    });
  })
}
/**
 * 拨打电话回调
 */
const handleContactClick = (val) => {
  uni.makePhoneCall({
    phoneNumber: val
  }).then(res => {}).catch(err => {});
}

const handlerJumpOtherApp = (latitude, longitude, garCoordinate) => {
  console.log(latitude + "=================>" + longitude);
  // 给出提示确定要跳转吗
  uni.showModal({
    title: '提示',
    content: '是否跳转到app定位进行导航?',
    success: function(res) {
      if (res.confirm) {
        uni.openLocation({
          latitude: latitude,
          longitude: longitude,
          success: function() {
            console.log('success');
          }
        });
      }
    }
  })
}

/**
 * 取消订单
 * @param {*} orderId 订单id
 */
const handleOderCancelClick = () => {
  cancelShow.value = true;
}

/**
 * 提交取消订单
 */
const submitFunction = (otherReason) => {
  let reason = otherReason
  if (currentCancelName.value != "其他") {
    reason = currentCancelName.value
  }
  if (!reason) {
    uni.$u.toast("请提供取消订单的原因")
    return
  }
  let params = {
    garOrderId: orderId.value,
    garCancelFlag: 1,
    garReason: reason
  }
  updateOrder(params).then(res => {
    if (res.data.success) {
      cancelShow.value = false
      uni.$u.toast(res.data.data)
      uni.$u.route({
        type: "reLaunch",
        url: `pages/order/index`,
      })
    }
  })
}
// 提交完成
const handleSubmitSuccess = (orderId) => {
  uni.showModal({
    title: '提示',
    content: '订单已经清运完成了吗?',
    success: function(res) {
      if (res.confirm) {
        updateOrder({
          garOrderId: orderId,
          handleType: 3
        }).then(res => {
          if (res.data.success) {
            uni.$u.toast("已完成")
            handleOrderDetail(orderId)
          }
        })
      } else if (res.cancel) {}
    }
  });
}
const handleEvaluate = (orderId, userType) => {
  uni.$u.route(`pages/order-info/order-other/evaluate/index?orderId=${orderId}&userType=${userType}`)
}

// 接收订单
// 接收订单
const handleOrder = (orderId) => {
  // 在开始运输前先分配驾驶员(如果有待分配的驾驶员)
  if (pendingDriverAssignments.value && Object.keys(pendingDriverAssignments.value).length > 0) {
    let driverData = {
      garOrderId: orderId,
      dispatchList: []
    }
    for (const key in pendingDriverAssignments.value) {
      driverData.dispatchList.push({
        ...pendingDriverAssignments.value[key]
      });
    }

    dispatchOrders(driverData).then(driverRes => {
      if (driverRes.data.success) {
        // 清空待分配列表
        pendingDriverAssignments.value = {};
        // 标记驾驶员已分配
        driverAssigned.value = true;

        // 然后分配处置场所(如果有待分配的处置场所)
        if (pendingDisposalAssignments.value && Object.keys(pendingDisposalAssignments.value).length > 0) {
          let disposalData = {
            garOrderId: orderId,
            dispatchList: []
          }
          for (const key in pendingDisposalAssignments.value) {
            disposalData.dispatchList.push({
              ...pendingDisposalAssignments.value[key]
            });
          }

          dispatchDisposalOrders(disposalData).then(disposalRes => {
            if (disposalRes.data.success) {
              // 清空待分配列表
              pendingDisposalAssignments.value = {};
              // 标记处置场所已分配
              disposalAssigned.value = true;

              // 然后更新订单状态为开始运输
              updateOrder({
                garOrderId: orderId,
                handleType: 0
              }).then(res => {
                if (res.data.success) {
                  if (res.data.data === "订单已经被别人接受啦") {
                    uni.$u.toast(res.data.data)
                    uni.$u.route({
                      type: "reLaunch",
                      url: `pages/order/index`,
                    })
                  } else {
                    uni.$u.toast(res.data.data)
                    handleOrderDetail(orderId)
                    refreshOrderData()
                  }
                }
              })
            } else {
              uni.$u.toast("指定处置场所失败,请重试");
            }
          })
        } else {
          // 没有待分配的处置场所,直接更新订单状态为开始运输
          updateOrder({
            garOrderId: orderId,
            handleType: 0
          }).then(res => {
            if (res.data.success) {
              if (res.data.data === "订单已经被别人接受啦") {
                uni.$u.toast(res.data.data)
                uni.$u.route({
                  type: "reLaunch",
                  url: `pages/order/index`,
                })
              } else {
                uni.$u.toast(res.data.data)
                handleOrderDetail(orderId)
                refreshOrderData()
              }
            }
          })
        }
      } else {
        uni.$u.toast("指定人员失败,请重试");
      }
    })
  } else {
    // 没有待分配的驾驶员,检查是否有待分配的处置场所
    if (pendingDisposalAssignments.value && Object.keys(pendingDisposalAssignments.value).length > 0) {
      let disposalData = {
        garOrderId: orderId,
        dispatchList: []
      }
      for (const key in pendingDisposalAssignments.value) {
        disposalData.dispatchList.push({
          ...pendingDisposalAssignments.value[key]
        });
      }

      dispatchDisposalOrders(disposalData).then(disposalRes => {
        if (disposalRes.data.success) {
          // 清空待分配列表
          pendingDisposalAssignments.value = {};
          // 标记处置场所已分配
          disposalAssigned.value = true;

          // 然后更新订单状态为开始运输
          updateOrder({
            garOrderId: orderId,
            handleType: 0
          }).then(res => {
            if (res.data.success) {
              if (res.data.data === "订单已经被别人接受啦") {
                uni.$u.toast(res.data.data)
                uni.$u.route({
                  type: "reLaunch",
                  url: `pages/order/index`,
                })
              } else {
                uni.$u.toast(res.data.data)
                handleOrderDetail(orderId)
                refreshOrderData()
              }
            }
          })
        } else {
          uni.$u.toast("指定处置场所失败,请重试");
        }
      })
    } else {
      // 没有待分配的驾驶员和处置场所,直接开始运输
      updateOrder({
        garOrderId: orderId,
        handleType: 0
      }).then(res => {
        if (res.data.success) {
          if (res.data.data === "订单已经被别人接受啦") {
            uni.$u.toast(res.data.data)
            uni.$u.route({
              type: "reLaunch",
              url: `pages/order/index`,
            })
          } else {
            uni.$u.toast(res.data.data)
            handleOrderDetail(orderId)
            refreshOrderData()
          }
        }
      })
    }
  }
}


const currentStep = (step) => {
  if (step > 2) {
    return step - 1;
  }
  return step;
}

/**
 * 清运状态
 * @param {*} status
 */
const cleanStatus = (status) => {
  if (dataGram.garCancelFlag === 1) {
    return '取消清运';
  }
  switch (status) {
    case 0:
      return '准备清运';
    case 1:
      return '正在清运';
    case 3:
      return '清运完成';
  }
}

const handleDisposalDispatchConfirm = (val) => {
  console.log(val);
  if (!val) {
    return;
  }

  // 判断是否是重新分配(订单状态为1)
  const isReassigning = dataGram.value?.garOrderHandlerStatus === 1;

  if (isReassigning) {
    // 如果是重新分配,直接调用接口分配处置场所
    let data = {
      garOrderId: orderId.value,
      dispatchList: []
    }

    // 新增:存储选中的处理场所信息
    selectedDisposalSites.value = [];

    for (const key in val) {
      data.dispatchList.push({
        ...val[key]
      });

      // 新增:提取处理场所信息
      selectedDisposalSites.value.push({
        companyName: val[key].companyName,
        contactName: val[key].personName,
        contactPhone: val[key].tel
      });
    }
    console.log(data);
    dispatchDisposalOrders(data).then(res => {
      if (res.data.success) {
        uni.$u.toast(res.data.msg)
        // 标记处置场所已分配
        disposalAssigned.value = true;
        // 检查是否两个任务都已完成
        // 立即刷新订单详情以确保分配信息得到保存
        handleOrderDetail(orderId.value);
      } else {
        uni.$u.toast("指定人员失败,请重试")
      }
      clashDisposalDispatchRef.value.close()
    })
  } else {
    // 初次分配,将待分配的处置场所存储起来,但不立即调用后端接口
    pendingDisposalAssignments.value = { ...val };

    // 新增:存储选中的处理场所信息
    selectedDisposalSites.value = [];

    for (const key in val) {
      // 新增:提取处理场所信息
      selectedDisposalSites.value.push({
        companyName: val[key].companyName,
        contactName: val[key].personName,
        contactPhone: val[key].tel
      });
    }

    // 显示提示信息
    uni.$u.toast("处置场所已选择,将在开始运输时分配");

    // 关闭弹窗
    clashDisposalDispatchRef.value.close();
  }
}


const handlerUpdateOrderClick = () => {
  carPopupShowFlag.value = true;
  // TODO  照搬一键清运得弹窗
  console.log("点击了修改订单按钮");
  // TODO
  queryCarList({
    companyId: dataGram.value.garOrderCompanyId
  }).then(res => {
    // 设置车辆类型
    candidates.value = [
      [...new Set(res.data.rows
          .filter(item => item.containerVolume)
          .map(item => {
            garCarLabelInfoList.value[item.carType] = item
            return item.carType
          }))]
    ];
    // 设置初始车辆数量
    candidates.value[0].forEach((item, index) => {
      garCarInfoList.value[item] = {
        garOrderCarNumber: 1,
        garOrderCarType: item,
        id: garCarLabelInfoList.value[item].id,
        containerVolume: garCarLabelInfoList.value[item].containerVolume
      }
    })
    // 设置默认车辆
    paramFrom.value.carType = candidates.value[0][0];
    garCarLabelInfoNow.value = garCarLabelInfoList.value[paramFrom.value.carType]
    console.log(garCarLabelInfoList.value, garCarInfoList.value, paramFrom.value.carType);
  })
}

// 指定人员

// 指定人员
const handleDriverDispatchConfirm = (val) => {
  console.log(val);
  if (!val) {
    return;
  }

  // 获取订单车辆数量
  const orderCarCount = dataGram.value?.garCarInfoList?.length || 0;

  // 计算选择的驾驶员数量
  const selectedDriverCount = Object.keys(val).length;

  // 检查驾驶员数量是否超过订单车辆数量
  if (selectedDriverCount > orderCarCount) {
    jumpPrompt(`选择的驾驶员数量不能超过${orderCarCount}个`);
    return;
  }

  // 判断是否是重新分配(订单状态为1)
  const isReassigning = dataGram.value?.garOrderHandlerStatus === 1;

  if (isReassigning) {
    // 如果是重新分配,直接调用接口分配驾驶员
    let data = {
      garOrderId: orderId.value,
      dispatchList: []
    }
    for (const key in val) {
      data.dispatchList.push({
        ...val[key]
      });
    }

    dispatchOrders(data).then(res => {
      if (res.data.success) {
        uni.$u.toast("驾驶员重新分配成功");
        // 更新界面数据
        handleOrderDetail(orderId.value);
        refreshOrderData();
        // 标记驾驶员已分配
        driverAssigned.value = true;
      } else {
        uni.$u.toast("指定人员失败,请重试");
      }
      clashDriverDispatchRef.value.close();
    });
  } else {
    // 初次分配,将待分配的驾驶员存储起来,但不立即调用后端接口
    pendingDriverAssignments.value = { ...val };

    // 显示提示信息
    uni.$u.toast("驾驶员已选择,将在开始运输时分配");

    // 关闭弹窗
    clashDriverDispatchRef.value.close();
  }
}

const submitUpdateCarInfo = () => {
  let garCarInfos = [];
  for (const key in garCarInfoList.value) {
    garCarInfos.push(garCarInfoList.value[key])
  }

  let data = {
    garOrderId: orderId.value,
    garCarInfoList: garCarInfos,
    updated: true
  }
  if (dataGram.value.garOrderAgreementTime) {
    let index = dataGram.value.garOrderAgreementTime.indexOf(' ') + 1;
    if (index > 0) {
      let val = dataGram.value.garOrderAgreementTime.substring(index, dataGram.value.garOrderAgreementTime
          .length);


      if (val == "07:00-08:00" || val == "08:00-09:00" || val == "09:00-10:00" || val == "10:00-11:00" ||
          val == "11:00-12:00" || val == "12:00-13:00" || val == "13:00-14:00" ||
          val == "14:00-15:00" || val == "15:00-16:00" || val == "16:00-17:00" || val == "17:00-18:00" ||
          val == "18:00-19:00" || val == "19:00-20:00" || val == "20:00-21:00" ||
          val == "21:00-22:00") {
        let size = garCarInfos.length;
        for (let index = 0; index < size; index++) {
          if ((garCarInfos[index].containerVolume == "8" || parseInt(garCarInfos[index]
              .containerVolume) >= 8) && garCarInfos[index].garOrderCarNumber > 0) {
            console.log(garCarInfos[index]);

            jumpPrompt("中大型车辆只能选择22:00-07:00时间段");
            return;
          }

        }
      }

    }

  }
  console.log(dataGram.value.garOrderAgreementTime);
  console.log(garCarInfos);
  console.log("=================================>");


  updateOrder(data).then(res => {
    if (res.data.code == 200) {
      uni.$u.toast("车辆信息修改成功")
      // 更新数据
      handleOrderDetail(orderId.value)
      // 关闭弹窗
      carPopupShowFlag.value = false
    }
  }).catch(err => {
    uni.$u.toast("修改失败,请重试")
  })
}

const showNavDialog = (longitude, latitude, locationName) => {
  // 校验经纬度有效性
  if (!longitude || !latitude) {
    uni.$u.toast('暂无有效导航坐标');
    return;
  }

  uni.showActionSheet({
    itemList: ['高德导航', '百度导航'],
    success: function (res) {
      if (res.tapIndex === 0) {
        // 调用你原来的高德导航方法
        handlerJumpGaoDeApp(longitude, latitude, locationName);
      } else if (res.tapIndex === 1) {
        // 调用你原来的百度导航方法
        handlerJumpBaiDuApp(longitude, latitude, locationName);
      }
    },
    fail: function (res) {
      console.log('取消导航选择:', res.errMsg);
    }
  });
};
// ===== 新增结束 =====

const handlerJumpGaoDeApp = (longitude,latitude,locationName) => {
  window.location.href =`https://uri.amap.com/marker?position=${longitude},${latitude}&name=${locationName}`;
}

const handlerJumpBaiDuApp = (longitude,latitude,locationName) => {
  window.location.href =`http://api.map.baidu.com/marker?location=${longitude},${latitude}&title=${locationName}&output=html`;
}


const deleteHandler = (handler) => {
  uni.showModal({
    title: '确认删除',
    content: `确定要删除处理人员 ${handler.garOrderHandlerName} 吗?`,
    success: function (res) {
      if (res.confirm) {
        deleteDriverByOrderNo(orderNo.value, handler.garHandlerCarCode).then(res => {
          if (res.data.success) {
            uni.$u.toast('删除成功');
            // 重新加载处理人员信息
            refreshOrderData();
            // 重新获取驾驶员列表
            fetchDriverList(orderId.value);
          } else {
            uni.$u.toast('删除失败: ' + res.data.msg);
          }
        }).catch(err => {
          uni.$u.toast('删除失败');
          console.error('删除处理人员失败:', err);
        });
      }
    }
  });
};


const jumpPrompt = (msg) => {
  uni.showModal({
    title: '提示',
    content: msg,
    showCancel: false,
    success: function(res) {
      if (res.confirm) {} else if (res.cancel) {}
    }
  });
}
const showLeftButtons = computed(() => {
  return (dataGram.value?.garOrderHandlerStatus === 0 && userType.value == '运输企业负责人' && dataGram.value?.garCancelFlag === 0) ||
      (dataGram.value?.garOrderScanHandlerFlag === 0 && userType.value == '用户' && dataGram.value?.garOrderHandlerStatus != 3 && dataGram.value?.garAskStatus != '1');
});

const showCenterButtons = computed(() => {
  return (dataGram.value?.garOrderHandlerStatus === 0 && userType.value == '运输企业负责人' && dataGram.value?.handleFlag && dataGram.value?.garCancelFlag === 0) ||
      (dataGram.value?.garOrderHandlerStatus === 1 && userType.value == '运输企业负责人') ||
      (dataGram.value?.garOrderHandlerStatus === 1 && userType.value == '运输企业负责人' && isAllTripsCompleted());
});

const showRightButtons = computed(() => {
  return (dataGram.value?.garOrderHandlerStatus === 0 && userType.value == '用户' && dataGram.value?.garCancelFlag === 0) ||
      (dataGram.value?.garEvaluateFlag === 0 && userType.value === '用户') ||
      (dataGram.value?.garHandlerEvaluateFlag === 0 && userType.value === '运输企业负责人' && dataGram.value?.haveEvaluateOfClient == 1) ||
      (dataGram.value?.garHandlerEvaluateFlag === 1 && userType.value === '运输企业负责人' && dataGram.value?.haveEvaluateOfClient == 1) ||
      (dataGram.value?.garEvaluateFlag === 1 && userType.value === '用户');
});

const showTopButtons = computed(() => {
  return (dataGram.value?.garOrderHandlerStatus === 0 && userType.value == '运输企业负责人' && dataGram.value?.handleFlag && dataGram.value?.garCancelFlag === 0) ||
      (dataGram.value?.garOrderHandlerStatus === 1 && userType.value == '运输企业负责人' && !isAllTripsCompleted()) ||
      (dataGram.value?.garOrderHandlerStatus === 1 && userType.value == '运输企业负责人' && isAllTripsCompleted());
});
/**
 * 初始化信息
 */
onLoad((options) => {
  orderId.value = options.orderId
  orderNo.value = options.orderId
  handleOrderDetail(orderId.value)
  refreshOrderData()
})

onShow(() => {
  try {
    if (isOnloadIn.value) {
      handleOrderDetail(orderId.value)
    } else {
      isOnloadIn.value = true
    }
  } catch (error) {
    console.log(error);
  }
})
</script>


<style lang="scss" scoped>
$custom-marin-bottom: 20rpx;
$custom-page-padding: 20rpx;
$custom-border-radio: 20rpx;
$custom-bottom-height: 200rpx;

@mixin card {
  padding: $custom-page-padding;
  box-sizing: border-box;
  background-color: #ffffff;
  border-radius: $custom-border-radio;
  margin-bottom: $custom-marin-bottom;
}

.order-detail-bottom {
  position: fixed;
  width: 100%;
  bottom: 0;
  left: 0;
  background-color: #fff;
  box-shadow: 0 -2rpx 10rpx rgba(0,0,0,0.05);
  padding: 20rpx $custom-page-padding;
  box-sizing: border-box;

  .order-detail-bottom-box {
    display: flex;
    flex-direction: column;
    gap: 20rpx;

    .order-detail-top-buttons {
      width: 100%;

      .button-group-wrap,
      .button-group-spread {
        display: flex;
        gap: 20rpx;
        width: 100%;

        u-button {
          flex: 1;
          height: 72rpx;
          line-height: 72rpx;
          font-size: 26rpx;
          padding: 0 20rpx;
          border-radius: 36rpx;
        }
      }

      .button-group-spread {
        justify-content: space-between;

        .btn-left,
        .btn-right {
          flex: 1;
        }
      }
    }

    .order-detail-bottom-buttons {
      display: flex;
      flex-direction: column;
      width: 100%;
      gap: 20rpx;

      .cancel-button-container {
        width: 100%;

        u-button {
          width: 100%;
          height: 72rpx;
          line-height: 72rpx;
          font-size: 26rpx;
          border-radius: 36rpx;
        }
      }

      .evaluation-buttons-container {
        display: flex;
        gap: 20rpx;

        u-button {
          flex: 1;
          height: 72rpx;
          line-height: 72rpx;
          font-size: 26rpx;
          border-radius: 36rpx;
        }
      }
    }
  }
}

.order-detail-container {
  height: 100%;
  width: 100%;
  background-color: $u-info-light;
  box-sizing: border-box;
  overflow-y: scroll;
  background: linear-gradient(to bottom, #19a97c, $u-info-light, $u-info-light, $u-info-light);


  .order-detail-container-box {
    height: 100%;
    width: 100%;
    padding: $custom-page-padding;
    box-sizing: border-box;

    .order-detail-top {
      @include card();

      .order-detail-top-box {
        .order-detail-top-box-step {
          u-steps {
            u-steps-item {}
          }
        }
      }
    }


    .order-detail-container-box-card {
      @include card();

      .order-detail-container-header-card-title {
        font-weight: bold;
        line-height: 80rpx;
        border-bottom: 3rpx solid $u-info-light;
        margin-bottom: $custom-marin-bottom;
        color: $u-primary;
        display: flex;
        align-items: center;

        .order-detail-container-header-card-uicon {
          background-color: $u-primary;
          margin-right: 10rpx;
          height: 35rpx;
          width: 15rpx;
          border-radius: 4rpx;
        }
      }

      /* 订单信息标题特殊样式 */
      .order-info-header {
        display: flex;
        align-items: center;
        background: linear-gradient(90deg, #19a97c, #19a97c80);
        color: white;
        padding: 15rpx;
        border-radius: 10rpx;
        margin-bottom: 15rpx;

        .order-detail-container-header-card-uicon {
          background-color: white;
          opacity: 0.8;
          margin-right: 8rpx;
          height: 25rpx;
          width: 6rpx;
          border-radius: 3rpx;
        }

        .title-text {
          font-size: 28rpx;
          font-weight: bold;
        }
      }

      .order-detail-container-header-item {
        display: flex;
        margin-bottom: $custom-marin-bottom;

        .order-detail-container-header-title {
          color: $u-main-color;
          white-space: nowrap;
          color: $u-info;
        }

        .order-detail-container-header-content {
          display: flex;
        }
      }
    }

    /* 车辆信息板块美化 */

    /* 车辆信息板块美化 */
    .vehicle-section {
      .section-header {
        display: flex;
        align-items: center;
        background: linear-gradient(90deg, #19a97c, #19a97c80);
        color: white;
        padding: 15rpx; /* 减小内边距 */
        border-radius: 10rpx; /* 减小圆角 */
        margin-bottom: 15rpx; /* 减小外边距 */

        .header-icon-bar {
          background-color: white;
          opacity: 0.8;
          margin-right: 8rpx; /* 减小右边距 */
          height: 25rpx; /* 减小高度 */
          width: 6rpx; /* 减小宽度 */
          border-radius: 3rpx;
        }

        .header-title {
          font-size: 28rpx; /* 减小字体大小 */
          font-weight: bold;
        }
      }

      /* 卡片通用样式 */
      .trip-summary-card, .vehicle-info-card, .driver-info-card, .handler-list-card, .assign-trip-card {
        background-color: #fff;
        border-radius: 10rpx; /* 减小圆角 */
        box-shadow: 0 1rpx 8rpx rgba(0, 0, 0, 0.05); /* 减小阴影 */
        margin-bottom: 15rpx; /* 减小外边距 */
        overflow: hidden;
      }

      .card-header {
        display: flex;
        align-items: center;
        padding: 15rpx; /* 减小内边距 */
        background-color: #f5f5f5;
        border-bottom: 1rpx solid #eee;

        .card-title {
          font-weight: bold;
          color: #333;
          margin-left: 8rpx; /* 减小左边距 */
          font-size: 26rpx; /* 减小字体大小 */
        }
      }

      /* 发车次数摘要 */
      .trip-summary-card {
        /* 现有的 summary-content 样式保持不变 */
        .summary-content {
          display: flex;
          align-items: center;
          padding: 20rpx 15rpx;
          background: linear-gradient(90deg, #e8f4f0, #fff);

          .summary-label {
            color: #666;
            margin-right: 8rpx;
            font-size: 24rpx;
          }

          .summary-value {
            color: #19a97c;
            font-weight: bold;
            font-size: 28rpx;
            margin: 0 4rpx;
          }

          .summary-unit {
            color: #666;
            font-size: 24rpx;
          }
        }

        /* 添加 reduce-trip-section 的样式 */
        /* 添加 reduce-trip-section 的样式 */
        .reduce-trip-section {
          display: flex;
          flex-wrap: wrap; /* 允许内容换行 */
          justify-content: space-between; /* 两端对齐,使右侧控件靠右 */
          align-items: center;
          padding: 20rpx 15rpx;
          border-top: 1rpx solid #e8f4f0;

          .reduce-label {
            color: #666;
            font-size: 24rpx;
            min-width: 120rpx; /* 固定标签宽度,防止换行 */
          }

          /* 右侧控件容器 */
          .right-controls {
            display: flex;
            align-items: center;
          }

          /* 为按钮添加样式 */
          .u-button {
            max-width: 120rpx; /* 限制按钮最大宽度 */
            font-size: 20rpx; /* 减小字体大小 */
            padding: 0 10rpx; /* 调整内边距 */
          }
        }
      }

      /* 车辆类型详情 */
      .vehicle-info-card {
        .car-type-list {
          padding: 15rpx; /* 减小内边距 */

          .car-type-item {
            display: flex;
            flex-wrap: wrap;
            padding: 15rpx; /* 减小内边距 */
            background-color: #f8f8f8;
            border-radius: 6rpx; /* 减小圆角 */
            margin-bottom: 10rpx; /* 减小外边距 */

            &:last-child {
              margin-bottom: 0;
            }

            .car-type-info, .car-count-info {
              display: flex;
              align-items: center;
              width: 100%;
              margin-bottom: 8rpx; /* 减小外边距 */

              &:last-child {
                margin-bottom: 0;
              }

              .info-label {
                color: #666;
                margin: 0 8rpx; /* 减小边距 */
                font-size: 24rpx; /* 减小字体大小 */
                min-width: 80rpx; /* 减小最小宽度 */
              }

              .info-value {
                color: #333;
                font-weight: 500;
                font-size: 24rpx; /* 减小字体大小 */
              }
            }
          }
        }
      }

      /* 驾驶员信息 */
      .driver-info-card {
        .driver-list {
          padding: 15rpx; /* 减小内边距 */

          .driver-item {
            padding: 15rpx; /* 减小内边距 */
            background-color: #f8f8f8;
            border-radius: 6rpx; /* 减小圆角 */
            margin-bottom: 10rpx; /* 减小外边距 */

            &:last-child {
              margin-bottom: 0;
            }

            .driver-basic-info, .driver-car-info {
              display: flex;
              align-items: center;
              margin-bottom: 8rpx; /* 减小外边距 */

              &:last-child {
                margin-bottom: 0;
              }

              .info-label {
                color: #666;
                margin: 0 8rpx; /* 减小边距 */
                font-size: 24rpx; /* 减小字体大小 */
                min-width: 100rpx; /* 减小最小宽度 */
              }

              .info-value {
                color: #333;
                font-weight: 500;
                font-size: 24rpx; /* 减小字体大小 */
              }
            }

            .driver-status {
              text-align: right;
              margin-top: 8rpx; /* 减小外边距 */
            }
          }
        }
      }

      /* 处理人员信息 */
      .handler-list-card {
        .handler-item {
          display: flex;
          justify-content: space-between;
          align-items: center;
          padding: 15rpx; /* 减小内边距 */
          border-bottom: 1rpx solid #eee;

          &:last-child {
            border-bottom: none;
          }

          .handler-basic-info {
            display: flex;
            flex-direction: column;

            .handler-name {
              font-weight: bold;
              font-size: 26rpx; /* 减小字体大小 */
              color: #333;
              margin-bottom: 4rpx; /* 减小外边距 */
            }

            .handler-car, .handler-volume {
              font-size: 22rpx; /* 减小字体大小 */
              color: #666;
              margin-right: 10rpx; /* 减小右边距 */
            }
          }

          .handler-trip-count {
            display: flex;
            flex-direction: column;
            align-items: flex-end;

            .count-label {
              font-size: 22rpx; /* 减小字体大小 */
              color: #666;
              margin-bottom: 4rpx; /* 减小外边距 */
            }

            .count-value {
              font-weight: bold;
              color: #19a97c;
              font-size: 26rpx; /* 减小字体大小 */
            }
          }

          .handler-trip-controls {
            display: flex;
            align-items: center;
            gap: 10rpx;

            .assign-button {
              padding: 0 15rpx;
              font-size: 22rpx;
              height: 50rpx;
              line-height: 50rpx;
            }
            .delete-button {
              padding: 0 15rpx;
              font-size: 22rpx;
              height: 50rpx;
              line-height: 50rpx;
            }
          }
        }
      }

      /* 分配趟次 */
      .assign-trip-card {
        .assign-content {
          padding: 15rpx; /* 减小内边距 */

          .selector-wrapper, .number-box-wrapper {
            display: flex;
            align-items: center;
            margin-bottom: 15rpx; /* 减小外边距 */

            &:last-child {
              margin-bottom: 0;
            }

            .selector-label, .number-label {
              width: 140rpx; /* 减小宽度 */
              font-size: 24rpx; /* 减小字体大小 */
              color: #333;
            }

            .handler-selector {
              flex: 1;
              height: 40rpx; /* 减小高度 */
              border: 1px solid #DCDFE6;
              border-radius: 4px;
              padding: 0 8rpx; /* 减小内边距 */
              outline: none;
              font-size: 24rpx; /* 减小字体大小 */
            }
          }

          .confirm-button {
            width: 100%;
            border-radius: 6rpx; /* 减小圆角 */
            font-size: 26rpx; /* 减小字体大小 */
            height: 40rpx; /* 减小高度 */
          }
        }
      }
    }
  }


  .space-box {
    padding-bottom: $custom-bottom-height;
    margin-bottom: 40rpx;
  }


  .order-detail-bottom {
    position: fixed; // 改为fixed定位,确保始终在底部
    width: 100%;
    bottom: 0;
    left: 0;
    background-color: #fff; // 添加背景色,避免穿透
    box-shadow: 0 -2rpx 10rpx rgba(0,0,0,0.05); // 添加阴影,提升层次感
    padding: 20rpx $custom-page-padding; // 上下内边距,左右和页面一致
    box-sizing: border-box;

    .order-detail-bottom-box {
      height: auto; // 取消固定高度,自适应内容
      padding: 0; // 移除原有内边距
      display: flex;
      flex-wrap: wrap; // 允许换行
      gap: 16rpx; // 按钮之间统一间距
      align-items: center;
    }

    .button-group-vertical {
      display: flex;
      flex-direction: column;
      gap: 20rpx;
      width: 100%;
    }

    // 左中右三个区域统一处理
    .order-detail-bottom-left,
    .order-detail-bottom-center,
    .order-detail-bottom-right {
      min-width: auto; // 取消最小宽度限制
      flex: 1; // 三个区域平均分配宽度
      display: flex;
      justify-content: center;
      align-items: center;
    }

    // 左侧区域单独处理(取消订单按钮)
    .order-detail-bottom-left {
      justify-content: flex-start;
      flex-direction: column;
      align-items: flex-start;
    }

    // 右侧区域单独处理(评价相关按钮)
    .order-detail-bottom-right {
      justify-content: flex-end;
    }
  }

  // 中间按钮组优化(分配/处理订单按钮)
  .order-detail-bottom-center {
    .button-group-wrap {
      display: flex;
      flex-wrap: wrap; // 超出时自动换行
      gap: 16rpx; // 按钮之间间距
      justify-content: center;
      width: 100%;
    }

    // 单个按钮样式统一优化
    u-button {
      flex: 0 0 auto; // 不自动拉伸
      min-width: 180rpx; // 最小宽度,确保按钮不会太窄
      max-width: 240rpx; // 最大宽度,避免过宽
      height: 72rpx; // 统一按钮高度
      line-height: 72rpx; // 垂直居中
      font-size: 26rpx; // 字体大小优化
      padding: 0 20rpx;
      border-radius: 36rpx; // 圆角优化,更美观
    }

    // 重新分配按钮组样式
    .button-group-spread {
      display: flex;
      justify-content: space-between;
      align-items: center;
      width: 100%;
      gap: 16rpx; // 中间间距
    }
  }

  // 适配小屏幕,当按钮过多时自动换行
  @media (max-width: 375px) {
    .order-detail-bottom-box {
      gap: 12rpx;
    }

    .order-detail-bottom-center u-button {
      min-width: 160rpx;
      font-size: 24rpx;
      height: 68rpx;
      line-height: 68rpx;
    }
  }
}

.mask-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 999;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
}

// 弹出框
.company-clean-container-car-popup {
  min-height: 450rpx;
  padding: $custom-page-padding;
  box-sizing: border-box;

  .company-clean-container-car-popup-content {
    font-size: 28rpx;

    .company-clean-container-car-popup-content-box {
      box-sizing: border-box;
      padding: $custom-page-padding;
      border: 2rpx solid #19a97c;
      border-radius: 10rpx;

      .company-clean-container-car-popup-content-box-item {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin: 20rpx 0;
        box-sizing: border-box;

        .company-clean-container-car-popup-content-box-item-text {}

        .company-clean-container-car-popup-content-box-item-number {}
      }
    }

    .company-clean-container-car-popup-content-title {
      color: $u-main-color;
      box-sizing: border-box;
      margin-bottom: 20rpx;
      font-size: 30rpx;
      font-weight: bold;
    }
  }

  .company-clean-container-car-popup-button-safe {
    width: 100%;
    height: $custom-bottom-height;
    box-sizing: border-box;
    padding: 20rpx;

    .company-clean-container-car-popup-button-safe-btn {
      width: 100%;
      height: 100%;
      border-radius: 10rpx;
      font-size: 30rpx;
      line-height: 100rpx;
      text-align: center;
    }
  }
}
.image-group {
  margin-bottom: 20px;
  padding: 10px;
  background-color: #f5f5f5;
  border-radius: 5px;
}

.image-group-title {
  margin-bottom: 10px;
  font-weight: bold;
  color: #333;
}

/* 确保u-upload组件内的图片水平排列 */
.image-group .u-upload {
  display: flex;
  flex-wrap: wrap;
}
.image-group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10rpx;
}

.car-status {
  padding: 4rpx 12rpx;
  border-radius: 6rpx;
  font-size: 24rpx;
  font-weight: bold;

  &.in-transit {
    background-color: #fff7e6;
    color: #ff9900;
  }

  &.completed {
    background-color: #e6f7ff;
    color: #19a97c;
  }
}
.driver-list-popup {
  min-height: 400rpx;
  max-height: 800rpx;
  padding: $custom-page-padding;
  box-sizing: border-box;

  .driver-list-popup-header {
    text-align: center;
    margin-bottom: 30rpx;

    .driver-list-popup-title {
      font-size: 32rpx;
      font-weight: bold;
      color: $u-main-color;
    }
  }

  .driver-list-popup-content {
    max-height: 600rpx;
    overflow-y: auto;

    .driver-item {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 20rpx 0;
      border-bottom: 1rpx solid $u-border-color;

      .driver-info {
        display: flex;
        flex-direction: column;

        .driver-name {
          font-size: 28rpx;
          font-weight: bold;
          margin-bottom: 10rpx;
        }

        .driver-phone {
          font-size: 24rpx;
          color: $u-tips-color;
        }
      }
    }
  }

  .driver-list-popup-footer {
    margin-top: 30rpx;
    text-align: center;
  }
}
.driver-info-container {
  .driver-info-row {
    display: flex;
    flex-wrap: wrap;
    padding: 10rpx 0;
    border-bottom: 1rpx solid $u-border-color;
    justify-content: flex-start;

    .driver-name, .car-code {
      margin-right: 20rpx;
      color: $u-main-color;
    }

    .driver-name {
      font-weight: bold;
    }
  }

  .driver-info-row:last-child {
    border-bottom: none;
  }
}

/* 车辆类型列表样式 */
.car-type-info-container {
  .car-type-info-header {
    font-weight: bold;
    color: $u-primary;
    margin-bottom: 20rpx;
    padding-bottom: 15rpx;
    border-bottom: 2rpx solid $u-primary;
    display: flex;
    align-items: center;

    .header-icon {
      display: inline-block;
      width: 6rpx;
      height: 30rpx;
      background-color: $u-primary;
      border-radius: 3rpx;
      margin-right: 15rpx;
    }
  }

  .car-type-info-row {
    display: flex;
    flex-direction: column;
    padding: 20rpx 15rpx;
    background-color: #f8f8f8;
    border-radius: 12rpx;
    margin-bottom: 15rpx;
    box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);

    .car-info-item {
      display: flex;
      align-items: center;
      margin-bottom: 10rpx;

      &:last-child {
        margin-bottom: 0;
      }

      .car-type-label, .car-count-label {
        font-weight: 500;
        color: #666;
        margin-right: 10rpx;
        width: 100rpx;
      }

      .car-type-value, .car-count-value {
        color: $u-main-color;
        font-weight: bold;
      }

      .car-count-value {
        color: $u-primary;
      }
    }

    &:last-child {
      margin-bottom: 0;
    }
  }
}

/* 订单信息板块样式 */
.order-info-section {
  .info-item {
    display: flex;
    padding: 15rpx;
    background-color: #f8f8f8;
    border-radius: 6rpx;
    margin-bottom: 10rpx;

    &:last-child {
      margin-bottom: 0;
    }

    .info-label {
      display: flex;
      align-items: center;
      min-width: 140rpx;
      color: #666;
      font-size: 24rpx;
    }

    .info-content {
      flex: 1;
      display: flex;
      align-items: center;
      color: #333;
      font-size: 24rpx;

      .content-text {
        flex: 1;
      }

      .qr-code-icon {
        margin-left: 10rpx;
      }
    }
  }

  /* 处置场地特殊处理 */
  .info-item:nth-child(n+5):nth-child(-n+7) {
    .info-label {
      min-width: 140rpx;
    }
  }
}

/* 订单人员板块样式 */
.order-person-section {
  .section-header {
    display: flex;
    align-items: center;
    background: linear-gradient(90deg, #19a97c, #19a97c80);
    color: white;
    padding: 15rpx;
    border-radius: 10rpx;
    margin-bottom: 15rpx;

    .header-icon-bar {
      background-color: white;
      opacity: 0.8;
      margin-right: 8rpx;
      height: 25rpx;
      width: 6rpx;
      border-radius: 3rpx;
    }

    .header-title {
      font-size: 28rpx;
      font-weight: bold;
    }
  }

  .info-item {
    display: flex;
    padding: 15rpx;
    background-color: #f8f8f8;
    border-radius: 6rpx;
    margin-bottom: 10rpx;

    &:last-child {
      margin-bottom: 0;
    }

    .info-label {
      display: flex;
      align-items: center;
      min-width: 140rpx;
      color: #666;
      font-size: 24rpx;
    }

    .info-content {
      flex: 1;
      display: flex;
      align-items: center;
      color: #333;
      font-size: 24rpx;

      .content-text {
        flex: 1;
      }

      .icon-box {
        margin-left: 10rpx;
      }
    }
  }
}

/* 处理信息板块样式 */
.process-info-section {
  .section-header {
    display: flex;
    align-items: center;
    background: linear-gradient(90deg, #19a97c, #19a97c80);
    color: white;
    padding: 15rpx;
    border-radius: 10rpx;
    margin-bottom: 15rpx;

    .header-icon-bar {
      background-color: white;
      opacity: 0.8;
      margin-right: 8rpx;
      height: 25rpx;
      width: 6rpx;
      border-radius: 3rpx;
    }

    .header-title {
      font-size: 28rpx;
      font-weight: bold;
    }
  }

  .photo-section {
    .info-item {
      margin-bottom: 15rpx;

      .info-label {
        display: flex;
        align-items: center;
        color: #666;
        font-size: 24rpx;
      }
    }

    .image-groups {
      .image-group {
        padding: 15rpx;
        background-color: #f8f8f8;
        border-radius: 6rpx;
        margin-bottom: 15rpx;

        &:last-child {
          margin-bottom: 0;
        }

        .image-group-header {
          display: flex;
          justify-content: space-between;
          align-items: center;
          margin-bottom: 10rpx;

          .image-group-title {
            font-size: 24rpx;
            font-weight: bold;
            color: #333;
          }
        }
      }
    }
  }

  .empty-image-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 30rpx;

    .empty-text {
      margin-top: 20rpx;
      color: #999;
      font-size: 24rpx;
    }
  }
}
</style>