roadList.esp 35.3 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
<!DOCTYPE html>
<html>

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>动态参数</title>
	<link href="../../css/frame.css" rel="stylesheet" />
	<link href="../../css/bus.css" rel="stylesheet" />
	<link href="../../scripts/easyui/themes/default/easyui.css" rel="stylesheet" />
	<style type="text/css">
		.timeSpans {
			background: url(../../images/timePicker.png) no-repeat 100.5% -1px white;
			border: 1px solid grey;
			height: 21px;
		}

		/*时间段选择窗口样式*/

		.timeSelector {
			min-height: 120px;
			width: 246px;
			padding: 8px;
			position: absolute;
			top: 0;
			left: 0;
			display: none;
			background-color: white;
			border: 1px solid #7C8895;
			z-index: 99;
			height: 120px;
		}

		.timeSelector .Wdate {
			width: 96px;
		}

		.timeSelector .btnDelete {
			display: block;
			float: right;
			margin-top: 3px;
			width: 16px;
			height: 16px;
			background: url(../../images/btnDelete.png) no-repeat 0 0;
		}

		.timeSelector a.settingBtn {
			float: left;
			margin-right: 14px;
		}

		.timeSpanContainer {
			height: 100px;
			overflow: auto;
		}

		.timeSpanContainer li {
			margin-bottom: 5px;
		}
	</style>
</head>

