<%@ 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() {
			jp.ajaxForm("#inputForm",function(data){
				if(data.success){
				    jp.success(data.msg);
					jp.go("${ctx}/warehouse/ledger/ledger");
				}else{
				    jp.error(data.msg);
				    $("#inputForm").find("button:submit").button("reset");
				}
			});
			
		});
		
		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>
<div class="wrapper wrapper-content">				
<div class="row">
	<div class="col-md-12">
	<div class="panel panel-primary">
		<div class="panel-heading">
			<h3 class="panel-title"> 
				<a class="panelButton" href="${ctx}/warehouse/ledger/ledger"><i class="ti-angle-left"></i> 返回</a>
			</h3>
		</div>
		<div class="panel-body">
		<form:form id="inputForm" modelAttribute="ledger" action="${ctx}/warehouse/ledger/ledger/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
				<div class="form-group">
					<label class="col-sm-2 control-label">物资名称：</label>
					<div class="col-sm-10">
						<form:input path="name" htmlEscape="false"    class="form-control "/>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">类型：</label>
					<div class="col-sm-10">
						<sys:treeselect id="type" name="type.id" value="${ledger.type.id}" labelName="type.name" labelValue="${ledger.type.name}"
							title="类型" url="/warehouse/materialtype/materialType/treeData" extId="${ledger.id}" cssClass="form-control " allowClear="true"/>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">型号：</label>
					<div class="col-sm-10">
						<form:input path="model" htmlEscape="false"    class="form-control "/>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">货架id集合：</label>
					<div class="col-sm-10">
						<form:input path="shelvesIds" htmlEscape="false"    class="form-control "/>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">数量：</label>
					<div class="col-sm-10">
						<form:input path="num" htmlEscape="false"    class="form-control "/>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">备注信息：</label>
					<div class="col-sm-10">
						<form:textarea path="remarks" htmlEscape="false" rows="4"    class="form-control "/>
					</div>
				</div>
		<div class="tabs-container">
            <ul class="nav nav-tabs">
				<li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true">台账明细：</a>
                </li>
            </ul>
            <div class="tab-content">
				<div id="tab-1" class="tab-pane fade in  active">
			<a class="btn btn-white btn-sm" onclick="addRow('#ledgerInfoList', ledgerInfoRowIdx, ledgerInfoTpl);ledgerInfoRowIdx = ledgerInfoRowIdx + 1;" title="新增"><i class="fa fa-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>批次号</th>
						<th>货品明细id</th>
						<th>二维码id</th>
						<th>货架id</th>
						<th>物资编码</th>
						<th>备注信息</th>
						<th width="10">&nbsp;</th>
					</tr>
				</thead>
				<tbody id="ledgerInfoList">
				</tbody>
			</table>
			<script type="text/template" id="ledgerInfoTpl">//<!--
				<tr id="ledgerInfoList{{idx}}">
					<td class="hide">
						<input id="ledgerInfoList{{idx}}_id" name="ledgerInfoList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
						<input id="ledgerInfoList{{idx}}_delFlag" name="ledgerInfoList[{{idx}}].delFlag" type="hidden" value="0"/>
					</td>
					
					<td>
						<input id="ledgerInfoList{{idx}}_name" name="ledgerInfoList[{{idx}}].name" type="text" value="{{row.name}}"    class="form-control "/>
					</td>
					
					
					<td>
						<sys:treeselect id="ledgerInfoList{{idx}}_type" name="ledgerInfoList[{{idx}}].type.id" value="{{row.type.id}}" labelName="ledgerInfoList{{idx}}.type.code" labelValue="{{row.type.code}}"
							title="类型" url="/warehouse/materialtype/materialType/treeData" cssClass="form-control  " allowClear="true" />
					</td>
					
					
					<td>
						<input id="ledgerInfoList{{idx}}_model" name="ledgerInfoList[{{idx}}].model" type="text" value="{{row.model}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="ledgerInfoList{{idx}}_batchNum" name="ledgerInfoList[{{idx}}].batchNum" type="text" value="{{row.batchNum}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="ledgerInfoList{{idx}}_goodsInfo" name="ledgerInfoList[{{idx}}].goodsInfo.id" type="text" value="{{row.goodsInfo.id}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="ledgerInfoList{{idx}}_qr" name="ledgerInfoList[{{idx}}].qr.id" type="text" value="{{row.qr.id}}"    class="form-control "/>
					</td>
					
					
					<td>
						<sys:treeselect id="ledgerInfoList{{idx}}_shelves" name="ledgerInfoList[{{idx}}].shelves.id" value="{{row.shelves.id}}" labelName="ledgerInfoList{{idx}}.shelves.name" labelValue="{{row.shelves.name}}"
							title="货架id" url="/warehouse/shelves/shelves/data" cssClass="form-control  " allowClear="true" />
					</td>
					
					
					<td>
						<input id="ledgerInfoList{{idx}}_code" name="ledgerInfoList[{{idx}}].code" type="text" value="{{row.code}}"    class="form-control "/>
					</td>
					
					
					<td>
						<textarea id="ledgerInfoList{{idx}}_remarks" name="ledgerInfoList[{{idx}}].remarks" rows="4"    class="form-control ">{{row.remarks}}</textarea>
					</td>
					
					<td class="text-center" width="10">
						{{#delBtn}}<span class="close" onclick="delRow(this, '#ledgerInfoList{{idx}}')" title="删除">&times;</span>{{/delBtn}}
					</td>
				</tr>//-->
			</script>
			<script type="text/javascript">
				var ledgerInfoRowIdx = 0, ledgerInfoTpl = $("#ledgerInfoTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
				$(document).ready(function() {
					var data = ${fns:toJson(ledger.ledgerInfoList)};
					for (var i=0; i<data.length; i++){
						addRow('#ledgerInfoList', ledgerInfoRowIdx, ledgerInfoTpl, data[i]);
						ledgerInfoRowIdx = ledgerInfoRowIdx + 1;
					}
				});
			</script>
			</div>
		</div>
		</div>
		<c:if test="${mode == 'add' || mode=='edit'}">
				<div class="col-lg-3"></div>
		        <div class="col-lg-6">
		             <div class="form-group text-center">
		                 <div>
		                     <button class="btn btn-primary btn-block btn-lg btn-parsley" data-loading-text="正在提交...">提 交</button>
		                 </div>
		             </div>
		        </div>
		</c:if>
		</form:form>
		</div>				
	</div>
	</div>
</div>
</div>
</body>
</html>