prj-common-directive.js 340 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 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805
//自定义指令
/**
 * loading载入中指令。
 */
angular.module('ScheduleApp').directive(
    'loadingWidget',
    [
        'requestNotificationChannel',
        function(requestNotificationChannel) {
            return {
                restrict: 'A',

                compile: function(tElem, tAttrs) {
                    var loadingCount = 0;

                    return {
                        pre: function(scope, element, attr) {

                        },
                        post: function(scope, element, attr) {
                            // 初始隐藏loading界面
                            element.hide();

                            // 开始请求通知处理
                            requestNotificationChannel.onRequestStarted(scope, function(requestInfo) {
                                if (loadingCount == 0) {
                                    element.show();
                                }
                                loadingCount ++;
                                // TODO:以后在载入中显示requestInfo相关信息
                                console.log(requestInfo);
                                console.log(loadingCount);
                            });
                            // 请求结束通知处理
                            requestNotificationChannel.onRequestEnded(scope, function() {
                                loadingCount --;
                                if (loadingCount == 0) {
                                    element.hide();
                                }

                                console.log(loadingCount);
                            });
                        }
                    };
                }

            };

        }
    ]
);
/**
 * remoteValidation指令,远程数据验证验证,作为属性放在某个指令上,依赖与指令的ngModel。
 * 属性如下:
 * remotevtype(必须):验证类型(在service中有对应映射),如rvtype="xl"
 * remotevparam(必须):后端判定查询参数,如rvparam={{ {'xl.id_eq': '123'} | json }}
 *
 */
angular.module('ScheduleApp').directive('remoteValidation', [
    '$$SearchInfoService_g',
    function($$SearchInfoService_g) {
        return {
            restrict: "A", // 属性
            require: "^ngModel", // 依赖所属指令的ngModel
            compile: function(tElem, tAttrs) {
                // 验证属性
                if (!tAttrs["remotevtype"]) { // 验证类型
                    throw new Error("remotevtype属性必须填写");
                } else if (!$$SearchInfoService_g.validate[tAttrs["remotevtype"]]) {
                    throw new Error(!tAttrs["remotevtype"] + "验证类型不存在");
                }
                if (!tAttrs["remotevparam"]) { // 查询参数
                    throw new Error("remotevparam属性必须填写");
                }

                // 监听获取的数据
                var $watch_rvtype = undefined;
                var $watch_rvparam_obj = undefined;

                // 验证数据
                var $$internal_validate = function(ngModelCtrl, scope) {
                    if ($watch_rvtype && $watch_rvparam_obj) {
                        // 获取查询参数模版
                        var paramTemplate = $$SearchInfoService_g.validate[$watch_rvtype].template;
                        if (!paramTemplate) {
                            throw new Error($watch_rvtype + "查询模版不存在");
                        }
                        // 判定如果参数对象不全,没有完全和模版参数里对应上,则不验证
                        var isParamAll = true;
                        for (var key in paramTemplate) {
                            if (key != "id" && !$watch_rvparam_obj[key]) { // id去掉
                                isParamAll = false;
                                break;
                            }
                        }
                        if (!isParamAll) {
                            ngModelCtrl.$setValidity('remote', true);
                        } else { // 开始验证
                            $$SearchInfoService_g.validate[$watch_rvtype].remote.do(
                                $watch_rvparam_obj,
                                function(result) {
                                    if (result.status == "SUCCESS") {
                                        ngModelCtrl.$setValidity('remote', true);
                                    } else {
                                        ngModelCtrl.$setValidity('remote', false);
                                        scope.$remote_msg = result.msg;
                                    }
                                },
                                function(result) {
                                    ngModelCtrl.$setValidity('remote', true);
                                }
                            );
                        }
                    }
                };

                return {
                    pre: function(scope, element, attr) {

                    },

                    post: function(scope, element, attr, ngModelCtrl) {
                        /**
                         * 监控验证类型属性变化。
                         */
                        attr.$observe("remotevtype", function(value) {
                            if (value && value != "") {
                                $watch_rvtype = value;
                                $$internal_validate(ngModelCtrl, scope);
                            }
                        });
                        /**
                         * 监控查询结果属性变化。
                         */
                        attr.$observe("remotevparam", function(value) {
                            if (value && value != "") {
                                //if (!ngModelCtrl.$dirty) { // 没有修改过模型数据,不验证
                                //    return;
                                //}
                                $watch_rvparam_obj = JSON.parse(value);
                                $$internal_validate(ngModelCtrl, scope);
                            }
                        });
                    }
                };
            }
        }
    }
]);

/**
 * remoteValidatiot2指令,远程数据验证验证,作为属性放在某个指令上,依赖与指令的ngModel(专门用于时刻表sheet验证)。
 * 属性如下:
 * remotevtype(必须):验证类型(在service中有对应映射),如rvtype="xl"
 * remotevparam(必须):后端判定查询参数,如rvparam={{ {'xl.id_eq': '123'} | json }}
 *
 */
angular.module('ScheduleApp').directive('remoteValidationt2', [
    '$$SearchInfoService_g',
    function($$SearchInfoService_g) {
        return {
            restrict: "A", // 属性
            require: "^ngModel", // 依赖所属指令的ngModel
            compile: function(tElem, tAttrs) {
                // 验证属性
                if (!tAttrs["remotevtype"]) { // 验证类型
                    throw new Error("remotevtype属性必须填写");
                } else if (!$$SearchInfoService_g.validate[tAttrs["remotevtype"]]) {
                    throw new Error(!tAttrs["remotevtype"] + "验证类型不存在");
                }
                if (!tAttrs["remotevparam"]) { // 查询参数
                    throw new Error("remotevparam属性必须填写");
                }

                // 监听获取的数据
                var $watch_rvtype = undefined;
                var $watch_rvparam_obj = undefined;

                // 验证数据
                var $$internal_validate = function(ngModelCtrl, scope) {
                    if ($watch_rvtype && $watch_rvparam_obj) {
                        // 获取查询参数模版
                        var paramTemplate = $$SearchInfoService_g.validate[$watch_rvtype].template;
                        if (!paramTemplate) {
                            throw new Error($watch_rvtype + "查询模版不存在");
                        }
                        // 判定如果参数对象不全,没有完全和模版参数里对应上,则不验证
                        var isParamAll = true;
                        for (var key in paramTemplate) {
                            if (!$watch_rvparam_obj[key]) {
                                isParamAll = false;
                                break;
                            }
                        }
                        if (!isParamAll) {
                            ngModelCtrl.$setValidity('remote', true);
                        } else { // 开始验证
                            $$SearchInfoService_g.validate[$watch_rvtype].remote.do(
                                $watch_rvparam_obj,
                                function(result) {
                                    if (result.status == "SUCCESS") {
                                        ngModelCtrl.$setValidity('remote', true);
                                    } else {
                                        ngModelCtrl.$setValidity('remote', false);
                                        scope.ctrl.ttInfoDetailManageForForm.sheetvaliddesc = result.msg;
                                    }
                                },
                                function(result) {
                                    alert("出错拉");
                                    ngModelCtrl.$setValidity('remote', true);
                                }
                            );
                        }
                    }
                };

                return {
                    pre: function(scope, element, attr) {

                    },

                    post: function(scope, element, attr, ngModelCtrl) {
                        /**
                         * 监控验证类型属性变化。
                         */
                        attr.$observe("remotevtype", function(value) {
                            if (value && value != "") {
                                $watch_rvtype = value;
                                $$internal_validate(ngModelCtrl, scope);
                            }
                        });
                        /**
                         * 监控查询结果属性变化。
                         */
                        attr.$observe("remotevparam", function(value) {
                            if (value && value != "") {
                                //if (!ngModelCtrl.$dirty) { // 没有修改过模型数据,不验证
                                //    return;
                                //}
                                $watch_rvparam_obj = JSON.parse(value);
                                $$internal_validate(ngModelCtrl, scope);
                            }
                        });
                    }
                };
            }
        }
    }
]);

/**
 * remoteValidationt3 远程验证指令(监控依赖的model变化)
 * 属性如下:
 * remotevtype(必须):验证类型(在service中有对应映射),如rvtype="xl"
 * remotemodel(必须):关联的model
 * remotemodelcol(必须):关联的model属性
 */
angular.module('ScheduleApp').directive(
    'remoteValidation3',
    [
        '$$SearchInfoService_g',
        '$q',
        function($$SearchInfoService_g, $q) {
            return {
                restrict: 'A', // 属性
                require: '^ngModel', // 依赖所属指令的ngModel
                compile: function(tElem, tAttrs) {
                    var remotevtype_attr = tAttrs['remotevtype'];
                    var remotemodel_attr = tAttrs['remotemodel'];
                    var remotemodelcol_attr = tAttrs['remotemodelcol'];
                    if (!remotevtype_attr) {
                        throw new Error("remotevtype属性必须填写");
                    }
                    if (!remotemodel_attr) {
                        throw new Error("remotemodel属性必须填写");
                    }
                    if (!remotemodelcol_attr) {
                        throw new Error("remotemodelcol属性必须填写");
                    }

                    return {
                        pre: function(scope, element, attr) {

                        },

                        post: function(scope, element, attr, ngModelCtrl) {
                            ngModelCtrl.$asyncValidators.remote =
                                function(modelValue, viewValue) {
                                    var deferred = $q.defer();

                                    // 远端验证service
                                    var param = JSON.parse(attr['remotemodel']);
                                    console.log(param);
                                    param[remotemodelcol_attr] = modelValue;
                                    $$SearchInfoService_g.validate[remotevtype_attr].remote.do(
                                        param,
                                        function(result) {
                                            if (result.status == "SUCCESS") {
                                                deferred.resolve();
                                            } else {
                                                scope.$remote_msg = result.msg;
                                                deferred.reject();
                                            }
                                        },
                                        function(result) {
                                            deferred.reject();
                                        }
                                    );

                                    return deferred.promise;
                                };
                        }
                    };
                }
            }
        }
    ]
);
/**
 * remoteWarn指令:远程验证警告,作为属性放在某个指令上。
 *                TODO:暂时没法整合到form上,类似$error这样
 * 属性如下:
 * remotewtype(必须):验证类型(在service中有对应映射),如rvtype="xl"
 * remotewparam(必须):后端判定查询参数,如rvparam={{ {'xl.id_eq': '123'} | json }}
 * remotewmsgprop(必须):警告信息属性名
 */
angular.module('ScheduleApp').directive('remoteWarn', [
    '$$SearchInfoService_g',
    function($$SearchInfoService_g) {
        return {
            restrict: "A", // 属性
            required: "^ngModel", // 依赖所属指令的ngModel
            compile: function(tElem, tAttrs) {
                // 验证属性
                if (!tAttrs["remotewtype"]) { // 验证类型
                    throw {msg : "remotewtype属性必须填写"};
                }
                if (!$$SearchInfoService_g.validate[tAttrs["remotewtype"]]) {
                    throw {msg : tAttrs["remotevtype"] + "验证类型不存在"};
                }
                if (!tAttrs["remotewparam"]) { // 查询参数
                    throw {msg : "remotevparam属性必须填写"};
                }
                if (!tAttrs["remotewmsgprop"]) { // 警告信息属性名
                    throw {msg : "remotewmsgprop属性必须填写"}
                }

                // 监听获取的数据
                var $watch_rvtype = undefined;
                var $watch_rvparam_obj = undefined;
                var $remotewmsgprop = undefined;

                // 验证数据
                var $$internal_validate = function(ngModelCtrl, scope) {
                    if ($watch_rvtype && $watch_rvparam_obj && $remotewmsgprop) {
                        // 获取查询参数模版
                        var paramTemplate = $$SearchInfoService_g.validate[$watch_rvtype].template;
                        if (!paramTemplate) {
                            throw {msg : $watch_rvtype + "查询模版不存在"};
                        }

                        // 判定如果参数对象不全,没有完全和模版参数里对应上,则不验证
                        var isParamAll = true;
                        for (var key in paramTemplate) {
                            if (key != "id" && !$watch_rvparam_obj[key]) { // id去掉
                                isParamAll = false;
                                break;
                            }
                        }

                        if (!isParamAll) {
                            scope["ctrl"][$remotewmsgprop] = undefined;
                        } else { // 开始验证警告
                            $$SearchInfoService_g.validate[$watch_rvtype].remote.do(
                                $watch_rvparam_obj,
                                function(result) {
                                    if (result.status == "SUCCESS") {
                                        scope["ctrl"][$remotewmsgprop] = undefined;
                                    } else {
                                        scope["ctrl"][$remotewmsgprop] = result.msg;
                                    }
                                },
                                function(result) {
                                    scope["ctrl"][$remotewmsgprop] = undefined;
                                }
                            );
                        }
                    }

                };

                return {
                    pre: function(scope, element, attr) {

                    },

                    post: function(scope, element, attr, ngModelCtrl) {
                        /**
                         * 监控验证类型属性变化。
                         */
                        attr.$observe("remotewtype", function(value) {
                            if (value && value != "") {
                                $watch_rvtype = value;
                                $$internal_validate(ngModelCtrl, scope);
                            }
                        });

                        /**
                         * 监控查询结果属性变化。
                         */
                        attr.$observe("remotewparam", function(value) {
                            if (value && value != "") {
                                $watch_rvparam_obj = JSON.parse(value);
                                $$internal_validate(ngModelCtrl, scope);
                            }
                        });

                        /**
                         * 监控警告信息属性名变化。
                         */
                        attr.$observe("remotewmsgprop", function(value) {
                            if (value && value != "") {
                                $remotewmsgprop = value;
                                $$internal_validate(ngModelCtrl, scope);
                            }
                        });

                    }
                };
            }
        };
    }
]);

angular.module('ScheduleApp').directive("saSelect", ['$timeout', function($timeout) {
    return {
        restrict: 'E',
        templateUrl: '/pages/scheduleApp/module/common/dts1/select/saSelectTemplate.html',
        scope: {
            model: "="
        },
        controllerAs: "$saSelectCtrl",
        bindToController: true,
        controller: function() {
            var self = this;
            self.datas = []; // 关联的字典数据,内部格式 {code:{值},name:{名字}}
        },
        /**
         * 此阶段可以改dom结构,此时angular还没扫描指令,
         * 这里就可以动态添加其他angularjs的指令字符串,如required指令字符串。
         * @param tElem
         * @param tAttrs
         * @returns {{pre: Function, post: Function}}
         */
        compile: function(tElem, tAttrs) {
            // 确定是否使用angularjs required验证
            // 属性 required
            // 如果没有填写,内部不添加验证,如果填写了,并且等于true添加验证,否则不添加
            var required_attr = tAttrs["required"];
            if (required_attr) {
                if (required_attr == "true") {
                    // 添加required属性指令
                    tElem.find("ui-select").attr("required", "");
                } else {
                    // 不等于true,不添加required属性指令
                }
            } else {
                // 不添加required属性指令
            }

            //console.log("saSelect" + ":compile = >" + tElem.html());

            return {
                pre: function(scope, element, attr) {
                    // TODO:
                },
                /**
                 * 相当于link函数。
                 *
                 * 重要属性如下:
                 * model 是绑定外部值。
                 * dicgroup 字典组的类型
                 * name input name属性值
                 */
                post: function(scope, element, attr) {
                    // 1、获取属性
                    var dicgroup_attr = attr['dicgroup']; // 字典组的类型
                    var name_attr = attr['name']; // input name属性值
                    var dicname_attr = attr['dicname']; // model关联的字典名字段
                    var codename_attr = attr['codename']; // model关联的字典值字段
                    var placeholder_attr = attr['placeholder']; // select placeholder提示

                    // 系统的字典对象,使用dictionaryUtils类获取
                    var origin_dicgroup;
                    var dic_key; // 字典key

                    if (dicgroup_attr) { // 赋值指定的字典数据
                        origin_dicgroup = dictionaryUtils.getByGroup(dicgroup_attr);
                        for (dic_key in origin_dicgroup) {
                            var data = {}; // 重新组合的字典元素对象
                            if (dic_key == "true")
                                data.code = true;
                            else
                                data.code = dic_key;
                            data.name = origin_dicgroup[dic_key];
                            scope["$saSelectCtrl"].datas.push(data);
                        }
                    }

                    if (name_attr) {
                        scope["$saSelectCtrl"].nv = name_attr;
                    }
                    if (placeholder_attr) {
                        scope["$saSelectCtrl"].ph = placeholder_attr;
                    }

                    scope["$saSelectCtrl"].select = function($item) {
                        if (codename_attr) {
                            scope["$saSelectCtrl"].model[codename_attr] = $item.code;
                        }
                        if (dicname_attr) {
                            scope["$saSelectCtrl"].model[dicname_attr] = $item.name;
                        }
                    };

                    scope["$saSelectCtrl"].remove = function() {
                        if (codename_attr) {
                            scope["$saSelectCtrl"].model[codename_attr] = null;
                        }
                        if (dicname_attr) {
                            scope["$saSelectCtrl"].model[dicname_attr] = null;
                        }
                        scope["$saSelectCtrl"].cmodel = null;
                    };

                    $timeout(function() {
                        // 创建内部使用的绑定对象
                        var model_code = scope["$saSelectCtrl"].model[codename_attr];
                        scope["$saSelectCtrl"].cmodel = model_code;
                    }, 0);
                }
            }
        }
    };
}]);



angular.module('ScheduleApp').directive("saSelect2", [
    '$timeout', '$$SearchInfoService_g',
    function($timeout, $$searchInfoService_g) {
        return {
            restrict: 'E',
            templateUrl: '/pages/scheduleApp/module/common/dts1/select/saSelect2Template.html',
            scope: {
                model: "=" // 独立作用域,关联外部的模型对象
            },
            controllerAs: "$saSelectCtrl",
            bindToController: true,
            controller: function($scope) {
                var self = this;
                self.$$data = []; // 内部关联的数据
            },
            /**
             * 此阶段可以改dom结构,此时angular还没扫描指令,
             * 这里就可以动态添加其他angularjs的指令字符串,如required指令字符串。
             * @param tElem
             * @param tAttrs
             * @returns {{pre: Function, post: Function}}
             */
            compile: function(tElem, tAttrs) {
                // 1、获取此阶段使用的属性
                var $required_attr = tAttrs["required"]; // 用于和表单验证连接,指定成required="true"才有效。

                // 2、处理属性

                // 确定是否使用angularjs required验证
                // 属性 required
                // 如果没有填写,内部不添加验证,如果填写了,并且等于true添加验证,否则不添加
                if ($required_attr) {
                    if ($required_attr == "true") {
                        // 添加required属性指令
                        tElem.find("ui-select").attr("required", "");
                    } else {
                        // 不等于true,不添加required属性指令
                    }
                } else {
                    // 不添加required属性指令
                }

                //console.log("saSelect" + ":compile = >" + tElem.html());

                return {
                    pre: function(scope, element, attr) {
                        // TODO:
                    },
                    /**
                     * 相当于link函数。
                     *
                     * 重要属性如下:
                     * model 是绑定外部值。
                     * dicgroup 字典组的类型
                     * name input name属性值
                     */
                    post: function(scope, element, attr) {
                        // 1、获取此阶段使用的属性
                        var $name_attr = attr["name"]; // 表单验证时需要的名字
                        var $type_attr = attr["type"]; // 关联的那种数据值(xl/cl/ry)-> 对应线路信息/车辆信息/人员信息,后面有的继续加
                        var $modelcolname1_attr = attr["modelcolname1"]; // 关联的模型字段名字1(一般应该是编码字段)
                        var $modelcolname2_attr = attr["modelcolname2"]; // 关联的模型字段名字2(一般应该是名字字段)
                        var $datacolname1_attr = attr["datacolname1"]; // 内部数据对应的字段名字1(与模型字段1对应)
                        var $datacolname2_attr = attr["datacolname2"]; // 内部数据对应的字段名字2(与模型字段2对应)
                        var $showcolname_attr = attr["showcolname"]; // 下拉框显示的内部数据字段名
                        var $placeholder_attr = attr["placeholder"]; // select placeholder字符串描述

                        // 2、处理属性、转换成$saSelectCtrl内部使用的属性
                        if ($name_attr) {
                            scope["$saSelectCtrl"].$name_attr = $name_attr;
                        }
                        if ($placeholder_attr) {
                            scope["$saSelectCtrl"].$placeholder_attr = $placeholder_attr;
                        }
                        if ($showcolname_attr) {
                            scope["$saSelectCtrl"].$showcolname_attr = $showcolname_attr;
                        }

                        // 2-1、添加内部方法,根据type值,改变$$data的值
                        scope["$saSelectCtrl"].$$internal_data_change_fn = function() {
                            // 根据type属性动态载入数据
                            if ($type_attr) {
                                $$searchInfoService_g[$type_attr].list(
                                    {type: "all"},
                                    function(result) {
                                        scope["$saSelectCtrl"].$$data = [];
                                        for (var i = 0; i < result.length; i ++) {
                                            var data = {}; // data是result的一部分属性集合,根据配置来确定
                                            if ($datacolname1_attr) {
                                                data[$datacolname1_attr] = result[i][$datacolname1_attr];
                                            }
                                            if ($datacolname2_attr) {
                                                data[$datacolname2_attr] = result[i][$datacolname2_attr];
                                            }
                                            if ($showcolname_attr) {
                                                // 动态添加基于名字的拼音
                                                data[$showcolname_attr] = result[i][$showcolname_attr];
                                                if (data[$showcolname_attr]) {
                                                    data["fullChars"] = pinyin.getFullChars(result[i][$showcolname_attr]).toUpperCase(); // 全拼
                                                    data["camelChars"] = pinyin.getCamelChars(result[i][$showcolname_attr]); // 简拼
                                                }
                                            }
                                            if (data["fullChars"])
                                                scope["$saSelectCtrl"].$$data.push(data);
                                        }
                                    },
                                    function(result) {

                                    }
                                );
                            }
                        };

                        // 3、选择、删除事件映射模型和内部数据对应的字段
                        scope["$saSelectCtrl"].$select_fn_attr = function($item) {
                            if ($modelcolname1_attr && $datacolname1_attr) {
                                scope["$saSelectCtrl"].model[$modelcolname1_attr] = $item[$datacolname1_attr];
                            }
                            if ($modelcolname2_attr && $datacolname2_attr) {
                                scope["$saSelectCtrl"].model[$modelcolname2_attr] = $item[$datacolname2_attr];
                            }
                        };
                        scope["$saSelectCtrl"].$remove_fn_attr = function() {
                            if ($modelcolname1_attr) {
                                scope["$saSelectCtrl"].model[$modelcolname1_attr] = null;
                            }
                            if ($modelcolname2_attr) {
                                scope["$saSelectCtrl"].model[$modelcolname2_attr] = null;
                            }
                            scope["$saSelectCtrl"].$$cmodel = null; // 内部模型清空

                            scope["$saSelectCtrl"].$$internal_data_change_fn();
                        };

                        // 4、搜索事件
                        scope["$saSelectCtrl"].$refreshdata_fn_attr = function($search) {
                            //var fullChars = pinyin.getFullChars($search).toUpperCase();
                            //var camelChars = pinyin.getCamelChars($search);
                            //
                            //console.log(fullChars + " " + camelChars);
                            // TODO:事件暂时没用,放着以后再说
                        };

                        // 5、全部载入后,输入的
                        $timeout(function() {
                            // 创建内部使用的绑定对象,用于确认选中那个值
                            scope["$saSelectCtrl"].$$cmodel = scope["$saSelectCtrl"].model[$modelcolname1_attr];

                            scope["$saSelectCtrl"].$$internal_data_change_fn();
                        }, 0);
                    }
                }
            }
        };
    }
]);





/**
 * saSelect3指令
 * 属性如下:
 * model(必须):指定一个外部object,独立作用域,如:model=ctrl.employeeInfoForSave
 * name(必须):控件的名字
 * placeholder(可选):占位符字符串
 * dcvalue(必须):绑定的model字段值,如:dcvalue={{ctrl.employeeInfoForSave.xl.id}}
 * dcname(必须):绑定的model字段名,如:dcname=xl.id
 * icname(必须):内部与之对应的字段名,如:icname=code
 * dcname2(可选):其他需要赋值的model字段名2,如:dcname2=xl.name
 * icname2(可选):内部与之对应的字段名2,如:icname2=name
 * dcname3(可选):其他需要赋值的model字段名3,如:dcname2=xl.name
 * icname3(可选):内部与之对应的字段名3,如:icname2=name
 * icnames(必须):用于用于显示,以及简评处理的内部数据字段,如:icnames=name
 * required(可选):是否要用required验证
 * datatype(必须):业务数据类型,有字典类型,动态数据类型,暂时写的死点
 * mlp(可选):是否多级属性(这里假设外部model如果多级,内部model也是多级)
 *
 * 高级属性:
 * dataassociate(可选):数据源是否关联属性(内部数据随外部指定的参数变化而变化)
 * dataparam(可选):数据源关联的外部参数对象
 *
 */
