<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 th:include="sys/common/fileUpload" th:remove="tag"></script> 
</head>
<style>
	.tablelink{margin-right:10px;}
	.stylecss{
	      color: red;
	}
	.select_width{
	     width: 70px;
	}
	.date_width{
	     width: 100px;
	}
	.uploadify {
    left: 1px;
   }
</style>
<body>
<div class="place">
	<span>位置：</span>
	<ul class="placeul">
		<li><a href="#">图书馆管理</a></li>
		<li><a th:href="@{/sys/story/storyList.html}">故事列表</a></li>
		<li><a href="#">图片管理</a></li>
	</ul>
</div>
<div class="rightinfo">
	<form id="seachform" th:action="@{/sys/story/storyTaskImg.html}" method="post">
	 <input type="hidden" name="EQ_storyId" th:value="${search.get('EQ_storyId')}">
	<input type="hidden" id="EQ_objectId" name="EQ_objectId" th:value="${search.get('EQ_objectId')}">
	<ul class="seachform">
		<li>
			<label>图片名称</label>
			<input name="LIKE_name" type="text" class="scinput" th:value="${search.get('LIKE_name')}"/>
		</li>
		<li>
			<label>&nbsp;</label>
			<input type="button" class="scbtn" value="查询" />
		</li>
		<li>
			<label>&nbsp;</label>
			<input type="file"  id="upfile"  />
		</li>
		<li>
				<ul class="toolbar">
					<a th:href="@{/sys/story/storyTaskList.html(EQ_storyId=${search.get('EQ_storyId')})}"><li class="click"><span><img style="width: 24px;height: 24px" th:src="@{/static/sys/images/goto.png}" /></span>返回</li></a>
				</ul>
		</li>
	</ul>
	</form>
	<table class="tablelist">
		<thead>
		    <tr>
		        <th style="width: 80px;">序号</th>
		        <th>图片名称</th>
		        <th>图片</th>
		        <th style="color: red;text-align: center;">排序</th>
		        <th>添加时间</th>
		        <th>操作</th>
		    </tr>
		</thead>
		<tbody>
			<tr th:each="item:${list}" >
				<td th:text="${itemStat.count}" ></td>
					<td th:text="${item.name}">
				      
				    </td>
					<td  class="imgtd">
							<img  th:if="${item.img}!=null" th:src="${imgUrl}+''+${item.img}" style="width: 50px;height: 50px;" />
					</td>
				    <td style="text-align: center;" >
					 <input type="number" th:value="${item.num}" th:onBlur="'updatePrice(\''+${item.id}+'\',\''+${item.num}+'\',this)'"  class="dfinput" style="width: 60px; height: 30px;color: red;"  >
					</td>
					<td  th:text="${#calendars.format(item.createTime,'yyyy-MM-dd HH:mm:ss')}" ></td>
				   <td>
				     <a href="javascript:;" th:onclick="'deleteById(\''+${item.id}+'\')'"  class="tablelink" >删除</a>
				   </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 uploadOptions(buttonId,buttonText,userId){
	var uploads = {
			buttonId: buttonId, //上传按钮ID
			buttonText: buttonText, //上传按钮文本
			auto: true, //是否自动上传
			queueID: "upload_file_view", //文件选择后的容器ID
			uploader: "[[${sysUrl}]]/sys/story/uploadfile?objectId="+userId, //上传处理URL
			fileTypeExts: "*.jpg;*.png;*.jpeg;*.gif", //允许上传的文件后缀
			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(){
	$("#upfile").uploadify("upload", "*");
}
$(function(){
	initUpload(uploadOptions("upfile","上传图片","[[${search.get('EQ_objectId')}]]"),"titleImg","titleImgImg");
});

</script>

<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/story/updateNum",
		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 deleteById(id){
	layer.confirm("确定删除该图片吗？",
			{icon: 4, btn: ['确定','取消']
	}, function(){
		$.ajax({
			url: '[[${sysUrl}]]/sys/story/storyImgDelete',
			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});
					}
			}
		});
	});
}
</script>
</body>
</html>