<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/My97DatePicker/WdatePicker.js" th:src="@{/static/sys/js/My97DatePicker/WdatePicker.js}"></script>
<script th:include="sys/common/fileUpload" th:remove="tag"></script> 
</head>
<style>
	.tablelink{margin-right:10px;}
	.stylecss{
	      color: red;
	}
	.select_width{
	     width: 220px;
	}
	.date_width{
	     width: 83px;
	}
	.uploadify {
    left: 1px;
   }
</style>
<body>
<div class="place">
	<span>位置：</span>
	<ul class="placeul">
		<li><a href="#">后台系统管理</a></li>
		<li><a href="#">朗读者管理</a></li>
	</ul>
</div>
<div class="rightinfo">
	<form id="seachform" th:action="@{/sys/jxy/jxylist.html}" method="post">
	<ul class="seachform">
	<li>
			<label>图书编号</label>
			<input name="LIKE_isbn13" type="text" class="scinput" th:value="${search.get('LIKE_isbn13')}"/>
		</li>
		<li>
			<label>标题</label>
			<input name="LIKE_title" type="text" class="scinput" th:value="${search.get('LIKE_title')}"/>
		</li>
		<li>
			<label>&nbsp;</label>
			<input type="button" class="scbtn" value="查询" />
		</li>
		<li>
		     <ul class="toolbar">
					<a th:href="@{/sys/jxy/addjxy.html}"><li class="click"><span><img th:src="@{/static/sys/images/t01.png}" /></span>添加</li></a>
			   </ul>
		</li>
	</ul>
	</form>
	<table class="tablelist">
		<thead>
		    <tr>
		        <th style=" width: 50px;">序号</th>
		        <th>图书编号</th>
		        <th>图书</th>
		        <th>标题</th>
		      <!--   <th>阅读时长</th>
		        <th>副标题</th> -->
		        <th>创建时间</th>
		        <th>二维码</th>
		        <th>操作</th>
		        <td style=" width: 360px;">
	                	<table class="imgtable">
	                	<thead>
					            <tr>
					                <th>文件</th>
					                <th style="color: red;text-align: center;">排序</th>
					                <th>操作</th>
					            </tr>
					        </thead>
					    </table>
	             </td>
		       
		    </tr>
		</thead>
		<tbody>
			<tr th:each="jxy:${list}" >
				<td th:text="${jxyStat.count}"  th:data-id="${jxy.id}" class="usercount"></td>
				<td th:text="${jxy.isbn13}"></td>
				<td th:title="${jxy.name}" th:text="${jxy.name} ? (${#strings.length(jxy.name)} &gt; 10 ? ${#strings.substring(jxy.name,0,10)} :${jxy.name} ) :'' ">
					</td>
				<td th:title="${jxy.title}" th:text="${jxy.title} ? (${#strings.length(jxy.title)} &gt; 10 ? ${#strings.substring(jxy.title,0,10)} :${jxy.title} ) :'' ">
					</td>
				<!-- <td th:text="${jxy.needTime}"></td>
				<td th:title="${jxy.subTitle}" th:text="${jxy.subTitle} ? (${#strings.length(jxy.subTitle)} &gt; 10 ? ${#strings.substring(jxy.subTitle,0,10)} :${jxy.subTitle} ) :'' ">
					</td> -->
				<td th:text="${#calendars.format(jxy.createTime,'yyyy-MM-dd')}" ></td>
				<td  class="imgtd">
							<img  th:if="${jxy.qrCode}!=null" th:src="${imgUrl}+''+${jxy.qrCode}" style="width: 50px;height: 50px;" />
					</td>
				<td>
				<a href="javascript:;" th:onclick="'deleteById(\''+${jxy.id}+'\')'"  class="tablelink" >删除</a>
					<a th:href="@{/sys/jxy/addjxy.html(id=${jxy.id})}" class="tablelink" >修改</a>	
					<input type="file" th:id="'file'+${jxyStat.count}">
				</td>
				<td style=" width: 360px;">
						<table class="imgtable">
					        <tbody>
					        		<tr th:each="img:${jxy.imglist}" >
										<td  class="imgtd" th:if="${img.fileType eq '1'}">
											<img  th:if="${img.fileUrl}!=null" th:src="${imgUrl}+''+${img.fileUrl}" style="width: 50px;height: 50px;" />
					                    </td>
					                    <td  th:if="${img.fileType eq '2'}" >
					                    <audio  th:if="${img.fileUrl}!=null"  controls="controls" th:src="${imgUrl}+''+${img.fileUrl}"style="width: 130px"></audio>
					                     </td>
					                       <td style="text-align: center;" >
											 <input type="number" th:value="${img.imgIndex}" th:onBlur="'updatePrice(\''+${img.id}+'\',\''+${img.imgIndex}+'\',this)'"  class="dfinput" style="width: 60px; height: 30px;color: red;"  >
											</td>
					                    <td>
					                      <a href="javascript:;" th:onclick="'deleteByIdwj(\''+${img.id}+'\')'"  class="tablelink" >删除</a>
					                    </td>
									</tr>
					        </tbody>
					  	</table>
					</td>
				
			</tr> 
		</tbody>
	</table>
	<!-- 分页 -->
	<div class="pagin">
    	<div class="message">共<i class="blue">[[${page.rowCnt}]]</i>条记录，当前显示第&nbsp;<i class="blue">[[${page.pageNo }]]&nbsp;</i>页</div>
    	<div th:utext='${listNavigatHtml}' th:remove="tag" ></div>
   	</div>
