<%@ 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{
                jp.loading();
                jp.post("${ctx}/filing/basicInformation/save",$('#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)

                    }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");
			}
		}
	</script>
</head>
<body class="bg-white">
		<form:form id="inputForm" modelAttribute="basicInformation" action="${ctx}/filing/basicInformation/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<table class="table table-bordered">
		   <tbody>
				<tr>
					<td class="width-15 active"><label class="pull-right"><font color="red">*</font>项目编码：</label></td>
					<td class="width-35">
						<form:input path="projectCode" htmlEscape="false"  class="form-control required"/>
					</td>
					<td class="width-15 active"><label class="pull-right"><font color="red">*</font>单体编码：</label></td>
					<td class="width-35">
						<form:input path="monomerCode" htmlEscape="false"  class="form-control required"/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right"><font color="red">*</font>项目名称：</label></td>
					<td class="width-35">
						<form:input path="entryName" htmlEscape="false"  class="form-control required"/>
					</td>
					<td class="width-15 active"><label class="pull-right">工程属性/重点程度：</label></td>
					<td class="width-35">
						<form:input path="emphasis" htmlEscape="false"  class="form-control"/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">建设年度1：</label></td>
					<td class="width-35">
						<form:input path="constructionYear" htmlEscape="false" rows="4"    class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right">建设年度1投资：</label></td>
					<td class="width-35">
						<form:input path="annualInvestment" htmlEscape="false" rows="4"    class="form-control "/>
					</td>
		  		</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">建设年度2：</label></td>
					<td class="width-35">
						<form:input path="constructionYearTwo" htmlEscape="false" rows="4"    class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right">建设年度2投资：</label></td>
					<td class="width-35">
						<form:input path="annualInvestmentTwo" htmlEscape="false" rows="4"    class="form-control "/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">建设年度3：</label></td>
					<td class="width-35">
						<form:input path="constructionYearThree" htmlEscape="false" rows="4"    class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right">建设年度3投资：</label></td>
					<td class="width-35">
						<form:input path="annualInvestmentThree" htmlEscape="false" rows="4"    class="form-control "/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">建设年度4：</label></td>
					<td class="width-35">
						<form:input path="constructionYearFour" htmlEscape="false" rows="4"    class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right">建设年度4投资:</label></td>
					<td class="width-35">
						<form:input path="annualInvestmentFour" htmlEscape="false" rows="4"    class="form-control "/>
					</td>
				</tr>
		 	</tbody>
		</table>
		<div class="tabs-container">
            <div class="tab-content">
				<div id="tab-1" class="tab-pane fade in  active">
			<a class="btn btn-white btn-sm" onclick="addRow('#basicChildList', basicInformationRowIdx, basicInformationTpl);basicInformationRowIdx = basicInformationRowIdx + 1;" title="新增">	<i class="glyphicon glyphicon-plus"></i> 新建</a>
			<table class="table table-striped table-bordered table-condensed">
				<thead>
					<tr>
						<th class="hide"></th>
						<th>项目编码</th>
						<th>单体编码</th>
						<th>项目名称</th>
						<th width="10">&nbsp;</th>
					</tr>
				</thead>
				<tbody id="basicChildList">
				</tbody>
			</table>
			<script type="text/template" id="basicInformationTpl">//<!--
				<tr id="basicChildList{{idx}}">
					<td class="hide">
						<input id="basicChildList{{idx}}_id" name="basicChildList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
						<input id="basicChildList{{idx}}_delFlag" name="basicChildList[{{idx}}].delFlag" type="hidden" value="0"/>
					</td>

					<td  class="max-width-250">
						<input type='text'  name="basicChildList[{{idx}}].projectCode" class="form-control"  value="{{row.projectCode}}"/>
					</td>

					<td  class="max-width-250">
						<input type='text'  name="basicChildList[{{idx}}].monomerCode" class="form-control"  value="{{row.monomerCode}}"/>
					</td>
					<td>
						<input type='text'  name="basicChildList[{{idx}}].entryName" class="form-control"  value="{{row.entryName}}"/>
					</td>
					<td class="text-center" width="10">
						{{#delBtn}}<span class="close" onclick="delRow(this, '#basicChildList{{idx}}')" title="删除">&times;</span>{{/delBtn}}
					</td>
				</tr>//-->
			</script>
			<script type="text/javascript">
				var basicInformationRowIdx = 0, basicInformationTpl = $("#basicInformationTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
				$(document).ready(function() {
					var data = ${fns:toJson(basicInformation.basicChildList)};
					for (var i=0; i<data.length; i++){
						addRow('#basicChildList', basicInformationRowIdx, basicInformationTpl, data[i]);
						basicInformationRowIdx = basicInformationRowIdx + 1;
					}
				});
			</script>
			</div>
		</div>
		</div>
		</form:form>
</body>
</html>
