classificationCpt.vue 98.1 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 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820
<template>
  <div class="classificationCptContainer">
    <ClassificationRuleHeader @rule-test="ruleTest" />
    <el-form ref="classification"
             label-suffix=":"
             label-width="260px"
             :model="classificationObj"
             :rules="rules"
             :validate-on-rule-change="false">
      <GoodsSourceCategoryPicker :classification-obj="classificationObj"
                                 :copy-package-goods-list="copyPackageGoodsList"
                                 :copy-upgrade-goods-list="copyUpgradeGoodsList"
                                 :disabled-goods-type-list="disabledGoodsTypeList"
                                 :disabled-package-goods-list="disabledPackageGoodsList"
                                 :disabled-upgrade-goods-list="disabledUpgradeGoodsList"
                                 :filter-goods-type-item-disabled="filterGoodsTypeItemDisabled"
                                 :filter-package-goods-item-disabled="filterPackageGoodsItemDisabled"
                                 :filter-upgrade-goods-item-disabled="filterUpgradeGoodsItemDisabled"
                                 :goods-list="goodsList"
                                 :goods-source-set="goodsSourceSet"
                                 :on-category-type-change="clearValidate"
                                 :pane-index="paneIndex"
                                 :remote-method="remoteMethod"
                                 :remote-method-package="remoteMethodPackage"
                                 :upgrade-goods-change="upgradeGoodsChange"
                                 :visible-change="visibleChange"
                                 :visible-change-package="visibleChangePackage" />
      <h3 v-if="!paneIndex">
        全部品类
      </h3>
      <p class="edit-sub-title">
        流量方分润
      </p>
      <el-form-item label="手续费计算(仅针对线上支付订单)"
                    label-width="310px"
                    prop="shop4sDeductChargeFlag">
        <el-radio-group v-model="classificationObj.shop4sDeductChargeFlag">
          <el-radio label="Y">
            扣除手续费
          </el-radio>
          <el-radio label="N">
            不扣除手续费
          </el-radio>
        </el-radio-group>
      </el-form-item>
      <div v-for="(item, index) in classificationObj.trafficSide"
           :key="expenseSideRowKey(item, index, 'traffic')"
           class="trafficSide">
        <el-form-item style="width: 100%"
                      required
                      :label="item.expenseCategoryName"
                      :prop="`trafficSide.${index}.calculateMode`"
                      :rules="[
                        { required: true, message: '请选择计算方式', trigger: 'change' },
                      ]">
          <template #label>
            <span class="label-span">
              <span class="sub-label">{{ item.expenseCategoryName }}</span>
              <!-- content="Top Left 提示文字" -->
              <el-tooltip class="item"
                          effect="dark"
                          placement="right">
                <template #content>
                  <p>计算模式说明:</p>
                  <p>
                    按品类计算:按商品对应的品类规则进行计算,多个商品进行结果汇总;
                  </p>
                  <p>
                    按整单计算:按整个订单进行计算,若存在多个商品的整单规则,则取最高的计算结果对应的规则;
                  </p>
                  <br />
                  <p>分润模式说明:</p>
                  <p>
                    若流量方分润扣除手续费,则收入=实收金额,毛利=实收金额-产品成本;
                  </p>
                  <p>
                    若流量方分润不扣除手续费,则收入=原支付金额,毛利=原支付金额-产品成本。
                  </p>
                  <br />
                  <p>按收入比例:以收入*(定义的比例)进行费用计算;</p>
                  <p>按毛利比例:以毛利*(定义的比例)进行费用计算;</p>
                  <p>按固定金额:费用=定义的固定金额;</p>
                  <p>按固定金额*购买数量:费用=定义的固定金额*购买数量;</p>
                  <p>
                    按(收入-自定义其他费用)比例:以(收入-自定义其他费用)*(定义的比例)进行费用计算,其中自定义其他费用为不包含产品成本的其他费用;
                  </p>
                  <p>
                    按(收入-其他费用)比例:以(收入-其他费用)*(定义的比例)进行费用计算,其中其他费用是包含产品成本的全部其他费用;
                  </p>
                </template>
                <i class="el-icon-info"></i>
              </el-tooltip>
              :
            </span>
          </template>
          <el-radio-group v-model="classificationObj.trafficSide[index].calculateMode"
                          @change="($event) => updateCalculateModeType($event, 'trafficSide', index)
                          ">
            <el-radio :label="1">
              按品类计算
            </el-radio>
            <el-radio :label="2">
              按整单计算
            </el-radio>
          </el-radio-group>
          <span v-if="classificationObj.trafficSide[index].calculateModeError"
                class="check_calculateMode">
            仅支持整单规则
          </span>
        </el-form-item>
        <div style="display: flex">
          <el-form-item required
                        :prop="`trafficSide.${index}.expenseCategoryCalculateType`"
                        :rules="[
                          { required: true, message: '请选择分润模式', trigger: 'change' },
                        ]">
            <el-select v-model="classificationObj.trafficSide[index]
                         .expenseCategoryCalculateType
                       "
                       placeholder="请选择分润模式"
                       @change="($event) => forceUpdate($event, 'trafficSide', index)">
              <el-option v-for="el in otherSelectOptions"
                         :key="el.expenseCategoryCalculateType"
                         :label="el.label"
                         :value="el.expenseCategoryCalculateType" />
            </el-select>
          </el-form-item>
          <!-- label-width="" -->
          <el-form-item label="分润比例设定"
                        required
                        :prop="`trafficSide.${index}.expenseCategoryValue`"
                        :rules="[
                          {
                            required: true,
                            message: '请输入分润比例',
                            trigger: ['change', 'blur'],
                          },
                        ]">
            <el-input v-model="classificationObj.trafficSide[index].expenseCategoryValue
                      "
                      style="width: 150px"
                      :placeholder="expenseCategoryPlaceholder(classificationObj.trafficSide[index].expenseCategoryCalculateType)
                      "
                      @input="
                        handleInput(
                          $event,
                          'trafficSide',
                          classificationObj.trafficSide[index]
                            .expenseCategoryCalculateType,
                          index,
                        )
                      ">
              <!-- accountSecondSetForm.marketingCostCalculateType== 1?'请输入固定金额': -->
              <!--  v-if="accountSecondSetForm.marketingCostCalculateType== 2" -->
              <template #suffix>
                <i v-if="
                     classificationObj.trafficSide[index]
                       .expenseCategoryCalculateType != 3
                       && classificationObj.trafficSide[index]
                         .expenseCategoryCalculateType != 10
                   "
                   class="suffix">
                  %
                </i>
              </template>
            </el-input>
          </el-form-item>
        </div>
        <!-- 多子类目 -->
        <el-form-item v-if="item.formType == 2" class="edit-form-item-table">
          <el-table style="width: 100%"
                    border
                    :cell-style="{ 'text-align': 'center' }"
                    :data="classificationObj.trafficSide[index].children"
                    :header-cell-style="headerCellStyle">
            <el-table-column label="子类目">
              <template #default="scope">
                <span>{{ scope.row.expenseCategoryName }}</span>
              </template>
            </el-table-column>
            <el-table-column label="计算模式" width="250">
              <template #default="scope">
                <el-form-item style="width: 100%"
                              required
                              :prop="`trafficSide[${index}].children[${scope.$index}].calculateMode`"
                              :rules="[
                                {
                                  required: true,
                                  message: '请选择计算方式',
                                  trigger: 'change',
                                },
                              ]">
                  <el-radio-group v-model="scope.row.calculateMode" :disabled="true">
                    <el-radio :label="1">
                      按品类计算
                    </el-radio>
                    <el-radio :label="2">
                      按整单计算
                    </el-radio>
                  </el-radio-group>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="计算模式">
              <template #default="scope">
                <el-form-item v-if="scope.row.nodeType != 4"
                              class="edit-form-item-table-children"
                              required
                              :prop="`trafficSide[${index}].children[${scope.$index}].expenseCategoryCalculateType`"
                              :rules="[
                                {
                                  required: true,
                                  message: '请选择分润模式',
                                  trigger: 'change',
                                },
                              ]">
                  <el-select v-model="scope.row.expenseCategoryCalculateType"
                             placeholder="请选择分润模式"
                             @change="($event) =>
                               forceUpdate($event, 'trafficSide', index, scope.$index)
                             ">
                    <el-option v-for="el in otherSelectOptions"
                               :key="el.expenseCategoryCalculateType"
                               :label="el.label"
                               :value="el.expenseCategoryCalculateType" />
                  </el-select>
                </el-form-item>
                <span v-else>-</span>
              </template>
            </el-table-column>
            <el-table-column label="分润模式">
              <template #default="scope">
                <el-form-item v-if="scope.row.nodeType != 4"
                              class="edit-form-item-table-children"
                              required
                              :prop="`trafficSide[${index}].children[${scope.$index}].expenseCategoryValue`"
                              :rules="[
                                {
                                  required: true,
                                  message: '请输入分润比例',
                                  trigger: ['change', 'blur'],
                                },
                              ]">
                  <el-input v-model="scope.row.expenseCategoryValue"
                            style="width: 150px"
                            :placeholder="expenseCategoryPlaceholder(scope.row.expenseCategoryCalculateType)
                            "
                            @input="
                              handleInput(
                                $event,
                                'trafficSide',
                                scope.row.expenseCategoryCalculateType,
                                index,
                                scope.$index,
                              )
                            ">
                    <template #suffix>
                      <i v-if="
                           scope.row.expenseCategoryCalculateType != 3
                             && scope.row.expenseCategoryCalculateType != 10
                         "
                         class="suffix">
                        %
                      </i>
                    </template>
                  </el-input>
                </el-form-item>
                <span v-else>-</span>
              </template>
            </el-table-column>
          </el-table>
        </el-form-item>
      </div>

      <p class="edit-sub-title">
        服务商分润
      </p>
      <el-form-item label="手续费计算(仅针对线上支付订单)"
                    label-width="310px"
                    prop="partnerDeductChargeFlag">
        <el-radio-group v-model="classificationObj.partnerDeductChargeFlag">
          <el-radio label="Y">
            扣除手续费
          </el-radio>
          <el-radio label="N">
            不扣除手续费
          </el-radio>
        </el-radio-group>
      </el-form-item>
      <div v-for="(item, index) in classificationObj.serviceProvider"
           :key="expenseSideRowKey(item, index, 'service')"
           class="serviceProvider">
        <el-form-item style="width: 100%"
                      required
                      :label="item.expenseCategoryName"
                      :prop="`serviceProvider.${index}.calculateMode`"
                      :rules="[
                        { required: true, message: '请选择计算方式', trigger: 'change' },
                      ]">
          <template #label>
            <span class="label-span">
              <span class="sub-label">{{ item.expenseCategoryName }}</span>
              <!-- content="Top Left 提示文字" -->
              <el-tooltip class="item"
                          effect="dark"
                          placement="right">
                <template #content>
                  <p>计算模式说明:</p>
                  <p>
                    按品类计算:按商品对应的品类规则进行计算,多个商品进行结果汇总;
                  </p>
                  <p>
                    按整单计算:按整个订单进行计算,若存在多个商品的整单规则,则取最高的计算结果对应的规则;
                  </p>
                  <br />
                  <p>分润模式说明:</p>
                  <p>
                    若流量方分润扣除手续费,则收入=实收金额,毛利=实收金额-产品成本;
                  </p>
                  <p>
                    若流量方分润不扣除手续费,则收入=原支付金额,毛利=原支付金额-产品成本。
                  </p>
                  <br />
                  <p>按收入比例:以收入*(定义的比例)进行费用计算;</p>
                  <p>按毛利比例:以毛利*(定义的比例)进行费用计算;</p>
                  <p>按固定金额:费用=定义的固定金额</p>
                  <p>按固定金额*购买数量:费用=定义的固定金额*购买数量</p>
                  <p>
                    按园区店总金额比例:以(收入-流量方总分润)*(定义的比例)进行费用计算;
                  </p>
                  <p>
                    按园区店毛利(不扣除产品成本)比例:以(收入-流量方总分润-其他费用不包含产品成本)*(定义的比例)进行费用计算
                  </p>
                  <p>
                    按园区店毛利比例:以(收入-流量方总分润-其他费用包含产品成本)*(定义的比例)进行费用计算
                  </p>
                  <p>
                    按(收入-自定义其他费用)比例:以(收入-自定义其他费用)*(定义的比例)进行费用计算,其中自定义其他费用为不包含产品成本的其他费用;
                  </p>
                  <p>
                    按(收入-其他费用)比例:以(收入-其他费用)*(定义的比例)进行费用计算,其中其他费用是包含产品成本的全部其他费用;
                  </p>
                </template>
                <i class="el-icon-info"></i>
              </el-tooltip>
              :
            </span>
          </template>
          <el-radio-group v-model="classificationObj.serviceProvider[index].calculateMode"
                          :disabled="classificationObj.serviceProvider[index].isDisabled"
                          @change="($event) =>
                            updateCalculateModeType($event, 'serviceProvider', index)
                          ">
            <el-radio :label="1">
              按品类计算
            </el-radio>
            <el-radio :label="2">
              按整单计算
            </el-radio>
          </el-radio-group>
          <span v-if="classificationObj.serviceProvider[index].calculateModeError"
                class="check_calculateMode">
            仅支持整单规则
          </span>
        </el-form-item>
        <div style="display: flex">
          <el-form-item required
                        :prop="`serviceProvider.${index}.expenseCategoryCalculateType`"
                        :rules="[
                          { required: true, message: '请选择分润模式', trigger: 'change' },
                        ]">
            <el-select v-model="classificationObj.serviceProvider[index]
                         .expenseCategoryCalculateType
                       "
                       placeholder="请选择分润模式"
                       @change="($event) => forceUpdate($event, 'serviceProvider', index)
                       ">
              <el-option v-for="el in severSelectOptions"
                         :key="el.expenseCategoryCalculateType"
                         :label="el.label"
                         :value="el.expenseCategoryCalculateType" />
            </el-select>
          </el-form-item>
          <el-form-item label="分润比例设定"
                        required
                        :prop="`serviceProvider.${index}.expenseCategoryValue`"
                        :rules="[
                          {
                            required: true,
                            message: '请输入分润比例',
                            trigger: ['change', 'blur'],
                          },
                        ]">
            <!-- expenseCategoryValue -->
            <el-input v-model="classificationObj.serviceProvider[index].expenseCategoryValue
                      "
                      style="width: 150px"
                      :placeholder="expenseCategoryPlaceholder(classificationObj.serviceProvider[index].expenseCategoryCalculateType)
                      "
                      @input="
                        handleInput(
                          $event,
                          'serviceProvider',
                          classificationObj.serviceProvider[index]
                            .expenseCategoryCalculateType,
                          index,
                        )
                      ">
              <template #suffix>
                <i v-if="
                     classificationObj.serviceProvider[index]
                       .expenseCategoryCalculateType != 3
                       && classificationObj.serviceProvider[index]
                         .expenseCategoryCalculateType != 10
                   "
                   class="suffix">
                  %
                </i>
              </template>
            </el-input>
          </el-form-item>
          <el-form-item v-if="item.formType != 2" label="分润服务商">
            <el-select v-model="classificationObj.serviceProvider[index].targetMerchant"
                       placeholder="请选分润服务商"
                       value-key="merchantId"
                       @change="handleSelectChange">
              <el-option v-for="el in serviceMerchantList"
                         :key="el.merchantId"
                         :label="el.merchantName"
                         :value="el" />
            </el-select>
          </el-form-item>
        </div>
        <!-- 多子类目 -->
        <el-form-item v-if="item.formType == 2" class="edit-form-item-table">
          <el-table style="width: 100%"
                    border
                    :cell-style="{ 'text-align': 'center' }"
                    :data="classificationObj.serviceProvider[index].children"
                    :header-cell-style="headerCellStyle">
            <el-table-column label="子类目">
              <template #default="scope">
                <span>{{ scope.row.expenseCategoryName }}</span>
              </template>
            </el-table-column>
            <el-table-column label="计算模式" width="250">
              <template #default="scope">
                <el-form-item style="width: 100%"
                              required
                              :prop="`serviceProvider[${index}].children[${scope.$index}].calculateMode`"
                              :rules="[
                                {
                                  required: true,
                                  message: '请选择计算方式',
                                  trigger: 'change',
                                },
                              ]">
                  <el-radio-group v-model="scope.row.calculateMode" :disabled="true">
                    <el-radio :label="1">
                      按品类计算
                    </el-radio>
                    <el-radio :label="2">
                      按整单计算
                    </el-radio>
                  </el-radio-group>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="计算模式">
              <template #default="scope">
                <el-form-item v-if="scope.row.nodeType != 4"
                              class="edit-form-item-table-children"
                              required
                              :prop="`serviceProvider[${index}].children[${scope.$index}].expenseCategoryCalculateType`"
                              :rules="[
                                {
                                  required: true,
                                  message: '请选择分润模式',
                                  trigger: 'change',
                                },
                              ]">
                  <el-select v-model="scope.row.expenseCategoryCalculateType"
                             placeholder="请选择分润模式"
                             @change="($event) =>
                               forceUpdate(
                                 $event,
                                 'serviceProvider',
                                 index,
                                 scope.$index,
                               )
                             ">
                    <el-option v-for="el in severSelectOptions"
                               :key="el.expenseCategoryCalculateType"
                               :label="el.label"
                               :value="el.expenseCategoryCalculateType" />
                  </el-select>
                </el-form-item>
                <span v-else>-</span>
              </template>
            </el-table-column>
            <el-table-column label="分润模式">
              <template #default="scope">
                <el-form-item v-if="scope.row.nodeType != 4"
                              class="edit-form-item-table-children"
                              required
                              :prop="`serviceProvider[${index}].children[${scope.$index}].expenseCategoryValue`"
                              :rules="[
                                {
                                  required: true,
                                  message: '请输入分润比例',
                                  trigger: ['change', 'blur'],
                                },
                              ]">
                  <el-input v-model="scope.row.expenseCategoryValue"
                            style="width: 150px"
                            :placeholder="expenseCategoryPlaceholder(scope.row.expenseCategoryCalculateType)
                            "
                            @input="
                              handleInput(
                                $event,
                                'serviceProvider',
                                scope.row.expenseCategoryCalculateType,
                                index,
                                scope.$index,
                              )
                            ">
                    <template #suffix>
                      <i v-if="
                           scope.row.expenseCategoryCalculateType != 3
                             && scope.row.expenseCategoryCalculateType != 10
                         "
                         class="suffix">
                        %
                      </i>
                    </template>
                  </el-input>
                </el-form-item>
                <span v-else>-</span>
              </template>
            </el-table-column>
            <el-table-column label="分润对象">
              <template #default="scope">
                <el-form-item class="edit-form-item-table-children">
                  <el-select v-model="scope.row.targetMerchant"
                             placeholder="请选分润服务商"
                             value-key="merchantId"
                             @change="handleSelectChange">
                    <el-option v-for="el in serviceMerchantList"
                               :key="el.merchantId"
                               :label="el.merchantName"
                               :value="el" />
                  </el-select>
                </el-form-item>
              </template>
            </el-table-column>
          </el-table>
        </el-form-item>
      </div>

      <p class="edit-sub-title">
        其他费用
        <span class="title-tips">用于费用预留,进行完流量方和服务商分润后,会自动先预留出对应的费用给承担方</span>
      </p>
      <el-form-item label="产品成本" prop="goodsCostConvertRate">
        <template #label>
          <span>
            产品成本
            <el-tooltip class="item"
                        effect="dark"
                        placement="right">
              <template #content>
                <p>
                  开启产品成本,计算分账时会自动预留出产品成本费用给对应的承担方;
                </p>
                <p>不开启产品成本,计算分账时不自动预留出产品成本费用;</p>
              </template>
              <i class="el-icon-info"></i>
            </el-tooltip>
            :
          </span>
        </template>
        <el-radio-group v-model="classificationObj.goodsCostFlag">
          <el-radio label="N">
            不扣除产品成本
          </el-radio>
          <el-radio label="Y">
            扣除产品成本
          </el-radio>
        </el-radio-group>
        <el-input v-show="classificationObj.goodsCostFlag == 'Y'"
                  v-model="classificationObj.goodsCostConvertRate"
                  class="rateinput"
                  placeholder="请输入折算比例"
                  style="width: 150px"
                  @input="
                    handleInputRate(
                      $event,
                      'goodsCostConvertRate',
                    )
                  ">
          <template #suffix>
            <i class="suffix">%</i>
          </template>
        </el-input>
      </el-form-item>
      <el-form-item label="虚拟对账成本" prop="virtualAccountCostConvertRate">
        <template #label>
          <span>
            虚拟对账成本
            <el-tooltip class="item"
                        effect="dark"
                        placement="right">
              <template #content>
                <p>
                  开启虚拟对账成本,计算分账时会自动预留出虚拟对账成本费用给对应的承担方;
                </p>
                <p>
                  不开启虚拟对账成本,计算分账时不自动预留出虚拟对账成本费用;
                </p>
              </template>
              <i class="el-icon-info"></i>
            </el-tooltip>
            :
          </span>
        </template>
        <el-radio-group v-model="classificationObj.virtualAccountCostFlag">
          <el-radio label="N">
            不扣虚拟对账成本
          </el-radio>
          <el-radio label="Y">
            扣除虚拟对账成本
          </el-radio>
        </el-radio-group>
        <el-input v-if="classificationObj.virtualAccountCostFlag == 'Y'"
                  v-model="classificationObj.virtualAccountCostConvertRate"
                  class="rateinput"
                  placeholder="请输入折算比例"
                  style="width: 150px"
                  @input="
                    handleInputRate(
                      $event,
                      'virtualAccountCostConvertRate',
                    )
                  ">
          <template #suffix>
            <i class="suffix">%</i>
          </template>
        </el-input>
      </el-form-item>
      <el-form-item label="回收成本" prop="recoveryCostConvertRate">
        <template #label>
          <span>
            回收成本
            <!-- content="Top Left 提示文字" -->
            <el-tooltip class="item"
                        effect="dark"
                        placement="right">
              <template #content>
                <p>
                  开启回收成本,计算分账时会自动预留出回收成本费用给对应的承担方;
                </p>
                <p>不开启回收成本,计算分账时不自动预留出回收成本费用;</p>
              </template>
              <i class="el-icon-info"></i>
            </el-tooltip>
            :
          </span>
        </template>
        <el-radio-group v-model="classificationObj.recoveryCostFlag">
          <el-radio label="N">
            不扣回收成本
          </el-radio>
          <el-radio label="Y">
            扣除回收成本
          </el-radio>
        </el-radio-group>
        <el-input v-if="classificationObj.recoveryCostFlag == 'Y'"
                  v-model="classificationObj.recoveryCostConvertRate"
                  class="rateinput"
                  placeholder="请输入折算比例"
                  style="width: 150px"
                  @input="
                    handleInputRate(
                      $event,
                      'recoveryCostConvertRate',
                    )
                  ">
          <template #suffix>
            <i class="suffix">%</i>
          </template>
        </el-input>
      </el-form-item>
      <el-form-item label="嘀加成本" prop="djCostConvertRate">
        <template #label>
          <span>
            嘀加成本
            <!-- content="Top Left 提示文字" -->
            <el-tooltip class="item"
                        effect="dark"
                        placement="right">
              <template #content>
                <p>
                  开启嘀加成本,计算分账时会自动预留出嘀加成本费用给对应的承担方;
                </p>
                <p>不开启嘀加成本,计算分账时不自动预留出嘀加成本费用;</p>
              </template>
              <i class="el-icon-info"></i>
            </el-tooltip>
            :
          </span>
        </template>
        <el-radio-group v-model="classificationObj.djCostFlag">
          <el-radio label="N">
            不扣嘀加成本
          </el-radio>
          <el-radio label="Y">
            扣除嘀加成本
          </el-radio>
        </el-radio-group>
        <el-input v-if="classificationObj.djCostFlag == 'Y'"
                  v-model="classificationObj.djCostConvertRate"
                  class="rateinput"
                  placeholder="请输入折算比例"
                  style="width: 150px"
                  @input="
                    handleInputRate(
                      $event,
                      'djCostConvertRate',
                    )
                  ">
          <template #suffix>
            <i class="suffix">%</i>
          </template>
        </el-input>
      </el-form-item>
      <el-form-item label="第三方成本" prop="thirdPartyCostConvertRate">
        <template #label>
          <span>
            第三方成本
            <!-- content="Top Left 提示文字" -->
            <el-tooltip class="item"
                        effect="dark"
                        placement="right">
              <template #content>
                <p>
                  开启第三方成本,计算分账时会自动预留出第三方成本费用给对应的承担方;
                </p>
                <p>不开启第三方成本,计算分账时不自动预留出第三方成本费用;</p>
              </template>
              <i class="el-icon-info"></i>
            </el-tooltip>
            :
          </span>
        </template>
        <el-radio-group v-model="classificationObj.thirdPartyCostFlag">
          <el-radio label="N">
            不扣第三方成本
          </el-radio>
          <el-radio label="Y">
            扣除第三方成本
          </el-radio>
        </el-radio-group>
        <el-input v-if="classificationObj.thirdPartyCostFlag == 'Y'"
                  v-model="classificationObj.thirdPartyCostConvertRate"
                  class="rateinput"
                  placeholder="请输入折算比例"
                  style="width: 150px"
                  @input="
                    handleInputRate(
                      $event,
                      'thirdPartyCostConvertRate',
                    )
                  ">
          <template #suffix>
            <i class="suffix">%</i>
          </template>
        </el-input>
      </el-form-item>
      <div v-for="(item, index) in classificationObj.platformPublic"
           :key="expenseSideRowKey(item, index, 'platform')"
           class="platformPublic">
        <el-form-item style="width: 100%"
                      required
                      :label="item.expenseCategoryName"
                      :prop="`platformPublic.${index}.calculateMode`"
                      :rules="[
                        { required: true, message: '请选择计算方式', trigger: 'change' },
                      ]">
          <template #label>
            <span class="label-span">
              <span class="sub-label">{{ item.expenseCategoryName }}</span>
              <!-- content="Top Left 提示文字" -->
              <el-tooltip class="item"
                          effect="dark"
                          placement="right">
                <template #content>
                  <p>计算模式说明:</p>
                  <p>
                    按品类计算:按商品对应的品类规则进行计算,多个商品进行结果汇总;
                  </p>
                  <p>
                    按整单计算:按整个订单进行计算,若存在多个商品的整单规则,则取最高的计算结果对应的规则;
                  </p>
                  <br />
                  <p>分润模式说明:</p>
                  <p>默认按不扣除手续费进行计算</p>
                  <!-- <p>
                  若流量方分润扣除手续费,则收入=实收金额,毛利=实收金额-产品成本;
                </p>
                <p>
                  若流量方分润不扣除手续费,则收入=原支付金额,毛利=原支付金额-产品成本。
                </p> -->
                  <br />
                  <p>按收入比例:以收入*(定义的比例)进行费用计算;</p>
                  <p>按毛利比例:以毛利*(定义的比例)进行费用计算;</p>
                  <p>按固定金额:费用=定义的固定金额</p>
                  <p>按固定金额*购买数量:费用=定义的固定金额*购买数量</p>
                </template>
                <i class="el-icon-info"></i>
              </el-tooltip>
              :
            </span>
          </template>
          <el-radio-group v-model="classificationObj.platformPublic[index].calculateMode"
                          :disabled="classificationObj.platformPublic[index].isDisabled"
                          @change="($event) =>
                            updateCalculateModeType($event, 'platformPublic', index)
                          ">
            <el-radio :label="1">
              按品类计算
            </el-radio>
            <el-radio :label="2">
              按整单计算
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <div style="display: flex">
          <el-form-item required
                        :prop="`platformPublic.${index}.expenseCategoryCalculateType`"
                        :rules="[
                          { required: true, message: '请选择分润模式', trigger: 'change' },
                        ]">
            <el-select v-model="classificationObj.platformPublic[index]
                         .expenseCategoryCalculateType
                       "
                       placeholder="请选择分润模式"
                       @change="($event) => forceUpdate($event, 'platformPublic', index)">
              <el-option v-for="el in defaultSelectOptions"
                         :key="el.expenseCategoryCalculateType"
                         :label="el.label"
                         :value="el.expenseCategoryCalculateType" />
            </el-select>
          </el-form-item>
          <el-form-item label="分润比例设定"
                        required
                        :prop="`platformPublic.${index}.expenseCategoryValue`"
                        :rules="[
                          {
                            required: true,
                            message: '请输入分润比例',
                            trigger: ['change', 'blur'],
                          },
                        ]">
            <el-input v-model="classificationObj.platformPublic[index].expenseCategoryValue
                      "
                      style="width: 150px"
                      :placeholder="expenseCategoryPlaceholder(classificationObj.platformPublic[index].expenseCategoryCalculateType)
                      "
                      @input="
                        handleInput(
                          $event,
                          'platformPublic',
                          classificationObj.platformPublic[index]
                            .expenseCategoryCalculateType,
                          index,
                        )
                      ">
              <!-- accountSecondSetForm.marketingCostCalculateType== 1?'请输入固定金额': -->
              <!--  v-if="accountSecondSetForm.marketingCostCalculateType== 2" -->
              <template #suffix>
                <i v-if="
                     classificationObj.platformPublic[index]
                       .expenseCategoryCalculateType != 3
                       && classificationObj.platformPublic[index]
                         .expenseCategoryCalculateType != 10
                   "
                   class="suffix">
                  %
                </i>
              </template>
            </el-input>
          </el-form-item>
        </div>
        <!-- 多子类目 -->
        <el-form-item v-if="item.formType == 2" class="edit-form-item-table">
          <el-table style="width: 100%"
                    border
                    :cell-style="{ 'text-align': 'center' }"
                    :data="classificationObj.platformPublic[index].children"
                    :header-cell-style="headerCellStyle">
            <el-table-column label="子类目">
              <template #default="scope">
                <span>{{ scope.row.expenseCategoryName }}</span>
              </template>
            </el-table-column>
            <el-table-column label="计算模式" width="250">
              <template #default="scope">
                <el-form-item style="width: 100%"
                              required
                              :prop="`platformPublic[${index}].children[${scope.$index}].calculateMode`"
                              :rules="[
                                {
                                  required: true,
                                  message: '请选择计算方式',
                                  trigger: 'change',
                                },
                              ]">
                  <el-radio-group v-model="scope.row.calculateMode" :disabled="true">
                    <el-radio :label="1">
                      按品类计算
                    </el-radio>
                    <el-radio :label="2">
                      按整单计算
                    </el-radio>
                  </el-radio-group>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column label="计算模式">
              <template #default="scope">
                <el-form-item v-if="scope.row.nodeType != 4"
                              class="edit-form-item-table-children"
                              required
                              :prop="`platformPublic[${index}].children[${scope.$index}].expenseCategoryCalculateType`"
                              :rules="[
                                {
                                  required: true,
                                  message: '请选择分润模式',
                                  trigger: 'change',
                                },
                              ]">
                  <el-select v-model="scope.row.expenseCategoryCalculateType"
                             placeholder="请选择分润模式"
                             @change="($event) =>
                               forceUpdate(
                                 $event,
                                 'platformPublic',
                                 index,
                                 scope.$index,
                               )
                             ">
                    <el-option v-for="el in defaultSelectOptions"
                               :key="el.expenseCategoryCalculateType"
                               :label="el.label"
                               :value="el.expenseCategoryCalculateType" />
                  </el-select>
                </el-form-item>
                <span v-else>-</span>
              </template>
            </el-table-column>
            <el-table-column label="分润模式">
              <template #default="scope">
                <el-form-item v-if="scope.row.nodeType != 4"
                              class="edit-form-item-table-children"
                              required
                              :prop="`platformPublic[${index}].children[${scope.$index}].expenseCategoryValue`"
                              :rules="[
                                {
                                  required: true,
                                  message: '请输入分润比例',
                                  trigger: ['change', 'blur'],
                                },
                              ]">
                  <el-input v-model="scope.row.expenseCategoryValue"
                            style="width: 150px"
                            :placeholder="expenseCategoryPlaceholder(scope.row.expenseCategoryCalculateType)
                            "
                            @input="
                              handleInput(
                                $event,
                                'platformPublic',
                                scope.row.expenseCategoryCalculateType,
                                index,
                                scope.$index,
                              )
                            ">
                    <template #suffix>
                      <i v-if="
                           scope.row.expenseCategoryCalculateType != 3
                             && scope.row.expenseCategoryCalculateType != 10
                         "
                         class="suffix">
                        %
                      </i>
                    </template>
                  </el-input>
                </el-form-item>
                <span v-else>-</span>
              </template>
            </el-table-column>
          </el-table>
        </el-form-item>
      </div>
    </el-form>
    <!-- <el-button @click="handleConfirm">测试</el-button> -->
    <TableAccount ref="tableAccount"
                  :classification-obj-select="tableClassificationObjSelect"
                  :merchant-distribution-rules="goodsTypeGroupRules.merchantDistributionRules
                  "
                  :owning-merchant-distribution-rules="goodsTypeGroupRules.owningMerchantDistributionRules"
                  :table-select-options="tableSelectOptions"
                  @distribution-rules-change="onDistributionRulesChange" />
  </div>