</div>

<script type="text/javascript">



function updatePrice(id,oldPrice,_this){
	var price = $(_this).val();
	if(price == oldPrice){
		return false;
	}
	if(price ==''|| price ==null){
		return false;
	}
	$(_this).removeAttr("onBlur");
	$.ajax({
		url : "[[${sysUrl}]]/sys/jxy/updateImgIndex",
		type : "post",
		data : {
			id : id,
			price : price
		},
		dataType : "json",
		success : function(data) {
			if(data.meta.success){
				 parent.layer.msg('操作成功',{icon:1});
				 $(_this).attr("onBlur","updatePrice("+id+","+price+",this)");
			}else{
				parent.layer.msg('操作失败',{icon: 9})
				$(_this).attr("onBlur","updatePrice("+id+","+oldPrice+",this)");
			}
		}
	});
}



function uploadOptions(buttonId,buttonText,leadyId){
	var uploads = {
			buttonId: buttonId, //上传按钮ID
			buttonText: buttonText, //上传按钮文本
			auto: true, //是否自动上传
			queueID: "upload_file_view", //文件选择后的容器ID
			uploader: "[[${sysUrl}]]/sys/jxy/uploads?leadyId="+leadyId, //上传处理URL
			fileTypeExts: "*.jpg;*.png;*.jpeg;*.gif;*.mp3", //允许上传的文件后缀
			fileSizeLimit: '5000000KB', //上传文件的大小限制
			queueSizeLimit: 2 //上传数量
		};
	return uploads;
}
//控件初始化    
/**
 *  id  input 隐藏框的ID  上传后返回的ID 保持在这
 *  idImg   img的id 上传后替换图片
 */
function initUpload(uploadOptions,id,idImg){
	$("#" + uploadOptions.buttonId).uploadify({
		//开启调试
		'debug' : false,
		//是否自动上传
		'auto' : uploadOptions.auto,
		//超时时间
		'successTimeout' : 99999,
		//附带值
		'formData' : {
			
		},
		//flash
		'swf' : "[[${sysUrl}]]/static/sys/js/uploadify/v3/uploadify.swf",
		//文件选择后的容器ID
		'queueID' : uploadOptions.queueID,
		//服务器端脚本使用的文件对象的名称 $_FILES个['upload']
		'fileObjName' : 'upload',
		//上传处理程序
		'uploader' : uploadOptions.uploader,
		//
		'buttonText' : uploadOptions.buttonText,
		'buttonClass' : 'tms-btn',
		//浏览按钮的宽度
		'width' : '84',
		//浏览按钮的高度
		'height' : '30',
		//在浏览窗口底部的文件类型下拉菜单中显示的文本
		'fileTypeDesc' : '支持的格式',
		//允许上传的文件后缀
		'fileTypeExts' : uploadOptions.fileTypeExts,
		//上传文件的大小限制
		'fileSizeLimit' : uploadOptions.fileSizeLimit,
		//上传数量
		'queueSizeLimit' : uploadOptions.queueSizeLimit,
		//返回一个错误，选择文件的时候触发
		'onSelectError' : function(file, errorCode, errorMsg) {
			switch (errorCode) {
				case -100:
					// alert("上传的文件数量已经超出系统限制的");
					break;
				case -110:
					//alert("文件 ["+file.name+"] 大小超出系统限制的大小！");
					break;
				case -120:
					//alert("文件 ["+file.name+"] 大小异常！");
					break;
				case -130:
					alert("文件 [" + file.name + "] 类型不正确！");
					break;
			}
		},
		//上传到服务器，服务器返回相应信息到data里
		'onUploadSuccess' : function(file, resData, resOk) {
			if(resData != null && resData != ""){
				var obj = $.parseJSON(resData);
				console.log(resData);
				console.log(obj);
				if(obj.status =="success"){
				   location.reload();
				}
			}
		}
	});
};

function uploadFile(){
	  $.each($("tbody").find('.usercount'),function(i, v){	
		  var id =$(v).data('id')
	      var num = $(v).html();
		  $("#file"+num).uploadify("upload", "*");
	    });
}
$(function(){
	 $.each($("tbody").find('.usercount'),function(i, v){	
		  var id =$(v).data('id')
	      var num = $(v).html();
		  initUpload(uploadOptions("file"+num,"上传",id));
	    });
});

function deleteByIdwj(id){
	layer.confirm("确定删除该文件吗？",
			{icon: 4, btn: ['确定','取消']
	}, function(){
		$.ajax({
			url: '[[${sysUrl}]]/sys/jxy/jxyImgDelete',
			type: "post",
			data:{
				'id': id
			},
			dataType: "json",
			success:function(data){
					
					if(data.meta.success){
						layer.msg("删除成功",{icon:1});
				    	setTimeout(function(){
				    		location.reload();
						},1000);
					}else{
						layer.msg(data.meta.message,{icon:11});
					}
			}
		});
	});
}
function deleteById(id){
	parent.layer.confirm("确定删除该图书？",
			{icon: 4, btn: ['确定','取消']
	}, function(){
		$.ajax({
			url: '[[${sysUrl}]]/sys/jxy/jxyDelete',
			type: "post",
			data:{
				'id': id
			},
			dataType: "json",
			success:function(data){
					
					if(data.meta.success){
						parent.layer.msg("删除成功",{icon:1});
						setTimeout(function(){
				    		location.reload();
						},1000);
					}else{
						parent.layer.msg(data.meta.message,{icon:11});
					}
			}
		});
	});
}
</script>
</body>
</html>