gantt.js 37.6 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
(function() {
    var indexLoad = layer.load(0, {content:'拼命计算中...',time: 10*1000,success: function(layero){
            layero.find('.layui-layer-content').css('padding-top', '40px');
        }});
	// 全屏模式点击事件.
	// $(document).on('click','.fullscreen',function() {
	// 	if($('.ganttSvgContainer').height()>400)
	// 		$('.ganttSvgContainer').css('height','400px');
	// 	else
	// 		$('.ganttSvgContainer').css('height','99%');
	// });
	$(document).on('click','.fullscreen',function() {
		if($('.gtt').height()>720)
			$('.gtt').css('height','720px');
		else
			$('.gtt').css('height','99%');
        echartsDrawGTT.resizeChart();
	});
	// 获取已存在的该时刻表明细数据.
	var objD = window.localStorage.isDoDate;
	// 获取表单参数配置数据.
	var map  = JSON.parse(window.localStorage.Gantt_AgursData);
	$('.skmxTitle').text( '【' + map.skbmc + '】' + '时刻表明细模型');
	// 延迟500毫秒执行.
	setTimeout(function(){
		var offsetY = -parseInt($('.offset').offset().top)+16;
		var offsetX = -parseInt($('.offset').offset().left)+50;
		$('.tipso-animation').tipso({
		      speed           : 100,
		      background      : '#E91E63',
		      color           : '#E91E63',
		      position		  :'right',
		      width           : 410,
		      delay           : 400,
		      animationIn	  : 'bounceIn',
		      animationOut	  : 'bounceOut',
		      offsetX         : offsetX,
		      offsetY         : offsetY,
		      content	      :'<div class="tipsdscontinue"> <span>图例:</span> <div class="dscrp sx"></div><span>:上行</span>  <div class="dscrp xx"></div> <span>:下行</span></br><div/></br>' +
		      				   '<div class="tipsdscontinue"> <span>该模块支持鼠标拖拽功能.</span> <div/>'

		});
		$('.tipso-animation').tipso('show');
		setTimeout(function(){$('.tipso-animation').tipso('hide');},4000);
		// 1、定义开始与结束时间点字符串.
		var seMap = getStartAndEndDate(map);
		// 2、获取开始与结束时间对象.
		/*var seDate = getksjssj(null,seMap.s.split('-')[0]);*/
		var seDate = getksjssj(null,seMap.s);
		// 3、定义周转时间.
		map.zzsj = getzzsj(map);
		// 5、方向代码.
		var dirA = getsxxDM();
		// 6、班次类型.
		var bcTypeArr = getbcType();
		// 7、参数配置信息.
		var dataMap  = argsMap(map,dirA,bcTypeArr,seMap);
        parameters.setDataMap(dataMap);
		// 8、定义最大车辆数与停站时间.
		var CSMap = null,data = null;

        // 创建ParameterObj
        var _paramObj;
		if(map.baseRes== '0') {
			CSMap = getMaxCarAndStopSpace0(map,seMap);
            // 发车间隙
            map.fcjx = CSMap.fcjx;
            map.stt = "1";
            _paramObj = Main_v2.getFactory().createParameterObj(map, dataMap);
		}else if(map.baseRes== '1') {
			CSMap = getMaxCarAndStopSpace1(map);
			// 发车间隙
			map.fcjx = CSMap.fcjx;
			map.stt = "1";
			_paramObj = Main_v2.getFactory().createParameterObj(map, dataMap);
		}else if (map.baseRes == '2') {
			// TODO:之后可能有新的参数加入
			_paramObj = Main_v2.getFactory().createParameterObj(map, dataMap);
			map.clzs = _paramObj.calcuClzx();
			CSMap = getMaxCarAndStopSpace1(map);
		} else if (map.baseRes == '3') { // 主站停站使用v2_2版本
			_paramObj = Main_v2.getFactory().createParameterObj(map, dataMap); // TODO:暂时使用v2_1版本的方法,通用的,后续再放到v2_2版本中
			console.log(_paramObj);
			map.clzs = InternalScheduleObj_v2_2.calcuClzx(_paramObj);
			CSMap = getMaxCarAndStopSpace1(map);
		} else if (map.baseRes == '4') {
		    // 创建参数对象
            _paramObj = Main_v2.getFactory().createParameterObj(map, dataMap); // TODO:暂时使用v2_1版本的方法,通用的,后续再放到v2_2版本中

        }

		// 定义时间参数.
		var stopArray = getsj(map);
		if(isNull(objD)) {
			if(map.baseRes== '0') {
				// 采用客流数据获取渲染时刻表明细图形的配置参数数据.
				data = BaseFun.KLplaceClassesTime(CSMap.gattA,stopArray,CSMap.maxCar,map,seMap,dataMap);
			}else if(map.baseRes== '1') {
				// 采用班型人次数据获取渲染时刻表明细图形的配置参数数据.
				// data = BaseFun.BXPplaceClassesTime(stopArray,CSMap.maxCar,map,seMap,dataMap,getylp(CSMap.maxCar).lpNoA);
				// data = BaseFun.BXPplaceClassesTime01(stopArray,CSMap.maxCar,map,seMap,dataMap,getylp(CSMap.maxCar).lpNoA);
				// data = BaseFun.BXPplaceClassesTime02(stopArray,CSMap.maxCar,map,seMap,dataMap);
				data = scheduleInitialize.scheduleInit(stopArray,CSMap.maxCar,map,seMap,dataMap);
				$(".paramAdd").addClass("hidden");
			} else if (map.baseRes == '2') {
				// TODO:绘制gantt图表
				// TODO:var seDate = getksjssj(null,seMap.s); 关联参数必须设置
				// TODO:CSMap.maxCar 之后要设定一下的
				data = Main_v2.BXPplaceClassesTime03(_paramObj, CSMap.maxCar);
				Main_v2.exportDataConfig(data.aInternalLpObj);
			} else if (map.baseRes == '3') { // 主站停站使用v2_2版本
				data = Main_v2_2.BXPplaceClassesTime03(_paramObj, CSMap.maxCar);
			} else if (map.baseRes == '4') { // v4版本
			    var scheduleBuilder_v4_com = $('#scheduleBuildInfo_V4').scheduleBuilder_v4(_paramObj);
                data = scheduleBuilder_v4_com.getGanttData();

            }

		}else {
			var jsonA = JSON.parse(objD);
			// 使用已有的时刻表明细数据渲染视图.
			var rsjar = jsonA.rsD;
			var rsLP = jsonA.rsLP;

			//查询出当日所有班次,并加入data,json里面一块输送给
			$.get('/logZndd/sch_qbc', {xl : rsjar[0].xl},function (data) {
				for (let t in data){
					var sch = data[t];
					if (sch.status == -1)
						continue;
					for (let rs  in rsjar){
						var rsj = rsjar[rs];
						//相同路牌加入到rsjar里,并特殊标注一个,提高一点y坐标
						if(sch.lpName == rsj.lpName && sch.fcsj == rsj.fcsj && sch.bcType == rsj.bcType){
							schonmap(sch,rsj);
						}
					}
				}

				data = {'json':rsjar,'bxrcgs':null};
				echartsDrawGTT.init(data.json,true,true);


			});

			return;
		}
		echartsDrawGTT.init(data.json,true,true);
		// console.log(data.json);
		// 创建甘特图对象.
		// var graph = d3.select('#ganttSvg').relationshipGraph(
		// 	getGraphArgus({'ganttInitParams': map,'yAxisCarArray':CSMap.maxCar,
		// 		'startDateTime':seDate.kssj,'endDateTime':seDate.jssj,'stopArray':stopArray,'dataMap':dataMap,'bxrcgs':data.bxrcgs}));
		// // 渲染数据.
		// graph.data(data.json);
		// // 记录操作记录.
		// graph.addHistory();
		// // 初始化右键菜单.
		// contextInit(graph);


        if (map.baseRes == '4' || map.baseRes == '3' || map.baseRes == '1' || map.baseRes == '0') {
            // 导入导出设置
            // Main_v2_2.exportExcelConfig($_GlobalGraph.getDataArray);

            var _dfun = function() {
                // fix,从新的甘特图中获取数据
                var _keyIndex = echartsDrawGTT.get_keyIndex();
                var historyData = echartsDrawGTT.getHistoryData();
                var _data = $.extend(true, [], data, historyData[_keyIndex]);

                var _i;
                var _j;
                var _gObj;

                var _rtnBcArray = [];
                for (_i = 0; _i < _data.length; _i++) {
                    _gObj = _data[_i].value;
                    _rtnBcArray.push({
                        lpName : _gObj[0],
                        fcsj: moment(_gObj[1]).format("HH:mm"),
                        ARRIVALTIME: moment(_gObj[2]).format("HH:mm"),
                        bcsj: _gObj[3] / 60000,
                        lpNo: _gObj[4],
                        lpType: _gObj[5],
                        bcType: _gObj[6],
                        fcno: _gObj[7],
                        xlDir: (_gObj[8] == 0 ? "relationshipGraph-up" : "relationshipGraph-down"),
                        jhlc: _gObj[9],
                        tcc: _gObj[10],
                        ttinfo: _gObj[11],
                        xl: _gObj[12],
                        qdz: _gObj[13],
                        zdz: _gObj[14],
                        STOPTIME: _gObj[15],
                        isfb: _gObj[16]
                    });
                }

				console.log("重组前数据=" + _data);
				console.log("重组后数据=" + _rtnBcArray);
				return _rtnBcArray;
			};
			if (_paramObj == null)
				return;
			Main_v2_2.exportExcelConfig(_paramObj, _dfun);
		}

        // 关闭弹出层
        layer.close(indexLoad);
	},500);


	function schonmap(sch,rsj){
		rsj.ARRIVALTIME_1 =  sch.zdsjActual;
		rsj.bcType_1 =  sch.bcType;
		rsj.bcs_1 = sch.bcs;
		rsj.bcsj_1= sch.bcsj;
		rsj.fcno_1= sch.fcno;
		rsj.fcsj_1= sch.fcsjActual;
		rsj.isSwitchXl_1=  0;
		rsj.isfb_1 =0;
		rsj.jhlc_1 = sch.jhlc;
		rsj.lpName_1 = sch.lpName;
		rsj.parent_1= 1;
		rsj.qdz_1= sch.qdzCode;
		rsj.xl_1 = sch.xlBm;
		rsj.xlDir_1= sch.xlDir == 0 ? "relationshipGraph-up" : "relationshipGraph-down";
		rsj.zdz_1= sch.zdzCode;
		rsj.isjh_1 = true;
	}

	/**
	 * @description : (TODO) 根据客流数据分析各个时间段内的配车数、获取发车间隙与车辆数的最大值.
	 *
	 * @param [map--表单参数;seMap--开始与结束时间字符串点].
	 *
	 * @returns 返回一个分装时间段内的车辆数、发车间隙、车辆数的最大值集合.
	 * */
	function getMaxCarAndStopSpace0(map,seMap) {
		var sortGattA = BaseFun.sortGattDate([{'type':'sm','num':parseInt(map.zgfbeforepcs),'time':seMap.s + '-' + seMap.e},
		               		                  {'type':'et','num':parseInt(map.wgfafterpcs),'time':map.earlyStartTime + '-' + seMap.e},
		            		                  {'type':'me','num':parseInt(map.gfzjpcs),'time':map.earlyEndTime + '-' + map.lateStartTime},
		            		                  {'type':'mm','num':parseInt(map.zgfpcs),'time':map.earlyStartTime + '-' + map.earlyEndTime},
		            		                  {'type':'ee','num':parseInt(map.wgfpcs),'time':map.lateStartTime + '-' + map.lateEndTime}]);
		return {'gattA':sortGattA,'stopSpace':  Math.round(map.zzsj/sortGattA[sortGattA.length-1].num) ,'maxCar':getyArray(sortGattA)};
	}

	/**
	 * @description : (TODO) 根据班型与人次得到发车间隙、车辆数的最大值.
	 *
	 * @param [map--表单参数].
	 *
	 * @returns 返回一个分装发车间隙、车辆数的最大值集合.
	 * */
	function getMaxCarAndStopSpace1(map) {
		return {'gattA':null,
				'fcjx': {'gffcjx': Math.round(map.zzsj.gfzzsj/map.clzs) ,
						 'dgfcjx': Math.round(map.zzsj.dgzzsj/map.clzs),
						 'dgmaxfcjx' : parseInt(map.dgmaxfcjx)},
				'maxCar':BaseFun.getYAxisCarArray(parseInt(map.clzs))};
	}

	/**
	 * @description : (TODO) 封装方向成对的数据集合.
	 *
	 * @param [gatps--表单数据;dira--方向集合;bcTypeArr--班次类型集合]
	 *
	 * @returns  返回一个封装方向成对的数据集合.
	 * */
	function argsMap(gatps,dira,bcTypeArr,seMap) {
		return {'jcsjArr' : BaseFun.formatPairing(gatps.upInTimer,gatps.downInTimer),// 进场里程。[下标0代表上;下标1代表下]
				'ccsjArr' : BaseFun.formatPairing(gatps.upOutTimer,gatps.downOutTimer),// 出场时间。[下标0代表上;下标1代表下]
				'jclcArr' : BaseFun.formatPairing(gatps.upInMileage,gatps.downInMileage),// 进场里程。[下标0代表上;下标1代表下]
				'cclcArr' : BaseFun.formatPairing(gatps.upOutMileage,gatps.downOutMileage),// 出场里程。[下标0代表上;下标1代表下]
				'pcxssjArr' : BaseFun.formatPairing(gatps.upTravelTime,gatps.downTravelTime),// 平常行驶时间。[下标0代表上;下标1代表下]
				'gfxxsjArr' : BaseFun.formatPairing(gatps.lateUpTime=='' ? gatps.upTravelTime : gatps.lateUpTime,
													gatps.lateDownTime=='' ? gatps.downTravelTime : gatps.lateDownTime),// 高峰行驶时间。[下标0代表上;下标1代表下]
				'dgxxsjArr' : BaseFun.formatPairing(gatps.troughUpTime=='' ? gatps.upTravelTime : gatps.troughUpTime,
										gatps.troughDownTime=='' ? gatps.downTravelTime : gatps.troughDownTime),// 低谷行驶时间。[下标0代表上;下标1代表下]
				'pcxslcArr' : BaseFun.formatPairing(gatps.upMileage,gatps.downMileage),// 行驶里程。[下标0代表上;下标1代表下]
				'qdzArr' : BaseFun.qzdz(gatps.up_s.split('_')[0],gatps.down_s.split('_')[0]),// 起始站。[下标0代表上;下标1代表下]
				'zdzArr':BaseFun.qzdz(gatps.up_s.split('_')[1],gatps.down_s.split('_')[1]),// 终点站。[下标0代表上;下标1代表下]
				'zwcArr' : BaseFun.formatPairing(gatps.workeLunch,gatps.workeDinner),// 午晚餐时间。[下标0代表午;下标1代表晚]
				'smbcsjArr' : BaseFun.formatksjssj(gatps), // 起终点站首末班车时间.[下标0代表起始站的首末班车时间;下标1代表终点站的首末班车时间]
				'zgfsjd' : BaseFun.getsd(BaseFun.getDateTime(gatps.earlyStartTime),
							   BaseFun.getDateTime(gatps.earlyEndTime)), // 早高峰时间段
				'wgfsjd' : BaseFun.getsd(BaseFun.getDateTime(gatps.lateStartTime),
							   BaseFun.getDateTime(gatps.lateEndTime)),// 晚高峰时间段
			    'gfzjsjd' : BaseFun.getsd(BaseFun.getDateTime(gatps.earlyEndTime),
						   BaseFun.getDateTime(gatps.lateStartTime)),//高峰之间时间段.
				'wgfzhsjd' :  BaseFun.getsd(BaseFun.getDateTime(gatps.lateEndTime),
						   BaseFun.getDateTime(seMap.e)),// 晚高峰之后时间段
				'zgfzqsjd': BaseFun.getsd(BaseFun.getDateTime(seMap.s),
						   BaseFun.getDateTime(gatps.earlyStartTime)),//早高峰之前时间段.
				'dira' : dira,// 方向集合 [下标0代表上;下标1代表下]
				'bcTypeArr' : bcTypeArr,// 班次类型
				'lbsj' : gatps.lb=='' ? 0:parseInt(gatps.lb),// 例保时间.
				// 'minztjx' : parseInt(gatps.mixstopTime),		// 最小停站时间.
				// 'ztjxA' :  BaseFun.formatPairing(gatps.upStopTime,gatps.downStopTime),		// 停站时间.
				// 'maxztjx' : parseInt(gatps.maxstopTime),		// 最大停站时间.
				'gftzsj': BaseFun.formatPairing(gatps.gfupStopTime,gatps.gfdownStopTime),// 高峰停站时间.
				'dgtzsj' : BaseFun.formatPairing(gatps.dgupStopTime,gatps.dgdownStopTime),// 低谷停站时间.
				'dgmaxtzsj' :  parseInt(gatps.dgmaxtzsj),// 低谷最大停站时间.
				// 'dgmaxfcjx' :  parseInt(gatps.dgmaxfcjx),// 低谷最大发车间隙.
				'dgmaxfcjx' :  20,// 低谷最大发车间隙.
				'map' : gatps,
				'zzsj':gatps.zzsj// 周转时间.
			};
	}

	/**
	 * @description : (TODO) 获取周转时间.
	 *
	 * @params [map--表单配置参数].
	 *
	 * @return 返回一个周转时间.
	 * */
	function getzzsj(map) {
		// 一圈所用时间 (上行+下行+停歇时间)
		return {
			'gfzzsj':  parseInt(map.earlyUpTime =='' ? map.upTravelTime : map.earlyUpTime) +
					   parseInt(map.gfupStopTime) + parseInt(map.gfdownStopTime) +
					   parseInt(map.earlyDownTime =='' ? map.downTravelTime : map.earlyDownTime ), // 高峰周转时间
			'dgzzsj':  parseInt(map.troughUpTime==''? map.upTravelTime : map.troughUpTime) +
					   parseInt(map.dgupStopTime) + parseInt(map.dgdownStopTime) +
					   parseInt(map.troughDownTime==''? map.downTravelTime: map.troughDownTime),// 低谷周转时间
			'dgmaxzzsj' : parseInt(map.troughUpTime==''? map.upTravelTime : map.troughUpTime) +
			   			  parseInt(map.dgmaxtzsj) + parseInt(map.dgmaxtzsj) +
			   			  parseInt(map.troughDownTime==''? map.downTravelTime: map.troughDownTime),// 低谷最大的周转时间
		};
	}

	/**
	 * @description : (TODO) 获取开始与结束时间字符串.
	 *
	 * @param [map--表单配置参数]
	 *
	 * @return 返回开始与结束时间字符串集合.
	 * */
	function getStartAndEndDate(map) {
		return {'s': map.linePlayType == '1' ? map.startStationFirstTime : getMinDate(map.startStationFirstTime,map.endStationFirstTime),
				'e': map.linePlayType == '1' ? map.startStationEndTime : getMaxDate(map.startStationEndTime,map.endStationEndTime)}
	}

	/**
	 * @description : (TODO) 获取最小时间.
	 *
	 * @param [d1--时间1;d2--时间2]
	 *
	 * @return 返回一个最小时间.
	 * */
	function getMinDate(d1,d2) {
		var str = '';
		if(strToTime(d1)>strToTime(d2))
			str = d2;
		else
			str = d1;
		return str;
	}

	/**
	 * @description : (TODO) 字符串时间点转时间对象.
	 *
	 * @param [t--字符串时间]
	 *
	 * @return 返回一个时间对象.
	 * */
	function strToTime(t) {
		var d = new Date();
		if(t) {
			var _str = t.split(':');
			d.setHours(parseInt(_str[0]));
			d.setMinutes(parseInt(_str[1]));
		}
		return d;
	}

	/**
	 * @description : (TODO) 获取最大时间.
	 *
	 * @param [d1--时间1;d2--时间2]
	 *
	 * @return 返回一个最大时间.
	 * */
	function getMaxDate(d1,d2) {
		var str = '';
		if(strToTime(d1)>strToTime(d2))
			str = d1;
		else
			str = d2;
		return str;
	}

	/**
	 * @description : (TODO) 获取开始与结束时间对象.
	 *
	 * @param [d--日期;str--时间点字符串]
	 *
	 * @return 返回一个开始与结束时间的集合对象.
	 * */
	function getksjssj(d,str) {
		var newDate = new Date();
		if(d !=null && d !='' && typeof(d) != 'undefined' ) {
			newDate = new Date(d.replace(/-/g,"/"));
		}
		var kssj = d3.time.hour.offset(BaseFun.getEndDate(
				newDate.getFullYear()+ "-" +
				(newDate.getMonth()+1) + "-" +
				newDate.getDate() + ' ' +
				str.split(':')[0] + ':00'),-1);

		var year = '' , month = '',dt = '';
		if(newDate.getDate()+1>31)
			dt = '01';
		else
			dt = newDate.getDate()+1;
		if(newDate.getMonth()+1>12)
			month = '01';
		else if(newDate.getDate()+1>31)
			month = newDate.getMonth()+2;
		else
			month = newDate.getMonth()+1;
		if(newDate.getMonth()+1>12)
			year = newDate.getFullYear()+1;
		else
			year = newDate.getFullYear();
		var jssj = BaseFun.getEndDate(year + '-' + month + '-' + dt + ' ' + '00:00');
		return {'kssj' : kssj, 'jssj' :  jssj};
	}

	/**
	 * @description : (TODO) 获取时间参数配置信息
	 *
	 * @param [map--表单配置参数]
	 *
	 * @returns 返回一个时间参数配置数据.
	 * */
	function getsj(map) {
		var sxsj = parseInt(map.upTravelTime);// 上行时间.
		var xxsj = parseInt(map.downTravelTime);// 下行时间.
		return [{'gfsxtzjx':parseInt(map.gfupStopTime), // 高峰上行停站间隙.
				 'gfxxtzjx':parseInt(map.gfdownStopTime), // 高峰下行停站间隙.
				 'dgsxtzjx':parseInt(map.dgupStopTime), // 低谷上行停站间隙.
				 'dgxxtzjx':parseInt(map.dgdownStopTime),// 低谷下行停站间隙.
			  	 'fcjx':map.fcjx,// 发车间隙.
			  	 'sxsj':sxsj,// 上行时间.
			  	 'xxsj':xxsj,// 下行时间.
			  	 'zzsj':map.zzsj,// 周转时间.
			  	 'wcsj':parseInt(map.workeLunch),// 午餐时间.
			  	 'wcsj':parseInt(map.workeDinner),// 晚餐时间.
			  	 'zgfsxsj':map.earlyUpTime==''? sxsj :  parseInt(map.earlyUpTime),// 早高峰上行行驶时间.
			  	 'zgfxxsj':map.earlyDownTime=='' ? xxsj : parseInt(map.earlyDownTime),// 早高峰下行行驶时间.
			     'wgfsxsj':map.lateUpTime=='' ? sxsj : parseInt(map.lateUpTime),// 晚高峰上行行驶时间.
			     'wgfxxsj':map.lateDownTime== '' ?  xxsj: parseInt(map.lateDownTime),// 晚高峰下行行驶时间.
			     'sxjcsj':map.upInTimer == '' ? 0 : parseInt(map.upInTimer),// 上行进场时间.
			     'sxccsj':map.upOutTimer == '' ? 0 : parseInt(map.upOutTimer),// 上行出场时间.
			     'xxjcsj':map.downInTimer =='' ? 0 : parseInt(map.downInTimer),// 下行进场时间.
			     'xxccsj':map.downOutTimer =='' ? 0 : parseInt(map.downOutTimer),// 下行进场时间.
			     'sxjclc':map.upInMileage==''? 0 : parseInt(map.upInMileage),// 上行进场里程.
			     'sxcclc':map.upOutMileage==''? 0:parseInt(map.upOutMileage),// 上行出场里程.
			     'xxjclc':map.downInMileage==''? 0 : parseInt(map.downInMileage),// 下行进场里程.
			     'xxcclc':map.downOutMileage==''?0:parseInt(map.downOutMileage),// 下行出场里程.
			     'lbsj': map.lb==''? 0 : parseInt(map.lb) // 例保时间.
			    }];
	}

	/**
	 * @description : (TODO) 获取方向代码.
	 *
	 * @param [sx--上行;xx--下行].
	 *
	 * @returns 返回一个方向集合对象.
	 * */
	function getsxxDM(sx,xx) {
		return  [sx == null || sx == '' || typeof(sx)=='undefined'  ? 'relationshipGraph-up' : sx,
				 xx == null || xx == '' || typeof(sx)=='undefined'  ? 'relationshipGraph-down': xx];
	}

	/**
	 * @description : (TODO) 获取班次类型.
	 *
	 * @param [bd--早例保;out--出场;normal--正常;cf--吃饭;in_--进场;lc--晚例保;major--放站;venting--直放;region--区间].
	 *
	 * @returns 返回一个班次类型集合对象.
	 * */
	function getbcType(bd,out,normal,cf,in_,lc,major,venting,region) {
		return {'bd' : bd == null || bd == '' || typeof(bd)=='undefined'  ? 'bd' : bd,
				'out': out == null || out == '' || typeof(out)=='undefined'  ? 'out' : out,
				'normal': normal == null || normal == '' || typeof(normal)=='undefined'  ? 'normal' : normal,
				'cf': cf == null || cf == '' || typeof(cf)=='undefined'  ? 'cf' : cf,
				'in_': in_ == null || in_ == '' || typeof(in_)=='undefined'  ? 'in' : in_,
				'lc': lc == null || lc == '' || typeof(lc)=='undefined'  ? 'lc' : lc,
				'major': major == null || major == '' || typeof(major)=='undefined'  ? 'major' : major,
				'venting': venting == null || venting == '' || typeof(venting)=='undefined'  ? 'venting' : venting,
				'region': region == null || region == '' || typeof(region)=='undefined'  ? 'region' : region,};
	}

	/**
	 * @description : (TODO) 获取车辆最大数值.
	 *
	 * @param [arr-数组]
	 *
	 * @returns 返回车辆数最大值.
	 * */
	function getyArray(arr) {
		// 获取车辆最大数,作为Y轴的值
		return BaseFun.getYAxisCarArray(arr[arr.length-1].num);
	}

	/**
	 * @description : (TODO) 验证参数是否为空.
	 *
	 * @param [args--需要验证的参数]
	 *
	 * @return 返回一个布尔值.
	 * */
	function isNull(agrs) {
		var tag = false;
		if(agrs==null || agrs=='' || agrs=='null')
			tag = true;
		return tag;
	}

	/**
	 * @description : (TODO) 获取路牌编码.
	 *
	 * @param [arr--路牌对象集合]
	 *
	 * @return 返回一个路牌编码数组集合.
	 * */
	function getylp(arr) {
		var ra = new Array(),name = new Array();
		for(var i = 0 ; i<arr.length;i++) {
			ra.push(arr[i].lpNo);
			name.push(arr[i].lpName);
		}
		return {'lpNoA':ra,'lpNameA':name,};
	}
	/**
	 * @description : (TODO) 获取甘特图参数配置信息.
	 *
	 * @param [p--配置参数]
	 *
	 * @return 返回甘特图的参数配置信息.
	 * */
	function getGraphArgus(p) {
		var bs =  p.stopArray[0].sxsj > 40 ? 4 : 2;
		var MULTIPLE = Math.round(105/parseInt(p.stopArray[0].sxsj)) >3 ? Math.round(90/parseInt(p.stopArray[0].sxsj)) :  Math.round(90/parseInt(p.stopArray[0].sxsj)) *bs;
		var VALUEKEYNAME = 'Worldwide Gross' ,
		 	DXHOURS = 24,MINUTE = 60,WIDTH = DXHOURS*MINUTE,MARGINLEFT = 380,HEIGHT = p.yAxisCarArray.length*60 + 240,
		    MARGINBOTTOM = 240,OFFSETX = 90,OFFSETY = 180,OFFSETUPY = 120,OFFSETDOWNY = 60,
		    STARTDATETIME = p.startDateTime ,ENDDATETIME = p.endDateTime ,TASKTYPES =p.yAxisCarArray ,TICKFORMAT ='%H:%M' ,SHOWTOOLTIPS = true;
		var dx_time = p.endDateTime.getTime() - p.startDateTime.getTime() ;
		// 计算出相差天数
   	 	var days=Math.floor(dx_time/(24*3600*1000));
   	 	// 计算出小时数
        var leave1=dx_time%(24*3600*1000); //计算天数后剩余的毫秒数
        var hours=Math.floor(leave1/(3600*1000));
        DXHOURS = days*24+hours;
        WIDTH = DXHOURS*MINUTE*MULTIPLE;
        var lpsplitA = getylp(p.yAxisCarArray);
		var args = {
    	        'valueKeyName': VALUEKEYNAME,
    	        'hours' : DXHOURS,
    	        'dxHours' : 24 - DXHOURS,
    	        'multiple': MULTIPLE,
    	        'width':WIDTH,
    	        'widtMargin':MARGINLEFT,
    	        'height':HEIGHT,
    	        'heightMargin':MARGINBOTTOM,
    	        'offsetX':OFFSETX,
    	        'offsetY':OFFSETY,
    	        'downDy':OFFSETDOWNY,
    	        'upDy':OFFSETUPY,
    	        'timeDomainStart' :STARTDATETIME,
    	        'timeDomainEnd' : ENDDATETIME,
    	        'startStr':'' + STARTDATETIME,
    	        'endStr': '' +ENDDATETIME,
    	        'taskTypes': TASKTYPES,
    	        'lpNoA':lpsplitA.lpNoA,
    	        'lpNameA':lpsplitA.lpNameA,
    	        'tickFormat': TICKFORMAT,
    	        'stopArray' : p.stopArray,
    	        'dataMap':p.dataMap,
    	        'showTooltips': SHOWTOOLTIPS,
    	        'bxrcgs':p.bxrcgs
    	   };
		return args;
	}

	/**
	 * @descirption : (TODO) 初始化右击rect元素右键菜单栏.
	 *
	 * @status OK.
	 * */
	function contextInit(graph) {
		// 初始化context.
		context.init({preventDoubleContext: true});
		// 设置参数.
		context.settings({compress: false});
		// 设置菜单栏的内容.
		context.attach('rect', [
			{text: '修改',action: function(e){
				// 弹出层mobal页面
				$.get('/pages/base/timesmodel/edit-detail.html', function(m){
					$(pjaxContainer).append(m);
					// 获取当前班次以及相邻班次的信息.(包括元素与数据).
					var nodeContext =  RelationshipGraph.getContextNodeAndData(
											d3.select('rect.selected').attr('parent-node').replace('-cover',''));
					// 显示修改班次片段.
					$('#editDetail_mobal').trigger('editDetailMobal.show',[graph,nodeContext,BaseFun,map]);
				});
			}},
			{text: '删除',action: function(e){
				// 获取当前班次以及相邻班次的信息.(包括元素与数据).
				var nodeContext =  RelationshipGraph.getContextNodeAndData(
						d3.select('rect.selected').attr('parent-node').replace('-cover',''));
				// 判断当前班次类型.
				if(isType(nodeContext.dqbcData.bcType,graph,'删除',null,null))
					return;
				layer.confirm('您确定要删除【路牌'+ nodeContext.dqbcData.lpName +'-->发车序号'+ nodeContext.dqbcData.fcno +'】当前班次嘛!'+
							  '</br>【注意】:如需要撤销当前操作,您可以在系统工具下拉选择点击【撤销按钮】进行恢复.', {
					btn : [ '确认提示并提交', '取消' ]
				}, function() {
					// 关闭弹出层.
					layer.closeAll();
					// 删除rect底层元素
					d3.select('rect[id='+ nodeContext.qdbcNodeId +']').remove();
					// 删除text元素.
					d3.selectAll('text[parent-node='+ nodeContext.qdbcNodeId +']').remove();
					// 删除圆.
					d3.selectAll('circle[parent-node='+ nodeContext.qdbcNodeId +']').remove();
					// 删除当前选择右键菜单rect元素.
					d3.selectAll('rect.selected').remove();
					var data = new Array();
					// 判断删除的班次是否为出场后或者进场前的班次.如果是,则需要重新定义进出场和早晚例保.
					if(nodeContext.lastData.bcType==graph.configuration.dataMap.bcTypeArr.out ||
					   nodeContext.nextData.bcType==graph.configuration.dataMap.bcTypeArr.in_) {
						// 获取所有班次. 定义当前路牌下的所有班次、其他路牌下的班次.
						var dtAll = graph.getDataArray(),dqlpbc = new Array,qtlpbc = new Array();
						// 遍历分割班次.
						for(var t = 0 ; t< dtAll.length; t++) {
							// 判断遍历的当前班次路牌是否与选中修改的班次路牌是否一致.
							if(dtAll[t].lpNo == nodeContext.dqbcData.lpNo)
								dqlpbc.push(dtAll[t]);
							else
								qtlpbc.push(dtAll[t]);
						}
						// 首先除去进出场班次和早晚例保班次.定义进出出场和早晚例保班次数组、正常(包括正常、区间、直放、吃饭、放站)班次数组.
						var jcclbbcA = Array(),normalA = new Array();
						for(var d = 0 ; d < dqlpbc.length; d++) {
							if(dqlpbc[d].bcType==graph.configuration.dataMap.bcTypeArr.bd ||
							   dqlpbc[d].bcType==graph.configuration.dataMap.bcTypeArr.in_||
							   dqlpbc[d].bcType==graph.configuration.dataMap.bcTypeArr.lc ||
							   dqlpbc[d].bcType==graph.configuration.dataMap.bcTypeArr.out)
								jcclbbcA.push(dqlpbc[d]);
							else
								normalA.push(dqlpbc[d]);
						}
						// 把当前路牌下的班次按发车序号顺序排序.
						normalA.sort(function(a,b){return a.fcno-b.fcno});
						// 先添加进出场班次和早晚例保班次-->然后合并其他班次-->然后重置发车序号和班次数-->根据数据重新渲染视图.
						data = BaseFun.setbcsAndfcno(qtlpbc.concat(BaseFun.addjclbbc(normalA,graph.configuration.dataMap,graph.configuration.stopArray[0].lbsj,map)));
					}else {
						data = graph.getDataArray();
					}
					var rsjar = BaseFun.tzsztest(graph.configuration.taskTypes,data,graph.configuration.dataMap);
					/*var resultJA = BaseFun.addjcclcbc01(graph.configuration.taskTypes,rsjar,
							graph.configuration.dataMap,graph.configuration.stopArray,data,
							graph.configuration.dataMap.map);*/
					// 获取图形数据.重新绘制.
					graph.data(BaseFun.addjcclcbc01(graph.configuration.taskTypes,rsjar,
							graph.configuration.dataMap,
							graph.configuration.stopArray,
							graph.configuration.dataMap.map));
					// 记录当前操作.
					graph.addHistory();
					stateSuccess('删除');
				});
			}},
			{text: '设为上行',action: function(e){
				// 获取当前班次以及相邻班次的信息.(包括元素与数据).
				var nodeContext =  RelationshipGraph.getContextNodeAndData(
										d3.select('rect.selected').attr('parent-node').replace('-cover',''));
				// 判断是否重复设置.
				if(nodeContext.dqbcData.xlDir == graph.configuration.dataMap.dira[0]) {
					layer.msg('当前选择的班次已是【上行班次】,不能重复设置!');
					return;
				}
				trimDir(graph,nodeContext,graph.configuration.dataMap.dira[0],graph.configuration.dataMap.dira[1]);
				stateSuccess('设置成为上行');
			}},
			{text: '设为下行',action: function(e){
				// 获取当前班次以及相邻班次的信息.(包括元素与数据).
				var nodeContext =  RelationshipGraph.getContextNodeAndData(
										d3.select('rect.selected').attr('parent-node').replace('-cover',''));
				// 判断是否重复设置.
				if(nodeContext.dqbcData.xlDir == graph.configuration.dataMap.dira[1]) {
					layer.msg('当前选择的班次已是【下行班次】,不能重复设置!');
					return;
				}
				trimDir(graph,nodeContext,graph.configuration.dataMap.dira[1],graph.configuration.dataMap.dira[0]);
				stateSuccess('设置成为下行');
			}},
			{text: '设为正常',action: function(e){
				// 获取当前班次以及相邻班次的信息.(包括元素与数据).
				var nodeContext =  RelationshipGraph.getContextNodeAndData(
										d3.select('rect.selected').attr('parent-node').replace('-cover',''));
				// 获取当前班次的数据.
				var dqbcData = nodeContext.dqbcData;
				// 判断当前班次类型.
				if(isType(dqbcData.bcType,graph,'设为正常班次',graph.configuration.dataMap.bcTypeArr.normal,'已是正常班次'))
					return;
				dqbcData.bcType = graph.configuration.dataMap.bcTypeArr.normal;
				graph.data(graph.getDataArray());
				graph.addHistory();
				stateSuccess('设置成为正常班次');
			}},
			{text: '设为区间',action: function(e){
				// 获取当前班次以及相邻班次的信息.(包括元素与数据).
				var nodeContext =  RelationshipGraph.getContextNodeAndData(
										d3.select('rect.selected').attr('parent-node').replace('-cover',''));
				// 获取当前班次的数据.
				var dqbcData = nodeContext.dqbcData;
				// 判断当前班次类型.
				if(isType(dqbcData.bcType,graph,'设为区间班次',graph.configuration.dataMap.bcTypeArr.region,'已是区间班次'))
					return;
				dqbcData.bcType = graph.configuration.dataMap.bcTypeArr.region;
				graph.data(graph.getDataArray());
				graph.addHistory();
				stateSuccess('设置成为区间班次');
			}},
			{text: '设为分班', action: function(e){
				// 获取当前班次以及相邻班次的信息.(包括元素与数据).
				var nodeContext =  RelationshipGraph.getContextNodeAndData(
										d3.select('rect.selected').attr('parent-node').replace('-cover',''));
				// 获取当前班次的数据.
				var dqbcData = nodeContext.dqbcData;
				// 判断当前班次类型.
				if(isType(dqbcData.isfb,graph,'设为分班',1,'已是分班班次'))
					return;
				/*if(dqbcData.isfb == 1) {
					layer.msg('当前选择的班次【已是分班】班次.不能重复设置!');
					return;
				}*/
				dqbcData.isfb = 1;
				graph.data(graph.getDataArray());
				graph.addHistory();
				stateSuccess('设置成为分班');
			}},
			{text: '取消分班', action: function(e){
				// 获取当前班次以及相邻班次的信息.(包括元素与数据).
				var nodeContext =  RelationshipGraph.getContextNodeAndData(
										d3.select('rect.selected').attr('parent-node').replace('-cover',''));
				// 获取当前班次的数据.
				var dqbcData = nodeContext.dqbcData;
				// 判断当前班次类型.
				if(isType(dqbcData.isfb,graph,'设为分班',0,'不是分班班次'))
					return;
				/*if(dqbcData.isfb == 0) {
					layer.msg('当前选择的班次【不是分班】班次.不能重复设置!');
					return;
				}*/
				dqbcData.isfb = 0;
				graph.data(graph.getDataArray());
				graph.addHistory();
				stateSuccess('取消分班');
			}},
			{text: '设为直放', action: function(e){
				// 获取当前班次以及相邻班次的信息.(包括元素与数据).
				var nodeContext =  RelationshipGraph.getContextNodeAndData(
										d3.select('rect.selected').attr('parent-node').replace('-cover',''));
				// 获取当前班次的数据.
				var dqbcData = nodeContext.dqbcData;
				// 判断当前班次类型.
				if(isType(dqbcData.bcType,graph,'设为直放班次',graph.configuration.dataMap.bcTypeArr.venting,'已是直放班次'))
					return;
				dqbcData.bcType = graph.configuration.dataMap.bcTypeArr.venting;
				graph.data(graph.getDataArray());
				graph.addHistory();
				stateSuccess('设置成为直放班次');
			}},
			{text: '设为放站', action: function(e){
				// 获取当前班次以及相邻班次的信息.(包括元素与数据).
				var nodeContext =  RelationshipGraph.getContextNodeAndData(
										d3.select('rect.selected').attr('parent-node').replace('-cover',''));
				// 获取当前班次的数据.
				var dqbcData = nodeContext.dqbcData;
				// 判断当前班次类型.
				if(isType(dqbcData.bcType,graph,'设为放站班次',graph.configuration.dataMap.bcTypeArr.major,'已是放站班次'))
					return;
				dqbcData.bcType = graph.configuration.dataMap.bcTypeArr.major;
				graph.data(graph.getDataArray());
				graph.addHistory();
				stateSuccess('设置成为放站班次');
			}},
		]);
	}

	function trimDir(graph,nodeContext,dqDir,tzDir) {
		// 获取所有班次. 定义当前路牌下的所有班次、其他路牌下的班次.
		var dtAll = graph.getDataArray(),dqlpbc = new Array,qtlpbc = new Array();
		// 遍历分割班次.
		for(var t = 0 ; t< dtAll.length; t++) {
			// 判断遍历的当前班次路牌是否与选中修改的班次路牌是否一致.
			if(dtAll[t].lpNo == nodeContext.dqbcData.lpNo)
				dqlpbc.push(dtAll[t]);
			else
				qtlpbc.push(dtAll[t]);
		}
		// 首先除去进出场班次和早晚例保班次.定义进出出场和早晚例保班次数组、正常(包括正常、区间、直放、吃饭、放站)班次数组.
		var jcclbbcA = Array(),normalA = new Array();
		for(var d = 0 ; d < dqlpbc.length; d++) {
			if(dqlpbc[d].bcType==graph.configuration.dataMap.bcTypeArr.bd ||
			   dqlpbc[d].bcType==graph.configuration.dataMap.bcTypeArr.in_||
			   dqlpbc[d].bcType==graph.configuration.dataMap.bcTypeArr.lc ||
			   dqlpbc[d].bcType==graph.configuration.dataMap.bcTypeArr.out)
				jcclbbcA.push(dqlpbc[d]);
			else
				normalA.push(dqlpbc[d]);
		}
		// 修改当前路牌下的班次方向.
		for(var r = 0; r<normalA.length;r++) {
			// 修改方向.
			if(normalA[r].xlDir == dqDir) {
				normalA[r].xlDir = tzDir;
			}else if(normalA[r].xlDir == tzDir) {
				normalA[r].xlDir = dqDir;
			}
		}
		// 把当前路牌下的班次按发车序号顺序排序.
		normalA.sort(function(a,b){return a.fcno-b.fcno});
		// 先添加进出场班次和早晚例保班次-->然后合并其他班次-->然后重置发车序号和班次数-->根据数据重新渲染视图.
		graph.data(BaseFun.setbcsAndfcno(qtlpbc.concat(BaseFun.addjclbbc(normalA,graph.configuration.dataMap,graph.configuration.stopArray[0].lbsj,map))));
		// graph.data(BaseFun.addjclbbc(normalA,graph.configuration.dataMap,graph.configuration.stopArray[0].lbsj,map));
		// 记录当前操作.
		graph.addHistory();
	}

	function isType(bcType,graph,msg,inType,opr) {
		var tag = false ;
		layer.closeAll();
		if(bcType==graph.configuration.dataMap.bcTypeArr.bd) {
			layer.msg('当前选择的班次是【早例保时间】不能'+ msg +'!');
			tag = true;
		}else if(bcType==graph.configuration.dataMap.bcTypeArr.cf) {
			layer.msg('当前选择的班次是【吃饭时间】不能'+ msg +'!');
			tag = true;
		}else if(bcType==graph.configuration.dataMap.bcTypeArr.in_) {
			layer.msg('当前选择的班次是【进场班次】不能'+ msg +'!');
			tag = true;
		}else if(bcType==graph.configuration.dataMap.bcTypeArr.lc) {
			layer.msg('当前选择的班次是【晚例保时间】不能'+ msg +'!');
			tag = true;
		}else if(bcType==graph.configuration.dataMap.bcTypeArr.out) {
			layer.msg('当前选择的班次是【出场班次】不能' + msg + '!');
			tag = true;
		}else if(bcType==inType) {
			layer.msg('当前选择的班次【'+ opr  +'】,不能重复设置!');
			tag = true;
		}
		return tag;
	}

	/**
	 * @description : (TODO) 左菜单操作成功状态反馈.
	 *
	 * @param [msg--消息状态]
	 * */
	function stateSuccess(msg) {
		layer.closeAll();
		layer.msg('操作成功!已【'+ msg + '】!');
	}
})();