</template>

<script>
import {
	getAllGoodsListPage as getAllGoodsList,
	merchantPackageGoodsInfoPage,
} from "@api/grounding";
import { mapGetters, mapMutations } from "vuex";
import {
	defaultSelectOptions,
	otherSelectOptions,
	severSelectOptions,
} from "@/common/constant/merchant";
import { limitPrice } from "@/common/format";
import { resolveBaseSceneCodeFromRouter } from "@/common/sceneBaseSceneCode";
import { deepClone } from "@/common/util";
import {
	filterUpgradeGoodsByMerchantCode,
	getUpgradeGoodsRowKey,
	mapProductSearchListToUpgradeGoodsOptions,
	resolveProductSearchPages,
	sameUpgradeGoodsRow,
} from "../../merchantStep/utils/groundingUpgradeList";
import { CLASSIFICATION_EMIT } from "../utils/classificationEmitTypes";
import { expenseSideRowKey } from "../utils/expenseRowKey";
import ClassificationRuleHeader from "./classificationCpt/ClassificationRuleHeader.vue";
import GoodsSourceCategoryPicker from "./classificationCpt/GoodsSourceCategoryPicker.vue";
import tableAccount from "./tableAccount";

export default {
	name: "ClassificationCpt",
	components: {
		TableAccount: tableAccount,
		ClassificationRuleHeader,
		GoodsSourceCategoryPicker,
	},
	inject: {
		financialRulesEnv: {
			from: "financialRulesEnv",
			default: null,
		},
	},
	props: {
		/** 见 utils/financialRulesContext.js(FinancialRulesPageContext) */
		pageContext: {
			type: Object,
			required: true,
		},
		/** 见 utils/financialRulesContext.js(FinancialRulesSelectionContext) */
		selectionContext: {
			type: Object,
			required: true,
		},
		/** 见 utils/financialRulesContext.js(FinancialRulesPaneContext) */
		paneContext: {
			type: Object,
			required: true,
		},
	},
	data() {
		/** 开启扣除(Y) 时要求比例非空且为合法数字,避免 undefined/null 误判为已填 */
		const rateFilled = (v) => {
			if (v === null || v === undefined) {
				return false;
			}
			const s = String(v).trim();
			if (s === "") {
				return false;
			}
			return !Number.isNaN(Number(s));
		};
		let validatorFormGoodsCostConvertRate = (rule, value, callback) => {
			if (this.classificationObj.goodsCostFlag === "N") {
				callback();
				return;
			}
			rateFilled(this.classificationObj.goodsCostConvertRate)
				? callback()
				: callback(new Error("请输入折算比例"));
		};
		let validatorForm1 = (rule, value, callback) => {
			if (this.classificationObj.virtualAccountCostFlag === "N") {
				callback();
				return;
			}
			rateFilled(this.classificationObj.virtualAccountCostConvertRate)
				? callback()
				: callback(new Error("请输入折算比例"));
		};
		let validatorForm2 = (rule, value, callback) => {
			if (this.classificationObj.recoveryCostFlag === "N") {
				callback();
				return;
			}
			rateFilled(this.classificationObj.recoveryCostConvertRate)
				? callback()
				: callback(new Error("请输入折算比例"));
		};
		let validatorForm3 = (rule, value, callback) => {
			if (this.classificationObj.djCostFlag === "N") {
				callback();
				return;
			}
			rateFilled(this.classificationObj.djCostConvertRate)
				? callback()
				: callback(new Error("请输入折算比例"));
		};
		let validatorForm4 = (rule, value, callback) => {
			if (this.classificationObj.thirdPartyCostFlag === "N") {
				callback();
				return;
			}
			rateFilled(this.classificationObj.thirdPartyCostConvertRate)
				? callback()
				: callback(new Error("请输入折算比例"));
		};
		return {
			classificationObj: {
				goodsTypes: [],
				// trafficSide: [],
				// serviceProviderSide: [],
				// platformPublic: [],
				// expenseCategoryRules: []
				shop4sDeductChargeFlag: "Y", // 导流方POS机支付是否扣除手续费(Y:扣除,N:不扣)
				partnerDeductChargeFlag: "Y", // 服务商POS机支付是否扣除手续费(Y:扣除,N:不扣)
				goodsCostFlag: "Y", // 平台方是否扣除产品成本(Y:计算,N:不计算)
				groupType: 1,
				categoryType: "", // 分类类别
				upgradeGoods: [], // 具体商品
				packageGoods: [],
				virtualAccountCostFlag: "Y",
				recoveryCostFlag: "Y",
				djCostFlag: "Y",
				thirdPartyCostFlag: "Y",
				goodsSource: 1,
				goodsCostConvertRate: "100",
				virtualAccountCostConvertRate: "100",
				recoveryCostConvertRate: "100",
				djCostConvertRate: "100",
				thirdPartyCostConvertRate: "100",
			},
			defaultSelectOptions: Object.freeze(defaultSelectOptions),
			severSelectOptions: Object.freeze(severSelectOptions),
			otherSelectOptions: Object.freeze([
				...defaultSelectOptions,
				...otherSelectOptions,
			]), // 新增适配分账模式
			// serviceMerchantList: [],
			rules: {
				upgradeGoods: [
					{ required: true, message: "请选择商品", trigger: ["change", "blur"] },
				],
				packageGoods: [
					{
						required: true,
						message: "请选择商品套餐",
						trigger: ["change", "blur"],
					},
				],
				goodsCostConvertRate: {
					required: true,
					validator: validatorFormGoodsCostConvertRate,
					trigger: "change",
				},
				virtualAccountCostConvertRate: {
					required: true,
					validator: validatorForm1,
					trigger: "change",
				},
				recoveryCostConvertRate: {
					required: true,
					validator: validatorForm2,
					trigger: "change",
				},
				djCostConvertRate: {
					required: true,
					validator: validatorForm3,
					trigger: "change",
				},
				thirdPartyCostConvertRate: {
					required: true,
					validator: validatorForm4,
					trigger: "change",
				},
				shop4sDeductChargeFlag: [
					{
						required: true,
						message: "请选择流量方线上支付是否扣除手续费",
						trigger: "change",
					},
				],
				partnerDeductChargeFlag: [
					{
						required: true,
						message: "请选择服务商线上支付是否扣除手续费",
						trigger: "change",
					},
				],
			},
			serviceSelectList: [],
			currentPage: 1,
			pageSize: 20,
			currentPagePackage: 1,
			pageSizePackage: 20,
			copyUpgradeGoodsList: [],
			copyPackageGoodsList: [],
			/** initList 回填期间抑制 goodsTypes 等 watch 向父组件 $emit,避免重复合并选中列表 */
			_suppressSelectionSync: false,
			/** 同 tick 内多次触发时只执行一次 initList */
			_initListScheduled: false,
		};
	},
	computed: {
		...mapGetters("FinancialRules", { goodsSourceSet: "goodsSourceSet" }),
		routerInfo() {
			const inj = this.financialRulesEnv;
			if (inj && inj.routerInfo) {
				return inj.routerInfo;
			}
			return {};
		},
		financialLedgerParty() {
			return (this.pageContext && this.pageContext.financialLedgerParty) || {};
		},
		serviceMerchantList() {
			return (this.pageContext && this.pageContext.serviceMerchantList) || [];
		},
		goodsList() {
			return (this.selectionContext && this.selectionContext.goodsList) || [];
		},
		goodsSelectList() {
			return (this.selectionContext && this.selectionContext.goodsSelectList) || [];
		},
		upgradeGoodsList() {
			return (this.selectionContext && this.selectionContext.upgradeGoodsList) || [];
		},
		packageGoodsList() {
			return (this.selectionContext && this.selectionContext.packageGoodsList) || [];
		},
		selectUpgradeGoodsList() {
			return (this.selectionContext && this.selectionContext.selectUpgradeGoodsList) || [];
		},
		selectPackageGoodsList() {
			return (this.selectionContext && this.selectionContext.selectPackageGoodsList) || [];
		},
		goodsTypeGroupRules() {
			return (this.paneContext && this.paneContext.goodsTypeGroupRules) || {};
		},
		paneIndex() {
			const p = this.paneContext && this.paneContext.paneIndex;
			return p != null ? p : 0;
		},
		tabItem() {
			return (this.paneContext && this.paneContext.tabItem) || {};
		},
		classificationObjSelect() {
			return (this.paneContext && this.paneContext.classificationObjSelect) || {};
		},
		// 不可选择的商品分类
		disabledGoodsTypeList() {
			// 根据区别已选的过滤出该组件自己勾选的 剩下的就是其他组件选的 要禁用
			const selectList = this.classificationObj.goodsTypes;
			// goodsList
			const list = this.goodsSelectList.filter((item) => {
				// item.goodsType
				// const flag = selectList.findIndex(el => { return el.goodsType == item.goodsType })
				if (
					selectList.findIndex((el) => {
						// 优先取三级,如果是 null/undefined 再取二级,最后取一级
						const elThirdType = el.thirdLevelGoodsType;
						const elSecondType = el.secondaryGoodsType;
						const elType = el.goodsType;
						const itemThirdType = item.thirdLevelGoodsType;
						const itemSecondType = item.secondaryGoodsType;
						const itemType = item.goodsType;
						return elThirdType == itemThirdType && elSecondType == itemSecondType && elType == itemType;
					}) == -1
				) {
					return item;
				}
			});
			return list;
		},
		// 不可选择的具体商品
		disabledUpgradeGoodsList() {
			const selectList = this.classificationObj.upgradeGoods;
			const list = this.selectUpgradeGoodsList.filter((item) => {
				if (
					selectList.findIndex((el) => {
						return sameUpgradeGoodsRow(el, item);
					}) == -1
				) {
					return item;
				}
			});
			return list;
		},
		// 不可选择的商品套餐
		disabledPackageGoodsList() {
			const selectList = this.classificationObj.packageGoods;
			const list = this.selectPackageGoodsList.filter((item) => {
				if (
					selectList.findIndex((el) => {
						return el.packageCode == item.packageCode;
					}) == -1
				) {
					return item;
				}
			});
			return list;
		},
		// table
		// 分账金额设置 对应的选项
		tableSelectOptions: {
			get() {
				const info = this.financialLedgerParty;
				//  平台方
				const platformSideobj = {
					merchantId: info.realityPlatformMerchantId, // 实际分账平台方商户id(嘀加智慧云为-1)
					merchantName: info.realityPlatformMerchantName,
					targetMerchantType: 1,
				};
				// 4s 店
				const merchantSideobj = {
					merchantId: info.realityShopMerchantId, // 实际分账商户方商户id(嘀加智慧云为-1)
					merchantName: info.realityShopMerchantName,
					targetMerchantType: 3,
				};
				// 如果勾选商户 就追加进去
				if (info.djzhySubMerchantId) {
					const dizhySubMerchantObj = {
						merchantId: info.djzhySubMerchantId, // 实际分账商户方商户id(嘀加智慧云为-1)
						merchantName: info.djzhySubMerchantName,
						targetMerchantType: 4,
					};
					return [
						platformSideobj,
						dizhySubMerchantObj,
						...this.serviceSelectList,
						merchantSideobj,
					];
				}
				return info.realityShopMerchantId
					? [platformSideobj, ...this.serviceSelectList, merchantSideobj]
					: [platformSideobj, ...this.serviceSelectList];
			},
		},
		/** 仅从 classificationObjSelect 展开,不含成本开关与手续费行;仅随配置变更重算 */
		baseTableClassificationFromSelect() {
			const filterObj = deepClone(this.classificationObjSelect);
			const obj = {};
			for (const key in filterObj) {
				if (!obj[key]) {
					obj[key] = [];
				}
				filterObj[key].map((item) => {
					if (item.formType == 2) {
						obj[key].push(...item.feeCategoryNameList);
					} else {
						obj[key].push(item);
					}
				});
			}
			return obj;
		},
		tableClassificationObjSelect() {
			const base = this.baseTableClassificationFromSelect;
			const obj = {};
			for (const key in base) {
				const arr = base[key];
				obj[key] = Array.isArray(arr) ? arr.slice() : arr;
			}
			if (this.classificationObj.goodsCostFlag == "Y") {
				const arr = [
					{
						id: 3,
						expenseCategoryId: 3,
						applicationObjectName: "产品成本",
						applicationObjectType: 3,
					},
				];
				obj.platformPublic && obj.platformPublic.push(...arr);
			}
			if (this.classificationObj.virtualAccountCostFlag == "Y") {
				const arr = [
					{
						id: 300,
						expenseCategoryId: 300,
						applicationObjectName: "虚拟对账成本",
						applicationObjectType: 3,
					},
				];
				obj.platformPublic && obj.platformPublic.push(...arr);
			}
			if (this.classificationObj.recoveryCostFlag == "Y") {
				const arr = [
					{
						id: 301,
						expenseCategoryId: 301,
						applicationObjectName: "回收成本",
						applicationObjectType: 3,
					},
				];
				obj.platformPublic && obj.platformPublic.push(...arr);
			}
			if (this.classificationObj.djCostFlag == "Y") {
				const arr = [
					{
						id: 700,
						expenseCategoryId: 700,
						applicationObjectName: "嘀加成本",
						applicationObjectType: 3,
					},
				];
				obj.platformPublic && obj.platformPublic.push(...arr);
			}
			if (this.classificationObj.thirdPartyCostFlag == "Y") {
				const arr = [
					{
						id: 701,
						expenseCategoryId: 701,
						applicationObjectName: "第三方成本",
						applicationObjectType: 3,
					},
				];
				obj.platformPublic && obj.platformPublic.push(...arr);
			}

			obj.platformPublic
			&& obj.platformPublic.push({
				id: 4,
				expenseCategoryId: 4,
				applicationObjectName: "手续费",
				applicationObjectType: 3,
			});
			return obj;
			// else {
			//   return this.classificationObjSelect
			// }
		},
	},
	watch: {
		"classificationObj.goodsSource": {
			handler(newVal) {
				this.setGoodsSource({
					goodsSource: newVal,
					tabIndex: this.paneIndex,
				});
			},
			immediate: true,
		},
		// 解决商品分类取消选择的数据锁死问题(一次取消多项时仅同步第一个删除项)
		"classificationObj.goodsTypes": {
			handler(val, oldVal) {
				if (this._suppressSelectionSync) {
					return;
				}
				if (val?.length < oldVal?.length) {
					const deleteItem = oldVal.find(
						item => !val.some(el => el.thirdLevelGoodsType == item.thirdLevelGoodsType && el.secondaryGoodsType == item.secondaryGoodsType && el.goodsType == item.goodsType),
					);
					this.emitClassificationChange(
						CLASSIFICATION_EMIT.DELETE_GOODS_TYPE_ITEM,
						deleteItem,
					);
				} else {
					this.emitClassificationChange(
						CLASSIFICATION_EMIT.ASSIGN_GOODS_TYPE_LIST,
						val,
					);
				}
			},
			deep: true,
		},
		"upgradeGoodsList": {
			handler(val) {
				if (val) {
					this.copyUpgradeGoodsList = filterUpgradeGoodsByMerchantCode(
						deepClone(val),
					);
				}
			},
		},
		"packageGoodsList": {
			handler(val) {
				if (val) {
					this.copyPackageGoodsList = deepClone(val);
				}
			},
		},

		// 解决具体商品取消选择的数据锁死问题(一次取消多项时仅同步第一个删除项)
		"classificationObj.upgradeGoods": {
			handler(val, oldVal) {
				if (this._suppressSelectionSync) {
					return;
				}
				if (val) {
					if (oldVal && val?.length < oldVal?.length) {
						const deleteItem = oldVal.find(
							item =>
								!val.some(el => sameUpgradeGoodsRow(el, item)),
						);
						this.emitClassificationChange(
							CLASSIFICATION_EMIT.DELETE_UPGRADE_GOODS_ITEM,
							deleteItem,
						);
					} else {
						this.emitClassificationChange(
							CLASSIFICATION_EMIT.ASSIGN_UPGRADE_GOODS_LIST,
							val,
						);
					}
				}
			},
			deep: true,
		},
		"classificationObj.packageGoods": {
			handler(val, oldVal) {
				if (this._suppressSelectionSync) {
					return;
				}
				if (val) {
					if (oldVal && val.length < oldVal.length) {
						const deleteItem = oldVal.find(
							item => !val.some(el => el.packageCode == item.packageCode),
						);
						this.emitClassificationChange(
							CLASSIFICATION_EMIT.DELETE_PACKAGE_GOODS_ITEM,
							deleteItem,
						);
					} else {
						this.emitClassificationChange(
							CLASSIFICATION_EMIT.ASSIGN_PACKAGE_GOODS_LIST,
							val,
						);
					}
				}
			},
			deep: true,
		},
		/** 父级门控「仅对用户交互过的 Tab 做分类纯数据校验」:initList 回填期间 _suppressSelectionSync 为 true,不视为用户触碰。 */
		"classificationObj": {
			handler() {
				if (this._suppressSelectionSync) {
					return;
				}
				this.emitClassificationChange(
					CLASSIFICATION_EMIT.CLASSIFICATION_TOUCHED,
					this.paneIndex,
				);
			},
			deep: true,
		},
		"classificationObjSelect": {
			handler() {
				this.scheduleInitList();
			},
			deep: true,
			immediate: true,
		},
		"goodsTypeGroupRules": {
			handler() {
				this.scheduleInitList();
			},
			deep: true,
			// immediate: true
		},
		"tabItem.pendingCalculateErrorOps": {
			handler() {
				this.$nextTick(() => this.replayPendingCalculateErrorOps());
			},
			deep: true,
		},
	},
	mounted() {
		// this.init4sServiceList()
		this.copyUpgradeGoodsList = filterUpgradeGoodsByMerchantCode(
			deepClone(this.upgradeGoodsList),
		);
		this.copyPackageGoodsList = deepClone(this.packageGoodsList);
		this.$nextTick(() => this.replayPendingCalculateErrorOps());
	},

	methods: {
		/** 费用归属/实际分账仅存在于 TableAccount 本地 form,不落 classificationObj;需单独上报以置父页 classificationUserTouched */
		onDistributionRulesChange() {
			this.emitClassificationChange(
				CLASSIFICATION_EMIT.CLASSIFICATION_TOUCHED,
				this.paneIndex,
			);
		},
		emitClassificationChange(type, payload) {
			this.$emit("classification-change", { type, payload });
		},
		expenseSideRowKey,
		// 获取goodsType数据的最细一级值(用于唯一性判断)
		_getFinestGoodsTypeValue(item) {
			if (!item) {
				return null;
			}
			// 优先使用三级类目,然后二级,最后一级
			if (item.thirdLevelGoodsType) {
				return item.thirdLevelGoodsType;
			}
			if (item.secondaryGoodsType) {
				return item.secondaryGoodsType;
			}
			return item.goodsType;
		},
		filterGoodsTypeItemDisabled(item, list) {
			if (!item || !Array.isArray(list)) {
				return false;
			}
			// 根据最细一级的值来比较
			const itemValue = this._getFinestGoodsTypeValue(item);
			return list.findIndex((el) => {
				const elValue = this._getFinestGoodsTypeValue(el);
				return itemValue === elValue;
			}) !== -1;
		},
		filterUpgradeGoodsItemDisabled(item, list) {
			if (!item || !Array.isArray(list)) {
				return false;
			}
			return (
				list.findIndex(el => sameUpgradeGoodsRow(el, item)) !== -1
			);
		},
		filterPackageGoodsItemDisabled(item, list) {
			if (!item || !Array.isArray(list)) {
				return false;
			}
			return list.findIndex(el => el.packageCode == item.packageCode) !== -1;
		},
		expenseCategoryPlaceholder(value) {
			if (!value) {
				return "";
			}
			return value == 3 || value == 10 ? "请输入金额" : "请输入比例";
		},
		...mapMutations("FinancialRules", ["setGoodsSource", "delGoodsSource"]),
		/** 父页校验失败时写入 tabItem.pendingCalculateErrorOps,虚拟 tab 挂载后再标红 */
		replayPendingCalculateErrorOps() {
			const ops = this.tabItem && this.tabItem.pendingCalculateErrorOps;
			if (!Array.isArray(ops) || !ops.length) {
				return;
			}
			this.$nextTick(() => {
				ops.forEach((op) => {
					if (
						!op
						|| (op.side !== "trafficSide" && op.side !== "serviceProvider")
					) {
						return;
					}
					const idx = op.rowIndex;
					if (typeof idx !== "number") {
						return;
					}
					this.setCalculateError(
						idx,
						op.side,
						op.flag === undefined ? true : op.flag,
					);
				});
			});
		},
		clearValidate() {
			this.$refs.classification.clearValidate([
				"goodsTypes",
				"upgradeGoods",
				"packageGoods",
			]);
			this.copyUpgradeGoodsList = filterUpgradeGoodsByMerchantCode(
				deepClone(this.upgradeGoodsList),
			);
			this.copyPackageGoodsList = deepClone(this.packageGoodsList);
			// 先同步 categoryType 到父组件的 goodsTypeGroupRules[idx],避免后续 initList 覆盖
			this.emitClassificationChange(
				CLASSIFICATION_EMIT.SYNC_CATEGORY_TYPE,
				this.classificationObj.categoryType,
			);
			this.emitClassificationChange(
				CLASSIFICATION_EMIT.DELETE_SELECT_GOODS_TYPE_LIST,
				this.classificationObj.goodsTypes,
			);
			this.classificationObj.goodsTypes = [];
			this.emitClassificationChange(
				CLASSIFICATION_EMIT.DELETE_SELECT_UPGRADE_GOODS_LIST,
				this.classificationObj.upgradeGoods,
			);
			this.classificationObj.upgradeGoods = [];
			this.emitClassificationChange(
				CLASSIFICATION_EMIT.DELETE_SELECT_PACKAGE_GOODS_LIST,
				this.classificationObj.packageGoods,
			);
			this.classificationObj.packageGoods = [];
		},
		/* 合并表头最后两项 */
		headerCellStyle({ row, columnIndex }) {
			// 这里 row[5] 为表头倒数第二列, row[6] 为倒数第一列
			row[2].colSpan = 0;
			row[3].colSpan = 2;
			if (columnIndex === 1) {
				return { display: "none" };
			}
			return { "text-align": "center", "height": "40px" };
		},
		// 获取商品数据
		remoteMethod(query) {
			this.goodsNameKeyword = query;
			this.currentPage = 1;
			this.copyUpgradeGoodsList = [];
			this.getSelectingList(); // 请求接口
		},
		// 获取套餐数据
		remoteMethodPackage(query) {
			this.packageNameKeyword = query;
			this.currentPagePackage = 1;
			this.copyPackageGoodsList = [];
			this.getSelectingListPackage(); // 请求接口
		},
		upgradeGoodsChange() {},
		visibleChange(data) {
			if (data) {
				this.bindUpgradeGoodsLoadmoreScroll();
				if (this.goodsNameKeyword) {
					this.goodsNameKeyword = "";
					this.currentPage = 1;
					this.copyUpgradeGoodsList = [];
					this.getSelectingList();
				}
			} else {
				this.unbindUpgradeGoodsLoadmoreScroll();
			}
		},
		visibleChangePackage(data) {
			if (data) {
				this.bindPackageGoodsLoadmoreScroll();
				if (this.packageNameKeyword) {
					this.packageNameKeyword = "";
					this.currentPagePackage = 1;
					this.copyPackageGoodsList = [];
					this.getSelectingListPackage();
				}
			} else {
				this.unbindPackageGoodsLoadmoreScroll();
			}
		},
		bindUpgradeGoodsLoadmoreScroll() {
			this.unbindUpgradeGoodsLoadmoreScroll();
			this.$nextTick(() => {
				const wrap = document.querySelector(
					".classification-upgrade-goods-popper .el-select-dropdown__wrap",
				);
				if (!wrap) {
					return;
				}
				const handler = () => {
					if (wrap.scrollHeight - wrap.scrollTop <= wrap.clientHeight + 1) {
						this.interestsLoadmore();
					}
				};
				wrap.addEventListener("scroll", handler, { passive: true });
				this._upgradeGoodsScrollCleanup = () => {
					wrap.removeEventListener("scroll", handler);
					this._upgradeGoodsScrollCleanup = null;
				};
			});
		},
		unbindUpgradeGoodsLoadmoreScroll() {
			if (typeof this._upgradeGoodsScrollCleanup === "function") {
				this._upgradeGoodsScrollCleanup();
			}
		},
		bindPackageGoodsLoadmoreScroll() {
			this.unbindPackageGoodsLoadmoreScroll();
			this.$nextTick(() => {
				const wrap = document.querySelector(
					".classification-package-goods-popper .el-select-dropdown__wrap",
				);
				if (!wrap) {
					return;
				}
				const handler = () => {
					if (wrap.scrollHeight - wrap.scrollTop <= wrap.clientHeight + 1) {
						this.interestsLoadmorePackage();
					}
				};
				wrap.addEventListener("scroll", handler, { passive: true });
				this._packageGoodsScrollCleanup = () => {
					wrap.removeEventListener("scroll", handler);
					this._packageGoodsScrollCleanup = null;
				};
			});
		},
		unbindPackageGoodsLoadmoreScroll() {
			if (typeof this._packageGoodsScrollCleanup === "function") {
				this._packageGoodsScrollCleanup();
			}
		},
		// 获取更多商品
		interestsLoadmore() {
			setTimeout(() => {
				this.currentPage = this.currentPage + 1;
				if (this.allPages < this.currentPage) {
					this.currentPage = this.allPages;
					return;
				}
				this.getSelectingList();
			}, 10);
		},
		// 获取更多套餐
		interestsLoadmorePackage() {
			setTimeout(() => {
				this.currentPagePackage = this.currentPagePackage + 1;
				if (this.allPagesPackage < this.currentPagePackage) {
					this.currentPagePackage = this.allPagesPackage;
					return;
				}
				this.getSelectingListPackage();
			}, 10);
		},
		getSelectingList(defaultSelect) {
			getAllGoodsList({
				// goodsNameKeyword: this.goodsNameKeyword,
				goodsNameKeyword: this.goodsNameKeyword,
				merchantId: this.routerInfo.merchantId,
				baseSceneCode: resolveBaseSceneCodeFromRouter(this.routerInfo),
				currentPage: this.currentPage,
				pageSize: this.pageSize,
			})
				.then((res) => {
					this.allPages = resolveProductSearchPages(
						res,
						this.currentPage,
						this.pageSize,
					);
					const resArr = mapProductSearchListToUpgradeGoodsOptions(res.list);
					let arr = this.copyUpgradeGoodsList.concat(resArr);
					if (defaultSelect?.length) {
						arr = arr.concat(defaultSelect);
					}
					arr = filterUpgradeGoodsByMerchantCode(arr);
					this.copyUpgradeGoodsList = this.unique(arr);
				})
				.catch((err) => {
					// 不在此处 toast:连续加载/翻页易刷屏;通过控制台排查。
					console.error("[FinancialRules/classificationCpt] getSelectingList", err);
				});
		},
		unique(arr) {
			const res = new Map();
			return arr.filter((a) => {
				const k = getUpgradeGoodsRowKey(a);
				if (!k) {
					return false;
				}
				return !res.has(k) && res.set(k, 1);
			});
		},
		// 或者商品套餐
		getSelectingListPackage(defaultSelect = []) {
			merchantPackageGoodsInfoPage({
				matchPackageNameOrCode: this.packageNameKeyword,
				currentPage: this.currentPagePackage,
				pageSize: this.pageSizePackage,
				status: 1,
				sceneType: this.routerInfo.scene,
				merchantIdList: [this.routerInfo.merchantId],
			})
				.then((res) => {
					this.allPagesPackage = res.pages;
					const resArr = [];
					res.list
					&& res.list.forEach((val) => {
						resArr.push({
							packageCode: val.packageCode,
							packageName: val.packageName,
						});
					});
					let arr = this.copyPackageGoodsList.concat(resArr);
					if (defaultSelect?.length) {
						arr = arr.concat(defaultSelect);
					}
					this.copyPackageGoodsList = this.uniquePackage(arr);
					// this.copyPackageGoodsList = arr
				})
				.catch((err) => {
					// 不在此处 toast:同上
					console.error("[FinancialRules/classificationCpt] getSelectingListPackage", err);
				});
		},
		uniquePackage(arr) {
			const res = new Map();
			return arr.filter(
				a => !res.has(a.packageCode) && res.set(a.packageCode, 1),
			);
		},
		// ...mapActions("FinancialRules", ["reset"]),
		ruleTest() {
			this.emitClassificationChange(CLASSIFICATION_EMIT.RULES_TEST);
		},
		// handleInputChildren (newValue, name,index, type, ChildrenIndex){
		//   const  valueName =
		//   this.handleInput(newValue,type,ChildrenIndex)
		// },
		updateCalculateModeType(event, name, index) {
			const obj = this.classificationObj[name][index];
			if (obj.formType == 2) {
				const children = obj.children || [];
				children.forEach((child, i) => {
					this.$set(children[i], "calculateMode", event);
				});
				// 子项 calculateMode 已通过 $set 触发响应式,无需整组件 $forceUpdate
			}
		},
		handleInputRate(newValue, name) {
			// 'expenseCategoryValue'
			// expenseCategoryValue
			// let valueName
			// if (ChildrenIndex != undefined) {
			//   valueName = this.classificationObj[name][index].children[ChildrenIndex]
			// } else {
			// let valueName = this.classificationObj[name]
			// }
			// console.log(valueName, "valueName")
			// debugger
			// const obj = this.classificationObj[name][index]
			// console.log(obj)
			// // obj.expenseCategoryValue = newValue
			// // this.$set(this.classificationObj[name], index, obj)
			// return
			newValue = newValue.replace(/[^\d.]/g, ""); // 清除“数字”和“.”以外的字符
			// 按百分比
			// console.log(newValue)
			// 验证第一个字符是数字
			newValue = newValue.replace(/^\./g, "");
			// 只保留第一个, 清除多余的
			newValue = newValue.replace(/\.{2,}/g, ".");
			newValue = newValue
				.replace(".", "$#$")
				.replace(/\./g, "")
				.replace("$#$", ".");
			// 只能输入两个小数

			newValue = newValue.replace(/^(-)*(\d+)\.(\d\d).*$/, "$1$2.$3");
			if (newValue > 100) {
				newValue = 100;
			}

			if (newValue < 0) {
				newValue = 0;
			}
			this.classificationObj[name] = newValue;
		},
		handleInput(newValue, name, type, index, ChildrenIndex) {
			let valueName;
			if (ChildrenIndex != undefined) {
				valueName = this.classificationObj[name][index].children[ChildrenIndex];
			} else {
				valueName = this.classificationObj[name][index];
			}
			// debugger
			// const obj = this.classificationObj[name][index]
			// console.log(obj)
			// // obj.expenseCategoryValue = newValue
			// // this.$set(this.classificationObj[name], index, obj)
			// return
			newValue = newValue.replace(/[^\d.]/g, ""); // 清除“数字”和“.”以外的字符
			// const handleName = this.classificationObj[name][index]
			// 按金额
			if (type == 3 || type == 10) {
				// this.classificationObj[name][index].expenseCategoryValue = limitPrice(newValue, this.accountSecondSetForm[name], 10, 2)
				valueName.expenseCategoryValue = limitPrice(
					newValue,
					valueName.expenseCategoryValue,
					10,
					2,
				);
				// 按百分比
			} else {
				// console.log(newValue)
				// 验证第一个字符是数字
				newValue = newValue.replace(/^\./g, "");
				// 只保留第一个, 清除多余的
				newValue = newValue.replace(/\.{2,}/g, ".");
				newValue = newValue
					.replace(".", "$#$")
					.replace(/\./g, "")
					.replace("$#$", ".");
				// 只能输入两个小数

				newValue = newValue.replace(/^(-)*(\d+)\.(\d\d).*$/, "$1$2.$3");
				if (newValue > 100) {
					newValue = 100;
				}

				if (newValue < 0) {
					newValue = 0;
				}
				valueName.expenseCategoryValue = newValue;
				// this.$set(this.classificationObj[name][index], 'expenseCategoryValue', newValue)
				// console.log(this.classificationObj[name][index].expenseCategoryValue)
			}
		},
		checkSelectEmpty() {
			this.classificationObj?.serviceProvider?.forEach((val, index) => {
				if (
					!this.serviceMerchantList.find(
						el => el.merchantId == val.targetMerchant?.merchantId,
					)
				) {
					this.$set(
						this.classificationObj?.serviceProvider[index],
						"targetMerchant",
						{},
					);
					this.$set(
						this.classificationObj?.serviceProvider[index],
						"targetMerchantId",
						"",
					);
					this.$set(
						this.classificationObj?.serviceProvider[index],
						"targetMerchantName",
						"",
					);
					val?.children?.forEach((item, idx) => {
						if (
							!this.serviceMerchantList.find(
								el => el.merchantId == item.targetMerchant?.merchantId,
							)
						) {
							this.$set(
								this.classificationObj?.serviceProvider[index].children[idx],
								"targetMerchant",
								{},
							);
							this.$set(
								this.classificationObj?.serviceProvider[index].children[idx],
								"targetMerchantId",
								"",
							);
							this.$set(
								this.classificationObj?.serviceProvider[index].children[idx],
								"targetMerchantName",
								"",
							);
						}
					});
				}
			});
			this.handleSelectChange();
			this.$nextTick(() => {
				this.$refs.tableAccount?.$refs.divisionRuleRef.clearValidate();
			});
		},
		scheduleInitList() {
			if (this._initListScheduled) {
				return;
			}
			this._initListScheduled = true;
			this.$nextTick(() => {
				this._initListScheduled = false;
				this.initList();
			});
		},
		initList() {
			this._suppressSelectionSync = true;
			try {
				this.classificationObj.groupType = this.paneIndex === 0 ? 1 : 2;
				// this.goodsTypeGroupRules
				const expenseCategoryRules
					= deepClone(this.goodsTypeGroupRules.expenseCategoryRules) || [];
				// console.log('expenseCategoryRules', expenseCategoryRules)
				const setList = this.classificationObjSelect;
				// const list = {}
				// console.log('setList', this.classificationObjSelect)
				// 初始化类目
				for (const key in setList) {
					// console.log('setList[key]', setList[key])
					// console.log('key', key)
					this.classificationObj[key] = [];
					setList[key].forEach((item) => {
						// debugger
						// console.log(setList[key])
						const editObj
							= expenseCategoryRules.find(
								el => el.expenseCategoryId == item.expenseCategoryId,
							) || {};
						// 解决 类目更新名字历史财务会覆盖掉的问题
						editObj.expenseCategoryName = item.applicationObjectName;
						editObj.children = editObj.children || [];
						// console.log(editObj)
						const obj = {
							expenseCategoryCalculateType: "", // 计算方式
							expenseCategoryValue: "", // 费用类目计算值(%/元)
							targetMerchantName: "",
							targetMerchantId: "",
							expenseCategoryId: item.expenseCategoryId, // 费用类目id
							expenseCategoryName: item.applicationObjectName, // 费用类目名
							formType: item.formType,
							calculateMode: editObj?.calculateMode || 1, // 计算模式
							nodeType: item.nodeType,
							targetType: item.targetType,
							// children: []
							// { applicationObjectType: 1, applicationObjectName: 'test1', id: 1 }
						};
						if (key == "serviceProvider") {
							obj.targetMerchant = {
								merchantId: editObj?.targetMerchantId,
								merchantName: editObj?.targetMerchantName,
							};
						}
						// 是多子类目
						// if (item.formType == 2) {
						if (item.nodeType == 2) {
							// console.log(item.feeCategoryNameList, 'item.feeCategoryNameList')
							// 解决子选项问题
							editObj.children = item.feeCategoryNameList.map((ele, index) => {
								// debugger
								// console.log(ele, 'editObj')
								const editChildrenObj
									= editObj.children?.find(
										el => el.expenseCategoryId == ele.expenseCategoryId,
									) || {};
								// 解决 类目更新名字历史财务会覆盖掉的问题
								editChildrenObj.expenseCategoryName = ele.applicationObjectName;
								// 兜底规则根据最新费用类目配置 并将兜底规则 分润模式和分润比例清空
								editChildrenObj.nodeType = ele.nodeType;
								// 当expenseCategoryCalculateType == 7是兜底规则
								editChildrenObj.expenseCategoryCalculateType
									= editChildrenObj.nodeType == 4
										|| editChildrenObj.expenseCategoryCalculateType == 7
										? ""
										: editChildrenObj.expenseCategoryCalculateType;
								editChildrenObj.expenseCategoryValue
									= editChildrenObj.nodeType == 4
										|| editChildrenObj.expenseCategoryCalculateType == 7
										? ""
										: editChildrenObj.expenseCategoryValue;
								// console.log(ele, 'ele')
								const childrenObj = {
									expenseCategoryCalculateType: "", // 计算方式
									expenseCategoryValue: "", // 费用类目计算值(%/元)
									targetMerchantName: "",
									targetMerchantId: "",
									expenseCategoryId: ele.expenseCategoryId, // 费用类目id
									expenseCategoryName: ele.applicationObjectName, // 费用类目名
									// expenseCategoryName: 22, // 费用类目名
									calculateMode: editChildrenObj?.calculateMode || 1, // 计算模式
									// nodeType: ele.nodeType ? ele.nodeType : ele.feeCategoryNameList.length - 1 != index ? 3 : 4,
									nodeType: ele.nodeType,
									categoryToSort: ele.categoryToSort,
									targetType: ele.targetType,
									// { applicationObjectType: 1, applicationObjectName: 'test1', id: 1 }
								};
								// console.log(item.feeCategoryNameList.length, index)
								if (key == "serviceProvider") {
									// console.log(editChildrenObj, 'editChildrenObj')
									childrenObj.targetMerchant = {
										merchantId: editChildrenObj?.targetMerchantId,
										merchantName: editChildrenObj?.targetMerchantName,
									};
									// console.log(childrenObj, 'editChildrenObj')
								}
								// return Object.assign(childrenObj, editChildrenObj)
								// console.log(editChildrenObj, 'editChildrenObj')
								return Object.assign(childrenObj, editChildrenObj);
							});
							// console.log(obj.children, ' obj.children')
						}
						// console.log(editObj, 'obj')
						this.classificationObj[key].push(Object.assign(obj, editObj));
						// console.log(this.classificationObj, ' this.classificationObj')
						// debugger
						// this.classificationObj[key].push(Object.assign(obj))
						// 流量方分润/其他费用是按整单计算 服务商分润 均为按整单计算 不可操作
						// if (key == 'trafficSide' || key == 'platformPublic') {
						//   if (editObj?.calculateMode == 2) {
						//     this.classificationObj.serviceProvider?.forEach(val => {
						//       val.isDisabled = true
						//       val.calculateMode = 2
						//     })
						//   }
						// }
					});
				}
				// 需要拷贝的值
				const keyNameList = [
					"shop4sDeductChargeFlag",
					"partnerDeductChargeFlag",
					"goodsCostFlag",
					"virtualAccountCostFlag",
					"recoveryCostFlag",
					"djCostFlag",
					"thirdPartyCostFlag",
					"groupType",
					"goodsTypes",
					"categoryType",
					"upgradeGoods",
					"packageGoods",
					"goodsSource",
					"goodsCostConvertRate",
					"virtualAccountCostConvertRate",
					"recoveryCostConvertRate",
					"djCostConvertRate",
					"thirdPartyCostConvertRate",
				];
				// 勿将 packageGoods / categoryType 先写成 "":接口无字段时会残留字符串,
				// getParams 在 categoryType 为空时会把 goodsTypeGroupRelations 误置为 "",触发「未指定商品/品类列表」。
				keyNameList.forEach((item) => {
					if (
						this.goodsTypeGroupRules[item] !== undefined
						&& this.goodsTypeGroupRules[item] !== null
					) {
						this.classificationObj[item] = this.goodsTypeGroupRules[item];
					}
				})
				;["goodsTypes", "upgradeGoods", "packageGoods"].forEach((k) => {
					const v = this.classificationObj[k];
					if (!Array.isArray(v)) {
						this.classificationObj[k]
							= v && typeof v === "object" ? [v] : v ? [v] : [];
					}
				});
				if (this.classificationObj.categoryType === 2) {
					this.classificationObj.upgradeGoods = filterUpgradeGoodsByMerchantCode(
						this.classificationObj.upgradeGoods,
					);
				}
				/*
       * 整表深拷贝:与父级/接口合并后的数据断开引用,避免表单编辑意外回写共享对象。
       * 代价:分类结构大或多 tab 时 clone 成本高;后续优化可优先考虑「仅对变更节点 $set」而非每次 init 全量 clone。
       */
				this.classificationObj = deepClone(this.classificationObj);
				// console.log(list)
				this.handleSelectChange();
				// this.classificationObj.expenseCategoryRules = list
			} finally {
				this.$nextTick(() => {
					this._suppressSelectionSync = false;
					this.replayPendingCalculateErrorOps();
					// 接口/缓存回填后清除校验态,避免初始化即出现红字(提交/测算时再 validate)
					if (
						this.$refs.classification
						&& typeof this.$refs.classification.clearValidate === "function"
					) {
						this.$refs.classification.clearValidate();
					}
					const ta = this.$refs.tableAccount;
					if (ta && ta.$refs) {
						if (typeof ta.$refs.divisionRuleRef?.clearValidate === "function") {
							ta.$refs.divisionRuleRef.clearValidate();
						}
						if (typeof ta.$refs.divisionRuleRef2?.clearValidate === "function") {
							ta.$refs.divisionRuleRef2.clearValidate();
						}
					}
				});
			}
		},
		filterEmpty(data) {
			return (data ?? "") === "";
		},
		/**
		 * 分润模式下拉变更时清空对应「费用取值」,并强制刷新视图。
		 * @param e 选中的分润模式(有值时会清空 expenseCategoryValue)
		 * @param name 分润方 key:trafficSide | serviceProvider | platformPublic
		 * @param index 主类目下标
		 * @param subIndex 子类目下标;空则为清空主类目取值
		 * 说明:此处依赖 $forceUpdate,因部分深层嵌套与 Element 表单项在仅改字段时偶发不同步;请勿用无参 this.forceUpdate() 作为通用手段。
		 */
		forceUpdate(e, name, index, subIndex) {
			if (e) {
				if (this.filterEmpty(subIndex)) {
					// 主类目
					this.classificationObj[name][index].expenseCategoryValue = "";
				} else {
					// 子类目
					this.classificationObj[name][index].children[
						subIndex
					].expenseCategoryValue = "";
				}
			}
			this.$forceUpdate(); // 强制更新
		},

		// 切换流量方/其他费用分润计算方式
		changeCalculateModeType(e) {
			if (e == 2) {
				// 流量方分润/其他费用是按整单计算 服务商分润同步为整单不可操作
				this.classificationObj.serviceProvider.forEach((val, index) => {
					this.$set(
						this.classificationObj.serviceProvider[index],
						"calculateMode",
						2,
					);
					this.$set(
						this.classificationObj.serviceProvider[index],
						"isDisabled",
						true,
					);
				});
			} else {
				this.classificationObj.serviceProvider.forEach((val, index) => {
					// 流量方分润/其他费用 有一个规则是整单 都不可编辑
					if (
						this.classificationObj.trafficSide.findIndex(
							v => v.calculateMode == 2,
						) > -1
						|| this.classificationObj.platformPublic.findIndex(
							v => v.calculateMode == 2,
						) > -1
					) {
						return;
					}
					this.$set(
						this.classificationObj.serviceProvider[index],
						"isDisabled",
						false,
					);
				});
			}
		},

		handleSelectChange() {
			const serviceProviderList = this.classificationObj.serviceProvider;
			let list = [];
			// console.log('serviceProviderList', serviceProviderList)
			if (
				typeof serviceProviderList == "object"
				&& serviceProviderList.length > 0
			) {
				list = serviceProviderList.reduce((pre, cur) => {
					const id = cur?.targetMerchant.merchantId;
					// 数组对象去重
					if (id && pre.findIndex(el => el.merchantId == id) == -1) {
						// console.log(cur)
						pre.push({
							merchantId: id,
							merchantName: cur.targetMerchant.merchantName,
							targetMerchantType: 2,
						});
					}
					if (cur.formType == 2) {
						// console.log(cur, 'cur')
						cur?.children
						&& cur.children.map((ele) => {
							const id = ele?.targetMerchant?.merchantId;
							if (id && pre.findIndex(el => el.merchantId == id) == -1) {
								// console.log(cur)
								pre.push({
									merchantId: id,
									merchantName: ele.targetMerchant.merchantName,
									targetMerchantType: 2,
								});
							}
						});
					}
					return pre;
				}, []);
			}

			this.serviceSelectList = list;
		},
		getParams() {
			const obj = deepClone(this.classificationObj);
			const expenseCategoryRules = [];
			// 合并出对象的集合 类目对象合集
			for (const key in obj) {
				if (
					Array.isArray(obj[key])
					&& key != "goodsTypes"
					&& key != "upgradeGoods"
					&& key != "packageGoods"
				) {
					const list = obj[key].map((cur) => {
						if (cur.formType == 2) {
							cur.children = (cur.children || []).map((ele) => {
								return {
									...ele,
									targetMerchantId:
                    ele?.targetMerchant?.merchantId ?? ele?.targetMerchantId,
									targetMerchantName:
                    ele?.targetMerchant?.merchantName ?? ele?.targetMerchantName,
								};
							});
						}
						return {
							...cur,
							targetMerchantId:
                cur?.targetMerchant?.merchantId ?? cur?.targetMerchantId,
							targetMerchantName:
                cur?.targetMerchant?.merchantName ?? cur?.targetMerchantName,
						};
					});
					expenseCategoryRules.push(...list);
				}
			}
			// console.log('expenseCategoryRules', expenseCategoryRules)
			const groupType = this.paneIndex ? 2 : 1;
			const asList = v =>
				Array.isArray(v) ? deepClone(v) : v && typeof v === "object" ? [deepClone(v)] : [];

			let goodsTypes = asList(obj.goodsTypes);
			let upgradeGoods = asList(obj.upgradeGoods);
			let packageGoods = asList(obj.packageGoods);
			goodsTypes.forEach((val) => {
				val.categoryType = 1;
			});
			upgradeGoods.forEach((val) => {
				val.categoryType = 2;
			});
			packageGoods.forEach((val) => {
				val.categoryType = 3;
			});

			const returnObj = {
				expenseCategoryRules,
				shop4sDeductChargeFlag: obj.shop4sDeductChargeFlag,
				partnerDeductChargeFlag: obj.partnerDeductChargeFlag,
				virtualAccountCostFlag: obj.virtualAccountCostFlag,
				recoveryCostFlag: obj.recoveryCostFlag,
				djCostFlag: obj.djCostFlag,
				thirdPartyCostFlag: obj.thirdPartyCostFlag,
				goodsCostFlag: obj.goodsCostFlag,
				goodsSource: obj.goodsSource,
				goodsCostConvertRate: obj.goodsCostConvertRate,
				virtualAccountCostConvertRate: obj.virtualAccountCostConvertRate,
				recoveryCostConvertRate: obj.recoveryCostConvertRate,
				djCostConvertRate: obj.djCostConvertRate,
				thirdPartyCostConvertRate: obj.thirdPartyCostConvertRate,
				groupType,
				goodsTypes,
				upgradeGoods,
				packageGoods,
			};
			// 非嘀加:与原先一致
			if (obj.goodsSource != 1) {
				return returnObj;
			}

			/**
			 * 嘀加商品来源(goodsSource===1):对齐 shelfManage/editCon/classificationCpt.getParams。
			 * categoryType 与 goodsTypes/upgradeGoods/packageGoods 不一致时,仅按 categoryType 取 relations 会得到空/错误类型,
			 * 后端报错:特殊品类-嘀加商品来源-未指定商品/品类列表。
			 */
			const pickRelations = (ct) => {
				if (ct == 1) {
					return goodsTypes;
				}
				if (ct == 2) {
					return upgradeGoods;
				}
				return packageGoods;
			};
			let effectiveCategoryType = obj.categoryType;
			let goodsTypeGroupRelations = pickRelations(effectiveCategoryType);

			const hasG = goodsTypes.length > 0;
			const hasU = upgradeGoods.length > 0;
			const hasP = packageGoods.length > 0;
			const singleFilledDim
				= Number(hasG) + Number(hasU) + Number(hasP) === 1
					? hasG
						? 1
						: hasU
							? 2
							: 3
					: null;
			if (
				(!goodsTypeGroupRelations || !goodsTypeGroupRelations.length)
				&& singleFilledDim != null
			) {
				effectiveCategoryType = singleFilledDim;
				goodsTypeGroupRelations = pickRelations(singleFilledDim);
			}

			const rule
				= this.goodsTypeGroupRules && typeof this.goodsTypeGroupRules === "object"
					? this.goodsTypeGroupRules
					: {};
			let relFallback = null;
			let fbCt = null;
			const rCt = rule.categoryType;
			if (rCt == 1 && Array.isArray(rule.goodsTypes) && rule.goodsTypes.length) {
				relFallback = deepClone(rule.goodsTypes);
				fbCt = 1;
			} else if (
				rCt == 2
				&& Array.isArray(rule.upgradeGoods)
				&& rule.upgradeGoods.length
			) {
				relFallback = deepClone(rule.upgradeGoods);
				fbCt = 2;
			} else if (
				rCt == 3
				&& Array.isArray(rule.packageGoods)
				&& rule.packageGoods.length
			) {
				relFallback = deepClone(rule.packageGoods);
				fbCt = 3;
			} else if (
				Array.isArray(rule.goodsTypeGroupRelations)
				&& rule.goodsTypeGroupRelations.length
			) {
				relFallback = deepClone(rule.goodsTypeGroupRelations);
				fbCt
					= rule.goodsTypeGroupRelations[0]?.categoryType || rCt || 1;
			}
			if (
				(!goodsTypeGroupRelations || !goodsTypeGroupRelations.length)
				&& Array.isArray(relFallback)
				&& relFallback.length
			) {
				// 表单上该维度已无任何勾选时,不得用 props 里的 rule(上一版缓存/接口体)把清单写回,
				// 否则 persist / 切 Tab 会把用户刚取消的勾选还原。
				const dimFormEmpty = (ct) => {
					if (ct == 1) {
						const g = obj.goodsTypes;
						return !g || (Array.isArray(g) && g.length === 0);
					}
					if (ct == 2) {
						const u = obj.upgradeGoods;
						return !u || (Array.isArray(u) && u.length === 0);
					}
					const p = obj.packageGoods;
					return (
						p == null
						|| p === ""
						|| (Array.isArray(p) && p.length === 0)
					);
				};
				if (fbCt != null && dimFormEmpty(fbCt)) {
					// skip relFallback
				} else {
					goodsTypeGroupRelations = relFallback;
					if (fbCt == 1 || fbCt == 2 || fbCt == 3) {
						effectiveCategoryType = fbCt;
					}
					if (effectiveCategoryType == 1) {
						goodsTypes = goodsTypeGroupRelations;
						returnObj.goodsTypes = goodsTypes;
					} else if (effectiveCategoryType == 2) {
						upgradeGoods = goodsTypeGroupRelations;
						returnObj.upgradeGoods = upgradeGoods;
					} else {
						packageGoods = goodsTypeGroupRelations;
						returnObj.packageGoods = packageGoods;
					}
				}
			}

			;(goodsTypeGroupRelations || []).forEach((val) => {
				if (val && typeof val === "object") {
					val.categoryType = effectiveCategoryType;
				}
			});

			// 特殊品类:兜底——仅单行度有数据时与后端期望的 goodsTypeGroupRelations 对齐
			if (
				groupType === 2
				&& (!goodsTypeGroupRelations || !goodsTypeGroupRelations.length)
			) {
				if (goodsTypes.length && !upgradeGoods.length && !packageGoods.length) {
					effectiveCategoryType = 1;
					goodsTypeGroupRelations = deepClone(goodsTypes);
				} else if (
					!goodsTypes.length
					&& upgradeGoods.length
					&& !packageGoods.length
				) {
					effectiveCategoryType = 2;
					goodsTypeGroupRelations = deepClone(upgradeGoods);
				} else if (
					!goodsTypes.length
					&& !upgradeGoods.length
					&& packageGoods.length
				) {
					effectiveCategoryType = 3;
					goodsTypeGroupRelations = deepClone(packageGoods);
				}
				;(goodsTypeGroupRelations || []).forEach((val) => {
					if (val && typeof val === "object") {
						val.categoryType = effectiveCategoryType;
					}
				});
			}

			// 全部品类(groupType===1):与可过校验的报文一致——嘀加来源无清单时用空字符串而非 [] / 省略字段
			if (groupType === 1 && (!goodsTypeGroupRelations || !goodsTypeGroupRelations.length)) {
				return {
					...returnObj,
					goodsTypes: [],
					upgradeGoods: [],
					packageGoods: "",
					categoryType: "",
					goodsTypeGroupRelations: "",
				};
			}

			return {
				...returnObj,
				categoryType: effectiveCategoryType,
				goodsTypeGroupRelations,
			};
		},
		handleConfirm() {
			return new Promise((resolve) => {
				if (!this.$refs.classification) {
					resolve(false);
					return;
				}
				// 勿用 async 作为 validate 回调:避免与 Element 表单校验时序叠加后下方表单项未标红
				this.$refs.classification.validate((valid) => {
					if (!valid) {
						this.$nextTick(() => this.scrollClassificationFirstError());
						resolve(false);
						return;
					}
					const obj = this.getParams();
					const ta = this.$refs.tableAccount;
					if (!ta) {
						resolve(false);
						return;
					}
					ta.handleConfirm().then((res) => {
						if (!res) {
							resolve(false);
							return;
						}
						ta.handleConfirm2().then((res2) => {
							if (!res2) {
								resolve(false);
								return;
							}
							resolve({
								...obj,
								merchantDistributionRules: res,
								owningMerchantDistributionRules: res2,
							});
						});
					});
				});
			});
		},
		scrollClassificationFirstError() {
			const form = this.$refs.classification;
			if (!form || !form.fields) {
				return;
			}
			const first = form.fields.find(f => f.validateState === "error");
			if (first && first.$el) {
				first.$el.scrollIntoView({ block: "center", behavior: "smooth" });
			}
		},
		getClassificationParams() {
			const obj = this.getParams();
			const res = this.$refs.tableAccount.getTableAccountParams();
			const res2 = this.$refs.tableAccount.getTableAccountParams2();
			// console.log("res", { ...obj, merchantDistributionRules: res })
			return { ...obj, merchantDistributionRules: res, owningMerchantDistributionRules: res2 };
			// : resolve(false)
			// return new Promise((resolve, reject) => {
			//   this.$refs.classification.validate(async (valid) => {
			//     console.log(valid)
			//     if (valid) {
			//       // console.log(this.getParams())
			//       const obj = this.getParams()
			//       const res = await this.$refs.tableAccount.handleConfirm()
			//       console.log("res", { ...obj, merchantDistributionRules: res })
			//       res
			//         ? resolve({ ...obj, merchantDistributionRules: res })
			//         : resolve(false)
			//     } else {
			//       resolve(false)
			//     }
			//   })
			// })
		},
		setCalculateError(index, item, flag = true) {
			if (this.classificationObj[item][index]) {
				this.$set(
					this.classificationObj[item][index],
					"calculateModeError",
					flag,
				);
			}
		},
	},
	beforeUnmount() {
		this.unbindUpgradeGoodsLoadmoreScroll();
		this.unbindPackageGoodsLoadmoreScroll();
		this.delGoodsSource({ tabIndex: this.paneIndex });
	},
};
</script>

