<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;
	}
	#joinServiceEdit label{
		font-size: 13px;
	}
</style>
<body>
<div class="place">
	<span>位置：</span>
	<ul class="placeul">
		<li><a th:href="@{/sys/imlibuser/school/list}">导入老师/学生</a></li>
		<li><a href="#">校区列表</a></li>
	</ul>
</div>
<div class="rightinfo">
	<form id="seachform" th:action="@{/sys/imlibuser/school/list}" method="post">
	  <input type="hidden" name="reportType" id="reportType" />
		<ul class="seachform">
			<li>
			  <input style="width: 250px;" name="leagueNname" placeholder="输入校区名称" type="text" class="scinput" th:value="${search.get('leagueNname')}"/>
		    </li>
		    <li>
			  <input type="button" class="scbtn" value="查询" />
		    </li>
		</ul>
	</form>
	
	<ul class="seachform">

	     <li>
		  <input type="button" id="principalimput" style="width: 100px;height: 30px"  class="scbtn" value=" + 导入校长" />
		  <div style="display: none">
		 	 <input type="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" id="principalfile" />
		  </div>
	    </li>
	    
	      <li>
		  <input type="button" id="leaderimput" style="width: 100px;height: 30px"  class="scbtn" value=" + 导入科目组长" />
		  <div style="display: none">
		 	 <input type="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" id="leaderfile" />
		  </div>
	    </li>
	    
	     <li>
		  <input type="button" id="headmasterimput" style="width: 100px;height: 30px"  class="scbtn" value=" + 导入班主任" />
		  <div style="display: none">
		 	 <input type="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" id="headmasterfile" />
		  </div>
	    </li>
	    
	     <li>
		  <input type="button" id="teacherimput" style="width: 100px;height: 30px"  class="scbtn" value=" + 导入科任老师" />
		  <div style="display: none">
		 	 <input type="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" id="teacherfile" />
		  </div>
	    </li>
	    
	    <li>
		  <input type="button" id="studentimput" style="width: 100px;height: 30px"  class="scbtn" value=" + 导入学生" />
		  <div style="display: none">
		 	 <input type="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" id="studentfile" />
		  </div>
	    </li>
	    
	    
	     <li>
		  <a th:href="@{/static/sys/excel/principal_lib .xlsx?1}"><input type="button" style="background: #ccc no-repeat center;width: 100px;height: 30px"  class="scbtn" value="校长模板" /></a>
	    </li>
	    
	     <li>
		  <a th:href="@{/static/sys/excel/leader_lib .xlsx?1}"><input type="button" style="background: #ccc no-repeat center;width: 100px;height: 30px"  class="scbtn" value="科目组长模板" /></a>
	    </li>
	    
	     <li>
		  <a th:href="@{/static/sys/excel/headmaster_lib.xlsx?1}"><input type="button" style="background: #ccc no-repeat center;width: 100px;height: 30px"  class="scbtn" value="班主任模板" /></a>
	    </li>
	    
	   <li>
		  <a th:href="@{/static/sys/excel/teacher_lib.xlsx?1}"><input type="button" style="background: #ccc no-repeat center;width: 100px;height: 30px"  class="scbtn" value="科任老师模板" /></a>
	    </li>
	    
	     <li>
		  <a th:href="@{/static/sys/excel/student_lib.xlsx?2}"><input type="button" style="background: #ccc no-repeat center;width: 100px;height: 30px"  class="scbtn" value="学生模板" /></a>
	    </li>
	    
<!-- 	     <li> -->
<!-- 		  <input type="button" id="exbutton" style="width: 100px;height: 30px;background: #ccc no-repeat center;"  class="scbtn" value="导出校区" /> -->
<!-- 	     </li> -->
	    
	    
	     <li style="line-height: 30px;">
	     	<a style="font-size: 13px;text-decoration: underline;" th:href="@{/sys/imlibuser/student/error/list}"  class="tablelink">学生添加失败列表</a>
	     </li>
	     
	      <li style="line-height: 30px;">
	     	<a style="font-size: 13px;text-decoration: underline;" th:href="@{/sys/imlibuser/teacher/error/list}"  class="tablelink">老师添加失败列表</a>
	     </li>

	</ul>
	
	<table class="tablelist">
		<thead>
		    <tr>
		    	<th style="min-width: 20%">校区 </th>
		    	<th style="width: 10%">校区服务塾币</th>