angular.module('ScheduleApp').directive("saSelect3", [
    '$timeout',
    '$$SearchInfoService_g',
    function($timeout, $$searchInfoService_g) {
        return {
            restrict: 'E',
            templateUrl: '/pages/scheduleApp/module/common/dts1/select/saSelect3Template.html',
            scope: {
                model: "=" // 独立作用域,关联外部的模型object
            },
            controllerAs: "$saSelectCtrl",
            bindToController: true,
            controller: function($scope) {
                var self = this;
                self.$$data = []; // ui-select显示用的数据源
                self.$$data_real= []; // 内部真实的数据源
            },

            /**
             * 此阶段可以改dom结构,此时angular还没扫描指令,
             * 这里就可以动态添加其他angularjs的指令字符串,如required指令字符串。
             * @param tElem
             * @param tAttrs
             * @returns {{pre: Function, post: Function}}
             */
            compile: function(tElem, tAttrs) {
                // 获取所有的属性
                var $name_attr = tAttrs["name"]; // 控件的名字
                var $placeholder_attr = tAttrs["placeholder"]; // 占位符的名字
                var $dcname_attr = tAttrs["dcname"]; // 绑定的model字段名
                var $icname_attr = tAttrs["icname"]; // 内部与之对应的字段名
                var $dcname2_attr = tAttrs["dcname2"]; // 其他需要赋值的model字段名2
                var $icname2_attr = tAttrs["icname2"]; // 内部与之对应的字段名2
                var $dcname3_attr = tAttrs["dcname3"]; // 其他需要赋值的model字段名3
                var $icname3_attr = tAttrs["icname3"]; // 内部与之对应的字段名3

                var $icname_s_attr = tAttrs["icnames"]; // 用于用于显示,以及简评处理的内部数据字段
                var $datatype_attr = tAttrs["datatype"]; // 内部业务数据类型
                var $required_attr = tAttrs["required"]; // 是否需要required验证
                var $mlp_attr = tAttrs["mlp"]; // 是否多级属性
                var $dataassociate_attr = tAttrs["dataassociate"]; // 数据源是否关联属性

                // controlAs名字
                var ctrlAs = "$saSelectCtrl";

                // 数据源初始化标志
                var $$data_init = false;
                // 如果有required属性,添加angularjs required验证
                if ($required_attr != undefined) {
                    tElem.find("ui-select").attr("required", "");
                }

                // 由于有的属性是多级的如xl.name,所以要在compile阶段重写属性绑定属性定义
                // 原来的设置:{{$select.selected[$saSelectCtrl.$icname_s]}}
                tElem.find("ui-select-match").html("{{$select.selected" + "." + $icname_s_attr + "}}");
                // 原来的设置:item[$saSelectCtrl.$icname] as item in $saSelectCtrl.$$data
                tElem.find("ui-select-choices").attr("repeat", "item" + "." + $icname_attr + " as item in $saSelectCtrl.$$data");
                // 原来的设置:item[$saSelectCtrl.$icname_s]
                tElem.find("ui-select-choices span").attr("ng-bind", "item" + "." + $icname_s_attr);
                // 原来的设置:{{$saSelectCtrl.$name}}
                tElem.find("ui-select").attr("name", $name_attr);
                // 原来的设置:{{$saSelectCtrl.$placeholder}}
                tElem.find("ui-select-match").attr("placeholder", $placeholder_attr);

                return {
                    pre: function(scope, element, attr) {
                        // TODO:
                    },
                    /**
                     * 相当于link函数。
                     * @param scope
                     * @param element
                     * @param attr
                     */
                    post: function(scope, element, attr) {
                        // 添加选中事件处理函数
                        scope[ctrlAs].$$internal_select_fn = function($item) {
                            if ($dcname_attr && $icname_attr) {
                                if ($mlp_attr) {
                                    eval("scope[ctrlAs].model" + "." + $dcname_attr + " = $item" + "." + $icname_attr + ";");
                                } else {
                                    scope[ctrlAs].model[$dcname_attr] = $item[$icname_attr];
                                }
                            }
                            if ($dcname2_attr && $icname2_attr) {
                                if ($mlp_attr) {
                                    eval("scope[ctrlAs].model" + "." + $dcname2_attr + " = $item" + "." + $icname2_attr + ";");
                                } else {
                                    scope[ctrlAs].model[$dcname2_attr] = $item[$icname2_attr];
                                }
                            }
                            if ($dcname3_attr && $icname3_attr) {
                                if ($mlp_attr) {
                                    eval("scope[ctrlAs].model" + "." + $dcname3_attr + " = $item" + "." + $icname3_attr + ";");
                                } else {
                                    scope[ctrlAs].model[$dcname3_attr] = $item[$icname3_attr];
                                }
                            }
                        };

                        // 删除选中事件处理函数
                        scope[ctrlAs].$$internal_remove_fn = function() {
                            scope[ctrlAs].$$internalmodel = undefined;
                            if ($mlp_attr) {
                                eval("scope[ctrlAs].model" + "." + $dcname_attr + " = undefined;");
                            } else {
                                scope[ctrlAs].model[$dcname_attr] = undefined;
                            }

                            if ($dcname2_attr) {
                                if ($mlp_attr) {
                                    eval("scope[ctrlAs].model" + "." + $dcname2_attr + " = undefined;");
                                } else {
                                    scope[ctrlAs].model[$dcname2_attr] = undefined;
                                }
                            }
                            if ($dcname3_attr) {
                                if ($mlp_attr) {
                                    eval("scope[ctrlAs].model" + "." + $dcname3_attr + " = undefined;");
                                } else {
                                    scope[ctrlAs].model[$dcname3_attr] = undefined;
                                }
                            }
                        };

                        /**
                         * 内部方法,读取字典数据作为数据源。
                         * @param dicgroup 字典类型,如:gsType
                         * @param ccol 代码字段名
                         * @param ncol 名字字段名
                         */
                        scope[ctrlAs].$$internal_dic_data = function(dicgroup, ccol, ncol) {
                            var origin_dicgroup = dictionaryUtils.getByGroup(dicgroup);
                            var dic_key; // 字典key
                            // 清空内部数据
                            scope[ctrlAs].$$data_real = [];
                            for (dic_key in origin_dicgroup) {
                                var data = {}; // 重新组合的字典元素对象
                                if (dic_key == "true")
                                    data[ccol] = true;
                                else
                                    data[ccol] = dic_key;
                                data[ncol] = origin_dicgroup[dic_key];
                                scope[ctrlAs].$$data_real.push(data);
                            }
                            // 这里直接将$$data_real数据深拷贝到$$data
                            angular.copy(scope[ctrlAs].$$data_real, scope[ctrlAs].$$data);

                            console.log(scope[ctrlAs].$$data);
                        };

                        /**
                         * TODO:这个方法有性能问题,result一多就会卡一卡,之后再解决把
                         * 内部方法,读取字典数据作为数据源。
                         * @param result 原始数据
                         * @param dcvalue 传入的关联数据
                         */
                        scope[ctrlAs].$$internal_other_data = function(result, dcvalue) {
                            console.log("start=" + dcvalue);
                            // 清空内部数据
                            scope[ctrlAs].$$data_real = [];
                            scope[ctrlAs].$$data = [];
                            for (var i = 0; i < result.length; i ++) {
                                if ($icname_s_attr) {
                                    if ($mlp_attr) {
                                        if (eval("result[i]" + "." + $icname_s_attr)) {
                                            // 全拼
                                            result[i]["fullChars"] = pinyin.getFullChars(eval("result[i]" + "." + $icname_s_attr)).toUpperCase();
                                            // 简拼
                                            result[i]["camelChars"] = pinyin.getCamelChars(eval("result[i]" + "." + $icname_s_attr));
                                        }
                                    } else {
                                        if (result[i][$icname_s_attr]) {
                                            // 全拼
                                            result[i]["fullChars"] = pinyin.getFullChars(result[i][$icname_s_attr]).toUpperCase();
                                            // 简拼
                                            result[i]["camelChars"] = pinyin.getCamelChars(result[i][$icname_s_attr]);
                                        }
                                    }
                                }

                                if (result[i]["fullChars"]) { // 有拼音的加入数据源
                                    scope[ctrlAs].$$data_real.push(result[i]);
                                }

                            }
                            //console.log("start2");

                            // 数量太大取前10条记录作为显示
                            if (angular.isArray(scope[ctrlAs].$$data_real)) {
                                // 先迭代循环查找已经传过来的值
                                if (scope[ctrlAs].$$data_real.length > 0) {
                                    if (dcvalue) {
                                        for (var j = 0; j < scope[ctrlAs].$$data_real.length; j++) {
                                            if (scope[ctrlAs].$$data_real[j][$icname_attr] == dcvalue) {
                                                scope[ctrlAs].$$data.push(angular.copy(scope[ctrlAs].$$data_real[j]));
                                                break;
                                            }
                                        }
                                    }
                                }
                                // 在插入剩余的数据
                                for (var k = 0; k < scope[ctrlAs].$$data_real.length; k++) {
                                    if (scope[ctrlAs].$$data.length < 10) {
                                        if ($mlp_attr) {
                                            if (eval("scope[ctrlAs].$$data_real[k]" + "." + $icname_attr + " != dcvalue")) {
                                                scope[ctrlAs].$$data.push(angular.copy(scope[ctrlAs].$$data_real[k]));
                                            }
                                        } else {
                                            if (scope[ctrlAs].$$data_real[k][$icname_attr] != dcvalue) {
                                                scope[ctrlAs].$$data.push(angular.copy(scope[ctrlAs].$$data_real[k]));
                                            }
                                        }
                                    } else {
                                        break;
                                    }
                                }
                            }

                            //console.log("end");
                        };

                        /**
                         * 判定一个对象是否为空对象。
                         * @param Obj
                         */
                        scope[ctrlAs].$$internal_isEmpty_obj = function(obj) {
                            console.log(typeof obj);

                            if (typeof obj === "object" && !(obj instanceof Array)) {
                                for (var prop in obj) {
                                    if (obj.hasOwnProperty(prop)) {
                                        return false;
                                    }
                                }
                                return true;
                            } else {
                                throw "必须是对象";
                            }
                        };

                        // 刷新数据
                        scope[ctrlAs].$$internal_refresh_fn = function(search) {
                            // 绑定的model字段值,此属性是绑定属性,只能在link阶段获取
                            var $dcvalue_attr = attr["dcvalue"];

                            console.log("刷新数据:" + $dcvalue_attr);

                            if (!$$data_init) { // 只初始化$$data_real一次,重新载入页面才能重新初始化
                                if (dictionaryUtils.getByGroup($datatype_attr)) { // 判定是否字典类型数据源
                                    scope[ctrlAs].$$internal_dic_data(
                                        $datatype_attr, $icname_attr, $icname_s_attr);
                                    if ($dcvalue_attr) {
                                        scope[ctrlAs].$$internalmodel = $dcvalue_attr;
                                    }
                                } else { // 非字典类型数据源
                                    if (!$dataassociate_attr) {
                                        $$searchInfoService_g[$datatype_attr].list(
                                            {type: "all"},
                                            function(result) {
                                                //console.log("ok:" + $datatype_attr);
                                                scope[ctrlAs].$$internal_other_data(result, $dcvalue_attr);
                                                //console.log("ok2:" + $datatype_attr);
                                                if ($dcvalue_attr) {
                                                    scope[ctrlAs].$$internalmodel = $dcvalue_attr;
                                                }

                                                $$data_init = true;
                                            },
                                            function(result) {

                                            }
                                        );
                                    }
                                }
                            }

                            if ($$data_init) {
                                if (search && search != "") { // 有search值
                                    if (!dictionaryUtils.getByGroup($datatype_attr)) { // 其他数据源
                                        // 处理search
                                        console.log("search:" + search);

                                        scope[ctrlAs].$$data = [];
                                        for (var k = 0; k < scope[ctrlAs].$$data_real.length; k++) {
                                            var upTerm = search.toUpperCase();
                                            if (scope[ctrlAs].$$data.length < 10) {
                                                if (scope[ctrlAs].$$data_real[k].fullChars.indexOf(upTerm) != -1
                                                    || scope[ctrlAs].$$data_real[k].camelChars.indexOf(upTerm) != -1) {
                                                    scope[ctrlAs].$$data.push(angular.copy(scope[ctrlAs].$$data_real[k]));
                                                }
                                            } else {
                                                break;
                                            }
                                        }
                                    }
                                }

                            }

                        };










                        // TODO:

                        // dom全部载入后调用
                        $timeout(function() {
                            console.log("dom全部载入后调用");
                        }, 0);
                        // 监控dcvalue model值变换
                        attr.$observe("dcvalue", function(value) {
                                console.log("监控dc1 model值变换:" + value);
                                scope[ctrlAs].$$internalmodel = value;
                            }
                        );
                        // 监控获取数据参数变换
                        attr.$observe("dataparam", function(value) {
                                // 判定是否空对象
                                console.log(value);
                                var obj = JSON.parse(value);
                                var $dcvalue_attr = attr["dcvalue"];
                                if (!scope[ctrlAs].$$internal_isEmpty_obj(obj)) {
                                    console.log("dataparam:" + obj);

                                    //

                                    obj["type"] = "all";

                                    $$data_init = false;
                                    $$searchInfoService_g[$datatype_attr].list(
                                        obj,
                                        function(result) {
                                            //console.log("ok:" + $datatype_attr);
                                            scope[ctrlAs].$$internal_other_data(result, $dcvalue_attr);
                                            //console.log("ok2:" + $datatype_attr);
                                            if ($dcvalue_attr) {
                                                scope[ctrlAs].$$internalmodel = $dcvalue_attr;
                                            }

                                            $$data_init = true;
                                        },
                                        function(result) {

                                        }
                                    );
                                }
                            }
                        );
                    }
                };
            }
        };

    }
]);


/**
 * saSelect4指令,封装angular-ui-select控件,并添加相应的业务。
 * name(必须):控件的名字
 * model(必须):指定一个外部object,独立作用域,如:model=ctrl.employeeInfoForSave
 * placeholder(可选):输入框占位符字符串
 *
 * dcvalue(必须):绑定的model字段值,如:dcvalue={{ctrl.employeeInfoForSave.xl.id}}
 * dcname(必须):绑定的model字段名,如:dcname=xl.id
 * icname(必须):内部与之对应的字段名,如:icname=code
 *
 * cmaps(可选):model其他字段和内部数据字段名映射,如:{{ {'xl.id' : 'id', 'xl.name' : 'name'} | json}}
 * dsparams(必须):内部数据源查询参数,如:{{ {'ttid': ctrl.rerunManageForSave.rerunTtinfo.id} | json }}
 * dscol(必须):内部显示的信息(暂时用内部字段),如:dscol=name
 * required(可选):是否要用required验证
 */
angular.module('ScheduleApp').directive('saSelect4', [
    '$timeout',
    '$$SearchInfoService_g',
    function($timeout, $$searchInfoService_g) {
        return {
            restrict: 'E',
            templateUrl: '/pages/scheduleApp/module/common/dts1/select/saSelect4Template.html',
            scope: {
                model: "=" // 独立作用域,关联外部的模型object
            },
            controllerAs: "$saSelectCtrl",
            bindToController: true,
            controller: function($scope) {
                var self = this;
                self.$$data = []; // ui-select显示用的数据
                self.$$data_real = []; // 内部真实的数据

                // saSelect4组件的ng-model,用于外部绑定验证等操作
                self.$$internalmodel = undefined;

                self.$$internal_select_value = undefined; // 选中的值
            },

            /**
             * 此阶段可以改dom结构,此时angular还没扫描指令,
             * 这里就可以动态添加其他angularjs的指令字符串,如required指令字符串。
             * @param tElem
             * @param tAttrs
             * @returns {{pre: Function, post: Function}}
             */
            compile: function(tElem, tAttrs) {
                // 获取属性
                var $name_attr = tAttrs["name"]; // 控件的名字
                var $placeholder_attr = tAttrs["placeholder"]; // 占位符的名字

                var $dcname_attr = tAttrs["dcname"]; // 绑定的model字段名
                var $icname_attr = tAttrs["icname"]; // 内部与之对应的字段名

                var $cmaps_attr = tAttrs["cmaps"]; // model其他字段和内部数据字段名映射
                var $dscol_attr = tAttrs["dscol"]; // 内部显示的信息
                var $required_attr = tAttrs["required"]; // 是否需要required验证

                // controlAs名字
                var ctrlAs = "$saSelectCtrl";

                // 验证属性
                if (!$name_attr) {
                    throw new error("name属性必须填写");
                }
                if (!$dcname_attr) {
                    throw new error("dcname属性必须填写");
                }
                if (!$icname_attr) {
                    throw new error("icname属性必须填写");
                }
                if (!$dscol_attr) {
                    throw new error("dscol属性必须填写");
                }

                // 动态设置dom
                // dom required 属性
                if ($required_attr != undefined) {
                    tElem.find("div").attr("required", "");
                }
                // dom placeholder 属性
                tElem.find("ui-select-match").attr("placeholder", $placeholder_attr);
                // dom dscol 属性
                tElem.find("ui-select-match").html("{{$select.selected" + "." + $dscol_attr + "}}");
                tElem.find("ui-select-choices span").attr("ng-bind", "item" + "." + $dscol_attr);
                // dom icname 属性
                tElem.find("ui-select-choices").attr("repeat", "item" + "." + $icname_attr + " as item in $saSelectCtrl.$$data");
                // dom name 属性
                tElem.find("div").attr("name", $name_attr);

                return {
                    pre: function(scope, element, attr) {
                        // TODO:
                    },

                    /**
                     * 相当于link函数。
                     * @param scope
                     * @param element
                     * @param attr
                     */
                    post: function(scope, element, attr) {

                        // 添加选中事件处理函数
                        scope[ctrlAs].$$internal_select_fn = function($item) {
                            if ($dcname_attr && $icname_attr) {
                                eval("scope[ctrlAs].model" + "." + $dcname_attr + " = $item" + "." + $icname_attr + ";");
                            }

                            if ($cmaps_attr) {
                                for (var mc in $cmaps_attr) { // model的字段名:内部数据源对应字段名
                                    var ic = $cmaps_attr[mc]; // 内部数据源对应字段
                                    eval("scope[ctrlAs].model" + "." + mc + " = $item" + "." + ic + ";");
                                }
                            }
                        };

                        // 删除选中事件处理函数
                        scope[ctrlAs].$$internal_remove_fn = function() {
                            scope[ctrlAs].$$internal_select_value = undefined;
                            if ($dcname_attr) {
                                eval("scope[ctrlAs].model" + "." + $dcname_attr + " = undefined;");
                            }

                            if ($cmaps_attr) {
                                var mc; // model的字段名
                                for (mc in $cmaps_attr) {
                                    eval("scope[ctrlAs].model" + "." + mc + " = undefined;");
                                }
                            }
                            scope[ctrlAs].$$internal_validate_model();
                        };

                        // 刷新数据
                        scope[ctrlAs].$$internal_refresh_fn = function(search) {
                            if (search && search != "") { // 有search值
                                // 处理search
                                console.log("search:" + search);

                                scope[ctrlAs].$$data = [];
                                for (var k = 0; k < scope[ctrlAs].$$data_real.length; k++) {
                                    var upTerm = search.toUpperCase();
                                    if (scope[ctrlAs].$$data.length < 10) {
                                        if (scope[ctrlAs].$$data_real[k].fullChars.indexOf(upTerm) != -1
                                            || scope[ctrlAs].$$data_real[k].camelChars.indexOf(upTerm) != -1) {
                                            scope[ctrlAs].$$data.push(angular.copy(scope[ctrlAs].$$data_real[k]));
                                        }
                                    } else {
                                        break;
                                    }
                                }
                            }
                        };

                        /**
                         * 验证内部数据,更新外部model
                         */
                        scope[ctrlAs].$$internal_validate_model = function() {
                            if (scope[ctrlAs].$$internal_select_value) {
                                var select_value_temp = scope[ctrlAs].$$internal_select_value;
                                if (scope[ctrlAs].$$data_real && scope[ctrlAs].$$data_real.length > 0) {
                                    var obj;
                                    for (var j = 0; j < scope[ctrlAs].$$data_real.length; j++) {
                                        if (eval("scope[ctrlAs].$$data_real[j]" + "." + $icname_attr + " == select_value_temp")) {
                                            obj = angular.copy(scope[ctrlAs].$$data_real[j]);
                                            break;
                                        }
                                    }
                                    if (obj) { // 在data中判定有没有
                                        for (var k = 0; k < scope[ctrlAs].$$data.length; k++) {
                                            if (eval("scope[ctrlAs].$$data[k]" + "." + $icname_attr + " == obj." + $icname_attr)) {
                                                obj = undefined;
                                                break;
                                            }
                                        }
                                        if (obj) {
                                            scope[ctrlAs].$$data.push(obj);
                                        }
                                        // 更新内部model,用于外部验证
                                        // 内部model的值暂时随意,以后再改
                                        scope[ctrlAs].$$internalmodel = {desc: "ok"};
                                    } else {
                                        scope[ctrlAs].$$internalmodel = undefined;
                                    }

                                } else {
                                    scope[ctrlAs].$$internalmodel = undefined;
                                }

                            } else {
                                scope[ctrlAs].$$internalmodel = undefined;
                            }
                        };

                        /**
                         * 内部方法,读取字典数据作为数据源。
                         * @param atype ajax查询类型
                         * @param ajaxparamobj 查询参数对象
                         */
                        scope[ctrlAs].$$internal_ajax_data = function(atype, ajaxparamobj) {
                            ajaxparamobj.type = 'all';
                            $$searchInfoService_g[atype].list(
                                ajaxparamobj,
                                function(result) {
                                    console.log("$$internal_ajax_data result");

                                    // 清空内部数据
                                    scope[ctrlAs].$$data_real = [];
                                    scope[ctrlAs].$$data = [];

                                    // result中添加拼音数据,注意:这里要求result返回对象数组
                                    for (var i = 0; i < result.length; i ++) {
                                        if ($dscol_attr) {
                                            if (eval("result[i]" + "." + $dscol_attr)) {
                                                // 全拼
                                                result[i]["fullChars"] = pinyin.getFullChars(eval("result[i]" + "." + $dscol_attr)).toUpperCase();
                                                // 简拼
                                                result[i]["camelChars"] = pinyin.getCamelChars(eval("result[i]" + "." + $dscol_attr));
                                            }
                                        }

                                        if (result[i]["fullChars"]) { // 有拼音的加入数据源
                                            scope[ctrlAs].$$data_real.push(result[i]);
                                        }

                                    }

                                    // 数据量太大,取10条记录显示
                                    if (angular.isArray(scope[ctrlAs].$$data_real)) {
                                        for (var k = 0; k < scope[ctrlAs].$$data_real.length; k++) {
                                            if (scope[ctrlAs].$$data.length < 10) {
                                                scope[ctrlAs].$$data.push(angular.copy(scope[ctrlAs].$$data_real[k]));
                                            } else {
                                                break;
                                            }
                                        }
                                    }

                                    scope[ctrlAs].$$internal_validate_model();
                                },
                                function(result) {

                                }
                            );
                        };

                        /**
                         * 内部方法,读取字典数据作为数据源。
                         * @param dictype 字典类型,如:gsType
                         */
                        scope[ctrlAs].$$internal_dic_data = function(dictype) {
                            if (!dictionaryUtils.getByGroup(dictype)) {
                                throw new error("字典数据不窜在=" + dictype);
                            }

                            // 清空内部数据
                            scope[ctrlAs].$$data_real = [];
                            scope[ctrlAs].$$data = [];

                            var origin_dicgroup = dictionaryUtils.getByGroup(dicgroup);
                            var dic_key; // 字典key

                            for (dic_key in origin_dicgroup) {
                                var data = {}; // 重新组合的字典元素对象
                                if (dic_key == "true")
                                    data[$icname_attr] = true;
                                else
                                    data[$icname_attr] = dic_key;
                                data[$dscol_attr] = origin_dicgroup[dic_key];
                                scope[ctrlAs].$$data_real.push(data);
                            }
                            // 这里直接将$$data_real数据深拷贝到$$data
                            angular.copy(scope[ctrlAs].$$data_real, scope[ctrlAs].$$data);
                            scope[ctrlAs].$$internal_validate_model();
                        };

                        attr.$observe("dsparams", function(value) {
                            if (value && value != "") {
                                var obj = JSON.parse(value);
                                console.log("observe 监控 dsparams=" + obj);

                                // dsparams格式如下:
                                // {type: 'dic/ajax', param: 'dic名字'/'ajax查询参数对象', atype: 'ajax查询类型'}

                                if (obj.type == 'dic') {
                                    scope[ctrlAs].$$internal_dic_data(obj.param);

                                } else if (obj.type == 'ajax') {
                                    scope[ctrlAs].$$internal_ajax_data(obj.atype, obj.param);
                                } else {
                                    throw new Error("dsparams参数格式异常=" + obj);
                                }

                            }

                        });

                        // 监控model绑定的dcvalue值变化
                        attr.$observe("dcvalue", function(value) {
                            if (value && value != "") {
                                console.log("observe 监控 dcvalue=" + value);
                                scope[ctrlAs].$$internal_select_value = value;
                                scope[ctrlAs].$$internal_validate_model();
                            }

                            // 闭包测试
                            var obj = {'a':1,'b':2};
                            var tfx = scope[ctrlAs].$$test.bind(obj);
                            console.log("闭包测试=" + tfx());
                        });

                        scope[ctrlAs].$$test = function() {
                            var exp = "this.a + '(' + this.b + ')'";
                            console.log("exp=" + exp);
                            return eval(exp);
                        };
                    }
                };

            }

        };
    }
]);
/**
 * saSelect5指令,基于简拼查询的select,内部封装angular-ui-select控件,并嵌入相应的业务逻辑。
 * name(必须):控件的名字
 * model(必须):独立作用域,指定一个外部对象模型双向绑定,如:model=ctrl.employeeInfoForSave
 * cmaps(必须):外部对象与指令内部数据对象字段名映射对象字符串,如:{'xl.id' : 'id', 'xl.name' : 'name'}
 * dcname(必须):绑定的model字段名,如:dcname=xl.id
 * icname(必须):内部与之对应的字段名,如:icname=id
 *
 * dsparams(必须):内部数据源查询参数对象,如:{{ {'ttid_eq': ctrl.rerunManageForSave.rerunTtinfo.id} | json }}
 * dsparamsextra(可选):内部数据源查询附加参数对象字符串,如:{'type':'all'}
 * iterobjname(必须):内部数据源迭代的数据变量名,如:iterobjname=item
 * iterobjexp(必须):内部显示用的表达式
 * searchph(必须):查询输入占位符字符串,如:searchph=请输入...
 * searchexp(必须):查询基于的内部数据源的表达式,如:searchexp=this.name+'('+this.code+')'
 *
 * required(可选):是否需要form的required验证
 *
 */
