<%@ 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/saveInventory",$('#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="inventoryData" action="${ctx}/filing/basicInformation/save" method="post" class="form-horizontal">
			<input type="hidden" id="uuid" name="uuid" value="${uuid}">
			<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>名称</th>
							<th>规格</th>
							<th>单位</th>
							<th>数量</th>
							<th>备注</th>
						</tr>
					</thead>
					<tbody id="inventoryList">
					</tbody>
				</table>
				<script type="text/template" id="basicInformationTpl">//<!--
					<tr id="inventoryList{{idx}}">
						<td class="hide">
						</td>
						<td  class="max-width-250">
						<input type='text' id="inventoryList[{{idx}}]_num"  name="inventoryList[{{idx}}].num" readonly= "true" class="form-control"  value="{{row.num}}"/>
						</td>
						<td  class="max-width-250">
						<input type='text' id="inventoryList[{{idx}}]_name"  name="inventoryList[{{idx}}].name" readonly= "true" class="form-control"  value="{{row.name}}"/>
						</td>
						<td  class="max-width-250">
						<input type='text' id="inventoryList[{{idx}}]_specifications"  name="inventoryList[{{idx}}].specifications" readonly= "true" class="form-control"  value="{{row.specifications}}"/>
						</td>
						<td  class="max-width-250">
						<input type='text' id="inventoryList[{{idx}}]_company"  name="inventoryList[{{idx}}].company" readonly= "true" class="form-control"  value="{{row.company}}"/>
						</td>

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