<!--		    	<th style="width: 10%">平台服务塾币</th>-->
		    	<th style="width: 10%">端口</th>
		    	<th style="width: 10%">校长人数</th>
		    	<th style="width: 10%">科目组长人数</th>
		    	<th style="width: 10%">班主任人数</th>
		    	<th style="width: 10%">科任老师人数</th>
		    	<th style="width: 10%">学生人数</th>
		    	<th style="width: 10%">流失学生人数</th>
<!-- 		        <th style="min-width: 14%">操作</th> -->
		    </tr> 
		</thead>
		<tbody>
			<tr th:each="item:${list}" th:style="${item.principal_num>0 || item.teacher_num>0 || item.student_num>0 ? 'color:red' : '' }">
				<td onclick="copyContent(this);"  th:text="${item.league_name}"></td>
				<td th:text="${item.lib_service+' 个'}"></td>
<!--				<td th:text="${item.platform_service+' 个'}"></td>-->
				<td th:text="${item.port_num+' 个'}"></td>
				<td >
					<a th:href="${sysUrl+'/sys/imlibuser/teacher/list/'+item.id+'/1'}"  class="tablelink">
						[[${item.principal_num+' 人'}]]
					</a>
				</td>
				<td >
					<a th:href="${sysUrl+'/sys/imlibuser/teacher/list/'+item.id+'/2'}"  class="tablelink">
						[[${item.leader_num+' 人'}]]
					</a>
				</td>
				<td >
					<a th:href="${sysUrl+'/sys/imlibuser/headmaster/list/'+item.id+'/2'}"  class="tablelink">
						[[${item.headmaster_num+' 人'}]]
					</a>
				</td>
				<td >
					<a th:href="${sysUrl+'/sys/imlibuser/headmaster/list/'+item.id+'/1'}"  class="tablelink">
						[[${item.teacher_num+' 人'}]]
					</a>
				</td>
				<td >
					<a th:href="${sysUrl+'/sys/imlibuser/student/list/'+item.id}"  class="tablelink">
						[[${item.student_num+' 人'}]]
					</a>
				</td>
				<td>
					<a th:href="${sysUrl+'/sys/imlibuser/invalidStudent/list/'+item.id}"  class="tablelink">
						[[${item.invalid_student_num+' 人'}]]
					</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>




<div class="formbody" id="joinServiceEdit" style="display: none">
	<input type="hidden" id="lib_service_id" value="" >
	<ul class="forminfo">
		<li >
			<label style="width: 100%">一个学币等于一个月的服务</label>
		</li>
		<li style="display: none">
			<label>校区服务学币：</label>
			<label><b id="lib_service_num">0</b> 个</label>
			<input onclick="joinServiceAdd(1);" type="button" style="width: 30px;height: 30px;border-radius: 50px;"  class="scbtn" value=" + " />
		</li>
		<li>
			<label>平台服务学币：</label>
			<label><b id="platform_service_num">0</b> 个</label>
			<input onclick="joinServiceAdd(2);" type="button" style="width: 30px;height: 30px;border-radius: 50px;"  class="scbtn" value=" + " />
		</li>
	</ul>
</div>



