<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: 150px;
	}
	
	.tablelist th,td{
		white-space: nowrap;
		text-overflow: ellipsis;
		overflow: hidden;
	}
	.tablelist td a{
    	text-decoration: underline;
	}
	
</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/train/video/list.html}" method="post">
	<input type="hidden" name="pageSize" id="pageSize" value="10" />
	<ul class="seachform">
		<li>
			<label>学习内容：</label>
			<select class="scinput select_width"  name="roleType"   style="width: 150px;" >
				<option value="">全部</option>
				<option value="1" th:selected="${search.get('roleType') eq '1'}" >校长端</option>
				<option value="2" th:selected="${search.get('roleType') eq '2'}">老师端</option>
				<option value="3" th:selected="${search.get('roleType') eq '3'}">家长端</option>
				<option value="4" th:selected="${search.get('roleType') eq '4'}">学生端</option>
			</select>
	    </li>
	    <li>
			<label>状态：</label>
			<select class="scinput select_width"  name="status"   style="width: 150px;" >
				<option value="">全部</option>
				<option value="0" th:selected="${search.get('status') eq '0'}">未发布</option>
				<option value="1" th:selected="${search.get('status') eq '1'}">发布</option>
				<option value="2" th:selected="${search.get('status') eq '2'}">删除</option>
			</select>
	    </li>
	    <li>
			 <label>模块：</label>
			 <input name="module" type="text" class="scinput" th:value="${search.module}"   />
		</li>
		<li>
			 <label>资料名称：</label>
			 <input name="title" type="text" class="scinput" th:value="${search.title}"   />
		</li>
		<li>
			<input type="button" class="scbtn" value="查询" />
		</li>
		<li>
			<ul class="toolbar">
				<a th:href="@{/sys/train/video/edit.html}">
					<li class="click"><span><img th:src="@{/static/sys/images/t01.png}"></span>添加视频</li>
				</a>
			</ul>
		</li>
	</ul>
	
	<ul class="toolbar" style="margin-bottom: 10px;">
		<li class="click">
			<a th:href="@{/static/sys/excel/exam_info.xlsx}">
				<span><img th:src="@{/static/sys/images/t02.png}"></span>下载测题模板
			</a>
		</li>
	</ul>
	
	</form> 
	
	
	

	<table class="tablelist">
		<thead>
		    <tr>
		    	<th >序号</th>
		    	<th >学习内容 </th>
		    	<th >模块 </th>
		    	<th >资料名称</th>
		    	<th >资料路径</th>
		    	<th >排序(从小到大)</th>
		    	<th >状态 </th>
		    	<th >上传时间 </th>
		    	<th >小测题量 </th>
		    	<th >操作 </th>
		    </tr> 
		</thead>
		<tbody>
			<tr th:each="item:${list}" >
				<td th:text="${itemStat.count}"></td>
				<td  th:switch="${item.role_type}">
				   <span th:case="1" style="color:red">校长端</span>
				   <span th:case="2" style="color:red">老师端</span>
				   <span th:case="3" style="color:red">家长端</span>
				   <span th:case="4" style="color:red">学生端</span>
				</td>
				<td th:text="${item.module}"></td>
				<td th:text="${item.title}"></td>
				<td th:text="${item.url}"></td>
				<td >
					<input type="number" th:value="${item.indes}" th:onBlur="'updateIndes(\''+${item.id}+'\',this)'" class="dfinput" style="width: 60px; height: 30px;">
				</td>
				<td  th:switch="${item.status}">
				   <span th:case="0" >未发布</span>
				   <span th:case="1" >发布</span>
				   <span th:case="2" style="color:red">已下架</span>
				</td>
				<td th:text="${item.create_time}"></td>
				<td th:text="${item.exam_num}"></td>
				<td >
					<a th:href="@{/sys/train/video/edit.html(id=${item.id})}" class="tablelink">编辑</a>
					<a href="javascript:;"  th:if="${item.status==0 || item.status==2 }" th:onclick="'joinServiceEdit(\''+${item.id}+'\')'" class="tablelink">发布</a>
					<a href="javascript:;"   th:onclick="'importexaminfo(\''+${item.id}+'\')'" class="tablelink">导入小测</a>
					<span style="display: none">
						<input type="file" id="importexaminfo_file">
						<input type="hidden" id="importexaminfo_file_id">
					</span>
				</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>
</body>

<script type="text/javascript">
$(function () {
	 $("#importexaminfo_file").change(function () {
		var formData = new FormData();
	        formData.append("file", document.getElementById("importexaminfo_file").files[0]);  
	        $.ajax({
	        	url: "[[${sysUrl}]]/sys/train/import/exam/info?videoId="+$("#importexaminfo_file_id").val(),
	            type: "POST",
	            data: formData,
	            contentType: false,
	            processData: false,
	            success: function (data) {
	            	if(data.meta.success){
	                	parent.layer.msg("导入成功",{icon:1});
				    	setTimeout(function(){
				    		$(".scbtn").click();
						},500);
	                }else {
	                    alert(data.msg);
	                }
	            },
	            error: function () {
	            	 alert("上传失败,请刷新后重试。");
	            }
	        });
		
	})
	
})


function updateIndes(id,obj){
	var url="[[${sysUrl}]]/sys/train/video/indes/update";
	var params = {
			"id":id,
			"indes":$(obj).val()
	};
	$.post(url,params,function(data){
			if(data != null){
				if(data.meta.success){
					layer.msg("操作成功!",{icon:1});
					setTimeout(function(){
						$(".scbtn").click();
					},500);
				}else{
					layer.msg(data.meta.message,{icon:11});
				}
		}
	});
}

function importexaminfo(videoId) {
	$("#importexaminfo_file_id").val(videoId);
	$("#importexaminfo_file").click();
};

</script>

</html>