prj-common-directive.js 117 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
// 自定义指令,指令模版在dt目录下


angular.module('ScheduleApp').directive('loadingWidget', ['requestNotificationChannel', function(requestNotificationChannel) {
    return {
        restrict: 'A',
        link: function(scope, element) {
            // 初始隐藏loading界面
            element.hide();

            // 开始请求通知处理
            requestNotificationChannel.onRequestStarted(scope, function() {
                element.show();
            });
            // 请求结束通知处理
            requestNotificationChannel.onRequestEnded(scope, function() {
                element.hide();
            });
        }
    };
}]);

angular.module('ScheduleApp').directive("saSelect", ['$timeout', function($timeout) {
    return {
        restrict: 'E',
        templateUrl: '/pages/scheduleApp/module/other/MyDictionarySelectTemplate.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);
                }
            }
        }
    };
}]);

/**
 * 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/dt/MyRadioGroupWrapTemplate.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;
                            }
                        };
                    }
                }
            };
        }
    };
}]);

angular.module('ScheduleApp').directive("remoteValidaton", [
    'BusInfoManageService_g',
    'EmployeeInfoManageService_g',
    'TimeTableManageService_g',
    function(
        busInfoManageService_g,
        employeeInfoManageService_g,
        timeTableManageService_g
    ) {
        /**
         * 远端验证指令,依赖于ngModel
         * 指令名称 remote-Validation
         * 需要属性 rvtype 表示验证类型
         */
        return {
            restrict: "A",
            require: "^ngModel",
            link: function(scope, element, attr, ngModelCtrl) {
                element.bind("keyup", function() {
                    var modelValue = ngModelCtrl.$modelValue;
                    var rv1_attr = attr["rv1"];
                    if (attr["rvtype"]) {

                        // 根据rvtype的值,确定使用那个远端验证的url,
                        // rv1, rv2, rv3是关联比较值,暂时使用rv1
                        // 这个貌似没法通用,根据业务变换
                        // TODO:暂时有点乱以后改
                        if (attr["rvtype"] == "insideCode") {
                            busInfoManageService_g.validate.insideCode(
                                {"insideCode_eq": modelValue, type: "equale"},
                                function(result) {
                                    //console.log(result);
                                    if (result.status == "SUCCESS") {
                                        ngModelCtrl.$setValidity('remote', true);
                                    } else {
                                        ngModelCtrl.$setValidity('remote', false);
                                    }
                                },
                                function(result) {
                                    //console.log(result);
                                    ngModelCtrl.$setValidity('remote', true);
                                }
                            );
                        } else if (attr["rvtype"] == "jobCode") {
                            if (!rv1_attr) {
                                ngModelCtrl.$setValidity('remote', false);
                                return;
                            }

                            employeeInfoManageService_g.validate.jobCode(
                                {"jobCode_eq": modelValue, "companyCode_eq": rv1_attr, type: "equale"},
                                function(result) {
                                    //console.log(result);
                                    if (result.status == "SUCCESS") {
                                        ngModelCtrl.$setValidity('remote', true);
                                    } else {
                                        ngModelCtrl.$setValidity('remote', false);
                                    }
                                },
                                function(result) {
                                    //console.log(result);
                                    ngModelCtrl.$setValidity('remote', true);
                                }
                            );
                        } else if (attr["rvtype"] == "ttinfoname") {
                            if (!rv1_attr) {
                                ngModelCtrl.$setValidity('remote', false);
                                return;
                            }

                            timeTableManageService_g.validate.ttinfoname(
                                {"name_eq": modelValue, "xl.id_eq": rv1_attr, type: "equale"},
                                function(result) {
                                    //console.log(result);
                                    if (result.status == "SUCCESS") {
                                        ngModelCtrl.$setValidity('remote', true);
                                    } else {
                                        ngModelCtrl.$setValidity('remote', false);
                                    }
                                },
                                function(result) {
                                    //console.log(result);
                                    ngModelCtrl.$setValidity('remote', true);
                                }
                            );

                        }
                    } else {
                        // 没有rvtype,就不用远端验证了
                        ngModelCtrl.$setValidity('remote', true);
                    }

                    attr.$observe("rv1", function(value) {
                        if (attr["rvtype"] == "jobCode") {
                            if (!value) {
                                ngModelCtrl.$setValidity('remote', false);
                                return;
                            }

                            employeeInfoManageService_g.validate.jobCode(
                                {"jobCode_eq": modelValue, "companyCode_eq": rv1_attr, type: "equale"},
                                function(result) {
                                    //console.log(result);
                                    if (result.status == "SUCCESS") {
                                        ngModelCtrl.$setValidity('remote', true);
                                    } else {
                                        ngModelCtrl.$setValidity('remote', false);
                                    }
                                },
                                function(result) {
                                    //console.log(result);
                                    ngModelCtrl.$setValidity('remote', true);
                                }
                            );
                        } else if (attr["rvtype"] == "ttinfoname") {
                            if (!value) {
                                ngModelCtrl.$setValidity('remote', false);
                                return;
                            }

                            console.log("rv1:" + value);

                            timeTableManageService_g.validate.ttinfoname(
                                {"name_eq": modelValue, "xl.id_eq": value, type: "equale"},
                                function(result) {
                                    //console.log(result);
                                    if (result.status == "SUCCESS") {
                                        ngModelCtrl.$setValidity('remote', true);
                                    } else {
                                        ngModelCtrl.$setValidity('remote', false);
                                    }
                                },
                                function(result) {
                                    //console.log(result);
                                    ngModelCtrl.$setValidity('remote', true);
                                }
                            );
                        }

                    });
                });
            }
        };
    }]);