angular.module('ScheduleApp').directive('saSelect5', [
    '$timeout',
    '$$SearchInfoService_g',
    'UserPrincipal',
    'DataStore',
    function($timeout, $$searchInfoService_g, UserPrincipal, DataStore) {
        return {
            restrict: 'E',
            templateUrl: '/pages/scheduleApp/module/common/dts1/select/saSelect5Template.html',
            scope: { // 独立作用域
                model: "=" // 绑定外部对象
            },
            controllerAs: "$saSelectCtrl",
            bindToController: true,
            controller: function($scope) {
                var self = this;
                self.$$data = []; // 内部ui-select显示用数据
                self.$$data_real = []; // 内部保存的实际数据

                // myselect组件的ng-model,用于外部绑定验证等操作
                self.$$internalmodel = undefined;

                self.$$internal_select_value = undefined; // 选中的值

            },

            /**
             * 此阶段可以改dom结构,此时angular还没扫描指令,
             * 这里就可以动态添加其他angularjs的指令字符串,如required指令字符串。
             * @param tElem
             * @param tAttrs
             * @returns {{pre: Function, post: Function}}
             */
            compile: function(tElem, tAttrs) {
                // 获取属性,并验证必须按属性
                var $name_attr = tAttrs["name"]; // 控件的名字
                var $cmaps_attr = tAttrs["cmaps"]; // 外部对象与指令内部数据对象字段名映射对象
                var $dcname_attr = tAttrs["dcname"]; // 绑定的model字段名
                var $icname_attr = tAttrs["icname"]; // 内部与之对应的字段名

                var $dsparams_attr = tAttrs["dsparams"]; // 内部数据源查询参数对象
                var $dsparamsextra_attr = tAttrs["dsparamsextra"]; // 内部数据源查询附加参数对象字符串
                var $iterobjname_attr = tAttrs["iterobjname"]; // 内部数据源迭代的数据变量名
                var $iterobjexp_attr = tAttrs["iterobjexp"]; // 内部显示用的表达式
                var $searchph_attr = tAttrs["searchph"]; // 查询输入占位符字符串
                var $searchexp_attr = tAttrs["searchexp"]; // 查询基于的内部数据源的表达式

                var $required_attr = tAttrs["required"]; // 是否需要required验证

                if (!$name_attr) {
                    throw new Error("name属性必须填写");
                }
                if (!$cmaps_attr) {
                    throw new Error("cmaps属性必须填写")
                }
                if (!$dcname_attr || !$icname_attr) {
                    throw new Error("dcname、icname属性必须填写");
                }
                if (!$dsparams_attr) {
                    throw new Error("dsparams属性必须填写");
                }
                if (!$iterobjname_attr) {
                    throw new Error("iterobjname属性必须填写");
                }
                if (!$iterobjexp_attr) {
                    throw new Error("iterobjexp属性必须填写");
                }
                if (!$searchph_attr) {
                    throw new Error("searchph属性必须填写");
                }
                if (!$searchexp_attr) {
                    throw new Error("searchexp属性必须填写");
                }

                // 内部controlAs名字
                var ctrlAs = "$saSelectCtrl";

                // 动态设置dom
                // dom,最外层name属性设置
                tElem.find("div:first").attr("name", $name_attr);
                // dom,最外层divrequired属性设置
                if ($required_attr != undefined) {
                    tElem.find("div[name=\'" + $name_attr + "\']").attr("required", "");
                }
                // dom,ui-select-match的placeholder属性设定
                tElem.find("ui-select-match").attr("placeholder", $searchph_attr);
                // dom,ui-select-match的内容设定
                var uiSelectMatchHtml = "{{" + ctrlAs + ".$$internal_match_str($select.selected)}}";
                tElem.find("ui-select-match").html(uiSelectMatchHtml);
                // dom,ui-select-choices的repeat属性设定
                var uiSelectChoices_repeatAttr = $iterobjname_attr + "." + $icname_attr + " as " + $iterobjname_attr + " in " + ctrlAs + ".$$data";
                tElem.find("ui-select-choices").attr("repeat", uiSelectChoices_repeatAttr);
                // dom,span ng-bind属性设置,TODO:暂时无法用transclude设置,先用属性设置
                tElem.find("ui-select-choices").html("{{" + $iterobjexp_attr + "}}");


                // 当前的数据模式,ajax,dic,local
                var dataModelType = undefined;

                return {
                    pre: function (scope, element, attr) {
                        // TODO:
                    },

                    /**
                     * 相当于link函数。
                     * @param scope
                     * @param element
                     * @param attr
                     */
                    post: function (scope, element, attr) {

                        // 添加选中事件处理函数
                        scope[ctrlAs].$$internal_select_fn = function($item) {
                            if ($dcname_attr.indexOf('_') > 0) {
                                scope[ctrlAs].model[$dcname_attr] = $item[$icname_attr];
                            } else {
                                eval("scope[ctrlAs].model" + "." + $dcname_attr + " = $item" + "." + $icname_attr + ";");
                            }


                            eval("var obj=" + $cmaps_attr);
                            for (var mc in obj) { // model的字段名:内部数据源对应字段名
                                var ic = obj[mc]; // 内部数据源对应字段
                                if (mc.indexOf('_') > 0) {
                                    scope[ctrlAs].model[mc] = $item[ic];
                                } else {
                                    try {
                                        eval("scope[ctrlAs].model" + "." + mc + " = $item" + "." + ic + ";");
                                    } catch (e) {
                                        // TODO:
                                        eval("scope[ctrlAs].model" + "." + mc + " = null;");
                                    }

                                }
                            }
                        };

                        // 删除选中事件处理函数
                        scope[ctrlAs].$$internal_remove_fn = function() {
                            if ($dcname_attr.indexOf('_') > 0) {
                                scope[ctrlAs].model[$dcname_attr] = undefined;
                            } else {
                                eval("scope[ctrlAs].model" + "." + $dcname_attr + " = undefined;");
                            }

                            eval("var obj=" + $cmaps_attr);
                            var mc; // model的字段名
                            for (mc in obj) {
                                if (mc.indexOf('_') > 0) {
                                    scope[ctrlAs].model[mc] = undefined;
                                } else {
                                    eval("scope[ctrlAs].model" + "." + mc + " = undefined;");
                                }
                            }
                        };

                        // 刷新数据
                        scope[ctrlAs].$$internal_refresh_fn = function(search) {
                            if (search && search != "") { // 有search值
                                // 处理search
                                console.log("search:" + search);

                                if (dataModelType == 'ajax' || dataModelType == 'local') {
                                    scope[ctrlAs].$$data = [];
                                    for (var k = 0; k < scope[ctrlAs].$$data_real.length; k++) {
                                        var upTerm = search.toUpperCase();
                                        if (scope[ctrlAs].$$data.length < 10) {
                                            if (scope[ctrlAs].$$data_real[k].$fullChars.indexOf(upTerm) != -1
                                                || scope[ctrlAs].$$data_real[k].$camelChars.indexOf(upTerm) != -1
                                                || scope[ctrlAs].$$data_real[k].$calcu_str.indexOf(upTerm) != -1) {
                                                scope[ctrlAs].$$data.push(angular.copy(scope[ctrlAs].$$data_real[k]));
                                            }
                                        } else {
                                            break;
                                        }
                                    }
                                }
                            }
                        };

                        /**
                         * 验证内部数据,更新外部model
                         */
                        scope[ctrlAs].$$internal_validate_model = function() {
                            // TODO:
                            //console.log(scope[ctrlAs].$$internal_select_value);
                            //console.log(scope[ctrlAs].$$data_real);

                            if (scope[ctrlAs].$$internal_select_value) {
                                var select_value_temp = scope[ctrlAs].$$internal_select_value;
                                if (scope[ctrlAs].$$data_real && scope[ctrlAs].$$data_real.length > 0) {
                                    var obj;
                                    for (var j = 0; j < scope[ctrlAs].$$data_real.length; j++) {
                                        if (eval("scope[ctrlAs].$$data_real[j]" + "." + $icname_attr + " == select_value_temp")) {
                                            obj = angular.copy(scope[ctrlAs].$$data_real[j]);
                                            break;
                                        }
                                    }
                                    if (obj) { // 在data中判定有没有
                                        // 初始化的时候,模拟选中uiselect
                                        scope[ctrlAs].$$internal_select_fn(obj);

                                        for (var k = 0; k < scope[ctrlAs].$$data.length; k++) {
                                            if (eval("scope[ctrlAs].$$data[k]" + "." + $icname_attr + " == obj." + $icname_attr)) {
                                                obj = undefined;
                                                break;
                                            }
                                        }
                                        if (obj) {
                                            scope[ctrlAs].$$data.push(obj);
                                        }
                                        // 更新内部model,用于外部验证
                                        // 内部model的值暂时随意,以后再改
                                        scope[ctrlAs].$$internalmodel = {desc: "ok"};

                                    } else {
                                        scope[ctrlAs].$$internalmodel = undefined;
                                    }

                                } else {
                                    scope[ctrlAs].$$internalmodel = undefined;
                                }

                            } else {
                                scope[ctrlAs].$$internalmodel = undefined;
                            }
                        };

                        /**
                         * 内部match表达式转换函数,需要外部绑定此函数的上下文。
                         * @param context function上下文
                         */
                        scope[ctrlAs].$$internal_match_str = function (context) {
                            var fx = function() {
                                try {
                                    return eval($searchexp_attr);
                                } catch (err) {
                                    //console.log(err);
                                    return undefined;
                                }

                            };

                            var str = fx.bind(context)();
                            if (str && str != "")
                                return str;
                            else
                                return undefined;
                        };

                        /**
                         * 内部方法,读取字典数据作为数据源。
                         * @param atype ajax查询类型
                         * @param ajaxparamobj 查询参数对象
                         */
                        scope[ctrlAs].$$internal_ajax_data = function(atype, ajaxparamobj) {
                            // 如果ajaxparamobj为空对象,则表示清空内部选项
                            var isEmptyObj = true;
                            for (var name in ajaxparamobj) {
                                isEmptyObj = false;
                            }
                            if (isEmptyObj) {
                                // 重新创建内部保存的数据
                                scope[ctrlAs].$$data_real = [];
                                // 重新创建内部ui-select显示用数据,默认取10条记录显示
                                scope[ctrlAs].$$data = [];

                                scope[ctrlAs].$$internal_remove_fn();
                                scope[ctrlAs].$$internal_validate_model();

                                return;
                            }

                            if ($dsparamsextra_attr) { // 合并附加参数
                                eval("var extra = " + $dsparamsextra_attr);
                                for (var extrakey in extra) {
                                    ajaxparamobj[extrakey] = extra[extrakey];
                                }
                            }

                            // 添加线路查询用的公司分公司信息
                            if (atype == 'xl') {
                                if (UserPrincipal.getGsStrs().length > 0) {
                                    ajaxparamobj["cgsbm_in"] = UserPrincipal.getGsStrs().join(",");
                                }
                            }

                            $$searchInfoService_g[atype].list(
                                ajaxparamobj,
                                function(result) {
                                    console.log("$$internal_ajax_data result");

                                    // 重新创建内部保存的数据
                                    scope[ctrlAs].$$data_real = [];
                                    // result中添加拼音数据,注意:这里要求result返回对象数组
                                    for (var i = 0; i < result.length; i++) {
                                        // 闭包绑定返回最终查询的值
                                        var calcu_str = scope[ctrlAs].$$internal_match_str(result[i]);
                                        if (calcu_str) {
                                            // 全拼
                                            if (!result[i]["$fullChars"]) {
                                                result[i]["$fullChars"] = pinyin.getFullChars(calcu_str);
                                            }
                                            // 简拼
                                            if (!result[i]["$camelChars"]) {
                                                result[i]["$camelChars"] = pinyin.getCamelChars(calcu_str);
                                            }
                                            // 原值
                                            if (!result[i]["$calcu_str"]) {
                                                result[i]["$calcu_str"] = calcu_str;
                                            }

                                            scope[ctrlAs].$$data_real.push(result[i]);
                                        }
                                    }

                                    // 重新创建内部ui-select显示用数据,默认取10条记录显示
                                    scope[ctrlAs].$$data = [];
                                    for (var k = 0; k < scope[ctrlAs].$$data_real.length; k++) {
                                        if (scope[ctrlAs].$$data.length < 10) {
                                            scope[ctrlAs].$$data.push(scope[ctrlAs].$$data_real[k]);
                                        } else {
                                            break;
                                        }
                                    }

                                    scope[ctrlAs].$$internal_validate_model();
                                },
                                function(result) {
                                    throw new Error("ajax查询出错");
                                }
                            );
                        };

                        /**
                         * 内部方法,读取字典数据作为数据源。
                         * @param dictype 字典类型,如:gsType
                         */
                        scope[ctrlAs].$$internal_dic_data = function(dictype) {
                            if (!dictionaryUtils.getByGroup(dictype)) {
                                throw new error("字典数据不窜在=" + dictype);
                            }

                            // 重新创建内部保存的数据
                            scope[ctrlAs].$$data_real = [];
                            var origin_dicgroup = dictionaryUtils.getByGroup(dictype);
                            var dic_key; // 字典key

                            //console.log(origin_dicgroup);

                            for (dic_key in origin_dicgroup) {
                                var data = {}; // 重新组合的字典元素对象
                                if (dic_key == "true")
                                    data[$icname_attr] = true;
                                else
                                    data[$icname_attr] = dic_key;
                                data['name'] = origin_dicgroup[dic_key]; // 字典写死name这个key名字
                                scope[ctrlAs].$$data_real.push(data);
                            }

                            // 重新创建内部ui-select显示用数据,直接复制所有的字典数据
                            scope[ctrlAs].$$data = [];
                            for (var k = 0; k < scope[ctrlAs].$$data_real.length; k++) {
                                scope[ctrlAs].$$data.push(scope[ctrlAs].$$data_real[k]);
                            }

                            scope[ctrlAs].$$internal_validate_model();
                        };

                        /**
                         * 内部方法,读取本地动态数据源。
                         * @param type
                         */
                        scope[ctrlAs].$$internal_local_data = function(type) {
                            // 重新创建内部保存的数据
                            scope[ctrlAs].$$data_real = [];
                            // 本地动态数据直接显示,暂时不优化
                            var ldata = DataStore.getData(type);
                            for (var i = 0; i < ldata.length; i++) {
                                // 闭包绑定返回最终查询的值
                                var calcu_str = scope[ctrlAs].$$internal_match_str(ldata[i]);
                                if (calcu_str) {
                                    // 全拼
                                    if (!ldata[i]["$fullChars"]) {
                                        ldata[i]["$fullChars"] = pinyin.getFullChars(calcu_str);
                                    }
                                    // 简拼
                                    if (!ldata[i]["$camelChars"]) {
                                        ldata[i]["$camelChars"] = pinyin.getCamelChars(calcu_str);
                                    }
                                    // 原值
                                    if (!ldata[i]["$calcu_str"]) {
                                        ldata[i]["$calcu_str"] = calcu_str;
                                    }

                                    scope[ctrlAs].$$data_real.push(ldata[i]);
                                }
                            }

                            // 重新创建内部ui-select显示用数据,默认取10条记录显示
                            scope[ctrlAs].$$data = [];
                            for (var k = 0; k < scope[ctrlAs].$$data_real.length; k++) {
                                if (scope[ctrlAs].$$data.length < 50) {
                                    scope[ctrlAs].$$data.push(scope[ctrlAs].$$data_real[k]);
                                } else {
                                    break;
                                }
                            }

                            scope[ctrlAs].$$internal_validate_model();
                        };

                        /**
                         * 内部方法,读取传过来的动态数据源。
                         * @param ldata
                         */
                        scope[ctrlAs].$$internal_pass_data = function(ldata) {
                            // 重新创建内部保存的数据
                            scope[ctrlAs].$$data_real = [];
                            // 重新创建内部ui-select显示用数据,默认取10条记录显示
                            scope[ctrlAs].$$data = [];

                            // 本地动态数据直接显示,暂时不优化
                            for (var i = 0; i < ldata.length; i++) {
                                scope[ctrlAs].$$data_real.push(ldata[i]);
                                scope[ctrlAs].$$data.push(ldata[i]);
                            }

                            scope[ctrlAs].$$internal_validate_model();
                        };

                        /**
                         * 监控dsparams属性变化
                         */
                        attr.$observe("dsparams", function(value) {
                            if (value && value != "") {
                                var obj = JSON.parse(value);
                                console.log("saSelect5 监控到dsparams属性变化,old=" + $dsparams_attr + ",new=" + value);

                                // dsparams格式如下:
                                // {type: 'ajax', param: 'ajax查询参数对象', atype: 'ajax查询累西'}
                                // {type: 'dic', param: 'dic名字'}
                                // {type: 'local', param: '本地存储type名字'}
                                // {type: 'passdata', : 'ldata': '本地存储数据'}

                                if (obj.type == 'dic') {
                                    dataModelType = 'dic';
                                    scope[ctrlAs].$$internal_dic_data(obj.param);

                                } else if (obj.type == 'ajax') {
                                    dataModelType = 'ajax';
                                    scope[ctrlAs].$$internal_ajax_data(obj.atype, obj.param);
                                } else if (obj.type == 'local') {
                                    dataModelType = 'local';
                                    scope[ctrlAs].$$internal_local_data(obj.param);
                                } else if (obj.type == 'passdata') {
                                    dataModelType = 'passdata';
                                    scope[ctrlAs].$$internal_pass_data(obj.ldata);
                                } else {
                                    throw new Error("dsparams参数格式异常=" + obj);
                                }

                            }
                        });

                        /**
                         * 监控外部模型dcname的值的变化。
                         */
                        scope.$watch(
                            function() {
                                if ($dcname_attr.indexOf('_') > 0) {
                                    return scope[ctrlAs].model[$dcname_attr];
                                } else {
                                    return eval("scope." + ctrlAs + ".model" + "." + $dcname_attr);
                                }
                            },
                            function(newValue, oldValue) {
                                if (newValue === undefined && oldValue === undefined) {
                                    // 两侧都是undefined,不处理

                                } else {
                                    console.log("saSelect5 监控到外部模型" + $dcname_attr + "属性值变化,old=" + oldValue + ",new=" + newValue);
                                    scope[ctrlAs].$$internal_select_value = newValue;
                                    scope[ctrlAs].$$internal_validate_model();
                                }
                            },
                            true
                        );
                    }
                };
            }
        };
    }
]);
/**
 * mySelect指令,封装uiselect指令,封装内部数据获取,只支持单选
 * cm(必须):绑定外部对象,因为关联的字段不只一个,单独使用ngModel不够
 * cmoptions(必须):描述绑定的逻辑配置对象,格式如下:
 *
 * // TODO:
 */
angular.module('ScheduleApp').directive('mySelect', [
    function() {
        return {
            restrict: 'E',
            template: '<div>bioxuxuan</div>',
            require: 'ngModel',
            compile: function(tElem, tAttrs) {
                return {
                    pre: function(scope, element, attr) {

                    },
                    post: function(scope, element, attr, ngModelCtr) {
                        // model -> view
                        ngModelCtr.$formatters.push(function(modelValue) {
                            // 监控model的变化
                            if (typeof modelValue != "undefined") {
                                console.log(modelValue);

                                return modelValue;
                            }
                        });

                        ngModelCtr.$render = function() {
                            if (typeof scope.ctrl.say != "undefined") {
                                element.find('div').css('color', 'red');
                            }
                        };

                        ngModelCtr.$setViewValue("init value");


                    }
                }
            }
        }
    }
]);

/**
 * saRadiogroup指令
 * 属性如下:
 * model(必须):独立作用域,外部绑定的一个值,如:ctrl.timeTableManageForForm.isEnableDisTemplate
 * dicgroup(必须):关联的字典数据type(TODO:以后增加其他数据源)
 * name(必须):控件的名字
 * required(可选):是否要用required验证
 * disabled(可选):标示单选框是否可选
 *
 */
angular.module('ScheduleApp').directive("saRadiogroup", [function() {
    /**
     * 使用字典数据的单选按钮组的指令。
     * 指令名称:truefalse-Dic
     */
    return {
        restrict: 'E',
        templateUrl: '/pages/scheduleApp/module/common/dts1/radioButton/saRadiogroupTemplate.html',
        scope: {
            model: "="
        },
        controllerAs: "$saRadiogroupCtrl",
        bindToController: true,
        controller: function($scope) {
            //$scope["model"] = {selectedOption: null};
            //console.log("controller");
            //console.log("controller:" + $scope["model"]);

            var self = this;
            self.$$data = null; // 内部数据
        },

        /**
         * 此阶段可以改dom结构,此时angular还没扫描指令,
         * 这里就可以动态添加其他angularjs的指令字符串,如required指令字符串。
         * @param tElem
         * @param tAttrs
         * @returns {{pre: Function, post: Function}}
         */
        compile: function(tElem, tAttrs) {
            // 获取属性
            var $dicgroup_attr = tAttrs["dicgroup"]; // 关联的字典数据type
            var $name_attr = tAttrs["name"]; // 控件的名字
            var $required_attr = tAttrs["required"]; // 是否要用required验证
            var $disabled_attr = tAttrs["disabled"]; // 标示单选框是否可选

            // controlAs名字
            var ctrlAs = "$saRadiogroupCtrl";

            // 如果有required属性,添加angularjs required验证
            if ($required_attr != undefined) {
                tElem.find("input").attr("required", "");
            }

            return {
                pre: function(scope, element, attr) {

                },

                /**
                 * 相当于link函数。
                 * @param scope
                 * @param element
                 * @param attr
                 */
                post: function(scope, element, attr) {
                    //console.log("link");
                    //console.log("link:" + scope.model);
                    //scope["model"] = {selectedOption: null};

                    if ($name_attr) {
                        scope[ctrlAs].nv = $name_attr;
                    }

                    if ($disabled_attr) {
                        scope[ctrlAs].disabled = true;
                    }
                    if ($dicgroup_attr) {
                        var obj = dictionaryUtils.getByGroup($dicgroup_attr);
                        scope[ctrlAs].$$data = obj;
                        // 处理 scope["dic"] key值
                        scope[ctrlAs].dicvalueCalcu = function(value) {
                            if (value == "true") {
                                //console.log(value);
                                return true;
                            } else if (value == "false") {
                                //console.log(value);
                                return false;
                            } else {
                                return value;
                            }
                        };
                    }
                }
            };
        }
    };
}]);



/**
 * saCheckboxgroup指令
 * 属性如下:
 * model(必须):指定一个外部object,独立作用域,如:model=ctrl.employeeInfoForSave
 * dcvalue(必须):绑定的model字段值,如:dcvalue={{ctrl.employeeInfoForSave.xl.id}}
 * dcname(必须):绑定的model字段名,如:dcname=xl.id
 * name(必须):控件的名字
 * required(可选):是否要用required验证
 * disabled(可选):标示框是否可选
 *
 */
angular.module('ScheduleApp').directive('saCheckboxgroup', [
    function() {
        return {
            restrict: 'E',
            templateUrl: '/pages/scheduleApp/module/common/dts1/checkbox/saCheckboxgroupTemplate.html',
            scope: {
                model: "=" // 独立作用域,关联外部的模型object
            },
            controllerAs: "$saCheckboxgroupCtrl",
            bindToController: true,
            controller: function($scope) {
                var self = this;
                self.$$data = []; // 内部的数据

                // TODO:数据写死,周一至周日选择数据,以后有别的数据再议
                self.$$data = [
                    {name: "星期一", checkedvalue: "1", uncheckedvalue: "0", ischecked: false},
                    {name: "星期二", checkedvalue: "1", uncheckedvalue: "0", ischecked: false},
                    {name: "星期三", checkedvalue: "1", uncheckedvalue: "0", ischecked: false},
                    {name: "星期四", checkedvalue: "1", uncheckedvalue: "0", ischecked: false},
                    {name: "星期五", checkedvalue: "1", uncheckedvalue: "0", ischecked: false},
                    {name: "星期六", checkedvalue: "1", uncheckedvalue: "0", ischecked: false},
                    {name: "星期日", checkedvalue: "1", uncheckedvalue: "0", ischecked: false}
                ];
            },

            /**
             * 此阶段可以改dom结构,此时angular还没扫描指令,
             * 这里就可以动态添加其他angularjs的指令字符串,如required指令字符串。
             * @param tElem
             * @param tAttrs
             * @returns {{pre: Function, post: Function}}
             */
            compile: function(tElem, tAttrs) {
                // 获取所有的属性
                var $name_attr = tAttrs["name"]; // 控件的名字
                var $required_attr = tAttrs["required"]; // 是否需要required验证
                var $disabled_attr = tAttrs["disabled"]; // 是否禁用
                var $dcname_attr = tAttrs["dcname"]; // 绑定的model字段名

                // controlAs名字
                var ctrlAs = '$saCheckboxgroupCtrl';

                // 如果有required属性,添加angularjs required验证
                if ($required_attr != undefined) {
                    //console.log(tElem.html());
                    tElem.find("div").attr("required", "");
                }
                // 如果有disabled属性,添加禁用标志
                if ($disabled_attr != undefined) {
                    tElem.find("input").attr("ng-disabled", "true");
                }

                return {
                    pre: function(scope, element, attr) {
                        // TODO:
                    },
                    /**
                     * 相当于link函数。
                     * @param scope
                     * @param element
                     * @param attr
                     */
                    post: function(scope, element, attr) {
                        // name属性
                        if ($name_attr) {
                            scope[ctrlAs]["$name_attr"] = $name_attr;
                        }

                        /**
                         * checkbox选择事件处理函数。
                         * @param $d 数据对象,$$data中的元素对象
                         */
                        scope[ctrlAs].$$internal_updateCheck_fn = function($d) {
                            $d.ischecked = !$d.ischecked;
                            console.log($d);
                        };

                        // 测试使用watch监控$$data的变化
                        scope.$watch(
                            function() {
                                return scope[ctrlAs]["$$data"];
                            },
                            function(newValue, oldValue) {
                                // 根据$$data生成对应的数据
                                var rule_days_arr = [];
                                var i;
                                for (i = 0; i < scope[ctrlAs]["$$data"].length; i++) {
                                    if (scope[ctrlAs]["$$data"][i].ischecked)
                                        rule_days_arr.push(scope[ctrlAs]["$$data"][i].checkedvalue);
                                    else
                                        rule_days_arr.push(scope[ctrlAs]["$$data"][i].uncheckedvalue);
                                }
                                scope[ctrlAs].$$internalmodel = rule_days_arr.join(",");
                                //scope[ctrlAs].$$internalmodel = undefined;
                                console.log("bbbbbbbb--->" + scope[ctrlAs].$$internalmodel);

                                // 更新model
                                if ($dcname_attr) {
                                    eval("scope[ctrlAs].model" + "." + $dcname_attr + " = rule_days_arr.join(',');");
                                }


                            },
                            true
                        );

                        // TODO:

                        // 监控dcvalue model值变换
                        attr.$observe("dcvalue", function(value) {
                            console.log("saCheckboxgroup 监控dc1 model值变换:" + value);
                            if (value) {
                                // 根据value值,修改$$data里的值
                                var data_array = value.split(",");
                                var i;
                                if (data_array.length > scope[ctrlAs]["$$data"].length) {
                                    for (i = 0; i < scope[ctrlAs]["$$data"].length; i ++) {
                                        if (data_array[i] == scope[ctrlAs]["$$data"][i].checkedvalue) {
                                            scope[ctrlAs]["$$data"][i].ischecked = true;
                                        } else {
                                            scope[ctrlAs]["$$data"][i].ischecked = false;
                                        }
                                    }
                                } else {
                                    for (i = 0; i < data_array.length; i ++) {
                                        if (data_array[i] == scope[ctrlAs]["$$data"][i].checkedvalue) {
                                            scope[ctrlAs]["$$data"][i].ischecked = true;
                                        } else {
                                            scope[ctrlAs]["$$data"][i].ischecked = false;
                                        }
                                    }
                                }

                            }
                        });
                    }

                };


            }

        };
    }
]);




/**
 * saDategroup指令
 * 属性如下:
 * model(必须):指定一个外部object,独立作用域,如:model=ctrl.employeeInfoForSave
 * dcvalue(必须):绑定的model字段值,如:dcvalue={{ctrl.employeeInfoForSave.xl.id}}
 * dcname(必须):绑定的model字段名,如:dcname=xl.id
 * name(必须):控件的名字
 * required(可选):是否要用required验证
 * disabled(可选):标示框是否可选
 *
 */
angular.module('ScheduleApp').directive('saDategroup', [
    '$filter',
    function($filter) {
        return {
            restrict: 'E',
            templateUrl: '/pages/scheduleApp/module/common/dts2/dateGroup/saDategroupTemplate.html',
            scope: {
                model: "=" // 独立作用域,关联外部的模型object
            },
            controllerAs: "$saDategroupCtrl",
            bindToController: true,
            controller: function($scope) {
                var self = this;
                self.$$data = []; // 内部的数据
                self.$$date_select; // 内部选中的日期

                //// 测试数据
                //self.$$data = [
                //    {datestr: '2011-01-01', ischecked: true},
                //    {datestr: '2011-01-01', ischecked: true},
                //    {datestr: '2011-01-01', ischecked: true}
                //];
            },

            /**
             * 此阶段可以改dom结构,此时angular还没扫描指令,
             * 这里就可以动态添加其他angularjs的指令字符串,如required指令字符串。
             * @param tElem
             * @param tAttrs
             * @returns {{pre: Function, post: Function}}
             */
            compile: function(tElem, tAttrs) {
                // 获取所有的属性
                var $name_attr = tAttrs["name"]; // 控件的名字
                var $required_attr = tAttrs["required"]; // 是否需要required验证
                var $disabled_attr = tAttrs["disabled"]; // 是否禁用
                var $dcname_attr = tAttrs["dcname"]; // 绑定的model字段名

                // controlAs名字
                var ctrlAs = '$saDategroupCtrl';

                // 如果有required属性,添加angularjs required验证
                if ($required_attr != undefined) {
                    //console.log(tElem.html());
                    tElem.find("div").attr("required", "");
                }
                // 如果有disabled属性,添加禁用标志
                if ($disabled_attr != undefined) {
                    tElem.find("input").attr("ng-disabled", "true");
                    tElem.find("div").attr("ng-disabled", "true");
                }

                return {
                    pre: function (scope, element, attr) {
                        // TODO:
                    },
                    /**
                     * 相当于link函数。
                     * @param scope
                     * @param element
                     * @param attr
                     */
                    post: function (scope, element, attr) {
                        // name属性
                        if ($name_attr) {
                            scope[ctrlAs]["$name_attr"] = $name_attr;
                        }


                        // 日期open属性,及方法
                        scope[ctrlAs].$$specialDateOpen = false;
                        scope[ctrlAs].$$specialDate_open = function() {
                            scope[ctrlAs].$$specialDateOpen = true;
                        };

                        // 监控选择的日期
                        scope.$watch(
                            function() {
                                return scope[ctrlAs]['$$date_select'];
                            },
                            function(newValue, oldValue) {
                                if (newValue) {
                                    //console.log("saDategroup--->selectdate:" + newValue);
                                    // 调用内置filter,转换日期到yyyy-MM-dd格式
                                    var text = $filter('date')(newValue, 'yyyy-MM-dd');
                                    var i;
                                    var isexist = false; // 日期是否已经选择标识
                                    for (i = 0; i < scope[ctrlAs]["$$data"].length; i++) {
                                        if (scope[ctrlAs]["$$data"][i].datestr == text) {
                                            isexist = true;
                                            break;
                                        }
                                    }
                                    if (!isexist) {
                                        scope[ctrlAs]["$$data"].push(
                                            {
                                                datestr: text,
                                                ischecked: true
                                            }
                                        );
                                    }

                                }

                            }
                        );

                        /**
                         * 日期点击事件处理函数。
                         * @param $index 索引
                         */
                        scope[ctrlAs].$$internal_datestr_click = function($index) {
                            scope[ctrlAs].$$data.splice($index, 1);
                        };

                        // 测试使用watch监控$$data的变化
                        scope.$watch(
                            function() {
                                return scope[ctrlAs]['$$data'];
                            },
                            function(newValue, oldValue) {
                                // 根据$$data生成对应的数据
                                var special_days_arr = [];
                                var i;
                                for (i = 0; i < scope[ctrlAs]["$$data"].length; i++) {
                                    special_days_arr.push(scope[ctrlAs]["$$data"][i].datestr);
                                }

                                scope[ctrlAs].$$internalmodel = special_days_arr.join(",");
                                console.log("bbbbbbbb--->" + scope[ctrlAs].$$internalmodel);

                                // 更新model
                                if ($dcname_attr) {
                                    eval("scope[ctrlAs].model" + "." + $dcname_attr + " = special_days_arr.join(',');");
                                }
                            },
                            true
                        );

                        // 监控dcvalue model值变换
                        attr.$observe("dcvalue", function(value) {
                            console.log("saDategroup 监控dc1 model值变换:" + value);
                            if (value) {
                                // 根据value值,修改$$data里的值
                                var date_array = value.split(",");
                                var i;
                                scope[ctrlAs]["$$data"] = [];
                                for (i = 0; i < date_array.length; i++) {
                                    scope[ctrlAs]["$$data"].push(
                                        {
                                            datestr: date_array[i],
                                            ischecked: true
                                        }
                                    );
                                }









                            }
                        });

                    }

                };
            }
        }
    }
]);


/**
 * saFbgsgroup指令
 * 属性如下:
 * name(必须):控件的名字
 * model(必须):指定一个外部object,独立作用域,如:model=ctrl.employeeInfoForSave
 * fbgsvalue(必须):绑定的model翻班格式值,如:fbgsvalue={{ctrl.employeeInfoForSave.fbgs}}
 * fbgsname(必须):绑定的model翻班格式字段名,如:fbgsname=fbgs
 *
 * required(可选):是否要用required验证
 *
 */
angular.module('ScheduleApp').directive(
    'saFbgsgroup',
    [
        function() {
            return {
                restrict: 'E',
                templateUrl: '/pages/scheduleApp/module/common/dts2/fbgsGroup/saFbgsgroupTemplate.html',
                scope: {
                    model: "=" // 独立作用域,关联外部的模型object
                },
                controllerAs: '$saFbgsgroupCtrl',
                bindToController: true,
                controller: function() {
                    var self = this;

                    self.$$dataSelected = []; // 选中的路牌列表

                    // saFbgsgroup组件的ng-model,用于外部绑定等操作
                    self.$$internalmodel = undefined;
                },

                /**
                 * 此阶段可以改dom结构,此时angular还没扫描指令,
                 * 这里就可以动态添加其他angularjs的指令字符串,如required指令字符串。
                 * @param tElem
                 * @param tAttrs
                 * @returns {{pre: Function, post: Function}}
                 */
                compile: function(tElem, tAttrs) {
                    // 获取所有属性
                    var $name_attr = tAttrs["name"]; // 控件的名字
                    var $required_attr = tAttrs["required"]; // 是否需要required验证
                    var $fbgsname_attr = tAttrs["fbgsname"]; // 绑定的model翻班格式字段名

                    // controlAs名字
                    var ctrlAs = '$saFbgsgroupCtrl';

                    // 如果有required属性,添加angularjs required验证
                    if ($required_attr != undefined) {
                        //console.log(tElem.html());
                        tElem.find("div").attr("required", "");
                    }

                    return {
                        pre: function(scope, element, attr) {

                        },

                        /**
                         * 相当于link函数。
                         * @param scope
                         * @param element
                         * @param attr
                         */
                        post: function(scope, element, attr) {
                            // name属性
                            if ($name_attr) {
                                scope[ctrlAs]["$name_attr"] = $name_attr;
                            }

                            /**
                             * 路牌列表点击(路牌列表中选中路牌)
                             * @param fbcode
                             */
                            scope[ctrlAs].$$internal_fb_click = function(fbcode) {
                                scope[ctrlAs].$$dataSelected.push(fbcode);
                            };

                            /**
                             * 选中的路牌双击(删除选中的路牌)
                             * @param $index
                             */
                            scope[ctrlAs].$$internal_sellplist_dbclick = function($index) {
                                scope[ctrlAs].$$dataSelected.splice($index, 1);
                            };

                            /**
                             * 验证内部数据,更新外部model
                             */
                            scope[ctrlAs].$$internal_validate_model = function() {
                                var data_temp = scope[ctrlAs].$$dataSelected;

                                if (data_temp &&
                                    data_temp.length > 0) {

                                    // 更新内部model,用于外部验证
                                    // 内部model的值暂时随意,以后再改
                                    scope[ctrlAs].$$internalmodel = {desc: "ok"};

                                    // 更新外部model字段
                                    if ($fbgsname_attr) {
                                        console.log("$fbgsname=" + data_temp.join(','));
                                        eval("scope[ctrlAs].model" + "." + $fbgsname_attr + " = data_temp.join(',');");
                                    }

                                } else {
                                    scope[ctrlAs].$$internalmodel = undefined;
                                }
                            };

                            // 监控内部数据,$$data_selected 变化
                            scope.$watch(
                                function() {
                                    return scope[ctrlAs].$$dataSelected;
                                },
                                function(newValue, oldValue) {
                                    scope[ctrlAs].$$internal_validate_model();
                                },
                                true
                            );

                            // 监控路牌名称范围值的变化,处理初始化赋值
                            attr.$observe("fbgsvalue", function(value) {
                                var data_temp = scope[ctrlAs].$$dataSelected;

                                if (value && value != "" && data_temp && data_temp.length == 0) { // 初始创建
                                    var data_temp = scope[ctrlAs].$$dataSelected;
                                    var fbgses = [];
                                    var i = 0;

                                    // 分隔翻班格式
                                    if (value.indexOf(",") >= 0) { // 以逗号分隔,如 1,1,0,1
                                        fbgses = value.split(",");
                                    } else {
                                        for (i = 0; i < value.length; i++) { // 字符串形式,如 1101
                                            fbgses.push(value.substr(i, 1));
                                        }
                                    }

                                    for (i = 0; i < fbgses.length; i++) {
                                        if (fbgses[i] == "1" || fbgses[i] == "0") {
                                            data_temp.push(fbgses[i]);
                                        }
                                    }
                                }
                            });
                        }
                    };
                }
            }
        }
    ]);


