<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> 
</head>
<style>
	.tablelink{margin-right:10px;}
	.stylecss{
	      color: red;
	}
</style>
<body>
<div class="rightinfo">
	<form id="seachform" th:action="@{/sys/lib/selectUserList.html}" method="post">
	<input type="hidden" id="libId" name="libId" th:value="${search.get('libId')}">
	<input type="hidden" id="type" name="type" th:value="${search.get('type')}">
	<ul class="seachform">
		<li>
			<label>昵称</label>
			<input name="name" type="text" class="scinput" th:value="${search.get('name')} == null  ? '': ${search.get('name')}"/>
		</li>
		<li>
			<label>手机号码</label>
			<input name="mobile" type="text" class="scinput" th:value="${search.get('mobile')} == null  ? '': ${search.get('mobile')}"/>
		</li>
			
			
			<li>
				<label>是否关注</label>
					<select class="scinput"  name="subscribe" th:switch="${search.get('subscribe')}" >
						<option value=""  th:selected="${ search.get('subscribe') eq '' }"  >全部</option>
						<option value="1" th:selected="${ search.get('subscribe') eq '1' }"  >已关注</option>
						<option value="0" th:selected="${ search.get('subscribe') eq '0' }" >未关注</option>
					</select>
			</li>
		<li>
			<label>&nbsp;</label>
			<input type="button" class="scbtn" value="查询" />
		</li>
		<li>
				<ul class="toolbar">
					<li class="click"><span><img style="width: 24px;height: 24px" th:src="@{/static/sys/images/select.png}" /></span>选择</li>
				</ul>
		</li>
		
	</ul>
	</form>
	<table class="tablelist">
		<thead>
		    <tr>
		        <th><input type="checkbox" onchange="selectAll()"></th>
		        <th style="width: 50px;">序号</th>
		        <th>昵称</th>
		        <th>头像</th>
		        <th>手机号码</th>
		        <th>是否关注</th>
		    </tr>
		</thead>
		<tbody>
			<tr th:each="item:${list}" >
				    <td><input name="selectlist" type="checkbox" th:data-id="${item.get('id')}" th:data-mobile="${item.get('mobile')}" th:data-name="${item.get('name')}"  /></td>
				    <td th:text="${itemStat.count}" ></td>
					<td class="getname" th:text="${item.get('name')}">
					</td>
					<td  class="imgtd">
							<img  th:if="${item.get('photo')}!=null" th:src="${imgUrl}+''+${item.get('photo')}" style="width: 50px;height: 50px;" />
					</td>
				<td th:text="${item.get('mobile')}" ></td>
				<td th:text="${item.get('subscribe')} ? (${item.get('subscribe')} == 1 ? '已关注' :'未关注') :'未关注'" ></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(){
	$('ul.toolbar li.click').click(function () {
	    var selectIds=[];
		var mobiles=[];
		var names=[];
		 $('[name=selectlist]:checkbox:checked').each(function() {
				 var id = $(this).attr('data-id');
				 selectIds.push(id);
			 var mobile = $(this).attr('data-mobile');
			 mobile=mobile!=undefined &&mobile !=''?mobile:" "
			 mobiles.push(mobile);
			 var name_ = $(this).attr('data-name');
			 name_=name_!=undefined &&name_ !=''?name_:" "
			 names.push(name_);
		 });
		 if(selectIds.length>0){
			 showIndex(selectIds,mobiles,names);
	   	 }else{
	   		closeWin();
	   	 }
		 
	 });
	$('[name=selectlist]:checkbox').change(function () {
		$(this).checked = !$(this).checked;
	 });
	
})
function selectAll() {
	$('[name=selectlist]:checkbox').each(function() {
		this.checked = !this.checked;
    });
}
function showIndex(selectIds,mobiles,names){
	var content ="您确定要添加管理员吗?";
	parent.layer.confirm(content, {
		icon: 4, btn: ['确定','关闭'] //按钮
	}, function(){
		var url="[[${sysUrl}]]/sys/lib/addAdmin";
		var id= $("#libId").val();
		var type= $("#type").val();
		 var params ={
		            'id' : id,
		            'type' : type,
		            'ids' : selectIds,
			        'names' : names,
			        'mobiles':mobiles
		        };
		$.post(url,params,function(data){
			if(data.meta.success){
				parent.layer.msg("添加成功",{icon:1});
				closeWin();
			}else{
				parent.layer.msg(data.meta.message,{icon:11});
				closeWin();
			}
		});
	});
}
function closeWin(){
	parent.location.reload();
	parent.layer.close(parent.layer.getFrameIndex(window.name));
}

</script>
</html>