<%@ 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;
        var count = 0;
		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 = $("#workDeviceRecords tr").length;
            if(list == '#workDeviceRecords'){
                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="workDeviceXjRecord" action="${ctx}/workdevicerecord/workDeviceXjRecord/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>
		<input type="hidden" name="projectId" id="projectId">
		<a class="btn btn-white btn-sm addBtn" onclick="addRow('#workDeviceRecords', workDeviceRecordsRowIdx, workDeviceRecordsTpl);workDeviceRecordsRowIdx = workDeviceRecordsRowIdx + 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><font color="red">*</font>联系电话</th>
				<th><font color="red">*</font>单价（元）</th>
				<th>备注</th>
				<th width="150px">操作</th>
			</tr>
			</thead>
			<tbody id="workDeviceRecords">
			<c:if test="${not empty workDeviceXjRecord.workDeviceRecordList}">
				<c:forEach items="${workDeviceXjRecord.workDeviceRecordList}" var="workDeviceRecord" varStatus="index">
					<tr id="workDeviceRecordList${index.index}">
						<td class="hide">
							<input id="workDeviceRecordList${index.index}_id" name="workDeviceRecordList[${index.index}].id" type="hidden" value="${workDeviceRecord.id}"/>
							<input id="workDeviceRecordList${index.index}_delFlag" name="workDeviceRecordList[${index.index}].delFlag" type="hidden" value="0"/>
						</td>
						<td>
							<input id="workDeviceRecordList${index.index}_deviceName"  name="workDeviceRecordList[${index.index}].deviceName" type="text" value="${workDeviceRecord.deviceName}"    class="form-control required"/>
						</td>

						<td>
							<input id="workDeviceRecordList${index.index}_deviceKind" name="workDeviceRecordList[${index.index}].deviceKind" type="text" value="${workDeviceRecord.deviceKind}"    class="form-control required"/>
						</td>
						<td>
							<input id="workDeviceRecordList${index.index}_deviceUnit" name="workDeviceRecordList[${index.index}].deviceUnit" type="text" value="${workDeviceRecord.deviceUnit}"    class="form-control required"/>
						</td>
						<td>
							<input id="workDeviceRecordList${index.index}_deviceCreator" name="workDeviceRecordList[${index.index}].deviceCreator" type="text" value="${workDeviceRecord.deviceCreator}"    class="form-control required"/>
						</td>
						<td>
							<input id="workDeviceRecordList${index.index}_devicePhone" name="workDeviceRecordList[${index.index}].devicePhone" type="text" value="${workDeviceRecord.devicePhone}"    class="form-control isTel required"/>
						</td>
						<td>
							<input id="workDeviceRecordList${index.index}_devicePrice" name="workDeviceRecordList[${index.index}].devicePrice" type="text" value="${workDeviceRecord.devicePrice}"    class="form-control number required"/>
						</td>
						<td>
							<input id="workDeviceRecordList${index.index}_remarks" name="workDeviceRecordList[${index.index}].remarks" type="text" value="${workDeviceRecord.remarks}"    class="form-control required"/>
						</td>
						<td class="text-center" style="width:80px;">
							<button class="btn btn-danger btn-xs" onclick="delRow(this, '#workDeviceRecordList${index.index}','#workDeviceRecords')" title="删除"><i class="fa fa-trash"></i> 删除</button>
						</td>
					</tr>
				</c:forEach>
			</c:if>
			</tbody>
		</table>
		<script type="text/template" id="workDeviceRecordsTpl">//<!--
			<tr id="workDeviceRecordList{{idx}}">
				<td class="hide">
					<input id="workDeviceRecordList{{idx}}_id" name="workDeviceRecordList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
					<input id="workDeviceRecordList{{idx}}_delFlag" name="workDeviceRecordList[{{idx}}].delFlag" type="hidden" value="0"/>
				</td>
				<td>
					<input id="workDeviceRecordList{{idx}}_deviceName"  name="workDeviceRecordList[{{idx}}].deviceName" type="text" value="{{row.deviceName}}"    class="form-control required"/>
				</td>
				<td>
					<input id="workDeviceRecordList{{idx}}_deviceKind"  name="workDeviceRecordList[{{idx}}].deviceKind" type="text" value="{{row.deviceKind}}"    class="form-control required"/>
				</td>
				<td>
					<input id="workDeviceRecordList{{idx}}_deviceUnit" name="workDeviceRecordList[{{idx}}].deviceUnit" type="text" value="{{row.deviceUnit}}"    class="form-control required"/>
				</td>
				<td>
					<input id="workDeviceRecordList{{idx}}_deviceCreator" name="workDeviceRecordList[{{idx}}].deviceCreator" type="text" value="{{row.deviceCreator}}"    class="form-control required"/>
				</td>
				<td>
					<input id="workDeviceRecordList{{idx}}_devicePhone" name="workDeviceRecordList[{{idx}}].devicePhone" type="text" value="{{row.devicePhone}}"    class="form-control isTel required"/>
				</td>
				<td>
					<input id="workDeviceRecordList{{idx}}_devicePrice" name="workDeviceRecordList[{{idx}}].devicePrice" type="text" value="{{row.devicePrice}}"    class="form-control number required"/>
				</td>
				<td>
					<input id="workDeviceRecordList{{idx}}_remarks" name="workDeviceRecordList[{{idx}}].remarks" type="text" value="{{row.remarks}}"    class="form-control required"/>
				</td>

				<td class="text-center" style="width:80px;">
					{{#delBtn}}<button class="btn btn-danger btn-xs" onclick="delRow(this, '#workDeviceRecordList{{idx}}','#workDeviceRecords')" title="删除"><i class="fa fa-trash"></i> 删除</button>{{/delBtn}}
				</td>
			</tr>//-->
		</script>
		<script type="text/javascript">
			var workDeviceRecordsRowIdx = 0, workDeviceRecordsTpl = $("#workDeviceRecordsTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
			if($("#id").val()){
                workDeviceRecordsRowIdx = ${fn:length(workDeviceXjRecord.workDeviceRecordList)};
			}
		</script>
		<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">
						<input id="askTime" name="askTime"  class="form-control layer-date laydate-icon required" style="min-width:100%;" onclick="laydate({istime: false,format: 'YYYY-MM-DD'})"
							value="<fmt:formatDate value="${workDeviceXjRecord.askTime}" pattern="yyyy-MM-dd" />"/>
					</td>
					<td class="width-15 active"><label class="pull-right"><font style="color: red">*</font>询价人员：</label></td>
					<td class="width-35">
						<sys:treeselect id="askUser" name="askUser.id" value="${workDeviceXjRecord.askUser.id}" labelName="askUser.name" labelValue="${workDeviceXjRecord.askUser.name}"
										title="用户" url="/sys/office/treeData?type=3" cssClass="form-control required" allowClear="true" notAllowSelectParent="true"/>
					</td>
				</tr>
		 	</tbody>
		</table>
	</form:form>
</body>
</html>