/**
 * saGuideboardgroup指令
 * 属性如下:
 * name(必须):控件的名字
 * model(必须):指定一个外部object,独立作用域,如:model=ctrl.employeeInfoForSave
 * xlidvalue(必须):绑定的model线路id值,如:xlidvalue={{ctrl.employeeInfoForSave.xl.id}}
 * lprangevalue(必须):绑定的model路牌名字范围值,如:lprangevalue={{ctrl.employeeInfoForSave.lprange}}
 * lprangename(必须):绑定的model路牌名字范围字段名,如:lprangename=lprange
 * lpidrangevalue(必须):绑定的model路牌id范围值,如:lprangevalue={{ctrl.employeeInfoForSave.lprange}}
 * lpidrangename(必须):绑定的model路牌id范围字段名,如:lprangename=lprange
 * lpstartvalue(必须):绑定的model起始路牌值,如:lpstartvalue={{ctrl.employeeInfoForSave.lpstart}}
 * lpstartname(必须):绑定的model起始路牌字段名,如:lpstartname=lpstart
 *
 * required(可选):是否要用required验证
 *
 */
angular.module('ScheduleApp').directive('saGuideboardgroup', [
    'GuideboardManageService_g',
    function(guideboardManageService_g) {
        return {
            restrict: 'E',
            templateUrl: '/pages/scheduleApp/module/common/dts2/guideboardGroup/saGuideboardgroupTemplate.html',
            scope: {
                model: "=" // 独立作用域,关联外部的模型object
            },
            controllerAs: '$saGuideboardgroupCtrl',
            bindToController: true,
            controller: function($scope) {
                var self = this;
                self.$$dataReal = []; // 选择线路后,该线路的路牌数据
                self.$$data = []; // 页面最多显示10条,可以通过$$searchText筛选

                // 测试数据
                //self.$$data = [
                //    {lpid: 1, lpname: '路1', isstart: false},
                //    {lpid: 2, lpname: '路2', isstart: true},
                //    {lpid: 3, lpname: '路3', isstart: false}
                //];

                self.$$searchText = undefined; // 搜索值
                self.$$dataSelected = []; // 选中的路牌列表
                self.$$dataSelectedStart = undefined; // 起始路牌
                self.$$isAll = false; // 是否显示全部
                self.$$showNumber = 10; // 显示的记录数
                self.$$calcuData = function() { // 处理$$data数据
                    console.log(self.$$searchText);
                    angular.forEach(self.$$dataReal, function(obj) {
                        if (self.$$isAll) { // 显示全部
                            if (self.$$searchText && self.$$searchText != "") { // 有筛选条件
                                if (obj.$fullChars.indexOf(self.$$searchText.toUpperCase()) != -1
                                    || obj.$camelChars.indexOf(self.$$searchText.toUpperCase()) != -1
                                    || obj.lpname.indexOf(self.$$searchText.toUpperCase()) != -1) {
                                    this.push(obj);
                                }
                            } else {
                                this.push(obj);
                            }
                        } else { // 显示限定数量
                            if (this.length < self.$$showNumber) {
                                if (self.$$searchText && self.$$searchText != "") { // 有筛选条件
                                    if (obj.$fullChars.indexOf(self.$$searchText.toUpperCase()) != -1
                                        || obj.$camelChars.indexOf(self.$$searchText.toUpperCase()) != -1
                                        || obj.lpname.indexOf(self.$$searchText.toUpperCase()) != -1) {
                                        this.push(obj);
                                    }
                                } else {
                                    this.push(obj);
                                }
                            }
                        }
                    }, self.$$data);

                };

                //self.$$dataSelected = [
                //    {lpid: 11, lpname: '路11', isstart: false},
                //    {lpid: 12, lpname: '路12', isstart: true},
                //    {lpid: 13, lpname: '路13', isstart: false}
                //];

                // saGuideboardgroup组件的ng-model,用于外部绑定等操作
                self.$$internalmodel = undefined;

                self.$$data_init = false; // *数据源初始化标志
                self.$$data_xl_first_init = false; // 线路是否初始化
                self.$$data_lp_first_init = false; // 路牌名字是否初始化
                self.$$data_lpid_first_init = false; // 路牌id是否初始化
                self.$$data_lpstart_first_init = false; // 起始路牌是否初始化

            },

            /**
             * 此阶段可以改dom结构,此时angular还没扫描指令,
             * 这里就可以动态添加其他angularjs的指令字符串,如required指令字符串。
             * @param tElem
             * @param tAttrs
             * @returns {{pre: Function, post: Function}}
             */
            compile: function(tElem, tAttrs) {
                // TODO:获取所有的属性
                var $name_attr = tAttrs["name"]; // 控件的名字
                var $required_attr = tAttrs["required"]; // 是否需要required验证
                var $lprangename_attr = tAttrs["lprangename"]; // 绑定的model路牌名字范围字段名
                var $lpidrangename_attr = tAttrs["lpidrangename"]; // 绑定的model路牌id范围字段名
                var $lpstartname_attr = tAttrs["lpstartname"]; // 绑定的model起始路牌字段名

                // controlAs名字
                var ctrlAs = '$saGuideboardgroupCtrl';

                // 如果有required属性,添加angularjs required验证
                if ($required_attr != undefined) {
                    //console.log(tElem.html());
                    tElem.find("div").attr("required", "");
                }

                return {
                    pre: function(scope, element, attr) {
                        // TODO:
                    },

                    /**
                     * 相当于link函数。
                     * @param scope
                     * @param element
                     * @param attr
                     */
                    post: function(scope, element, attr) {
                        // name属性
                        if ($name_attr) {
                            scope[ctrlAs]["$name_attr"] = $name_attr;
                        }

                        // 监听搜索框,keydwon,keyup事件
                        tElem.on('keydown', '[name=lpsearch]', function(event) {
                            if (event.keyCode == 13) { // 阻止回车事件造成的form提交
                                return false;
                            }
                        });
                        tElem.on('keyup', '[name=lpsearch]', function() {
                            // 因为在dom事件里修改了model的值,必须写在scope.$apply中,否则页面上绑定效果无
                            // 另一种做法可以写在$watch方法中
                            scope.$apply(function() {
                                scope[ctrlAs].$$data = [];
                                scope[ctrlAs].$$calcuData();

                            });
                        });


                        /**
                         * 路牌列表点击(路牌列表中选中路牌)
                         * @param $index
                         */
                        scope[ctrlAs].$$internal_lplist_click = function($index) {
                            var data_temp = scope[ctrlAs].$$data;
                            if (data_temp && data_temp.length > $index) {
                                scope[ctrlAs].$$dataSelected.push({
                                    lpid: data_temp[$index].lpid,
                                    lpname: data_temp[$index].lpname,
                                    isstart: data_temp[$index].isstart
                                });

                                // 如果没有指定过初始路牌,默认选择此路牌作为起始路牌
                                if (scope[ctrlAs].$$dataSelectedStart == undefined) {
                                    scope[ctrlAs].$$internal_sellplist_click(
                                        scope[ctrlAs].$$dataSelected.length - 1);
                                }
                            }
                        };
                        /**
                         * 选中的路牌单击(初始路牌选择)
                         * @param $index
                         */
                        scope[ctrlAs].$$internal_sellplist_click = function($index) {
                            var data_temp = scope[ctrlAs].$$dataSelected;
                            if (data_temp && data_temp.length > $index) {
                                for (var i = 0; i < data_temp.length; i++) {
                                    data_temp[i].isstart = false;
                                }
                                data_temp[$index].isstart = true;
                                scope[ctrlAs].$$dataSelectedStart = $index;
                            }
                        };
                        /**
                         * 选中的路牌双击(删除选中的路牌)
                         * @param $index
                         */
                        scope[ctrlAs].$$internal_sellplist_dbclick = function($index) {
                            var data_temp = scope[ctrlAs].$$dataSelected;
                            if (data_temp && data_temp.length > $index) {
                                if (scope[ctrlAs].$$dataSelectedStart == $index) {
                                    scope[ctrlAs].$$dataSelectedStart = undefined;
                                }
                                data_temp.splice($index, 1);
                            }
                        };


                        /**
                         * 验证内部数据,更新外部model
                         */
                        scope[ctrlAs].$$internal_validate_model = function() {
                            var data_temp = scope[ctrlAs].$$dataSelected;
                            var data_temp2 = scope[ctrlAs].$$dataSelectedStart;
                            var lpNames = [];
                            var lpIds = [];
                            var lpStart = 0;
                            var i = 0;

                            if (data_temp &&
                                data_temp.length > 0 &&
                                data_temp2 != undefined) {

                                for (i = 0; i < data_temp.length; i++) {
                                    lpNames.push(data_temp[i].lpname);
                                    lpIds.push(data_temp[i].lpid)
                                }
                                data_temp[data_temp2].isstart = true;
                                lpStart = data_temp2 + 1;

                                // 更新内部model,用于外部验证
                                // 内部model的值暂时随意,以后再改
                                scope[ctrlAs].$$internalmodel = {desc: "ok"};

                                // 更新外部model字段
                                if ($lprangename_attr) {
                                    console.log("lprangename=" + lpNames.join(','));
                                    eval("scope[ctrlAs].model" + "." + $lprangename_attr + " = lpNames.join(',');");
                                }
                                if ($lpidrangename_attr) {
                                    console.log("lpidrangename=" + lpIds.join(','));
                                    eval("scope[ctrlAs].model" + "." + $lpidrangename_attr + " = lpIds.join(',');");
                                }
                                if ($lpstartname_attr) {
                                    console.log("lpstartname=" + lpStart);
                                    eval("scope[ctrlAs].model" + "." + $lpstartname_attr + " = lpStart;");
                                }

                            } else {
                                scope[ctrlAs].$$internalmodel = undefined;
                            }


                        };

                        // 监控内部数据,$$data_selected 变化
                        scope.$watch(
                            function() {
                                return scope[ctrlAs].$$dataSelected;
                            },
                            function(newValue, oldValue) {
                                scope[ctrlAs].$$internal_validate_model();
                            },
                            true
                        );

                        // 监控内部数据,$$data_selected_start 变化
                        scope.$watch(
                            function() {
                                return scope[ctrlAs].$$dataSelectedStart;
                            },
                            function(newValue, oldValue) {
                                scope[ctrlAs].$$internal_validate_model();
                            },
                            true
                        );

                        /**
                         * 验证数据是否初始化完成,
                         * 所谓的初始化就是内部所有的数据被有效设定过一次。
                         */
                        scope[ctrlAs].$$internal_validate_init = function() {
                            var self = scope[ctrlAs];

                            if (self.$$data_xl_first_init &&
                                self.$$data_lp_first_init &&
                                self.$$data_lpid_first_init &&
                                self.$$data_lpstart_first_init) {
                                console.log("数据初始化完毕!");
                                self.$$data_init = true;
                            }

                        };

                        // 监控初始化标志,线路,路牌,路牌id,起始路牌
                        scope.$watch(
                            function() {
                                return scope[ctrlAs].$$data_xl_first_init;
                            },
                            function(newValue, oldValue) {
                                scope[ctrlAs].$$internal_validate_init();
                            }
                        );
                        scope.$watch(
                            function() {
                                return scope[ctrlAs].$$data_lp_first_init;
                            },
                            function(newValue, oldValue) {
                                scope[ctrlAs].$$internal_validate_init();
                            }
                        );
                        scope.$watch(
                            function() {
                                return scope[ctrlAs].$$data_lpid_first_init;
                            },
                            function(newValue, oldValue) {
                                scope[ctrlAs].$$internal_validate_init();
                            }
                        );
                        scope.$watch(
                            function() {
                                return scope[ctrlAs].$$data_lpstart_first_init;
                            },
                            function(newValue, oldValue) {
                                scope[ctrlAs].$$internal_validate_init();
                            }
                        );

                        // 监控是否显示所有数据,$$isAll 变化
                        scope.$watch(
                            function() {
                                return scope[ctrlAs].$$isAll;
                            },
                            function(newValue, oldValue) {
                                console.log("dfdfdfdfdf");
                                if (scope[ctrlAs].$$dataReal.length > 0) {
                                    scope[ctrlAs].$$data = [];
                                    scope[ctrlAs].$$calcuData();
                                }
                            },
                            true
                        );

                        // 监控线路id的变化
                        attr.$observe("xlidvalue", function(value) {
                            if (value && value != "") {
                                console.log("xlidvalue=" + value);

                                guideboardManageService_g.rest.list(
                                    {"xl.id_eq": value, size: 100},
                                    function(result) {
                                        // 获取值了
                                        console.log("路牌获取了");

                                        scope[ctrlAs].$$dataReal = [];
                                        angular.forEach(result.content, function(obj) {
                                                this.push({
                                                    lpid: obj.id,
                                                    lpname: obj.lpName,
                                                    isstart: false,
                                                    '$fullChars': pinyin.getFullChars(obj.lpName), // 全拼
                                                    '$camelChars': pinyin.getCamelChars(obj.lpName) // 简拼
                                                });
                                            }, scope[ctrlAs].$$dataReal);

                                        scope[ctrlAs].$$data = [];
                                        scope[ctrlAs].$$calcuData();

                                        if (scope[ctrlAs].$$data_init) {
                                            scope[ctrlAs].$$dataSelected = [];
                                            scope[ctrlAs].$$dataSelectedStart = undefined;
                                            scope[ctrlAs].$$internalmodel = undefined;

                                            scope[ctrlAs].$$searchText = undefined;
                                        }
                                        scope[ctrlAs].$$data_xl_first_init = true;
                                    },
                                    function(result) {

                                    }
                                );

                            }
                        });

                        // 监控路牌名称范围值的变化
                        attr.$observe("lprangevalue", function(value) {
                            if (value && value != "") {
                                var data_temp = scope[ctrlAs].$$dataSelected;
                                var lpnames = value.split(",");
                                var i = 0;
                                if (data_temp && data_temp.length == 0) { // 初始创建
                                    console.log("lprangevalue变换了");
                                    for (i = 0; i < lpnames.length; i++) {
                                        scope[ctrlAs].$$dataSelected.push({
                                            lpname: lpnames[i],
                                            isstart: false
                                        });
                                    }
                                } else {
                                    for (i = 0; i < lpnames.length; i++) {
                                        data_temp[i].lpname = lpnames[i];
                                    }
                                }
                                scope[ctrlAs].$$data_lp_first_init = true;
                            }
                        });

                        // 监控路牌id范围值的变化
                        attr.$observe("lpidrangevalue", function(value) {
                            if (value && value != "") {
                                console.log("lpidrangevalue=" + value);
                                var data_temp = scope[ctrlAs].$$dataSelected;
                                var lpids = value.split(",");
                                var i = 0;
                                if (data_temp && data_temp.length == 0) { // 初始创建
                                    console.log("lpidrangevalue");
                                    for (i = 0; i < lpids.length; i++) {
                                        scope[ctrlAs].$$dataSelected.push({
                                            lpid: lpids[i],
                                            isstart: false
                                        });
                                    }
                                } else {
                                    for (i = 0; i < lpids.length; i++) {
                                        data_temp[i].lpid = lpids[i];
                                    }
                                }
                                scope[ctrlAs].$$data_lpid_first_init = true;
                            }
                        });

                        // 监控起始路牌的变化
                        attr.$observe("lpstartvalue", function(value) {
                            if (value && value != "") {
                                scope[ctrlAs].$$dataSelectedStart = value - 1;
                                scope[ctrlAs].$$data_lpstart_first_init = true;
                            }
                        });



                    }
                }

            }
        }
    }
]);




/**
 * saEmployeegroup指令
 * 属性如下:
 * name(必须):控件的名字
 * model(必须):指定一个外部object,独立作用域,如:model=ctrl.employeeInfoForSave
 * xlidvalue(必须):绑定的model线路id值,如:xlidvalue={{ctrl.employeeInfoForSave.xl.id}}
 * dbbmrangevalue(必须):绑定的model搭班编码范围值,如:lprangevalue={{ctrl.employeeInfoForSave.lprange}}
 * dbbmrangename(必须):绑定的model搭班编码范围字段名,如:lprangename=lprange
 * rycidrangevalue(必须):绑定的model人员配置idid范围值,如:lprangevalue={{ctrl.employeeInfoForSave.lprange}}
 * rycidrangename(必须):绑定的model人员配置id范围字段名,如:lprangename=lprange
 * rystartvalue(必须):绑定的model起始人员,如:lpstartvalue={{ctrl.employeeInfoForSave.lpstart}}
 * rystartname(必须):绑定的model起始人员字段名,如:lpstartname=lpstart
 *
 * required(可选):是否要用required验证
 *
 */