<style scoped lang="scss">
.edit-sub-title {
	padding-bottom: 15px;
	border-bottom: 1px solid #e8e8ea;
}

::v-deep {
	.trafficSide,
	.platformPublic,
	.serviceProvider {
		display: flex;
		flex-flow: column;

		.el-form-item {
			width: 28%;
		}

		.check_calculateMode {
			margin-left: 30px;
			color: #f56c6c;
		}
	}
}

.el-select-dropdown__item {
	padding-right: 40px;

	.goodName {
		color: #333333;
	}

	.typeName {
		margin: 0 8px;
		font-size: 12px;
		color: #999999;
	}
}

.el-select-dropdown__item.selected {
	span {
		color: #2a58ad;
	}
}

.edit-form-item-table {
	width: 90% !important;
}

.edit-form-item-table-children {
	width: 100% !important;
}

::v-deep {
	.el-select__tags,
	.el-cascader__tags {
		white-space: nowrap;
		overflow: hidden;
		flex-wrap: nowrap;

		.el-tag--info {
			display: flex;
			align-items: center;
		}
	}
	.el-cascader__tags {
		.el-tag span {
			display: inline-block;
			max-width: 240px;
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
		}
	}

	.el-select__tags-text {
		display: inline-block;
		max-width: 240px;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	.el-form-item__label {
		display: flex;
		align-items: center;
		justify-content: flex-end;

		.label-span {
			display: flex;
			align-items: center;

			.sub-label {
				display: inline-block;
				max-width: 205px;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
			}
		}
	}

	.rateinput {
		margin-left: 30px;
	}
}
</style>