<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: 220px;
	}
	.date_width{
	     width: 150px;
	}
	body{min-width:180px;}
    .select1{
 		width:100%;
	    height: 32px;
	    line-height: 32px;
	    border-top: solid 1px #a7b5bc;
	    border-left: solid 1px #a7b5bc;
	    border-right: solid 1px #ced9df;
	    border-bottom: solid 1px #ced9df;
	    opacity:1;
       margin-bottom: 10px;
   	}
	
	
</style>
<body>

<div class="rightinfo">
	<input type="hidden" id="from_merchant" name="from_merchant" th:value="${merchant.id}">
	<input type="hidden" id="max_service_num" name="max_service_num" th:value="${merchant.libService}">
	<input type="hidden" id="max_platformservice_num" name="max_platformservice_num" th:value="${merchant.platformService}">
	
	<div class="formbody" id="joinServiceAdd" >
		<ul class="seachform" style="margin-top: 40px;margin-left:27%">
			<li>
				<div class="vocation" style="margin-right: 5px; width: 300px">
					<select name="to_merchant" id="to_merchant" class="select1"> 
						<option value="" >请选择您的下级商户</option>
						<option th:each="item:${subMerchants}" th:value="${item.id}" th:text="${item.unitName}"></option>
					</select>
				</div>
			</li>
		</ul>
		
		<ul class="seachform" style="margin-top: 20px;margin-left:38%">
		    <li>
			  <input type="button" id="reduce_num" style="width: 30px;height: 30px;border-radius: 50px;"  class="scbtn" value=" - " />
		    </li>
		    <li>
			  <input type="text" id="add_service_num" value="1" style="width: 50px;height: 30px;text-align: center;"   />
		    </li>
		    <li>
			  <input type="button" id="add_num" style="width: 30px;height: 30px;border-radius: 50px;"  class="scbtn" value=" + " />
		    </li>
		</ul>
		<button style="margin-top: 20px;margin-left: 38%" type="submit" onclick="save();" class="btn">提交</button>
	</div>
		
</div>
</body>


<script type="text/javascript">
var lng="[[${#lists.size(subMerchants)}]]";
var type="[[${param.type}]]";

$(function () {
	
	if(parseInt(lng)<=0){
		parent.layer.msg("您暂无下级商户，暂无法操作。",{icon:11});
	}
	
	$("#reduce_num").click(function (){
		if($("#add_service_num").val()<=1){
			parent.layer.msg("分配的塾币数量不能小于1",{icon:11});
			return;
		}
		$("#add_service_num").val(parseInt($("#add_service_num").val())-1);
	});
	
	$("#add_num").click(function (){
		var max_service_num=$("#max_service_num").val();
		var max_platformservice_num=$("#max_service_num").val();
		if(type==1){
			if((parseInt($("#add_service_num").val())+1)>max_service_num){
				parent.layer.msg("分配的机构塾币数量不能大于您的机构塾币",{icon:11});
				return;
			}
		}else{
			if((parseInt($("#add_service_num").val())+1)>max_platformservice_num){
				parent.layer.msg("分配的平台塾币数量不能大于您的平台塾币",{icon:11});
				return;
			}
		}
		$("#add_service_num").val(parseInt($("#add_service_num").val())+1);
	});

})


function save(){
	var fromMerchant= $("#from_merchant").val();
	var toMerchant=$("#to_merchant").val();
	if(toMerchant==''){
		parent.layer.msg("请选择您要分配的商户",{icon:11});
		return;
	}
	
	var num=$("#add_service_num").val();
	
	var url="[[${sysUrl}]]/sys/fx/allot";
	var params ={
        'fromMerchant' : fromMerchant,
        'toMerchant' : toMerchant,
        'num':num,
        'type':type
    };
	$.post(url,params,function(data){
		if(data.meta.success){
			parent.layer.msg("设置成功",{icon:1});
			parent.location.reload();
			parent.layer.close(parent.layer.getFrameIndex(window.name));
		}else{
			parent.layer.msg(data.meta.message,{icon:11});
		}
	});
}


</script>





</html>