angular.module('ScheduleApp').directive('saEmployeegroup', [
    'EmployeeConfigService_g',
    function(employeeConfigService_g) {
        return {
            restrict: 'E',
            templateUrl: '/pages/scheduleApp/module/common/dts2/employeeGroup/saEmployeegroupTemplate.html',
            scope: {
                model: "=" // 独立作用域,关联外部的模型object
            },
            controllerAs: '$saEmployeegroupCtrl',
            bindToController: true,
            controller: function($scope) {
                var self = this;
                self.$$dataReal = []; // 选择线路后,该线路的人员配置数据
                self.$$data = []; // 页面最多显示10条,可以通过$$searchText筛选

                // 测试数据
                //self.$$data = [
                //    {id: 1, dbbm: "1", jsy: '忍1', spy: '守1'},
                //    {id: 2, dbbm: "2", jsy: '忍2', spy: '守2'},
                //    {id: 3, dbbm: "3", jsy: '忍3', spy: '守3'}
                //];

                self.$$searchText = undefined; // 搜索值
                self.$$dataSelected = []; // 选中的人员配置列表
                self.$$dataSelectedStart = undefined; // 起始人员配置

                //self.$$dataSelected = [
                //    {id: 1, dbbm: "1", jsy: '忍1', spy: '守1', isstart: false},
                //    {id: 2, dbbm: "2", jsy: '忍2', spy: '守2', isstart: true},
                //    {id: 3, dbbm: "3", jsy: '忍3', spy: '守3', isstart: false}
                //];

                self.$$isFB = false; // 是否分班
                self.$$dataFBSelected = []; // 选中的分班人员组配置列表
                self.$$dataFBInternalSelected = undefined; // 分班组内人员选中标识
                self.$$dataFBSelectedStart = undefined; // 选中的起始分班人员组合
                self.$$isAll = false; // 是否显示全部
                self.$$showNumber = 10; // 显示的记录数
                self.$$calcuData = function() { // 处理$$data数据
                    console.log(self.$$searchText);
                    angular.forEach(self.$$dataReal, function(obj) {
                        if (self.$$isAll) { // 显示全部
                            if (self.$$searchText && self.$$searchText != "") { // 有筛选条件
                                if (obj.$fullChars.indexOf(self.$$searchText.toUpperCase()) != -1
                                    || obj.$camelChars.indexOf(self.$$searchText.toUpperCase()) != -1
                                    || obj.$str.indexOf(self.$$searchText.toUpperCase()) != -1) {
                                    this.push(obj);
                                }
                            } else {
                                this.push(obj);
                            }
                        } else { // 显示限定数量
                            if (this.length < self.$$showNumber) {
                                if (self.$$searchText && self.$$searchText != "") { // 有筛选条件
                                    if (obj.$fullChars.indexOf(self.$$searchText.toUpperCase()) != -1
                                        || obj.$camelChars.indexOf(self.$$searchText.toUpperCase()) != -1
                                        || obj.$str.indexOf(self.$$searchText.toUpperCase()) != -1) {
                                        this.push(obj);
                                    }
                                } else {
                                    this.push(obj);
                                }
                            }
                        }
                    }, self.$$data);

                };


                //self.$$dataFBSelected = [
                //    {isstart: true, group: [
                //        {id: 1, dbbm: "1", jsy: '忍1', spy: '守1', isselected: false},
                //        {id: 2, dbbm: "2", jsy: '忍2', spy: '守2', isstart: true}
                //    ]},
                //    {isstart: false, group: [
                //        {id: 1, dbbm: "1", jsy: '忍1', spy: '守1', isselected: false},
                //        {id: 2, dbbm: "2", jsy: '忍2', spy: '守2', isstart: true}
                //    ]}
                //];

                // saGuideboardgroup组件的ng-model,用于外部绑定等操作
                self.$$internalmodel = undefined;

                self.$$data_init = false; // *数据源初始化标志
                self.$$data_xl_first_init = false; // 线路是否初始化
                self.$$data_ry_first_init = false; // 人员配置是否初始化
                self.$$data_ry_first_data = undefined; // 人员配置初始化数据
                self.$$data_rycid_first_init = false; // 人员配置id是否初始化
                self.$$data_rycid_first_data = undefined; // 人员配置id初始化数据
                self.$$data_rystart_first_init = false; // 起始人员是否初始化
                self.$$data_rystart_first_data = undefined; // 起始人员初始化数据

            },

            /**
             * 此阶段可以改dom结构,此时angular还没扫描指令,
             * 这里就可以动态添加其他angularjs的指令字符串,如required指令字符串。
             * @param tElem
             * @param tAttrs
             * @returns {{pre: Function, post: Function}}
             */
            compile: function(tElem, tAttrs) {
                // TODO:获取所有的属性
                var $name_attr = tAttrs["name"]; // 控件的名字
                var $required_attr = tAttrs["required"]; // 是否需要required验证
                var $dbbmrangename_attr = tAttrs["dbbmrangename"]; // 绑定的model搭班编码范围字段名
                var rycidrangename_attr = tAttrs["rycidrangename"]; // 绑定的model人员配置id范围字段名
                var $rystartname_attr = tAttrs["rystartname"]; // 绑定的model起始人员字段名

                // controlAs名字
                var ctrlAs = '$saEmployeegroupCtrl';

                // 如果有required属性,添加angularjs required验证
                if ($required_attr != undefined) {
                    //console.log(tElem.html());
                    tElem.find("div").attr("required", "");
                }

                return {
                    pre: function(scope, element, attr) {
                        // TODO:
                    },

                    /**
                     * 相当于link函数。
                     * @param scope
                     * @param element
                     * @param attr
                     */
                    post: function(scope, element, attr) {
                        // name属性
                        if ($name_attr) {
                            scope[ctrlAs]["$name_attr"] = $name_attr;
                        }

                        // 监听搜索框,keydwon,keyup事件
                        tElem.on('keydown', '[name=rysearch]', function(event) {
                            if (event.keyCode == 13) { // 阻止回车事件造成的form提交
                                return false;
                            }
                        });
                        tElem.on('keyup', '[name=rysearch]', function() {
                            // 因为在dom事件里修改了model的值,必须写在scope.$apply中,否则页面上绑定效果无
                            // 另一种做法可以写在$watch方法中
                            scope.$apply(function() {
                                scope[ctrlAs].$$data = [];
                                scope[ctrlAs].$$calcuData();

                            });
                        });


                        /**
                         * 人员配置列表点击(人员配置列表中选中路牌)
                         * @param $index
                         */
                        scope[ctrlAs].$$internal_rylist_click = function($index) {
                            var data_temp = scope[ctrlAs].$$data;
                            if (data_temp && data_temp.length > $index) {
                                if (!scope[ctrlAs].$$isFB) { // 不分班
                                    scope[ctrlAs].$$dataSelected.push({
                                        id : data_temp[$index].id,
                                        dbbm: data_temp[$index].dbbm,
                                        jsy: data_temp[$index].jsy,
                                        spy: data_temp[$index].spy,
                                        jcode: data_temp[$index].jcode,
                                        scode: data_temp[$index].scode,
                                        isstart: false
                                    });

                                    // 如果没有指定过初始人员,默认选择此人员作为起始人员
                                    if (scope[ctrlAs].$$dataSelectedStart == undefined) {
                                        scope[ctrlAs].$$internal_selrylist_click(
                                            scope[ctrlAs].$$dataSelected.length - 1);
                                    }
                                } else { // 分班
                                    if (scope[ctrlAs].$$dataFBInternalSelected) { // 替换组内人员
                                        scope[ctrlAs].$$dataFBSelected
                                            [scope[ctrlAs].$$dataFBInternalSelected.gindex].group
                                            [scope[ctrlAs].$$dataFBInternalSelected.index] = {
                                            id : data_temp[$index].id,
                                            dbbm: data_temp[$index].dbbm,
                                            jsy: data_temp[$index].jsy,
                                            spy: data_temp[$index].spy,
                                            jcode: data_temp[$index].jcode,
                                            scode: data_temp[$index].scode,
                                            isselected: true
                                        };

                                    } else {
                                        scope[ctrlAs].$$dataFBSelected.push({
                                            isstart: false,
                                            group: [].concat(
                                                {
                                                    id : data_temp[$index].id,
                                                    dbbm: data_temp[$index].dbbm,
                                                    jsy: data_temp[$index].jsy,
                                                    spy: data_temp[$index].spy,
                                                    jcode: data_temp[$index].jcode,
                                                    scode: data_temp[$index].scode,
                                                    isselected: false
                                                }, {
                                                    id : data_temp[$index].id,
                                                    dbbm: data_temp[$index].dbbm,
                                                    jsy: data_temp[$index].jsy,
                                                    spy: data_temp[$index].spy,
                                                    jcode: data_temp[$index].jcode,
                                                    scode: data_temp[$index].scode,
                                                    isselected: false
                                                }
                                            )
                                        });
                                        if (scope[ctrlAs].$$dataFBSelectedStart == undefined) {
                                            scope[ctrlAs].$$internal_selrygrouplist_click(
                                                scope[ctrlAs].$$dataFBSelected.length - 1);
                                        }
                                    }
                                }

                            }
                        };

                        /**
                         * 选中的人员单击(初始人员选择)
                         * @param $index
                         */
                        scope[ctrlAs].$$internal_selrylist_click = function($index) {
                            var data_temp = scope[ctrlAs].$$dataSelected;
                            if (data_temp && data_temp.length > $index) {
                                for (var i = 0; i < data_temp.length; i++) {
                                    data_temp[i].isstart = false;
                                }
                                data_temp[$index].isstart = true;
                                scope[ctrlAs].$$dataSelectedStart = $index;
                            }
                        };
                        /**
                         * 选中的人员双击(删除选中的人员)
                         * @param $index
                         */
                        scope[ctrlAs].$$internal_selrylist_dbclick = function($index) {
                            var data_temp = scope[ctrlAs].$$dataSelected;
                            if (data_temp && data_temp.length > $index) {
                                if (scope[ctrlAs].$$dataSelectedStart == $index) {
                                    scope[ctrlAs].$$dataSelectedStart = undefined;
                                }
                                data_temp.splice($index, 1);
                            }
                        };

                        /**
                         * 选中的分班组人员单击(初始人员选择)
                         * @param $index
                         */
                        scope[ctrlAs].$$internal_selrygrouplist_click = function($index) {
                            var data_temp = scope[ctrlAs].$$dataFBSelected;
                            if (data_temp && data_temp.length > $index) {
                                for (var i = 0; i < data_temp.length; i++) {
                                    data_temp[i].isstart = false;
                                    for (var j = 0; j < data_temp[i].group.length; j++) {
                                        data_temp[i].group[j].isselected = false;
                                    }
                                }
                                data_temp[$index].isstart = true;
                                scope[ctrlAs].$$dataFBSelectedStart = $index;
                                scope[ctrlAs].$$dataFBInternalSelected = undefined;
                            }
                        };
                        /**
                         * 分组内部单击(选中分班中的某组人员)
                         * @param $groupindex 组index
                         * @param $index 组内部某个index
                         * @param $event 事件防止冒泡
                         */
                        scope[ctrlAs].$$internal_selrygroup_click = function($groupindex, $index, $event) {
                            var data_temp = scope[ctrlAs].$$dataFBSelected;
                            if (data_temp && data_temp.length > $groupindex) {
                                if (data_temp[$groupindex].group && data_temp[$groupindex].group.length > $index) {
                                    // $$dataFBInternalSelected的格式如下:
                                    //{gindex: 1, index: 0}
                                    for (var i = 0; i < data_temp.length; i++) {
                                        data_temp[i].isstart = false;
                                        for (var j = 0; j < data_temp[i].group.length; j++) {
                                            data_temp[i].group[j].isselected = false;
                                        }
                                    }
                                    data_temp[$groupindex].group[$index].isselected = true;
                                    scope[ctrlAs].$$dataFBInternalSelected = {
                                        gindex: $groupindex, index: $index
                                    };
                                    scope[ctrlAs].$$dataFBSelectedStart = undefined;
                                    $event.stopPropagation();
                                }
                            }

                        };
                        /**
                         * 选中的分班人员双击(删除选中的人员)
                         * @param $index
                         */
                        scope[ctrlAs].$$internal_selrygrouplist_dbclick = function($index) {
                            var data_temp = scope[ctrlAs].$$dataFBSelected;
                            if (data_temp && data_temp.length > $index) {
                                if (scope[ctrlAs].$$dataFBSelectedStart == $index) {
                                    scope[ctrlAs].$$dataFBSelectedStart = undefined;
                                }
                                if (scope[ctrlAs].$$dataFBInternalSelected &&
                                    scope[ctrlAs].$$dataFBInternalSelected.gindex == $index) {
                                    scope[ctrlAs].$$dataFBInternalSelected = undefined;
                                }
                                data_temp.splice($index, 1);
                            }
                        };

                        /**
                         * 验证内部数据,更新外部model
                         */
                        scope[ctrlAs].$$internal_validate_model = function() {
                            var data_temp = scope[ctrlAs].$$dataSelected;
                            var data_temp2 = scope[ctrlAs].$$dataSelectedStart;
                            var data_temp3 = scope[ctrlAs].$$dataFBSelected;
                            var data_temp4 = scope[ctrlAs].$$dataFBSelectedStart;
                            var ryDbbms = [];
                            var ryDbbm_group = [];
                            var ryCids = [];
                            var ryCid_group = [];
                            var ryStart = 0;
                            var i = 0;
                            var j = 0;

                            var isFB = scope[ctrlAs].$$isFB;

                            if (isFB) {
                                if (data_temp3 &&
                                    data_temp3.length > 0 &&
                                    data_temp4 != undefined) {

                                    for (i = 0; i < data_temp3.length; i++) {
                                        for (j = 0; j < data_temp3[i].group.length; j++) {
                                            ryDbbm_group.push(data_temp3[i].group[j].dbbm);
                                            ryCid_group.push(data_temp3[i].group[j].id);
                                        }
                                        ryDbbms.push(ryDbbm_group.join("-"));
                                        ryCids.push(ryCid_group.join("-"));
                                        ryDbbm_group = [];
                                        ryCid_group = [];
                                    }

                                    data_temp3[data_temp4].isstart = true;
                                    ryStart = data_temp4 + 1;

                                    // 更新内部model,用于外部验证
                                    // 内部model的值暂时随意,以后再改
                                    scope[ctrlAs].$$internalmodel = {desc: "ok"};

                                    // 更新外部model字段
                                    if ($dbbmrangename_attr) {
                                        console.log("dbbmrangename=" + ryDbbms.join(','));
                                        eval("scope[ctrlAs].model" + "." + $dbbmrangename_attr + " = ryDbbms.join(',');");
                                    }
                                    if (rycidrangename_attr) {
                                        console.log("rycidrangename=" + ryCids.join(','));
                                        eval("scope[ctrlAs].model" + "." + rycidrangename_attr + " = ryCids.join(',');");
                                    }
                                    if ($rystartname_attr) {
                                        console.log("rystartname=" + ryStart);
                                        eval("scope[ctrlAs].model" + "." + $rystartname_attr + " = ryStart;");
                                    }

                                } else {
                                    scope[ctrlAs].$$internalmodel = undefined;
                                }

                            } else {
                                if (data_temp &&
                                    data_temp.length > 0 &&
                                    data_temp2 != undefined) {

                                    for (i = 0; i < data_temp.length; i++) {
                                        ryDbbms.push(data_temp[i].dbbm);
                                        ryCids.push(data_temp[i].id);
                                    }
                                    data_temp[data_temp2].isstart = true;
                                    ryStart = data_temp2 + 1;

                                    // 更新内部model,用于外部验证
                                    // 内部model的值暂时随意,以后再改
                                    scope[ctrlAs].$$internalmodel = {desc: "ok"};

                                    // 更新外部model字段
                                    if ($dbbmrangename_attr) {
                                        console.log("dbbmrangename=" + ryDbbms.join(','));
                                        eval("scope[ctrlAs].model" + "." + $dbbmrangename_attr + " = ryDbbms.join(',');");
                                    }
                                    if (rycidrangename_attr) {
                                        console.log("rycidrangename=" + ryCids.join(','));
                                        eval("scope[ctrlAs].model" + "." + rycidrangename_attr + " = ryCids.join(',');");
                                    }
                                    if ($rystartname_attr) {
                                        console.log("rystartname=" + ryStart);
                                        eval("scope[ctrlAs].model" + "." + $rystartname_attr + " = ryStart;");
                                    }

                                } else {
                                    scope[ctrlAs].$$internalmodel = undefined;
                                }
                            }

                        };

                        // 监控内部数据,$$dataSelected 变化
                        scope.$watch(
                            function() {
                                return scope[ctrlAs].$$dataSelected;
                            },
                            function(newValue, oldValue) {
                                scope[ctrlAs].$$internal_validate_model();
                            },
                            true
                        );

                        // 监控内部数据,$$dataSelectedStart 变化
                        scope.$watch(
                            function() {
                                return scope[ctrlAs].$$dataSelectedStart;
                            },
                            function(newValue, oldValue) {
                                scope[ctrlAs].$$internal_validate_model();
                            },
                            true
                        );


                        // 监控内部数据,$$dataFBSelected 变化
                        scope.$watch(
                            function() {
                                return scope[ctrlAs].$$dataFBSelected;
                            },
                            function(newValue, oldValue) {
                                scope[ctrlAs].$$internal_validate_model();
                            },
                            true
                        );

                        // 监控内部数据,$$dataFBSelectedStart 变化
                        scope.$watch(
                            function() {
                                return scope[ctrlAs].$$dataFBSelectedStart;
                            },
                            function(newValue, oldValue) {
                                scope[ctrlAs].$$internal_validate_model();
                            },
                            true
                        );

                        // 监控内部数据,$$dataFBInternalSelected 变化
                        scope.$watch(
                            function() {
                                return scope[ctrlAs].$$dataFBInternalSelected;
                            },
                            function(newValue, oldValue) {
                                scope[ctrlAs].$$internal_validate_model();
                            },
                            true
                        );

                        // 监控内部数据,$$isFB 变化
                        scope.$watch(
                            function() {
                                return scope[ctrlAs].$$isFB;
                            },
                            function(newValue, oldValue) {
                                scope[ctrlAs].$$internal_validate_model();
                            },
                            true
                        );

                        /**
                         * 验证数据是否初始化完成,
                         * 所谓的初始化就是内部所有的数据被有效设定过一次。
                         */
                        scope[ctrlAs].$$internal_validate_init = function() {
                            var self = scope[ctrlAs];
                            var data_temp = self.$$dataReal;
                            var dataSelect_temp = self.$$dataSelected;
                            var dataFBSelect_temp = self.$$dataFBSelected;
                            var dbbmnames = null;
                            var dbbmnamegroup = null;
                            var rycids = null;
                            var rycidgroup = null;

                            var i = 0;
                            var j = 0;
                            var k = 0;

                            if (self.$$data_xl_first_init &&
                                self.$$data_ry_first_init &&
                                self.$$data_rycid_first_init &&
                                self.$$data_rystart_first_init && !self.$$data_init) {
                                console.log("开始初始化数据");

                                // 判定是否分班,字符串中包含-就是了
                                if (self.$$data_ry_first_data.indexOf("-") != -1 && dataFBSelect_temp.length == 0) { // 分班
                                    self.$$isFB = true;

                                    // 搭班编码、人员配置id
                                    dbbmnames = self.$$data_ry_first_data.split(",");
                                    rycids = self.$$data_rycid_first_data.split(",");
                                    for (i = 0; i < dbbmnames.length; i++) {
                                        dataFBSelect_temp.push({
                                            group: [],
                                            isstart: false
                                        });
                                        dbbmnamegroup = dbbmnames[i].split("-");
                                        rycidgroup = rycids[i].split("-");

                                        for (k = 0; k < dbbmnamegroup.length; k++) {
                                            dataFBSelect_temp[i].group.push({
                                                id: rycidgroup[k],
                                                dbbm: dbbmnamegroup[k],
                                                isselected: false
                                            });

                                            for (j = 0; j < data_temp.length; j++) {
                                                if (dataFBSelect_temp[i].group[k].dbbm == data_temp[j].dbbm) {
                                                    dataFBSelect_temp[i].group[k].jsy = data_temp[j].jsy;
                                                    dataFBSelect_temp[i].group[k].spy = data_temp[j].spy;
                                                    dataFBSelect_temp[i].group[k].jcode = data_temp[j].jcode;
                                                    dataFBSelect_temp[i].group[k].scode = data_temp[j].scode;
                                                    break;
                                                }
                                            }
                                        }

                                    }

                                    // 初始人员
                                    scope[ctrlAs].$$dataFBSelectedStart = self.$$data_rystart_first_data - 1;


                                } else if (dataSelect_temp.length == 0) {
                                    self.$$isFB = false;

                                    // 搭班编码、人员配置id
                                    dbbmnames = self.$$data_ry_first_data.split(",");
                                    rycids = self.$$data_rycid_first_data.split(",");
                                    for (i = 0; i < dbbmnames.length; i++) {
                                        dataSelect_temp.push({
                                            id: rycids[i],
                                            dbbm: dbbmnames[i],
                                            isstart: false
                                        });
                                        for (j = 0; j < data_temp.length; j++) {
                                            if (dataSelect_temp[i].dbbm == data_temp[j].dbbm) {
                                                dataSelect_temp[i].jsy = data_temp[j].jsy;
                                                dataSelect_temp[i].spy = data_temp[j].spy;
                                                dataSelect_temp[i].jcode = data_temp[j].jcode;
                                                dataSelect_temp[i].scode = data_temp[j].scode;
                                                break;
                                            }
                                        }
                                    }
                                    // 初始人员
                                    scope[ctrlAs].$$dataSelectedStart = self.$$data_rystart_first_data - 1;

                                }

                                console.log("数据初始化完毕!");
                                self.$$data_init = true;
                            }

                        };

                        // 监控初始化标志,线路,人员,起始人员
                        scope.$watch(
                            function() {
                                return scope[ctrlAs].$$data_xl_first_init;
                            },
                            function(newValue, oldValue) {
                                scope[ctrlAs].$$internal_validate_init();
                            }
                        );
                        scope.$watch(
                            function() {
                                return scope[ctrlAs].$$data_ry_first_init;
                            },
                            function(newValue, oldValue) {
                                scope[ctrlAs].$$internal_validate_init();
                            }
                        );
                        scope.$watch(
                            function() {
                                return scope[ctrlAs].$$data_rycid_first_init;
                            },
                            function(newValue, oldValue) {
                                scope[ctrlAs].$$internal_validate_init();
                            }
                        );
                        scope.$watch(
                            function() {
                                return scope[ctrlAs].$$data_rystart_first_init;
                            },
                            function(newValue, oldValue) {
                                scope[ctrlAs].$$internal_validate_init();
                            }
                        );

                        // 监控是否显示所有数据,$$isAll 变化
                        scope.$watch(
                            function() {
                                return scope[ctrlAs].$$isAll;
                            },
                            function(newValue, oldValue) {
                                console.log("dfdfdfdfdf");
                                if (scope[ctrlAs].$$dataReal.length > 0) {
                                    scope[ctrlAs].$$data = [];
                                    scope[ctrlAs].$$calcuData();
                                }
                            },
                            true
                        );


                        // 监控线路id的变化
                        attr.$observe("xlidvalue", function(value) {
                            if (value && value != "") {
                                console.log("xlidvalue=" + value);

                                employeeConfigService_g.rest.list(
                                    {"xl.id_eq": value, "isCancel_eq" : false, "ryDestroyStatus_eq" : 0, size: 200},
                                    function(result) {
                                        // 获取值了
                                        console.log("人员配置获取了");

                                        scope[ctrlAs].$$dataReal = [];
                                        angular.forEach(result.content, function(obj) {
                                            var n1 = obj.jsy == null ? "" : (obj.jsy.personnelName || "");
                                            var n2 = obj.spy == null ? "" : (obj.spy.personnelName || "");
                                            //var n3 = obj.dbbm || "";
                                            var c1 = obj.jsy == null ? "" : (obj.jsy.jobCode || "");
                                            var c2 = obj.spy == null ? "" : (obj.spy.jobCode || "");

                                            if (c1.indexOf("-") > 0) {
                                                c1 = c1.substr(3);
                                            }
                                            if (c2.indexOf("-") > 0) {
                                                c2 = c2.substr(3);
                                            }

                                            var str = [];
                                            str.push(n1);
                                            str.push(n2);
                                            //str.push(n3);
                                            str.push(c1);
                                            str.push(c2);
                                            this.push({
                                                id: obj.id,
                                                dbbm: obj.dbbm,
                                                jsy: n1,
                                                spy: n2,
                                                jcode: c1,
                                                scode: c2,
                                                '$fullChars': pinyin.getFullChars(str.join("-")), // 全拼
                                                '$camelChars': pinyin.getCamelChars(str.join("-")), // 简拼
                                                '$str': str.join("-")
                                            });
                                        }, scope[ctrlAs].$$dataReal);

                                        scope[ctrlAs].$$data = [];
                                        scope[ctrlAs].$$calcuData();

                                        if (scope[ctrlAs].$$data_init) {
                                            scope[ctrlAs].$$dataSelected = [];
                                            scope[ctrlAs].$$dataSelectedStart = undefined;

                                            scope[ctrlAs].$$dataFBSelected = [];
                                            scope[ctrlAs].$$dataFBInternalSelected = undefined;
                                            scope[ctrlAs].$$dataFBSelectedStart = undefined;

                                            scope[ctrlAs].$$internalmodel = undefined;

                                            scope[ctrlAs].$$searchText = undefined;
                                        }
                                        scope[ctrlAs].$$data_xl_first_init = true;
                                    },
                                    function(result) {

                                    }
                                );

                            }
                        });

                        // 监控搭班编码范围值的变化
                        attr.$observe("dbbmrangevalue", function(value) {
                            if (value && value != "") {
                                console.log("dbbmrangevalue变换了");
                                scope[ctrlAs].$$data_ry_first_init = true;
                                scope[ctrlAs].$$data_ry_first_data = value;
                            }
                        });

                        // 监控人员配置id范围值的变化
                        attr.$observe("rycidrangevalue", function(value) {
                            if (value && value != "") {
                                console.log("rycidrangevalue变换了");
                                scope[ctrlAs].$$data_rycid_first_init = true;
                                scope[ctrlAs].$$data_rycid_first_data = value;
                            }
                        });

                        // 监控起始人员的变化
                        attr.$observe("rystartvalue", function(value) {
                            if (value && value != "") {
                                console.log("rystartvalue变换了");
                                scope[ctrlAs].$$data_rystart_first_init = true;
                                scope[ctrlAs].$$data_rystart_first_data = value;
                            }
                        });

                    }
                }

            }
        }
    }
]);


/**
 * saBcgroup指令,用于套跑界面中,从指定线路,指定时刻表,指定路牌的班次列表中选择套跑班次。
 * 属性如下:
 * name(必须):控件的名字
 * model(必须):指定一个外部object,独立作用域,如:model=ctrl.employeeInfoForSave
 * bcttinfoidsvalue(必须):绑定的model班次ids字段值,如:bcttinfoidsvalue={{ctrl.employeeInfoForSave.lprange}}
 * bcttinfoidsname(必须):bind的model班次ids字段名,如:bcttinfoidsname=lprange
 * bcttinfofcsjs(必须):bind的model班次发车时间s字段名
 * dataparams (必须):内部数据关联的查询参数,如:{{ {'ttid': ctrl.rerunManageForSave.rerunTtinfo.id} | json }}
 * required(可选):是否要用required验证
 *
 */
angular.module('ScheduleApp').directive('saBcgroup', [
    'TimeTableDetailManageService_g',
    function(timeTableDetailManageService_g) {
        return {
            restrict: 'E',
            templateUrl: '/pages/scheduleApp/module/common/dts2/bcGroup/saBcgroupTemplate.html',
            scope: {
                model: "=" // 独立作用域,关联外部的模型object
            },
            controllerAs: '$saBcgroupCtrl',
            bindToController: true,
            controller: function($scope) {
                var self = this;
                self.$$data = []; // 选择线路,时刻表,路牌后的班次列表

                // 测试数据
                //self.$$data = [
                //    {bcttinfoid: 1, bcfcsj: '7:30', bctype: 'out'},
                //    {bcttinfoid: 2, bcfcsj: '8:30', bctype: 'normal'},
                //    {bcttinfoid: 3, bcfcsj: '9:30', bctype: 'in'}
                //];


                self.$$dataSelected = []; // 套跑选中的班次列表

                //self.$$dataSelected = [
                //    {bcttinfoid: 1, bcfcsj: '7:30', bctype: 'out'},
                //    {bcttinfoid: 2, bcfcsj: '8:30', bctype: 'normal'},
                //    {bcttinfoid: 3, bcfcsj: '9:30', bctype: 'in'}
                //];

                // saBcgroup组件的ng-model,用于外部绑定等操作
                self.$$internalmodel = undefined;

                self.$$data_bcdata_first_init = false; // 班次数据首次初始化标志
                self.$$data_bcttinfoids_first_init = false; // 班次ids数据首次初始化标志
                self.$$data_bcttinfoids_first_data = undefined; // 班次ids数据首次初始化数据

            },

            /**
             * 此阶段可以改dom结构,此时angular还没扫描指令,
             * 这里就可以动态添加其他angularjs的指令字符串,如required指令字符串。
             * @param tElem
             * @param tAttrs
             * @returns {{pre: Function, post: Function}}
             */
            compile: function(tElem, tAttrs) {
                // TODO:获取所有的属性
                var $name_attr = tAttrs["name"]; // 控件的名字
                var $required_attr = tAttrs["required"]; // 是否需要required验证
                var $bcttinfoidsname_attr = tAttrs["bcttinfoidsname"]; // bind的model班次ids字段名
                var $bcttinfofcsjs_attr = tAttrs["bcttinfofcsjs"]; // bind的model班次发车时间s字段名

                // controlAs名字
                var ctrlAs = '$saBcgroupCtrl';

                // 如果有required属性,添加angularjs required验证
                if ($required_attr != undefined) {
                    //console.log(tElem.html());
                    tElem.find("div").attr("required", "");
                }

                return {
                    pre: function(scope, element, attr) {
                        // TODO:
                    },

                    /**
                     * 相当于link函数。
                     * @param scope
                     * @param element
                     * @param attr
                     */
                    post: function(scope, element, attr) {
                        // name属性
                        if ($name_attr) {
                            scope[ctrlAs]["$name_attr"] = $name_attr;
                        }

                        // TODO:


                        /**
                         * 班次列表点击(班次列表中选中班次)
                         * @param $index
                         */
                        scope[ctrlAs].$$internal_bclist_click = function($index) {
                            var data_temp = scope[ctrlAs].$$data;
                            var data_temp2 = scope[ctrlAs].$$dataSelected;
                            var i = 0;
                            var isunique = true; // 是否已经选择过
                            if (data_temp && data_temp.length > $index) {
                                for (i = 0; i < data_temp2.length; i++) {
                                    if (data_temp2[i].bcttinfoid == data_temp[$index].bcttinfoid) {
                                        isunique = false;
                                        break;
                                    }
                                }
                                if (isunique) {
                                    data_temp2.push({
                                        bcttinfoid: data_temp[$index].bcttinfoid,
                                        bcfcsj: data_temp[$index].bcfcsj,
                                        bctype: data_temp[$index].bctype
                                    });
                                }

                            }
                        };
                        /**
                         * 选中的班次双击(删除选中的班次)
                         * @param $index
                         */
                        scope[ctrlAs].$$internal_selbclist_dbclick = function($index) {
                            var data_temp = scope[ctrlAs].$$dataSelected;
                            if (data_temp && data_temp.length > $index) {
                                data_temp.splice($index, 1);
                            }
                        };


                        /**
                         * 验证内部数据,更新外部model
                         */
                        scope[ctrlAs].$$internal_validate_model = function() {
                            var data_temp = scope[ctrlAs].$$dataSelected;
                            var bcttinfoIds = [];
                            var bcttinfofscjs = [];
                            var i = 0;

                            if (data_temp &&
                                data_temp.length > 0) {

                                for (i = 0; i < data_temp.length; i++) {
                                    bcttinfoIds.push(data_temp[i].bcttinfoid);
                                    bcttinfofscjs.push(data_temp[i].bcfcsj);
                                }

                                // 更新外部model字段
                                if ($bcttinfoidsname_attr) {
                                    console.log("bcttinfoidsname=" + bcttinfoIds.join(','));
                                    eval("scope[ctrlAs].model" + "." + $bcttinfoidsname_attr + " = bcttinfoIds.join(',');");
                                }
                                if ($bcttinfofcsjs_attr) {
                                    eval("scope[ctrlAs].model" + "." + $bcttinfofcsjs_attr + " = bcttinfofscjs.join(',');");
                                }

                                // 更新内部model,用于外部验证
                                // 内部model的值暂时随意,以后再改
                                scope[ctrlAs].$$internalmodel = {desc: "ok"};

                                scope[ctrlAs].$$data_bcdata_first_init = true;
                                scope[ctrlAs].$$data_bcttinfoids_first_init = true;

                            } else {
                                scope[ctrlAs].$$internalmodel = undefined;
                            }

                        };

                        // 监控内部数据,$$data_selected 变化
                        scope.$watch(
                            function() {
                                console.log("长度:" + scope[ctrlAs].$$dataSelected.length);
                                return scope[ctrlAs].$$dataSelected;
                            },
                            function(newValue, oldValue) {
                                scope[ctrlAs].$$internal_validate_model();
                            },
                            true
                        );

                        /**
                         * 验证数据是否初始化完成,
                         * 所谓的初始化就是内部所有的数据被有效设定过一次。
                         */
                        scope[ctrlAs].$$internal_validate_init = function() {
                            var self = scope[ctrlAs];

                            var data_temp = self.$$data;
                            var dataSelect_temp = self.$$dataSelected;
                            var bcttinfoids = null;

                            var i = 0;
                            var j = 0;

                            if (self.$$data_bcdata_first_init &&
                                self.$$data_bcttinfoids_first_init) {
                                console.log("开始初始化数据");

                                bcttinfoids = self.$$data_bcttinfoids_first_data ? self.$$data_bcttinfoids_first_data.split(",") : [];

                                for (i = 0; i < bcttinfoids.length; i++) {
                                    dataSelect_temp.push({
                                        bcttinfoid: bcttinfoids[i]
                                    });
                                    for (j = 0; j < data_temp.length; j++) {
                                        if (dataSelect_temp[i].bcttinfoid == data_temp[j].bcttinfoid) {
                                            dataSelect_temp[i].bcfcsj = data_temp[j].bcfcsj;
                                            dataSelect_temp[i].bctype = data_temp[j].bctype;
                                            break;
                                        }
                                    }
                                }

                                console.log("数据初始化完毕!");
                            }

                        };

                        // 监控初始化标志
                        scope.$watch(
                            function() {
                                return scope[ctrlAs].$$data_bcdata_first_init;
                            },
                            function(newValue, oldValue) {
                                scope[ctrlAs].$$internal_validate_init();
                            }
                        );
                        scope.$watch(
                            function() {
                                return scope[ctrlAs].$$data_bcttinfoids_first_init;
                            },
                            function(newValue, oldValue) {
                                scope[ctrlAs].$$internal_validate_init();
                            }
                        );

                        // 监控内部数据的变化
                        attr.$observe("dataparams", function(value) {
                            if (value && value != "") {
                                if (value == '{}') {
                                    return;
                                }

                                console.log("bcgroup observe 监控 dataparams=" + value);

                                timeTableDetailManageService_g.bcdetails.list(
                                    JSON.parse(value),
                                    function(result) {
                                        // 获取值了
                                        console.log("内部班次数据获取了");

                                        scope[ctrlAs].$$data = [];
                                        for (var i = 0; i < result.length; i++) {
                                            scope[ctrlAs].$$data.push({
                                                bcttinfoid: result[i].id,
                                                bcfcsj: result[i].fcsj,
                                                bctype: result[i].bcType
                                            });
                                        }
                                        if (scope[ctrlAs].$$data_bcdata_first_init &&
                                            scope[ctrlAs].$$data_bcttinfoids_first_init) {

                                            scope[ctrlAs].$$dataSelected = [];
                                            scope[ctrlAs].$$internalmodel = undefined;
                                        }
                                        scope[ctrlAs].$$data_bcdata_first_init = true;
                                    },
                                    function(result) {

                                    }
                                );
                            }
                        });
                        // 监控班次ids数据的变化
                        attr.$observe("bcttinfoidsvalue", function(value) {
                            if (value && value != "") {
                                console.log("observe 监控 bcttinfoidsvalue=" + value);
                                scope[ctrlAs].$$data_bcttinfoids_first_init = true;
                                scope[ctrlAs].$$data_bcttinfoids_first_data = value;
                            }
                        });

                    }
                }

            }
        }
    }
]);
/**
 * saTimeTable指令,时刻表显示指令,excel表格形式,支持菜单,事件处理。
 * name(必须),控件的名字
 * celldbclickFn,单元格双击事件
 * lpbxdbclickFn,路牌班型单元双击事件
 * ds,外部数据源
 *
 * TODO:优化开发中
 *
 */

angular.module('ScheduleApp').factory(
    'SaTimeTableUtils',
    [
        function() {
            // 内部班次信息类
            // detailInfo是后台返回的数据,格式如下:
            // {"ttdid":null,"fcsj":"3/17.10","bc_type":null,"xldir":null,"isfb":false,"qdz":null,"zdz":null,"tcc":null}
            var BcInfo = function(detailInfo) {
                this.ttdid = detailInfo && detailInfo.ttdid; // 时刻表id
                this.fcsj = detailInfo && detailInfo.fcsj; // 发车时间
                this.bc_type = detailInfo && detailInfo.bc_type; // 班次类型
                this.xldir = detailInfo && detailInfo.xldir; // 线路上下行
                this.ists = detailInfo && detailInfo.ists; // 是否停驶
                this.isfb = detailInfo && detailInfo.isfb; // 是否分班
                this.qdzCode = detailInfo && detailInfo.qdzCode; // 起点站Code
                this.zdzCode = detailInfo && detailInfo.zdzCode; // 终点站Code
                this.bcsj = detailInfo && detailInfo.bcsj; // 班次历时

                // 路牌信息
                this.lpId = undefined; // id
                this.lpName = undefined; // 名字

                // 发车序号,班次数
                this.fcno = undefined;
                this.bcs = undefined;

                this.sel = false; // 是否被选中

                // 其余函数判定的内部保存值
                this.isCanSel = false; // 是否能被选择
                this.isInValid = false; // 数据是否无效

            };
            BcInfo.prototype.canUpdate = function() { // 是否能更新
                if (this.sel && this.ttdid) {
                    return true;
                } else {
                    return false;
                }
            };
            BcInfo.prototype.canDelete = function() { // 是否能删除
                if (this.sel && this.ttdid) {
                    return true;
                } else {
                    return false;
                }
            };
            BcInfo.prototype.canSel = function() { // 是否能选中
                if (this.ttdid) {
                    this.isCanSel = true;
                    return true;
                } else if (this.fcsj) {
                    // 没有ttdid,有fcsj标识,
                    // 由于是后台返回数据的格式,这种就是路牌和汇总信息,不能选中
                    this.isCanSel = false;
                    return false;
                } else {
                    // 都是空的,表示是一个空班次,可以选中
                    this.isCanSel = true;
                    return true;
                }
            };
            BcInfo.prototype.validInfo = function() { // 验证班次信息内容是否正确
                if (this.canSel() && this.ttdid) {
                    if (!this.qdzCode || // 起点站编码为空判定
                        !this.zdzCode || // 终点站编码为空判定
                        (!this.bcsj && this.bcsj !== 0)) { // 班次历时为空判定
                        this.isInValid = true;
                    } else {
                        this.isInValid = false;
                    }
                } else {
                    this.isInValid = false;
                }
            };

            BcInfo.prototype.where = function(xldir, startTime_h_m, endTime_h_m, isInOut) { // 判定班次是否在指定条件内
                var fcsj_m_h = [];
                fcsj_m_h[0] = parseInt(this.fcsj.split(":")[0]);
                fcsj_m_h[1] = parseInt(this.fcsj.split(":")[1]);

                var fcsj = new Date(2000,1,1);
                fcsj.setHours(fcsj_m_h[0]);
                fcsj.setMinutes(fcsj_m_h[1]);

                var s_temp_date = new Date(2000, 1, 1);
                var e_temp_date = new Date(2000, 1, 1);

                if (xldir == 2) { // 上下行
                    // 判定是否要进出场班次
                    if (isInOut == false && (this.bc_type == "in" || this.bc_type == "out")) {
                        return false;
                    }

                    if (startTime_h_m) {
                        if (endTime_h_m) {
                            s_temp_date.setHours(startTime_h_m[0]);
                            s_temp_date.setMinutes(startTime_h_m[1]);
                            e_temp_date.setHours(endTime_h_m[0]);
                            e_temp_date.setMinutes(endTime_h_m[1]);
                            return fcsj >= s_temp_date && fcsj <= e_temp_date;
                        } else {
                            s_temp_date.setHours(startTime_h_m[0]);
                            s_temp_date.setMinutes(startTime_h_m[1]);
                            return fcsj >= s_temp_date;
                        }
                    } else {
                        if (endTime_h_m) {
                            e_temp_date.setHours(endTime_h_m[0]);
                            e_temp_date.setMinutes(endTime_h_m[1]);
                            return fcsj <= e_temp_date;
                        } else {
                            return false;
                        }
                    }
                } else {
                    // 判定是否要进出场班次
                    if (isInOut == false && (this.bc_type == "in" || this.bc_type == "out")) {
                        return false;
                    }

                    if (xldir == this.xldir) {
                        if (startTime_h_m) {
                            if (endTime_h_m) {
                                s_temp_date.setHours(startTime_h_m[0]);
                                s_temp_date.setMinutes(startTime_h_m[1]);
                                e_temp_date.setHours(endTime_h_m[0]);
                                e_temp_date.setMinutes(endTime_h_m[1]);
                                return fcsj >= s_temp_date && fcsj <= e_temp_date;
                            } else {
                                s_temp_date.setHours(startTime_h_m[0]);
                                s_temp_date.setMinutes(startTime_h_m[1]);
                                return fcsj >= s_temp_date;
                            }
                        } else {
                            if (endTime_h_m) {
                                e_temp_date.setHours(endTime_h_m[0]);
                                e_temp_date.setMinutes(endTime_h_m[1]);
                                return fcsj <= e_temp_date;
                            } else {
                                return true;
                            }
                        }
                    } else {
                        return false;
                    }
                }
            };

            return {
                createBcInfo: function(detailInfo, lpDetailInfo) {
                    var bcInfo = new BcInfo(detailInfo);
                    if (!bcInfo.ttdid && bcInfo.fcsj && bcInfo.fcsj.indexOf('_') > 0) {
                        var temp_info = bcInfo.fcsj.split('_');
                        // 添加信息的属性
                        bcInfo.lpName = temp_info[1];
                        bcInfo.lpId = temp_info[0];
                        // 修改fcsj为路牌名字
                        bcInfo.fcsj = bcInfo.lpName;
                    }

                    // 重新设定路牌信息
                    if (!bcInfo.lpId) {
                        bcInfo.lpId = lpDetailInfo.lpId;
                        bcInfo.lpName = lpDetailInfo.lpName;
                    }

                    return bcInfo;
                },

                /**
                 * 创建班型信息。
                 * @param bcInfo new BcInfo
                 */
                createBxInfo: function(bcInfo) {
                    var bxInfo = {};
                    bxInfo.xl = {};
                    bxInfo.ttinfo = {};
                    bxInfo.lp = {};
                    bxInfo.lp.id = bcInfo && bcInfo.lpId;
                    bxInfo.lp.lpName = bcInfo && bcInfo.lpName;
                    bxInfo.bxType1 = "_null_";
                    bxInfo.bxType2 = "_null_";
                    bxInfo.gs = "0";
                    bxInfo.bxPds = "0";

                    return bxInfo;
                },

                // TODO:
                initTTInfoDetail: function(formobj, cellinfo, colinfo, xlid, xlname, ttid, ttname) {
                    formobj.xl = {};
                    formobj.xl.id = xlid;
                    formobj.xl.name = xlname;
                    formobj.ttinfo = {};
                    formobj.ttinfo.id = ttid;
                    formobj.ttinfo.name = ttname;
                    formobj.lp = {};
                    formobj.lp.id = cellinfo.lpId;
                    formobj.lp.lpName = cellinfo.lpName;
                    formobj.fcno = cellinfo.fcno;
                    formobj.bcs = cellinfo.bcs;
                    formobj.isFB = cellinfo.isfb;
                    formobj.isTS = 0;

                    formobj.bcType = colinfo.bc_type;
                    formobj.xlDir = colinfo.xldir;

                    formobj.qdzCode = colinfo.qdzCode;
                    formobj.zdzCode = colinfo.zdzCode;

                }
            };
        }
    ]
);

