<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;
	}
	.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 th:href="@{/sys/sales/libVipCodeList.html}">销售卡折扣配置</a></li>
	</ul>
</div>
<div class="rightinfo">
	<form id="seachform" th:action="@{/sys/sales/libVipCodeList.html}" method="post">
	<input type="hidden" name="EQ_libId" th:value="${search.get('EQ_libId')}">
	<ul class="seachform">
		<li>
		<label>类型</label>
					<select class="scinput" style="width: 200px;" name="EQ_type"   >
					    <option value=""  th:selected="${ search.get('EQ_type') eq '' }"  >全部</option>
					    <option value="1"  th:selected="${ search.get('EQ_type') eq '1' }"  >未使用</option>
					    <option value="2"  th:selected="${ search.get('EQ_type') eq '2' }"  >已使用</option>
					</select>
		</li>
		<li>
			<label>&nbsp;</label>
			<input type="button" class="scbtn" value="查询" />
		</li>
		<li th:if="${ #httpSession.getAttribute('admin') !=null   } " >
				<ul class="toolbar"  th:onclick="'libVipAdd(\''+${search.get('EQ_libId')}+'\')'">
					<li class="click"><span><img th:src="@{/static/sys/images/t01.png}" /></span>新增</li>
				</ul>
		</li>
		<li th:if="${ #httpSession.getAttribute('admin') !=null  } ">
		
		  
		   
			<input type="button" id="button" style="width: 100px;" class="scbtnbution" value="导出" />
		</li>
		<li>
				<ul class="toolbar">
					<a th:href="@{/sys/lib/libJoinList.html}"><li class="click"><span><img style="width: 24px;height: 24px" th:src="@{/static/sys/images/goto.png}" /></span>返回</li></a>
				</ul>
		</li>
	</ul>
	</form>
	<table class="tablelist">
		<thead>
		    <tr>
		        <th style="width: 80px;">序号</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:text="${item.vipCode}" ></td>
					<td  th:switch="${item.type}">
					   <span th:case="2" th:text="${item.user.name}"></span>
					   <span th:case="*"></span>
					</td>
					<td  th:switch="${item.type}">
					   <span th:case="2">已使用</span>
					   <span th:case="*">未使用</span>
					</td>
					<td th:text="${item.discount}+'%'" ></td>
					<td  th:text="${#calendars.format(item.createTime,'yyyy-MM-dd HH:mm:ss')}" ></td>
					<td  th:text="${#calendars.format(item.updateTime,'yyyy-MM-dd HH:mm:ss')}" ></td>
					<td >
						<a href="javascript:;" th:if="${item.type} eq '1' " th:onclick="'deleteById(\''+${item.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">

$("#button").on('click',function(){
	document.getElementById("seachform").action = "[[${sysUrl}]]/sys/report/exportLibVipCode";
	$("#seachform").submit();
	document.getElementById("seachform").action = "[[${sysUrl}]]/sys/sales/libVipCodeList.html";
});


function deleteById(id){
	layer.confirm("确定删除该折扣吗？",
			{icon: 4, btn: ['确定','取消']
	}, function(){
		$.ajax({
			url: '[[${sysUrl}]]/sys/sales/libVipCodeDelete',
			type: "post",
			data:{
				'id': id
			},
			dataType: "json",
			success:function(data){
					
					if(data.meta.success){
						layer.msg("删除成功",{icon:1});
				    	setTimeout(function(){
				    		location.reload();
						},1000);
					}else{
						layer.msg(data.meta.message,{icon:11});
					}
			}
		});
	});
}

function libVipAdd(id){
	layer.open({
	    type: 2,
	    title: "添加会员卡折扣",
	    closeBtn: 1, //不显示关闭按钮
	    shift: 0.8,
	    //offset: '100px',
	    area: ['40%', '50%'],
	    content: '[[${sysUrl}]]/sys/sales/libVipCodeAdd.html?libId='+id
	});
}
</script>
</html>