allline.html 11.6 KB
<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;
}

.table-bordered>thead>tr>th, .table-bordered>thead>tr>td {
	border-bottom-width: 2px;
	text-align: center;
}

.table>tbody+tbody {
	border-top: 1px solid;
}

.table>tbody>tr>td, .table>tbody>tr>th, .table>tfoot>tr>td, .table>tfoot>tr>th,
	.table>thead>tr>td, .table>thead>tr>th {
	text-align: center;
}

.table-checkable tr>th:first-child, .table-checkable tr>td:first-child {
	text-align: center;
	max-width: initial;
	min-width: 40px;
	padding-left: 0;
	padding-right: 0;
}
</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 class="form-inline" action="" method="post">
					<div style="display: inline-block; margin-left: 24px;"
						id="gsdmDiv_allline">
						<span class="item-label" style="width: 80px;">公司: </span> <select
							class="form-control" name="company" id="gsdmAllline"
							style="width: 140px;"></select>
					</div>
					<div style="display: inline-block; margin-left: 15px;"
						id="fgsdmDiv_allline">
						<span class="item-label" style="width: 80px;">分公司: </span> <select
							class="form-control" name="subCompany" id="fgsdmAllline"
							style="width: 140px;"></select>
					</div>
					<div style="display: inline-block; margin-left: 15px;">
						<span class="item-label" style="width: 80px;">线路: </span> <select
							class="form-control" name="line" id="line" style="width: 120px;"></select>
					</div>
					<div style="display: inline-block; margin-left: 15px;">
						<span class="item-label" style="width: 80px;">开始时间: </span> <input
							class="form-control" type="text" id="startDate"
							style="width: 120px;" />
					</div>
					<div style="display: inline-block; margin-left: 15px;">
						<span class="item-label" style="width: 80px;">结束时间: </span> <input
							class="form-control" type="text" id="endDate"
							style="width: 120px;" />
					</div>
					<div class="form-group">
						<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: 20px; overflow: auto; min-width: 1000px">
					<table class="table table-bordered table-hover table-checkable"
						id="forms1">
						<thead>
							<tr>
								<th colspan="15">营运线路名称统计表</th>
							</tr>
							<tr>
								<td rowspan="2" style="padding-top: 20px;">日期</td>
								<td rowspan="2" style="padding-top: 20px;">公司</td>
								<td rowspan="2" style="padding-top: 20px;">直属公司</td>
								<td rowspan="2" style="padding-top: 20px;">线路名称</td>
								<td colspan="2">出车数</td>
								<td rowspan="2">出车率</td>
								<td colspan="2">班次数</td>
								<td rowspan="2" style="padding-top: 20px;">班次执行率</td>
								<td rowspan="2" style="padding-top: 20px;">说明</td>
							</tr>
							<tr>
								<td>计划</td>
								<td>实际</td>
								<td>计划</td>
								<td>实际</td>
							</tr>
						</thead>
						<tbody id="tbody">

						</tbody>
						<tr>
							<td colspan="1">分类汇总</td>
							<td><span id="total_gs">&nbsp;</span></td>
							<td><span id="total_zhgs">&nbsp;</span></td>
							<td><span id="total_xlts">&nbsp;</span></td>
							<td><span id="total_jh">&nbsp;</span></td>
							<td><span id="total_sj">&nbsp;</span></td>
							<td><span id="total_ccl">&nbsp;</span></td>
							<td><span id="total_bcjh">&nbsp;</span></td>
							<td><span id="total_bcsj">&nbsp;</span></td>
							<td><span id="total_bczxl">&nbsp;</span></td>
							<td><span id="total_sm">&nbsp;</span></td>
						</tr>
					</table>
				</div>
			</div>
		</div>
	</div>
</div>