angular.module('ScheduleApp').directive(
    'saTimetable',
    [
        '$compile',
        '$window',
        '$timeout',
        function($compile, $window, $timeout) {
            return {
                restrict: 'E',
                templateUrl: '/pages/scheduleApp/module/common/dts2/ttinfotable/saTimeTableTemplate.html',
                scope: { // 独立作用域
                    // 注意:数据暂时从外部ngModel里获取,以后内部自己处理
                    ds: "=ngModel",
                    celldbclickFn: "&celldbclick",
                    lpbxdbclickFn: "&lpbxdbclick"

                    // TODO:

                },
                controllerAs: "$saTimeTableCtrl",
                bindToController: true,
                controller: function() {
                    var self = this;
                    this.$$headToolTip = ""; // 表头tooltip信息

                    // TODO:
                },

                /**,
                 * compile阶段,angular还没有编译模版,根据需要可以修改模版dom
                 * @param tElem
                 * @param tAttrs
                 * @returns {{pre: Function, post: Function}}
                 */
                compile: function(tElem, tAttrs) {
                    // 获取属性
                    var $attr_name = tAttrs["name"]; // 控件的名字
                    if (!$attr_name) {
                        throw new Error("saTimeTable指令 name属性required");
                    }
                    var $attr_celldbclick = tAttrs["celldbclick"]; // 单元格双击事件名

                    // 内部controlAs名字
                    var ctrlAs = '$saTimeTableCtrl';

                    // 当前选中的cell
                    var startRowIndex = undefined;
                    var startColIndex = undefined;
                    var shiftKey = false; // shift键是否被按住
                    var ctrlKey = false; // ctrl是否被按住
                    // shift选中的cell
                    var shiftCells = [];

                    // TODO:

                    // 监听滚动条事件
                    //console.log(tElem.find('.tt_table').html());
                    //tElem.on('scroll', '.tt_table', function() {
                    //    // 因为在dom事件里修改了model的值,必须写在scope.$apply中,否则页面上绑定效果无
                    //    // 另一种做法可以写在$watch方法中
                    //    console.log("ssssssssssss......");
                    //});

                    return {
                        pre: function(scope, element, attr) {
                            // TODO:
                            //alert(element.find("#tooltipTest").html());
                            //$compile(element.find("#tooltipTest"))(scope);

                        },
                        post: function(scope, element, attr) {
                            // TODO:

                            // ------------------- dom事件处理function -----------------//
                            scope[ctrlAs].$$cell_click = function(rowindex, colindex, cell) {
                                console.log("click " + "row=" + rowindex + ",col=" + colindex);
                                var internal_ds = scope[ctrlAs].ds.detailInfos;

                                if (cell.canSel()) { // 是班次的单元格才能操作
                                    cell.sel = !cell.sel;
                                }

                            };
                            scope[ctrlAs].$$cell_dbclick = function(rowindex, colindex, cell) {
                                if (cell.canSel()) { // 是班次的单元格才能操作
                                    if ($attr_celldbclick) {
                                        // 注意调用方法
                                        scope[ctrlAs].celldbclickFn()(rowindex, colindex);
                                    }
                                }
                            };
                            scope[ctrlAs].$$bx_cell_dbclick = function(rowindex) {
                                scope[ctrlAs].lpbxdbclickFn()(rowindex);
                            };

                            // ------------------- 监控function ------------------//
                            // 监控明细数据,生成表头的tooltip
                            scope.$watch(
                                function() {
                                    return scope[ctrlAs].ds;
                                },
                                function(newValue, oldValue) {
                                    if (newValue &&
                                        newValue.detailHeads &&
                                        newValue.detailHeads.length > 0) {
                                        var tooltip = [];
                                        tooltip.push("出场");
                                        angular.forEach(newValue.detailHeads, function(value) {
                                            if (value != "出场" &&
                                                value != "路牌" &&
                                                value != "进场" &&
                                                value != "空驶班次/空驶里程" &&
                                                value != "运营班次/运营里程" ) {
                                                var exist = false;
                                                angular.forEach(tooltip, function(tip) {
                                                    if (tip == value) {
                                                        exist = true;
                                                    }
                                                });
                                                if (!exist) {
                                                    tooltip.push(value);
                                                }
                                            }
                                        });
                                        tooltip.push("进场");
                                        scope[ctrlAs].$$headToolTip = tooltip.join(",");
                                    }
                                },
                                true
                            );

                            // 5、全部载入后,输入的
                            $timeout(function() {
                                console.log("宽度宽度:" + element.find(".tt_table_head").width());
                            }, 0);
                        }
                    };
                }

            };
        }
    ]
);

/**
 * saTimetablePreview指令,时刻表预览模式视图。
 */
angular.module("ScheduleApp").directive(
    "saTimetable2",
    [
        '$timeout',
        function($timeout) {
            return {
                restrict : 'E',
                templateUrl : '/pages/scheduleApp/module/common/dts2/ttinfotable/saTimeTablePreViewTemplate.html',
                scope : { // 独立作用域
                    // 使用外部数据源,内部重新组合显示
                    ds : "=ngModel"
                },
                controllerAs : "$saTimeTablePreviewCtrl",
                bindToController: true,
                controller : function() {
                    var self = this;

                    // 内部班次时刻模型
                    self.internalBcModel = {
                        up_qdz_name : "", // 上行起点站名字
                        down_qdz_name : "", // 下行起点站名字
                        up_bc_list_asc : [], // 上行班次列表(按照发车时间升序)
                        down_bc_list_asc : [] // 下行班次列表(按照发车时间升序)
                    };

                    // 内部各个路牌block车次链模型
                    self.internalLpBlockModel = {
                        // key:路牌名字
                        // value: 数组(按照发车时间排序)
                        // value 数据内对象 {fcsj:发车时间,isUp:是否上行,fcno:发车顺序号,index:对应的班次列表索引}
                    };

                    // TODO:
                },

                /**,
                 * compile阶段,angular还没有编译模版,根据需要可以修改模版dom
                 * @param tElem
                 * @param tAttrs
                 * @returns {{pre: Function, post: Function}}
                 */
                compile : function(tElem, tAttrs) {
                    // 获取属性
                    var $attr_name = tAttrs["name"]; // 控件的名字
                    if (!$attr_name) {
                        throw new Error("saTimeTablePreview指令 name属性required");
                    }

                    // 内部controlAs名字
                    var ctrlAs = "$saTimeTablePreviewCtrl";

                    // TODO:

                    //------------------ 内部方法 --------------------//
                    var date_wrap_prefix = "2000-01-01 "; // 包装日期的前缀
                    var date_wrap_format = "YYYY-MM-DD HH:mm"; // 日期格式
                    /**
                     * 将时间包装成日期,方便计算。
                     * @param timeStr 时间格式,如 06:30
                     * @returns moment对象
                     */
                    var _fun_WrapTime = function(timeStr) {
                        return moment(
                            date_wrap_prefix + timeStr,
                            date_wrap_format
                        );
                    };

                    /**
                     * 点击班次html元素(dl),触发班次移动,如下:
                     * 1、点击上行班次,下一个下行班次在下行班次列表中移到中间位置
                     * 2、点击下行班次,下一个上行班次在上行班次列表中移到中间位置
                     * @param ctrl 内部控制器
                     * @param index 班次索引
                     * @param isUp 是否上行
                     * @private
                     */
                    var _fun_bcDDViewMove = function(ctrl, index, isUp) {
                        // 获取当前点击班次对象
                        var oBc;
                        if (isUp) {
                            oBc = ctrl.internalBcModel.up_bc_list_asc[index];
                        } else {
                            oBc = ctrl.internalBcModel.down_bc_list_asc[index];
                        }

                        // 找出车次链中的下一个班次索引,没有就undefined
                        var nextIndex = undefined;
                        var nextBlockBc = undefined;
                        var currentBlockBcIndex = undefined;
                        angular.forEach(ctrl.internalLpBlockModel[oBc.lpName], function(data, i) {
                            if (data.fcsj == oBc.fcsj) {
                                currentBlockBcIndex = i;
                            }
                        });
                        if (currentBlockBcIndex != undefined &&
                            currentBlockBcIndex < (ctrl.internalLpBlockModel[oBc.lpName].length - 1)) {
                            nextBlockBc = ctrl.internalLpBlockModel[oBc.lpName][currentBlockBcIndex + 1];
                            nextIndex = nextBlockBc.index;
                        }
                        // 先删除click标记,再添加
                        angular.forEach(ctrl.internalBcModel.up_bc_list_asc, function(data) {
                            delete data["isClick"];
                        });
                        angular.forEach(ctrl.internalBcModel.down_bc_list_asc, function(data) {
                            delete data["isClick"];
                        });
                        oBc.isClick = true;
                        if (nextIndex) {
                            if (nextBlockBc.isUp) {
                                ctrl.internalBcModel.up_bc_list_asc[nextIndex].isClick = true;
                            } else {
                                ctrl.internalBcModel.down_bc_list_asc[nextIndex].isClick = true;
                            }
                        }

                        // 移动,同方向不移动
                        var clientHeight = angular.element("#temp").height() - 34;
                        if (nextBlockBc && isUp != nextBlockBc.isUp) {
                            if (isUp) { // 移动下行
                                angular.element(".ttpv_table_scrollbar:eq(1)").animate(
                                    {scrollTop : nextIndex * 30 - clientHeight / 2}, 400);
                            } else { // 移动上行
                                angular.element(".ttpv_table_scrollbar:eq(0)").animate(
                                    {scrollTop : nextIndex * 30 - clientHeight / 2}, 400);
                            }
                        }

                    };

                    /**
                     * 刷新内部数据。
                     * @param ctrl 内部控制器对象($saTimeTablePreviewCtrl)
                     * @private
                     */
                    var _fun_refreshInternalModel = function(ctrl) {
                        // 初始化内部数据
                        ctrl.internalBcModel = {
                            up_qdz_name : "", // 上行起点站名字
                            up_zdz_name : "", // 上行终点站名字
                            down_qdz_name : "", // 下行起点站名字
                            down_zdz_name : "", // 下行终点站名字
                            up_bc_list_asc : [], // 上行班次列表(按照发车时间升序)
                            down_bc_list_asc : [] // 下行班次列表(按照发车时间升序)
                        };
                        ctrl.internalLpBlockModel = {

                        };

                        // ngModel传入的数据
                        var dataSource = ctrl.ds.bcList;

                        // 构造上下行班次列表,并确定上下行的首发站点
                        angular.forEach(dataSource, function(bcObj) {
                            var _internalBcObj = {};
                            // 构造内部班次对象
                            _internalBcObj.lpName = bcObj.lp.lpName; // 路牌
                            _internalBcObj.fcsj = bcObj.fcsj; // 发车时间
                            _internalBcObj.ddsj = _fun_WrapTime(bcObj.fcsj).add(bcObj.bcsj, "m").format("HH:mm");
                            _internalBcObj.qdzName = bcObj.qdzName; // 起点站名字
                            _internalBcObj.zdzName = bcObj.zdzName; // 终点站名字
                            _internalBcObj.bcType = bcObj.bcType; // 班次类型
                            _internalBcObj.isTs = bcObj.isTS; // 是否停驶
                            _internalBcObj.isFb = bcObj.isFB; // 是否分班
                            _internalBcObj.remark = bcObj.remark; // 备注
                            _internalBcObj._fcno = bcObj.fcno; // 发车顺序号

                            if (bcObj.xlDir == "0") { // 上行
                                ctrl.internalBcModel.up_bc_list_asc.push(_internalBcObj);
                                // 确定起点站
                                if (ctrl.internalBcModel.up_qdz_name == "") {
                                    if (bcObj.bcType == "normal") {
                                        ctrl.internalBcModel.up_qdz_name = bcObj.qdzName;
                                    }
                                }
                                // 确定终点站
                                if (ctrl.internalBcModel.up_zdz_name == "") {
                                    if (bcObj.bcType == "normal") {
                                        ctrl.internalBcModel.up_zdz_name = bcObj.zdzName;
                                    }
                                }
                            }
                            if (bcObj.xlDir == "1") { // 下行
                                ctrl.internalBcModel.down_bc_list_asc.push(_internalBcObj);
                                // 确定起点站
                                if (ctrl.internalBcModel.down_qdz_name == "") {
                                    if (bcObj.bcType == "normal") {
                                        ctrl.internalBcModel.down_qdz_name = bcObj.qdzName;
                                    }
                                }
                                // 确定终点站
                                if (ctrl.internalBcModel.down_zdz_name == "") {
                                    if (bcObj.bcType == "normal") {
                                        ctrl.internalBcModel.down_zdz_name = bcObj.zdzName;
                                    }
                                }
                            }

                        });

                        // 发车时间升序排序上行班次
                        ctrl.internalBcModel.up_bc_list_asc.sort(function(a, b) {
                            var a_wrapTime = _fun_WrapTime(a.fcsj);
                            var b_wrapTime = _fun_WrapTime(b.fcsj);

                            // 判定如果发车时间是以00,01,02,03开头的,说明是下一天凌晨的班次,需要加1天判定
                            // TODO:以后要配合首班车的发车时间判定
                            if (a.fcsj.indexOf("00:") == 0 ||
                                a.fcsj.indexOf("01:") == 0 ||
                                a.fcsj.indexOf("02:") == 0) {
                                a_wrapTime.add(1, "day");
                            }
                            if (b.fcsj.indexOf("00:") == 0 ||
                                b.fcsj.indexOf("01:") == 0 ||
                                b.fcsj.indexOf("02:") == 0) {
                                b_wrapTime.add(1, "day");
                            }

                            if (a_wrapTime.isBefore(b_wrapTime)) {
                                return -1;
                            } else if (a_wrapTime.isAfter(b_wrapTime)) {
                                return 1;
                            } else {
                                return 0;
                            }

                        });
                        // 发车时间升序排序下行班次
                        ctrl.internalBcModel.down_bc_list_asc.sort(function(a, b) {
                            var a_wrapTime = _fun_WrapTime(a.fcsj);
                            var b_wrapTime = _fun_WrapTime(b.fcsj);

                            // 判定如果发车时间是以00,01,02,03开头的,说明是下一天凌晨的班次,需要加1天判定
                            // TODO:以后要配合首班车的发车时间判定
                            if (a.fcsj.indexOf("00:") == 0 ||
                                a.fcsj.indexOf("01:") == 0 ||
                                a.fcsj.indexOf("02:") == 0) {
                                a_wrapTime.add(1, "day");
                            }
                            if (b.fcsj.indexOf("00:") == 0 ||
                                b.fcsj.indexOf("01:") == 0 ||
                                b.fcsj.indexOf("02:") == 0) {
                                b_wrapTime.add(1, "day");
                            }

                            if (a_wrapTime.isBefore(b_wrapTime)) {
                                return -1;
                            } else if (a_wrapTime.isAfter(b_wrapTime)) {
                                return 1;
                            } else {
                                return 0;
                            }
                        });

                        // 构造路牌block车次链,按照发车顺序排序
                        angular.forEach(ctrl.internalBcModel.up_bc_list_asc, function(data, index) {
                            if (!ctrl.internalLpBlockModel[data.lpName]) {
                                ctrl.internalLpBlockModel[data.lpName] = [];
                            }
                            ctrl.internalLpBlockModel[data.lpName].push({
                                fcsj : data.fcsj,
                                isUp : true,
                                fcno : data._fcno,
                                index : index
                            });
                        });
                        angular.forEach(ctrl.internalBcModel.down_bc_list_asc, function(data, index) {
                            if (!ctrl.internalLpBlockModel[data.lpName]) {
                                ctrl.internalLpBlockModel[data.lpName] = [];
                            }
                            ctrl.internalLpBlockModel[data.lpName].push({
                                fcsj : data.fcsj,
                                isUp : false,
                                fcno : data._fcno,
                                index : index
                            });
                        });
                        angular.forEach(ctrl.internalLpBlockModel, function(value, key) {
                            value.sort(function (a, b) {
                                if (a.fcno < b.fcno) {
                                    return -1;
                                } else if (a.fcno > b.fcno) {
                                    return 1;
                                } else {
                                    return 0;
                                }
                            });
                        });


                    };

                    return {
                        pre : function(scope, element, attr) {
                            // TODO:
                        },
                        post : function(scope, element, attr) {
                            // 班次html点击事件
                            scope[ctrlAs].$$bcDD_Click = function(index, xlDir) {
                                _fun_bcDDViewMove(scope[ctrlAs], index, xlDir);
                            };

                            // 监控ngModel绑定的外部数据源的刷新状态变化
                            scope.$watch(
                                function() {
                                    return scope[ctrlAs].ds.refreshInfos;
                                },
                                function(newValue, oldValue) {
                                    if (newValue === undefined && oldValue === undefined) {
                                        return;
                                    }
                                    console.log("saTimetable2 refresh");
                                    _fun_refreshInternalModel(scope[ctrlAs]);
                                },
                                true
                            );
                        }
                    };
                }
            };
        }
    ]
);
/**
 * 滚动事件控制指令。
 */
angular.module('ScheduleApp').directive(
    'saTscrolly1',
    [
        function() {
            return {
                restrict: 'A',

                compile: function(tElem, tAttrs) {

                    return {
                        pre: function(scope, element, attr) {
                            // TODO:
                            //alert(element.find("#tooltipTest").html());
                            //$compile(element.find("#tooltipTest"))(scope);

                        },

                        post: function(scope, element, attr) {
                            //var head = element[0];

                            //console.log("llllllllload");
                            //console.log(element.name);

                            element.bind('scroll', function() {
                                //console.log("top=", angular.element(".tt_table_head").css("top"));
                                //console.log("left=", angular.element(".tt_table_head").css("left"));
                                //console.log("s top=" + element.scrollTop());

                                angular.element(".tt_table_head").css("top", element.scrollTop());
                                angular.element(".tt_table_head:eq(0)").css("left", element.scrollLeft());
                                angular.element(".tt_table_body:eq(0)").css("left", element.scrollLeft());

                            });
                        }

                    };
                }
            }
        }
    ]
);
/**
 * 滚动事件控制指令。
 */
angular.module('ScheduleApp').directive(
    'saTscrolly2',
    [
        function() {
            return {
                restrict: 'A',

                compile: function(tElem, tAttrs) {

                    return {
                        pre: function(scope, element, attr) {
                            // TODO:
                            //alert(element.find("#tooltipTest").html());
                            //$compile(element.find("#tooltipTest"))(scope);

                        },

                        post: function(scope, element, attr) {
                            //var head = element[0];

                            //console.log("llllllllload");
                            //console.log(element.name);

                            element.bind('scroll', function() {
                                //console.log("top=", angular.element(".tt_table_head").css("top"));
                                //console.log("left=", angular.element(".tt_table_head").css("left"));
                                //console.log("s top=" + element.scrollTop());

                                angular.element(attr.scrclass).css("top", element.scrollTop());
                                // angular.element(".tt_table_head:eq(0)").css("left", element.scrollLeft());
                                // angular.element(".tt_table_body:eq(0)").css("left", element.scrollLeft());

                            });
                        }

                    };
                }
            }
        }
    ]
);
/**
 * saOrderoption指令,搜索时的排序选项(在搜索时可以使用,通用的)
 * 属性如下:
 * name(必须):控件的名字
 * columns(必须,独立作用域):字段名字列表,格式:[{name:[字段名],desc:[字段描述]}...]
 * ordercolumns(必须,独立作用域):字段排序列表,格式:{order: '字段1,字段2',direction: 'ASC,DESC'}
 */
angular.module('ScheduleApp').directive(
    'saOrderoption',
    [
        function() {
            return {
                restrict: 'E',
                templateUrl: '/pages/scheduleApp/module/common/dts2/queryOption/saOrderOptionTemplate.html',
                scope: {
                    columns: '=',
                    ordercolumns: '='
                },
                controllerAs: '$saOrderOptionCtrl',
                bindToController: true,
                controller: function() {
                    var self = this;

                    // 字段列表是否预载入
                    self.$$columns_loaded = false;
                    // 字段排序是否预载入
                    self.$$ordercolumns_loaded = false;


                    // 每组选项内部数据源
                    // 格式:[{column:[选中的字段名],dir:[ASC/DESC]}]
                    self.$$selectgroupds = [];

                    // TODO:选择事件

                    self.$$select_column_change = function() {
                        self.$$refresh_selectgroupds();
                    };

                    self.$$select_dir_change = function() {
                        self.$$refresh_selectgroupds();
                    };

                    self.$$add_option_click = function(index) {
                        self.$$selectgroupds.splice(index, 0, {
                            column: self.columns[0].name,
                            dir: "ASC"
                        });
                        self.$$refresh_selectgroupds();
                    };
                    self.$$del_option_click = function(index) {
                        self.$$selectgroupds.splice(index, 1);
                        self.$$refresh_selectgroupds();
                    };

                    // 刷新选项内部数据源
                    self.$$refresh_selectgroupds = function() {
                        if (!self.$$columns_loaded || !self.$$ordercolumns_loaded || self.columns.length == 0) {
                            // 没有载入完成,或者字段列表为空
                            return;
                        }

                        if (self.$$selectgroupds.length == 0) { // 默认添加一组排序
                            self.$$selectgroupds.push({
                                column: self.columns[0].name,
                                dir: "ASC"
                            });
                        }

                        // 重新计算ordercolumns

                        var aColumn = [];
                        var aDir = [];
                        for (var i = 0; i < self.$$selectgroupds.length; i++) {
                            aColumn.push(self.$$selectgroupds[i].column);
                            aDir.push(self.$$selectgroupds[i].dir);
                        }
                        if (self.ordercolumns) {
                            self.ordercolumns.order = aColumn.join(",");
                            self.ordercolumns.direction = aDir.join(",");
                        } else {
                            self.ordercolumns = {order: aColumn.join(","), direction: aDir.join(",")}
                        }

                    }
                },
                compile: function(tElem, tAttrs) {
                    // 获取所有属性,并验证
                    var $name_attr = tAttrs['name']; // 控件的名字
                    if (!$name_attr) {
                        throw "必须有名称属性";
                    }

                    // controlAs名字
                    var ctrlAs = '$saOrderOptionCtrl';

                    // TODO:



                    return {
                        pre: function(scope, element, attr) {

                        },

                        post: function(scope, element, attr) {

                            //--------------------- 监控属性方法 -------------------//
                            // 监控字段名字列表
                            scope.$watch(
                                function() {
                                    return scope[ctrlAs].columns;
                                },
                                function(newValue, oldValue) {
                                    if (!scope[ctrlAs].$$columns_loaded) {
                                        // TODO:格式判定以后做,假设格式是对的


                                    }

                                    scope[ctrlAs].$$columns_loaded = true;
                                    scope[ctrlAs].$$refresh_selectgroupds();
                                },
                                true
                            );
                            // 监控字段排序列表
                            scope.$watch(
                                function() {
                                    return scope[ctrlAs].ordercolumns;
                                },
                                function(newValue, oldValue) {
                                    if (!scope[ctrlAs].$$ordercolumns_loaded) {
                                        if (newValue) {
                                            var aColumns = []; // 排序的字段
                                            var aDirs = []; // 排序字段对应的排序方向

                                            if (newValue.order) {
                                                aColumns = newValue.order.split(",");
                                            }
                                            if (newValue.direction) {
                                                aDirs = newValue.direction.split(",");
                                            }

                                            for (var i = 0; i < aColumns.length; i++) {
                                                if (i < aDirs.length) {
                                                    scope[ctrlAs].$$selectgroupds.push({
                                                        column: aColumns[i],
                                                        dir: aDirs[i]
                                                    });
                                                } else {
                                                    scope[ctrlAs].$$selectgroupds.push({
                                                        column: aColumns[i],
                                                        dir: 'ASC'
                                                    });
                                                }
                                            }
                                        }
                                    }
                                    scope[ctrlAs].$$ordercolumns_loaded = true;
                                    scope[ctrlAs].$$refresh_selectgroupds();

                                },
                                true
                            );
                        }

                    };
                }
            };
        }
    ]
);
/**
 * saScpdate指令(非通用指令,只在排班计划form中使用)。
 * 属性如下:
 * name(必须):控件的名字
 * xlid(必须):线路id
 * xlname(必须):线路名字
 * from(必须):独立作用域-绑定的开始时间属性名
 * to(必须):独立作用域-绑定的结束时间属性名
 * error(必须):独立作用域-绑定的错误描述属性名
 */
