<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>
</head>
<style>
	.tablelink{margin-right:10px;}
	.stylecss{
	      color: red;
	}
	.select_width{
	     width: 220px;
	}
	.date_width{
	     width: 83px;
	}
</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/ydz/articelist.html}" method="post">
	<ul class="seachform">
	<li>
			<label>标题</label>
			<input name="headline" type="text" class="scinput" th:value="${search.get('headline')}"/>
		</li>
		<li>
			<input type="button" class="scbtn" value="查询" />
		</li>
	<li>
				<ul class="toolbar">
		<a th:href="@{/sys/ydz/addartice.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 style="color: red;text-align: center;">排序</th>
		        <th>创建时间
		        </th>
		        <th>操作</th>
		    </tr>
		</thead>
		<tbody>
			<tr th:each="itemlist:${list}" >
				<td th:text="${itemlistStat.count}" ></td>
				<td th:title="${itemlist.get('headline')}" th:text="${itemlist.get('headline')} ? (${#strings.length(itemlist.get('headline'))} &gt; 35 ? ${#strings.substring(itemlist.get('headline'),0,35)} :${itemlist.get('headline')} ) :'' ">
				</td>
				<td th:title="${itemlist.get('content')}" th:text="${itemlist.get('content')} ? (${#strings.length(itemlist.get('content'))} &gt; 35 ? ${#strings.substring(itemlist.get('content'),0,35)} :${itemlist.get('content')} ) :'' ">
				</td>	
				<td th:text="${itemlist.get('grade')}"></td>
				<td th:switch="${itemlist.get('version')}" >
				    <span th:case="1">第一套</span>
				    <span th:case="2">第二套</span>
				    <span th:case="3">第三套</span>
				</td>
				<td style="text-align: center;" >
				<input type="number" th:value="${itemlist.number}" th:onBlur="'updatenum(\''+${itemlist.id}+'\',\''+${itemlist.number}+'\',this)'"  class="dfinput" style="width: 60px; height: 30px;color: red;"  >
				</td>
				<td th:text="${#calendars.format(itemlist.get('create_time'),'yyyy-MM-dd HH:mm:ss')}" ></td>
				<td>
					<a th:href="@{/sys/ydz/addartice.html(id=${itemlist.get('id')})}" class="tablelink" >修改</a>
				    <a href="javascript:;" th:onclick="'deleteById(\''+${itemlist.get('id')}+'\')'"  class="tablelink" >删除</a>
				    <a th:href="@{/sys/ydz/articeMatterlist.html(artice_id=${itemlist.get('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 updatenum(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/ydz/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){
	parent.layer.confirm("确定删除该问题？",
			{icon: 4, btn: ['确定','取消']
	}, function(){
		$.ajax({
			url: '[[${sysUrl}]]/sys/ydz/articeDelete',
			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>