<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">
	<form id="seachform" th:action="@{/sys/sales/salesPriceList.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: 100px;" name="EQ_species"   >
					    <option value=""  th:selected="${ search.get('EQ_species') eq '' }"  >全部</option>
						<option th:value="${sort.code}" th:each="sort:${species}" th:selected="${ search.get('EQ_type') eq sort.code }" >[[${sort.name}]]</option>
					</select>
		</li>
		<li>
		<label>销售卡类型</label>
					<select class="scinput" style="width: 200px;" name="EQ_type"   >
					    <option value=""  th:selected="${ search.get('EQ_type') eq '' }"  >全部</option>
						<option th:value="${sort.code}" th:each="sort:${cardType}" th:selected="${ search.get('EQ_type') eq sort.code }" >[[${sort.name}]]</option>
					</select>
		</li>
		<li>
			<label>&nbsp;</label>
			<input type="button" class="scbtn" 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 style="color: red;text-align: center;">销售卡实际价格</th>
		        <th style="text-align: center;">H5页面展示</th>
		        <th>添加时间</th>
		    </tr>
		</thead>
		<tbody>
			<tr th:each="item:${list}">
					<td th:text="${itemStat.count}" ></td>
					<td>
				       <span th:each="sort:${species}"  th:if="${sort.code eq item.species}" th:text="${sort.name}"></span>
				    </td>
					<td>
				       <span th:each="sort:${cardType}" class="sort_name" th:data-name="${sort.name}" th:if="${sort.code eq item.type}" th:text="${sort.name}"></span>
				    </td>
				    <td th:text="${item.price}">
					</td>
					<td th:text="${item.discount}" style="text-align: center;color: red;"></td>
				    <!--<td style="text-align: center;" >
					 <input type="number" th:value="${item.discount}" th:onBlur="'updatePrice(\''+${item.id}+'\',\''+${item.discount}+'\',\''+${item.type}+'\',\''+${item.libId}+'\',\''+${item.aliases}+'\',this)'"  class="dfinput" style="width: 70px; height: 30px;color: red;"  >
					</td>-->
					<td style="text-align: center;" >
					 <input type="text" th:value="${item.name}" th:onBlur="'updateName(\''+${item.id}+'\',\''+${item.name}+'\',this)'"  class="dfinput" style="width: 200px; height: 30px;color: red;"  >
					</td>
					<td  th:text="${#calendars.format(item.createTime,'yyyy-MM-dd HH:mm:ss')}" ></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 updatePrice(id,oldPrice,type,libId,aliases,_this){
	var price = $(_this).val();
	if(price<1){
		parent.layer.msg(aliases+"不能低于1元",{icon: 9})
		return false;
	}
	if(price == oldPrice){
		return false;
	}
	if(price ==''|| price ==null){
		return false;
	}
	var sortName=$(_this).parents('tr').find('.sort_name').attr('data-name'); 
	$(_this).removeAttr("onBlur");
	$.ajax({
		url : "[[${sysUrl}]]/sys/sales/updatePrice",
		type : "post",
		data : {
			id : id,
			price : price,
			oldPrice:oldPrice,
			aliases:aliases,
			sortName:sortName,
			type:type,
			libId:libId
		},
		dataType : "json",
		success : function(data) {
			if(data.meta.success){
				 parent.layer.msg('操作成功',{icon:1});
				 $(_this).attr("onBlur","updatePrice("+id+","+price+",this)");
			}else{
				parent.layer.msg('操作失败',{icon: 9})
				$(_this).attr("onBlur","updatePrice("+id+","+oldPrice+",this)");
			}
		}
	});
}
function updateName(id,oldName,_this){
	var name = $(_this).val();
	if(name == oldName){
		return false;
	}
	if(name ==''|| name ==null){
		return false;
	}
	$(_this).removeAttr("onBlur");
	$.ajax({
		url : "[[${sysUrl}]]/sys/sales/updateName",
		type : "post",
		data : {
			id : id,
			name : name
		},
		dataType : "json",
		success : function(data) {
			if(data.meta.success){
				 parent.layer.msg('操作成功',{icon:1});
				 $(_this).attr("onBlur","updatePrice("+id+","+name+",this)");
			}else{
				parent.layer.msg('操作失败',{icon: 9})
				$(_this).attr("onBlur","updatePrice("+id+","+name+",this)");
			}
		}
	});
}

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