<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>核准阶段管理</title>
	<meta name="decorator" content="ani"/>
	<script type="text/javascript">

		$(document).ready(function() {
	        $('#inDate').datetimepicker({
				 format: "YYYY-MM-DD HH:mm:ss"
		    });
		});

		function save() {
            var isValidate = jp.validateForm('#inputForm');//校验表单
            if(!isValidate){
                return false;
			}else{
            	var uuid = $("#uuid").val();
                jp.loading();
                jp.post("${ctx}/raiseCapitalDesign/saveVlatage",$('#inputForm').serialize(),function(data){
                    if(data.success){
                        jp.getParent().refresh();
                        var dialogIndex = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                        parent.layer.close(dialogIndex);
                        jp.success(data.msg)
						jp.getParent().refreshCharts(uuid);
                    }else{
                        jp.error(data.msg);
                    }
                })
			}

        }
		function addRow(list, idx, tpl, row){
			$(list).append(Mustache.render(tpl, {
				idx: idx, delBtn: true, row: row
			}));
			$(list+idx).find("select").each(function(){
				$(this).val($(this).attr("data-value"));
			});
			$(list+idx).find("input[type='checkbox'], input[type='radio']").each(function(){
				var ss = $(this).attr("data-value").split(',');
				for (var i=0; i<ss.length; i++){
					if($(this).val() == ss[i]){
						$(this).attr("checked","checked");
					}
				}
			});
			$(list+idx).find(".form_datetime").each(function(){
				 $(this).datetimepicker({
					 format: "YYYY-MM-DD HH:mm:ss"
			    });
			});
		}
		function delRow(obj, prefix){
			var id = $(prefix+"_id");
			var delFlag = $(prefix+"_delFlag");
			if (id.val() == ""){
				$(obj).parent().parent().remove();
			}else if(delFlag.val() == "0"){
				delFlag.val("1");
				$(obj).html("&divide;").attr("title", "撤销删除");
				$(obj).parent().parent().addClass("error");
			}else if(delFlag.val() == "1"){
				delFlag.val("0");
				$(obj).html("&times;").attr("title", "删除");
				$(obj).parent().parent().removeClass("error");
			}
		}

		function highVoltageCalculate(obj,prefix) {
			var tr=$(obj).parent().parent();
			var singleCircuitPath =document.getElementById(prefix+"_singleCircuitPath").value;//单回路路径
			var doubleCircuitPath =document.getElementById(prefix+"_doubleCircuitPath").value;//双回路路径
			var highSingleVoltageCoefficient = $("#highSingleVoltageCoefficient").val();//10KV单回路路径系数
			var highDoubleVoltageCoefficient = $("#highDoubleVoltageCoefficient").val();//10KV双回路路径系数

			if (singleCircuitPath==undefined || singleCircuitPath==null || singleCircuitPath==''){
				singleCircuitPath=0;
			}
			if (doubleCircuitPath==undefined || doubleCircuitPath==null || doubleCircuitPath==''){
				doubleCircuitPath=0;
			}
			if (highSingleVoltageCoefficient==undefined || highSingleVoltageCoefficient==null || highSingleVoltageCoefficient==''){
				highSingleVoltageCoefficient=1;
			}
			if (highDoubleVoltageCoefficient==undefined || highDoubleVoltageCoefficient==null || highDoubleVoltageCoefficient==''){
				highDoubleVoltageCoefficient=1;
			}
			var total=parseFloat(singleCircuitPath)*parseFloat(highSingleVoltageCoefficient)+parseFloat(doubleCircuitPath)*parseFloat(highDoubleVoltageCoefficient);
			document.getElementById(prefix+"_singleLong").value=total.toFixed(2);
		}

		function lowVoltageCalculate(obj,prefix) {
			var tr=$(obj).parent().parent();
			var singleCircuitPath =document.getElementById(prefix+"_singleCircuitPath").value;//单回路路径
			var doubleCircuitPath =document.getElementById(prefix+"_doubleCircuitPath").value;//双回路路径
			var lowSingleVoltageCoefficient = $("#lowSingleVoltageCoefficient").val();//0.4KV单回路路径系数
			var lowDoubleVoltageCoefficient = $("#lowDoubleVoltageCoefficient").val();//0.4KV双回路路径系数

			if (singleCircuitPath==undefined || singleCircuitPath==null || singleCircuitPath==''){
				singleCircuitPath=0;
			}
			if (doubleCircuitPath==undefined || doubleCircuitPath==null || doubleCircuitPath==''){
				doubleCircuitPath=0;
			}
			if (lowSingleVoltageCoefficient==undefined || lowSingleVoltageCoefficient==null || lowSingleVoltageCoefficient==''){
				lowSingleVoltageCoefficient=1;
			}
			if (lowDoubleVoltageCoefficient==undefined || lowDoubleVoltageCoefficient==null || lowDoubleVoltageCoefficient==''){
				lowDoubleVoltageCoefficient=1;
			}
			var total=parseFloat(singleCircuitPath)*parseFloat(lowSingleVoltageCoefficient)+parseFloat(doubleCircuitPath)*parseFloat(lowDoubleVoltageCoefficient);
			document.getElementById(prefix+"_singleLong").value=total.toFixed(2);
		}
	</script>
