<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="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/card/cardlist.html}" method="post">
	<ul class="seachform">
		<li>
			<label>活动名称</label>
			<input name="LIKE_name" type="text" class="scinput" th:value="${search.get('LIKE_name')}"/>
		</li>
		<li>
			<label>微信关键字</label>
			<input name="LIKE_keyword" type="text" class="scinput" th:value="${search.get('LIKE_keyword')}"/>
		</li>
		<li>
			<label>&nbsp;</label>
			<input type="button" class="scbtn" value="查询" />
		</li>
		<li>
				<ul class="toolbar">
					<a th:href="@{/sys/card/add/0.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: 40px;">序号</th>
		        <th>活动名称</th>
		        <th>图书馆</th>
		        <th>微信关键字</th>
		        <th>活动类型</th>
		        <th>二维码</th>
		        <th>活动开始时间</th>
		        <th>活动结束时间</th>
		        <th>活动状态</th>
		        <th style="width: 200px;">操作</th>
		    </tr>
		</thead>
		<tbody>
			<tr th:each="item:${list}" >
				<td th:text="${itemStat.count}" ></td>
				<td th:text="${item.get('name')}"></td>
				<td th:text="${item.get('league_name')}"></td>
				<td th:text="${item.get('keyword')}"></td>
				<td th:text="${item.get('play_type')}>1 ?(${item.get('play_type')} ==2 ? '刮刮乐' : '砸金蛋') :'大转盘' " ></td>
				<td  class="imgtd">
							<img  th:if="${item.qr_code}!=null" th:src="${imgUrl}+''+${item.qr_code}" class="tablelink" style="width: 50px;height: 50px;" />
					</td>
				<td th:text="${#calendars.format(item.get('start_time'),'yyyy-MM-dd HH:mm:ss')}"></td>
				<td th:text="${#calendars.format(item.get('end_time'),'yyyy-MM-dd HH:mm:ss')}"></td>
				<td th:switch="${item.get('play_status')}" >
				    <span th:remove="tag" th:case="1">
				      <b style="margin-right: 20px;"class="stylecss">进行中</b>
				      <a href="javascript:;" th:onclick="'fabu(\''+${item.get('id')}+'\',2);'"  class="tablelink" >终止活动</a>
				    </span>
					<span th:case="2" >已结束</span>
				    <span th:remove="tag" th:case="*">
				      <b style="margin-right: 20px;">未开始</b>
				      <a href="javascript:;" th:onclick="'fabu(\''+${item.get('id')}+'\',1);'"  class="tablelink" >活动发布</a>
				    </span>
				</td>
				
				<td>
				        <a href="javascript:;" class="tablelink" th:if="${item.get('play_status') ==0 }"   th:onclick="'generatingSncode(\''+${item.get('id')}+'\');'">生成SN码</a>
				        <a  th:href="@{/sys/card/snCodeList/{id}.html(id=${item.get('id')})}" th:if="${item.get('play_status') ==1 || item.get('play_status') ==2 }" class="tablelink" >SN码管理</a>
						<a  th:href="@{/sys/card/awardLog/{id}.html(id=${item.get('id')})}" class="tablelink" >抽奖记录</a>
					    <a href="javascript:;"  th:if="${item.get('play_status') ==0 }" th:onclick="'deleteById(\''+${item.get('id')}+'\')'"  class="tablelink" >删除</a>
						<a  th:href="@{/sys/card/add/{id}.html(id=${item.get('id')})}" th:if="${item.get('play_status') ==1 || item.get('play_status') ==0 }" 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 deleteById(id){
	parent.layer.confirm("确定删除该活动吗？",
			{icon: 4, btn: ['确定','取消']
	}, function(){
		$.ajax({
			url: '[[${sysUrl}]]/sys/card/deleteCard',
			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});
					}
			}
		});
	});
}

function generatingSncode(id){
	parent.layer.confirm("确定生成snCode吗？",
			{icon: 4, btn: ['确定','取消']
	}, function(){
		$.ajax({
			url: '[[${sysUrl}]]/sys/card/generatingSncode',
			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});
					}
			}
		});
	});
}
function fabu(id,type){
	var desc="确定发布活动吗？";
	if(type == 2 ){
		desc="确定结束活动吗？";
	}
	parent.layer.confirm(desc,
			{icon: 4, btn: ['确定','取消']
	}, function(){
		$.ajax({
			url: '[[${sysUrl}]]/sys/card/fabu',
			type: "post",
			data : {
				'id' : id,
				'type' :type
			},
			dataType: "json",
			success:function(data){
					if(data.meta.success){
						parent.layer.msg(data.meta.message,{icon:1});
						location.reload();
					}else{
						parent.layer.msg(data.meta.message,{icon:11});
					}
			}
		});
	});
}
</script>
</body>
</html>