<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/problem/problemlist.html}" method="post">
	<ul class="seachform">
	<li>
			<label>标题</label>
			<input name="title" type="text" class="scinput" th:value="${search.get('title')}"/>
		</li>
		<li>
			<input type="button" class="scbtn" value="查询" />
		</li>
	<li>
				<ul class="toolbar">
		<a th:href="@{/sys/problem/addproblem.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>
		    </tr>
		</thead>
		<tbody>
			<tr th:each="problemlist:${list}" >
				<td th:text="${problemlistStat.count}" ></td>
				<td th:title="${problemlist.get('title')}" th:text="${problemlist.get('title')} ? (${#strings.length(problemlist.get('title'))} &gt; 35 ? ${#strings.substring(problemlist.get('title'),0,35)} :${problemlist.get('title')} ) :'' ">
					</td>
				<td th:title="${problemlist.get('link')}" th:text="${problemlist.get('link')} ? (${#strings.length(problemlist.get('link'))} &gt; 35 ? ${#strings.substring(problemlist.get('link'),0,35)} :${problemlist.get('link')} ) :'' ">
					</td>	
				<td th:switch="${problemlist.get('type')}" >
				    <span th:case="1">外借书及阅读指导</span>
				    <span th:case="2">同伴作业督导</span>
				    <span th:case="3">阅读评测</span>
				    <span th:case="4">关于私塾家</span>
				</td>
				<td th:switch="${problemlist.get('stat')}" >
				    <span th:case="1">馆长端</span>
				    <span th:case="2">家长端</span>
				    <span th:case="3">馆长助理端</span>
				    <span th:case="4">老师端</span>
				    <span th:case="3">校长端</span>
				</td>
				<td style="text-align: center;" >
											 <input type="number" th:value="${problemlist.num}" th:onBlur="'updatenum(\''+${problemlist.id}+'\',\''+${problemlist.num}+'\',this)'"  class="dfinput" style="width: 60px; height: 30px;color: red;"  >
											</td>
				<td>
					<a th:href="@{/sys/problem/addproblem.html(id=${problemlist.get('id')})}" class="tablelink" >修改</a>
				    <a href="javascript:;" th:onclick="'deleteById(\''+${problemlist.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/problem/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/problem/problemDelete',
			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>