<body>
	<div>

		<form action="" id="titleForm">
			<table class="settingsContainer" style="margin-left: 10px;">
				<!--<tr>
					<td class="tdTitle">占用公交车道</td>
					<td class="tdContent"><input id="" name=""
						class="settingParameter needReboot" type="text" /></td>
				</tr>
				<tr>
					<td class="tdTitle">机动车车牌类型</td>
					<td class="tdContent"><select id="" name=""
						class="settingParameter">
							<option id="yellow">黄牌</option>
							<option id="blue">蓝牌</option>
							<option id="white">白牌</option>
							<option id="black">黑牌</option>
					</select></td>
				</tr>-->
				<tr>
					<td class="tdTitle">
						<a href="#" class="settingBtn" id="loadRoadInfo" onclick="loadLineInfo()">加载线路信息</a>
					</td>
					<td class="tdContent">
						<a href="#" class="settingBtn" id="downloadRoad" onclick="downloadLine()">导出线路信息</a>
					</td>
				</tr>
				<tr>
					<td class="tdTitle">线路版本:</td>
					<td class="tdContent">
						<span id="roadVersion"></span>
					</td>
					<td class="tdTitle">线路个数:</td>
					<td class="tdContent">
						<span id="roadCount"></span>
					</td>
					<td class="tdTitle"></td>
					<td class="tdContent">
						<a href="#" class="settingBtn" id="addLine">添加线路</a>
					</td>
				</tr>
			</table>

		</form>

		<form id="gridForm" style="padding-top: 10px">
		</form>

		<div style="display: none;">
			<div id="loadLine" class="easyui-dialog dialogDiv" data-options="resizable:true,modal:true,closed:true">
				<form id="loadLineForm" action="/do/trafficController/importFile?FileType=BusLine.Xml" method="POST" enctype="multipart/form-data">
					<table>
						<tr>
							<td class="tdTitle">选择文件</td>
							<td class="tdContent">
								<input id="lineFile" name="file" type="file" class="fileInput" value="" />
							</td>
						</tr>
					</table>
					<% inputSecurityToken(); %>
				</form>
			</div>

			<div id="editLine" class="easyui-dialog dialogDiv" data-options="resizable:true,modal:true,closed:true">
				<form id="editLineForm">
					<table>
						<tr>
							<td class="tdTitle">线路编号:</td>
							<td class="tdContent">
								<input id="line_no" name="line_no" onkeyup="value=value.replace(/[^a-zA-Z0-9]/g,'')" class="settingParameter needReboot"
								 type="text" />
							</td>
						</tr>
						<tr>
							<td class="tdTitle">线路名称:</td>
							<td class="tdContent">
								<input id="line_name" name="line_name" class="settingParameter needReboot" type="text" />
							</td>
						</tr>
						<input id="line_id" name="line_id" style="display:none;" />
					</table>
				</form>
			</div>
			<div id="editRoad" class="easyui-dialog dialogDiv" data-options="resizable:true,modal:true,closed:true">
				<form id="editRoadForm">
					<table>
						<tr>
							<td class="tdTitle" style="display: none">路段序号:</td>
							<td class="tdContent" style="display: none">
								<input id="road_seq" name="road_seq" class="settingParameter needReboot" type="text" />
							</td>

						</tr>
						<tr>
							<td class="tdTitle">路段编号:</td>
							<td class="tdContent">
								<input id="road_no" name="road_no" onkeyup="value=value.replace(/[^a-zA-Z0-9]/g,'')" class="settingParameter needReboot"
								 type="text" />
							</td>
							<td class="tdTitle">路段类型:</td>
							<td class="tdContent">
								<select id="road_type" name="road_type" class="settingParameter">
									<option value="限行路段">限行路段</option>
									<option value="封闭路段">封闭路段</option>
								</select>
							</td>

						</tr>
						<tr>
							<td class="tdTitle">路段名称:</td>
							<td class="tdContent" colspan="3">
								<input id="road_name" name="road_name" class="settingParameter needReboot" type="text" style="width: 410px" />
							</td>
						</tr>

						<tr>
							<td class="tdTitle">路段方向:</td>
							<td class="tdContent">
								<input id="road_direction" name="road_direction" class="settingParameter needReboot" type="text" />
							</td>
							<td class="tdTitle">交管局编号:</td>
							<td class="tdContent">
								<input id="extra_info_detail" name="extra_info_detail" class="settingParameter needReboot" type="text" />
							</td>

						</tr>
						<tr>
							<td class="tdTitle">开始经度:</td>
							<td class="tdContent">
								<input id="start_longitude" name="start_longitude" class="settingParameter needReboot" type="text" onkeyup="value=value.replace(/[^\d\.]/g,'') "
								/>
							</td>
							<td class="tdTitle">开始纬度:</td>
							<td class="tdContent">
								<input id="start_latitude" name="start_latitude" class="settingParameter needReboot" type="text" onkeyup="value=value.replace(/[^\d\.]/g,'') "
								/>
							</td>
						</tr>
						<tr>
							<td class="tdTitle">结束经度:</td>
							<td class="tdContent">
								<input id="end_longitude" name="end_longitude" class="settingParameter needReboot" type="text" onkeyup="value=value.replace(/[^\d\.]/g,'') "
								/>
							</td>
							<td class="tdTitle">结束纬度:</td>
							<td class="tdContent">
								<input id="end_latitude" name="end_latitude" class="settingParameter needReboot" type="text" onkeyup="value=value.replace(/[^\d\.]/g,'') "
								/>
							</td>
						</tr>

						<tr>
							<td class="tdTitle">限行时间:</td>
							<td class="tdContent" colspan="3">
								<input type="text" class="settingElement timeSpans" id="restrict_times" name="restrict_times" readonly="true" style="width: 410px"
								/>
								<div class="timeSelector">
									<ul class='timeSpanContainer'>
									</ul>
									<a class="timeSelectorAdd settingBtn">添加时间段</a>
									<a class="timeSelectorSave settingBtn">保存</a>
								</div>
							</td>

						</tr>
					</table>
				</form>
			</div>
		</div>
		<div id="roadDetail" class="roadDetail">
			<table border="0" cellpadding="0" cellspacing="0">
				<tr>
					<td class="tdTitle">路段序号:</td>
					<td class="tdContent">
						<span name="road_seq"></span>
					</td>
					<td class="tdTitle">路段编号:</td>
					<td class="tdContent">
						<span name="road_no"></span>
					</td>
				</tr>
				<tr>
					<td class="tdTitle">路段名称:</td>
					<td class="tdContent" colspan="3">
						<span name="road_name"></span>
					</td>
				</tr>
				<tr>
					<td class="tdTitle">路段类型:</td>
					<td class="tdContent">
						<span name="road_type"></span>
					</td>
					<td class="tdTitle">路段方向:</td>
					<td class="tdContent">
						<span name="road_direction"></span>
					</td>
				</tr>
				<tr>
					<td class="tdTitle">开始经度:</td>
					<td class="tdContent">
						<span name="start_longitude"></span>
					</td>
					<td class="tdTitle">开始纬度:</td>
					<td class="tdContent">
						<span name="start_latitude"></span>
					</td>
				</tr>
				<tr>
					<td class="tdTitle">结束经度:</td>
					<td class="tdContent">
						<span name="end_longitude"></span>
					</td>
					<td class="tdTitle">结束纬度:</td>
					<td class="tdContent">
						<span name="end_latitude"></span>
					</td>
				</tr>
				<tr>

					<td class="tdTitle">交管局编号:</td>
					<td class="tdContent">
						<span name="extra_info_detail"></span>
					</td>
					<td class="tdTitle">限行时间:</td>
					<td class="tdContent">
						<span name="restrict_times"></span>
					</td>
				</tr>
			</table>
		</div>
	</div>
	<script src="../../scripts/jquery-1.11.1.js"></script>
	<script src="../../scripts/easyui/jquery.easyui.min.js"></script>
	<script src="../../scripts/easyui/locale/easyui-lang-zh_CN.js"></script>
	<script src="../../scripts/easyui/jquery.easyui.extension.js"></script>
	<script src="../../scripts/My97DatePicker/WdatePicker.js"></script>
	<script src="../../scripts/jquery.doubletable.js"></script>
	<script src="../../scripts/utilities.js"></script>
	<script src="../../scripts/jquery.form.js"></script>
	<script src="../../scripts/jquery.validate.min.js"></script>
	<script src="../../scripts/jquery.validate.extend.js"></script>
	<script type="text/javascript">

		var roads, roadsUrl,
			arrNodes = ["line_detail", "road"], roadJson = {}, treeGrid, lineNos = [], roadNos = [], lineId = 0, maxId = 0;

		//roadJson 初始化
		roadJson.line_count = 0;
		roadJson.version = "0.0.0.1";
		roadJson.line_detail = [];

		var showedDatepicker;//已经显示的
		roadsUrl = "/do/trafficController/exportFile?FileType=BusLine.Xml&CodeType=utf-8";
		//        roadsUrl = "xml/roadTest.xml";
		var initxml = '<?xml version="1.0" encoding="utf-8"?><line_info><version>0.0.0.1</version><protocol>0.0.0.1</protocol></line_info>';
		var roadOriginalJson = {
			"road_seq": "", "road_no": "", "road_name": "", "road_type": "", "start_longitude": "", "start_latitude": "", end_longitude: "", "end_latitude": "",
			"restrict_times": "", "road_direction": "", "road_extra_info": ""
		};

		$(document).ready(function () {
			treeGrid = $("#gridForm").initTable();
			queryRoadJson(true);
			clickMethod();

		});

		function queryRoadJson(isFirst) {

			try {
				if (isFirst == null || isFirst == "deleteLine") {
					roadsUrl = "../../do/trafficController/exportFile?FileType=BusLine.Xml&CodeType=utf-8";
				}
				$.ajax({
					url: roadsUrl,
					type: 'post',
					data: { "-xsrf-": $("input[name='-xsrf-']").val() },
					success: function (xml) {
						lineId = 0;
						lineNos = [];
						roadNos = [];
						try {
							xml = $.trim(xml) || initxml;
							roads = $.parseXML(xml);
							roadJson = parseXmlToJson($(roads).find("line_info")[0].childNodes);
						}
						catch (e) {
							if (roadJson == null) {
								roadJson = {};
								roadJson.line_count = 0;
								roadJson.version = "0.0.0.1";
								roadJson.line_detail = [];
							}
						}
						//赋初始值
						initEval(roadJson);
						if (isFirst == true) {
							treeGrid.query(roadJson.line_detail || []);
							treeGrid.TRClick();
						} else if (isFirst == "deleteLine") {
							treeGrid.query(roadJson.line_detail || []);
						}
					},
					error: function (a, b, c) {
						alert(c);
					}
				});
			} catch (e) {
			}
		}

		function clickMethod() {

			$("#addLine").bind("click", function (event) {
				showLineEdit();
			});

			//时间选择控件
			$(".timeSpans").on("click", showTimeSelector).on("focus", onTimeSelectorFocus);

			$(".timeSelectorAdd").on("click", addTimePicker);//添加空的时间段选择框
			$(".timeSelectorSave").on("click", saveTimeSpans);//保存选择的时间段
			$(".timeSelector").on("click", function (e) {
				e.stopPropagation();
			});

			$("#gridForm").on("click", "a", function (event) {
				switch (event.target.id) {
					case "updateLine":
						showUpdateLineForm($(this).closest("tr").attr("id"));
						break;
					case "delLine":
						deleteLine($(this).closest("tr").attr("id"));
						break;
					case "addRoad":
						showAddRoadForm($(this).closest("tr").next("tr").find("table"), $(this).closest("tr").attr("id"));
						break;
					case "editRoadButton":
						showUpdateRoadForm($(this).closest("tr").attr("id"), $(this).closest("tr"));
						break;
					case "delRoadButton":
						deleteRoad($(this).closest("tr").attr("id"), $(this).closest("tr"));
						break;
				}
				return false;
			}).on("mouseover", "tr", function (event) {
				var $tr = $(this).closest("tr");
				if ($tr.attr("name") == "road" && $tr.attr("id")) {
					$tr.css("background-color", "#D6EEFF");
					showRoadDetail($tr, event);
				}

			}).on("mouseout", "tr", function (event) {
				var $tr = $(this).closest("tr");
				if ($tr.attr("name") == "road" && $tr.attr("id")) {
					$tr.css("background-color", "#EBEDF1");
				}
				$("#roadDetail").hide();
			});


		}

		//初始赋值
		function initEval() {
			$("#roadVersion").html(roadJson.version);
			$("#roadCount").html(roadJson.line_count);
		}

		function downloadLine() {
			var downloadUrl = "/do/trafficController/exportFile?FileType=BusLine.Xml";
			window.open(downloadUrl);
		}

		function loadLineInfo() {
			$("#loadLine").dialog({
				title: '加载线路信息',
				width: 500,
				height: 200,
				closed: false,
				cache: false,
				modal: true,
				buttons: [{
					text: '确认上传',
					handler: function () {
						var options = {
							dataType: "json",
							beforeSubmit: validateFileName,
							success: showUploadResult,
							error: onUploadError
						};
						//调用上传接口
						$("#loadLineForm").ajaxSubmit(options);
						$("#loadLine").dialog({ closed: true });
					}
				}, {
					text: '取消',
					handler: function () {
						$("#loadLine").dialog({ closed: true });
					}
				}]
			});
		}

		//检测上传文件是否正确
		function validateFileName(formData, jqForm, options) {
			var fileName;
			if (!formData || formData.length < 1 || formData[0].value == "") {
				$.messager.alert("提示", "请选择文件!", "error");
				return false;
			}
			//验证文件格式
			if (typeof (formData[0].value) == "object" && formData[0].value.name) {
				fileName = formData[0].value.name;
			} else {
				fileName = formData[0].value;
			}

			if (!isFileNameEndWith(fileName, "xml")) {
				$.messager.alert("提示", "必须为 .xml 后辍名的文件!", "error");
				return false;
			}

			//验证通过,显示进度条
			$.messager.progress({
				title: "",
				text: "上传中,请稍侯...",
				interval: 1000
			});
			return true;
		}

		function isFileNameEndWith(fileName, extenName) {
			return fileName.substring(fileName.length - extenName.length) == extenName;
		}

		function showUploadResult(response, statusText, xhr, $form) {
			if (response.error) {
				queryRoadJson();
				$.messager.alert("提示", "上传成功", "info");
			} else {
				$.messager.alert("提示", "失败!原因:" + response.feedback.Msg, "error");
			}
			$.messager.progress("close");
		}

		//当上传失败时显示出错信息
		function onUploadError() {
			$.messager.alert("提示", "上传失败!", "error");
			try {
				$.messager.progress("close");
			} catch (e) {

			}
		}

		//添加线路
		function showLineEdit() {
			//清空
			$("#editLine input").val("");
			//$("#editLine input[name='line_no']").removeAttr("readonly");
			$("#editLine").dialog({
				title: '添加线路信息',
				width: 400,
				height: 200,
				closed: false,
				cache: false,
				modal: true,
				buttons: [{
					text: '保存',
					handler: function () {
						//验证线路信息
						if (validateLine()) {
							var lineDetail = {};
							//验证成功后,保存线路信息
							$("#editLine form input").each(function (i, item) {
								if (item.name == "line_id") {

									lineDetail[item.name] = ++maxId;
									lineNos.push(lineDetail[item.name]);
								} else {
									lineDetail[item.name] = item.value;
								}

							});
							//roadJson 不存在则修改一个正常的值信息
							if (roadJson == null) {
								roadJson = {};
								roadJson.line_count = 0;
								roadJson.version = "0.0.0.1";
								roadJson.line_detail = [];

							}
							if (roadJson.line_detail == null || roadJson.line_detail == undefined) {
								roadJson.line_detail = [];
							}

							roadJson.line_detail.push(lineDetail);
							roadJson.line_count = parseInt(roadJson.line_count) + 1;
							$("#gridForm").addParent(lineDetail);
							$("#editLine").dialog({ closed: true });

							saveBusLine();
						}
					}
				}, {
					text: '取消',
					handler: function () {
						$("#editLine").dialog({ closed: true });
					}
				}]
			});

		}

		//修改线路
		function showUpdateLineForm(lineNo) {

			$.each(roadJson.line_detail, function (i, line) {
				if (line.line_id == lineNo) {
					$.each(line, function (key, value) {
						$("#editLine input[name='" + key + "']").val(value);
					});
					$("#editLine").dialog({
						title: '修改线路信息',
						width: 400,
						height: 200,
						closed: false,
						cache: false,
						modal: true,
						buttons: [{
							text: '保存',
							handler: function () {
								//验证线路信息
								if (validateLine()) {
									line.line_no = $("#editLine input[name='line_no']").val();
									line.line_name = $("#editLine input[name='line_name']").val();

									$("#editLine").updateParent(lineNo, line);
									$("#editLine").dialog({ closed: true });
									saveBusLine();
								}
							}
						}, {
							text: '取消',
							handler: function () {
								$("#editLine").dialog({ closed: true });
							}
						}]
					});
				}
			});
		}

		//删除线路
		function deleteLine(lineNo) {

			$.messager.confirm("提示", "删除线路信息后会级联删除路段信息,确认删除吗?", function (isConfirm) {
				if (isConfirm) {
					$.each(roadJson.line_detail, function (i, item) {
						if (null != item && item.line_id == lineNo) {
							roadJson.line_detail.splice(i, 1);
							$("#gridForm").deleteParent(lineNo);
							lineNos.splice(lineNos.indexOf(lineNo), 1);
							roadJson.line_count = parseInt(roadJson.line_count) - 1;
							saveBusLine(true);
						}
					});
					//                 	logInfo("删除线路信息:" + totalXml());
				} else {

				}
			});
		}

		//添加路段
		function showAddRoadForm($table, lineId) {
			$("#editRoad input").val('');
			$("#editRoad select").val('限行路段');
			$("#editRoad input[name='road_no']").removeAttr("readonly");

			$("#editRoad").dialog({
				title: '添加路段信息',
				width: 660,
				height: 300,
				closed: false,
				cache: false,
				modal: true,
				buttons: [{
					text: '保存',
					handler: function () {
						//验证线路信息
						if (validateRoad(lineId)) {
							$.each(roadJson.line_detail, function (i, line) {
								if (line.line_id == lineId) {
									var road = {};

									transferRoadFromEdit(road, "#editRoad");

									if (line.roads == null || line.roads == undefined || typeof (line.roads) != "object") {
										line.roads = {};
										line.roads.count = 0;
										line.roads.road = [];
									}
									if (line.roads.road == null || line.roads.road == undefined) {
										line.roads.road = [];
									}
									line.roads.count = parseInt(line.roads.count) + 1;
									road['road_seq'] = line.roads.count;

									line.roads.road.push(road);

									$("#editRoad").addChild($table, road, line.roads.count + 1);

									roadNos.push(lineId + "_" + road.road_no);

									saveBusLine();

									$("#editRoad").dialog({ closed: true });
									return false;
								}

							});

						}
					}
				}, {
					text: '取消',
					handler: function () {
						$("#editRoad").dialog({ closed: true });
					}
				}]
			});
		}

		//展示路段详情
		function showRoadDetail($tr, event) {
			$("#roadDetail span[name='road_seq']").html($tr.find("td").eq(0).html());
			$("#roadDetail span[name='road_no']").html($tr.find("td").eq(1).html());
			$("#roadDetail span[name='road_name']").html($tr.find("td").eq(2).html());
			$("#roadDetail span[name='road_type']").html($tr.find("td").eq(3).html());
			$("#roadDetail span[name='start_longitude']").html($tr.find("td").eq(4).html());
			$("#roadDetail span[name='start_latitude']").html($tr.find("td").eq(5).html());
			$("#roadDetail span[name='end_longitude']").html($tr.find("td").eq(6).html());
			$("#roadDetail span[name='end_latitude']").html($tr.find("td").eq(7).html());
			$("#roadDetail span[name='restrict_times']").html($tr.find("td").eq(9).html());
			$("#roadDetail span[name='road_direction']").html($tr.find("td").eq(10).html());
			$("#roadDetail span[name='extra_info_detail']").html($tr.find("td").eq(11).html());


			var bodyHeight = $("body").height();
			var bodyWidth = $("body").width();

			var clientX = event.clientX;
			var clientY = event.clientY;

			var divHeight = $("#roadDetail").height();
			var divWidth = $("#roadDetail").width()
			var left = clientX, top = clientY;

			if (clientX + divWidth > bodyWidth) {
				left = clientX - divWidth;
			}
			if (clientY + divHeight > bodyHeight) {
				top = clientY - divHeight;
			}

			$("#roadDetail").show().css("left", left).css("top", top);

		}

		function refreshRoad($tr) {
			$("#editRoad input[name='road_seq']").val($tr.find("td").eq(0).html());
			$("#editRoad input[name='road_no']").val($tr.find("td").eq(1).html());
			$("#editRoad input[name='road_name']").val($tr.find("td").eq(2).html());
			$("#editRoad select[name='road_type']").val($tr.find("td").eq(3).html());
			$("#editRoad input[name='start_longitude']").val($tr.find("td").eq(4).html());
			$("#editRoad input[name='start_latitude']").val($tr.find("td").eq(5).html());
			$("#editRoad input[name='end_longitude']").val($tr.find("td").eq(6).html());
			$("#editRoad input[name='end_latitude']").val($tr.find("td").eq(7).html());
			$("#editRoad input[name='restrict_times']").val($tr.find("td").eq(9).html());
			$("#editRoad input[name='road_direction']").val($tr.find("td").eq(10).html());
			$("#editRoad input[name='extra_info_detail']").val($tr.find("td").eq(11).html());
		}

		//修改路段
		function showUpdateRoadForm(roadNo, $tr) {
			$("#editRoad input[name='road_no']").attr("readonly", "readonly");
			refreshRoad($tr);
			var lineId = $tr.closest("table").closest("tr").prev().attr("id");
			$("#editRoad").dialog({
				title: '修改路段信息',
				width: 660,
				height: 300,
				closed: false,
				cache: false,
				modal: true,
				buttons: [{
					text: '保存',
					handler: function () {
						//验证线路信息
						if (validateRoad()) {
							$.each(roadJson.line_detail, function (i, item) {
								if (item.roads == undefined || item.roads.road == undefined || lineId != item.line_id) {
									return true;
								}
								$.each(item.roads.road, function (j, road) {
									if (road.road_no == $tr.attr("id")) {
										$("#editRoad").updateChild(roadNo, transferRoadFromEdit(road, "#editRoad"));
										roadNos.push(lineId + "_" + road.road_no);
										saveBusLine();
										$("#editRoad").dialog({ closed: true });
										return false;
									}
								});
							});
							$("#editRoad").dialog({ closed: true });
						}
					}
				}, {
					text: '取消',
					handler: function () {
						$("#editRoad").dialog({ closed: true });
					}
				}]
			});
		}

		//删除路段
		function deleteRoad(roadNo, $tr) {
			var lineId = $tr.closest("table").closest("tr").prev().attr("id");
			$.messager.confirm("提示", "确认删除路段信息吗?", function (isConfirm) {
				if (isConfirm) {
					$.each(roadJson.line_detail, function (i, line) {
						if (line != undefined && null !== line &&
							undefined != line.roads && null != line.roads &&
							undefined != line.roads.road && null != line.roads.road && lineId == line.line_id) {

							$.each(line.roads.road, function (j, road) {
								if (road != null && road.road_no == roadNo) {
									line.roads.road.splice(j, 1);
									$("#gridForm").deleteChild(roadNo)
									roadNos.splice(roadNos.indexOf(line.line_id + "_" + road.road_no), 1);
									line.roads.count = parseInt(line.roads.count) - 1;
									saveBusLine();
								}
							});
						}
					});

				} else {

				}
			});
		}

		//获取编辑线路段页面的数据 组织成json,并返回,需传入要组织的线路段页面对象
		function transferRoadFromEdit(road, El) {

			$.each(roadOriginalJson, function (key, value) {
				if (key != "road_extra_info" || key != "road_type") {
					road[key] = $(El + " input[name='" + key + "']").val();
				}
			});

			road["road_type"] = $(El + " select[name='road_type']").val();

			var extraInfoDetail = $(El + " input[name='extra_info_detail']").val();
			if (extraInfoDetail != null && extraInfoDetail != undefined) {
				if (road.road_extra_info == null) {
					road.road_extra_info = {};
					road.road_extra_info.extra_info_count = 1;
					road.road_extra_info.extra_info = {};
					road.road_extra_info.extra_info.extra_info_seq = 1;
					road.road_extra_info.extra_info.extra_info_detail = extraInfoDetail;
				} else if (road.road_extra_info.extra_info == null) {
					road.road_extra_info.extra_info.extra_info_seq = 1;
					road.road_extra_info.extra_info.extra_info_detail = extraInfoDetail;
				} else {
					road.road_extra_info.extra_info.extra_info_detail = extraInfoDetail;
				}
			}
			return road;
		}


		//验证线路信息
		function validateLine() {
			var lineNoVal = $("#editLine input[name='line_no']").val();
			if (lineNoVal == null || lineNoVal == "" || $.trim(lineNoVal) == "") {
				$.messager.alert("验证", "线路编号不能为空", "info");
				return false;
			}

			var lindNameVal = $("#editLine input[name='line_name']").val();
			if (lindNameVal == null || lindNameVal == "" || $.trim(lindNameVal) == "") {
				$.messager.alert("验证", "线路名称不能为空", "info");
				return false;
			}

			return true;
		}

		function validateRoad(lineNo) {
			var roadNo = $("#editRoad input[name='road_no']").val();
			if (roadNo == null || roadNo == "" || $.trim(roadNo) == "") {
				$.messager.alert("验证", "路段编号不能为空", "info");
				return false;
			}
			var roadName = $("#editRoad input[name='road_name']").val();
			if (roadName == null || roadName == "" || $.trim(roadName) == "") {
				$.messager.alert("验证", "路段名称不能为空", "info");
				return false;
			}
			var roadType = $("#editRoad select[name='road_type']").val();
			if (roadType == null || roadType == "" || $.trim(roadType) == "") {
				$.messager.alert("验证", "路段类型不能为空", "info");
				return false;
			}
			var startLongitude = $("#editRoad input[name='start_longitude']").val();
			if (startLongitude == null || startLongitude == "" || $.trim(startLongitude) == "") {
				$.messager.alert("验证", "开始经度不能为空", "info");
				return false;
			}
			var startLatitude = $("#editRoad input[name='start_latitude']").val();
			if (startLatitude == null || startLatitude == "" || $.trim(startLatitude) == "") {
				$.messager.alert("验证", "开始纬度不能为空", "info");
				return false;
			}
			var endLatitude = $("#editRoad input[name='end_latitude']").val();
			if (endLatitude == null || endLatitude == "" || $.trim(endLatitude) == "") {
				$.messager.alert("验证", "结束经度不能为空", "info");
				return false;
			}
			var endLatitude = $("#editRoad input[name='end_latitude']").val();
			if (endLatitude == null || endLatitude == "" || $.trim(endLatitude) == "") {
				$.messager.alert("验证", "结束纬度不能为空", "info");
				return false;
			}
			if (null != lineNo && undefined != lineNo && roadNos.indexOf(lineNo + "_" + roadNo) >= 0
				&& !$("#editRoad input[name='road_no']").attr("readonly")) {
				$.messager.alert("验证", "同一线路的线路段编号不能重复", "info");
				return false;
			}
			return true;
		}

		//将xml转换为json
		function parseXmlToJson(nodes) {
			var json = {};
			$.each(nodes, function (i, node) {
				var nodeName = node.nodeName;
				if (nodeName != "#text") {
					if (node.childNodes.length == 1) {

						if (nodeName == "line_no") {
							lineNos.push(++lineId);
							json["line_id"] = lineId;
							//if(maxId > lineId)
							maxId = maxId > lineId ? maxId : lineId;
						}

						json[nodeName] = node.textContent || node.text;

						if (nodeName == "road_no") {
							roadNos.push(lineNos.concat().pop() + "_" + (node.textContent || node.text));
						}

					} else if (node.childNodes.length > 0) {
						if (arrNodes.indexOf(nodeName) >= 0) {
							if (typeof json[nodeName] == "undefined") {
								json[nodeName] = [];
							}
							json[nodeName].push(parseXmlToJson(node.childNodes));
						} else {
							json[nodeName] = parseXmlToJson(node.childNodes);
						}
					}
				}
			});
			return json;
		}

		function totalXml() {
			var xml = "<?xml version='1.0' encoding='GBK'?>";
			xml += "<line_info>" + parseJsonToXml(roadJson) + "</line_info>";
			return xml;
		}

		function saveBusLine(isDeleteLine) {
			var xml = totalXml();
			var url = "../../do/trafficController/saveBusLine";

			$.ajax({
				url: url,
				data: { param: xml, "-xsrf-": $("input[name='-xsrf-']").val() },
				type: 'post',
				contentType: "application/x-www-form-urlencoded;charset=UTF-8",
				dataType: "json",
				success: function (msg) {
					if (msg.error) {
						if (isDeleteLine) {
							$("#gridForm").find("tbody").html("");
							queryRoadJson("deleteLine");
						} else {
							queryRoadJson();
						}
						$.messager.show({
							title: '结果',
							msg: "保存成功!3秒后关闭此提示",
							timeout: 3000,
							showType: 'slide'
						});
					}
				},
				error: function (XMLHttpRequest, textStatus, error) {

					queryRoadJson();
					$.messager.alert("错误", "调用出错,出错原因:" + error + " 错误状态:" + textStatus);
				}
			})
		}

		function parseJsonToXml(json, parentNode) {
			var xml = "";
			if (json instanceof Array) {
				$.each(json, function (i, item) {
					xml += parseJsonToXml(item);
					if (json.length - 1 > i) {
						xml += "</" + parentNode + ">" + "<" + parentNode + ">";
					}
				});
			} else {
				$.each(json, function (key, value) {
					if (key == "line_id") {
						return true;
					}
					xml += "<" + key + ">";
					if (typeof (value) == "string" || typeof (value) == "number") {
						xml += value;
					} else {
						xml += parseJsonToXml(value, key);
					}
					xml += "</" + key + ">";
				});
			}
			return xml;
		}

		if (!Array.prototype.indexOf) {
			Array.prototype.indexOf = function (elt /*, from*/) {
				var len = this.length >>> 0;

				var from = Number(arguments[1]) || 0;
				from = (from < 0)
					? Math.ceil(from)
					: Math.floor(from);
				if (from < 0)
					from += len;

				for (; from < len; from++) {
					if (from in this &&
						this[from] === elt)
						return from;
				}
				return -1;
			};
		}


		//添加空的时间段选择控件
		function addTimePicker(event) {
			event.stopPropagation();
			var timeSpanContainer = $(event.currentTarget).parent().find(".timeSpanContainer");
			var timePickerLength = timeSpanContainer.find("li").length;

			var newTimePickerArray = new Array();
			var tagId1 = "s" + (timePickerLength - 1);
			var tagId2 = "e" + (timePickerLength - 1);
			newTimePickerArray.push("<li><input type='text' id='" + tagId1 + "' class='Wdate timePicker'  onclick=\"WdatePicker({dateFmt:'HH:mm:ss', maxDate: '#F{$dp.$D(\\'" + tagId2 + "\\')||\\'23:59:59\\'}'})\" />&nbsp;-&nbsp;");
			newTimePickerArray.push("<input type='text' id='" + tagId2 + "' class='Wdate timePicker' onclick=\"WdatePicker({dateFmt:'HH:mm:ss', minDate: '#F{$dp.$D(\\'" + tagId1 + "\\')||\\'00:00:00\\'}'})\" />");
			newTimePickerArray.push("<a href='#' class='btnDelete' /></a></li>");
			timeSpanContainer.append(newTimePickerArray.join(""));
			//添加删除的事件绑定
			$(".btnDelete").bind("click", deleteTimePicker);

			if (timePickerLength + 1 >= 10) {
				timeSpanContainer.parent().find(".timeSelectorAdd").hide();
			}
		}

		//显示时间段选择窗口
		function showTimeSelector(event) {
			event.stopPropagation();

			if (showedDatepicker) {
				saveTimeSpan(null);
			}

			if ($(".timeSpans").val() == null || $(".timeSpans").val() == "") {
				$(".timeSpans").val("00:00-23:59");
			}

			//保存当前时间控件
			showedDatepicker = $(event.currentTarget).next().find(".timeSpanContainer");

			var timeValue = event.currentTarget.value;//获取已选择的时间段
			var timeSpanArray = timeValue.split(";");
			var htmlTagsArray = new Array();
			var tagId1, tagId2;
			var timePair, timeStart, timeEnd;
			for (var i = 0; i < timeSpanArray.length; i++) {
				tagId1 = "s" + i;
				tagId2 = "e" + i;
				timePair = timeSpanArray[i].split('-');
				//如果时间段不合法(开始,结束时间缺少),直接跳过该值
				if (timePair.length != 2) {
					continue;
				}
				htmlTagsArray.push("<li><input type='text' id='" + tagId1 + "' class='Wdate timePicker' value='" + timePair[0] + "' onclick=\"WdatePicker({dateFmt:'HH:mm'})\" />&nbsp;-&nbsp;");
				htmlTagsArray.push("<input type='text' id='" + tagId2 + "' class='Wdate timePicker' value='" + timePair[1] + "' onclick=\"WdatePicker({dateFmt:'HH:mm'})\" />");
				htmlTagsArray.push("<a href='#' class='btnDelete' /></a></li>");
			}
			//显示控件(先清空,再添加新的时间选择控件)
			var timeSelector = $(event.currentTarget).parent().find(".timeSelector");
			//先解绑删除按钮事件
			$(".btnDelete").unbind("click");
			timeSelector.find(".timeSpanContainer").html("").html(htmlTagsArray.join(""));
			//显示时间段选择组件的位置
			timeSelector.css("top", 58).css("left", 170).show();
			timeSelector.show();
			//绑定删除时间段的方法
			$(".btnDelete").bind("click", deleteTimePicker);
			//判断是否显示添加时间段按钮
			if (htmlTagsArray.length >= 10) {
				timeSelector.find(".timeSelectorAdd").hide();
			} else {
				timeSelector.find(".timeSelectorAdd").show();
			}
		}

		//删除之前的时间控件
		function deleteTimePicker(event) {
			event.stopPropagation();
			var liContainer = $(event.currentTarget).parent();
			var timespansContainer = liContainer.parents(".timeSelector");
			//先解绑删除按钮的事件
			$(event.currentTarget).unbind();
			liContainer.remove();
			//检测时间段控件的个数
			var timeSpansCount = timespansContainer.find("li").length;
			if (timeSpansCount < 10) {
				timespansContainer.parent().find(".timeSelectorAdd").show();
			}
		}

		//保存已修改的时间段的值
		function saveTimeSpans(event) {
			var timeSpanContainer = $(event.currentTarget).parent().find(".timeSpanContainer");
			saveTimeSpan(timeSpanContainer);
		}

		function saveTimeSpan(container) {
			if (!container) {
				container = showedDatepicker;
			}
			if (!container) {
				return;
			}
			var timePickerPairsContainer = container.find("li");
			var timeSpanValueArray = new Array();
			var timePickers;
			for (var i = 0; i < timePickerPairsContainer.length; i++) {
				var timePickerPairs = $(timePickerPairsContainer[i]).find(".Wdate");
				if (timePickerPairs.length == 2 && timePickerPairs[0].value && timePickerPairs[1].value) {
					timeSpanValueArray.push(timePickerPairs[0].value + "-" + timePickerPairs[1].value);
				}
			}
			//保存到原始
			var valueContainer = container.parent().siblings("input");
			valueContainer.val(timeSpanValueArray.join(";"));
			//关闭
			container.parent().hide();
			showedDatepicker = null;
		}

		//不让时间对话框获取焦点
		function onTimeSelectorFocus(event) {
			this.blur();
		}

	</script>
</body>

</html>