angular.module('ScheduleApp').directive(
    'saScpdate',
    [
        'SchedulePlanManageService_g',
        function(service) {
            return {
                restrict: 'E',
                templateUrl: '/pages/scheduleApp/module/common/dts2/scheduleplan/saScpdateTemplate.html',
                scope: {
                    from: '=',
                    to: '=',
                    xlid: '=',
                    xlname: '=',
                    ttinfonames: '=',
                    ttinfoids: '=',
                    error: '='
                },
                controllerAs: '$saScpdateCtrl',
                bindToController: true,
                controller: function() {
                    var self = this;

                    // 内部ng-model值,用于和required配对
                    self.$$internalmodel = undefined;

                    // 内部数据源(时刻表的一些信息)
                    self.$$ds = [];

                },
                compile: function(tElem, tAttrs) {
                    // 获取所有属性,并验证
                    var $name_attr = tAttrs['name']; // 控件的名字
                    if (!$name_attr) {
                        throw "必须有名称属性";
                    }

                    // controlAs名字
                    var ctrlAs = '$saScpdateCtrl';

                    // 线路id
                    var xl_id = undefined;
                    // 线路名字
                    var xl_name = undefined;
                    // 开始时间
                    var from_date = undefined;
                    // 结束时间
                    var to_date = undefined;

                    // 内部添加required验证,将所有的错误应用到required验证上去
                    tElem.find("div").attr("required", "");

                    return {
                        pre: function(scope, element, attr) {

                        },

                        post: function(scope, element, attr) {
                            // 属性值
                            if ($name_attr) {
                                scope[ctrlAs]["$name_attr"] = $name_attr;
                            }

                            // 开始日期open属性,及方法
                            scope[ctrlAs].$$fromDateOpen = false;
                            scope[ctrlAs].$$fromDate_open = function() {
                                scope[ctrlAs].$$fromDateOpen = true;
                            };

                            // 结束日期open属性,及方法
                            scope[ctrlAs].$$toDateOpen = false;
                            scope[ctrlAs].$$toDate_open = function() {
                                scope[ctrlAs].$$toDateOpen = true;
                            };


                            // 内部模型刷新
                            scope[ctrlAs].$$internal_model_refresh = function() {
                                if (!xl_id) {
                                    scope[ctrlAs].$$internalmodel = undefined;
                                    scope[ctrlAs].error = "线路必须选择";
                                    return;
                                }
                                if (!xl_name) {
                                    scope[ctrlAs].$$internalmodel = undefined;
                                    scope[ctrlAs].error = "线路必须选择";
                                    return;
                                }

                                if (!from_date) {
                                    scope[ctrlAs].$$internalmodel = undefined;
                                    scope[ctrlAs].error = "开始日期必须选择";
                                    return;
                                }
                                if (!to_date) {
                                    scope[ctrlAs].$$internalmodel = undefined;
                                    scope[ctrlAs].error = "结束日期必须选择";
                                    return;
                                }
                                if (from_date > to_date) {
                                    scope[ctrlAs].$$internalmodel = undefined;
                                    scope[ctrlAs].error = "开始日期必须在结束日期之前";
                                    return;
                                }

                                if (!scope[ctrlAs].$$ds || scope[ctrlAs].$$ds.length == 0) {
                                    scope[ctrlAs].$$internalmodel = undefined;
                                    scope[ctrlAs].error = "无可用时刻表";
                                }

                                var QClass = service.ttinfo;
                                var ttinfonames = [];
                                var ttinfoids = [];
                                QClass.val({xlid: xl_id, from: from_date, to: to_date},
                                    function(result) {
                                        scope[ctrlAs].$$ds = [];

                                        var errorTTInfos = 0;
                                        var errorLpCount = 0;

                                        if (result && result.data && result.data.infos && result.data.infos.length > 0) {
                                            angular.forEach(result.data.infos, function(obj) {
                                                scope[ctrlAs].$$ds.push({
                                                    xlid: xl_id,
                                                    ttid: obj.ttid,
                                                    xlname: xl_name,
                                                    ttname: obj.ttname,

                                                    allbc: obj.allbc,
                                                    inbc: obj.inbc,
                                                    outbc: obj.outbc,
                                                    yybc: obj.yybc,

                                                    errorbc: obj.errorbc,
                                                    errorlpCount: obj.errorlpCount,
                                                    errorlpInfo: obj.errorlpInfo,

                                                    lineVersion: obj.lineVersion

                                                });

                                                if (obj.errorbc > 0) {
                                                    errorTTInfos ++;
                                                } else if (obj.errorlpCount > 0) {
                                                    errorLpCount ++;
                                                } else {
                                                    ttinfonames.push(obj.ttname);
                                                    ttinfoids.push(obj.ttid);
                                                }
                                            });

                                            if (errorTTInfos > 0) {
                                                scope[ctrlAs].$$internalmodel = undefined;
                                                scope[ctrlAs].error = "时刻表有错误班次";
                                            } else if (errorLpCount > 0) {
                                                scope[ctrlAs].$$internalmodel = undefined;
                                                scope[ctrlAs].error = "时刻表有错误路牌";
                                            } else {
                                                scope[ctrlAs].$$internalmodel = "ok";
                                                scope[ctrlAs].ttinfonames = ttinfonames.join(",");
                                                scope[ctrlAs].ttinfoids = ttinfoids.join(",");
                                            }

                                        } else {
                                            scope[ctrlAs].$$internalmodel = undefined;
                                            scope[ctrlAs].error = "无可用时刻表";
                                        }
                                    },
                                    function() {
                                        scope[ctrlAs].$$internalmodel = undefined;
                                        scope[ctrlAs].error = "获取时刻表数据失败!";
                                    }
                                );


                                scope[ctrlAs].$$internalmodel = "ok";
                            };

                            scope[ctrlAs].$$internal_model_refresh(); // 初始执行

                            //--------------------- 监控属性方法 -------------------//
                            // 监控线路id模型值变化
                            scope.$watch(
                                function() {
                                    return scope[ctrlAs].xlid;
                                },
                                function(newValue, oldValue) {
                                    xl_id = newValue;
                                    scope[ctrlAs].$$internal_model_refresh();
                                }
                            );
                            // 监控线路name模型值变化
                            scope.$watch(
                                function() {
                                    return scope[ctrlAs].xlname;
                                },
                                function(newValue, oldValue) {
                                    xl_name = newValue;
                                    scope[ctrlAs].$$internal_model_refresh();
                                }
                            );

                            // 监控开始时间模型值变化
                            scope.$watch(
                                function() {
                                    return scope[ctrlAs].from;
                                },
                                function(newValue, oldValue) {
                                    from_date = newValue;
                                    scope[ctrlAs].$$internal_model_refresh();
                                }
                            );
                            // 监控结束时间模型值变化
                            scope.$watch(
                                function() {
                                    return scope[ctrlAs].to;
                                },
                                function(newValue, oldValue) {
                                    to_date = newValue;
                                    scope[ctrlAs].$$internal_model_refresh();
                                }
                            );

                        }
                    };
                }
            };
        }
    ]
);

/**
 * saSrule指令(非通用指令,只在排班计划form中使用)。
 * 属性如下:
 * name(必须):控件的名字
 * xlid(必须):线路id
 * from(必须):独立作用域-绑定的开始时间属性名
 * to(必须):独立作用域-绑定的结束时间属性名
 * error(必须):独立作用域-绑定的错误描述属性名
 */
angular.module('ScheduleApp').directive(
    'saSrule',
    [
        'SchedulePlanManageService_g',
        function(service) {
            return {
                restrict: 'E',
                templateUrl: '/pages/scheduleApp/module/common/dts2/scheduleplan/saSruleTemplate.html',
                scope: {
                    from: '=',
                    to: '=',
                    xlid: '=',
                    error: '='
                },
                controllerAs: '$saSruleCtrl',
                bindToController: true,
                controller: function() {
                    var self = this;

                    // 内部ng-model值,用于和required配对
                    self.$$internalmodel = undefined;

                    // 内部数据源(时刻表的一些信息)
                    self.$$count = 0;
                    self.$$qyCount = 0;
                    self.$$qyErrorCount = 0;
                    self.$$errorInfos = [];

                },
                compile: function(tElem, tAttrs) {
                    // 获取所有属性,并验证
                    var $name_attr = tAttrs['name']; // 控件的名字
                    if (!$name_attr) {
                        throw "必须有名称属性";
                    }

                    // controlAs名字
                    var ctrlAs = '$saSruleCtrl';

                    // 线路id
                    var xl_id = undefined;
                    // 开始时间
                    var from_date = undefined;
                    // 结束时间
                    var to_date = undefined;

                    // 内部添加required验证,将所有的错误应用到required验证上去
                    tElem.find("div").attr("required", "");

                    return {
                        pre: function(scope, element, attr) {

                        },

                        post: function(scope, element, attr) {
                            // 属性值
                            if ($name_attr) {
                                scope[ctrlAs]["$name_attr"] = $name_attr;
                            }

                            // 开始日期open属性,及方法
                            scope[ctrlAs].$$fromDateOpen = false;
                            scope[ctrlAs].$$fromDate_open = function() {
                                scope[ctrlAs].$$fromDateOpen = true;
                            };

                            // 结束日期open属性,及方法
                            scope[ctrlAs].$$toDateOpen = false;
                            scope[ctrlAs].$$toDate_open = function() {
                                scope[ctrlAs].$$toDateOpen = true;
                            };

                            // 内部模型刷新
                            scope[ctrlAs].$$internal_model_refresh = function() {
                                if (!xl_id) {
                                    scope[ctrlAs].$$internalmodel = undefined;
                                    scope[ctrlAs].error = "线路必须选择";
                                    return;
                                }
                                if (!from_date) {
                                    scope[ctrlAs].$$internalmodel = undefined;
                                    scope[ctrlAs].error = "开始日期必须选择";
                                    return;
                                }
                                if (!to_date) {
                                    scope[ctrlAs].$$internalmodel = undefined;
                                    scope[ctrlAs].error = "结束日期必须选择";
                                    return;
                                }
                                if (from_date > to_date) {
                                    scope[ctrlAs].$$internalmodel = undefined;
                                    scope[ctrlAs].error = "开始日期必须在结束日期之前";
                                    return;
                                }

                                scope[ctrlAs].$$count = 0;
                                scope[ctrlAs].$$qyCount = 0;
                                scope[ctrlAs].$$qyErrorCount = 0;
                                scope[ctrlAs].$$errorInfos = [];

                                if (scope[ctrlAs].$$qyCount == 0) {
                                    scope[ctrlAs].$$internalmodel = undefined;
                                    scope[ctrlAs].error = "无可启用的规则数";
                                }

                                var QClass = service.v_rules;
                                QClass.val({xlid: xl_id, from: from_date, to: to_date},
                                    function(result) {
                                        scope[ctrlAs].$$count = result.data.count;
                                        scope[ctrlAs].$$qyCount = result.data.qyCount;
                                        scope[ctrlAs].$$qyErrorCount = result.data.qyErrorCount;

                                        angular.forEach(result.data.errorInfos, function(obj) {
                                            scope[ctrlAs].$$errorInfos.push({
                                                ruleId: obj.ruleId,
                                                clZbh: obj.clZbh,
                                                qyrq: moment(obj.qyrq).format("YYYY年MM月DD日"),
                                                infos: obj.errorDescList.join("")
                                            });
                                        });

                                        if (scope[ctrlAs].$$qyErrorCount > 0) {
                                            scope[ctrlAs].$$internalmodel = undefined;
                                            scope[ctrlAs].error = "有错误的规则";
                                        } else {
                                            scope[ctrlAs].$$internalmodel = "ok";
                                            scope[ctrlAs].$$errorInfos = [];
                                        }
                                    },
                                    function() {
                                        scope[ctrlAs].$$internalmodel = undefined;
                                        scope[ctrlAs].error = "获取规则数据失败!";
                                    }
                                );

                                scope[ctrlAs].$$internalmodel = "ok";
                            };

                            scope[ctrlAs].$$internal_model_refresh(); // 初始执行

                            //--------------------- 监控属性方法 -------------------//
                            // 监控线路id模型值变化
                            scope.$watch(
                                function() {
                                    return scope[ctrlAs].xlid;
                                },
                                function(newValue, oldValue) {
                                    xl_id = newValue;
                                    scope[ctrlAs].$$internal_model_refresh();
                                }
                            );

                            // 监控开始时间模型值变化
                            scope.$watch(
                                function() {
                                    return scope[ctrlAs].from;
                                },
                                function(newValue, oldValue) {
                                    from_date = newValue;
                                    scope[ctrlAs].$$internal_model_refresh();
                                }
                            );
                            // 监控结束时间模型值变化
                            scope.$watch(
                                function() {
                                    return scope[ctrlAs].to;
                                },
                                function(newValue, oldValue) {
                                    to_date = newValue;
                                    scope[ctrlAs].$$internal_model_refresh();
                                }
                            );
                        }
                    };
                }
            };
        }
    ]
);
/**
 * saPlaninfoedit指令,排班明细编辑控件,用在调度执勤日报的修改功能
 * name(必须),控件的名字
 * ds,外部数据源
 * cl1,车辆1属性
 * cl2,车辆2属性
 * j1,驾驶员1属性
 * j2,驾驶员2属性
 * s1,售票员1属性
 * s2,售票员2属性
 */
angular.module('ScheduleApp').directive(
    'saPlaninfoedit',
    [
        function() {
            return {
                restrict: 'E',
                templateUrl: '/pages/scheduleApp/module/common/dts2/scheduleplan/saPlaninfoeditTemplate.html',
                scope: { // 独立作用域
                    ds: '=ngModel'
                },
                controllerAs: '$saPlanInfoEditCtrl',
                bindToController: true,
                controller: function() {
                    //var self = this;

                },

                compile: function(tElem, tAttrs) {
                    // 获取属性
                    var $attr_name = tAttrs["name"]; // 控件的名字
                    if (!$attr_name) {
                        throw {msg: "saPlaninfoedit指令name属性不能为空"};
                    }

                    // 内部controlAs名字
                    var ctrlAs = '$saPlanInfoEditCtrl';


                    // 内部变量,原始车辆,人员数据
                    var old_cl = {}; // key:{车辆id_车辆自编号},value:所在list下标数组
                    var old_j = {}; // key:{驾驶员id_姓名_工号}, value:所在list下标数组
                    var old_s = {}; // key:{售票员id_姓名_工号}, value:所在list下标数组
                    var old_isfb = false; // 是否有分班
                    var old_isfb_index = 0; // 分班开始索引
                    var old_hasJCBC = false; // 是否有进场班次
                    var old_max_fcno = 0; // 最大发车顺序号
                    var old_firstJCBCFcno = 0; // 第一个进场班次发车顺序号
                    var old_half_bcs = 0; // 一般的班次数量

                    // 内部变量,变更的车辆,变更的人员
                    var new_cl1 = undefined; // 新的车辆1(车辆id_车辆自编号)
                    var new_cl2 = undefined; // 新的车辆2(车辆id_车辆自编号)
                    var new_j1 = undefined; // 新的驾驶员1(驾驶员id_姓名_工号)
                    var new_j2 = undefined; // 新的驾驶员2(驾驶员id_姓名_工号)
                    var new_s1 = undefined; // 新的售票员1(售票员id_姓名_工号)
                    var new_s2 = undefined; // 新的售票员2(售票员id_姓名_工号)

                    return {
                        pre: function(scope, element, attr) {

                        },
                        post: function(scope, element, attr) {

                            /**
                             * 刷新车辆数据。
                             */
                            scope[ctrlAs].$$internal_refresh_dsdata_cl = function() {
                                if (new_cl1) {
                                    var new_cl1_id = new_cl1.split("_")[0];
                                    var new_cl1_zbh = new_cl1.split("_")[1];

                                    if (new_cl2) {
                                        var new_cl2_id = new_cl2.split("_")[0];
                                        var new_cl2_zbh = new_cl2.split("_")[1];

                                        if (old_isfb) { // 使用分班判定
                                            angular.forEach(scope[ctrlAs].ds, function(obj, index) {
                                                if (index < old_isfb_index) {
                                                    obj.cl = new_cl1_id;
                                                    obj.clZbh = new_cl1_zbh;
                                                } else {
                                                    obj.cl = new_cl2_id;
                                                    obj.clZbh = new_cl2_zbh;
                                                }
                                            });

                                        } else if (old_hasJCBC && old_firstJCBCFcno < old_max_fcno) { // 使用进出场判定
                                            angular.forEach(scope[ctrlAs].ds, function(obj) {
                                                if (obj.fcno <= old_firstJCBCFcno) {
                                                    obj.cl = new_cl1_id;
                                                    obj.clZbh = new_cl1_zbh;
                                                } else {
                                                    obj.cl = new_cl2_id;
                                                    obj.clZbh = new_cl2_zbh;
                                                }
                                            });
                                        } else { // 使用一半一半班次判定
                                            angular.forEach(scope[ctrlAs].ds, function(obj, index) {
                                                if (index < old_half_bcs) {
                                                    obj.cl = new_cl1_id;
                                                    obj.clZbh = new_cl1_zbh;
                                                } else {
                                                    obj.cl = new_cl2_id;
                                                    obj.clZbh = new_cl2_zbh;
                                                }
                                            });
                                        }

                                    } else {
                                        angular.forEach(scope[ctrlAs].ds, function(obj, index) {
                                            obj.cl = new_cl1_id;
                                            obj.clZbh = new_cl1_zbh;
                                        });
                                    }

                                } else {
                                    // 使用旧的
                                    angular.forEach(old_cl, function(value, key) {
                                        angular.forEach(value, function(i) {
                                            scope[ctrlAs].ds[i].cl = key.split("_")[0];
                                            scope[ctrlAs].ds[i].clZbh = key.split("_")[1];
                                        });
                                    });
                                }
                            };

                            /**
                             * 刷新驾驶员数据。
                             */
                            scope[ctrlAs].$$internal_refresh_dsdata_j = function() {
                                if (new_j1) {
                                    var new_j1_id = new_j1.split("_")[0];
                                    var new_j1_name = new_j1.split("_")[1];
                                    var new_j1_gh = new_j1.split("_")[2];
                                    if (new_j1_gh && new_j1_gh.indexOf("-") > 0) {
                                        new_j1_gh = new_j1_gh.substr(3); // 修正工号,把 55- 这种前缀去掉
                                    }

                                    if (new_j2) {
                                        var new_j2_id = new_j2.split("_")[0];
                                        var new_j2_name = new_j2.split("_")[1];
                                        var new_j2_gh = new_j2.split("_")[2];
                                        if (new_j2_gh && new_j2_gh.indexOf("-") > 0) {
                                            new_j2_gh = new_j2_gh.substr(3); // 修正工号,把 55- 这种前缀去掉
                                        }

                                        if (old_isfb) { // 使用分班判定
                                            angular.forEach(scope[ctrlAs].ds, function(obj, index) {
                                                if (index < old_isfb_index) {
                                                    obj.j = new_j1_id;
                                                    obj.jGh = new_j1_gh;
                                                    obj.jName = new_j1_name;
                                                } else {
                                                    obj.j = new_j2_id;
                                                    obj.jGh = new_j2_gh;
                                                    obj.jName = new_j2_name;
                                                }
                                            });

                                        } else if (old_hasJCBC && old_firstJCBCFcno < old_max_fcno) { // 使用进出场判定
                                            angular.forEach(scope[ctrlAs].ds, function(obj) {
                                                if (obj.fcno <= old_firstJCBCFcno) {
                                                    obj.j = new_j1_id;
                                                    obj.jGh = new_j1_gh;
                                                    obj.jName = new_j1_name;
                                                } else {
                                                    obj.j = new_j2_id;
                                                    obj.jGh = new_j2_gh;
                                                    obj.jName = new_j2_name;
                                                }
                                            });
                                        } else { // 使用一半一半班次判定
                                            angular.forEach(scope[ctrlAs].ds, function(obj, index) {
                                                if (index < old_half_bcs) {
                                                    obj.j = new_j1_id;
                                                    obj.jGh = new_j1_gh;
                                                    obj.jName = new_j1_name;
                                                } else {
                                                    obj.j = new_j2_id;
                                                    obj.jGh = new_j2_gh;
                                                    obj.jName = new_j2_name;
                                                }
                                            });
                                        }

                                    } else {
                                        angular.forEach(scope[ctrlAs].ds, function(obj, index) {
                                            obj.j = new_j1_id;
                                            obj.jGh = new_j1_gh;
                                            obj.jName = new_j1_name;
                                        });
                                    }

                                } else {
                                    // 使用旧的
                                    angular.forEach(old_j, function(value, key) {
                                        angular.forEach(value, function(i) {
                                            scope[ctrlAs].ds[i].j = key.split("_")[0];
                                            scope[ctrlAs].ds[i].jName = key.split("_")[1];
                                            scope[ctrlAs].ds[i].jGh = key.split("_")[2];
                                        });
                                    });
                                }
                            };
                            /**
                             * 刷新售票员数据。
                             */
                            scope[ctrlAs].$$internal_refresh_dsdata_s = function() {
                                if (new_s1) {
                                    var new_s1_id = new_s1.split("_")[0];
                                    var new_s1_name = new_s1.split("_")[1];
                                    var new_s1_gh = new_s1.split("_")[2];
                                    if (new_s1_gh && new_s1_gh.indexOf("-") > 0) { // 修正工号,吧 55- 这种前缀去掉
                                        new_s1_gh = new_s1_gh.substr(3);
                                    }

                                    if (new_s2) {
                                        var new_s2_id = new_s2.split("_")[0];
                                        var new_s2_name = new_s2.split("_")[1];
                                        var new_s2_gh = new_s2.split("_")[2];
                                        if (new_s2_gh && new_s2_gh.indexOf("-") > 0) { // 修正工号,吧 55- 这种前缀去掉
                                            new_s2_gh = new_s2_gh.substr(3);
                                        }

                                        if (old_isfb) { // 使用分班判定
                                            angular.forEach(scope[ctrlAs].ds, function(obj, index) {
                                                if (index < old_isfb_index) {
                                                    obj.s = new_s1_id;

                                                    obj.sGh = new_s1_gh;
                                                    obj.sName = new_s1_name;
                                                } else {
                                                    obj.s = new_s2_id;
                                                    obj.sGh = new_s2_gh;
                                                    obj.sName = new_s2_name;
                                                }
                                            });

                                        } else if (old_hasJCBC && old_firstJCBCFcno < old_max_fcno) { // 使用进出场判定
                                            angular.forEach(scope[ctrlAs].ds, function(obj) {
                                                if (obj.fcno <= old_firstJCBCFcno) {
                                                    obj.s = new_s1_id;
                                                    obj.sGh = new_s1_gh;
                                                    obj.sName = new_s1_name;
                                                } else {
                                                    obj.s = new_s2_id;
                                                    obj.sGh = new_s2_gh;
                                                    obj.sName = new_s2_name;
                                                }
                                            });
                                        } else { // 使用一半一半班次判定
                                            angular.forEach(scope[ctrlAs].ds, function(obj, index) {
                                                if (index < old_half_bcs) {
                                                    obj.s = new_s1_id;
                                                    obj.sGh = new_s1_gh;
                                                    obj.sName = new_s1_name;
                                                } else {
                                                    obj.s = new_s2_id;
                                                    obj.sGh = new_s2_gh;
                                                    obj.sName = new_s2_name;
                                                }
                                            });
                                        }

                                    } else {
                                        angular.forEach(scope[ctrlAs].ds, function(obj, index) {
                                            obj.s = new_s1_id;
                                            obj.sGh = new_s1_gh;
                                            obj.sName = new_s1_name;
                                        });
                                    }

                                } else {
                                    // 先清空
                                    angular.forEach(scope[ctrlAs].ds, function(obj) {
                                        obj.s = undefined;
                                        obj.sGh = undefined;
                                        obj.sName = undefined;
                                    });

                                    // 使用旧的
                                    angular.forEach(old_s, function(value, key) {
                                        angular.forEach(value, function(i) {
                                            scope[ctrlAs].ds[i].s = key.split("_")[0];
                                            scope[ctrlAs].ds[i].sName = key.split("_")[1];
                                            scope[ctrlAs].ds[i].sGh = key.split("_")[2];
                                        });
                                    });
                                }
                            };

                            /**
                             * 刷新内部数据。
                             */
                            scope[ctrlAs].$$internal_refresh_dsdata = function() {
                                // 更新车辆
                                scope[ctrlAs].$$internal_refresh_dsdata_cl();

                                // 更新驾驶员
                                scope[ctrlAs].$$internal_refresh_dsdata_j();

                                // 更新售票员
                                scope[ctrlAs].$$internal_refresh_dsdata_s();
                            };

                            // -------------- 监控function ---------------//
                            attr.$observe('cl1', function(value) {
                                if (value && value != "") {
                                    var obj = JSON.parse(value);
                                    if (obj.id && obj.zbh) {
                                        new_cl1 = obj.id + "_" + obj.zbh;
                                    } else {
                                        new_cl1 = undefined;
                                    }
                                    scope[ctrlAs].$$internal_refresh_dsdata();
                                }
                            });

                            attr.$observe('cl2', function(value) {
                                if (value && value != "") {
                                    var obj = JSON.parse(value);
                                    if (obj.id && obj.zbh) {
                                        new_cl2 = obj.id + "_" + obj.zbh;
                                    } else {
                                        new_cl2 = undefined;
                                    }
                                    scope[ctrlAs].$$internal_refresh_dsdata();
                                }
                            });

                            attr.$observe('j1', function(value) {
                                if (value && value != "") {
                                    var obj = JSON.parse(value);
                                    if (obj.id && obj.name && obj.jobCode) {
                                        new_j1 = obj.id + "_" + obj.name + "_" + obj.jobCode;
                                    } else {
                                        new_j1 = undefined;
                                    }
                                    scope[ctrlAs].$$internal_refresh_dsdata();
                                }
                            });

                            attr.$observe('j2', function(value) {
                                if (value && value != "") {
                                    var obj = JSON.parse(value);
                                    if (obj.id && obj.name && obj.jobCode) {
                                        new_j2 = obj.id + "_" + obj.name + "_" + obj.jobCode;
                                    } else {
                                        new_j2 = undefined;
                                    }
                                    scope[ctrlAs].$$internal_refresh_dsdata();
                                }
                            });

                            attr.$observe('s1', function(value) {
                                if (value && value != "") {
                                    var obj = JSON.parse(value);
                                    if (obj.id && obj.name && obj.jobCode) {
                                        new_s1 = obj.id + "_" + obj.name + "_" + obj.jobCode;
                                    } else {
                                        new_s1 = undefined;
                                    }
                                    scope[ctrlAs].$$internal_refresh_dsdata();
                                }
                            });

                            attr.$observe('s2', function(value) {
                                if (value && value != "") {
                                    var obj = JSON.parse(value);
                                    if (obj.id && obj.name && obj.jobCode) {
                                        new_s2 = obj.id + "_" + obj.name + "_" + obj.jobCode;
                                    } else {
                                        new_s2 = undefined;
                                    }
                                    scope[ctrlAs].$$internal_refresh_dsdata();
                                }
                            });

                            scope.$watch(
                                function() {
                                    return scope[ctrlAs].ds;
                                },
                                function(newValue, oldValue) {
                                    if (newValue && newValue.length > 0) {

                                        var j1 = newValue[0].j;

                                        angular.forEach(newValue, function(obj, index) {
                                            var k1 = obj.cl + "_" + obj.clZbh;
                                            var k2 = !obj.j? undefined: obj.j + "_" + obj.jName + "_" + obj.jGh;
                                            var k3 = !obj.s? undefined: obj.s + "_" + obj.sName + "_" + obj.sGh;

                                            if (!old_cl[k1]) {
                                                old_cl[k1] = [];
                                            }
                                            if (!old_j[k2] && k2) {
                                                old_j[k2] = [];
                                            }
                                            if (!old_s[k3] && k3) {
                                                old_s[k3] = [];
                                            }

                                            // 闭包
                                            (function(i) {
                                                old_cl[k1].push(i);
                                                if (k2) {
                                                    old_j[k2].push(i);
                                                }
                                                if (k3) {
                                                    old_s[k3].push(i);
                                                }
                                            })(index);

                                            // 判断是否分班
                                            if (j1 != obj.j && !old_isfb) {
                                                old_isfb = true;
                                                old_isfb_index = index;
                                            }

                                            // 判断进出场
                                            if (obj.bcType == 'in' && !old_hasJCBC) {
                                                old_hasJCBC = true;
                                                old_firstJCBCFcno = obj.fcno;
                                            }
                                        });

                                        old_max_fcno = newValue[newValue.length - 1].fcno;
                                        old_half_bcs = newValue.length / 2;

                                        // 可以用resource封装一下
                                        // TODO:
                                    }
                                }
                            );
                        }
                    }
                }
            };
        }
    ]
);
/**
 * saPlaninfoedit2指令,排班明细编辑控件,用在调度执勤日报的修改功能
 * name(必须),控件的名字
 * ds,外部数据源
 * fd, 表单数据源
 */
