<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>私塾家</title>
<script th:include="sys/common/metaCSS" th:remove="tag"></script> 
<script th:include="sys/common/metaJS" th:remove="tag"></script>
	<link th:href="@{/static/js/select/fselect.css}" rel="stylesheet" type="text/css">
<script src="sys/js/jquery.validate.min.js" th:src="@{/static/sys/js/jquery.validate.min.js}"></script>
<script src="sys/js/jquery-validation/messages_zh.js" th:src="@{/static/sys/js/jquery-validation/messages_zh.js}"></script>
<script src="sys/js/My97DatePicker/WdatePicker.js" th:src="@{/static/sys/js/My97DatePicker/WdatePicker.js}"></script>
	<script src="sys/js/select/fSelect.js" th:src="@{/static/js/select/fselect.js}"></script>


	<style>
		body {
			min-width: 180px;
		}

		.select1 {
			width: 100%;
			height: 32px;
			line-height: 32px;
			border-top: solid 1px #a7b5bc;
			border-left: solid 1px #a7b5bc;
			border-right: solid 1px #ced9df;
			border-bottom: solid 1px #ced9df;
			opacity: 1;
			margin-bottom: 10px;
		}

		.btn {
			width: 100px;
		}

		label.control-label-error {
			color: Red;
		}

		.forminfo li label {
			width: 85px;
			line-height: 34px;
			display: block;
			float: left;
		}
	</style>
</head>

<body>
<div class="formbody">
	<form id="submitFrom"   method="post" class="form-horizontal form-validate">
		     <input type="hidden" name="id" id="id" th:if="${materiel.id}"  th:value="${materiel.id}"/>
		     <input type="hidden" name="materielFlow" id="materielFlow" th:if="${materiel.materielFlow}"  th:value="${materiel.materielFlow}"/>

		<input type="hidden" name="price"  th:if="${isManager==0}"  th:value="${materiel.price}"/>
		<input type="hidden" name="totalSum"  th:if="${isManager==0}"  th:value="${materiel.totalSum}"/>

		<ul class="forminfo">
			<li class="clearfix" id="clearfix">
				<label>物料名称：<b>*</b></label>
				<div class="vocation" style="margin-right: 5px; width: 300px">
					<select class="select1" name="materielName" id="materielName">
						<option>请选择</option>
						<option  th:each="sort:${materielList}"  th:value="${sort.name}" th:code="${sort.code}" th:selected="${ sort.name eq materiel.materielName }" th:text="${sort.name}" ></option>
					</select>
				</div>

			</li>
			<li class="clearfix" id="clearfix">
				<label>物料编码：<b>*</b></label>
				<input type="text"  disabled="disabled" id="materieCode" class="dfinput fl" th:value="${materiel.materieCode}"/>
				<input type="hidden" name="materieCode" id="hidmaterieCode" th:value="${materiel.materieCode}"/>
		   </li>

			<li class="clearfix" id="clearfix">
				<label>供应商：<b>*</b></label>
				<div class="vocation" style="margin-right: 5px; width: 300px">
					<select class="select1" name="supplier" id="supplier">
						<option>请选择</option>
						<option  th:each="sort:${materielSale}"  th:value="${sort.name}" th:code="${sort.code}" th:selected="${ sort.name eq materiel.supplier }" th:text="${sort.name}" ></option>
					</select>
				</div>
			</li>
			<li class="clearfix" id="clearfix">
				<label>供应商编码：<b>*</b></label>
				<input type="text"  disabled="disabled" id="supplierCode" class="dfinput fl" th:value="${materiel.supplierCode}"/>
				<input type="hidden" name="supplierCode" id="hidsupplierCode" th:value="${materiel.supplierCode}"/>
			</li>
			<li class="clearfix" id="clearfix" th:if="${isManager==1}">
				<label>单价：<b>*</b></label>
				<input type="text" name="price" id="price" class="dfinput fl" th:value="${materiel.price}"/>
			</li>
			<li class="clearfix" id="clearfix">
				<label>入库数量：<b>*</b></label>
				<input type="text" name="inCount" class="dfinput fl" id="inCount" th:value="${materiel.inCount}"/>
			</li>
			<li class="clearfix" id="clearfix" th:if="${isManager==1}">
				<label>总价：<b>*</b></label>
				<input type="text"  disabled="disabled" class="dfinput fl" id="totalSum" th:value="${materiel.totalSum}"/>
				<input type="hidden" name="totalSum" id="hidtotalSum" th:value="${materiel.totalSum}"/>
			</li>
			<li class="clearfix" id="clearfix">
				<label>备注：<b>*</b></label>
				<input type="text" name="remark" class="dfinput fl" id="remark" th:value="${materiel.remark}"/>
			</li>
				<input type="hidden" name="userdCount" class="dfinput fl" id="userdCount" th:value="${materiel.userdCount}"/>
			<li>
				<label>&nbsp;</label>
				<button type="submit" class="btn">保存</button>
				<button type="button" class="btn" onclick="closeWin();">取消</button>
			</li>
		</ul>
	</form>
</div>
</body>
<script type="text/javascript">

$(function(){
	$('#materielName').on('change',function(){
//判断是否选取prompt属性，无返回值；
		if($(this).val()){
			var selectText = $(this).find('option:selected').attr("code");
			if(selectText){}
			$('#materieCode').val(selectText);
			$('#hidmaterieCode').val(selectText);
		}else{
			$('#materieCode').val('');
			$('#hidmaterieCode').val('');
		}
	});

	$('#supplier').on('change',function(){
//判断是否选取prompt属性，无返回值；
		if($(this).val()){
			var selectText = $(this).find('option:selected').attr("code");
			$('#supplierCode').val(selectText);
			$('#hidsupplierCode').val(selectText);
		}else{
			$('#supplierCode').val('');
			$('#hidsupplierCode').val('');
		}
	});


	$('#price').on('change',function(){
//判断是否选取prompt属性，无返回值；
		if($(this).val()){
			var selectText = $("#inCount").val();
			if(selectText){
				$('#totalSum').val($(this).val() * selectText * 1);
				$('#hidtotalSum').val($(this).val() * selectText * 1);
			}

		}
	});

	$('#inCount').on('change',function(){
//判断是否选取prompt属性，无返回值；
		if($(this).val()){
			var selectText = $("#price").val();
			if(selectText){
				$('#totalSum').val($(this).val() * selectText * 1);
				$('#hidtotalSum').val($(this).val() * selectText * 1);
			}

		}
	});

	$("#submitFrom").validate({
		rules : {

			materielName : {
				required : true
			},
			supplier : {
				required : true
			},
			inCount : {
				required : true
			}
		},
		messages: {
			materielName : {
				required : '物料名称不能为空'
			},
			supplier : {
				required : '供应商名称不能为空'
			},
			inCount : {
				required: '入库数量不能为空'
			}
			
		},
		errorPlacement : function(error, element) {
				error.appendTo(element.parent()); 
		},
		submitHandler : function(form) {
			roleFrom();
		}
	});
});
function roleFrom(){
	var url="[[${sysUrl}]]/sys/bookList/saveMaterie";
	var params = $("#submitFrom").serialize();
	$.post(url,params,function(data){
		if(data != null){
				if(data.code='999'){
					layer.msg("新增成功",{icon:1});
					setTimeout(function(){
						window.location.href ='[[${sysUrl}]]/sys/bookList/materielList.html';
					},1000);
				}else{
					layer.msg(data.meta.message,{icon:11});
				}
		}
		
	});
}
function closeWin() {
	window.location.href ='[[${sysUrl}]]/sys/bookList/materielList.html';
}


</script>
</html>