scheduleAnaly.html 13.7 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
<style type="text/css">
	.table-bordered {
	  border: 1px solid; }
	  .table-bordered > thead > tr > th,
	  .table-bordered > thead > tr > td,
	  .table-bordered > tbody > tr > th,
	  .table-bordered > tbody > tr > td,
	  .table-bordered > tfoot > tr > th,
	  .table-bordered > tfoot > tr > td {
	    border: 1px solid;
	    text-align: center; }
	  .table-bordered > thead > tr > th,
	  .table-bordered > thead > tr > td {
	    border-bottom-width: 2px; }
	 
	 .table > tbody + tbody {
	   border-top: 1px solid; }
</style>

<div class="page-head">
	<div class="page-title">
		<h1>时刻表分析</h1>
	</div>
</div>

<div class="row">
	<div class="col-md-12">
		<div class="portlet light porttlet-fit bordered">
			<div class="portlet-title">
				<form id="history" class="form-inline" action="">
					<div style="display: inline-block;margin-left: 33px;" id="company1">
						<span class="item-label" style="width: 80px;">公司: </span>
						<select class="form-control" name="company" id="company" style="width: 150px;"></select>
					</div>
					<div style="display: inline-block;margin-left: 24px;" id="subCompany1">
						<span class="item-label" style="width: 80px;">分公司: </span>
						<select class="form-control" name="subCompany" id="subCompany" style="width: 150px;"></select>
					</div>
					<div style="display: inline-block;margin-left: 38px;">
						<span class="item-label" style="width: 80px;">线路: </span>
						<select class="form-control" name="line" id="line" style="width: 150px;"></select>
					</div>
					<div style="display: inline-block;margin-left: 10px;">
						<span class="item-label" style="width: 80px;">班次类型: </span>
						<select class="form-control" name="bcType" id="bcType" style="width: 150px;">
							<option value="0">全部班次</option>
							<option value="1">全程</option>
							<option value="2">区间</option>
						</select>
					</div>
					<div style="margin-top: 10px"></div>
					<div style="display: inline-block;margin-left: 5px;">
						<span class="item-label" style="width: 80px;">开始时间: </span>
						<input class="form-control" type="text" id="startDate" style="width: 150px;"/>
					</div>
					<div style="display: inline-block;margin-left: 10px;">
						<span class="item-label" style="width: 80px;">结束时间: </span>
						<input class="form-control" type="text" id="endDate" style="width: 150px;"/>
					</div>
					<div style="display: inline-block;margin-left: 10px;">
						<span class="item-label" style="width: 80px;">模板类型: </span>
						<select class="form-control" name="model" id="model" style="width: 150px;">
							<option value="">请选择...</option>
						</select>
					</div>
					<div class="form-group" style="margin-left: 10px">
						<input class="btn btn-default" type="button" id="query" value="筛选"/>
						<input class="btn btn-default" type="button" id="export" value="导出"/>
					</div>
				</form>
			</div>
			<div class="portlet-body">
				<div class="table-container" style="margin-top: 50px;overflow:auto;min-width: 906px">
					<table class="table table-bordered table-hover table-checkable" id="forms">
						<thead>
							<tr class="hidden">
								<th style="display: none;"></th>
								<th width="8%">公司</th>
								<th width="8%">分公司</th>
								<th width="8%">线路</th>
								<th width="8%">起点站名</th>
								<th width="6%">路牌</th>
								<th width="6%">计发时间</th>
								<th width="6%">计划运送时间(分)</th>
								<th width="6%">计划完成次数</th>
								<th width="6%">完成次数</th>
								<th width="6%">最早发车时间</th>
								<th width="6%">最晚发车时间</th>
								<th width="6%">平均发车时间</th>
								<th width="6%">最慢运送时间(分)</th>
								<th width="6%">最快运送时间(分)</th>
								<th width="6%">平均运送时间(分)</th>
							</tr>
						</thead>
						<tbody>
							
						</tbody>
					</table>
					<div style="text-align: right;">
						<ul id="pagination" class="pagination"></ul>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

