<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/lib/libJoinList.html}">图书馆</a></li>
		<li><a href="#">组团配置</a></li>
	</ul>
</div>
<div class="rightinfo">
	<ul class="toolbar" style="margin-bottom: 10px;"  onclick="libVipAdd()">
		<li class="click"><span><img th:src="@{/static/sys/images/t01.png}" /></span>新增</li>
	</ul>
	<br/>


	<table class="tablelist">
		<thead>
		    <tr>
		        <th style="width: 80px;text-align: center;">序号</th>
		        <th style="color: red;text-align: center;">团购原价</th>
		        <th style="color: red;text-align: center;">组团人数</th>
		        <th style="color: red;text-align: center;">团购折扣</th>
		        <th style="text-align: center;">添加时间</th>
		    </tr>
		</thead>
		<tbody>
			<tr th:each="item:${list}" >
				<td th:text="${itemStat.count}" ></td>
				    <td style="text-align: center;" >
					 <input type="text" th:value="${item.price/100.0}" th:onBlur="'updateGroup(\''+${item.id}+'\',\''+${item.price/100}+'\',\'price\',this)'"  class="dfinput" style="width: 60px; height: 30px;color: red;"  >
					</td>
					<td style="text-align: center;" >
					 <input type="number" th:value="${item.number}" th:onBlur="'updateGroup(\''+${item.id}+'\',\''+${item.number}+'\',\'number\',this)'"  class="dfinput" style="width: 60px; height: 30px;color: red;"  >
					</td>
					 <td style="text-align: center;" >
					 <input type="number" th:value="${item.discount}" th:onBlur="'updateGroup(\''+${item.id}+'\',\''+${item.discount}+'\',\'discount\',this)'"  class="dfinput" style="width: 60px; height: 30px;color: red;"  >
					</td>
					<td  th:text="${#calendars.format(item.createTime,'yyyy-MM-dd HH:mm:ss')}" ></td>
			</tr>
		</tbody>
	</table>
	<br/>
	<br/>
	
	<img  th:src="@{{imgUrl}/group/{libId}.png(imgUrl=${imgUrl},libId=${param.libId})}">

</div>
<script type="text/javascript">
var libId='[[${param.libId}]]';

function libVipAdd(){
	parent.layer.open({
	    type: 2,
	    title: "添加团购配置",
	    closeBtn: 1, //不显示关闭按钮
	    shift: 0.8,
	    //offset: '100px',
	    area: ['40%', '50%'],
	    content: '[[${sysUrl}]]/sys/group/salesGroupPriceAdd.html?libId='+libId
	});
}


function updateGroup(id,oldval,type,_this){
	var val = $(_this).val();
	if(val == oldval){
		return false;
	}
	if(val ==''|| val ==null){
		return false;
	}
	$(_this).removeAttr("onBlur");
	$.ajax({
		url : "[[${sysUrl}]]/sys/group/updateGroup",
		type : "post",
		data : {
			id : id,
			val : val,
			type:type
		},
		dataType : "json",
		success : function(data) {
			if(data.meta.success){
				 parent.layer.msg('操作成功',{icon:1});
				 $(_this).attr("onBlur","updateGroup("+id+","+val+","+type+",this)");
				 if(type=='discount'){
					 $.ajax({
							url : "[[${sysUrl}]]/sys/group/geCode",
							type : "get",
							data : {
								libId : libId,
								discount : val,
								num:100
							},
							dataType : "json",
							success : function(data) {	
								
							}
						});
				 }
				
			}else{
				parent.layer.msg('操作失败',{icon: 9})
				$(_this).attr("onBlur","updateGroup("+id+","+oldval+","+type+",this)");
			}
		}
	});
}


</script>
</body>
</html>