add_purchase.js 174 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 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271
// components/add_purchase/add_purchase.js
var s = getApp(),
  ut = require("../../utils/util"),
  i = s.request,
  rq = i,
  oo = s.globalData,
  o = s.globalData.setting,
  os = o;
let self = null;
var wxlog = require("../../utils/wxlog.js");
var w_time = null;
var timer_get = null;
var t_time = null;
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  lifetimes: {
    // attached: function () {
    //   // this.clearTime()
    //   console.error('加购组件');
    //   self = this
    //   // 在组件实例进入页面节点树时执行
    //   let ee = this, that = ee, th = ee;
    //   //先获取一下导购的门店
    //   th.check_guide(() => {
    //     th.get_user_store();
    //   })
    //   //----获取系统参数-----
    //   getApp().getConfig2(function (e) {
    //     ee.setData({
    //       bconfig: e,
    //       sales_rules: e.sales_rules,
    //     });
    //     th.wait_for_store_config();
    //     if (e.categoryset.indexOf("," + 1 + ",") != -1) {
    //       ee.setData({
    //         is_show_pl: 1
    //       });
    //     }
    //     if (e.categoryset.indexOf("," + 3 + ",") != -1) {
    //       ee.setData({
    //         is_show_pp: 1
    //       });
    //     }
    //     if (e.categoryset.indexOf("," + 2 + ",") != -1) {
    //       ee.setData({
    //         is_show_gb: 1
    //       });
    //     }
    //     console.log('获取系统参数');
    //     console.log(e);
    //     var json_d = JSON.parse(e.switch_list);
    //     ee.setData({
    //       store_config: e,
    //       sys_switch: json_d,
    //       is_closecoupon: json_d.is_closecoupon,
    //       is_newsales_rules: json_d.is_newsales_rules,
    //       is_retail_price: json_d.is_retail_price || 0,
    //       appoint_pick_keyid: json_d.appoint_pick_keyid,
    //       // goods_bottomconent:e.goods_bottomconent
    //     });

    //     //判断商品详情要有东西
    //     // if (e && e.goods_bottomconent) {
    //     //   //商品详情广告----
    //     //   a.wxParse("goodInfo_ad", "html", ut.format_content(e.goods_bottomconent), ee, 6);
    //     //   common.wxParseAddFullImageUrl(ee, "goodInfo_ad");
    //     //   //-------
    //     // }

    //     //------几人评价-------
    //     //n.init(th, "", "comments");

    //     // th.requestCardNum(), 
    //     wx.pageScrollTo && th.setData({
    //       supportPageScroll: !0
    //     });

    //     //计算等级价相关
    //     var swithc_list = e.switch_list;
    //     var sw_arr = JSON.parse(swithc_list);
    //     console.log('plus-111')
    //     //---如果后台又开等级卡的开关---
    //     ut.get_plus_name_price(sw_arr, th);

    //   }, 1);
    // },

  },
  /**
   * 组件的初始数据
   */
  data: {
    add_cart_show: false, //是否显示
    iurl: getApp().globalData.setting.imghost,
    prom_price: null,
    sele_g: null,
    gid: '',
    prom_type: '',
    prom_id: '',
    goodsInputNum: 1,
    def_pick_store: null, // 默认的门店
    openSpecModal_ind: 1,
    goods_type: 0,
    iscart: 0, //是否从购物车过来的
    cx_prom_group: [], //促销活动,用于显示和判断默认要用什么促销活动
    //门店相关
    ismend: 0,
    only_pk: null,
    stoid: o.stoid,
    is_get_local_ok: 0, //获取坐标是否完成
    def_pickpu_list: null,
    more_store: 0, //选择门店
    sort_store: 0, //门店分类
    choice_sort_store: 0, //选择分类门店
    sec_pick_index: 0, //第二级门店选择ID
    fir_pick_index: 0, //第一级门店选择ID
    all_pick_list: null, //所有的门店先记录起来
    fir_def_store: null, //客户默认的门店的
    keyword: '', //门店搜索
    is_no_new: 1,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    closeSpecModal() {
      this.clearTime()
      this.setData({
        add_cart_show: false
      })

      this.triggerEvent('hide_add_purchase', {})
    },
    clearTime() {
      if (timer_get) {
        clearInterval(timer_get);
      }
      if (w_time) {
        clearInterval(w_time);
      }
      if (t_time) {
        clearInterval(t_time);
      }

    },
    previewImage(e) {
      // this.data.show_prew_img = 1;
      getApp().pre_img(this.data.sele_g.original_img);
    },
    initbef: function () {
      // this.clearTime()
      console.error('加购组件');
      self = this
      // 在组件实例进入页面节点树时执行
      let ee = this, that = ee, th = ee;
      //先获取一下导购的门店
      th.check_guide(() => {
        th.get_user_store();
      })
      //----获取系统参数-----
      getApp().getConfig2(function (e) {
        ee.setData({
          bconfig: e,
          sales_rules: e.sales_rules,
        });
        th.wait_for_store_config();
        if (e.categoryset.indexOf("," + 1 + ",") != -1) {
          ee.setData({
            is_show_pl: 1
          });
        }
        if (e.categoryset.indexOf("," + 3 + ",") != -1) {
          ee.setData({
            is_show_pp: 1
          });
        }
        if (e.categoryset.indexOf("," + 2 + ",") != -1) {
          ee.setData({
            is_show_gb: 1
          });
        }
        console.log('获取系统参数');
        console.log(e);
        var json_d = JSON.parse(e.switch_list);
        ee.setData({
          store_config: e,
          sys_switch: json_d,
          is_closecoupon: json_d.is_closecoupon,
          is_newsales_rules: json_d.is_newsales_rules,
          is_retail_price: json_d.is_retail_price || 0,
          appoint_pick_keyid: json_d.appoint_pick_keyid,
          // goods_bottomconent:e.goods_bottomconent
        });

        //判断商品详情要有东西
        // if (e && e.goods_bottomconent) {
        //   //商品详情广告----
        //   a.wxParse("goodInfo_ad", "html", ut.format_content(e.goods_bottomconent), ee, 6);
        //   common.wxParseAddFullImageUrl(ee, "goodInfo_ad");
        //   //-------
        // }

        //------几人评价-------
        //n.init(th, "", "comments");

        // th.requestCardNum(), 
        wx.pageScrollTo && th.setData({
          supportPageScroll: !0
        });

        //计算等级价相关
        var swithc_list = e.switch_list;
        var sw_arr = JSON.parse(swithc_list);
        console.log('plus-111')
        //---如果后台又开等级卡的开关---
        ut.get_plus_name_price(sw_arr, th);

      }, 1);
    },
    init(gid, prom_type, prom_id, goods_type = 0, iscart = 0, cartid = 0) {
      this.initbef()
      // this.clearTime()
      //--先判断会员状态-- 
      var user_info = getApp().globalData.userInfo;
      if (user_info == null || user_info.mobile == undefined || user_info.mobile == "" || user_info.mobile == null) {
        wx.showModal({
          title: '提示',
          content: '你还没有登录',
          confirmText: '去登录',
          success(res) {

            if (res.confirm) {
              wx.navigateTo({
                url: '/packageE/pages/togoin/togoin',
              })
            } else if (res.cancel) {
              console.log('用户点击取消')
            }
          }
        })
        return false;
      }


      if (!gid) {
        wx.showToast({
          title: '商品信息不对',
          icon: 'none'
        })
        return
      }
      this.setData({
        gid,
        prom_id,
        prom_type,
        goods_type,
        add_cart_show: true,
        goodsInputNum: 1,
        iscart,
        cartid
      })
      if (goods_type == 1) {
        this.get_ser_info()
      } else {
        this.get_goods_info()
      }

    },
    //获取服务详情 
    get_ser_info() {
      let i = getApp().request;
      let gid = this.data.gid
      let ee = this;
      let that = this
      let th = this;
      i.get("/api/weshop/serviceCard/get/" + o.stoid + "/" + ee.data.gid, {
        failRollback: !0,
        success: function (t) {
          if (t.data.code == 0) {
            // console.log('GET pic and video');
            if (t.data.data.listServiceItem) {
              that.setData({
                listServiceItem: t.data.data.listServiceItem,
              });
            };
            that.setData({
              'sele_g.goods_name': t.data.data.serviceName,
              'sele_g.shop_price': t.data.data.money,
              'sele_g.show_price': t.data.data.show_price,
              'sele_g.validDays': t.data.data.validDays,
              'sele_g.serviceContent': t.data.data.serviceContent,
              'sele_g.image_url': t.data.data.imgUrl,
              'sele_g.original_img': that.data.iurl + t.data.data.imgUrl,
              'sele_g.goods_id': t.data.data.id,
              'sele_g.id': t.data.data.id,
              'sele_g.sales_sum': t.data.data.sales_sum,
              'sele_g.storageId': t.data.data.storageId,
              'sele_g.service_sn': t.data.data.serviceSn,
              'sele_g.listServiceVideos': t.data.data.listServiceVideos,

              'data.goods_name': t.data.data.serviceName,
              'data.shop_price': t.data.data.money,
              'data.show_price': t.data.data.show_price,
              'data.validDays': t.data.data.validDays,
              'data.serviceContent': t.data.data.serviceContent,
              'data.image_url': t.data.data.imgUrl,
              'data.original_img': that.data.iurl + t.data.data.imgUrl,
              'data.goods_id': t.data.data.id,
              'data.id': t.data.data.id,
              'data.sales_sum': t.data.data.sales_sum,
              'data.storageId': t.data.data.storageId,
              'data.service_sn': t.data.data.serviceSn,
              'data.listServiceVideos': t.data.data.listServiceVideos,
            });

            // that.getTaohe();
            // ----> 秒杀
            let prom_type = th.data.prom_type;

            let goods_id = th.data.goods_id;
            if (!goods_id) goods_id = th.data.sele_g.goods_id;

            if (prom_type) { // 进入商品详情页地址传参有带goods_id、prom_type、prom_id参数, 即从秒杀入口进入
              let prom_id = th.data.prom_id;
              // 检查活动是否开始
              th.ser_check_prom(goods_id, prom_type, prom_id);

            } else { // 从非秒杀入口进入,地址不带prom_type、prom_id参数
              getApp().request.promiseGet('/api/weshop/activitylist/listGoodActInfo2', {
                data: {
                  store_id: os.stoid,
                  goods_id: goods_id,
                  goods_type: 1,
                  user_id: oo.user_id,
                }
              }).then(res => {
                if (res.data.code == 0) {
                  let result = res.data.data;
                  let resLength = result.length;
                  if (resLength == 1) { // 如果数组长度为1,则直接显示当前活动
                    let goods_id = th.data.gid;
                    let prom_type = result[0].prom_type;
                    let prom_id = result[0].act_id;
                    th.setData({
                      prom_type: prom_type,
                      prom_id: prom_id,
                    });
                    // 检查活动是否开始
                    th.ser_check_prom(goods_id, prom_type, prom_id);
                  } else if (resLength > 1) { //如果数组长度大于1,表示当前商品参加多个活动,以列表形式显示多活动
                    th.setData({
                      actList: res.data.data,
                    });
                  };

                } else {
                  th.setData({
                    actList: res.data.data,
                  });
                }
              });
            };

            // console.log('0xxxxx999999', t.data.data);
            //-----商品详情---
            //if(!t.data.data.serviceContent) t.data.data.serviceContent="  ";
            //a.wxParse("content", "html", ut.format_content(t.data.data.serviceContent), ee, 6);
            //e.wxParseAddFullImageUrl(ee, "content");
            // getApp().deal_iframe(a,e,'content',t.data.data.serviceContent,ee);

            //获取重表
            getApp().promiseGet("/api/weshop/serviceItem/list", {
              data: { store_id: o.stoid, service_id: t.data.data.id }
            }).then(res => {
              if (res.data.code == 0) {
                var list = res.data.data;
                that.setData({ service_list: list })
              }
            })

          } else {
            wx.showModal({
              title: t.data.msg,
              showCancel: !1,
              complete: function () {
                wx.navigateBack();
              }
            });
          };
        }
      });

    },
    get_normal(gid) {
      this.setData({
        prom_type: 0,
        isshow: 1,
      });
      if (this.data.goods_type != 1) {

        this.get_sku(os.stoid, this.data.data, gid);
      }

      this.get_sto();
      if (!this.data.data.whsle_id)
        this.check_is_youhui(gid);
      this.data.is_normal = 1;
    },
    //获取商品详情
    get_goods_info() {

      let i = getApp().request;
      let gid = this.data.gid
      let ee = this;
      i.get("/api/weshop/goods/get/" + getApp().globalData.setting.stoid + "/" + this.data.gid, {
        failRollback: !0,
        success: (t) => {
          console.log(t);
          // t.data.data.prom_type=0
          if (t.data.code == 0) {
            // if (t.data.data && t.data.data.prom_type == 4) {
            //   if (ee.data.prom_type4 == 1) {
            //     t.data.data.prom_type = 0
            //   }
            // }
            if (t.data.data.is_on_sale != 1) {
              wx.showToast({
                title: '商品已经下架',
                icon: 'none',
                duration: 2000
              })
              return
            }
            // ee.init(gid);
            var timestamp = Date.parse(new Date());
            timestamp = timestamp / 1000;
            if (t.data.data.on_time > timestamp) {
              wx.showToast({
                title: '商品还未上架',
                icon: 'none',
                duration: 2000
              })
              return
            }

            if (t.data.data.down_time > 0) {
              if (t.data.data.down_time < timestamp) {
                wx.showToast({
                  title: '商品已经到期下架',
                  icon: 'none',
                  duration: 2000
                })
                return
              }
            }

            // let p_type = parseInt(this.data.prom_type ? ee.data.prom_type : 0);



            //-- 把商品的赋值,同时给活动赋值 --
            ee.data.fir_goods = JSON.parse(JSON.stringify(t.data.data));

            t.data.data.on_time = ut.formatTime(t.data.data.on_time, 'yyyy-MM-dd hh:mm:ss');

            let cur_price = t.data.data.shop_price;
            if (getApp().globalData.userInfo && getApp().globalData.userInfo.card_field) {
              let cfile = getApp().globalData.userInfo.card_field;
              if (t.data.data[cfile]) {
                cur_price = t.data.data[cfile];
              }
            }
            let txt = (cur_price / t.data.data.market_price * 10).toFixed(2).toString();
            txt = parseFloat(txt);

            t.data.data['disc'] = txt;

            if (t.data.data.original_img.indexOf(o.imghost) == -1)
              t.data.data.original_img = o.imghost + t.data.data.original_img;


            t.data.data.prom_type = ee.data.prom_type;
            t.data.data.prom_id = ee.data.prom_id;

            //只有是普通商品的时候,才要给商品赋值指定门店
            if ([1, 2, 4, 6, 8, 9].indexOf(parseInt(ee.data.prom_type)) < 0 && t.data.data.pick_up_lists && t.data.data.pick_up_lists.length) {
              t.data.data.pickup_ids = t.data.data.pick_up_lists;
            }
            //}
            ee.setData({
              data: t.data.data,
              sele_g: t.data.data,
              userInfo: getApp().globalData.userInfo
            });

            //一件代发商品不去计算优惠
            if (!ee.data.fir_goods.whsle_id && ee.data.prom_type != 1 && ee.data.prom_type != 4 && ee.data.prom_type != 6 && ee.data.prom_type != 2) {
              ee.check_is_youhui(ee.data.gid);
            }


            //获取统一条形码,普通商品和优惠促销的商品
            if (ee.data.data.prom_type == 0 || ee.data.data.prom_type == 3 || ee.data.data.prom_type == 5 || ee.data.data.prom_type == 7 || ee.data.data.prom_type == 9 || ee.data.data.prom_type == 10) {
              ee.get_sto();
              ee.get_sku(o.stoid, t.data.data, gid);
              ee.check_has_flash();

            } else {
              var gg = "",
                item = t.data.data;

              if (item.goods_spec == "null" || item.goods_spec == null) item.goods_spec = "";
              if (item.goods_color == "null" || item.goods_color == null) item.goods_color = "";

              if (item.goods_spec != "" && item.goods_color != "") {
                gg = item.goods_spec + "/" + item.goods_color;
              } else if (item.goods_spec != "" || item.goods_color != "") {
                gg = item.goods_spec + item.goods_color;
              } else {
                gg = "规格1";
              }
              t.data.data.gg = gg;
              var uu = [];
              uu.push(t.data.data);

              ee.setData({
                sku_g: uu,
              });
            }
            ee.data.g_buy_num = new Map();

            //-- 增加相同的活动 --
            ee.check_prom(gid, ee.data.data.prom_type, ee.data.data.prom_id);
          } else {
            wx.showModal({
              title: t.data.msg,
              showCancel: !1,
            });
          }
        }
      });
    },
    //----------装载同一条形码的商品---------- 
    async get_sku(stoid, gd, g_id, is_normal, func) {
      console.log('get_sku');
      var tt = this,
        arrdata = null;
      var now = ut.gettimestamp();
      await getApp().request.promiseGet("/api/weshop/goods/page", {
        data: {
          store_id: o.stoid,
          sku: gd.sku,
          more_spec: gd.more_spec,
          isonsale: 1,
          is_on_sale: 1,
          pageSize: 500,
          orderField: 'gg_ordid,goods_spec,sort',
          isnewwhere: 1,
          js_pickup_id: 0
        }
      }).then(res => {
        var e = res;
        if (e.data.code == 0) arrdata = e.data.data.pageData;
      })
      if (!arrdata) return false;

      // if(arrdata[0]){
      //   tt.setData({
      //     new_share_imgurl:arrdata[0].share_imgurl
      //   })
      // }

      var arrsku = new Array();
      var gitem = null;
      var gb = 1,
        gg = "";
      for (var i = 0; i < arrdata.length; i++) {
        var goodsinfo = arrdata[i],
          prom = null;

        if (goodsinfo.goods_id != g_id) {


          //要判断一下商品的活动是不是多活动,确定一下商品的prom_type
          var url = '/api/weshop/activitylist/listGoodActInfo2New';
          var req_d = {
            "store_id": os.stoid,
            "goods_id": goodsinfo.goods_id,
            "user_id": getApp().globalData.user_id,
          }
          var ck_res = await getApp().request.promiseGet("/api/weshop/activitylist/listGoodActInfo2New", { data: req_d });
          if (ck_res.data.code == 0 && ck_res.data.data && ck_res.data.data.length > 0) {
            var arr = ck_res.data.data;
            //-- 预热也要计算 --
            var arr2 = arr.filter(function (e) {
              return e.s_time < ut.gettimestamp() || (e.warm_uptime && e.warm_uptime < ut.gettimestamp())
            })

            if (arr2.length == 1) {
              goodsinfo.prom_type = arr2[0].prom_type;
              goodsinfo.prom_id = arr2[0].act_id;
            }
          }

          switch (goodsinfo.prom_type) {
            case 1:

              if (goodsinfo.prom_id) {
                await getApp().request.promiseGet("/api/ms/flash_sale/get/" + os.stoid + "/" + goodsinfo.prom_id, {}).then(res => {
                  if (res.data.code == 0) prom = res.data.data;
                })
              }


              break;
            case 6:
              await getApp().request.promiseGet("/api/weshop/teamlist/get/" + os.stoid + "/" + goodsinfo.prom_id, {}).then(res => {
                console.log(res);
                if (res.data.code == 0) prom = res.data.data;
              })

              break;
            case 2:
              await getApp().request.promiseGet("/api/weshop/goods/groupBuy/getActInfo/" + os.stoid + "/" + goodsinfo.goods_id + "/" + goodsinfo.prom_id, {}).then(res => {
                if (res.data.code == 0) prom = res.data.data;
              })
              break;
            case 4:
              await getApp().request.promiseGet("/api/weshop/integralbuy/getActInfo/" + os.stoid + "/" + goodsinfo.goods_id + "/" + goodsinfo.prom_id, {}).then(res => {
                if (res.data.code == 0) prom = res.data.data;
              })
              break
            //预售和幸运购不参与
            case 8:
            case 9:
              continue;
          }

        } else {

          //只有是普通商品的时候,才要给商品赋值指定门店
          if ([1, 2, 4, 6, 8, 9].indexOf(parseInt(this.data.prom_type)) < 0 || is_normal) {
            //如果商品有设置分组
            if (goodsinfo.pick_group_ids) {
              goodsinfo.pickup_ids = goodsinfo.pick_up_lists;
            }
          }

        }
        //---如果有活动,不算在一起---
        if (prom) {
          if ([1, 2, 4, 6].indexOf(parseInt(goodsinfo.prom_type)) > -1) {
            console.log(prom);
            if (prom.is_end == 0 && prom.end_time > now && (prom.start_time < now || (prom.show_time && prom.show_time < now))) continue;
          } else {
            continue;
          }
        }
        var item = arrdata[i], gg = "";

        if (goodsinfo.goods_id != g_id) {
          //-- 如果商品有设置分组 --
          if (item.pick_group_ids) {
            item.pickup_ids = item.pick_up_lists;
          }
        }


        if (item.goods_spec == "null" || item.goods_spec == null) item.goods_spec = "";
        if (item.goods_color == "null" || item.goods_color == null) item.goods_color = "";

        if (item.goods_spec != "" && item.goods_color != "") {
          gg = item.goods_spec + "/" + item.goods_color;
        } else if (item.goods_spec != "" || item.goods_color != "") {
          gg = item.goods_spec + item.goods_color;
        } else {
          gg = "规格" + gb;
          gb++;
        }
        item.gg = gg;

        if (item.spec_img)
          item.original_img = os.imghost + item.spec_img;
        else
          item.original_img = os.imghost + item.original_img;


        if (item.goods_id == g_id) {
          gitem = item;
        } else {
          arrsku.push(item);
        }
      }

      //-----------排列在最前面-------------
      arrsku.splice(0, 0, gitem);

      if (is_normal == 1) {
        tt.setData({
          sku_g_pt: arrsku,
          sele_g: gitem
        });
        func();
      } else {
        tt.setData({
          sku_g: arrsku,
          sele_g: gitem
        });
      }
    },

    //-- 判断是否有秒杀 --
    check_has_flash: function (gid) {
      var th = this;
      var url = "/api/weshop/activitylist/getGoodActInfo";
      var user_id = getApp().globalData.user_id;
      if (!user_id) user_id = 0;

      if (!gid) gid = this.data.data.goods_id

      var req_data = {
        store_id: os.stoid,
        goodsidlist: gid,
        is_detail: 1,
        user_id: user_id,
        timetype: 0
      };
      //获取秒杀的多规格
      getApp().request.promiseGet(url, {
        data: req_data
      }).then(async function (res) {
        if (res.data.code == 0 && res.data.data && res.data.data.length) {
          var arr_data = res.data.data;
          var new_arr = [];
          for (let i in arr_data) {
            let item = arr_data[i];
            //找不到活动要剔除
            if (!item.act_name) continue;

            if ([1, 2, 4, 6, 8, 9].indexOf(item.prom_type) == -1) continue;
            new_arr.push(item);
          }

          // if (new_arr.length == 1) {
          //   th.data.prom_id = new_arr[0].act_id;
          //   th.data.prom_type = new_arr[0].prom_type;
          // }

          th.setData({
            more_flash: new_arr
          });
        }
      })
    },


    //--------检查是否活动,活动是否开始,或者是否结束-------
    async check_prom(gid, prom_type, prom_id) {

      console.log('check_prom');
      var ee = this,
        th = ee;
      var user_id = getApp().globalData.user_id;
      if (!user_id) user_id = 0;

      if (prom_type == 3 || prom_type == 0 || prom_type == 5 || prom_type == 7 || prom_type == 9 || prom_type == 10) {
        this.setData({
          prom_type: 0,
          isshow: 1,
        });
        return false;
      }

      if (prom_type == 2) {
        //-------判断团购活动是否抢光---------
        await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/" + prom_type + "/" + prom_id, {
          1: 1
        }).then(res => {
          var em = res;
          if (em.data.code == 0) {
            if (em.data.data <= 0) ee.setData({
              prom_r_null: 1
            });
            //拿取价格并且判断时间--
            getApp().request.get("/api/weshop/goods/groupBuy/getActInfo/" + os.stoid + "/" + gid + "/" + prom_id, {
              success: function (t) {
                if (t.data.code != 0) {
                  ee.get_normal(gid);
                  return false;
                }
                //----已经结束-----
                if (t.data.data.is_end == 1) {
                  ee.get_normal(gid);
                  return false;
                }
                //----已经过期-----
                var now = ut.gettimestamp();
                if (t.data.data.end_time < now || t.data.data.start_time > now) {
                  ee.get_normal(gid);
                  return false;
                }

                /*-- 还没有开始预热的也不显示 --*/
                if (t.data.data.show_time > now) {
                  ee.get_normal(gid);
                  return false;
                }

                var t_gd = ee.data.data;
                var prom_end_time = ut.formatTime(t.data.data.end_time, "yyyy-MM-dd hh:mm:ss");
                var prom_start_time = ut.formatTime(t.data.data.start_time, "yyyy-MM-dd hh:mm:ss");

                ee.setData({
                  prom_price: t.data.data.price,
                  prom_type: 2,
                  prom_id: prom_id,
                  prom_buy_limit: t.data.data.buy_limit,
                  prom_act: t.data.data,
                  prom_end_time: prom_end_time,
                  prom_start_time: prom_start_time,
                  isshow: 1,
                });

                ee.get_sto();
                var newTime = ut.gettimestamp();
                var endTime2 = t.data.data.end_time;
                var endTime1 = t.data.data.start_time;
                if (endTime1 > newTime) {
                  ee.setData({
                    prom_time_text: '距团购开始还有'
                  })
                  // ee.countDown(endTime1, 0);
                } else {
                  if (endTime2 > newTime) {
                    ee.setData({
                      prom_time_text: '距团购结束还有',
                      prom_st: 1
                    })
                    // ee.countDown(endTime2);
                  }
                }

              }
            });
          }
        })
      }

      if (prom_type == 1 && prom_id == 0) {
        this.setData({
          prom_type: 0,
          isshow: 1,
        });

        //获取门店
        this.get_sto();
        this.get_sku(o.stoid, this.data.data, gid);
        this.check_has_flash();
        this.data.is_normal = 1;
        if (!this.data.data.whsle_id) this.check_is_youhui(gid, 1);
        return false;
      }

      //if (prom_type != 3 && prom_type!=0){
      //---判断秒杀----
      if (prom_type == 1 && prom_id > 0) {
        //-------判断活动是否抢光---------
        await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/" + prom_type + "/" + prom_id, {
          1: 1
        }).then(res => {
          var em = res;
          if (em.data.code == 0) {

            if (em.data.data <= 0) ee.setData({
              prom_r_null: 1, pro_null: 1
            });
            //拿取价格并且判断时间--
            getApp().request.get("/api/ms/flash_sale/getNew/" + os.stoid + "/" + user_id + "/" + prom_id, {
              success: function (t) {
                if (t.data.code != 0) {
                  ee.get_normal(gid);
                  return false;
                }
                ee.setData({
                  is_share_text: t.data.data.is_share_text
                })
                //----已经结束-----
                if (t.data.data.is_end == 1) {
                  ee.get_normal(gid);
                  return false;
                }
                //----已经过期-----
                var now = ut.gettimestamp();
                if (t.data.data.end_time < now) {
                  ee.get_normal(gid);
                  return false;
                }
                /*-- 还没有开始预热的也不显示 --*/
                if (t.data.data.show_time > now) {
                  ee.get_normal(gid);
                  return false;
                }

                var t_gd = ee.data.data;
                var prom_end_time = ut.formatTime(t.data.data.end_time, "yyyy-MM-dd hh:mm:ss");
                var prom_start_time = ut.formatTime(t.data.data.start_time, "yyyy-MM-dd hh:mm:ss");

                ee.setData({
                  prom_price: t.data.data.user_price,
                  prom_type: 1,
                  prom_id: prom_id,
                  prom_buy_limit: t.data.data.buy_limit,
                  prom_act: t.data.data,
                  prom_end_time: prom_end_time,
                  prom_start_time: prom_start_time,
                  isshow: 1,
                });

                ee.get_sto();
                var newTime = ut.gettimestamp();
                var endTime2 = t.data.data.end_time;
                var endTime1 = t.data.data.start_time;
                if (endTime1 > newTime) {
                  ee.setData({
                    prom_time_text: '距秒杀开始还有'
                  })
                  // ee.countDown(endTime1, 0);
                } else {
                  if (endTime2 > newTime) {
                    ee.setData({
                      prom_time_text: '距秒杀结束还有',
                      prom_st: 1
                    })
                    // ee.countDown(endTime2);
                  }
                }

                //如果是进行中的话
                if (endTime1 < newTime) {
                  //-- 获取秒杀活动的多少规格 --
                  ee.get_more_flahs(function (list) {
                    if (list && list.length > 1) {

                      var n_item = list[0];
                      var ind = list.findIndex(function (ele) {
                        return ele.goods_id == ee.data.data.goods_id;
                      })
                      if (ind < 0) return false;
                      if (ind > 0) {
                        n_item = JSON.parse(JSON.stringify(list[ind]));
                        list.splice(ind, 1);
                        list.unshift(n_item);
                      }

                      ee.data.sele_g.viplimited = n_item.viplimited;
                      ee.data.data.viplimited = n_item.viplimited;

                      ee.data.sele_g.prom_type = 1;
                      ee.data.sele_g.prom_id = n_item.act_id;

                      var gb = 1;
                      //-- 显示多规格 --
                      for (let i in list) {
                        let item = list[i];
                        var gg = "";
                        if (item.goods_spec == "null" || item.goods_spec == null) item.goods_spec = "";
                        if (item.goods_color == "null" || item.goods_color == null) item.goods_color = "";

                        if (item.goods_spec != "" && item.goods_color != "") {
                          gg = item.goods_spec + "/" + item.goods_color;
                        } else if (item.goods_spec != "" || item.goods_color != "") {
                          gg = item.goods_spec + item.goods_color;
                        } else {
                          gg = "规格" + gb;
                          gb++;
                        }
                        item.gg = gg;
                        item.prom_id = item.prom_id;
                        item.prom_type = 1;
                      }

                      ee.setData({
                        sku_g: list,
                        is_more_flash: 1
                      });

                    }
                  })
                }

              }
            });
          }
        })
      }

      if (prom_type == 4) {
        //th.setData({is_integral_normal:1});
        var rdata = {
          store_id: o.stoid,
          stype: 1,
          stypeup: 1,
          goods_id: gid,
          timetype: 2,
          user_id: getApp().globalData.user_id,
        }

        var integrals = 0;
        var get_datas = {
          user_id: getApp().globalData.user_id,
          store_id: o.stoid,
        };
        await getApp().request.promiseGet("/api/weshop/users/getAllPoints", {
          data: get_datas
        }).then(res => {
          if (res.data.code == 0) {
            integrals = res.data.data?.Integral ? res.data.data?.Integral : 0;
          }
        })

        //获取一下积分活动
        await getApp().request.promiseGet("/api/weshop/integralbuy/pageIntegralBuyGoodsList", {
          data: rdata
        }).then(res => {
          //调用接口有数据的时候
          if (res.data.code == 0 && res.data.data && res.data.data.pageData && res.data.data.pageData.length > 0) {
            var inte_data = res.data.data.pageData[0];
            var can_integral = (parseFloat(integrals) >= parseFloat(inte_data.integral));
            let times = new Date().getTime()
            inte_data.show_time_off = ""
            let atimes = inte_data.start_time * 1000

            if (atimes > times) {
              inte_data.show_time_off = ut.formatTime(inte_data.start_time)
            }

            ee.setData({
              prom_price: parseFloat(inte_data.addmoney),
              prom_integral: parseFloat(inte_data.integral),
              prom_type: 4,
              prom_id: inte_data.id,
              prom_buy_limit: inte_data.limitvipqty,
              prom_act: inte_data,
              isshow: 1,
              can_integral: can_integral,
              is_shopbuy: parseInt(inte_data.is_shopbuy ? inte_data.is_shopbuy : 0)
            });
            ee.get_sto();

          } else {
            ee.get_normal(gid);
            return false;
          }
        })

      }

      //---判断拼单----
      if (prom_type == 6) {

        th.setData({
          user_order_pt_state: 0
        });

        //-------判断活动是否抢光---------
        await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/" + prom_type + "/" + prom_id, {
          1: 1
        }).then(res => {
          var em = res;
          var flag = null;
          if (em.data.code == 0) {
            if (em.data.data <= 0) ee.setData({
              prom_r_null: 1
            });
            //-- 拿取价格并且判断时间,同时判断会员身份 --
            getApp().request.get("/api/weshop/teamlist/getUser/" + os.stoid + "/" + prom_id + "/" + getApp().globalData.user_id, {
              success: async function (t) {
                if (t.data.code != 0) {
                  ee.get_normal(gid);
                  return false;
                }
                //----已经结束-----
                if (t.data.data.is_end == 1) {
                  ee.get_normal(gid);
                  return false;
                }
                //----已经过期-----
                var now = ut.gettimestamp();
                if (t.data.data.end_time < now) {
                  ee.get_normal(gid);
                  return false;
                }

                /*-- 还没有开始预热的也不显示 --*/
                if (t.data.data.show_time > now) {
                  ee.get_normal(gid);
                  return false;
                }

                /*-- 判断拼单是否启用 --*/
                if (!t.data.data.is_show) {
                  console.log('没启用');
                  wx.setNavigationBarTitle({
                    title: '系统提示',
                  });
                  wx.showToast({
                    title: '此商品暂时没有拼单活动',
                    icon: 'none',
                    success() {
                      setTimeout(() => {
                        wx.navigateBack()
                      }, 2000)
                    }
                  });
                  return false
                }


                //-------查看自己是不是有买过该团的商品,并还为支付,或者在进行中-------
                await getApp().request.promiseGet("/api/weshop/order/page", {
                  data: {
                    pt_prom_id: prom_id,
                    user_id: oo.user_id,
                    store_id: os.stoid,
                    pageSize: 1,
                    page: 1
                  }
                }).then(e => {
                  if (e.data.code == 0 && e.data.data.pageData.length > 0) {
                    var odr = e.data.data.pageData[0];
                    th.data.buy_order = odr;
                    if (odr.pt_status == 0 && odr.order_status == 1) {
                      th.setData({
                        user_order_pt_state: 1
                      });
                    }
                    if (odr.pt_status == 1 && odr.order_status == 1) {
                      if (odr.is_zsorder == 4) {
                        getApp().request.promiseGet("/api/weshop/teamgroup/page/", {
                          data: {
                            store_id: os.stoid,
                            team_id: odr.pt_prom_id,
                            listno: odr.pt_listno
                          }
                        }).then(res => {
                          var now = ut.gettimestamp();
                          if (res.data.code == 0 && res.data.data && res.data.data.pageData && res.data.data.pageData.length > 0) {
                            var tgr = res.data.data.pageData[0];
                            //如果团的时间已经到了
                            if (now >= tgr.kt_end_time) {
                              th.update_jiti(tgr.id);
                            } else {
                              th.setData({
                                user_order_pt_state: 2
                              });
                            }
                          }
                        })

                      } else {
                        th.setData({
                          user_order_pt_state: 2
                        });
                      }
                    }

                    if (odr.pt_status == 2 && odr.is_zsorder == 4) {
                      th.setData({
                        user_order_pt_state: 3,
                      });
                      th.data.wk_order_id = odr.order_id;
                    }
                  }
                })

                //----------查看阶梯团------------
                if (t.data.data.ct_rylist != "null" && t.data.data.ct_rylist != "" && t.data.data.ct_rylist != null && t.data.data.ct_rylist != undefined) {
                  t.data.data.ct_rylist = JSON.parse(t.data.data.ct_rylist);
                  var max_num = 0;
                  t.data.data.ct_rylist.forEach(function (val, ind) {
                    if (parseInt(val.rynum) > max_num) max_num = parseInt(val.rynum);
                  })
                  t.data.data.max_ct_num = max_num;
                }

                var prom_end_time = ut.formatTime(t.data.data.end_time, "yyyy-MM-dd hh:mm:ss");
                var prom_start_time = ut.formatTime(t.data.data.start_time, "yyyy-MM-dd hh:mm:ss");
                ee.setData({
                  prom_price: t.data.data.price,
                  prom_type: 6,
                  prom_id: prom_id,
                  prom_buy_limit: t.data.data.buy_limit,
                  prom_act: t.data.data,
                  prom_end_time: prom_end_time,
                  prom_start_time: prom_start_time,
                  isshow: 1,
                });

                ee.get_sto();

                var newTime = now;
                var endTime2 = t.data.data.end_time;
                var endTime1 = t.data.data.start_time;

                if (endTime1 > newTime) {
                  ee.setData({
                    prom_time_text: '距拼单开始还剩:'
                  })
                  // ee.countDown(endTime1, 0);
                } else {
                  if (endTime2 > newTime) {
                    ee.setData({
                      prom_time_text: '距拼单结束还剩:',
                      prom_st: 1
                    })
                    // ee.countDown(endTime2);
                  }
                }
                //-------查看有多少人在开这个团-------
                // th.get_team_group(prom_id);
              }
            });
          }
        })
      }
    },


    //--------服务卡检查是否活动,活动是否开始,或者是否结束-------
    async ser_check_prom(gid, prom_type, prom_id) {
      var ee = this, th = ee;
      var user_id = getApp().globalData.user_id;
      if (!user_id) user_id = 0;

      if (prom_type == 1 && prom_id == 0) {
        this.setData({
          prom_type: 0
        });

        //获取门店
        this.get_sto();
        // this.get_sku(o.stoid, this.data.data, gid);
        this.check_has_flash();
        this.data.is_normal = 1;
        // this.check_is_youhui(gid, 1);
        return false;
      }

      //---判断秒杀----
      if (prom_type == 1 && prom_id > 0) {
        //-------判断活动是否抢光---------
        await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/" + prom_type + "/" + prom_id, {
          1: 1
        }).then(res => {
          var em = res;
          if (em.data.code == 0) {

            if (em.data.data <= 0) {
              th.setData({
                prom_r_null: 1,
                goodsInputNum: res.data.data,
              });

              // th.setData({goodsInputNum: redis_num})
            };
            //拿取价格并且判断时间--
            getApp().request.get("/api/ms/flash_sale/getNew/" + os.stoid + "/" + user_id + "/" + prom_id, {
              success: function (t) {
                let sele_g_new = t.data.data
                let sele_g = th.data.sele_g
                if (sele_g_new && sele_g_new.original_img && !sele_g.original_img) {
                  sele_g.original_img = sele_g_new.original_img
                }
                th.setData({
                  sele_g
                });

                if (t.data.code != 0) {
                  ee.get_normal(gid);
                  return false;
                }
                //----已经结束-----
                if (t.data.data.is_end == 1) {
                  ee.get_normal(gid);
                  return false;
                }
                //----已经过期-----
                var now = ut.gettimestamp();
                if (t.data.data.end_time < now) {
                  ee.get_normal(gid);
                  return false;
                }
                /*-- 还没有开始预热的也不显示 --*/
                if (t.data.data.show_time > now) {
                  ee.get_normal(gid);
                  return false;
                }

                var t_gd = ee.data.data;
                var prom_end_time = ut.formatTime(t.data.data.end_time, "yyyy-MM-dd hh:mm:ss");
                var prom_start_time = ut.formatTime(t.data.data.start_time, "yyyy-MM-dd hh:mm:ss");

                ee.setData({
                  prom_price: t.data.data.user_price,
                  prom_type: 1,
                  prom_id: prom_id,
                  prom_buy_limit: t.data.data.buy_limit,
                  prom_act: t.data.data,
                  prom_end_time: prom_end_time,
                  prom_start_time: prom_start_time,
                });

                ee.get_sto();
                var newTime = ut.gettimestamp();
                var endTime2 = t.data.data.end_time;
                var endTime1 = t.data.data.start_time;
                if (endTime1 > newTime) {
                  ee.setData({
                    prom_time_text: '距秒杀开始还有',
                    prom_st: 0,
                  })
                  // ee.countDown(endTime1, 0);
                } else {
                  if (endTime2 > newTime) {
                    ee.setData({
                      prom_time_text: '距秒杀结束还有',
                      prom_st: 1
                    })
                    // ee.countDown(endTime2);
                  }
                }

                //如果是进行中的话
                if (endTime1 < newTime) {
                  //-- 获取秒杀活动的多少规格 --
                  ee.get_more_flash(function (list) {
                    if (list && list.length > 1) {

                      var n_item = list[0];
                      var ind = list.findIndex(function (ele) {
                        return ele.goods_id == ee.data.data.goods_id;
                      })
                      if (ind < 0) return false;
                      if (ind > 0) {
                        n_item = JSON.parse(JSON.stringify(list[ind]));
                        list.splice(ind, 1);
                        list.unshift(n_item);
                      }

                      ee.data.sele_g.viplimited = n_item.viplimited;
                      ee.data.data.viplimited = n_item.viplimited;

                      var gb = 1;
                      //-- 显示多规格 --
                      for (let i in list) {
                        let item = list[i];
                        var gg = "";
                        if (item.goods_spec == "null" || item.goods_spec == null) item.goods_spec = "";
                        if (item.goods_color == "null" || item.goods_color == null) item.goods_color = "";

                        if (item.goods_spec != "" && item.goods_color != "") {
                          gg = item.goods_spec + "/" + item.goods_color;
                        } else if (item.goods_spec != "" || item.goods_color != "") {
                          gg = item.goods_spec + item.goods_color;
                        } else {
                          gg = "规格" + gb;
                          gb++;
                        }
                        item.gg = gg;
                        item.prom_id = item.prom_id;
                        item.prom_type = 1;
                      }

                      ee.setData({
                        sku_g: list,
                      });

                    }
                  })
                }

              }
            });
          }
        })
      }

    },
    //获取更多秒杀
    get_more_flash: async function (func) {

      var f_more = false;
      var user_id = getApp().globalData.user_id;
      if (!user_id) user_id = 0;

      var url = "/api/weshop/goods/listSkuFlash?store_id=" + os.stoid + "&goods_id=" + this.data.gid + "&user_id=" + user_id;
      //获取秒杀的多规格
      await getApp().request.promiseGet(url, {}).then(res => {
        if (res.data.code == 0 && res.data.data && res.data.data.length > 0) {
          f_more = res.data.data;
        }
      })
      if (!f_more) {
        func(false);
        return false;
      }
      //-- 秒杀的价格要更新 --
      for (let i in f_more) {

        let item = f_more[i];
        f_more[i].prom_id = item.act_id;
        f_more[i].prom_type = 1;
        if (item.goods_id == this.data.sele_g.goods_id) {
          continue;
        }
        var url = "/api/ms/flash_sale/getNew/" + os.stoid + "/" + user_id + "/" + item.act_id;
        await getApp().request.promiseGet(url, {}).then(rs => {
          if (rs.data.code == 0) {
            f_more[i].price = rs.data.data.user_price;

          }
        })
      }
      func(f_more);

    },
    //---------拿出门店分类和门店------------
    get_sto(e, func, item) {

      var th = this,
        that = this;
      var is_normal = e;

      if (e == 1) {
        th.setData({
          is_normal: 1
        })
      } else {
        th.setData({
          is_normal: 0
        })
      }

      timer_get = setInterval(function () {

        if (th.data.is_get_local_ok == 0) return false;
        if (!th.data.fir_def_store) return false;

        var dd = null,
          i = getApp().request;
        if (!th.data.sele_g) return false;

        var g_distr_type = th.data.sele_g.distr_type;
        if (g_distr_type && g_distr_type != 0) {
          dd = {
            store_id: o.stoid,
            distr_type: g_distr_type,
            isstop: 0,
            is_pos: 1,
            pageSize: 2000
          }
        } else {
          dd = {
            store_id: o.stoid,
            isstop: 0,
            is_pos: 1,
            pageSize: 2000
          }
        }
        //如果有距离的话
        if (th.data.lat != null) {
          dd.lat = th.data.lat;
          dd.lon = th.data.lon;
        }

        clearInterval(timer_get);

        //如果会员是有默认的门店话
        if (!th.data.def_pick_store && th.data.fir_def_store && Object.keys(th.data.fir_def_store).length > 0) {
          th.setData({
            def_pick_store: th.data.fir_def_store
          });
        }
        wx.showLoading({
          title: '加载中.',
          mask: true
        });
        //----------获取门店----------------
        getApp().request.promiseGet("/api/weshop/pickup/list", {
          data: dd,
        }).then(res => {
          var e = res;

          if (e.data.code == 0 && e.data.data && e.data.data.pageData && e.data.data.pageData.length > 0) {

            var pickup_ids = th.data.sele_g.pickup_ids;
            //不是单独购买的时候,要清空商品pickup_ids

            var py = parseFloat(th.data.prom_type + '');
            if (!is_normal && py > 0 && [3, 5, 7, 10].indexOf(py) < 0) {
              pickup_ids = null;
            }
            //-- 把秒杀的指定对象带入 --
            if (item) {
              if (item.is_pickup && item.pick_up_lists) {
                pickup_ids = item.pick_up_lists
              } else {
                pickup_ids = null;
              }

            } else if (!is_normal && [1, 2, 6].indexOf(py) > -1 && th.data.prom_act.pick_up_lists) { //指定门店判断, 不是普通购买的时候,秒杀的时候,秒杀有指定门店
              pickup_ids = th.data.prom_act.pick_up_lists
            }

            //-- 如果有指定门店的时候 --
            if (pickup_ids) {

              var ok_arr = [];
              for (let i in e.data.data.pageData) {
                let ite = e.data.data.pageData[i];
                //-- 查找一下门店有没有在 --
                var idx = pickup_ids.findIndex(function (e) {
                  return e.pickup_id == ite.pickup_id;
                })
                if (idx > -1) {
                  ok_arr.push(ite)
                }
              }

              //判断会员的默认的门店是不是匹配指定的门店
              if (th.data.def_pick_store && JSON.stringify(th.data.def_pick_store) != '{}') {
                //-- 查找一下门店有没有在 --
                var idx1 = pickup_ids.findIndex(function (e) {
                  return e.pickup_id == th.data.def_pick_store.pickup_id;
                })

                if (idx1 < 0) {
                  //如果是秒杀的指定门店,就要设置秒杀的
                  if (!is_normal && [1, 2, 6].indexOf(py) > -1) {
                    th.data.def_pick_store.is_no_dis_act = 1;
                  } else {
                    th.data.def_pick_store.is_no_dis_nor = 1;
                  }
                } else {
                  th.data.def_pick_store.is_no_dis_nor = 0;
                  th.data.def_pick_store.is_no_dis_act = 0;
                }

                that.setData({
                  def_pick_store: th.data.def_pick_store
                })

              }
              e.data.data.pageData = ok_arr;     //数组重新赋值
              e.data.data.total = ok_arr.length; //数组的长度
            }
            else {
              //-- 多规格指定门店优化 --
              if (th.data.def_pick_store && JSON.stringify(th.data.def_pick_store) != '{}') {

                th.data.def_pick_store.is_no_dis_nor = 0;
                th.data.def_pick_store.is_no_dis_act = 0;
                that.setData({
                  def_pick_store: th.data.def_pick_store
                })
              }
            }

            //过滤后门店数量还是要大于0
            if (e.data.data.pageData.length > 0) {

              var his_cate_num = 0;
              for (let i in e.data.data.pageData) {
                let item = e.data.data.pageData[i];
                if (item.category_id > 0) {
                  his_cate_num = 1;
                }
                if (getApp().is_virtual(th.data.sele_g) && th.data.sales_rules >= 2) {
                  e.data.data.pageData[i].CanOutQty = 100000;
                }
              }

              e.his_cate_num = his_cate_num;

              if (th.data.def_pick_store && JSON.stringify(th.data.def_pick_store) != '{}' &&
                getApp().is_virtual(th.data.sele_g) && th.data.sales_rules >= 2) {
                th.setData({
                  'def_pick_store.CanOutQty': 100000
                })
              }

              //如果有开启距离的功能,没有设置默认门店,要用最近的门店作为默认门店
              if (dd.lat && (!th.data.def_pick_store || JSON.stringify(th.data.def_pick_store) == '{}') && th.data.bconfig && th.data.bconfig.is_sort_storage) {
                th.setData({
                  def_pick_store: e.data.data.pageData[0],
                  sto_sele_name: e.data.data.pageData[0].pickup_name,
                  sto_sele_id: e.data.data.pageData[0].pickup_id,
                  sto_sele_distr: e.data.data.pageData[0].distr_type
                });
                th.data.fir_def_store = e.data.data.pageData[0];
              }

              //-- 如果有默认选择门店的时候,要把默认门店放在第一位,修改不要配送方式的判断 --
              if (th.data.def_pick_store && JSON.stringify(th.data.def_pick_store) != '{}') {
                for (var k = 0; k < e.data.data.pageData.length; k++) {
                  if (e.data.data.pageData[k].pickup_id == th.data.def_pick_store.pickup_id) {
                    e.data.data.pageData.splice(k, 1); //删除
                    break;
                  }
                }
                e.data.data.pageData.splice(0, 0, th.data.def_pick_store); //添加
              }


              th.setData({
                all_pick_list: e.data.data.pageData
              });

              //--获取线下库存,而且不是新的门店规则, 同时是普通购买的时候,或者同时不能是活动,秒杀,拼团,积分购--
              if (!getApp().is_virtual(th.data.sele_g) && th.data.sales_rules >= 2 && !th.data.is_newsales_rules
                && !th.data.sele_g.whsle_id && ([1, 2, 4, 6, 8, 9].indexOf(th.data.prom_type) == -1 || is_normal == 1)) {
                setTimeout(function () {
                  th.deal_pickup_dline(e);
                }, 800)
              } else {
                setTimeout(function () {
                  th.deal_pickup(e); //--普通门店排版--
                }, 800)
              }
              if (func) func();
            } else {

              if (func) func();
              th.setData({ sp_seleing: 0 })
              wx.hideLoading();
            }
          } else {
            if (func) func();
            th.setData({ sp_seleing: 0 })
            wx.hideLoading();
          }
        }, err => {
          ut.m_toast('网络繁忙,请稍后重试');
          if (func) func();
          th.setData({ sp_seleing: 0 })
          wx.hideLoading();
        })
      }, 200)

    },

    //------------处理门店---------------
    deal_pickup(e) {

      var th = this;
      if (!th.data.sele_g) {
        wx.hideLoading();
        return false
      }

      var g_distr_type = th.data.sele_g.distr_type;
      wx.hideLoading()


      /*--- 判断初始的用户的默认门店要不要弄进去 ---*/
      var fid = -1;
      if (th.data.fir_def_store) {
        var fid = e.data.data.pageData.findIndex((e) => {
          return e.pickup_id == th.data.fir_def_store.pickup_id;
        })
      }
      //--如果找到默认门店,同时也应该判断配送方式对不对--
      if (th.data.fir_def_store && th.data.fir_def_store.pickup_id && fid < 0 &&
        (g_distr_type == 0 || th.data.fir_def_store.distr_type == 0 || th.data.def_pick_store.distr_type == g_distr_type)) {
        th.data.fir_def_store.CanOutQty = 0;
        //--当选择的门店是客户默认的门店的时候--
        if (th.data.def_pick_store && th.data.fir_def_store.pickup_id == th.data.def_pick_store.pickup_id) {
          th.setData({
            def_pick_store: th.data.fir_def_store
          });
          e.data.data.pageData.unshift(th.data.def_pick_store);
        } else {
          e.data.data.pageData.splice(1, 0, th.data.fir_def_store);
        }
      }



      //单总量超出10个的时候,同时门店有分类
      if (e.data.data.total > 10 && e.his_cate_num) {
        getApp().request.get("/api/weshop/storagecategory/page", {
          data: {
            store_id: o.stoid,
            pageSize: 1000,
            orderField: "sort",
            orderType: 'asc',
          },
          success: function (ee) {
            if (ee.data.code == 0) {
              var check_all_cate = 0;
              if (ee.data.data && ee.data.data.pageData && ee.data.data.pageData.length > 0) {
                for (let i in ee.data.data.pageData) {
                  let item = ee.data.data.pageData[i];
                  if (item.is_show == 1) {
                    check_all_cate = 1;
                    break
                  }
                }
              }
              if (check_all_cate) {
                var sto_cate = ee.data.data.pageData;
                var sto_arr = e.data.data.pageData;
                var newarr = new Array();
                var qita = new Array();

                var is_del_pk = 0;
                //----要进行门店分组--------
                for (var i = 0; i < sto_arr.length; i++) {
                  //找一下这个门店有没有在分类数组内
                  var find2 = 0,
                    find2name = "",
                    sort = 0;
                  is_del_pk = 0;
                  for (var m = 0; m < sto_cate.length; m++) {
                    if (sto_arr[i].category_id == sto_cate[m].cat_id) {
                      if (sto_cate[m].is_show != 1) {
                        is_del_pk = 1;
                        sto_arr.splice(i, 1);
                        i--;
                      } else {
                        find2 = sto_cate[m].cat_id;
                        find2name = sto_cate[m].cat_name;
                        sort = sto_cate[m].sort;
                        is_del_pk = 0;
                      }
                      break;
                    }
                  }
                  if (is_del_pk) continue;

                  if (newarr.length > 0) {
                    var find = 0;
                    //如果有找到,那门店就在这个分组内,否则,分类就要排在其他
                    if (find2 != 0) {
                      for (var ii = 0; ii < newarr.length; ii++) {
                        if (sto_arr[i].category_id == newarr[ii].cat_id) {
                          newarr[ii].s_arr.push(sto_arr[i]);
                          find = 1;
                          break;
                        }
                      }
                      if (find == 0) {
                        var arr0 = new Array();
                        arr0.push(sto_arr[i]);
                        var item = {
                          cat_id: find2,
                          name: find2name,
                          sort: sort,
                          s_arr: arr0
                        };
                        newarr.push(item);
                      }
                    } else {
                      qita.push(sto_arr[i]);
                    }
                  } else {
                    //如果有找到,那门店就在这个分组内,否则,分类就要排在其他
                    if (find2 != 0) {
                      var arr0 = new Array();
                      arr0.push(sto_arr[i]);
                      var item = {
                        cat_id: find2,
                        name: find2name,
                        sort: sort,
                        s_arr: arr0
                      };
                      newarr.push(item);
                    } else {
                      qita.push(sto_arr[i]);
                    }
                  }
                }

                var def_arr = new Array();
                //-- 开始就看10个门店 --
                for (var k = 0; k < 10; k++) {
                  if (k == sto_arr.length) break;
                  def_arr.push(sto_arr[k]);
                }

                th.setData({
                  def_pickpu_list: def_arr,
                  pickpu_list: ee.data.data.pageData
                });


                //门店分类要排序下
                function compare(property) {
                  return function (a, b) {
                    var value1 = a[property];
                    var value2 = b[property];
                    return value1 - value2;
                  }
                }

                if (newarr.length > 0)
                  newarr.sort(compare("sort"));


                //----安排其他的分类-----
                if (qita.length > 0) {
                  var item = {
                    cat_id: -1,
                    name: "其他",
                    s_arr: qita
                  };
                  newarr.push(item);
                }

                var sd = {
                  all_sto: newarr,
                  is_show_sto_cat: 1
                }
                if (!sto_arr || sto_arr.length <= 10) {
                  sd.is_show_sto_cat = -1;
                  sd.only_pk = sto_arr;
                }
                th.setData(sd);

              } else {
                th.setData({
                  is_show_sto_cat: -1,
                  only_pk: e.data.data.pageData
                });
                //-----如果没有默认门店,要取第一个门店作为默认店.此时没有门店分类的情况------
                if (!th.data.def_pick_store) {
                  th.setData({
                    def_pick_store: e.data.data.pageData[0],
                    sto_sele_name: e.data.data.pageData[0].pickup_name,
                    sto_sele_id: e.data.data.pageData[0].pickup_id,
                    sto_sele_distr: e.data.data.pageData[0].distr_type
                  })
                }
              }
            } else {
              th.setData({
                is_show_sto_cat: -1,
                only_pk: e.data.data.pageData
              });
              //-----如果没有默认门店,要取第一个门店作为默认店.此时没有门店分类的情况------
              if (!th.data.def_pick_store) {
                th.setData({
                  def_pick_store: e.data.data.pageData[0],
                  sto_sele_name: e.data.data.pageData[0].pickup_name,
                  sto_sele_id: e.data.data.pageData[0].pickup_id,
                  sto_sele_distr: e.data.data.pageData[0].distr_type
                })
              }

            }
          }
        });
      } else {

        th.setData({
          is_show_sto_cat: 0,
          only_pk: e.data.data.pageData
        });
        //-----如果没有默认门店,要取第一个门店作为默认店------
        if (!th.data.def_pick_store && th.data.bconfig && th.data.bconfig.is_sort_storage) {
          th.setData({
            def_pick_store: e.data.data.pageData[0],
            sto_sele_name: e.data.data.pageData[0].pickup_name,
            sto_sele_id: e.data.data.pageData[0].pickup_id,
            sto_sele_distr: e.data.data.pageData[0].distr_type
          })
        }
      }
    },

    //------------处理线下门店库存--------
    deal_pickup_dline(e) {
      var pkno = [],
        th = this;
      if (!th.data.sele_g) {
        wx.hideLoading();
        return false;
      }

      if (this.data.def_pick_store) {
        pkno.push(this.data.def_pick_store.pickup_no);
      }
      for (var i in e.data.data.pageData) {
        var item = e.data.data.pageData[i];
        if (pkno.indexOf(item.pickup_no) < 0)
          pkno.push(item.pickup_no);
      }
      pkno.sort();
      var pkno_str = pkno.join(",");
      var o_plist = e.data.data.pageData;
      var new_list = [];
      var is_find_def_store = 0;


      var g_distr_type = th.data.sele_g.distr_type;
      var lock = [];

      var lock_rq = {
        store_id: os.stoid,
        wareId: th.data.sele_g.goods_id,
        pageSize: 1000
      };

      if (th.data.sales_rules == 3) {
        lock_rq.appoint_pick_keyid = th.data.appoint_pick_keyid;
      }

      //先读取门店的lock,采用链式写法,少用await
      getApp().request.promiseGet("/api/weshop/order/ware/lock/page", {
        data: lock_rq
      }).then(res => {
        if (res.data.code == 0 && res.data.data.total > 0) {
          lock = res.data.data.pageData
        }
        var sto_rq = {
          wareIds: encodeURIComponent(th.data.sele_g.erpwareid),
          storeId: os.stoid,
          pageSize: 2000
        }

        if (th.data.sales_rules == 3) {
          sto_rq.storageIds = th.data.appoint_pick_keyid;
        } else {
          sto_rq.storageNos = pkno_str;
        }


        //---通过接口获取门店的线下库存信息--
        return getApp().request.promiseGet("/api/weshop/goods/getWareStorages", {
          data: sto_rq
        })
      }).then(res => {

        wx.hideLoading();
        if (res.data.code == 0) {

          if (res.data.data.pageData && res.data.data.pageData.length > 0) {

            var def_pick_store = th.data.def_pick_store;
            var plist = res.data.data.pageData;

            if (th.data.sales_rules == 3) {
              var lock_num = 0;
              var Qty = 0;
              //-- 计算锁住的库存 --
              for (var i in lock) lock_num += lock[i].outQty;
              Qty = plist[0].CanOutQty - lock_num;

              if (Qty > 0) {
                for (var kk in o_plist) {
                  o_plist[kk].CanOutQty = Qty;
                  new_list.push(o_plist[kk]);
                }
                if (th.data.fir_def_store &&
                  (g_distr_type == 0 || th.data.fir_def_store.distr_type == 0 || (th.data.def_pick_store && th.data.def_pick_store.distr_type == g_distr_type))) {
                  th.data.fir_def_store.Qty = Qty;
                  if (def_pick_store && def_pick_store.pickup_id == th.data.fir_def_store.pickup_id)
                    th.setData({
                      def_pick_store: th.data.fir_def_store
                    })
                  is_find_def_store = 1;
                }

                if (def_pick_store) {
                  //-- 如果库存为0就要重新赋值 --
                  def_pick_store.CanOutQty = Qty;
                  th.setData({
                    def_pick_store
                  })
                }


              } else {
                th.setData({
                  all_sto: null,
                  only_pk: null,
                  def_pickpu_list: null
                });
                return false;
              }

            } else {


              //以原来的数组为外循环,保证距离的顺序
              for (var kk in o_plist) {
                for (var ii in plist) {
                  //线下的门店小心
                  var n_item = plist[ii];
                  if (n_item.StorageNo == o_plist[kk].pickup_no) {

                    //拿到锁库的数量
                    var lock_num = th.find_lock_num(o_plist[kk].pickup_id, lock);
                    //可出库数大于预出库库存的数量,可以判断为有库存
                    if (n_item.CanOutQty > lock_num) {
                      o_plist[kk].CanOutQty = n_item.CanOutQty - lock_num;
                      new_list.push(o_plist[kk]);

                      var ck_store = th.data.fir_def_store;
                      if (th.data.def_pick_store && JSON.stringify(th.data.def_pick_store) != '{}') {
                        ck_store = th.data.def_pick_store;
                      }


                      //--如果找到默认门店,同时也应该判断配送方式对不对--
                      if (th.data.fir_def_store && n_item.StorageNo == th.data.fir_def_store.pickup_no && (g_distr_type == 0 || th.data.fir_def_store.distr_type == 0 || th.data.def_pick_store.distr_type == g_distr_type)) {
                        th.data.fir_def_store.CanOutQty = n_item.CanOutQty - lock_num;
                        if (def_pick_store && def_pick_store.pickup_id == th.data.fir_def_store.pickup_id)
                          th.setData({
                            def_pick_store: th.data.fir_def_store
                          })
                        is_find_def_store = 1;
                      }

                      //-- 如果库存为0就要重新赋值 --
                      if (def_pick_store && n_item.StorageNo == def_pick_store.pickup_no) {
                        def_pick_store.CanOutQty = o_plist[kk].CanOutQty;
                        th.setData({ def_pick_store })
                      }

                    }
                    break;
                  }
                }
              }

            }



            //数据组装下
            var em = {};
            em.data = {};
            em.data.data = {};
            em.data.data.total = new_list.length;
            em.data.data.pageData = new_list;
            em.his_cate_num = e.his_cate_num;


            var fid = -1;
            if (th.data.fir_def_store) {
              var fid = em.data.data.pageData.findIndex((e) => {
                return e.pickup_id == th.data.fir_def_store.pickup_id;
              })
            }
            //--如果找到默认门店,同时也应该判断配送方式对不对--
            if (th.data.fir_def_store && th.data.fir_def_store.pickup_id && fid < 0 &&
              (g_distr_type == 0 || th.data.fir_def_store.distr_type == 0 || th.data.def_pick_store.distr_type == g_distr_type)) {
              th.data.fir_def_store.CanOutQty = 0;
              //--当选择的门店是客户默认的门店的时候--
              if (th.data.def_pick_store && th.data.fir_def_store.pickup_id == th.data.def_pick_store.pickup_id) {
                th.setData({
                  def_pick_store: th.data.fir_def_store
                });
                em.data.data.pageData.unshift(th.data.def_pick_store);
              } else {
                em.data.data.pageData.splice(1, 0, th.data.fir_def_store);
              }
            }

            for (let j = 0; j < em.data.data.pageData.length; j++) {
              var iu = em.data.data.pageData[j];
              if (iu.CanOutQty <= 0) iu.is_no_qyt = 1;

            }

            //---把数组组装进去---
            th.deal_pickup(em);

          } else {

            th.setData({
              all_sto: null,
              only_pk: null,
              def_pickpu_list: null
            })
          }

        } else {

          th.setData({
            all_sto: null,
            only_pk: null,
            def_pickpu_list: null
          })
        }
      })
    },

    //------------加入购物车--------------
    addCart: function (t) {
      //如果是切换规格的时候,让商品不能提交到确认订单的页面,否则活动会出错,金额也不对
      if (this.data.sp_seleing) {
        return false;
      }

      var th = this;
      var ind = t.currentTarget.dataset.openSpecModal_ind;
      if (!ind) ind = t.currentTarget.dataset.openspecmodal_ind;
      th.setData({
        open_ind_store: ind
      });


      if ("add" == t.currentTarget.dataset.action && getApp().is_sp_hao()) {
        wx.showToast({
          title: "视频号商品不允许加入购物车",
          icon: 'none',
          duration: 2000
        });
        return false;
      }

      if (th.data.adding) return false;
      th.data.adding = 1;

      wx.showLoading({
        mask: true
      })



      //如果是秒杀的话,要看redis够不够
      if (this.data.prom_type == 1 || this.data.prom_type == 2) {

        if (this.data.openSpecModal_flash_normal) {
          this.data.is_normal = 1; //是普通购买
          th.add_cart_func(t);
          return false;
        }


        this.getactLen(function (num) {
          if (num < th.data.goodsInputNum) {
            wx.hideLoading();
            th.data.adding = 0;
            // getApp().my_warnning("活动库存不足!", 0, th);
            wx.showToast({
              title: '活动库存不足!',
              icon: 'none',
            });
            return false;
          } else {
            th.add_cart_func(t);
          }
        });
      } else {
        th.add_cart_func(t);
      }
    },

    //------------加入购物车--------------
    addCartSer: async function (t) {
      var th = this;
      var ind = t.currentTarget.dataset.openSpecModal_ind;
      var action = t.currentTarget.dataset.action;



      if (getApp().is_sp_hao() && action == 'add') {
        wx.showToast({
          title: "视频号商品不允许加入购物车",
          icon: 'none',
          duration: 2000
        });
        return false;
      }


      if (this.data.goodsInputNum == 0) {
        getApp().my_warnning('请输入购买数量', 1, th, 450);
        return false;
      }



      if (!ind) ind = t.currentTarget.dataset.openspecmodal_ind;

      th.setData({
        open_ind_store: ind
      });

      if (!th.data.sto_sele_name) {
        getApp().my_warnning('请选择门店', 1, th, 450);
        return false;
      };

      // 库存
      var redisNums = 0;
      // 限购数
      var limitNum = 0;
      // 已购买数量
      var boughtNum = 0;

      var is_ok = 1;

      // 秒杀活动
      if (this.data.prom_type == 1) {
        // 如果是秒杀活动下的单独购买,is_normal为1
        if (this.data.openSpecModal_flash_normal) this.data.is_normal = 1;

        if (!this.data.is_normal) {// 秒杀购买

          // 获取redis当前可以购买的数量
          // 如果数量为0,设置和显示已抢光
          // 否则,进一步判断是否超出限购或超出库存
          await this.getactLenser().then(async function (res) {
            redisNums = res;
            let curNum = th.data.goodsInputNum;
            // res: redis可购买数量
            console.log('当前可以购买的数量:', res);
            if (res <= 0) {
              // 可购买数量<=0, 设置和显示已抢光
              th.setData({
                prom_r_null: 1,
              });
              // wx.showModal({
              // 	title: '超出活动库存',
              // });
              getApp().my_warnning('超出活动库存', 0, self);
              is_ok = 0;
              return false;
            } else {
              // 可购买数量>0
              // 计算自己还可以购买的数量
              // 自己还可购买的数量c = 每人活动限购数量a - 自己已经购买的数量b
              // 如果限购数量a>redis可购买数量d,当增加数量t>d, 提示超出库存
              // 如果限购数量a<=redis可购买数量d, 当增加数量t>a,提示超出限购
              let actInfo = th.data.sele_g;
              await th.get_buy_num2().then(function (data) {
                let limited = actInfo.buy_limit == 0 ? 100000 : actInfo.buy_limit; // 限购数量a
                let promcardbuynum = data.data.data.promcardbuynum;
                let buyedNum = promcardbuynum; // 自己已经购买的数量b
                let canBuyNum = limited - buyedNum; // 自己还可购买的数量c
                limitNum = limited;
                boughtNum = buyedNum;

                if (canBuyNum <= 0) {
                  canBuyNum = 0;
                };

                if (canBuyNum > res) {
                  if (curNum > res) { // t当前增减的数量
                    // wx.showModal({
                    // 	title: '超出活动库存',
                    // });
                    getApp().my_warnning('超出活动库存', 0, self);
                    th.setData({
                      goodsInputNum: res || 1
                    });
                    is_ok = 0;
                    return false;
                  };
                };

                if (canBuyNum <= res) {
                  if (curNum > canBuyNum) {
                    // wx.showModal({
                    // 	title: '超出限购数量',
                    // });
                    getApp().my_warnning('超出限购数量', 0, self);
                    th.setData({
                      goodsInputNum: canBuyNum || 1,
                    });
                    is_ok = 0;
                    return false;
                  }
                }
              })

            }
          })

        }
      }


      if (!is_ok) return false;



      if (action == "buy") {
        //--------------此时操作的数据------------
        var newd = {
          id: th.data.data.id,
          goods_num: th.data.goodsInputNum,
          pick_id: th.data.sto_sele_id,
          keyid: th.data.sto_sele_keyid,
        };
        newd['pick_name'] = th.data.sto_sele_name;
        newd['guide_id'] = getApp().globalData.guide_id;
        newd['guide_type'] = 0;

        if (getApp().globalData.groupchat_id) {
          newd['groupchat_id'] = getApp().globalData.groupchat_id;
        }
        if (this.data.prom_type && this.data.prom_type == 1) {
          newd['prom_type'] = this.data.prom_type;
          newd['prom_id'] = this.data.prom_id;
          newd['prom_price'] = this.data.prom_price;
        };

        if (this.data.prom_type == 1 && this.data.openSpecModal_flash_normal) {
          newd['prom_type'] = 0;
          newd['prom_price'] = this.data.data.shop_price;
        };

        console.log('newd++++++++', newd);
        th.buyNow(newd);
      } else {

        var newd = {
          service_id: th.data.data.id,
          service_sn: th.data.data.service_sn,
          service_name: th.data.data.goods_name,
          goods_num: th.data.goodsInputNum,
          pick_id: th.data.sto_sele_id,
          user_id: oo.user_id,
          store_id: os.stoid,
          money: th.data.data.shop_price,
        };
        if (getApp().globalData.guide_id) {
          newd['guide_id'] = getApp().globalData.guide_id;
          newd['guide_type'] = 0;
        };
        if (getApp().globalData.groupchat_id) {
          newd['groupchat_id'] = getApp().globalData.groupchat_id;
        }
        // 秒杀:单独购买的情况下,加入购物车显示的是零售价,否则显示秒杀活动价
        if (th.data.prom_type == 1) {
          newd['prom_type'] = th.data.prom_type;
          newd['prom_id'] = th.data.prom_id;
          if (th.data.openSpecModal_flash_normal) {
            newd['money'] = th.data.data.shop_price;
            newd['is_pd_normal'] = 1;
          } else {
            newd['money'] = th.data.prom_price;
          };
        };


        //----先看会员在购物车中是否加入了该商品-----
        getApp().request.get("/api/weshop/cartService/page", {
          data: {
            store_id: os.stoid,
            user_id: oo.user_id,
            service_id: th.data.data.id,
          },
          success: function (re) {
            //-------如果购物车中有相关的数据---------
            if (re.data.data.total > 0) {
              var item = null;
              // 多门店问题
              var cartGoodsNum = 0;
              const tmpObj = re.data.data.pageData;
              for (let i = 0; i < tmpObj.length; i++) {
                if (th.data.sto_sele_id != tmpObj[i].pick_id) {
                  cartGoodsNum += parseInt(tmpObj[i].goods_num);
                } else {
                  item = tmpObj[i];
                }
              }
              // 当前门店同类商品还没加入到购物车 但是有其他门店的同类商品
              if (th.data.prom_type == 1 && !th.data.is_normal && !item) {

                // 秒杀购物车购买 修正数量
                var snum = limitNum - boughtNum;
                if (snum <= 0) {
                  // wx.showModal({
                  // 	title: '超出限购数量',
                  // });
                  getApp().my_warnning('超出限购数量', 0, self);
                  return false;
                }

                var cSnum = snum - cartGoodsNum <= 0 ? 0 : snum - cartGoodsNum;
                var cRedisNums = redisNums - cartGoodsNum <= 0 ? 0 : redisNums - cartGoodsNum;

                if (newd['goods_num'] >= redisNums) {
                  if (redisNums > snum) {
                    newd['goods_num'] = cSnum;
                  } else {
                    newd['goods_num'] = cRedisNums;
                  }
                } else {
                  if (newd['goods_num'] > snum) newd['goods_num'] = cSnum;
                }

                if (newd['goods_num'] <= 0) {
                  getApp().my_warnning('加入购物车成功', 1, th, 450);
                  th.closeSpecModal();
                  return false;
                }
                getApp().request.post("/api/weshop/cartService/save", {
                  data: newd,
                  success: function (t) {
                    getApp().my_warnning('加入购物车成功', 1, th, 450);
                    var c_num = th.data.cartGoodsNum + th.data.goodsInputNum;
                    th.setData({
                      cartGoodsNum: c_num
                    });
                    th.closeSpecModal();
                  }
                });
                return false;
              }

              // 以下为当前门店同类商品已经加入到购物车
              var totalNum = th.data.goodsInputNum + item.goods_num;

              // 秒杀购物车购买 修正数量
              if (th.data.prom_type == 1 && !th.data.is_normal) {
                var snum = limitNum - boughtNum;
                if (snum <= 0) {
                  // wx.showModal({
                  // 	title: '超出限购数量',
                  // });
                  getApp().my_warnning('超出限购数量', 0, self);
                  return false;
                }
                if (totalNum >= redisNums) {
                  if (redisNums > snum) {
                    totalNum = snum - cartGoodsNum;
                  } else {
                    totalNum = redisNums - cartGoodsNum;
                  }
                } else {
                  if (totalNum > snum)
                    totalNum = snum - cartGoodsNum;
                }
              }

              var updata = {
                id: item.id,
                goods_num: totalNum,
                money: th.data.data.shop_price,
                store_id: os.stoid,
              };

              // 秒杀:单独购买的情况下,加入购物车显示的是零售价,否则显示秒杀活动价
              if (th.data.prom_type == 1) {
                // updata['prom_type'] = th.data.options.prom_type;
                // updata['prom_id'] = th.data.options.prom_id;
                if (th.data.openSpecModal_flash_normal) {
                  updata['money'] = th.data.data.shop_price;
                  updata['is_pd_normal'] = 1;
                } else {
                  updata['money'] = th.data.prom_price;
                };
              };

              if (getApp().globalData.guide_id) {
                updata['guide_id'] = getApp().globalData.guide_id;
                updata['guide_type'] = 1;
              }
              if (getApp().globalData.groupchat_id) {
                updata['groupchat_id'] = getApp().globalData.groupchat_id;
              }
              getApp().request.put("/api/weshop/cartService/update", {
                data: updata,
                success: function (t) {
                  getApp().my_warnning('加入购物车成功', 1, th, 450);
                  var c_num = th.data.cartGoodsNum + th.data.goodsInputNum;
                  th.setData({
                    cartGoodsNum: c_num
                  });
                  th.closeSpecModal();
                }
              });
            } else {
              getApp().request.post("/api/weshop/cartService/save", {
                data: newd,
                success: function (t) {
                  getApp().my_warnning('加入购物车成功', 1, th, 450);
                  var c_num = th.data.cartGoodsNum + th.data.goodsInputNum;
                  th.setData({
                    cartGoodsNum: c_num
                  });
                  th.closeSpecModal();
                }
              });
            }
          }
        });

      };







    },
    get_buy_num2: async function () {
      // var map = this.data.g_buy_num,
      var th = this,
        user_id = getApp().globalData.user_id;
      // if (user_id == null) {
      //     // map.set(gd.goods_id, 0);
      //     th.setData({
      //         // g_buy_num: map,
      //         prom_buy_num: 0,
      //     });
      //     "function" == typeof func && func();
      //     return false;
      // }


      //----获取商品购买数----

      //----获取活动购买数----
      return await getApp().request.promiseGet("/api/weshop/rechargeServicelist/getUserBuyGoodsNum", {
        data: {
          store_id: os.stoid,
          user_id: user_id,
          card_id: th.data.gid,
          prom_type: th.data.prom_type,
          prom_id: th.data.prom_id
        },
        //-----获取-----
        success: function (tt) {
          if (tt.data.code == 0) {
            // map.set(gd.goods_id, g_buy_num);
            th.setData({
              // g_buy_num: map,
              promcardbuynum: tt.data.data.promcardbuynum,
              cardbuynum: tt.data.data.cardbuynum,
            });
          }
        }
      });


    },

    //-- 加入购物的函数 --
    add_cart_func: function (t) {
      var i = getApp().request;
      if (oo.user_id == null) {
        wx.hideLoading();
        th.data.adding = 0;
        return s.my_warnning("还未登录!", 0, this);
      }

      if (!getApp().globalData.userInfo) {
        wx.hideLoading();
        th.data.adding = 0;
        return s.my_warnning("还未登录!", 0, this);
      }

      var e = this,
        th = e,
        a = 0,
        o = this.data.sele_g;
      a = o.goods_id;

      //----------添加到购物车时,要判断限购数量,--------
      e.get_buy_num(o, function (ee) {
        //---判断商品是否超出限购---
        if (th.data.g_buy_num != null && th.data.sele_g.viplimited > 0) {
          if (th.data.goodsInputNum + th.data.g_buy_num.get(th.data.sele_g.goods_id) > th.data.sele_g.viplimited) {
            wx.hideLoading();
            th.data.adding = 0;
            wx.showToast({
              title: '超出商品限购',
              icon: 'none',
            });
            // s.my_warnning('超出商品限购', 0, th);
            return false;
          }
        }
        //---判断商品是否超出活动限购---
        if ((th.data.prom_buy_num != -1 && th.data.prom_buy_limit > 0) && !th.data.is_normal) {
          if (th.data.goodsInputNum + th.data.prom_buy_num > th.data.prom_buy_limit) {
            wx.hideLoading();
            th.data.adding = 0;
            wx.showToast({
              title: '超出商品活动限购',
              icon: 'none',
            });
            // s.my_warnning('超出商品活动限购', 0, th);
            return false;
          }
        }

        if (th.data.goodsInputNum <= 0) {
          wx.hideLoading();
          th.data.adding = 0;
          return s.my_warnning("商品数量不能为0", 0, th);
        }
        if (th.data.sto_sele_name == null || th.data.sto_sele_name == undefined)
          th.setData({
            sto_sele_name: ""
          });
        if (th.data.sto_sele_name == "") {
          wx.hideLoading();
          th.data.adding = 0;
          return s.my_warnning("请选择门店", 0, th);
        }

        //--------------此时操作的数据------------
        var newd = {
          goods_id: o.goods_id,
          goods_num: th.data.goodsInputNum,
          pick_id: th.data.sto_sele_id,
          user_id: oo.user_id,
          store_id: th.data.stoid,
          goods_price: o.shop_price,
          member_goods_price: o.shop_price,
          goods_name: o.goods_name,
          goods_sn: o.goods_sn,
          sku: o.sku,
          prom_id: th.data.sele_g.prom_id,
          prom_type: th.data.sele_g.prom_type,
        };

        //-- 代发商品不参加优惠 --
        if (th.data.sele_g.whsle_id) {
          newd.prom_type = 0;
          newd.prom_id = 0;
        }

        //---是不是从收藏夹出来的---
        if (th.data.c_guide_id) {
          newd['guide_id'] = th.data.c_guide_id;
          newd['guide_type'] = 2;
          if ("add" == t.currentTarget.dataset.action) newd['guide_type'] = 3;
        } else {
          if (getApp().globalData.guide_id) {
            newd['guide_id'] = getApp().globalData.guide_id;
            newd['guide_type'] = 0;
            if ("add" == t.currentTarget.dataset.action) newd['guide_type'] = 1;
          }
        }
        if (getApp().globalData.groupchat_id) {
          newd['groupchat_id'] = getApp().globalData.groupchat_id;
        }
        //让商品带上房间号
        //让商品带上房间号
        if (!th.data.sys_switch.is_skuroom_id && th.data.sys_switch.is_skuroom_id == 1) {
          if (th.data.data.goods_id == getApp().globalData.room_goods_id) {
            newd.room_id = getApp().globalData.room_id;
          }
        } else {
          if (newd.goods_id == getApp().globalData.room_goods_id) newd.room_id = getApp().globalData.room_id;
        }

        //如果是积分够,is_integral_normal就要有积分购普通购买字段
        if (th.data.openSpecModal_inte_normal == 1 && th.data.prom_type == 4) {
          newd.is_integral_normal = 1;
        }

        //如果有线下取价
        if (o.offline_price) {
          newd.offline_price = o.offline_price;
          newd.pricing_type = o.pricing_type;
        }


        //获取到优惠测序类型
        //-----如果是秒杀,团购,积分购,拼团-----
        if (th.data.prom_type == 1 || th.data.prom_type == 2) {

          if (th.data.openSpecModal_flash_normal) {

            newd.prom_type = 0;
            newd.prom_id = 0;
            newd.is_pd_normal = 1;
            //---如果是线下门店销售的时候---
            if (th.data.sales_rules >= 2) {
              var pick = th.get_pick_from_list(th.data.sto_sele_id)
              //---通过接口获取门店的线下库存信息--
              th.check_CanOutQty(th.data.sele_g, pick, function (CanOutQty) {
                if (CanOutQty) {
                  if (CanOutQty < e.data.goodsInputNum) {
                    wx.hideLoading();
                    th.data.adding = 0;
                    wx.showToast({
                      title: '库存不足!',
                      icon: 'none',
                    });
                    return false;
                  }

                  th.add_cart_next(e, t, a, o, newd, CanOutQty);
                } else {
                  wx.hideLoading();
                  th.data.adding = 0;
                  wx.showToast({
                    title: '库存不足!',
                    icon: 'none',
                  });
                  return false;
                }
              })


            } else {
              if (o.store_count <= 0) {
                wx.hideLoading();
                th.data.adding = 0;
                wx.showToast({
                  title: '库存已为空!',
                  icon: 'none'
                });
                return false;
              }
              if (o.store_count < e.data.goodsInputNum) {
                wx.hideLoading();
                th.data.adding = 0;
                wx.showToast({
                  title: '库存不足!',
                  icon: 'none',
                });
                return false;
                // return s.my_warnning("库存不足!", 0, th);
              }
              th.add_cart_next(e, t, a, o, newd); //加入购物车下一步
            };
            return false;
          }

          newd.goods_price = th.data.prom_price;
          newd.member_goods_price = th.data.prom_price,
            newd.prom_type = th.data.prom_type;
          newd.prom_id = th.data.prom_id;

          if (o.store_count <= 0) {
            wx.hideLoading();
            th.data.adding = 0;
            wx.showToast({
              title: '库存已为空!',
              icon: 'none',
            });
            return false;
          }
          if (o.store_count < e.data.goodsInputNum) {
            wx.hideLoading();
            th.data.adding = 0;
            wx.showToast({
              title: '库存不足!',
              icon: 'none',
            });
            return false;
          }
          th.add_cart_next(e, t, a, o, newd); //加入购物车下一步

        }
        // else if (o.prom_type == 7) {
        //
        //   //判断进行中的活动,是不是要判断线下库存
        //   th.check_zh_acting(function (ee) {
        //       newd.prom_id = 0;
        //       newd.prom_type = 0;
        //       if (ee && th.data.sele_g.act) {
        //         newd.prom_id = th.data.sele_g.act.id;
        //         newd.prom_type = 7;
        //         if (o.store_count <= 0) {
        //           wx.hideLoading();
        //           th.data.adding=0;
        //           wx.showToast({
        //             title: '库存已为空!',
        //             icon: 'none',
        //           });
        //           return false;
        //         };
        //         if (o.store_count < e.data.goodsInputNum) {
        //           wx.hideLoading();
        //           th.data.adding=0;
        //           wx.showToast({
        //             title: '库存不足!',
        //             icon: 'none',
        //           });
        //           return false;
        //           //return s.my_warnning("库存不足!", 0, th);
        //         };
        //         th.add_cart_next(e, t, a, o, newd); //加入购物车下一步
        //         return false;
        //       } else {
        //         //---如果是线下门店销售的时候---
        //         if (!th.data.sele_g.whsle_id && th.data.sales_rules >= 2) {
        //           var pick = th.get_pick_from_list(th.data.sto_sele_id)
        //
        //           th.check_CanOutQty(th.data.sele_g, pick, function (CanOutQty) {
        //             if (CanOutQty) {
        //
        //               if (CanOutQty < e.data.goodsInputNum) {
        //                 wx.hideLoading();
        //                 th.data.adding=0;
        //                 wx.showToast({
        //                   title: '库存不足!',
        //                   icon: 'none',
        //                 });
        //                 return false;
        //               }
        //
        //               th.add_cart_next(e, t, a, o, newd, CanOutQty);
        //             } else {
        //               wx.hideLoading();
        //               th.data.adding=0;
        //               wx.showToast({
        //                 title: '库存不足!',
        //                 icon: 'none',
        //               });
        //               return false;
        //             }
        //           })
        //
        //         } else {
        //           if (o.store_count <= 0) {
        //             wx.hideLoading();
        //             th.data.adding=0;
        //             wx.showToast({
        //               title: '库存已为空!',
        //               icon: 'none',
        //             });
        //             return false;
        //             //return s.my_warnning("库存已为空!", 0, th);
        //           };
        //           if (o.store_count < e.data.goodsInputNum) {
        //             wx.hideLoading();
        //             th.data.adding=0;
        //             wx.showToast({
        //               title: '库存不足!',
        //               icon: 'none',
        //             });
        //             return false;
        //             //return s.my_warnning("库存不足!", 0, th);
        //           };
        //           th.add_cart_next(e, t, a, o, newd); //加入购物车下一步
        //         }
        //       }
        //     })
        // }
        //要包含积分购的普通购买0 3,5,7,10,  is_integral_normal积分普通购买字段
        else if ([0, 3, 5, 7, 10].indexOf(th.data.prom_type) > -1 || newd.is_integral_normal) {
          newd.prom_type = 0;
          newd.prom_id = 0;

          //---如果是线下门店销售的时候---
          if (th.data.sales_rules >= 2 && !th.data.sele_g.whsle_id) {
            var pick = th.get_pick_from_list(th.data.sto_sele_id)
            //---通过接口获取门店的线下库存信息--
            th.check_CanOutQty(th.data.sele_g, pick, function (CanOutQty) {
              if (CanOutQty) {

                if (CanOutQty < e.data.goodsInputNum) {
                  wx.hideLoading();
                  th.data.adding = 0;
                  wx.showToast({
                    title: '库存不足!',
                    icon: 'none',
                  });
                  return false;
                }

                th.add_cart_next(e, t, a, o, newd, CanOutQty);
              } else {
                wx.hideLoading();
                wx.showToast({
                  title: '库存不足!',
                  icon: 'none',
                });
                return false;
              }
            })

          } else {
            if (o.store_count <= 0) {
              wx.hideLoading();
              wx.showToast({
                title: '库存已为空!',
                icon: 'none',
              });
              return false;
              //return s.my_warnning("库存已为空!", 0, th);
            };
            if (o.store_count < e.data.goodsInputNum) {
              wx.hideLoading();
              wx.showToast({
                title: '库存不足!',
                icon: 'none',
              });
              return false;
              //return s.my_warnning("库存不足!", 0, th);
            }
            th.add_cart_next(e, t, a, o, newd); //加入购物车下一步
          }
        }



      })
    },

    //---加入购物车的最后一步---
    add_cart_next(e, t, a, o, newd, CanOutQty) {


      if (getApp().globalData.groupchat_id) {
        newd.groupchat_id = getApp().globalData.groupchat_id
      }
      var th = this,
        i = getApp().request;
      //---如果商品不是积分购和拼团,要判断一个是否要进行等级价的判断------
      if ((o.prom_type != 6 && o.prom_type != 4 && o.prom_type != 2 && o.prom_type != 1) || th.data.is_normal) {
        var conf = th.data.bconfig;
        if (conf.switch_list && getApp().globalData.userInfo['card_field'] && getApp().globalData.userInfo['card_expiredate']) {
          var s_list = JSON.parse(conf.switch_list);
          var now = ut.gettimestamp();


          var str = getApp().globalData.userInfo['card_expiredate'].replace(/-/g, '/');
          var end = new Date(str);
          end = Date.parse(end) / 1000;


          //--如果后台有开启等级价的功能,而且会员的等级没有过期的情况下--
          if (parseInt(s_list.rank_switch) == 2 && end > now) {
            var card_price = o[getApp().globalData.userInfo['card_field']];
            //如果会员有等级价
            if (getApp().globalData.userInfo['card_field'] != undefined && getApp().globalData.userInfo['card_field'] != null &&
              getApp().globalData.userInfo['card_field'] != "" && card_price > 0) {
              newd.goods_price = card_price;
              newd.member_goods_price = card_price;
            }
          }
        }
      }

      //if (this.data.data.goods.is_virtual) return this.buyVirtualGoods(d);
      if ("add" == t.currentTarget.dataset.action) {

        if ([3, 5, 7, 10].indexOf(newd.prom_type) > -1) {
          newd.prom_type = 0;
          newd.prom_id = 0;
        }

        wxlog.info(getApp().globalData.user_id + '-加入购物车:' + JSON.stringify(newd));
        //
        // //如果有搭配购的时候的时候
        // if(th.data.collocationGoods  && newd.prom_type==0){
        //   newd.prom_type = 5;
        //   newd.prom_id = th.data.collocationGoods.id;
        // }
        //
        // //如果有搭配购的时候的时候
        // if(th.data.zh_act && (!th.data.zh_act.zh_num || th.data.zh_act.zh_buy_num>th.data.zh_act.zh_num )  && newd.prom_type==0){
        //   newd.prom_type = 7;
        //   newd.prom_id = th.data.zh_act.id;
        // }      

        //----先看会员在购物车中是否加入了该商品-----
        i.get("/api/weshop/cart/page", {
          data: {
            store_id: e.data.stoid,
            user_id: oo.user_id,
            goods_id: a,
            pick_id: e.data.sto_sele_id,
            prom_type: newd.prom_type,
            prom_id: newd.prom_id,
            state: 0,
          },
          success: function (re) {

            //-- 判断活动是不是一样 --
            var item = null;
            //-------如果购物车中有相关的数据---------
            if (re.data.data.total > 0) {
              for (var j = 0; j < re.data.data.pageData.length; j++) {
                if (!th.check_is_like(re.data.data.pageData[j], newd, 1)) continue;
                item = re.data.data.pageData[j];
                break;
              }

              if (!item) {
                for (var j = 0; j < re.data.data.pageData.length; j++) {
                  if (!th.check_is_like(re.data.data.pageData[j], newd)) continue;
                  item = re.data.data.pageData[j];
                  break;
                }
              }

            }

            if (item) {
              item = re.data.data.pageData[0];
              //判断数量,要看下购物车中有没有该商品
              if (CanOutQty) {
                if (item.goods_num + th.data.goodsInputNum > CanOutQty) {
                  wx.hideLoading();
                  th.data.adding = 0;
                  wx.showToast({
                    title: '库存不足!',
                    icon: 'none',
                  });
                  return false;
                  // return s.my_warnning("库存不足!", 0, th);
                }
              } else {
                if (item.goods_num + th.data.goodsInputNum > o.store_count) {
                  wx.hideLoading();
                  th.data.adding = 0;
                  wx.showToast({
                    title: '库存不足!',
                    icon: 'none',
                  });
                  return false;
                  //return s.my_warnning("库存不足!", 0, th);
                }

                //秒杀有限购的时候,同时不是普通购买
                if (item.goods_num + th.data.goodsInputNum + th.data.prom_buy_num > th.data.prom_buy_limit && th.data.prom_buy_limit > 0 && !newd.is_pd_normal && (th.data.prom_type == 1 || th.data.prom_type == 2)) {
                  wx.hideLoading();
                  th.data.adding = 0;
                  wx.showToast({
                    title: '此商品已在购物车,去购物车结算!',
                    icon: 'none',
                  });
                  return false;
                  //return s.my_warnning("库存不足!", 0, th);
                }
              }

              var updata = {
                id: item.id,
                goods_num: e.data.goodsInputNum + item.goods_num,
                goods_price: newd.goods_price,
                member_goods_price: newd.goods_price,
                store_id: th.data.stoid,
                prom_id: newd.prom_id, //把活动id带上去(用于购物车失效变成有效商品)
                prom_type: newd.prom_type
              };

              if (newd.is_pd_normal) {
                updata.is_pd_normal = 1
              }

              //---是不是从收藏夹出来的---
              if (th.data.c_guide_id) {
                updata['guide_id'] = th.data.c_guide_id;
                updata['guide_type'] = 3; //加入购物车之后就变成了3
              } else {
                if (getApp().globalData.guide_id) {
                  updata['guide_id'] = getApp().globalData.guide_id;
                  updata['guide_type'] = 0;
                }
              }
              if (getApp().globalData.groupchat_id) {
                updata['groupchat_id'] = getApp().globalData.groupchat_id;
              }

              getApp().request.put("/api/weshop/cart/update", {
                data: updata,
                success: function (t) {
                  wx.hideLoading();
                  th.data.adding = 0;
                  getApp().my_warnning('加入购物车成功', 1, th, 450);
                  var c_num = th.data.cartGoodsNum + th.data.goodsInputNum;
                  th.setData({
                    cartGoodsNum: c_num
                  });
                  th.closeSpecModal();
                }
              });
            } else {
              getApp().request.post("/api/weshop/cart/save", {
                data: newd,
                success: function (t) {
                  wx.hideLoading();
                  th.data.adding = 0;
                  getApp().my_warnning('加入购物车成功', 1, th, 450);
                  var c_num = th.data.cartGoodsNum + e.data.goodsInputNum;
                  th.setData({
                    cartGoodsNum: c_num
                  });
                  th.closeSpecModal();
                }
              });
            }
          }
        });

      } else {

        newd['pick_name'] = th.data.sto_sele_name;
        newd['pick_dis'] = th.data.sto_sele_distr;
        th.buyNow(newd);

      }
    },

    //-------------获取购买数量的总函数----------------
    get_buy_num: function (gd, func) {
      var map = this.data.g_buy_num,
        th = this,
        user_id = getApp().globalData.user_id;
      if (user_id == null) {
        map.set(gd.goods_id, 0);
        th.setData({
          g_buy_num: map,
          prom_buy_num: 0,
        });
        "function" == typeof func && func();
        return false;
      }

      if (map.has(gd.goods_id)) {
        "function" == typeof func && func();
      } else {
        //----获取商品购买数----
        getApp().request.get("/api/weshop/ordergoods/getUserBuyGoodsNum", {
          data: {
            store_id: os.stoid,
            user_id: user_id,
            goods_id: gd.goods_id, isnew: 1,
            timetype:gd.viplimited_timetype
          },
          success: function (t) {
            if (t.data.code == 0) {
              var g_buy_num = t.data.data.goodsbuynum;

              //如果是秒杀的时候
              if (th.data.prom_type == 0 && gd.prom_type == 1) {
                gd.prom_type = 0;
              }
              //如果全场优惠,商品做了秒杀
              if (th.data.prom_type == 3 && gd.prom_type == 1) {
                gd.prom_type = 0;
              }
              //如果全场阶梯优惠,商品做了秒杀
              if (th.data.prom_type == 10 && gd.prom_type == 1) {
                gd.prom_type = 0;
              }


              if (!th.data.is_normal && (gd.prom_type == 1 || gd.prom_type == 2 || gd.prom_type == 4 || gd.prom_type == 6)) {
                //----获取活动购买数----
                getApp().request.get("/api/weshop/ordergoods/getUserBuyGoodsNum", {
                  data: {
                    store_id: os.stoid,
                    user_id: user_id,
                    goods_id: gd.goods_id,
                    prom_type: gd.prom_type,
                    prom_id: gd.prom_id, isnew: 1
                  },
                  //-----获取-----
                  success: function (tt) {
                    if (tt.data.code == 0) {
                      map.set(gd.goods_id, g_buy_num);
                      th.setData({
                        g_buy_num: map,
                        prom_buy_num: tt.data.data.promgoodsbuynum,
                      });
                      "function" == typeof func && func();
                    }
                  }
                });
              } else {
                map.set(gd.goods_id, g_buy_num);
                th.setData({
                  g_buy_num: map
                });
                "function" == typeof func && func();
              }
            }
          }
        });
      }
    },
    //---  获取卡类列表 ---
    getPlusCardType: function (func) {
      var storid = os.stoid;
      var th = this;
      var user = getApp().globalData.userInfo;
      if (!user) return false;
      getApp().request.promiseGet("/api/weshop/plus/vip/mem/bership/list?" + "storeId=" + storid, {}).then(res => {
        var plusCard = res.data.data;
        var arr = [1219, 2089, 3031];
        var new_arr = new Array();
        var card_name_map = new Map();

        var list = [];
        for (var i = 0; i < plusCard.length; i++) {
          if ((!user || user.card_field == null || user.card_field == "") && plusCard[i].IsStopBuy == true) continue;
          var name = "card" + plusCard[i].CorrPrice.toLowerCase();
          card_name_map.set(name, plusCard[i].CardName);
          list.push(plusCard[i]);
        }

        var ob = {
          "card_list": list,
          "name_map": card_name_map
        };
        func(ob);
      })
    },


    //----------增加购买数量-----------
    addCartNum: function (t) {
      var add_num = 1;
      var p_type = parseInt(this.data.prom_type)
      if ([1, 2, 4, 6, 8, 9].indexOf(p_type) == -1 || this.data.openSpecModal_inte_normal == 1 || this.data.is_normal == 1) {
        add_num = getApp().get_limit_qty(this.data.sele_g, this.data.is_act, 1);
      }

      this.checkCartNum(this.data.goodsInputNum + add_num);
    },
    //------检查数量是不是超出限购------
    checkCartNum: function (t) {
      var th = this;

      var mo_num = getApp().get_limit_qty(th.data.sele_g, th.data.is_act);
      var steep = getApp().get_limit_qty(th.data.sele_g, th.data.is_act, 1);
      this.get_buy_num(this.data.sele_g, async function () {

        var is_show_bs = 0;
        var l_num = -1;

        //--判断商品是否超出限购--
        if (th.data.g_buy_num != null && th.data.sele_g.viplimited > 0) {

          var gd_buy_num = th.data.g_buy_num.get(th.data.sele_g.goods_id);

          if (t + gd_buy_num > th.data.sele_g.viplimited) {
            wx.showToast({
              title: '超出商品限购',
              icon: 'none',
            });

            is_show_bs = 1;

            // s.my_warnning('超出商品限购', 0, th);
            l_num = th.data.sele_g.viplimited - gd_buy_num;
            if (l_num < 0) l_num = 0;
            // th.setData({
            //   goodsInputNum: num
            // })
            // return false;
          }
        }

        //如果是普通购买的情况下
        if (th.data.openSpecModal_flash_normal) th.data.is_normal = 1;

        //--判断商品是否超出活动限购--
        if (th.data.prom_buy_num != -1 && th.data.prom_buy_limit > 0 && !th.data.is_normal) {
          if (t + th.data.prom_buy_num > th.data.prom_buy_limit) {
            wx.showToast({
              title: '超出商品活动限购',
              icon: 'none',
            });
            // s.my_warnning('超出商品活动限购', 0, th);
            var num = th.data.prom_buy_limit - th.data.prom_buy_num;
            if (num < 0) num = 0;
            th.setData({
              goodsInputNum: num
            })
            return false;
          }
        }

        if ((th.data.sele_g.prom_type == 1 || th.data.sele_g.prom_type == 2 || th.data.sele_g.prom_type == 6) && !th.data.is_normal) {
          var redis_num = 0;
          //------判断活动是否抢光-----
          await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" +
            os.stoid + "/" + th.data.sele_g.prom_type + "/" + th.data.sele_g.prom_id, {
            1: 1
          }).then(res => {
            redis_num = res.data.data;
          });

          if (t > redis_num) {
            wx.showToast({
              title: '超出商品活动库存',
              icon: 'none',
            });
            // s.my_warnning('超出商品活动库存', 0, th);
            th.setData({
              goodsInputNum: redis_num
            })
            return false;
          }
        }
        var e = th.data.sele_g.store_count;
        var p_type = parseInt(th.data.prom_type + ''); //&& p_type!=1 && p_type!=4
        if (!th.data.sele_g.whsle_id && th.data.sales_rules >= 2 &&
          ([1, 2, 4, 6, 8, 9].indexOf(p_type) == -1 || th.data.openSpecModal_inte_normal == 1 || th.data.is_normal == 1)) {

          //-- 如果是虚拟商品,默认给最大值 --
          if (getApp().is_virtual(th.data.sele_g)) {
            e = 100000;
          } else {
            if (!th.data.def_pick_store) {
              wx.showToast({
                title: '请选择门店',
                icon: 'none',
              });
              // wx.showModal({title: '请选择门店',});
              return false;
            } else {
              e = th.data.def_pick_store.CanOutQty;
            }
          }
        }

        //-- 限购数量也要进行计算一下 --
        if (l_num > -1) {
          if (e > l_num) e = l_num;
        }

        //--- 促销活动也不控制起订量, 这里很重要的一个控制,起订量的 ----
        if ([0, 3, 5, 7, 10].indexOf(p_type) > -1 || th.data.openSpecModal_inte_normal == 1 || th.data.is_normal == 1) {
          if (t < mo_num) {
            t = mo_num;
            if (!is_show_bs) {
              wx.showToast({
                title: '购买数未达到起订量',
                icon: 'none',
              });
            }
            is_show_bs = 1;
          }
          if (t > mo_num && (t - mo_num) % steep != 0) {

            if (!is_show_bs) {
              wx.showToast({
                title: '购买数必须是起订量的倍数',
                icon: 'none',
              });
            }

            t = mo_num + parseInt((t - mo_num) / steep) * steep + steep;
            is_show_bs = 1;
          }
        }

        if (!e) e = 0;
        //库存不足,不增加
        if (e < t) {
          if (!is_show_bs) {
            wx.showToast({
              title: '库存不足',
              icon: 'none',
            });
          }

          // wx.showModal({title: '库存不足',});
          if (e < 0) e = 0;

          //只有普通商品才有起购数
          if ([1, 2, 4, 6, 8, 9].indexOf(p_type) == -1 || th.data.openSpecModal_inte_normal == 1 || th.data.is_normal == 1) {
            if (e < mo_num) e = mo_num;
            if (e > mo_num && (e - mo_num) % steep != 0) {
              e = mo_num + parseInt((e - mo_num) / steep) * steep;
            }
          }
          th.setData({
            goodsInputNum: e
          });
          return false;
        }

        //var steep=getApp().get_limit_qty(th.data.sele_g,0,1);
        t > e || 0 == e ? t = e : t < 1 && (t = 1);


        //只有普通商品才有起购数
        if ([1, 2, 4, 6, 8, 9].indexOf(p_type) == -1 || th.data.openSpecModal_inte_normal == 1 || th.data.is_normal == 1) {
          if (t < mo_num) t = mo_num;
        }


        th.setData({
          goodsInputNum: t
        });
        th.is_show_more_buy();

      })
    },
    is_show_more_buy: async function () {
      var prom_goods = this.data.prom_goods;
      if (!prom_goods) return false;
      //如果系统默认的顺序不是以优惠促销为默认第一位的时候
      if (this.check_prom_custom(1) !== 3) {
        return false;
      }

      if (!this.data.sele_g) return false;

      var per_price = this.data.sele_g.shop_price
      if (this.data.card_field && this.data.sele_g[this.data.card_field] > 0) {
        per_price = this.data.sele_g[this.data.card_field];
      }

      var all_price = per_price * this.data.goodsInputNum;
      var con = null;
      for (var i in prom_goods) {
        var item = prom_goods[i];
        if (item.prom_type == 1) {
          if (item.condition > this.data.goodsInputNum) {
            con = item;
            con.need = (item.condition - this.data.goodsInputNum).toFixed(2) + "件";
            break;
          }
        } else {
          if (parseFloat(item.condition) > parseFloat(parseFloat(all_price).toFixed(2))) {
            con = item;
            con.need = (item.condition - all_price).toFixed(2) + "元";
            break;
          }
        }
      }
      //获取用户参与优惠促销的次数
      //if(con && con.prom_id){
      //await this.getUserBuyPromNum_pre(con.prom_id);
      //}
      this.setData({
        hui_condition: con
      });

    },

    //----------减少购买数量-----------
    subCartNum: function (t) {
      var add_num = 1;
      var p_type = parseInt(this.data.prom_type)
      if ([1, 2, 4, 6, 8, 9].indexOf(p_type) == -1 || this.data.openSpecModal_inte_normal == 1 || this.data.is_normal == 1) {
        add_num = getApp().get_limit_qty(this.data.sele_g, this.data.is_act, 1);
        var mo_num = getApp().get_limit_qty(this.data.sele_g, this.data.is_act);
        if (this.data.goodsInputNum - add_num < mo_num) {
          wx.showToast({
            title: '购买数量不能小于起订量',
            icon: 'none',
          });
          return false;
        }
      }
      this.checkCartNum(this.data.goodsInputNum - add_num);
    },
    //----------输入框输入购买数量-----------
    inputCartNum: function (t) {
      this.checkCartNum(Number(t.detail.value));
    },
    //统一一下获取线下库存的函数
    async check_CanOutQty(goodsinfo, item, func) {

      var sales_rules = this.data.sales_rules;
      //如果默认是商品
      if (getApp().is_virtual(goodsinfo)) {
        return func(100000);
      }

      var lock_rq = {
        store_id: os.stoid,
        wareId: goodsinfo.goods_id,
        pageSize: 1000
      };

      if (sales_rules == 2) {
        lock_rq.storageId = item.pickup_id
      } else {
        lock_rq.appoint_pick_keyid = encodeURIComponent(this.data.appoint_pick_keyid)
      }

      var lock = 0;
      var CanOutQty = 0;
      var plist = null;
      //先读取门店的lock
      await getApp().request.promiseGet("/api/weshop/order/ware/lock/page", {
        data: lock_rq
      }).then(res => {
        if (res.data.code == 0 && res.data.data.total > 0) {
          for (var i in res.data.data.pageData)
            lock += res.data.data.pageData[i].outQty;
        }
      })

      var sto_req = {
        wareIds: encodeURIComponent(goodsinfo.erpwareid),
        storeId: os.stoid
      }
      if (sales_rules == 2) {
        sto_req.storageNos = item.pickup_no
      } else {
        sto_req.storageIds = encodeURIComponent(this.data.appoint_pick_keyid)
      }



      //读取线下的门店库存
      await getApp().request.promiseGet("/api/weshop/goods/getWareStorages", {
        data: sto_req
      }).then(res => {
        if (res.data.code == 0 && res.data.data.total > 0) {
          plist = res.data.data.pageData[0];
        }
      })

      if (plist && plist.CanOutQty - lock > 0) {
        CanOutQty = plist.CanOutQty - lock;
      }

      if (func) func(CanOutQty);

    },
    //获取更多秒杀
    get_more_flahs: async function (func) {
      var f_more = false;
      var user_id = getApp().globalData.user_id;
      if (!user_id) user_id = 0;

      var url = "/api/weshop/goods/listSkuFlash?store_id=" + os.stoid + "&goods_id=" + this.data.data.goods_id + "&user_id=" + user_id;
      //获取秒杀的多规格
      await getApp().request.promiseGet(url, {}).then(res => {
        if (res.data.code == 0 && res.data.data && res.data.data.length > 0) {
          f_more = res.data.data;
        }
      })
      if (!f_more) {
        func(false);
        return false;
      }
      //-- 秒杀的价格要更新 --
      for (let i in f_more) {

        let item = f_more[i];
        f_more[i].prom_id = item.act_id;
        f_more[i].prom_type = 1;

        var url = "/api/ms/flash_sale/getNew/" + os.stoid + "/" + user_id + "/" + item.act_id;
        await getApp().request.promiseGet(url, {}).then(rs => {
          if (rs.data.code == 0 && rs.data.data) {
            f_more[i].price = rs.data.data.user_price;
            f_more[i].is_pickup = rs.data.data.is_pickup;
            f_more[i].pick_up_lists = rs.data.data.pick_up_lists;
          }
        })
      }
      func(f_more);

    },
    //获取redis中的数量
    async getactLen(func) {
      var r_num = 0,
        prom_type = this.data.prom_type,
        prom_id = this.data.prom_id;
      await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/" + prom_type + "/" + prom_id, {
        1: 1
      }).then(res => {
        var em = res;
        if (em.data.code == 0) {
          r_num = em.data.data;
        }
      })
      func(r_num);
    },
    //获取redis中的数量
    async getactLenser() {
      let prom_type = this.data.prom_type;
      let prom_id = this.data.prom_id;
      return await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/" + prom_type + "/" + prom_id, {
        1: 1
      }).then(res => {
        if (res.data.code == 0) {
          // 当前可以购买的数量
          let r_num = res.data.data;
          return r_num;
        };
      })
    },

    //因为在购物车  普通商品和 优惠促销,搭配购,组合购 阶梯购是一样的
    check_is_like(e, newd, idx) {
      if (e.prom_type == newd.prom_type) return true;
      if (!idx) {
        if (e.prom_type == 0) {
          if ([3, 5, 7, 10].indexOf(newd.prom_type) > -1) return true;
        }
        if (newd.prom_type == 0) {
          if ([3, 5, 7, 10].indexOf(e.prom_type) > -1) return true;
        }
      }
      return false;
    },
    //----------增加购买数量-----------
    addCartNumser: function (t) {
      this.checkCartNumser(this.data.goodsInputNum + 1);
    },
    //----------减少购买数量-----------
    subCartNumser: function (t) {
      this.checkCartNumser(this.data.goodsInputNum - 1);
    },
    //----------输入框输入购买数量-----------
    inputCartNumser: function (t) {
      this.checkCartNumser(Number(t.detail.value));
    },

    //------检查数量是不是超出限购------
    checkCartNumser: async function (t) {
      var th = this;

      if (!th.data.def_pick_store) {
        wx.showModal({ title: '请选择门店', });
        return false;
      };

      // 非秒杀活动
      if (this.data.prom_type != 1) {
        this.setData({
          goodsInputNum: t,
        });
      };

      // 秒杀活动
      if (this.data.prom_type == 1) {
        // 如果是秒杀活动下的单独购买,is_normal为1
        if (this.data.openSpecModal_flash_normal) this.data.is_normal = 1;

        if (this.data.is_normal) {// 单独购买
          this.setData({
            goodsInputNum: t,
          });
        } else {// 秒杀购买

          // 获取redis当前可以购买的数量
          // 如果数量为0,设置和显示已抢光
          // 否则,进一步判断是否超出限购或超出库存
          await this.getactLenser().then(async function (res) {
            // res: redis可购买数量
            // console.log('当前可以购买的数量:', res);
            if (res <= 0) {
              // 可购买数量<=0, 设置和显示已抢光
              th.setData({
                prom_r_null: 1,
              });
            } else {
              // 可购买数量>0
              // 计算自己还可以购买的数量
              // 自己还可购买的数量c = 每人活动限购数量a - 自己已经购买的数量b
              // 如果限购数量a>redis可购买数量d,当增加数量t>d, 提示超出库存
              // 如果限购数量a<=redis可购买数量d, 当增加数量t>a,提示超出限购
              let actInfo = th.data.sele_g;
              await th.get_buy_num2().then(function (data) {
                let limited = actInfo.buy_limit == 0 ? 100000 : actInfo.buy_limit; // 限购数量a
                let promcardbuynum = data.data.data.promcardbuynum;
                let buyedNum = promcardbuynum; // 自己已经购买的数量b
                let canBuyNum = limited - buyedNum; // 自己还可购买的数量c

                if (canBuyNum <= 0) {
                  canBuyNum = 0;
                };

                if (limited > res) {
                  if (t > res) { // t当前增减的数量
                    // wx.showModal({
                    // 	title: '超出活动库存',
                    // });
                    getApp().my_warnning('超出活动库存', 0, self);
                    th.setData({
                      goodsInputNum: res || 1,
                    });
                    return false;
                  };
                };

                if (limited <= res) {
                  if (t > canBuyNum) {
                    // wx.showModal({
                    // 	title: '超出限购数量',
                    // });
                    getApp().my_warnning('超出限购数量', 0, self);
                    th.setData({
                      goodsInputNum: canBuyNum || 1,
                    });
                    return false;
                  };
                };

                th.setData({
                  goodsInputNum: t,
                });
              });
            };
          });

        }


      };











      // var e = th.data.sele_g.goods_num;
      // var p_type = th.data.prom_type; //&& p_type!=1 && p_type!=4
      // if (th.data.sales_rules == 2 && (p_type != 1 && p_type != 4 && p_type != 6 || th.data.openSpecModal_inte_normal == 1 || th.data.is_normal == 1)) {
      //     if (!th.data.def_pick_store) {
      //         wx.showModal({title: '请选择门店',});
      //         return false;
      //     } else {
      //         e = th.data.def_pick_store.CanOutQty;
      //     }
      // }


      // th.setData({goodsInputNum: t});

      // });


    },
    //-----------选择属性的按钮事件----------
    sele_spec: function (e) {

      //如果只有一个规格直接结束
      if ((this.data.sku_g && this.data.sku_g.length == 1) || (this.data.sku_g_pt && this.data.sku_g_pt.length == 1)) {
        return
      }
      if (this.data.sp_seleing) {
        return false;
      }

      this.setData({ sp_seleing: 1 })

      var that = this;
      var th = this;

      //在切换规格的时候,指定门店不匹配的状态要清理
      if (th.data.def_pick_store && JSON.stringify(th.data.def_pick_store) != '{}') {
        th.data.def_pick_store.is_no_dis_nor = 0;
        that.setData({
          def_pick_store: th.data.def_pick_store
        })
      }

      //切换完商品后,海报图片都要跟换
      this.data.share_goods_img = null;

      var gid = e.currentTarget.dataset.gid;
      var nor = e.currentTarget.dataset.nor;
      var user_id = getApp().globalData.user_id;

      var sku_g = this.data.sku_g;
      if (nor || (gid != this.data.base_nor_goods_id && this.data.base_nor)) {
        sku_g = this.data.sku_g_pt;
        if (nor) this.data.base_nor = nor;
      }

      //要把不匹配还原
      if (th.data.def_pick_store && JSON.stringify(th.data.def_pick_store) != '{}') {
        th.data.def_pick_store.is_no_dis = 0;
        th.data.def_pick_store.is_no_dis_nor = 0;
        th.setData({ def_pick_store: th.data.def_pick_store })
      }

      //普通商品多规格的时候,商品切换
      if (this.data.base_nor_prom_type) this.data.base_nor_prom_type = parseInt(this.data.base_nor_prom_type);
      if ([1, 2, 4, 6, 8, 9].indexOf(this.data.base_nor_prom_type) == -1) {

        this.setData({
          prom_goods: null,
          jieti_prom: null,
          order_prom: null,
          zh_act: null,
          more_flash: null,
        })
      }

      //拼团在点击回来的时候,还是只能是立即购买,不能有购物车的情况
      if (this.data.base_nor_prom_type == 6 && parseInt(gid + '') == parseInt(this.data.base_nor_goods_id + '')) {
        this.setData({
          openSpecModal_pt: 1,
          openSpecModal: 0,
          sku_g: this.data.sku_g_pt,
          is_normal: 1
        })
        nor = 1;
      }


      //that.data.change=1;
      var item = null;
      for (var i in sku_g) {
        if (sku_g[i].goods_id == gid) {
          item = sku_g[i];
          if (item.original_img.indexOf(that.data.iurl) == -1) {
            item.original_img = that.data.iurl + item.original_img;
          }
          break
        }
      }
      console.log(item, 2000);
      var cur_price = item.shop_price;
      if (getApp().globalData.userInfo && getApp().globalData.userInfo.card_field) {
        var cfile = getApp().globalData.userInfo.card_field;
        console.log('cfile', cfile);
        if (item[cfile]) {
          cur_price = item[cfile];
        }
      }
      var txt = (cur_price / item.market_price * 10).toFixed(2).toString();
      txt = parseFloat(txt);
      item['disc'] = txt;
      if (item) this.setData({
        sele_g: item,
        gid: gid,
        data: item,
      });


      if (nor) {
        that.set_sele_g(sku_g)
        that.get_sto(1, () => {
          that.sele_spec_next(that, item, gid, nor);
        });
      }
      else that.get_sto(null, () => {
        that.sele_spec_next(that, item, gid, nor);
      }, item);

    },
    //-- 选择规格下一步 --
    sele_spec_next(that, item, gid, nor) {
      let th = this;
      if (!item.whsle_id && ([1, 2, 4, 6].indexOf(item.prom_type) == -1 || this.data.is_normal == 1))
        that.check_is_youhui(gid, that.data.is_normal, 1);

      //默认门店要拿下门店库存
      if (that.data.sales_rules >= 2 && that.data.def_pick_store && !that.data.sele_g.whsle_id && [1, 2, 4, 6].indexOf(item.prom_type) == -1) {
        var lock = 0,
          plist = null;

        that.check_CanOutQty(that.data.sele_g, that.data.def_pick_store, function (CanOutQty) {
          that.data.def_pick_store.CanOutQty = CanOutQty;
          //--给门店赋值线下库存--
          that.setData({
            def_pick_store: that.data.def_pick_store
          });
        })

      }
      that.sele_spec_chech_activity(nor);

      //如果是秒杀,拼团等互动,就不重新算界面
      if ([1, 2, 4, 6, 8, 9].indexOf(this.data.base_nor_prom_type) > -1) {
        return false;
      }

      that.check_has_flash(gid);
      var url = '/api/weshop/activitylist/listGoodActInfo2New';
      var req_d = {
        "store_id": os.stoid,
        "goods_id": that.data.gid,
        "user_id": getApp().globalData.user_id,
      }
      getApp().request.get(url, {
        data: req_d,
        success: function (e) {
          if (e.data.code != 0 || !e.data.data || e.data.data.length <= 0) return false;
          var arr = e.data.data;
          if (!arr || !arr.length) {
            return false;
          }
          var arr3 = arr.filter(function (e) {
            return e.s_time < ut.gettimestamp() && e.prom_type == 7;
          })

          //-- 组合购要在面前计算 --,计算完之后,再来计算check_is_youhui --
          if (arr3 && arr3.length > 0) {
            //获取活动信息
            var url = "/api/weshop/prom/zhbuy/get/" + os.stoid + "/" +
              arr3[0].act_id + "/" + getApp().globalData.user_id;
            getApp().request.get(url, {
              success: function (e) {
                if (e.data.code == 0 && e.data.data) {
                  if (ut.gettimestamp() < e.data.data.start_time) {
                    return false;
                  }
                  if (e.data.data.is_end == 0 && ut.gettimestamp() < e.data.data.end_time) {
                    //-- 获取商品列表 --
                    th.setData({
                      zh_act: e.data.data
                    });
                    th.getUserBuyPromNum(e.data.data.id)
                  }
                }
                if (!item.whsle_id) that.check_is_youhui(gid, that.data.is_normal);
              }
            });
          } else {
            if (!item.whsle_id) that.check_is_youhui(gid, that.data.is_normal);
          }

        }
      })
    },
    //选择了不同的规格的时候要判断是不是有活动正在进行中
    async sele_spec_chech_activity(nor) {
      //---如果是活动的时候---
      var prom = null, goodsinfo = this.data.sele_g, th = this;

      //如果是普通购买的时候,要返回原先
      if (goodsinfo.goods_id == this.data.base_nor_goods_id) {
        goodsinfo.prom_type = this.data.base_nor_prom_type;
        goodsinfo.prom_id = this.data.base_nor_prom_id;

        this.setData({
          prom_type: this.data.base_nor_prom_type,
          prom_id: this.data.base_nor_prom_id,
        })
      }

      var user_id = getApp().globalData.user_id;
      if (!user_id) user_id = 0;
      if (goodsinfo.prom_type == 1) {
        await getApp().request.promiseGet("/api/ms/flash_sale/getNew/" + os.stoid + "/" + user_id + "/" + goodsinfo.prom_id, {}).then(res => {
          if (res.data.code == 0 && res.data.data) {
            prom = res.data.data;
            prom.price = prom.user_price;
            this.setData({
              is_share_text: prom.is_share_text
            })
          }
        })
      }
      if (goodsinfo.prom_type == 6) {
        await getApp().request.promiseGet("/api/weshop/teamlist/get/" + os.stoid + "/" + goodsinfo.prom_id, {}).then(res => {
          if (res.data.code == 0) {
            prom = res.data.data;


            //----------查看阶梯团------------
            if (prom.ct_rylist != "null" && prom.ct_rylist != "" && prom.ct_rylist != null && prom.ct_rylist != undefined) {
              prom.ct_rylist = JSON.parse(prom.ct_rylist);
              var max_num = 0;
              prom.ct_rylist.forEach(function (val, ind) {
                if (parseInt(val.rynum) > max_num) max_num = parseInt(val.rynum);
              })
              prom.max_ct_num = max_num;
            }

          }
        })
      }

      if (goodsinfo.prom_type == 4) {
        await getApp().request.promiseGet("/api/weshop/integralbuy/getActInfo/" + os.stoid + "/" + goodsinfo.goods_id + "/" + goodsinfo.prom_id, {}).then(res => {
          if (res.data.code == 0) {
            prom = res.data.data;
          }
        })

        if (prom) {
          let times = new Date().getTime()
          prom.show_time_off = ""
          let atimes = prom.start_time * 1000

          if (atimes > times) {
            prom.show_time_off = ut.formatTime(prom.start_time)
          }
        }

      }
      console.log('活动详情------------');
      console.log(prom);
      //----------如果有活动,并且在进行中,就不计算线下库存---------------
      var now = ut.gettimestamp();
      if (prom) {

        var t1 = prom.start_time;
        var prom_st = 1;
        if (prom.show_time) {
          t1 = prom.show_time;
          if (prom.start_time > now) prom_st = 0;
        }
        if (prom.is_end == 0 && prom.end_time > now && t1 < now) {
          th.setData({
            prom_type: goodsinfo.prom_type,
            prom_price: prom.price,
            prom_buy_limit: prom.buy_limit ? prom.buy_limit : (prom.limitvipqty ? prom.limitvipqty : 0),
            prom_end_time: prom.end_time,
            prom_start_time: prom.start_time,
            prom_st: prom_st,
            prom_act: prom,
            prom_id: prom.id,
            sp_seleing: 0
          })

          var pro_null = null;
          if (goodsinfo.prom_type == 1) {
            var rs = await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/1/" + prom.id, {});
            if (rs && rs.data.code == 0 && rs.data.data <= 0) {
              pro_null = 1;
            }
          }
          th.setData({ pro_null });


          //却换图片
          th.init(goodsinfo.goods_id);
          var newTime = ut.gettimestamp();
          var endTime2 = prom.end_time;
          var endTime1 = prom.start_time;

          this.data.is_timer = 0;

          setTimeout(function () {
            th.data.is_timer = 1;
            if (endTime1 > newTime) {
              th.setData({
                prom_time_text: '距秒杀开始还有'
              })
              // th.countDown(endTime1, 0);
            } else {
              if (endTime2 > newTime) {
                th.setData({
                  prom_time_text: '距秒杀结束还有',
                  prom_st: 1
                })
                // th.countDown(endTime2);
              }
            }

          }, 1000)

          return false;
        }
      }

      if (nor) {
        th.setData({ sp_seleing: 0 })
        return false;
      }

      //---设置普通商品---
      th.setData({
        prom_type: 0,
        prom_price: null,
        prom_buy_limit: null,
        prom_end_time: null,
        prom_start_time: null,
        prom_st: null,
        sp_seleing: 0
      })

    },
    //---检查有没有优惠活动---  is_nor的普通购买的时候,is_spec是切换规格的时候
    check_is_youhui: async function (gid, is_nor, is_spec) {
      var th = this;
      var user_id = getApp().globalData.user_id;
      if (!user_id) user_id = 0;

      //普通购买的时候,重新算一下组合购有没有
      if (is_nor || is_spec) {


        th.setData({
          cx_prom_group: []
        })

        var arr3 = null;
        var url = '/api/weshop/activitylist/listGoodActInfo2New';
        var req_d = {
          "store_id": os.stoid,
          "goods_id": gid,
          "user_id": user_id,
        }
        await getApp().request.promiseGet(url, {
          data: req_d,
        }).then(e => {
          if (e.data.code == 0 && e.data.data && e.data.data.length > 0) {
            var arr = e.data.data;
            if (arr.length) {
              arr3 = arr.filter(function (e) {
                return e.s_time < ut.gettimestamp() && e.prom_type == 7;
              })
            }
          }
        })

        if (arr3 && arr3.length > 0) {
          //获取活动信息
          var url = "/api/weshop/prom/zhbuy/get/" + os.stoid + "/" + arr3[0].act_id + "/" + getApp().globalData.user_id;
          await getApp().request.promiseGet(url, {

          }).then(e => {
            if (e.data.code == 0 && e.data.data) {
              if (ut.gettimestamp() < e.data.data.start_time) {
                return false;
              }
              if (e.data.data.is_end == 0 && ut.gettimestamp() < e.data.data.end_time) {
                //-- 获取商品列表 --

                if (is_spec) {
                  th.setData({
                    zh_act: e.data.data
                  })
                } else {
                  th.data.zh_act = e.data.data;
                }

                th.getUserBuyPromNum(e.data.data.id)
              }
            }
          })
        }
      }

      var r_data = null;


      //-- 如果有组合购的时候 --
      if (th.data.zh_act) {
        var show_time = ut.formatTime(th.data.zh_act.start_time) + "至" + ut.formatTime(th.data.zh_act.end_time);
        //-- 开始组装数据 --
        th.add_cx_prom_group({
          id: th.data.zh_act.id,
          title: th.data.zh_act.name,
          show_time: show_time,
          prom_type: 7
        });
      }

      //调用接口判断订单优惠,
      await getApp().request.promiseGet("/api/weshop/goods/getGoodsPromListNew1/" + os.stoid + "/" + gid + "/0" + "/" + user_id, {}).then(async res => {
        if (res.data.code == 0 && res.data.data) {
          r_data = res.data.data;
          var max = 0,
            min = 0;

          //如果是搭配购的时候
          if (r_data.collocationList) {
            for (var i in r_data.collocationList) {
              if (max == 0) max = r_data.collocationList[i].price;
              if (min == 0) min = r_data.collocationList[i].price;

              if (max < parseFloat(r_data.collocationList[i].price)) max = r_data.collocationList[i].price;
              if (min > parseFloat(r_data.collocationList[i].price)) min = r_data.collocationList[i].price;
            }
            r_data.collocationPromList.max = (max + th.data.data.shop_price).toFixed(2);
            r_data.collocationPromList.min = (min + th.data.data.shop_price).toFixed(2);
            var show_price = '¥' + r_data.collocationPromList.max + '-' + r_data.collocationPromList.min;
            var show_time = ut.formatTime(r_data.collocationPromList.start_time) + "至" + ut.formatTime(r_data.collocationPromList.end_time);

            //-- 开始组装数据 --
            th.add_cx_prom_group({
              id: r_data.collocationPromList.id,
              title: r_data.collocationPromList.title,
              show_price: show_price,
              show_time: show_time,
              prom_type: 5,
              main_gid: gid
            });
          }



          //优惠促销的时候
          if (r_data.promGoodsLists) {

            var fir_act = r_data.promGoodsLists[0];
            var is_yh_out_limit = 0;


            //-- 计算一下限购,满足限购数才显示  --
            if (fir_act.limit_num) {
              // await this.getUserBuyPromNum_pre(fir_act.prom_id);
              if (th.data.user_pre_buynum >= fir_act.limit_num) {
                is_yh_out_limit = 1;
              }
            }

            //如果是有限购的时候
            if (fir_act.gd_limit_num > 0 && !is_yh_out_limit) {
              var lrs = {
                store_id: os.stoid,
                user_id: user_id,
                goods_id: gid,
                prom_type: 3,
                prom_id: fir_act.prom_id, isnew: 1
              };
              var gd_limit_rs = await getApp().promiseGet('/api/weshop/ordergoods/getUserBuyGoodsNum', { data: lrs });
              var pro_by_num = 0;
              if (gd_limit_rs && gd_limit_rs.data.code == 0) {
                pro_by_num = gd_limit_rs.data.data.promgoodsbuynum
              }
              if (pro_by_num >= fir_act.gd_limit_num) {
                is_yh_out_limit = 1;
              }
            }
            //--  如果超出限购,就不显示了 --
            if (!is_yh_out_limit) {
              var more_arr = ut.format_yh_act(fir_act);

              var limit = '每人' + (fir_act.limit_num ? '限参与' + fir_act.limit_num + '次' : '参与不限次');
              if (fir_act.gd_limit_num > 0) {
                limit += ",限购" + fir_act.gd_limit_num + "件";
              }

              //-- 开始组装数据 --
              th.add_cx_prom_group({
                id: fir_act.prom_id,
                condition: fir_act.condition + (fir_act.prom_type == 1 ? '件' : '元'),
                limit: limit,
                gd_limit_num: fir_act.gd_limit_num > 0 ? fir_act.gd_limit_num : 0,
                more: more_arr,
                prom_type: 3,
                promGoodsListsDtos: r_data.promGoodsLists,
                is_yh_out_limit: is_yh_out_limit
              });
            }

          }

          //普通购买不在界面显示
          if (is_nor) {
            th.data.collocationGoods = r_data.collocationPromList;
            th.data.prom_goods = r_data.promGoodsLists;
          } else {
            th.setData({
              order_prom: r_data.promOrder,
              collocationGoods: r_data.collocationPromList,
              prom_goods: r_data.promGoodsLists,
            })
          }


        }
      })


      //-- 如果有阶梯购的时候 --
      if (r_data && r_data.ladderLists) {
        var act_id = r_data.ladderLists[0].form_id;
        //-- 判断会员能不能参与阶梯促销 --
        await getApp().request.promiseGet("/api/weshop/prom/ladderForm/getNew/" + os.stoid + "/" + user_id + "/" + act_id, {}).then(res => {
          if (res.data.code == 0 && res.data.data) {
            var prom_content = "";
            //暂定优惠促销还不能重叠
            // if (res.data.data.good_object == 0 && (r_data.promGoodsLists || th.data.zh_act)) {
            //   return false;
            // }
            // if (res.data.data.good_object == 1) {
            //   r_data.promGoodsLists = null;
            // }

            for (let jj in r_data.ladderLists) {
              if (r_data.ladderLists[jj].discount == 10) {
                prom_content += "第" + (parseInt(jj) + 1) + "件原价,";
              } else {
                prom_content += "第" + (parseInt(jj) + 1) + "件" + r_data.ladderLists[jj].discount + "折,";
              }
            }
            prom_content = ut.sub_last(prom_content);
            th.data.prom_type = 10;
            th.data.prom_id = act_id;
            th.setData({
              jieti_prom: prom_content,
              ladder_act_id: act_id
            })

            //-- 组装一下阶梯促销 --
            var s_time = res.data.data.start_time;
            var e_time = res.data.data.end_time;
            th.add_cx_prom_group({
              id: act_id,
              title: prom_content,
              show_time: ut.formatTime(s_time) + "至" + ut.formatTime(e_time),
              prom_type: 10
            });

          }
        })
      }

      th.is_show_more_buy();

      //-- 如果有促销活动也算是有参与活动,参与活动的也统一不进行计算起订的数量 --
      this.data.is_act = 0;
      if (this.data.zh_act || this.data.prom_goods || this.data.jieti_prom || this.data.collocationGoods) {
        this.data.is_act = 1;
      }

      console.log("11111111-gd");
      console.log(th.data.sele_g);

      //-- 更新默认购买的数量 ---
      var mo_num = getApp().get_limit_qty(th.data.sele_g, this.data.is_act);
      this.setData({
        goodsInputNum: mo_num
      })
      this.setData({
        mo_num: mo_num
      })
    },
    //获取促销活动的组合
    add_cx_prom_group(data) {
      var th = this;
      getApp().getConfig2(function (e) {
        //需要读者系统顺序
        var json_d = JSON.parse(e.switch_list);
        var auto_promote_sale = json_d.auto_promote_sale;
        if (auto_promote_sale) {
          var auto_promote_sale = auto_promote_sale.split(',');
          var fd = auto_promote_sale.indexOf(data.prom_type + '');
          data.sort = fd;
        } else {
          data.sort = data.prom_type;
        }

        var fdix = th.data.cx_prom_group.findIndex(function (em) {
          return em.prom_type == data.prom_type
        })

        if (fdix > -1) {
          th.data.cx_prom_group.splice(fdix, 1);
        }

        th.data.cx_prom_group.push(data);

        //-- 排序一下 --
        function comp(a, b) {
          return a.sort - b.sort; //升序
        }
        var ppdata = th.data.cx_prom_group;
        //使用sort排序
        ppdata.sort(comp);

        th.setData({
          cx_prom_group: ppdata
        })

      })
    },
    find_lock_num(pick_id, lock) {
      var lock_num = 0;
      if (!lock) return 0;
      if (lock.length < 0) return 0;
      for (var i in lock) {
        if (pick_id == lock[i].pickupId) {
          lock_num += lock[i].outQty;
        }
      }
      return lock_num;
    },
    //--- 获取默认的促销活动的默认活动 ---
    check_prom_custom(ind) {
      if (ind) {
        if (!this.data.cx_prom_group.length) return 0;
      } else {
        if (!this.data.cx_prom_group.length) return {
          prom_type: 0,
          id: 0
        };
      }

      var prom = null;
      prom = JSON.parse(JSON.stringify(this.data.cx_prom_group[0]));

      //-- 要判断有没有超出限购 --
      if (prom.prom_type == 3 && prom.is_yh_out_limit) {
        if (this.data.cx_prom_group.length > 1) {
          prom = this.data.cx_prom_group[1];
        } else {
          prom.prom_type = 0;
          prom.id = 0;
        }
      }

      if (ind) {
        return prom.prom_type;
      }
      return prom;
    },
    // 选择门店
    choice_store: function (ee) {
      var th = this;
      var ind = ee.currentTarget.dataset.ind;
      var bconfig = th.data.bconfig;
      this.setData({
        keyword: ''
      })
      //--先判断会员状态--
      var user_info = getApp().globalData.userInfo;
      if (user_info == null || user_info.mobile == undefined || user_info.mobile == "" || user_info.mobile == null) {
        wx.navigateTo({
          url: '/packageE/pages/togoin/togoin',
        })
        return false;
      }


      //如果开启了,则不在选择门店
      if (this.data.sys_switch.is_pricing_open_store && getApp().globalData.pk_store) {
        return false;
      }

      if (!th.data.only_pk && !th.data.def_pickpu_list && !th.data.change) {
        // getApp().confirmBox("门店库存不足", null, 25000, !1);
        wx.showToast({
          title: '门店库存不足',
          icon: 'none',
        });
        return false;
      }
      th.data.change = 0;

      if (th.data.only_pk && !th.data.only_pk.length) {
        // getApp().confirmBox("门店库存不足", null, 25000, !1);
        wx.showToast({
          title: '门店库存不足',
          icon: 'none',
        });
        return false;
      }
      if (th.data.def_pickpu_list && !th.data.def_pickpu_list.length) {
        // getApp().confirmBox("门店库存不足", null, 25000, !1);
        wx.showToast({
          title: '门店库存不足',
          icon: 'none',
        });
        return false;
      }

      //如果开启了,则不在选择门店
      if (th.data.sys_switch.is_pricing_open_store && getApp().globalData.pk_store) {
        return false;
      }



      if (bconfig && bconfig.is_sort_storage) {
        wx.getLocation({
          type: 'gcj02',
          success: function (res) {

            th.data.lat = res.latitude;
            th.data.lon = res.longitude;
            th.data.is_get_local_ok = 1;
            th.setData({
              is_gps: 1
            });
            //th.onShow();
            th.get_sto(th.data.is_normal);
          },
          fail: function (res) {



            //th.onShow();
            th.data.is_get_local_ok = 1;
            th.get_sto(th.data.is_normal);
            if (res.errCode == 2) {
              th.setData({
                is_gps: 0
              });
              if (th.data.is_gps == 0) {
                getApp().confirmBox("请开启GPS定位", null, 25000, !1);
              }
            } else {
              th.setData({
                is_gps: "3"
              });
            }

          }
        })
      } else {
        th.data.is_get_local_ok = 1;
        th.get_sto(th.data.is_normal);
      }

      if (ind != undefined && ind != null) {
        this.setData({
          open_ind_store: ind,
          store: 1,
          openSpecModal: !1,
          openSpecModal_pt: !1,
          openSpecModal_flash_normal: !1,
        })
      } else {
        this.setData({
          store: 1,
          openSpecModal: !1,
          openSpecModal_pt: !1,
          openSpecModal_flash_normal: !1

        })
      }
    },

    //关闭选择门店
    close_popup: function (e) {
      var th = this;
      this.setData({
        store: 0,
        choice_sort_store: 0,
        sort_store: 0,
        fir_pick_index: 0,
        sec_pick_index: 0
      })

      var openindstore = this.data.open_ind_store;
      if (openindstore == 1) {
        th.setData({
          openSpecModal: !0,
          openSpecModal_ind: openindstore,
        });
      } else if (openindstore == 2) {
        th.setData({
          openSpecModal: !0,
          openSpecModal_ind: openindstore,
        });
      } else if (openindstore == 4) { //4就是拼团
        th.setData({
          openSpecModal_pt: 1, //打开拼团购买界面
          store: 0, //关闭门店
          choice_sort_store: 0, //关闭门店2级
          sort_store: 0, //关闭门店2级
        });
      } else {
        th.setData({
          store: 0,
          choice_sort_store: 0,
          sort_store: 0
        })
      }


    },
    choose_for_store_fir: function (e) {
      var index_c = e.currentTarget.dataset.ind;
      var th = this;
      th.setData({
        fir_pick_index: index_c
      })

    },
    //选择更多门店
    more_store: function () {
      this.setData({
        sort_store: 1
      });
    },
    check_guide(func) {
      var first_leader = getApp().globalData.first_leader;
      if (!first_leader) {
        func();
        return false;
      }
      if (this.data.is_geted_guide_pick) {
        func();
        return false;
      }

      if (getApp().globalData.guide_pick_id) {
        func();
        return false;
      }
      var th = this;
      getApp().request.promiseGet("/api/weshop/shoppingGuide/get/" + os.stoid + "/" + first_leader, {}).then(res => {
        if (res.data.code == 0) {
          getApp().globalData.guide_pick_id = res.data.data.pickup_id;
        }
        th.data.is_geted_guide_pick = 1;
        func();
      })
    },

    //确定def_pick为选择的门店
    sure_pick: function (e) {
      var th = this;
      var item = null;
      var openindstore = parseInt(th.data.open_ind_store);

      if (th.data.choice_sort_store == 0) {
        var index = th.data.fir_pick_index;
        if (th.data.is_show_sto_cat == 1) {
          item = th.data.def_pickpu_list[index];
        } else {
          item = th.data.only_pk ? th.data.only_pk[index] : null; //当没有门店分类的时候
        }

      } else {
        var index = th.data.sec_pick_index;
        item = th.data.sec_sto.s_arr[index];
      }

      if (!item) return false;

      if (item.is_no_dis_nor || (item.is_no_dis_act && !th.data.is_normal)) {
        wx.showToast({
          title: "该门店不可售,请选择其他门店",
          icon: 'none',
          duration: 2000
        });
        return false;
      }


      if (!th.data.sele_g) return false;
      //判断门店的配送方式是不是匹配
      var g_distr_type = th.data.sele_g.distr_type;
      if (item.distr_type != 0 && g_distr_type != 0 && item.distr_type != g_distr_type) {
        wx.showToast({
          title: "门店配送方式不匹配,请选择其他门店",
          icon: 'none',
          duration: 2000
        });
        return false;
      }

      //--回调函数的用法--
      th.check_the_pick(item, function () {
        th.setData({
          def_pick_store: item,
          sto_sele_name: item.pickup_name,
          sto_sele_id: item.pickup_id,
          sto_sele_distr: item.distr_type,
          store: 0,
          choice_sort_store: 0,
          fir_pick_index: 0
        });

        switch (openindstore) {
          case 1:
            th.setData({
              openSpecModal: !0,
              openSpecModal_ind: openindstore,
            });
            break;
          case 2:
            th.setData({
              openSpecModal: !0,
              openSpecModal_ind: openindstore,
            });
            break;
          case 4:
            th.setData({
              openSpecModal_pt: 1, //打开拼团购买界面
              store: 0, //关闭门店
              choice_sort_store: 0, //关闭门店2级
              sort_store: 0, //关闭门店2级
            });
            break;
          case 5:
            th.setData({
              openSpecModal_flash_normal: 1, //打开拼团购买界面
              store: 0, //关闭门店
              choice_sort_store: 0, //关闭门店2级
              sort_store: 0, //关闭门店2级
            });
            break;
          default:
            th.setData({
              store: 0,
              choice_sort_store: 0,
              sort_store: 0
            })
            break
        }

        //如果商品没有其他活动,要取一下线下价格
        th.get_off_price();
      })
    },
    //---点击二级之后的选择---
    choose_for_store: function (e) {
      var index_c = e.currentTarget.dataset.ind;
      var th = this;
      th.setData({
        sec_pick_index: index_c,
        fir_pick_index: index_c
      })

    },
    //把选择的门店设置成默认的门店def_pick
    set_def_pick: function (e) {
      var th = this;
      var item = null;
      if (th.data.choice_sort_store == 0) {
        var index = th.data.fir_pick_index;
        if (th.data.is_show_sto_cat == 1) {
          item = th.data.def_pickpu_list[index];
        } else {
          item = th.data.only_pk ? th.data.only_pk[index] : null; //当没有门店分类的时候
        }
      } else {
        var index = th.data.sec_pick_index;
        item = th.data.sec_sto.s_arr[index];
      }

      if (!item) return false;

      //判断门店的配送方式是不是匹配
      var g_distr_type = th.data.sele_g.distr_type;
      if (item.distr_type != 0 && g_distr_type != 0 && item.distr_type != g_distr_type) {
        wx.showToast({
          title: "门店配送方式不匹配",
          icon: 'none',
          duration: 2000
        });
        return false;
      }

      //先设置之前,要判断是不是有库存
      th.check_the_pick(item, function () {
        var store_id = o.stoid;
        var user_id = getApp().globalData.user_id;
        var def_pickup_id = item.pickup_id;

        getApp().request.put('/api/weshop/users/update', {
          data: {
            user_id: user_id,
            def_pickup_id: def_pickup_id
          },
          success: function (res) {
            if (res.data.code == 0) {
              if (th.data.choice_sort_store == 0) th.setData({
                fir_pick_index: 0
              });
              getApp().globalData.pk_store = item;
            } else {
              //s.showWarning("设置默认门店地址失败", null, 500, !1);
              getApp().my_warnning("设置默认门店地址失败", 0, th)
            }

          }
        });

        th.setData({
          def_pick_store: item,
          sto_sele_name: item.pickup_name,
          sto_sele_id: item.pickup_id,
          sto_sele_distr: item.distr_type,
          store: 0,
          choice_sort_store: 0
        });

        var openindstore = th.data.open_ind_store;
        if (openindstore == 1) {
          th.setData({
            openSpecModal: !0,
            openSpecModal_ind: openindstore,
            store: 0,
            choice_sort_store: 0,
            sort_store: 0,
          });
        } else if (openindstore == 2) {
          th.setData({
            openSpecModal: !0,
            openSpecModal_ind: openindstore,
            store: 0,
            choice_sort_store: 0,
            sort_store: 0,
          });
        } else if (openindstore == 4) { //4就是拼团
          th.setData({
            openSpecModal_pt: 1, //打开拼团购买界面
            store: 0, //关闭门店
            choice_sort_store: 0, //关闭门店2级
            sort_store: 0, //关闭门店2级
          });
        } else {
          th.setData({
            store: 0,
            choice_sort_store: 0,
            sort_store: 0,
          })
        }

        //如果商品没有其他活动,要取一下线下价格
        th.get_off_price();

      })
    },


    get_user_store() {

      var th = this;
      var that = this;
      //--获取用户的默认门店
      getApp().get_user_store(function (e) {
        if (!e) {
          th.data.fir_def_store = {}; //赋值空对象
          return false;
        }
        if (getApp().globalData.is_dj_pk) th.setData({
          has_def: 1
        });

        var ee = JSON.parse(JSON.stringify(e));

        //--定时器推迟一下--
        var appd = getApp().globalData;
        w_time = setInterval(function () {
          if (that.data.is_get_local_ok == 0) return false;
          if (!that.data.sele_g) return false;
          if (th.data.fir_goods) var g_distr_type = th.data.fir_goods.distr_type;
          //--如果默认门店的配送方式不对,就不能被选择,这里不控制,如果不一样,就说明配送方式不对--
          if (ee.distr_type != 0 && g_distr_type != 0 && ee.distr_type != g_distr_type) {
            ee.is_no_dis = 1;
          }

          //-- 如果有指定门店的时候,pickup_ids是经过判断是不是普通商品后才会有的 --
          if (th.data.sele_g && th.data.sele_g.pickup_ids && th.data.prom_type == 0) {
            var idx = th.data.sele_g.pickup_ids.findIndex(function (e) {
              return e.pickup_id == ee.pickup_id;
            })
            if (idx < 0) {
              ee.is_no_dis_nor = 1;
            }
          }

          clearInterval(w_time);
          var distance = null;
          var e = JSON.parse(JSON.stringify(ee));

          //如果有开启近距离的话,同时距离优不一样了
          if (that.data.lat != null) {
            //如果经纬度有变化的话
            if (e && appd.lat == that.data.lat && appd.lon == that.data.lon && e.distance > 0) {
              that.set_def_storage(e);
            } else {
              //要用接口是获取距离,js的计算不准
              getApp().request.promiseGet("/api/weshop/pickup/list", {
                data: {
                  store_id: os.stoid,
                  pickup_id: e.pickup_id,
                  lat: th.data.lat,
                  lon: th.data.lon,
                  isstop: 0,
                  is_pos: 1
                },
              }).then(res => {
                if (res.data.code == 0) {
                  e = res.data.data.pageData[0];
                  if (e) {
                    e.is_no_dis = ee.is_no_dis;
                    appd.pk_store = e;
                    that.set_def_storage(e);
                  }

                }
              })
            }
            //e.distance = distance;
            appd.lat = that.data.lat;
            appd.lon = that.data.lon;

          } else {
            if (e) {
              e.distance = null;
              that.set_def_storage(e);
            }
          }
        }, 200)

      });
    },
    //如果开启线下库存,已经急速库存才会使用
    check_the_pick(item, func) {
      var th = this;
      var goodsinfo = th.data.sele_g;
      var erpwareid = goodsinfo.erpwareid;
      var plist = null;
      var lock = 0;

      //---如果是活动的时候,同时不是普通购买---
      if (getApp().is_virtual(th.data.sele_g) || th.data.sele_g.whsle_id || ([1, 2, 4, 6, 8, 9].indexOf(th.data.prom_type) > -1 && !th.data.is_normal)) {
        func();
        return false;
      }

      if (this.data.sales_rules == 1) {
        func();
      } else {
        // if (plist && plist.CanOutQty - lock > 0) {
        //     item.CanOutQty = plist.CanOutQty - lock;
        //     func();
        //     return false;
        // }
        this.check_CanOutQty(goodsinfo, item, function (CanOutQty) {

          // let str = item.pickup_name + '库存不足!';
          if (!CanOutQty) {
            wx.showToast({
              title: item.pickup_name + '库存不足!',
              icon: 'none',
            });
            return false;
          }
          item.CanOutQty = CanOutQty;
          func();

        });

      }
    },
    //----获取线下价格-------
    get_off_price() {
      var th = this;
      //没有开启就返回
      if (!th.data.is_open_offline) return false;
      //先看下购买的功能有没有到期
      getApp().request.promiseGet("/store/storemoduleendtime/page?store_id=" + os.stoid + "&type=6", {}).then(res => {
        //未购买
        if (res.data.code != 0 || !res.data.data || !res.data.data.pageData || !res.data.data.pageData.length) {
          return false;
        } else {
          //已经过期
          var item = res.data.data.pageData[0];
          if (item.end_time < ut.gettimestamp()) {
            return false;
          }
        }


        var cur_goods = this.data.sele_g;
        var cur_price = cur_goods.shop_price;
        if (th.data.card_field && cur_goods[th.data.card_field] > 0) {
          cur_price = cur_goods[th.data.card_field];
        }

        var user_info = getApp().globalData.userInfo;
        //获取一下接口,判断是不是有线下接口,必须是普通商品,全局优惠活动也是不行
        if (cur_goods.prom_type == 0 && !this.data.prom_goods) {
          cur_goods.offline_price = null;
          //如果没有门店,不用计算线下价格
          var def_pick_store = this.data.def_pick_store;
          if (!def_pick_store) return false;
          getApp().request.get("/api/weshop/goods/listWarePrice", {
            data: {
              VIPId: encodeURIComponent(user_info.erpvipid),
              store_id: os.stoid,
              PickupId: def_pick_store.pickup_id,
              WareIds: encodeURIComponent(cur_goods.erpwareid)
            },
            success: function (res) {
              if (res.data.code == 0 && res.data.data && res.data.data.length > 0) {
                var datalist = res.data.data;
                if (datalist[0].WarePrice < cur_price) {
                  cur_goods.offline_price = datalist[0].WarePrice; //存储线下活动的价格
                  cur_goods.pricing_type = datalist[0].PriceType; //存储线下活动的类型
                }
              }
              th.setData({
                sele_g: cur_goods
              });
            }

          })
        }

      })


    },
    //--- 设置一下默认库存的数量 ----
    set_def_storage(ee) {
      var that = this,
        th = this;
      getApp().getConfig2(function (e) {
        var sales_rules = e.sales_rules;
        if (sales_rules >= 2 && [1, 2, 4, 6, 8, 9].indexOf(th.data.prom_type) == -1 && !th.data.sele_g.whsle_id) {
          getApp().waitfor2(that, "wait_for_user_store", "fir_goods", function () {
            var lock = 0,
              plist = null;
            var gd = that.data.fir_goods;
            //先读取门店的lock,采用链式写法,少用await
            // getApp().request.promiseGet("/api/weshop/order/ware/lock/page", {
            //     data: {
            //         store_id: os.stoid,
            //         wareId: that.data.fir_goods.goods_id,
            //         storageId: ee.pickup_id,
            //         pageSize: 1000
            //     }
            // }).then(res => {
            //     if (res.data.code == 0 && res.data.data.total > 0) {
            //         for (var i in res.data.data.pageData)
            //             lock += res.data.data.pageData[i].outQty
            //     }
            //     //---通过接口获取门店的线下库存信息--
            //     return getApp().request.promiseGet("/api/weshop/goods/getWareStorages", {
            //         data: {
            //             storageNos: ee.pickup_no,
            //             wareIds: encodeURIComponent(th.data.data.erpwareid),
            //             storeId: os.stoid
            //         }
            //     })
            // }).then(res => {
            //     if (res.data.code == 0 && res.data.data.total > 0) {
            //         plist = res.data.data.pageData[0];
            //     } else {
            //         wx.showToast({
            //             title: '库存不足,请更换其他门店',
            //             icon: 'none',
            //         });
            //     }
            //
            //     if (plist && plist.CanOutQty - lock > 0) {
            //         ee.CanOutQty = plist.CanOutQty - lock;
            //     } else {
            //         ee.CanOutQty = 0;
            //     }
            //     //--给门店赋值线下库存--
            //     that.data.fir_def_store = ee;
            //     that.setData({
            //         def_pick_store: ee,
            //         sto_sele_name: ee.pickup_name,
            //         sto_sele_id: ee.pickup_id,
            //         sto_sele_distr: ee.distr_type
            //     })
            // })
            //最新的获取线下门店库存
            th.check_CanOutQty(gd, ee, function (CanOutQty) {
              ee.CanOutQty = CanOutQty;
              //--给门店赋值线下库存--
              that.data.fir_def_store = ee;
              that.setData({
                def_pick_store: ee,
                sto_sele_name: ee.pickup_name,
                sto_sele_id: ee.pickup_id,
                sto_sele_distr: ee.distr_type
              })
            })


          })
        } else {
          that.data.fir_def_store = ee;
          that.setData({
            def_pick_store: ee,
            sto_sele_name: ee.pickup_name,
            sto_sele_id: ee.pickup_id,
            sto_sele_distr: ee.distr_type
          })
        }
      })

    },
    wait_for_store_config: function () {
      var th = this;
      //----获取系统参数-----
      getApp().getConfig2(function (e) {
        th.setData({
          bconfig: e,
        });
      })
      t_time = setInterval(function () {


        if (th.data.bconfig == null) false;
        var e = th.data.bconfig;
        if (e && e.is_sort_storage) {


          wx.getLocation({
            type: 'gcj02',
            success: function (res) {
              th.data.lat = res.latitude;
              th.data.lon = res.longitude;
              th.data.is_get_local_ok = 1;
            },
            fail: function (res) {
              if (res.errCode == 2) {
                th.setData({
                  is_gps: 0
                });
                if (th.data.is_gps == 0) {
                  getApp().confirmBox("请开启GPS定位", null, 10000, !1);
                }

              } else {
                th.setData({
                  is_gps: "3"
                });
              }

              th.data.is_get_local_ok = 1;
            }
          })
        } else {
          th.data.is_get_local_ok = 1;
        }
        clearInterval(t_time);
      }, 500)
    },
    //获取搜索门店输入的值 
    input_store: function (e) {
      this.setData({
        keyword: e.detail.value
      })
    },
    //搜索门店
    searchfn() {
      let choice_sort_store = this.data.choice_sort_store
      if (choice_sort_store == 0) { //全局搜索
        let all_pick_list = this.data.all_pick_list
        let def_pickpu_list = this.data.def_pickpu_list
        let keyword = this.data.keyword
        if (keyword) {
          let arr = all_pick_list.filter(item => {
            let i = item.pickup_name.indexOf(keyword)
            if (i > -1) {
              return true
            } else {
              return false
            }
          })
          if (arr && arr.length > 0) {
            if (this.data.is_show_sto_cat == 1) {
              this.setData({
                def_pickpu_list: arr
              })
            } else {
              this.setData({
                only_pk: arr
              })
            }
          } else {
            wx.showToast({
              title: '没有搜索到门店',
              icon: 'none',
              duration: 2000
            })
          }
        } else {
          if (this.data.is_show_sto_cat == 1) {
            this.setData({
              def_pickpu_list: all_pick_list.slice(0, 10)
            })
          } else {
            this.setData({
              only_pk: all_pick_list
            })
          }

        }
      } else { //分类下搜索
        let sec_i = this.data.sec_i
        let all_sto = this.data.all_sto
        let old_all_sto = this.data.old_all_sto
        if (!old_all_sto) {
          this.setData({
            old_all_sto: JSON.parse(JSON.stringify(all_sto))
          })
        }
        let sec_sto = this.data.sec_sto
        let sec_arr = this.data.old_all_sto[sec_i].s_arr
        let keyword = this.data.keyword
        let text = 'sec_sto.s_arr'
        if (keyword) {
          let arr = sec_arr.filter(item => {
            let i = item.pickup_name.indexOf(keyword)
            if (i > -1) {
              return true
            } else {
              return false
            }
          })
          if (arr && arr.length > 0) {
            this.setData({
              [text]: arr
            })
          } else {
            wx.showToast({
              title: '没有搜索到门店',
              icon: 'none',
              duration: 2000
            })
          }
        } else {
          if (this.data.old_all_sto) {
            this.setData({
              [text]: this.data.old_all_sto[sec_i].s_arr
            })
          } else {
            this.setData({
              [text]: all_sto[sec_i].s_arr
            })
          }
        }


      }
    },
    //---选择分类门店---
    choice_sort_store: function (e) {
      var index = e.currentTarget.dataset.index;
      var region_name = e.currentTarget.dataset.region;
      var item = this.data.all_sto[index];
      this.setData({
        region_name: region_name,
        sort_store: 0,
        choice_sort_store: 1,
        sec_sto: item,
        sec_i: index,
        sec_pick_index: 0
      });
    },
    // 返回按钮
    returns: function () {
      this.setData({
        sort_store: 0,
        choice_sort_store: 0
      });
    },
    pop_err_img: function (e) {
      var txt = e.currentTarget.dataset.errorimg;
      var ob = {};
      ob[txt] = this.data.iurl + "/miniapp/images/default_g_img.gif";
      this.setData(ob);
    },
    async getUserBuyPromNum(prom_id, is_zh) {
      var userInfo = getApp().globalData.userInfo;
      var url = `/api/weshop/ordergoods/getUserBuyPromNum?store_id=${os.stoid}&user_id=${userInfo.user_id}&prom_type=7&prom_id=${prom_id}`;
      let res = await getApp().request.promiseGet(url, {
        data: {}
      });
      let userbuynum = 0
      if (res.data.code == 0 && res.data.data) {
        userbuynum = res.data.data.userbuynum
      }
      this.setData({
        userbuynum
      })
      if (is_zh) this.data.user_zh_buy_num = userbuynum;
      // return userbuynum
    },
    //-- 根据ID拿出门店 --
    get_pick_from_list(pid) {
      var all_pick_list = this.data.all_pick_list;
      for (var i in all_pick_list) {
        var item = all_pick_list[i];
        if (item.pickup_id == pid) {
          return item;
        }
      }
    },

  }
})