<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: 70px;
	}
	.date_width{
	     width: 100px;
	}
</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/wx/userList.html}" method="post">
	<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>
					<select class="scinput select_width"  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>开始时间</label>
				<input type="text" id="beginDate" name="beginDate"  onclick="WdatePicker({maxDate:'#F{$dp.$D(\'endDate\')}'})" th:value="${search.beginDate }" class="scinput date_width " placeholder="开始时间">
			</li>
			
			
			<li>
				<label>结束时间</label>
				<input type="text" id="endDate" name="endDate"  onclick="WdatePicker({minDate:'#F{$dp.$D(\'beginDate\')}'})" th:value="${search.endDate }" class="scinput date_width" placeholder="结束时间">
			</li>
		<li>
			<label>&nbsp;</label>
			<input type="button" class="scbtn" value="查询" />
		</li>
		<li>
			<label>&nbsp;</label>
			<input type="button" id="detailbutton" style="width: 120px;" class="scbtnbution" value="更新全部用户" />
		</li>
		
	</ul>
	</form>
	<table class="tablelist">
		<thead>
		    <tr>
		        <th style="width: 50px;">序号</th>
		        <th>昵称</th>
		        <th>头像</th>
		        <th>openId</th>
		        <th>unionid</th>
		        <th>地区</th>
		        <th>是否关注</th>
		        <th style="width: 141px;" >创建日期</th>
		        <th>操作</th>
		    </tr>
		</thead>
		<tbody>
			<tr th:each="item:${list}" >
				<td th:text="${itemStat.count}" ></td>
					<td th:text="${item.get('wx_name')}"></td>
					<td  class="imgtd">
							<img  th:if="${item.get('photo')}!=null" th:src="${imgUrl}+''+${item.get('photo')}+'?x-oss-process=image/resize,m_lfit,h_100,w_100'" style="width: 50px;height: 50px;" />
					</td>
					<td th:text="${item.get('wx_account')}"></td>
					<td th:text="${item.get('unionid')}"></td>
					<td th:text="(${item.get('country')} ne null ? ${item.get('country')} : '' ) +''+(${item.get('province')} ne null ? ${item.get('province')} : '' )+''+(${item.get('city')} ne null ? ${item.get('city')} : '' )"></td>
				<td th:classappend="${item.get('subscribe')} ==1 ? 'stylecss'" th:text="${item.get('subscribe')} ? (${item.get('subscribe')} == 1 ? '已关注' :'未关注') :'未关注'" ></td>
				<td style="width: 141px;" th:text="${#calendars.format(item.get('create_time'),'yyyy-MM-dd HH:mm:ss')}" ></td>
				<td>
					<a href="javascript:;" th:onclick="'update(\''+${item.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>
</body>
<script type="text/javascript">

function update(id){
	var desc="更新用户基本信息？";
	parent.layer.confirm(desc,
			{icon: 4, btn: ['确定','取消']
	}, function(){
		$.ajax({
			url: '[[${sysUrl}]]/sys/wx/update',
			type: "post",
			data : {
				'id' : id
			},
			dataType: "json",
			success:function(data){
					if(data.meta.success){
						parent.layer.msg("更新成功",{icon:1});
						location.reload();
					}else{
						parent.layer.msg(data.meta.message,{icon:11});
					}
			}
		});
	});
}

$("#detailbutton").on('click',function(){
	updateAll();
});

function updateAll(){
	var desc="更新全部用户？";
	parent.layer.confirm(desc,
			{icon: 4, btn: ['确定','取消']
	}, function(){
		$.ajax({
			url: '[[${sysUrl}]]/sys/wx/updateAll',
			type: "post",
			dataType: "json",
			success:function(data){
					if(data.meta.success){
						parent.layer.msg("更新成功",{icon:1});
						location.reload();
					}else{
						parent.layer.msg(data.meta.message,{icon:11});
					}
			}
		});
	});
}

</script>
</html>