<script>
	$(function(){
		var page = 0, initPagination;
		$('#export').attr('disabled', "true");
		
		// 关闭左侧栏
		if (!$('body').hasClass('page-sidebar-closed'))
			$('.menu-toggler.sidebar-toggler').click();
		
		$("#startDate").datetimepicker({
			format : 'YYYY-MM-DD',
			locale : 'zh-cn'
		});
		
		$("#endDate").datetimepicker({
			format : 'YYYY-MM-DD',
			locale : 'zh-cn'
		});

		var d = new Date();
		var year = d.getFullYear();
		var month = d.getMonth() + 1;
		var day = d.getDate();
		if(month < 10)
			month = "0" + month;
		if(day < 10)
			day = "0" + day;
		$("#startDate").val(year + "-" + month + "-" + day);
		$("#endDate").val(year + "-" + month + "-" + day);
		
		var fage=false;
		var xlList;
		var obj = [];
		
		$.get('/report/lineList',function(result){
			xlList=result;
			$.get('/user/companyData', function(result){
				obj = result;
				var options = '';
				for(var i = 0; i < obj.length; i++){
					options += '<option value="'+obj[i].companyCode+'">'+obj[i].companyName+'</option>';
				}
				
				if(obj.length ==0){
					 $("#company1").css('display','none');
				}else if(obj.length ==1){
					 $("#company1").css('display','none');
					if(obj[0].children.length == 1  || obj[0].children.length ==0)
						$('#subCompany1').css('display','none');
				}
				$('#company').html(options);
				updateCompany();
			});
		})
		$("#company").on("change",updateCompany);
		function updateCompany(){
			var company = $('#company').val();
			var options = '';
// 			var options = '<option value="">全部分公司</option>';
			for(var i = 0; i < obj.length; i++){
				if(obj[i].companyCode == company){
					var children = obj[i].children;
					for(var j = 0; j < children.length; j++){
						options += '<option value="'+children[j].code+'">'+children[j].name+'</option>';
					}
				}
			}
			$('#subCompany').html(options);
		}
		
		
		var tempData = {};
		$.get('/report/lineList',function(xlList){
			var data = [];
			$.get('/user/companyData', function(result){
				for(var i = 0; i < result.length; i++){
					var companyCode = result[i].companyCode;
					var children = result[i].children;
					for(var j = 0; j < children.length; j++){
						var code = children[j].code;
						for(var k=0;k < xlList.length;k++ ){
							if(xlList[k]["fgsbm"]==code && xlList[k]["gsbm"]==companyCode){
								data.push({id: xlList[k]["xlbm"], text: xlList[k]["xlname"]});
								tempData[xlList[k]["xlbm"]] = companyCode+":"+code;
							}
						}
					}
				}
				initPinYinSelect2('#line',data,'');
				line = data[0].id;
				updateModel();
				
			});
		});
		
		$("#line").on("change", function(){
			if($("#line").val() == " "){
				$("#company").attr("disabled", false);
				$("#subCompany").attr("disabled", false);
			} else {
				var temp = tempData[$("#line").val()].split(":");
				$("#company").val(temp[0]);
				updateCompany();
				$("#subCompany").val(temp[1]);
				$("#company").attr("disabled", true);
// 				$("#subCompany").attr("disabled", true);
			}
		});
		

		$("#query").on("click", function(){
			page = 0;
			jsDoQuery(true);
		});
		
		var list;
		var line = $("#line").val();
		var startDate = $("#startDate").val();
		var endDate = $("#endDate").val();
		var model = $("#model").val();
		var bcType = $('#bcType').val();
		var company = $("#company").val();
		var subCompany = $("#subCompany").val();
		var lineName = $('#line option:selected').text();
		function jsDoQuery(pagination){
			if($("#startDate").val() == null || $("#startDate").val().trim().length == 0){
				layer.msg("请选择时间范围!");
				return;
			}
			if($("#endDate").val() == null || $("#endDate").val().trim().length == 0){
				layer.msg("请选择时间范围!");
				return;
			}
			var params = {};
// 			line = $("#line").val();
			startDate = $("#startDate").val();
			endDate = $("#endDate").val();
			model = $("#model").val();
			bcType = $("#bcType").val();
			company = $("#company").val();
			subCompany = $("#subCompany").val();
			lineName = $('#line option:selected').text();
			if(lineName == "全部线路")
				lineName = $('#subCompany option:selected').text();
			params['page'] = page;
			params['line'] = line;
			params['startDate'] = startDate;
			params['endDate'] = endDate;
			params['model'] = model;
			params['bcType'] = bcType;
			params['company'] = company;
			params['subCompany'] = subCompany;
			params['type'] = "query";
			$(".hidden").removeClass("hidden");
			var i = layer.load(2);
			$get('/pcpc/scheduleAnaly', params, function(result){
				list = result.dataList;
				dataPageChange(page, result.dataList);
				layer.close(i);

				if(result.dataList.length == 0)
					$("#export").attr('disabled',"true");
				else
					$("#export").removeAttr("disabled");
				
				if(pagination && result.dataList.length > 0){
					//重新分页
					initPagination = true;
					showPagination(result);
					
					$('#pagination').show();
				} else if(result.dataList.length == 0){
					$('#pagination').hide();
				}
			});
		}
		
		function dataPageChange(page, list){
			var tempList = [];
			for(var f = page*10; f < list.length && f < (page+1)*10; f++){
				tempList[tempList.length] = list[f];
			}
			// 把数据填充到模版中
			var tbodyHtml = template('list_scheduleAnaly',{list:tempList});
			// 把渲染好的模版html文本追加到表格中
			$('#forms tbody').html(tbodyHtml);
		}
		
		$("#export").on("click",function(){
			var params = {};
			params['page'] = page;
			params['line'] = line;
			params['startDate'] = startDate;
			params['endDate'] = endDate;
			params['model'] = model;
			params['company'] = company;
			params['subCompany'] = subCompany;
			params['bcType'] = bcType;
			params['type'] = "export";
			params['lineName'] = lineName;
			var i = layer.load(2);
			$get('/pcpc/scheduleAnaly', params, function(result){
				window.open("/downloadFile/download?fileName="
						+moment(startDate).format("YYYYMMDD")+
						"-"+moment(endDate).format("YYYYMMDD")
						+"-"+lineName+"-时刻表分析");
				layer.close(i);
			});
		});


		$("#line").on("change", function(){
			line = $("#line").val();
			if(line == " ")
				line = "";
			updateModel();
		});
		$('#startDate, #endDate').on("blur", function(){
			startDate = $("#startDate").val();
			endDate = $("#endDate").val();
			updateModel();
		});
		
		var flag = 0;
		function updateModel(){
			if(flag == 1)
				return;
			flag = 1;
			var treeData = [];
			var params = {};
			params['line'] = line;
			params['startDate'] = startDate;
			params['endDate'] = endDate;
			$('#model').html('<option value="">载入中...</option>');
			$get('/pcpc/getModel', params, function(result){
				treeData = createTreeData(result);
				var options = '<option value="">请选择...</option>';
				var size = 0;
				$.each(treeData, function(i, g){
					options += '<option value="'+g.id+'">'+g.name+'</option>';
					size++;
				});
				$('#model').html(options)/* .select2() */;
				flag = 0;
			});
// 			params['xl.lineCode_eq'] = line;
// 			$get('/tic_ec', params, function(result){
// 				treeData = createTreeData(result.data.content);
// 				var options = '<option value="">请选择...</option>';
// 				$.each(treeData, function(i, g){
// 					if(!g.isCancel)
// 						options += '<option value="'+g.id+'">'+g.name+'</option>';
// 				});
// 				$('#model').html(options)/* .select2() */;
// 				flag = 0;
// 			});
		}
		
		/**
		 * 将模块List 转换为树结构
		 * @param arr
		 * @returns {Array}
		 */
		function createTreeData(arr){
			var treeData = [];
			var len = arr.length;
			for(var i = 0; i < len; i ++){
				var pId = arr[i].pId;
				arr[i].text = arr[i].name;
				if(!pId){
					treeData.push(arr[i]);
				}

				for(var j = 0; j < len; j ++){
					if(pId == arr[j].id){
						if(!arr[j].children)
							arr[j].children = [];
						arr[j].children.push(arr[i]);
						break;
					}
				}
			}
			return treeData;
		}
		
		function showPagination(data){
			//分页
			$('#pagination').jqPaginator({
			    totalPages: data.totalPage,
			    visiblePages: 6,
			    currentPage: page + 1,
			    first: '<li class="first"><a href="javascript:void(0);">首页<\/a><\/li>',
	            prev: '<li class="prev"><a href="javascript:void(0);">上一页<\/a><\/li>',
	            next: '<li class="next"><a href="javascript:void(0);">下一页<\/a><\/li>',
	            last: '<li class="last"><a href="javascript:void(0);">尾页<\/a><\/li>',
	            page: '<li class="page"><a href="javascript:void(0);">{{page}}<\/a><\/li>',
			    onPageChange: function (num, type) {
			    	if(initPagination){
			    		initPagination = false;
			    		return;
			    	}
			    	page = num - 1;
// 			    	jsDoQuery(false);
					dataPageChange(page, list);
			    }
			});
		}
		
		
	});
	
</script>
<script type="text/html" id="list_scheduleAnaly">
	{{each list as obj i}}
		<tr>
			<th style="display: none;"></th>
			<td>{{obj.company}}</td>
			<td>{{obj.subCompany}}</td>
			<td>{{obj.line}}</td>
			<td>{{obj.qdz}}</td>
			<td>{{obj.lp}}</td>
			<td>{{obj.jhfc}}</td>
			<td>{{obj.bcsj}}</td>
			<td>{{obj.jhbc}}</td>
			<td>{{obj.sjbc}}</td>
			<td>{{obj.zzfc}}</td>
			<td>{{obj.zwfc}}</td>
			<td>{{obj.pjfc}}</td>
			<td>{{obj.zmys}}</td>
			<td>{{obj.zkys}}</td>
			<td>{{obj.pjys}}</td>
		</tr>
	{{/each}}
	{{if list.length == 0}}
		<tr>
			<td colspan="15"><h6 class="muted">没有找到相关数据</h6></td>
		</tr>
	{{/if}}
</script>