<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 th:href="@{/sys/lib/libBookInfoList.html}">图书列表</a></li>
	</ul>
</div>
<div class="formbody">
	<div class="formtitle"><span th:text="${info.id} ? '修改图书' :'新增图书'">新增图书</span></div>
	<form id="submitFrom"   method="post" class="form-horizontal form-validate">
		     <input type="hidden" name="id" th:if="${info.id}" th:value="${info.id}"/>
		     <input type="hidden" name="authorIntro" th:if="${info.authorIntro}" th:value="${info.authorIntro}"/>
		     <input type="hidden" name="summary" id="summary"  />
		     <input type="hidden" name="publisher" th:if="${info.publisher}" th:value="${info.publisher}"/>
		     <input type="hidden" name="isbn10" th:if="${info.isbn10}" th:value="${info.isbn10}"/>
		     <input type="hidden" name="doubanImage" th:if="${info.doubanImage}" th:value="${info.doubanImage}"/>
		     <input type="hidden" name="pubdate" th:if="${info.pubdate}" th:value="${info.pubdate}"/>
		     <input type="hidden" name="pages" th:if="${info.pages}" th:value="${info.pages}"/>
		     <input type="hidden" name="catalog" th:if="${info.catalog}" th:value="${info.catalog}"/>
		     <input type="hidden" name="bookStock" th:if="${info.bookStock}" th:value="${info.bookStock}"/>
		     <input type="hidden" name="libId" id="libId" th:value="${info.libId}"/>
		     
		     <input type="hidden" name="bookGr"  th:value="${info.bookGr}"/>
		     <input type="hidden" name="keywordFeel"  th:value="${info.keywordFeel}"/>
		     <input type="hidden" name="parentTheme"  th:value="${info.parentTheme}"/>
		     <input type="hidden" name="childTheme"  th:value="${info.childTheme}"/>
		     <input type="hidden" name="grade"  th:value="${info.grade}"/>
		     <input type="hidden" name="section"  th:value="${info.section}"/>
		<ul class="forminfo">
			<li class="clearfix">
				<label>图书名称:<b>*</b></label>
				<input type="text" id="title" class="dfinput fl" name="title"  th:value="${info.title}"/>
			</li>
			 <li class="clearfix">
			    <label>图书馆：<b>*</b></label>
				<div class="vocation" style="margin-right: 5px; width: 346px">
					<select class="select1" name="orgCode" id="orgCode">
					   		 <option th:each="sort:${libList}" th:data-id="${sort.id}" th:selected="${ info.orgCode eq sort.orgCode }"  th:value="${sort.orgCode}">[[${sort.leagueName}]]</option>
					</select>
				</div>
		   </li>
			<li class="clearfix">
				<label>作者:<b>*</b></label>
				<input type="text" id="author" class="dfinput fl" name="author"  th:value="${info.author}"/>
			</li>
			<li class="clearfix">
				<label>价格:<b>*</b></label>
				<input type="text" id="price" class="dfinput fl" name="price"  th:value="${info.price}"/>
			</li>
			<li class="clearfix" th:if="${info.id == null}">
				<label>数量:<b>*</b></label>
				<input type="number" id="num" class="dfinput fl" name="num"  value="1"/>
			</li>
			<li class="clearfix">
				<label>ISBN13:<b>*</b></label>
				<input type="number" id="isbn13" class="dfinput fl" name="isbn13"  th:value="${info.isbn13}"/>
			</li>
		   <li class="clearfix">
			    <label>书籍分类：<b>*</b></label>
				<div class="vocation" style="margin-right: 5px; width: 346px">
					<select class="select1" name="bookTag">
					   		 <option th:each="sort:${book_tags}" th:selected="${ info.bookTag eq sort.code }"  th:value="${sort.code}">[[${sort.name}]]</option>
					</select>
				</div>
		   </li>
		   <li class="clearfix">
			    <label>编码分类：<b>*</b></label>
				<div class="vocation" style="margin-right: 5px; width: 346px">
					<select class="select1" name="bookcase">
					   		 <option th:each="sort:${book_case}" th:selected="${ info.bookcase eq sort.code }"  th:value="${sort.code}">[[${sort.name}]]</option>
					</select>
				</div>
		   </li>
		   <li class="clearfix">
				<label>起始年龄:<b>*</b></label>
				<input type="text" id="startAge" class="dfinput fl" name="startAge"  th:value="${info.startAge}"/>
			</li>
			<li class="clearfix">
				<label>结束年龄:<b>*</b></label>
				<input type="text" id="endAge" class="dfinput fl" name="endAge"  th:value="${info.endAge}"/>
			</li>
			<li class="clearfix">
				<label>关键字:<b>*</b></label>
				<input type="text" id="keyword" class="dfinput fl" name="keyword"  th:value="${info.keyword}"/>
			</li>
		   <li class="clearfix">
			    <label>状态：<b>*</b></label>
				<div class="vocation" style="margin-right: 5px; width: 346px">
					<select class="select1" name="type">
					   		 <option value="1"  th:selected="${ info.type eq '1' }" >上架</option>
					   		 <option value="2" th:selected="${ info.type eq '2' }">下架</option>
					</select>
				</div>
		   </li>
			<li>
			    <input type="hidden" name="localImage" id="localImage" th:value="${info.localImage}"/>
				<label class="upload-file">头像<b>*</b></label>
				<img id="localImageImg" th:src=" ${info.localImage} !=null  ? (${info.localImage} !='' ? ${imgUrl}+''+${info.localImage}+'?x-oss-process=image/resize,m_lfit,h_100,w_120' : '' ) :'' "  style="width:200px;height:140px; margin-left: 109px;" />
				<input type="file" id="upfile">
			</li>
			<li class="clearfix">
				<label>简介:</label>
				<textarea rows="10" cols="80" id="text1" class="textinput">[[${info.summary}]]</textarea>
			</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(){
	
	var bookTag = '[[${info.bookTag}]]';
	if(bookTag!=''){
		var arr=bookTag.split(',');
		
		for(var j=0;j<arr.length;j++){
		 $.each($("#clear").find('input[type=checkbox]'),function(i, v){
				if(arr[j]==$(v).val()){
					$(v).attr("checked", true);
					return 	false;
				}
			});
		}
		
	}
	
	$("#submitFrom").validate({
		rules : {
			
			title : {
				required : true,
				maxlength: 300
			},
			author : {
				required : true,
				maxlength: 300
			},
			isbn13 : {
				required : true,
				maxlength: 300
			}
		},
		messages: {
			title : {
				required : "名称不能为空",
				maxlength : "最多300个字符",
			},
			author : {
				required : "CODE不能为空",
				maxlength : "最多300个字符",
			},
			isbn13 : {
				required : "ISBN号不能为空",
				maxlength : "最多300个字符",
			}
			
		},
		errorPlacement : function(error, element) {
				error.appendTo(element.parent()); 
		},
		submitHandler : function(form) {
			roleFrom();
		}
	});
	
});
function roleFrom(){
	$('#libId').val($("#orgCode").find("option:selected").attr('data-id'));
	var url="[[${sysUrl}]]/sys/lib/libBookInfoSave";
	var text1 = $("#text1").val();
	$("#summary").val(text1);
	var params = $("#submitFrom").serialize();
	$.post(url,params,function(data){
		if(data != null){
				if(data.meta.success){
					layer.msg("操作成功!",{icon:1});
			    	setTimeout(function(){
			    		window.location.href ='[[${sysUrl}]]/sys/lib/libBookInfoList.html';
					},1000);
				}else{
					layer.msg(data.meta.message,{icon:11});
				}
		}
		
	});
}


$(function(){
	initUpload(uploadOptions("upfile","上传封面"),"localImage","localImageImg");
});

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

</script>
</html>