<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="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="price" th:if="${info.price}" th:value="${info.price}"/>
		     <input type="hidden" name="publisher" th:if="${info.publisher}" th:value="${info.publisher}"/>
		     <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>
				<input type="text" id="author" class="dfinput fl" name="author"  th:value="${info.author}"/>
			</li>
			<li class="clearfix">
				<label>图书ISBN码:<b>*</b></label>
				<input type="text" id="isbnshow" class="dfinput fl" name="isbnshow"  th:value="${info.isbnshow}"/>
				<input type="hidden" name="isbn13" id="hidisbn13" th:value="${info.isbn13}">
			</li>
			<li class="clearfix">
				<label class="fl">是否丛书:</label>
				<div th:remove="tag">
				<label class="fl" style="width: 70px;"><input type="checkbox" name="csbox" onchange="javascript:haha(this)" id="csbox">是否丛书</label>
				</div>
			</li>
			<li class="clearfix" id="csli" style="display:none">
				<label>丛书编号:</label>
				<div class="vocation" style="margin-right: 5px; width: 200px">
				<select id= "csselect1" class="select1" >
					<option value="1" th:selected="${ info.csisbnshow eq '1' }">1</option>
					<option value="2" th:selected="${ info.csisbnshow eq '2' }">2</option>
					<option value="3" th:selected="${ info.csisbnshow eq '3' }">3</option>
					<option value="4" th:selected="${ info.csisbnshow eq '4' }">4</option>
					<option value="5" th:selected="${ info.csisbnshow eq '5' }">5</option>
					<option value="6" th:selected="${ info.csisbnshow eq '6' }">6</option>
					<option value="7" th:selected="${ info.csisbnshow eq '7' }">7</option>
					<option value="8" th:selected="${ info.csisbnshow eq '8' }">8</option>
					<option value="9" th:selected="${ info.csisbnshow eq '9' }">9</option>
					<option value="10" th:selected="${ info.csisbnshow eq '10' }">10</option>
					<option value="11" th:selected="${ info.csisbnshow eq '11' }">11</option>
					<option value="12" th:selected="${ info.csisbnshow eq '12' }">12</option>
					<option value="13" th:selected="${ info.csisbnshow eq '13' }">13</option>
					<option value="14" th:selected="${ info.csisbnshow eq '14' }">14</option>
					<option value="15" th:selected="${ info.csisbnshow eq '15' }">15</option>
					<option value="16" th:selected="${ info.csisbnshow eq '16' }">16</option>
					<option value="17" th:selected="${ info.csisbnshow eq '17' }">17</option>
					<option value="18" th:selected="${ info.csisbnshow eq '18' }">18</option>
					<option value="19" th:selected="${ info.csisbnshow eq '19' }">19</option>
					<option value="20" th:selected="${ info.csisbnshow eq '20' }">20</option>
				</select>
				</div>
			</li>
			<input type="hidden" id="csisbn" class="dfinput fl" name="csisbn"  th:value="${info.csisbn}"/>
			<input type="hidden" id="isSerial" class="dfinput fl" name="isSerial"  th:value="${info.isSerial}"/>
		   <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>
				<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>
				<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="keyword" class="dfinput fl" name="keyword"  th:value="${info.keyword}"/>
			</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" class=" fl" cols="80" id="text1">[[${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 iscs = '[[${info.isSerial}]]';
	if(iscs == "2"){
		$("#csbox").attr("checked","checked");
		$("#csli").show();
	}
	
	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
			},
			isbnshow : {
				required : true,
				maxlength: 300
			}
		},
		messages: {
			title : {
				required : "名称不能为空",
				maxlength : "最多300个字符",
			},
			author : {
				required : "作者不能为空",
				maxlength : "最多300个字符",
			},
			isbnshow : {
				required : "ISBN号不能为空",
				maxlength : "最多300个字符",
			}
			
		},
		errorPlacement : function(error, element) {
				error.appendTo(element.parent()); 
		},
		submitHandler : function(form) {
			roleFrom();
		}
	});
	
});
function haha(obj){
	if($(obj).prop("checked")){
	//选中操作
		 $("#isSerial").val("2");  
	      $("#csli").show();
	}else{
	//取消选中操作
		$("#isSerial").val("1");  
   	 	$("#csli").hide();
	}
}
function selcsisbn(opvalue){
	
}
function roleFrom(){
/* 	var imgs = $("#localImage").val();
	if(imgs == ""){
		alert("请上传书籍封面！");
		return ;
	} */
	// 先处理isbn号
	var isSerial = $("#isSerial").val();
	if(isSerial == "2"){ //丛书
		//this.options[this.options.selectedIndex].value
		var options=$("#csselect1 option:selected"); 
		$("#hidisbn13").val($("#isbnshow").val()+""+options.val()); //
		$("#csisbn").val($("#isbnshow").val());
	}else{ //非丛书
		$("#hidisbn13").val($("#isbnshow").val()); //
		$("#csisbn").val("");
	}
	
	var url="[[${sysUrl}]]/sys/lib/libBookBaseSave";
	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/libBookBaseList.html';
					},1000);
				}else{
					layer.msg(data.meta.message,{icon:11});
				}
		}
		
	});
}


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

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

</script>
</html>