angular.module('ScheduleApp').directive(
    'saPlaninfoedit2',
    [
        function() {
            return {
                restrict: 'E',
                templateUrl: '/pages/scheduleApp/module/common/dts2/scheduleplan/saPlaninfoeditTemplate.html',
                scope: { // 独立作用域
                    ds: '=ngModel', // 时刻明细数据源头
                    fd: '=formData' // 表单数据源(车辆、驾驶员、售票员信息)
                },
                controllerAs: '$saPlanInfoEditCtrl',
                bindToController: true,
                controller: function() {
                    //var self = this;

                },

                compile: function(tElem, tAttrs) {
                    // 获取属性
                    var $attr_name = tAttrs["name"]; // 控件的名字
                    if (!$attr_name) {
                        throw {msg: "saPlaninfoedit2指令name属性不能为空"};
                    }

                    // 内部controlAs名字
                    var ctrlAs = '$saPlanInfoEditCtrl';


                    // 内部变量,原始车辆,人员数据
                    var old_cl = {}; // key:{车辆id_车辆自编号},value:所在list下标数组
                    var old_j = {}; // key:{驾驶员id_姓名_工号}, value:所在list下标数组
                    var old_s = {}; // key:{售票员id_姓名_工号}, value:所在list下标数组
                    var old_isfb = false; // 是否有分班
                    var old_isfb_index = 0; // 分班开始索引
                    var old_hasJCBC = false; // 是否有进场班次
                    var old_max_fcno = 0; // 最大发车顺序号
                    var old_firstJCBCFcno = 0; // 第一个进场班次发车顺序号
                    var old_half_bcs = 0; // 一般的班次数量
                    var old_ddreason = {}; // key:{调度原因}, value:所在list下标数组
                    var old_dddesc = {}; // key:{调度描述}, value:所在list下标数组

                    // 内部变量,变更的车辆,变更的人员
                    var new_cl1 = undefined; // 新的车辆1(车辆id_车辆自编号)
                    var new_cl2 = undefined; // 新的车辆2(车辆id_车辆自编号)
                    var new_j1 = undefined; // 新的驾驶员1(驾驶员id_姓名_工号)
                    var new_j2 = undefined; // 新的驾驶员2(驾驶员id_姓名_工号)
                    var new_s1 = undefined; // 新的售票员1(售票员id_姓名_工号)
                    var new_s2 = undefined; // 新的售票员2(售票员id_姓名_工号)
                    var new_ddreason = undefined; // 调度原因
                    var new_dddesc = undefined; // 调度描述

                    // 表单值,被赋值的次数
                    var form_data_assign_count = { // 大于1表示已经初始化过了
                        cl1 : -1,
                        cl2 : -1,
                        j1 : -1,
                        j2 : -1,
                        j3 : -1,
                        s1 : -1,
                        s2 : -1,
                        s3 : -1
                    };

                    return {
                        pre: function(scope, element, attr) {

                        },
                        post: function(scope, element, attr) {

                            /**
                             * 刷新调度原因数据。
                             */
                            scope[ctrlAs].$$internal_refresh_dsdata_ddreason = function() {
                                if (new_ddreason) {
                                    angular.forEach(scope[ctrlAs].ds, function(obj) {
                                        obj.modifyReason = new_ddreason;
                                    });
                                } else {
                                    // 清空,不使用旧的
                                    angular.forEach(old_ddreason, function(value, key) {
                                        angular.forEach(value, function(i) {
                                            scope[ctrlAs].ds[i].modifyReason = undefined;
                                        });
                                    });
                                }
                            };

                            /**
                             * 刷新调度描述数据。
                             */
                            scope[ctrlAs].$$internal_refresh_dsdata_dddesc = function() {
                                if (new_dddesc) {
                                    angular.forEach(scope[ctrlAs].ds, function(obj) {
                                        obj.modifyRemark = new_dddesc;
                                    });
                                } else {
                                    // 清空,不使用旧的
                                    angular.forEach(old_dddesc, function(value, key) {
                                        angular.forEach(value, function(i) {
                                            scope[ctrlAs].ds[i].modifyRemark = undefined;
                                        });
                                    });
                                }
                            };

                            /**
                             * 刷新车辆数据。
                             */
                            scope[ctrlAs].$$internal_refresh_dsdata_cl = function() {
                                if (new_cl1) {
                                    var new_cl1_id = new_cl1.split("_")[0];
                                    var new_cl1_zbh = new_cl1.split("_")[1];

                                    if (new_cl2) {
                                        var new_cl2_id = new_cl2.split("_")[0];
                                        var new_cl2_zbh = new_cl2.split("_")[1];

                                        if (old_isfb) { // 使用分班判定
                                            angular.forEach(scope[ctrlAs].ds, function(obj, index) {
                                                if (index < old_isfb_index) {
                                                    obj.cl = new_cl1_id;
                                                    obj.clZbh = new_cl1_zbh;
                                                } else {
                                                    obj.cl = new_cl2_id;
                                                    obj.clZbh = new_cl2_zbh;
                                                }
                                            });

                                        } else if (old_hasJCBC && old_firstJCBCFcno < old_max_fcno) { // 使用进出场判定
                                            angular.forEach(scope[ctrlAs].ds, function(obj) {
                                                if (obj.fcno <= old_firstJCBCFcno) {
                                                    obj.cl = new_cl1_id;
                                                    obj.clZbh = new_cl1_zbh;
                                                } else {
                                                    obj.cl = new_cl2_id;
                                                    obj.clZbh = new_cl2_zbh;
                                                }
                                            });
                                        } else { // 使用一半一半班次判定
                                            angular.forEach(scope[ctrlAs].ds, function(obj, index) {
                                                if (index < old_half_bcs) {
                                                    obj.cl = new_cl1_id;
                                                    obj.clZbh = new_cl1_zbh;
                                                } else {
                                                    obj.cl = new_cl2_id;
                                                    obj.clZbh = new_cl2_zbh;
                                                }
                                            });
                                        }

                                    } else {
                                        angular.forEach(scope[ctrlAs].ds, function(obj, index) {
                                            obj.cl = new_cl1_id;
                                            obj.clZbh = new_cl1_zbh;
                                        });
                                    }

                                } else {
                                    // 清空,不使用旧的
                                    angular.forEach(old_cl, function(value, key) {
                                        angular.forEach(value, function(i) {
                                            //scope[ctrlAs].ds[i].cl = key.split("_")[0];
                                            //scope[ctrlAs].ds[i].clZbh = key.split("_")[1];
                                            scope[ctrlAs].ds[i].cl = undefined;
                                            scope[ctrlAs].ds[i].clZbh = undefined;
                                        });
                                    });
                                }
                            };

                            /**
                             * 刷新驾驶员数据。
                             */
                            scope[ctrlAs].$$internal_refresh_dsdata_j = function() {
                                if (new_j1) {
                                    var new_j1_id = new_j1.split("_")[0];
                                    var new_j1_name = new_j1.split("_")[1];
                                    var new_j1_gh = new_j1.split("_")[2];
                                    if (new_j1_gh && new_j1_gh.indexOf("-") > 0) {
                                        new_j1_gh = new_j1_gh.substr(3); // 修正工号,把 55- 这种前缀去掉
                                    }

                                    if (new_j2) {
                                        var new_j2_id = new_j2.split("_")[0];
                                        var new_j2_name = new_j2.split("_")[1];
                                        var new_j2_gh = new_j2.split("_")[2];
                                        if (new_j2_gh && new_j2_gh.indexOf("-") > 0) {
                                            new_j2_gh = new_j2_gh.substr(3); // 修正工号,把 55- 这种前缀去掉
                                        }

                                        if (old_isfb) { // 使用分班判定
                                            angular.forEach(scope[ctrlAs].ds, function(obj, index) {
                                                if (index < old_isfb_index) {
                                                    obj.j = new_j1_id;
                                                    obj.jGh = new_j1_gh;
                                                    obj.jName = new_j1_name;
                                                } else {
                                                    obj.j = new_j2_id;
                                                    obj.jGh = new_j2_gh;
                                                    obj.jName = new_j2_name;
                                                }
                                            });

                                        } else if (old_hasJCBC && old_firstJCBCFcno < old_max_fcno) { // 使用进出场判定
                                            angular.forEach(scope[ctrlAs].ds, function(obj) {
                                                if (obj.fcno <= old_firstJCBCFcno) {
                                                    obj.j = new_j1_id;
                                                    obj.jGh = new_j1_gh;
                                                    obj.jName = new_j1_name;
                                                } else {
                                                    obj.j = new_j2_id;
                                                    obj.jGh = new_j2_gh;
                                                    obj.jName = new_j2_name;
                                                }
                                            });
                                        } else { // 使用一半一半班次判定
                                            angular.forEach(scope[ctrlAs].ds, function(obj, index) {
                                                if (index < old_half_bcs) {
                                                    obj.j = new_j1_id;
                                                    obj.jGh = new_j1_gh;
                                                    obj.jName = new_j1_name;
                                                } else {
                                                    obj.j = new_j2_id;
                                                    obj.jGh = new_j2_gh;
                                                    obj.jName = new_j2_name;
                                                }
                                            });
                                        }

                                    } else {
                                        angular.forEach(scope[ctrlAs].ds, function(obj, index) {
                                            obj.j = new_j1_id;
                                            obj.jGh = new_j1_gh;
                                            obj.jName = new_j1_name;
                                        });
                                    }

                                } else {
                                    // 清空,不使用使用旧的
                                    angular.forEach(old_j, function(value, key) {
                                        angular.forEach(value, function(i) {
                                            //scope[ctrlAs].ds[i].j = key.split("_")[0];
                                            //scope[ctrlAs].ds[i].jName = key.split("_")[1];
                                            //scope[ctrlAs].ds[i].jGh = key.split("_")[2];
                                            scope[ctrlAs].ds[i].j = undefined;
                                            scope[ctrlAs].ds[i].jName = undefined;
                                            scope[ctrlAs].ds[i].jGh = undefined;
                                        });
                                    });
                                }
                            };

                            /**
                             * 刷新售票员数据(和驾驶员配对的,有驾驶员,才有售票员)。
                             */
                            scope[ctrlAs].$$internal_refresh_dsdata_s = function() {
                                var j_id = undefined;
                                var s_id = undefined;
                                var s_gh = undefined;
                                var s_name = undefined;

                                if (new_j1) {
                                    j_id = new_j1.split("_")[0];
                                    if (new_s1) {
                                        s_id = new_s1.split("_")[0];
                                        s_name = new_s1.split("_")[1];
                                        s_gh = new_s1.split("_")[2];
                                        if (s_gh && s_gh.indexOf("-") > 0) { // 修正工号,把 55- 这种前缀去掉
                                            s_gh = s_gh.substr(3);
                                        }
                                    } else {
                                        s_id = undefined;
                                        s_gh = undefined;
                                        s_name = undefined
                                    }
                                    angular.forEach(scope[ctrlAs].ds, function(obj, index) {
                                        if (obj.j == j_id) {
                                            obj.s = s_id;
                                            obj.sGh = s_gh;
                                            obj.sName = s_name;
                                        }
                                    });
                                }
                                if (new_j2) {
                                    j_id = new_j2.split("_")[0];
                                    if (new_s2) {
                                        s_id = new_s2.split("_")[0];
                                        s_name = new_s2.split("_")[1];
                                        s_gh = new_s2.split("_")[2];
                                        if (s_gh && s_gh.indexOf("-") > 0) { // 修正工号,把 55- 这种前缀去掉
                                            s_gh = s_gh.substr(3);
                                        }
                                    } else {
                                        s_id = undefined;
                                        s_gh = undefined;
                                        s_name = undefined
                                    }

                                    angular.forEach(scope[ctrlAs].ds, function(obj, index) {
                                        if (obj.j == j_id) {
                                            obj.s = s_id;
                                            obj.sGh = s_gh;
                                            obj.sName = s_name;
                                        }
                                    });
                                }
                            };

                            //-------------- 监控调度原因的变化 ----------------//
                            scope.$watch(
                                function() {
                                    return scope[ctrlAs].fd.ddr;
                                },
                                function(newValue, oldValue) {
                                    if (newValue || newValue == 0) {
                                        new_ddreason = newValue;
                                    }
                                    scope[ctrlAs].$$internal_refresh_dsdata_ddreason();
                                },
                                true
                            );

                            //-------------- 监控调度描述的变化 ----------------//
                            scope.$watch(
                                function() {
                                    return scope[ctrlAs].fd.ddrdesc;
                                },
                                function(newValue, oldValue) {
                                    if (newValue || newValue == 0) {
                                        new_dddesc = newValue;
                                    }
                                    scope[ctrlAs].$$internal_refresh_dsdata_dddesc();
                                },
                                true
                            );


                            //-------------- 监控表单车辆1的变化 ----------------//
                            scope.$watch(
                                function() {
                                    return scope[ctrlAs].fd.cl1;
                                },
                                function(newValue, oldValue) {
                                    if (form_data_assign_count.cl1 > 2) {
                                        if (newValue.id) {
                                            if (newValue.id && newValue.zbh) {
                                                new_cl1 = newValue.id + "_" + newValue.zbh;
                                            } else {
                                                new_cl1 = undefined;
                                            }
                                        } else {
                                            new_cl1 = undefined;
                                        }
                                        scope[ctrlAs].$$internal_refresh_dsdata_cl();
                                    }

                                    form_data_assign_count.cl1 ++;
                                },
                                true
                            );

                            //-------------- 监控表单车辆2的变化 ----------------//
                            scope.$watch(
                                function() {
                                    return scope[ctrlAs].fd.cl2;
                                },
                                function(newValue, oldValue) {
                                    if (form_data_assign_count.cl2 > 2) {
                                        if (newValue.id) {
                                            if (newValue.id && newValue.zbh) {
                                                new_cl2 = newValue.id + "_" + newValue.zbh;
                                            } else {
                                                new_cl2 = undefined;
                                            }
                                        } else {
                                            new_cl2 = undefined;
                                        }
                                        scope[ctrlAs].$$internal_refresh_dsdata_cl();
                                    }

                                    form_data_assign_count.cl2 ++;
                                },
                                true
                            );

                            //-------------- 监控表单驾驶员1的变化 ----------------//
                            scope.$watch(
                                function() {
                                    return scope[ctrlAs].fd.j1;
                                },
                                function(newValue, oldValue) {
                                    if (form_data_assign_count.j1 > 2) {
                                        if (newValue.id) {
                                            if (newValue.id && newValue.name && newValue.jobCode) {
                                                new_j1 = newValue.id + "_" + newValue.name + "_" + newValue.jobCode;
                                            } else {
                                                new_j1 = undefined;
                                            }
                                        } else {
                                            new_j1 = undefined;
                                        }

                                        scope[ctrlAs].$$internal_refresh_dsdata_j();
                                        scope[ctrlAs].$$internal_refresh_dsdata_s();
                                    }

                                    form_data_assign_count.j1 ++;
                                },
                                true
                            );

                            //-------------- 监控表单售票员1的变化 ----------------//
                            scope.$watch(
                                function() {
                                    return scope[ctrlAs].fd.s1;
                                },
                                function(newValue, oldValue) {
                                    if (form_data_assign_count.s1 > 2) {
                                        if (newValue.id) {
                                            if (newValue.id && newValue.name && newValue.jobCode) {
                                                new_s1 = newValue.id + "_" + newValue.name + "_" + newValue.jobCode;
                                            } else {
                                                new_s1 = undefined;
                                            }
                                        } else {
                                            new_s1 = undefined;
                                        }

                                        scope[ctrlAs].$$internal_refresh_dsdata_j();
                                        scope[ctrlAs].$$internal_refresh_dsdata_s();
                                    }

                                    form_data_assign_count.s1 ++;
                                },
                                true
                            );

                            //-------------- 监控表单驾驶员2的变化 ----------------//
                            scope.$watch(
                                function() {
                                    return scope[ctrlAs].fd.j2;
                                },
                                function(newValue, oldValue) {
                                    if (form_data_assign_count.j2 > 2) {
                                        if (newValue.id) {
                                            if (newValue.id && newValue.name && newValue.jobCode) {
                                                new_j2 = newValue.id + "_" + newValue.name + "_" + newValue.jobCode;
                                            } else {
                                                new_j2 = undefined;
                                            }
                                        } else {
                                            new_j2 = undefined;
                                        }

                                        scope[ctrlAs].$$internal_refresh_dsdata_j();
                                        scope[ctrlAs].$$internal_refresh_dsdata_s();
                                    }

                                    form_data_assign_count.j2 ++;
                                },
                                true
                            );

                            //-------------- 监控表单售票员2的变化 ----------------//
                            scope.$watch(
                                function() {
                                    return scope[ctrlAs].fd.s2;
                                },
                                function(newValue, oldValue) {
                                    if (form_data_assign_count.s2 > 2) {
                                        if (newValue && newValue.id) {
                                            if (newValue.id && newValue.name && newValue.jobCode) {
                                                new_s2 = newValue.id + "_" + newValue.name + "_" + newValue.jobCode;
                                            } else {
                                                new_s2 = undefined;
                                            }
                                        } else {
                                            new_s2 = undefined;
                                        }

                                        scope[ctrlAs].$$internal_refresh_dsdata_j();
                                        scope[ctrlAs].$$internal_refresh_dsdata_s();
                                    }

                                    form_data_assign_count.s2 ++;
                                },
                                true
                            );

                            //-------------------- 监控ds的变化,更新数据源,初始化formdata的数据 ---------------//
                            scope.$watch(
                                function() {
                                    return scope[ctrlAs].ds;
                                },
                                function(newValue, oldValue) {
                                    if (newValue && newValue.length > 0) {
                                        var j1 = newValue[0].j;

                                        var cl_idFlags = []; // 车辆idFlags数组(有顺序)
                                        var j_s_idFlags = []; // 驾驶员idFlags,售票员idFlags,[{j:idFlag,s:idFlag},...](有顺序)
                                        var addreason = []; // 营运调度的原因
                                        var adddesc = []; // 营运导读的备注
                                        var isRepeat = false;
                                        var i = 0;

                                        angular.forEach(newValue, function(obj, index) {
                                            var k1 = obj.cl + "_" + obj.clZbh;
                                            var k2 = !obj.j? undefined: obj.j + "_" + obj.jName + "_" + obj.jGh;
                                            var k3 = !obj.s? undefined: obj.s + "_" + obj.sName + "_" + obj.sGh;

                                            if (!old_cl[k1]) {
                                                old_cl[k1] = [];
                                            }
                                            if (!old_j[k2] && k2) {
                                                old_j[k2] = [];
                                            }
                                            if (!old_s[k3] && k3) {
                                                old_s[k3] = [];
                                            }

                                            var dd4 = obj.modifyReason == null || obj.modifyReason == undefined ? undefined :
                                                obj.modifyReason;
                                            var dd5 = obj.modifyRemark == null || obj.modifyRemark == undefined ? undefined :
                                                obj.modifyRemark;

                                            if (!old_ddreason[dd4] && dd4) {
                                                old_ddreason[dd4] = [];
                                            }
                                            if (!old_dddesc[dd5] && dd5) {
                                                old_dddesc[dd5] = [];
                                            }

                                            // 闭包
                                            (function(i) {
                                                old_cl[k1].push(i);
                                                if (k2) {
                                                    old_j[k2].push(i);
                                                }
                                                if (k3) {
                                                    old_s[k3].push(i);
                                                }
                                                if (dd4) {
                                                    old_ddreason[dd4].push(i);
                                                }
                                                if (dd5) {
                                                    old_dddesc[dd5].push(i);
                                                }
                                            })(index);

                                            // 判断是否分班
                                            if (j1 != obj.j && !old_isfb) {
                                                old_isfb = true;
                                                old_isfb_index = index;
                                            }

                                            // 判断进出场
                                            if (obj.bcType == 'in' && !old_hasJCBC) {
                                                old_hasJCBC = true;
                                                old_firstJCBCFcno = obj.fcno;
                                            }

                                            //-------------- formdata用数据处理 -------------//
                                            // 车辆处理
                                            isRepeat = false;
                                            if (obj.cl) {
                                                for (i = 0; i < cl_idFlags.length; i++) {
                                                    if (cl_idFlags[i] == (obj.cl + "_" + obj.clZbh)) {
                                                        isRepeat = true;
                                                        break;
                                                    }
                                                }
                                                if (!isRepeat) {
                                                    cl_idFlags.push(obj.cl + "_" + obj.clZbh);
                                                }
                                            }

                                            // 人员处理(以驾驶员id为主,没有的话,售票员不管了)
                                            isRepeat = false;
                                            if (obj.j) {
                                                for (i = 0; i < j_s_idFlags.length; i++) {
                                                    if (j_s_idFlags[i].j == (obj.j + "_" + obj.jName + "_" + obj.jGh)) {
                                                        isRepeat = true;
                                                        break;
                                                    }
                                                }
                                                if (!isRepeat) {
                                                    j_s_idFlags.push({
                                                        j: obj.j + "_" + obj.jName + "_" + obj.jGh,
                                                        s: !obj.s? undefined: (obj.s + "_" + obj.sName + "_" + obj.sGh)
                                                    });
                                                }
                                            }

                                            // 调度原因处理
                                            isRepeat = false;
                                            if (obj.modifyReason || obj.modifyReason == 0) {
                                                for (i = 0; i < addreason.length; i++) {
                                                    if (addreason[i] == obj.modifyReason) {
                                                        isRepeat = true;
                                                        break;
                                                    }
                                                }
                                                if (!isRepeat) {
                                                    addreason.push(obj.modifyReason);
                                                }
                                            }

                                            // 调整备注处理
                                            isRepeat = false;
                                            if (obj.modifyRemark && obj.modifyRemark != "") {
                                                for (i = 0; i < adddesc.length; i++) {
                                                    if (adddesc[i] == obj.modifyRemark) {
                                                        isRepeat = true;
                                                        break;
                                                    }
                                                }
                                                if (!isRepeat) {
                                                    adddesc.push(obj.modifyRemark);
                                                }
                                            }

                                        });

                                        old_max_fcno = newValue[newValue.length - 1].fcno;
                                        old_half_bcs = newValue.length / 2;

                                        // 更新formdata
                                        for (i = 0; i < cl_idFlags.length; i++) { // 车辆更新前两辆
                                            if (i == 0) { // 第一组车
                                                scope[ctrlAs].fd["cl1"].id = cl_idFlags[i].split("_")[0];
                                                new_cl1 = cl_idFlags[i];
                                            } else if (i == 1) { // 第二组车
                                                scope[ctrlAs].fd["cl2"].id = cl_idFlags[i].split("_")[0];
                                                new_cl2 = cl_idFlags[i];
                                            } else { // 第三组及以上车全部忽略
                                                break;
                                            }
                                        }
                                        for (i = 0; i < j_s_idFlags.length; i++) { // 人员更新
                                            if (i == 0) { // 第一组人员
                                                scope[ctrlAs].fd["j1"].id = j_s_idFlags[i].j.split("_")[0];
                                                scope[ctrlAs].fd["s1"].id = j_s_idFlags[i].s && j_s_idFlags[i].s.split("_")[0];
                                                new_j1 = j_s_idFlags[i].j;
                                                new_s1 = j_s_idFlags[i].s;

                                            } else if (i == 1) { // 第二组人员
                                                scope[ctrlAs].fd["j2"].id = j_s_idFlags[i].j.split("_")[0];
                                                scope[ctrlAs].fd["s2"].id = j_s_idFlags[i].s && j_s_idFlags[i].s.split("_")[0];
                                                new_j2 = j_s_idFlags[i].j;
                                                new_s2 = j_s_idFlags[i].s;
                                            } else { // 第三组及以上全部忽律
                                                break;
                                            }
                                        }
                                        // 更新form_data_assign_count,有值设置成2,没值设置成3,表示已经从ds处初始化完毕
                                        if (new_cl1) {
                                            form_data_assign_count["cl1"] = 2;
                                        } else {
                                            form_data_assign_count["cl1"] = 3;
                                        }
                                        if (new_cl2) {
                                            form_data_assign_count["cl2"] = 2;
                                        } else {
                                            form_data_assign_count["cl2"] = 3;
                                        }
                                        if (new_j1) {
                                            form_data_assign_count["j1"] = 2;
                                        } else {
                                            form_data_assign_count["j1"] = 3;
                                        }
                                        if (new_j2) {
                                            form_data_assign_count["j2"] = 2;
                                        } else {
                                            form_data_assign_count["j2"] = 3;
                                        }
                                        if (new_s1) {
                                            form_data_assign_count["s1"] = 2;
                                        } else {
                                            form_data_assign_count["s1"] = 3;
                                        }
                                        if (new_s2) {
                                            form_data_assign_count["s2"] = 2;
                                        } else {
                                            form_data_assign_count["s2"] = 3;
                                        }


                                        for (i = 0; i < addreason.length; i++) { // 调度原因更新
                                            if (i > 1) { // 有多个,只更新第一个
                                                break;
                                            } else {
                                                scope[ctrlAs].fd.ddr = addreason[i];
                                            }
                                        }
                                        for (i = 0; i < adddesc.length; i++) {
                                            if (i > 1) { // 有多个,只更新第一个
                                                break;
                                            } else {
                                                scope[ctrlAs].fd.ddrdesc = adddesc[i];
                                            }
                                        }
                                    }
                                }
                            );
                        }
                    }
                }
            };
        }
    ]
);
/**
 * saPlanInfoView指令,排班明细显示指令(以类似时刻表的形式显示)
 */
angular.module('ScheduleApp').directive(
    'saPlaninfoview',
    [
        '$compile',
        '$window',
        '$timeout',
        function($compile, $window, $timeout) {
            return {
                restrict: 'E',
                templateUrl: '/pages/scheduleApp/module/common/dts2/scheduleplan/saPlanInfoViewTemplate.html',
                scope: { // 独立作用域
                    ds: "=ngModel",
                    celldbclickFn: "&celldbclick",
                    toolbarLpLbClickFn: "&toolbarlplbclick"
                },
                controllerAs: "$saPlanInfoViewCtrl",
                bindToController: true,
                controller: function() {
                    var self = this;
                    // .ttInfo_detail高度
                    self.ttInfo_detail_height = 800;
                    // ds绑定的数据-路牌扩展数据
                    self.ds_ext_lp_info = {"路牌名字" : {allLb : "关联的班次是否全部烂班(true/false)"}};
                    // ds绑定的数据-线路扩展数据
                    self.ds_ext_xl_info = {"dir0_qdzName" : "上线起点站名字", "dir0_tip_width" : "上行图标宽度",
                        "dir1_qdzName" : "下行起点站名字", "dir1_tip_width" : "下行图标宽度"};
                    // ds绑定的数据-标题扩展数据1
                    self.ds_head_info1 = ["路牌", "驾驶员", "自编号", "车牌号"];
                    // ds绑定的数据-标题扩展数据2
                    self.ds_head_info2 = [];

                    // TODO:后面可能还有其他扩展信息

                },
                /**
                 * compile阶段,angular还没有编译模版,根据需要可以修改模版dom
                 * @param tElem
                 * @param tAttrs
                 * @returns {{pre: Function, post: Function}}
                 */
                compile: function(tElem, tAttrs) {
                    // 获取属性
                    var $attr_name = tAttrs["name"]; // 控件的名字
                    if (!$attr_name) {
                        throw new Error("saPlanInfoView指令 name属性required");
                    }

                    var $attr_celldbclick = tAttrs["celldbclick"]; // 单元格双击事件名
                    var $atrr_toolbarlplbclick = tAttrs["toolbarlplbclick"]; // 工具栏路牌烂班点击事件

                    // 内部controlAs名字
                    var ctrlAs = '$saPlanInfoViewCtrl';

                    return {
                        pre: function(scope, element, attr) {
                            // TODO:

                        },
                        post: function(scope, element, attr) {
                            // TODO:

                            // ------------------- dom事件处理function -----------------//
                            scope[ctrlAs].$$cell_click = function(rowindex, colindex, cell) {
                                console.log("click " + "row=" + rowindex + ",col=" + colindex);
                                if (cell.id) { // 有排班明细id的cell才能操作
                                    cell.sel = !cell.sel; // 是否选中toggle
                                }

                            };
                            scope[ctrlAs].$$cell_dbclick = function(rowindex, colindex, cell) {
                                if (cell.id) { // 有排班明细id的cell才能操作
                                    if ($attr_celldbclick) {
                                        // 注意调用方法
                                        scope[ctrlAs].celldbclickFn()(rowindex, colindex);
                                    }
                                }
                            };
                            // 工具栏单击事件
                            scope[ctrlAs].$$toolbar1_dbclick = function() {
                                if ($atrr_toolbarlplbclick) {
                                    scope[ctrlAs].toolbarLpLbClickFn()();
                                }

                            };

                            // ------------------- 监控function ------------------//
                            // 监控 ds: "=ngModel" 数据
                            scope.$watch(
                                function() {
                                    return scope[ctrlAs].ds;
                                },
                                function(newValue) {
                                    // 创建ds绑定的数据-路牌扩展数据
                                    if (newValue["contents"]) {
                                        angular.forEach(newValue["contents"], function(value) {
                                            var _lpName = value[0]["lpName"];
                                            scope[ctrlAs]["ds_ext_lp_info"][_lpName] = {allLb : false};
                                            var _bcCounts = 0; // 班次总数
                                            var _lbBcCounts = 0; // 烂班班次总数
                                            angular.forEach(value, function(bc) {
                                                if (bc.id) {
                                                    _bcCounts ++;
                                                    if (bc.status == -1) {
                                                        _lbBcCounts ++;
                                                    }
                                                }
                                            });
                                            if (_bcCounts > 0 && _bcCounts == _lbBcCounts) {
                                                scope[ctrlAs]["ds_ext_lp_info"][_lpName].allLb = true;
                                            }
                                        });
                                    }

                                    // 创建ds绑定数据-线路扩展数据
                                    scope[ctrlAs]["ds_ext_xl_info"] = {};
                                    scope[ctrlAs]["ds_ext_xl_info"].dir0_qdzName = "";
                                    scope[ctrlAs]["ds_ext_xl_info"].dir1_qdzName = "";
                                    scope[ctrlAs]["ds_ext_xl_info"].dir0_tip_width = 50;
                                    scope[ctrlAs]["ds_ext_xl_info"].dir1_tip_width = 50;
                                    if (newValue["contents"]) {
                                        angular.forEach(newValue["contents"], function(value) {
                                            if (scope[ctrlAs]["ds_ext_xl_info"].dir0_qdzName
                                                && scope[ctrlAs]["ds_ext_xl_info"].dir1_qdzName) {
                                                return;
                                            }
                                            angular.forEach(value, function (bc) {
                                                if (bc.id && bc.bcType == 'normal') {
                                                    if (bc.xlDir == '0' && bc.qdzName && !scope[ctrlAs]["ds_ext_xl_info"].dir0_qdzName) {
                                                        scope[ctrlAs]["ds_ext_xl_info"].dir0_qdzName = bc.qdzName;
                                                        scope[ctrlAs]["ds_ext_xl_info"].dir0_tip_width += bc.qdzName.length * 15;
                                                    } else if (bc.xlDir == '1' && bc.qdzName && !scope[ctrlAs]["ds_ext_xl_info"].dir1_qdzName) {
                                                        scope[ctrlAs]["ds_ext_xl_info"].dir1_qdzName = bc.qdzName;
                                                        scope[ctrlAs]["ds_ext_xl_info"].dir1_tip_width += bc.qdzName.length * 15;
                                                    }
                                                }

                                            })
                                        });
                                    }

                                    // 计算 .ttInfo_detail高度
                                    scope[ctrlAs]["ttInfo_detail_height"] = 0;
                                    var toolbar_height = 31; // 工具栏高度(参见template css)
                                    var tt_table_head_height = 36; // 表格标题高度(参见template css)
                                    var table_info_height = 30; // 表格行高度(参见template css)
                                    var table_extra_height = 30; // 表格修正高度
                                    if (newValue["contents"]) {
                                        scope[ctrlAs]["ttInfo_detail_height"] =
                                            toolbar_height +
                                            tt_table_head_height +
                                            table_info_height * newValue["contents"].length +
                                            table_extra_height;
                                    }

                                    // 创建ds绑定的数据-标题扩展数据2
                                    scope[ctrlAs]["ds_head_info2"] = [];
                                    angular.forEach(newValue["header"], function(head) {
                                        if (head != '路牌' && head != '驾驶员' && head != '自编号' && head != '车牌号') {
                                            scope[ctrlAs]["ds_head_info2"].push(head);
                                        }
                                    });
                                    // 2个班次一组 [上行group_no,下行group_no],从1开始
                                    var group_num = 1;
                                    var group_num_array = [1, 1];
                                    for (var i = 0; i < scope[ctrlAs]["ds_head_info2"].length; i++) {
                                        var head = scope[ctrlAs]["ds_head_info2"][i];
                                        if (head == scope[ctrlAs]["ds_ext_xl_info"].dir0_qdzName) {
                                            scope[ctrlAs]["ds_head_info2"][i] = head.substr(0, 1) + group_num_array[0];
                                        } else {
                                            scope[ctrlAs]["ds_head_info2"][i] = head.substr(0, 1) + group_num_array[1];
                                            group_num ++ ;
                                            group_num_array = [group_num, group_num];
                                        }

                                        // TODO:如果是环线的话,目前group_num都是1,后面如果有变化再修正
                                    }

                                    // TODO:

                                },
                                true
                            );

                        }

                    };

                }
            };
        }
    ]
);