<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: 83px;
	}
	.seachform li{
	    height: 50px;
	    float:none;
	}
	.seachform li label{
	    width: 80px;
	    text-align: right;
	}
	.scbtn{
		margin-left:90px 
	}
	strong{
		margin-right: 20px;
	}
	
</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">
	<ul class="seachform">
		<li>
			<label>图书馆：</label>
			<select class="scinput select_width"  name="libId" id="libIdChange"  style="width: 250px;" >
				<option value=""   >请选择</option>
				<option th:each="item:${libList}"  th:value="${item.get('id')}"    >[[${item.get('league_name')}]]</option>
			</select>
		</li>
		<li>
			<label>服务跟进人：</label>
			<select class="scinput select_width"  name="salesUserId" id="salesUserId" style="width: 250px;" >
				<option value=""   >请选择</option>
				
			</select>
		</li>
		<li style="line-height: 35px;">
			<label>会员卡类型：</label>
			<div id="species" >
				<strong><input type="radio"  name="species" value="S001" data-text='普通卡'>普通卡</strong>
				<!-- <strong><input type="radio"  name="species" value="S002" data-text='荣誉馆长'>荣誉馆长</strong> -->
				<strong><input type="radio"  name="species" value="S003" data-text='学霸卡'>学霸卡</strong>
			</div>
		</li>
		<li >
			<label>&nbsp;</label>
			<div id="type">
			<!--  
				<strong><input type="radio"  name="type"  >普通卡</strong>
				<strong><input type="radio"  name="type"  >荣誉馆长</strong>
				<strong><input type="radio"  name="type"  >学霸卡</strong>
				-->
			</div>
		</li>
		<li>
			<label>会员卡号：</label>
			<input type="text" id="vip" name="vip"  class="scinput date_width" style="width: 250px;" placeholder="会员卡号">
		</li>
		<li>
			<label>价格：</label>
			<input type="text" id="price" name="price"  class="scinput date_width" style="width: 250px;" placeholder="价格">
		</li>
		<li>
			<input type="button" class="scbtn" id="subtn" value="保存" />
		</li>

	</ul>



</div>
</body>
<script type="text/javascript">
	var path="[[${sysUrl}]]";
	var S001=[],S002=[],S003=[];
	$(function (){
		$("#subtn").on('click',function (){
			saveLineOrderDetails();
		});
		$("#libIdChange").on('change',function (){
			var libId=$(this).val();
			$("#salesUserId").html('<option value="">请选择</option>');
			$("#type").html("");
			$("input[name='species']").attr('checked',false);
			queryStaffingList(libId);
			querySalesPriceList(libId);
		})
		$("#species input").on('change',function (){
			var speciesVal=$(this).val();
			$("#type").html("");
			if(speciesVal=='S001'){
				$("#type").html(S001.join(''));
			}else if(speciesVal=='S002'){
				$("#type").html(S002.join(''));
			}else if(speciesVal=='S003'){
				$("#type").html(S003.join(''));
			}
		})
		function saveLineOrderDetails(){
			 var libId=$("#libIdChange").val();
			 var thistmp=$("input[name='type']:checked");
			 var salesPriceId=thistmp.val();
			 var price_species=thistmp.attr("data-species");
			 var price_type=thistmp.attr("data-type");
			 var aliases=thistmp.attr("data-aliases");
			 var staffing_type=$("#salesUserId").find("option:selected").attr("data-type");
			 var price=$("#price").val();
			 var vip=$("#vip").val();
			 var details='';
			 var salesUserId=$("#salesUserId").find("option:selected").attr("data-userId");
			 if(libId==''){
				 alert("请选择图书馆");
				 return;
			 }
			 if(staffing_type==undefined || staffing_type==null || staffing_type==''){
				 alert("请选择服务跟进人");
				 return;
			 }
			 if(price_species==undefined || price_species==null || price_species==''){
				 alert("请选择会员卡类型");
				 return;
			 }
			 if(salesPriceId==undefined || salesPriceId==null || salesPriceId==''){
				 alert("请选择会员卡类型");
				 return;
			 }
			 if(vip==''){
				 alert("请输入会员卡号");
				 return;
			 }
			 if(price==''){
				 alert("请输入价格");
				 return;
			 }
			 details=$("input[value='"+price_species+"']").attr("data-text")+aliases;
			 var content ="您确定要新增记录吗?";
			 parent.layer.confirm(content, {
				icon: 4, btn: ['确定','关闭'] //按钮
			 }, function(){
					 var url =path+"/sys/order/saveLineOrderDetails";
		       		 var params ={
		       				 'price':price,
		       				 'salesPriceId':salesPriceId,//卡片明细ID
		       				 'salesUserId' : salesUserId,
		       				 'libId' : libId,
		       				 'details' : details,
		       				 'know' : '财务手动添加',
		       				 'priceSpecies' : price_species,//卡的种类1普通卡，2荣誉馆长，3学霸卡
		       				 'priceType' : price_type,//1年卡，2半年卡，3季度卡，（卡种类为3）1 单次卡，2 VIP专席卡40小时，3 VIP专席卡120小时
		       				 'staffingType' : staffing_type,//人员类型
		       				 'code' :vip
		       		 };
		   			$.post(url,params,function(data){
		   				if (data.code == 999) {
		   					parent.layer.msg("新增成功",{icon:1});
		       				window.location.href=window.location.href;
		   				 }else{
		   					parent.layer.msg("新增失败！"+data.msg,{icon:0});
		   				 }
		   			});
			 });
		 }
		 //服务跟进人	
		 function queryStaffingList(libId){
			var url=path+"/sys/order/libStaffingList";
			$.ajax({
		        url:url,
		        dataType:'json',
		        cache:false,
		        type:'post',
		        data:{
		        	libId:libId
		        },
		        error:function(){return false;},
		        success:function(data){
		        	var temp=[],obj=data.data.data;
	        		for(var i=0,len=obj.length;i<len;i++){
	        			temp.push('<option value="'+obj[i].id+'" data-userId="'+obj[i].userId+'" data-type="'+obj[i].type+'">'+obj[i].name+'</option>')
	        		}
		      		$("#salesUserId").append(temp.join(''));
		        }
		    });
		 }
		//卡片明细ID  querySalesPriceList
		function querySalesPriceList(libId){
			var url=path+"/sys/order/salesPriceList";
			$.ajax({
		        url:url,
		        dataType:'json',
		        cache:false,
		        type:'post',
		        data:{
		        	libId:libId
		        },
		        error:function(){return false;},
		        success:function(data){
		        	S001=[],S002=[],S003=[];
		        	var temp=[],obj=data.data.data;
	        		for(var i=0,len=obj.length;i<len;i++){
	        			
	        			var html='<strong><input type="radio" name="type" data-aliases="'+obj[i].aliases+'" data-species="'+obj[i].species+'"  data-type="'+obj[i].type+'" value="'+obj[i].id+'">'+obj[i].name+'</strong>';
	        			if(obj[i].species=='S001'){
	        				S001.push(html);
	        			}else if(obj[i].species=='S002'){
	        				S002.push(html);
	        			}else if(obj[i].species=='S003'){
	        				if(obj[i].type != 'C005'){
	        					S003.push(html);
	        				}
	        				
	        			} 
	        		}
		        }
		    });
		}
	})
</script>

</html>