<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> 
<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>
 <style>
    	.clearfix:after {
			visibility: hidden;
			display: block;
			font-size: 0;
			content: " ";
			clear: both;
			height: 0;
		}
		.clearfix { display: inline-table; }
		* html .clearfix { height: 1%; }
		.clearfix { display: block; }
		.fl{display:inline;float:left}
		clearfix >control-label-error{display:inline;float:left;marign-left:10px}
		 label.control-label-error {
  				color: Red;
             }
          .lispan {line-height: 34px;}   
          
          .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;
    	}
    </style>
</head>

<body>
<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    	<li><a href="#">图书馆管理</a></li>
    	<li><a href="#">新增卡券</a></li>
    </ul>
</div>
<div class="formbody">
	<form id="submitFrom"   method="post" class="form-horizontal form-validate">
			 
		<ul class="forminfo">
			<li class="clearfix">
			    <label>卡券类型：<b>*</b></label>
				<div class="vocation" style="margin-right: 5px; width: 179px">
					<select class="select1" name="cardType">
					   		 <option value="CASH"  >现金券</option>
					   		 <option value="MEMBER_CARD">会员卡</option>
					</select>
				</div>
		   </li>
		   <li>
				<label>现金券起用金额(单位分):<b>*</b></label>
				<input type="text" name="leastCost" class="dfinput fl"  id="leastCost" >
			</li>
			<li>
				<label>现金券减免金额(单位分):<b>*</b></label>
				<input type="text" name="reduceCost" class="dfinput fl"  id="reduceCost" >
			</li>
			<li>
				<label>库存:<b>*</b></label>
				<input type="text" name="cardStore" class="dfinput fl"  id="cardStore" >
			</li>
		   <li>
			    <input type="hidden" name="logoUrl" id="logoUrl" />
				<label class="upload-file">卡券logo<b>*</b></label>
				<img id="imgUrlImg" src=""  style="width:200px;height:140px; margin-left: 109px;" />
				<input type="file" id="upfile">
			</li>
			<li>
			    <input type="hidden" name="backgroundPicUrl" id="backgroundPicUrl" />
				<label class="upload-file">会员卡背景<b>*</b></label>
				<img id="imgUrlImg2" src=""  style="width:200px;height:140px; margin-left: 109px;" />
				<input type="file" id="upfile2">
			</li>
			<li>
				<label>&nbsp;</label>
				<button type="submit" class="btn">保存</button>
				<button type="button" class="btn" onclick="window.history.go(-1);">取消</button>
			</li>
		</ul>
	</form>
</div>
</body>
<script th:include="sys/common/fileUpload" th:remove="tag"></script> 
<script type="text/javascript">

$(function(){
	$("#submitFrom").validate({
		ignore:"",
		rules : {
			logoUrl : {
				required : true
			},
			cardStore :{
				required : true
			}
		},
		messages: {
			logoUrl : {
				required : "logo图片不能为空"
			},
			cardStore :{
				required : "库存不能为空"
			}
			
		},
		errorPlacement : function(error, element) {
				error.appendTo(element.parent()); 
		},
		submitHandler : function(form) {
			roleFrom();
		}
	});
	
});
function roleFrom(){
	var url="[[${sysUrl}]]/sys/wxcard/saveCardInfo";
	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/wxcard/wxcardList.html';
					},1000);
				}else{
					layer.msg(data.msg,{icon:11});
				}
		}
		
	});
}

$(function(){
	initUpload(uploadOptions("upfile","上传图片"),"logoUrl","imgUrlImg");
	initUpload(uploadOptions("upfile2","上传图片"),"backgroundPicUrl","imgUrlImg2");
});

//附件上传
function uploadFile(){
	$("#upfile").uploadify("upload", "*");
	$("#upfile2").uploadify("upload", "*");
}



</script>
</html>