<div class="formbody" id="joinServiceAdd" style="display: none;">
	<input type="hidden" id="lib_service_type" value="" >
	<ul class="seachform" style="margin-top: 20px;margin-left:30%">
	    <li>
		  <input type="button" id="reduce_num" style="width: 30px;height: 30px;border-radius: 50px;"  class="scbtn" value=" - " />
	    </li>
	    <li>
		  <input type="text" id="add_service_num" value="1"  style="width: 50px;height: 30px;text-align: center;"   />
	    </li>
	    <li>
		  <input type="button" id="add_num" style="width: 30px;height: 30px;border-radius: 50px;"  class="scbtn" value=" + " />
	    </li>
	</ul>
	<button style="margin-top: 20px;margin-left: 30%" type="submit" onclick="save();" class="btn">提交</button>
</div>




</body>
<input id="copy_content" type="text" value="" >

<script type="text/javascript">
$("#exbutton").on('click',function(){
	document.getElementById("seachform").action = "[[${sysUrl}]]/sys/imlibuser/school/exlist";
	$("#seachform").submit();
	document.getElementById("seachform").action = "[[${sysUrl}]]/sys/imlibuser/school/list";
});
</script>



<script type="text/javascript">


function save(){
	var type= $("#lib_service_type").val();
	var num=$("#add_service_num").val();
	var libId=$("#lib_service_id").val();
	
	var url="[[${sysUrl}]]/sys/imlibuser/join/update/"+libId;
	var params ={
        'type' : type,
        'num':num
    };
	$.post(url,params,function(data){
		if(data.meta.success){
			parent.layer.msg("设置成功",{icon:1});
			parent.location.reload();
			parent.layer.close(parent.layer.getFrameIndex(window.name));
		}else{
			parent.layer.msg(data.meta.message,{icon:11});
		}
	});
}


function joinServiceAdd(type){
	var title='校区服务学币';
	if(type==1){
		title="校区服务学币";
	}else{
		title="平台服务学币";
	}
	$("#add_service_num").val(1)
	 $.ajax({
		  url: "[[${sysUrl}]]/sys/imlibuser/join/get/"+$("#lib_service_id").val(),
	      type: 'POST',
	      data: {},
	      processData: false,
	      contentType: false, 
	      beforeSend: function () {
	      },
	      success: function (responseStr) {
	    	  if(responseStr.meta.success){
	    		  $("#lib_service_type").val(type);
	    		  layer.open({
	    			    type: 1,
	    			    title: title,
	    			    closeBtn: 1, //不显示关闭按钮
	    			    shift: 0.8,
	    			    offset: '150px',
	    			    area: ['20%', '30%'],
	    			    content: $("#joinServiceAdd")
	    			});
	    		  
	    	  }else{
	    		  parent.layer.msg(responseStr.meta.message,{icon:11});
	    	  }
	      }
	      ,
	      error : function (responseStr) {
	    	  parent.layer.msg("查询失败,请刷新后重试！",{icon:11});
	      }
	  });
	

}


function joinServiceEdit(libId){
	
	  $.ajax({
		  url: "[[${sysUrl}]]/sys/imlibuser/join/get/"+libId,
	      type: 'POST',
	      data: {},
	      processData: false,
	      contentType: false, 
	      beforeSend: function () {
	      },
	      success: function (responseStr) {
	    	  if(responseStr.meta.success){
	    		  $("#lib_service_id").val(libId);
	    		  $("#lib_service_num").html(responseStr.data.join.libService);
	    		  $("#platform_service_num").html(responseStr.data.join.platformService);
	    		  
	    		  layer.open({
    			    type: 1,
    			    title: '服务学币设置',
    			    closeBtn: 1, //不显示关闭按钮
    			    shift: 0.8,
    			    offset: '150px',
    			    area: ['40%', '30%'],
    			    content: $("#joinServiceEdit")
	    		 });
	    		  
	    	  }else{
	    		  parent.layer.msg(responseStr.meta.message,{icon:11});
	    	  }
	      }
	      ,
	      error : function (responseStr) {
	    	  parent.layer.msg("查询失败,请刷新后重试！",{icon:11});
	      }
	  });
	
	

}

