<%@ 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() {
			$('#startDate').datetimepicker({
				format: "YYYY-MM-DD"
			});
			$('#endDate').datetimepicker({
				format: "YYYY-MM-DD"
			});
		});
		function save() {
            let isValidate = jp.validateForm('#inputForm');//校验表单
            if(!isValidate){
                return false;
			}else{
                jp.loading();
				jp.post("${ctx}/finance/corresponding/save",$('#inputForm').serialize(), function (data) {
					if (data.success) {
						jp.getParent().refresh();
						let 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="corresponding" 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="serialNumber" htmlEscape="false"    class="form-control required"/>
					</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('#childList', 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>物料编码<a style="color: red">*</a></th>
								<th>物料类型<a style="color: red">*</a></th>
								<th>物料描述<a style="color: red">*</a></th>
								<th width="40">操作</th>
							</tr>
							</thead>
							<tbody id="childList">
							</tbody>
						</table>
						<script type="text/template" id="basicInformationTpl">//<!--
				<tr id="childList{{idx}}">
					<td class="hide">
						<input id="childList{{idx}}_id" name="childList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
						<input id="childList{{idx}}_delFlag" name="childList[{{idx}}].delFlag" type="hidden" value="0"/>
					</td>

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

					<td  class="max-width-250">
						<input type='text'  name="childList[{{idx}}].materialType" class="form-control"  value="{{row.materialType}}"/>
					</td>
					<td>
						<input type='text'  name="childList[{{idx}}].materialDescription" class="form-control"  value="{{row.materialDescription}}"/>
					</td>
					<td class="text-center" width="10">
						{{#delBtn}}<span class="close" onclick="delRow(this, '#childList{{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(corresponding.childList)};
								for (var i=0; i<data.length; i++){
									addRow('#childList', basicInformationRowIdx, basicInformationTpl, data[i]);
									basicInformationRowIdx = basicInformationRowIdx + 1;
								}
							});
						</script>
					</div>
				</div>
			</div>
	</form:form>
</body>
</html>