</head>
<body class="bg-white">
<div>
	<ul class="nav nav-tabs list-tabs">
		<li class="active" role="presentation" id="click1"><a id="dq" href="javascript:void(0)">10kV部分</a></li>
	</ul>
</div>
		<form:form id="inputForm" modelAttribute="voltageData" action="${ctx}/filing/basicInformation/save" method="post" class="form-horizontal">
			<input type="hidden" id="uuid" name="uuid" value="${uuid}">
			<input type="hidden" id="highSingleVoltageCoefficient" value="${highSingleVoltageCoefficient}">
			<input type="hidden" id="highDoubleVoltageCoefficient" value="${highDoubleVoltageCoefficient}">
			<input type="hidden" id="lowSingleVoltageCoefficient" value="${lowSingleVoltageCoefficient}">
			<input type="hidden" id="lowDoubleVoltageCoefficient" value="${lowDoubleVoltageCoefficient}">
			<div class="tabs-container">
				<div class="tab-content">
					<div id="tab-1" class="tab-pane fade in  active">
				<table class="table table-striped table-bordered table-condensed">
					<thead>
						<tr>
							<th class="hide"></th>
							<th>导线型号</th>
							<th>单回路路径(km)</th>
							<th>双回路路径(km)</th>
							<th>单线长(km)</th>
						</tr>
					</thead>
					<tbody id="highVoltageList">
					</tbody>
				</table>
				<script type="text/template" id="basicInformationTpl">//<!--
					<tr id="highVoltageList{{idx}}">
						<td class="hide">
							<input id="highVoltageList{{idx}}_id" name="highVoltageList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
							<input id="highVoltageList{{idx}}_delFlag" name="highVoltageList[{{idx}}].delFlag" type="hidden" value="0"/>
						</td>

						<td  class="max-width-250">
						<input type='text' id="highVoltageList[{{idx}}]_voltageName"  name="highVoltageList[{{idx}}].voltageName" readonly= "true" class="form-control"  value="{{row.voltageName}}"/>
						</td>

						<td  class="max-width-250">
							<input type='text' id="highVoltageList[{{idx}}]_singleCircuitPath" name="highVoltageList[{{idx}}].singleCircuitPath" placeholder="请输入数字"  onkeyup="this.value=this.value.replace(/^(\d*\.?\d{0,2}).*/,'$1')" maxlength="10" class="form-control number"  value="{{row.singleCircuitPath}}" onchange="highVoltageCalculate(this,'highVoltageList[{{idx}}]')"/>
						</td>
						<td class="max-width-250">
							<input type='text' id="highVoltageList[{{idx}}]_doubleCircuitPath" name="highVoltageList[{{idx}}].doubleCircuitPath" placeholder="请输入数字"  onkeyup="this.value=this.value.replace(/^(\d*\.?\d{0,2}).*/,'$1')" maxlength="10" class="form-control number"  value="{{row.doubleCircuitPath}}" onchange="highVoltageCalculate(this,'highVoltageList[{{idx}}]')"/>
						</td>
						<td class="max-width-250">
							<input type='text' id="highVoltageList[{{idx}}]_singleLong" name="highVoltageList[{{idx}}].singleLong" readonly= "true" class="form-control number"  value="{{row.singleLong}}"/>
						</td>
					</tr>//-->
				</script>
				<script type="text/javascript">
					var basicInformationRowIdx = 0, basicInformationTpl = $("#basicInformationTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
					$(document).ready(function() {
						var data = ${fns:toJson(highVoltageList)};
						for (var i=0; i<data.length; i++){
							console.log(data[i])
							addRow('#highVoltageList', basicInformationRowIdx, basicInformationTpl, data[i]);
							basicInformationRowIdx = basicInformationRowIdx + 1;
						}
					});
				</script>
				</div>
			</div>
		</div>

			<div>
				<ul class="nav nav-tabs list-tabs">
					<li class="active" role="presentation" id="click2" ><a id="qd" href="javascript:void(0)">0.4kV部分</a></li>
				</ul>
			</div>

			<div class="tabs-container">
				<div class="tab-content">
					<div id="tab-2" class="tab-pane fade in  active">
						<table class="table table-striped table-bordered table-condensed">
							<thead>
							<tr>
								<th class="hide"></th>
								<th>导线型号</th>
								<th>单回路路径(km)</th>
								<th>双回路路径(km)</th>
								<th>单线长(km)</th>
							</tr>
							</thead>
							<tbody id="lowVoltageList">
							</tbody>
						</table>
						<script type="text/template" id="lowVoltageTpl">//<!--
				<tr id="lowVoltageList{{idx}}">
					<td class="hide">
						<input id="lowVoltageList{{idx}}_id" name="lowVoltageList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
						<input id="lowVoltageList{{idx}}_delFlag" name="lowVoltageList[{{idx}}].delFlag" type="hidden" value="0"/>
					</td>

					<td  class="max-width-250">
					<input type='text' id="lowVoltageList[{{idx}}]_voltageName" name="lowVoltageList[{{idx}}].voltageName"  readonly= "true" class="form-control"  value="{{row.voltageName}}"/>
					</td>

					<td  class="max-width-250">
						<input type='text' id="lowVoltageList[{{idx}}]_singleCircuitPath" name="lowVoltageList[{{idx}}].singleCircuitPath" placeholder="请输入数字"  onkeyup="this.value=this.value.replace(/^(\d*\.?\d{0,2}).*/,'$1')" maxlength="10" class="form-control number"  value="{{row.singleCircuitPath}}" onchange="lowVoltageCalculate(this,'lowVoltageList[{{idx}}]')"/>
					</td>
					<td class="max-width-250">
						<input type='text' id="lowVoltageList[{{idx}}]_doubleCircuitPath" name="lowVoltageList[{{idx}}].doubleCircuitPath" placeholder="请输入数字"  onkeyup="this.value=this.value.replace(/^(\d*\.?\d{0,2}).*/,'$1')" maxlength="10" class="form-control number"  value="{{row.doubleCircuitPath}}" onchange="lowVoltageCalculate(this,'lowVoltageList[{{idx}}]')"/>
					</td>
					<td class="max-width-250">
						<input type='text' id="lowVoltageList[{{idx}}]_singleLong" name="lowVoltageList[{{idx}}].singleLong" readonly= "true" class="form-control number"  value="{{row.singleLong}}"/>
					</td>
				</tr>//-->
						</script>
						<script type="text/javascript">
							var lowVoltageRowIdx = 0, lowVoltageTpl = $("#lowVoltageTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
							$(document).ready(function() {
								var data = ${fns:toJson(lowVoltageList)};
								for (var i=0; i<data.length; i++){
									console.log(data[i])
									addRow('#lowVoltageList', lowVoltageRowIdx, lowVoltageTpl, data[i]);
									lowVoltageRowIdx = lowVoltageRowIdx + 1;
								}
							});
						</script>
					</div>
				</div>
			</div>
		</form:form>
</body>
</html>