<script>
	$(function() {
		// 关闭左侧栏
		if (!$('body').hasClass('page-sidebar-closed'))
			$('.menu-toggler.sidebar-toggler').click();

		$("#startDate,#endDate").datetimepicker({
			format : 'YYYY-MM-DD',
			locale : 'zh-cn'
		});

		var obj = [];
		$.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) {
				$("#gsdmDiv_allline").css('display', 'none');
				$('#fgsdmDiv_allline').css('display', 'none');
			} else if (obj.length == 1) {
				$("#gsdmDiv_allline").css('display', 'none');
				if (obj[0].children.length == 1 || obj[0].children.length == 0)
					$('#fgsdmDiv_allline').css('display', 'none');
			}
			$('#gsdmAllline').html(options);
			updateCompany();
		});

		$("#gsdmAllline").on("change", updateCompany);
		function updateCompany() {
			var company = $('#gsdmAllline').val();
			var options = '';
			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>';
					}
				}
			}
			$('#fgsdmAllline').html(options);
		}

		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){
					 $("#gsdmDiv_allline").css('display','none');
				}else if(obj.length ==1){
					 $("#gsdmDiv_allline").css('display','none');
					if(obj[0].children.length == 1  || obj[0].children.length ==0)
						$('#fgsdmDiv_allline').css('display','none');
				}
				$('#gsdmAllline').html(options);
				updateCompany();
			});
		})
		$("#gsdmAllline").on("change",updateCompany);
		function updateCompany(){
			var company = $('#gsdmAllline').val();
			var options = '';
			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>';
					}
				}
			}
			$('#fgsdmAllline').html(options);
			initXl();
		}

		/* $.get('/basic/lineCode2Name',function(result){
			var data=[];
			
			for(var code in result){
				data.push({id: code, text: result[code]});
			}
			initPinYinSelect2('#line',data,'');
			
		}) */
		
		$("#fgsdmAllline").on("change",initXl);
		function initXl(){
			var data=[];
			if(fage){
				$("#line").select2("destroy").html('');
			}
			var fgs=$('#fgsdmAllline').val();
			var gs=$('#gsdmAllline').val();
			for(var i=0;i<xlList.length;i++){
				if(gs!=""){
					if(fgs!=""){
						if(xlList[i]["fgsbm"]==fgs && xlList[i]["gsbm"]==gs){
							data.push({id: xlList[i]["xlbm"], text: xlList[i]["xlname"]});
						}
					}else{
						if(xlList[i]["gsbm"]==gs){
							data.push({id: xlList[i]["xlbm"], text: xlList[i]["xlname"]});
						}
					}
				}
			}
			initPinYinSelect2('#line',data,'');
			fage=true;
		}

		var line;
		var startDate;
		var endDate;
		var gsdmAllline;
		var fgsdmAllline;
		$("#query")
				.on(
						"click",
						function() {
							line = $("#line").val();
							startDate1 = $("#startDate").val();
							endDate1 = $("#endDate").val();
							gsdmAllline = $("#gsdmAllline").val();
							fgsdmAllline = $("#fgsdmAllline").val();
							if (startDate1 != '' && endDate1 != '') {
								$post(
										'/mcy_forms/allline',
										{
										    gsdmAllline:gsdmAllline,
										    fgsdmAllline:fgsdmAllline, 
											line : line,
											startDate : $("#startDate").val(),
											endDate : $("#endDate").val(),
											type : 'query'
										},
										function(result) {
											// 把数据填充到模版中
											var tbodyHtml = template('allline',
													{
														list : result
													});
											// 把渲染好的模版html文本追加到表格中
											$('#tbody').html(tbodyHtml);
											line = $("#line").val();
											startDate = $("#startDate").val();
											endDate = $("#endDate").val();
											$("#sDate").text(startDate);
											$("#eDate").text(endDate);

											var total_jh = 0;
											var total_sj = 0, total_ccl = 0, total_bcjh = 0;
											var total_bcjh = 0, total_bcsj = 0, total_bczxl = 0;
											var total_gs = 0;
											var total_zhgs = 0;
											$.each(
															result,
															function(i, obj) {
																total_gs += Number(obj.gsgs);
																total_zhgs += Number(obj.fgsgs);
																total_jh = Number(obj.cchjh)
																		+ Number(total_jh);
																total_sj = Number(obj.cchsj)
																		+ Number(total_sj);

																total_ccl = (Number(total_sj) / Number(total_jh)) * 100;
																total_bcjh = Number(obj.bcjh)
																		+ Number(total_bcjh);
																total_bcsj = Number(obj.bcsj)
																		+ Number(total_bcsj);
																total_bczxl = (Number(total_bcsj) / Number(total_bcjh)) * 100;

															});
											$("#total_gs").text(total_gs);
											$("#total_zhgs").text(total_zhgs);
											$("#total_jh").text(total_jh);
											$("#total_sj").text(total_sj);
											$("#total_ccl").text(
													total_ccl.toFixed(2) + '%');
											$("#total_bcjh").text(total_bcjh);
											$("#total_bcsj").text(total_bcsj);
											$("#total_bczxl").text(
													total_bczxl.toFixed(2)
															+ '%');

											var temp = {};
											var today_account = 0;

											temp["line"] = $("#line").text();
											$
													.each(
															result,
															function(i, obj) {
																if (moment(
																		obj.schedule_date_str)
																		.format(
																				"YYYY-MM-DD") == moment(
																		obj.startDate)
																		.format(
																				"YYYY-MM-DD")) {
																	today_account++;
																}
																obj.updateDate = moment(
																		obj.startDate)
																		.format(
																				"YYYY-MM-DD HH:mm:ss");
															});

										})

							} else {
								layer.msg("请选择时间范围!");
							}
						});

		$("#export").on(
				"click",
				function() {
					line = $("#line").val();
					startDate1 = $("#startDate").val();
					endDate1 = $("#endDate").val();
					gsdmAllline = $("#gsdmAllline").val();
					fgsdmAllline = $("#fgsdmAllline").val();
					$post('/mcy_export/alllineExport', {
						gsdmAllline : gsdmAllline,
						fgsdmAllline : fgsdmAllline,
						line : line,
						startDate : startDate,
						endDate : endDate,
						type : 'export'
					}, function(result) {
						window.open("/downloadFile/download?fileName=营运线路名称统计表"
								+ moment(startDate).format("YYYYMMDD"));
					});
				});
	});
</script>
<script type="text/html" id="allline">
	{{each list as obj i}}
		<tr>
			<td>{{obj.rq}}</td>
			<td>{{obj.gs}}</td>
			<td>{{obj.zhgs}}</td>
			<td>{{obj.xl}}</td>
			<td>{{obj.cchjh}}</td>
			<td>{{obj.cchsj}}</td>
			<td>{{obj.chl}}</td>
			<td>{{obj.bcjh}}</td>
			<td>{{obj.bcsj}}</td>
			<td>{{obj.bbzxl}}</td>
			<td>{{obj.xl}}</td>
		</tr>
	{{/each}}
	{{if list.length == 0}}
		<tr>
			<td colspan="12"><h6 class="muted">没有找到相关数据</h6></td>
		</tr>
	{{/if}}
</script>