<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>交接单管理</title>
	<meta name="decorator" content="default"/>
	<script src="${ctxStatic}/layer-v2.3/laydate/laydate.js"></script>
	<script type="text/javascript">
		var validateForm;
//		function doSubmit(){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
//		  if(validateForm.form()){
//			  $("#inputForm").submit();
//			  return true;
//		  }
//
//		  return false;
//		}
		$(document).ready(function() {
			validateForm = $("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
            getCurrentDocumentHei()
		});
        function addRow(list, idx, tpl, row){
            var idx2 = $("#workHandBills tr").length;
            if(list == '#workHandBills'){
                bornTemplete(list, idx, tpl, row, idx2);
            }
        }
        function bornTemplete(list, idx, tpl, row, idx1){
            $(list).append(Mustache.render(tpl, {
                idx: idx, delBtn: true, row: row,
                order:idx1 + 1
            }));
//            $(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");
//                    }
//                }
//            });
            getCurrentDocumentHei();
        }
        function delRow(obj, prefix,othis){
            var id = $(prefix+"_id");
            var delFlag = $(prefix+"_delFlag");
            if (id.val() == ""){
                delFlag.val("1");
                $(obj).parent().parent().remove();
            }else if(delFlag.val() == "0"){
                delFlag.val("1");
                $(obj).html("&divide;").attr("title", "撤回删除");
                $(obj).parent().parent().addClass("error");
                $(obj).parent().parent().addClass("hide");
            }else if(delFlag.val() == "1"){
                delFlag.val("0");
                $(obj).parent().parent().removeClass("error");
            }
            getCurrentDocumentHei(othis);
        }
        function isNumber(val){
            if(val === "" || val ==null){
                return false;
            }
            var regPos = /^\d+(\.\d+)?$/; //非负浮点数
            var regNeg = /^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$/; //负浮点数
            if(regPos.test(val) || regNeg.test(val)){
                return true;
            }else{
                return false;
            }

        }
        function getCurrentDocumentHei(obj){
            var height = $(document).outerHeight();
            if(height < 410){
                height = height + 350;
            }
            var hei = 0;
            if(obj){
                hei = $(obj).find("tr").eq(0).height() || 0;
            }
            parent.$("#controltype").attr("height",(height - hei) +"px")
        }
	</script>
</head>
<body class="hideScroll">
		<form:form id="inputForm" modelAttribute="workHandBill" action="${ctx}/workhandbill/workHandBill/save" method="post" class="">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>
		<input type="hidden" name="projectId" id="projectId">
		<table class="table table-bordered  table-condensed dataTables-example dataTable no-footer">
		   <tbody>
				<tr>
					<td class="width-15 active"><label class="pull-right"><font style="color: red">*</font>接收人：</label></td>
					<td class="width-35">
						<sys:treeselect id="billRecUser" name="billRecUser.id" value="${workHandBill.billRecUser.id}" labelName="billRecUser.name" labelValue="${workHandBill.billRecUser.name}"
							title="用户" url="/sys/office/treeData?type=3" cssClass="form-control required" allowClear="true" notAllowSelectParent="true"/>
					</td>
					<td class="width-15 active"><label class="pull-right"><font style="color: red">*</font>送达人：</label></td>
					<td class="width-35">
						<sys:treeselect id="billSendUser" name="billSendUser.id" value="${workHandBill.billSendUser.id}" labelName="billSendUser.name" labelValue="${workHandBill.billSendUser.name}"
										title="用户" url="/sys/office/treeData?type=3" cssClass="form-control required" allowClear="true" notAllowSelectParent="true"/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right"><font style="color: red">*</font>交接时间：</label></td>
					<td class="width-35">
						<input id="billHandTime" name="billHandTime" class="laydate-icon form-control layer-date required" style="min-width:100%;" onclick="laydate({istime: false,format: 'YYYY-MM-DD'})"
							value="<fmt:formatDate value="${workHandBill.billHandTime}" pattern="yyyy-MM-dd HH:mm:ss"/>"/>
					</td>
				</tr>
		 	</tbody>
		</table>
		<a class="btn btn-white btn-sm addBtn" onclick="addRow('#workHandBills', workHandBillsRowIdx, workHandBillsTpl);workHandBillsRowIdx = workHandBillsRowIdx + 1;" title="新增"><i class="fa fa-plus"></i> 新增</a>
		<table id="contentTable2" class="table table-striped table-bordered table-condensed">
			<thead>
			<tr>
				<th><font color="red">*</font>序号</th>
				<th><font color="red">*</font>资料名称</th>
				<th><font color="red">*</font>有无</th>
				<th><font color="red">*</font>份数或页数</th>
				<th>备注</th>
				<th width="150px">操作</th>
			</tr>
			</thead>
			<tbody id="workHandBills">
			<c:if test="${not empty workHandBill.workHandBillDetailList}">
				<c:forEach items="${workHandBill.workHandBillDetailList}" var="workHandBill" varStatus="index">
					<tr id="workHandBillDetailList${index.index}">
						<td class="hide">
							<input id="workHandBillDetailList${index.index}_id" name="workHandBillDetailList[${index.index}].id" type="hidden" value="${workHandBill.id}"/>
							<input id="workHandBillDetailList${index.index}_delFlag" name="workHandBillDetailList[${index.index}].delFlag" type="hidden" value="0"/>
						</td>
						<td>
							<input id="workHandBillDetailList${index.index}_materialNumber"  name="workHandBillDetailList[${index.index}].materialNumber" type="text" value="${workHandBill.materialNumber}"    class="form-control required"/>
						</td>

						<td>
							<input id="workHandBillDetailList${index.index}_materialName" name="workHandBillDetailList[${index.index}].materialName" type="text" value="${workHandBill.materialName}"    class="form-control required"/>
						</td>
						<td>
							<input id="workHandBillDetailList${index.index}_materialFlag" name="workHandBillDetailList[${index.index}].materialFlag" type="text" value="${workHandBill.materialFlag}"    class="form-control required"/>
						</td>
						<td>
							<input id="workHandBillDetailList${index.index}_materialPages" name="workHandBillDetailList[${index.index}].materialPages" type="text" value="${workHandBill.materialPages}"    class="form-control required"/>
						</td>
						<td>
							<input id="workHandBillDetailList${index.index}_remarks" name="workHandBillDetailList[${index.index}].remarks" type="text" value="${workHandBill.remarks}"    class="form-control number required"/>
						</td>
						<td class="text-center" style="width:80px;">
							<span class="btn btn-danger btn-xs" onclick="delRow(this, '#workHandBillDetailList${index.index}','#workHandBills')" title="删除"><i class="fa fa-trash"></i> 删除</span>
						</td>
					</tr>
				</c:forEach>
			</c:if>
			</tbody>
		</table>
		<script type="text/template" id="workHandBillsTpl">//<!--
		<tr id="workHandBillDetailList{{idx}}">
			<td class="hide">
				<input id="workHandBillDetailList{{idx}}_id" name="workDeviceRecordList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
				<input id="workHandBillDetailList{{idx}}_delFlag" name="workDeviceRecordList[{{idx}}].delFlag" type="hidden" value="0"/>
			</td>
			<td>
				<input id="workHandBillDetailList{{idx}}_materialNumber"  name="workHandBillDetailList[{{idx}}].materialNumber" type="text" value="{{row.materialNumber}}"    class="form-control required"/>
			</td>
			<td>
				<input id="workHandBillDetailList{{idx}}_materialName"  name="workHandBillDetailList[{{idx}}].materialName" type="text" value="{{row.materialName}}"    class="form-control required"/>
			</td>
			<td>
				<input id="workHandBillDetailList{{idx}}_materialFlag" name="workHandBillDetailList[{{idx}}].materialFlag" type="text" value="{{row.materialFlag}}"    class="form-control required"/>
			</td>
			<td>
				<input id="workHandBillDetailList{{idx}}_materialPages" name="workHandBillDetailList[{{idx}}].materialPages" type="text" value="{{row.materialPages}}"    class="form-control required"/>
			</td>
			<td>
				<input id="workHandBillDetailList{{idx}}_remarks" name="workHandBillDetailList[{{idx}}].remarks" type="text" value="{{row.remarks}}"    class="form-control required"/>
			</td>

			<td class="text-center" style="width:80px;">
				{{#delBtn}}<span class="btn btn-danger btn-xs" onclick="delRow(this, '#workHandBillDetailList{{idx}}','#workHandBills')" title="删除"><i class="fa fa-trash"></i> 删除</span>{{/delBtn}}
			</td>
		</tr>//-->
		</script>
		<script type="text/javascript">
			var workHandBillsRowIdx = 0, workHandBillsTpl = $("#workHandBillsTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
			if($("#id").val()){
                workHandBillsRowIdx = ${fn:length(workHandBill.workHandBillDetailList)};
			}
		</script>
	</form:form>
</body>
</html>