alone.js 3 KB
/**
 * 单线路调度
 */

var _alone = (function(){
	var upCode = 0
		,downCode = 1;
	
	var aloneObject = {
		init: function(cb){
			_data.queryRealSchedule(lineCodes, function(schList){
				
				var schTempList;
				for(var lineCode in lineMap){
					schTempList = schList[lineCode];
					tab = $('#tab_line_' + lineCode);
					tab.append(template('alone_main_temp', lineMap[lineCode]));
					
					//有排班数据
					if(schTempList){
						var rs = splitDir(schTempList);
						//填充表格数据
						calculateLineNo(
								tab.find('table[data-type=up] tbody').html(template('alone_plan_table_temp', {list: rs.up}))[0]
						);
						calculateLineNo(
								tab.find('table[data-type=down] tbody').html(template('alone_plan_table_temp', {list: rs.down}))[0]
						);
						
						//滚动条	
						tab.find('._body').slimscroll({
								height: 'calc(100% - 80px)',
								alwaysVisible: true
						});
					}
					_data.queryStationRoute(lineCode , 'lineSvg' + lineCode , drawSvg.initAloneSvg);
				}
				
				$('.console-log .log-item-list').slimscroll({
					height: '100%'
				})
				//托管Question
				$('#tgQuestion').popover({
					content: template('tg_question_info_temp', {}),
					html: true,
					placement: 'left',
					trigger: 'hover',
					container: '.portlet-fullscreen'
				});
				
				initRemarksPop();
				
				cb && cb();
			});
		},
		//刷新单个班次
		refreshSchedule: function(schedule){
			//xlBm
			var $tr = $('tr[data-id='+schedule.id+']', '#tab_line_' + schedule.xlBm)
				,newTr = template('alone_plan_table_temp', {list: [schedule]});
			
			$tr.replaceWith(newTr);
			initRemarksPop();
		},
		//添加一个班次到表格
		addScheduleToTable: function(schedule){
			var upDown = schedule.xlDir==0?'up':'down';
			//重新渲染表格
			var table = $('#tab_line_' + schedule.xlBm).find('.pb-table[data-type='+upDown+']');
			//获取班次信息
			var schArray = _data.findSchByLine(schedule.xlBm, schedule.xlDir);
			calculateLineNo(
					table.find('tbody').html(template('alone_plan_table_temp', {list: schArray}))[0]
			);
			
			var currTr = table.find('tr[data-id='+schedule.id+']');
			console.log(currTr);
			//重新设置滚动条,
			table.find('._body').slimscroll({
					height: 'calc(100% - 80px)',
					alwaysVisible: true,
					start: currTr
			});
			
		},
		//重新计算行号
		calculateLineNo: calculateLineNo
	}
	
	//计算行号
	function calculateLineNo(table){
		var rows = table.rows;
		$.each(rows,function(i, r){
			var cells = r.cells;
			$(cells[0]).text(i + 1);
		});
	}
	
	function splitDir(list){
		var rs = {up: [], down: []};
		$.each(list, function(){
			if(this.xlDir == upCode)
				rs.up.push(this);
			else
				rs.down.push(this);
		});
		
		return rs;
	}
	
	function initRemarksPop(){
		//备注POPOVER
		$('.remarks-popover', '.pb-table').popover({trigger: 'hover',container: '.portlet-fullscreen',placement:'bottom'});
	}
	return aloneObject;
})();