function copyContent(ElementObj){
    //获取点击的值
    var clickContent = ElementObj.innerText;         
    //获取要赋值的input的元素
    var inputElement =  document.getElementById("copy_content");
    //给input框赋值
    inputElement.value = clickContent;
    //选中input框的内容
    inputElement.select();
     // 执行浏览器复制命令
    document.execCommand("Copy");
    //提示已复制
    parent.layer.msg("已复制校区名称");
     
}

	$(function () {
		
		
		$("#reduce_num").click(function (){
			if($("#add_service_num").val()<=1){
				parent.layer.msg("学币不能小于1。",{icon:11});
				return;
			}
			
			$("#add_service_num").val(parseInt($("#add_service_num").val())-1);
		});
		

		$("#add_num").click(function (){
			$("#add_service_num").val(parseInt($("#add_service_num").val())+1);
		});
		
		$("#teacherimput").click(function (){
			$("#teacherfile").click();
		})
	
	    var $teacherfile =  $("#teacherfile");
	    $teacherfile.change(function () {
	        if($(this).val() != ""){
	        	fileTeacherLoad(this);
	        }
	    })
		
		
		$("#studentimput").click(function (){
			$("#studentfile").click();
		})
	    var $studentfile =  $("#studentfile");
	    $studentfile.change(function () {
	        if($(this).val() != ""){
	        	fileStudentLoad(this);
	        }
	    })
	    
	    
	    
	    $("#principalimput").click(function (){
			$("#principalfile").click();
		})
	    var $principalfile =  $("#principalfile");
	    $principalfile.change(function () {
	        if($(this).val() != ""){
	        	filePrincipalLoad(this);
	        }
	    })
	    
	    
	    $("#leaderimput").click(function (){
			$("#leaderfile").click();
		})
	    var $leaderfile =  $("#leaderfile");
	    $leaderfile.change(function () {
	        if($(this).val() != ""){
	        	fileLeaderLoad(this);
	        }
	    })
	    
	    
	    $("#headmasterimput").click(function (){
			$("#headmasterfile").click();
		})
	    var $leaderfile =  $("#headmasterfile");
	    $leaderfile.change(function () {
	        if($(this).val() != ""){
	        	fileHeadmasterLoad(this);
	        }
	    })
	    
	  
	})

	//+ 导入学生
	function fileStudentLoad(ele){
	  var formData = new FormData();
	  var name = $(ele).val();
	  var files = $(ele)[0].files[0];
	  formData.append("file", files);
	  formData.append("name", name);
	  $.ajax({
		  url: "[[${sysUrl}]]/sys/imlibuser/student/import",
	      type: 'POST',
	      data: formData,
	      processData: false,
	      contentType: false, 
	      beforeSend: function () {
	    	  parent.layer.msg("数据正在导入中....",{icon:2});
	      },
	      success: function (responseStr) {
	    	  if(responseStr.meta.success){
		    	  parent.layer.msg("导入成功",{icon:1});
				  parent.location.reload();
				  parent.layer.close(parent.layer.getFrameIndex(window.name));
	    	  }else{
	    		  parent.layer.msg(responseStr.meta.message,{icon:11});
	    		  $("#studentfile").val("");
	    	  }
	      }
	      ,
	      error : function (responseStr) {
	    	  parent.layer.msg("导入失败,请刷新后重试！",{icon:11});
	    	  $("#studentfile").val("");
	      }
	  });
	}
	
	//+ 导入老师
	function fileTeacherLoad(ele){
		  var formData = new FormData();
		  var name = $(ele).val();
		  var files = $(ele)[0].files[0];
		  formData.append("file", files);
		  formData.append("name", name);
		  $.ajax({
		      url: "[[${sysUrl}]]/sys/imlibuser/teacher/import",
		      type: 'POST',
		      data: formData,
		      processData: false,
		      contentType: false, 
		      beforeSend: function () {
		    	  parent.layer.msg("数据正在导入中....",{icon:2});
		      },
		      success: function (responseStr) {
		    	  if(responseStr.meta.success){
		    	  	 parent.layer.msg("导入成功",{icon:1});
					 parent.location.reload();
					 parent.layer.close(parent.layer.getFrameIndex(window.name));
		    	  }else{
		    		 parent.layer.msg(responseStr.meta.message,{icon:11});
		    		 $("#teacherfile").val("");
		    	  }
		      }
		      ,
		      error : function (responseStr) {
		    		parent.layer.msg("导入失败,请刷新后重试！",{icon:11});
		    		 $("#teacherfile").val("");
		      }
		  });
		}
	
	
	
	//  + 导入校长
	function filePrincipalLoad(ele){
		  var formData = new FormData();
		  var name = $(ele).val();
		  var files = $(ele)[0].files[0];
		  formData.append("file", files);
		  formData.append("name", name);
		  $.ajax({
			  url: "[[${sysUrl}]]/sys/imlibuser/principal/import",
		      type: 'POST',
		      data: formData,
		      processData: false,
		      contentType: false, 
		      beforeSend: function () {
		    	  parent.layer.msg("数据正在导入中....",{icon:2});
		      },
		      success: function (responseStr) {
		    	  if(responseStr.meta.success){
			    	  parent.layer.msg("导入成功",{icon:1});
					  parent.location.reload();
					  parent.layer.close(parent.layer.getFrameIndex(window.name));
		    	  }else{
		    		  parent.layer.msg(responseStr.meta.message,{icon:11});
		    		  $("#principalfile").val("");
		    	  }
		      }
		      ,
		      error : function (responseStr) {
		    	  parent.layer.msg("导入失败,请刷新后重试！",{icon:11});
		    	  $("#studentfile").val("");
		      }
		  });
		}

	
	// + 导入科目组长
	function fileLeaderLoad(ele){
		  var formData = new FormData();
		  var name = $(ele).val();
		  var files = $(ele)[0].files[0];
		  formData.append("file", files);
		  formData.append("name", name);
		  $.ajax({
			  url: "[[${sysUrl}]]/sys/imlibuser/leader/import",
		      type: 'POST',
		      data: formData,
		      processData: false,
		      contentType: false, 
		      beforeSend: function () {
		    	  parent.layer.msg("数据正在导入中....",{icon:2});
		      },
		      success: function (responseStr) {
		    	  if(responseStr.meta.success){
			    	  parent.layer.msg("导入成功",{icon:1});
					  parent.location.reload();
					  parent.layer.close(parent.layer.getFrameIndex(window.name));
		    	  }else{
		    		  parent.layer.msg(responseStr.meta.message,{icon:11});
		    		  $("#principalfile").val("");
		    	  }
		      }
		      ,
		      error : function (responseStr) {
		    	  parent.layer.msg("导入失败,请刷新后重试！",{icon:11});
		    	  $("#leaderfile").val("");
		      }
		  });
		}
	
	
	// + 导入班主任
	function fileHeadmasterLoad(ele){
		  var formData = new FormData();
		  var name = $(ele).val();
		  var files = $(ele)[0].files[0];
		  formData.append("file", files);
		  formData.append("name", name);
		  $.ajax({
			  url: "[[${sysUrl}]]/sys/imlibuser/headmaster/import",
		      type: 'POST',
		      data: formData,
		      processData: false,
		      contentType: false, 
		      beforeSend: function () {
		    	  parent.layer.msg("数据正在导入中....",{icon:2});
		      },
		      success: function (responseStr) {
		    	  if(responseStr.meta.success){
			    	  parent.layer.msg("导入成功",{icon:1});
					  parent.location.reload();
					  parent.layer.close(parent.layer.getFrameIndex(window.name));
		    	  }else{
		    		  parent.layer.msg(responseStr.meta.message,{icon:11});
		    		  $("#principalfile").val("");
		    	  }
		      }
		      ,
		      error : function (responseStr) {
		    	  parent.layer.msg("导入失败,请刷新后重试！",{icon:11});
		    	  $("#headmasterfile").val("");
		      }
		  });
		}
	
	

	
	

</script>


</html>