/**
 * saSelect2指令,根据属性值,动态载入数据,然后支持拼音搜索,点击右边的按钮清除选择并重新载入数据。
 * 1、compile阶段使用的属性如下:
 *      required:用于和表单验证连接,指定成required="true"才有效。
 * 2、link阶段使用的属性如下
 *      model:关联的模型对象
 *      name:表单验证时需要的名字
 *      type:关联的那种数据值(xl/cl/ry)-> 对应线路信息/车辆信息/人员信息,后面有的继续加
 *      modelcolname1:关联的模型字段名字1(一般应该是编码字段)
 *      modelcolname2:关联的模型字段名字2(一般应该是名字字段)
 *      datacolname1;内部数据对应的字段名字1(与模型字段1对应)
 *      datacolname2:内部数据对应的字段名字2(与模型字段2对应)
 *      showcolname:下拉框显示的内部数据字段名(注意:不是模型数据字段名),TODO:以后考虑放动态表达式,并在compile阶段使用
 *      placeholder:select placeholder字符串描述
 *
 * $$pyFilter,内部的filter指令,结合简拼音进行拼音过滤。
 * $$SearchInfoService_g,内部使用的数据服务
 */
// saSelect2指令使用的内部信service
angular.module('ScheduleApp').factory('$$SearchInfoService_g', ['$resource', function($resource) {
    return {
        xl: $resource(
            '/line/:type',
            {order: 'name', direction: 'ASC'},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        ),
        zd: $resource(
            '/stationroute/stations',
            {order: 'stationCode', direction: 'ASC'},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        ),
        tcc: $resource(
            '/carpark/:type',
            {order: 'parkCode', direction: 'ASC'},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        ),
        ry: $resource(
            '/personnel/:type',
            {order: 'personnelName', direction: 'ASC'},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        ),
        cl: $resource(
            '/cars/:type',
            {order: "insideCode", direction: 'ASC'},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        ),
        ttInfo: $resource(
            '/tic/:type',
            {order: "name", direction: 'ASC'},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        ),
        cci: $resource(
            '/cci/cars',
            {},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }

        ),
        cci2: $resource(
            '/cci/:type',
            {},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        ),
        cci3: $resource(
            '/cci/cars2',
            {},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }

        ),
        eci: $resource(
            '/eci/jsy',
            {},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        ),
        eci2: $resource(
            '/eci/spy',
            {},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        )
    }
}]);
angular.module('ScheduleApp').filter("$$pyFilter", function() {
    return function(items, props) {
        var out = [];
        var limit = props["limit"] || 20; // 默认20条记录

        if (angular.isArray(items)) {
            items.forEach(function(item) {
                if (out.length < limit) {
                    if (props.search) {
                        var upTerm = props.search.toUpperCase();
                        if(item.fullChars.indexOf(upTerm) != -1
                            || item.camelChars.indexOf(upTerm) != -1) {
                            out.push(item);
                        }
                    }
                }
            });
        }

        return out;
    };
});
angular.module('ScheduleApp').directive("saSelect2", [
    '$timeout', '$$SearchInfoService_g',
    function($timeout, $$searchInfoService_g) {
        return {
            restrict: 'E',
            templateUrl: '/pages/scheduleApp/module/other/MySearchSelectTemplate.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/dt/MyUiSelectWrapTemplate1.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");
                            // 清空内部数据
                            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) {

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

    }
]);

/**
 * 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/dt/MyCheckboxGroupWrapTemplate.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/dt/MyDateGroupWrapTemplate.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
                                        }
                                    );
                                }









                            }
                        });

                    }

                };
            }
        }
    }
]);

/**
 * 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/dt/MyGuideboardGroupWrapTemplate.html',
            scope: {
                model: "=" // 独立作用域,关联外部的模型object
            },
            controllerAs: '$saGuideboardgroupCtrl',
            bindToController: true,
            controller: function($scope) {
                var self = this;
                self.$$data = []; // 选择线路后,该线路的路牌数据

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


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

                //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;
                        }

                        // TODO:


                        /**
                         * 路牌列表点击(路牌列表中选中路牌)
                         * @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();
                            }
                        );


                        // 监控线路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].$$data = [];
                                        for (var i = 0; i < result.content.length; i++) {
                                            scope[ctrlAs].$$data.push({
                                                lpid: result.content[i].id,
                                                lpname: result.content[i].lpName,
                                                isstart: false
                                            });
                                        }
                                        if (scope[ctrlAs].$$data_init) {
                                            scope[ctrlAs].$$dataSelected = [];
                                            scope[ctrlAs].$$dataSelectedStart = undefined;
                                            scope[ctrlAs].$$internalmodel = 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/dt/MyEmployeeGroupWrapTemplate.html',
            scope: {
                model: "=" // 独立作用域,关联外部的模型object
            },
            controllerAs: '$saEmployeegroupCtrl',
            bindToController: true,
            controller: function($scope) {
                var self = this;
                self.$$data = []; // 选择线路后,该线路的人员配置数据

                // 测试数据
                //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.$$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.$$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;
                        }

                        /**
                         * 人员配置列表点击(人员配置列表中选中路牌)
                         * @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,
                                        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,
                                            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,
                                                    isselected: false
                                                }, {
                                                    id : data_temp[$index].id,
                                                    dbbm: data_temp[$index].dbbm,
                                                    jsy: data_temp[$index].jsy,
                                                    spy: data_temp[$index].spy,
                                                    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.$$data;
                            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) {
                                console.log("开始初始化数据");

                                // 判定是否分班,字符串中包含-就是了
                                if (self.$$data_ry_first_data.indexOf("-") != -1) { // 分班
                                    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;
                                                    break;
                                                }
                                            }
                                        }

                                    }

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


                                } else {
                                    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;
                                                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();
                            }
                        );


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

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

                                        scope[ctrlAs].$$data = [];
                                        for (var i = 0; i < result.content.length; i++) {
                                            scope[ctrlAs].$$data.push({
                                                id: result.content[i].id,
                                                dbbm: result.content[i].dbbm,
                                                jsy: result.content[i].jsy.personnelName,
                                                spy: result.content[i].spy == null ? "" : result.content[i].spy.personnelName
                                            });
                                        }
                                        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].$$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;
                            }
                        });

                    }
                }

            }
        }
    }
]);