
<html>
<head>
<title>私塾家</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="icon" href="/favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<link th:href="@{/static/sys/css/main.css}" rel="stylesheet"/>
<link th:href="@{/static/sys/css/select.css}" rel="stylesheet"/>
<script src="sys/js/My97DatePicker/WdatePicker.js" th:src="@{/static/sys/js/My97DatePicker/WdatePicker.js}"></script>
<style>
	.tablelink{margin-right:10px;}
	td img{  
                cursor: pointer;  
                transition: all 0.6s;  
    }  
   td img:hover{  
                transform: scale(2.5);  
    } 
</style>

 
<script src="/static/js/jquery-2.2.4.min.js"></script>
<script src="/static/js/layer/layer.js"></script>
<script src="/static/js/city/city.json.js"></script>
<script src="/static/js/city/citySetMe_V.js"></script>
<script src="/static/js/city/Popt.js"></script>

</head>
 <style type="text/css">
   	  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;
   	  }
   	 .btn{
   	  		width: 100px;
   	 }
   	 input{
   			margin-bottom: 10px;
   	 }

    </style>
<body>

	<div class="formbody" id="studentServiceEdit">
		<div style="margin-left: 25px">
			<h1 style="font-size: 18px">[[${libVip.childName}]]&nbsp;</h1>
			<span>[[${libVip.school}]]&nbsp;</span>
			<span>&nbsp;</span>
			<span th:if="${libVipServices.size()>0}">已有的服务</span>
			<span th:if="${libVipServices.size()<=0 && libVipServices_S999.size()<=0}">暂无服务</span>
			<span th:each="item:${libVipServices}" th:text="${item.startTime+'&nbsp;--&nbsp;'+item.endTime+'&nbsp;（'+(item.correctType==1 || item.correctType==null ? '平台批改' : item.correctType==2 ? '机构自批改' : item.correctType==3 ? '家长自批改' : '') +'）'}"></span>
			<span th:each="item:${libVipServices_S999}" th:text="${item.startTime+'&nbsp;--&nbsp;'+item.endTime+'&nbsp;（内部用户）'}"></span>
			<span>&nbsp;</span>
			<input type="hidden" id="vip_id" name="vip_id" th:value="${libVip.id}">
			<input type="hidden" id="lib_id" name="lib_id" th:value="${libJoin.id}">
		</div>
		<ul class="forminfo">

			<li>
				<label>服务日期：<b>*</b></label>
				<div class="vocation" style="margin-right: 5px; width: 345px">
					<input type="text" id="start_time" name="start_time" placeholder="开始日期" autocomplete="off"
						onclick=" WdatePicker({ dateFmt: 'yyyy-MM-dd HH:mm:ss', isShowToday: false, isShowClear: false });"  class="scinput date_width " >
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;月数：
						<select id="service_num" name="service_num" class="select1" style="width: 30%;"> 
							<option  value="1" >1个月</option>
							<option  value="2" >2个月</option>
							<option  value="3" >3个月</option>
							<option  value="4" >4个月</option>
							<option  value="5" >5个月</option>
							<option  value="6" >6个月</option>
							<option  value="7" >7个月</option>
							<option  value="8" >8个月</option>
							<option  value="9" >9个月</option>
							<option  value="10" >10个月</option>
							<option  value="11" >11个月</option>
							<option  value="12" >12个月</option>
							<option  value="13" >13个月</option>
							<option  value="14" >14个月</option>
							<option  value="15" >15个月</option>
							<option  value="16" >16个月</option>
							<option  value="17" >17个月</option>
							<option  value="18" >18个月</option>
							<option  value="19" >19个月</option>
							<option  value="20" >20个月</option>
							<option  value="21" >21个月</option>
							<option  value="22" >22个月</option>
							<option  value="23" >23个月</option>
							<option  value="24" >24个月</option>
							<option  value="25" >25个月</option>
						</select>
				</div>
			</li>
			<li></li>
			<li>
				<label>批改类型：<b>*</b></label>
				<div class="vocation" style="margin-right: 5px; width: 320px">
					<select name="correct_type" id="correct_type" class="select1" > 
						<option  value="1" >平台作业批改服务</option>
						<option  value="2" >软件服务(作业需机构老师自批)</option>
<!-- 						<option  value="3" >软件服务(作业需家长自批)</option> -->
					</select>
				</div>
			</li>
			
		
			<li></li>
			<li></li>
			<li>
				<label>&nbsp;</label>
				<button type="submit" onclick="save();" class="btn" style="width: 150px">确定保存</button>
				<button type="button" onclick="closeWin();" class="btn" style="background: #ccc;">取消添加</button>
			</li>
		</ul>
	</div>
		
</body>
<script type="text/javascript">
function save(){
	if( $("#start_time").val()==''){
		parent.layer.msg("开始时间不能为空",{icon:11});
		return ;
	}
	parent.layer.confirm("您确定要保存学生服务?", {
		icon: 4, btn: ['确定','关闭'],offset: '100px' //按钮
	}, function(){
		var url="[[${sysUrl}]]/sys/imlibuser/student/service/check/[[${libJoin.id}]]/[[${libVip.id}]]";
		var params ={
            'startTime' : $("#start_time").val(),
            'serviceNum' : $("#service_num").val(),
            'correctType' : $("#correct_type").val()
        };
		$.post(url,params,function(data){
			if(data.meta.success){
				
				if(data.data.isService || data.data.isService_S999 ){
					var title="您现在购买的服务时间与此用户现有的服务<br/>";
					var libVipServices=data.data.libVipServices;
					for (var i = 0; i < libVipServices.length; i++) {
						title=title+libVipServices[i].startTime+"&nbsp;--&nbsp;"+libVipServices[i].endTime;
						if(libVipServices[i].correctType==1){
							title=title+"(非自批改)"
						}else{
							title=title+"(自批改)"
						}
						title=title+"<br/>"
					}
					
					var libVipServices_S999=data.data.libVipServices_S999;
					for (var i = 0; i < libVipServices_S999.length; i++) {
						title=title+libVipServices_S999[i].startTime+"&nbsp;--&nbsp;"+libVipServices_S999[i].endTime;
						title=title+"(内部用户服务)"
						title=title+"<br/>"
					}
					
					title=title+"冲突，是否要将现有的服务替换？<br/>";
					
					if(data.data.isService_S999 ){
						title=title+"【内部用户变成普通用户】<br/>";
					}
					parent.layer.confirm(title, {
						icon: 4, btn: ['确定','关闭'],offset: '100px' //按钮
					}, function(){
						
						var url="[[${sysUrl}]]/sys/imlibuser/student/service/save/[[${libJoin.id}]]/[[${libVip.id}]]";
						var params ={
				            'startTime' : $("#start_time").val(),
				            'serviceNum' : $("#service_num").val(),
				            'correctType' : $("#correct_type").val(),
				            'takeType' : 1
				        };
						$.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});
							}
						});
					
					});
					
				}else{
					
					var url="[[${sysUrl}]]/sys/imlibuser/student/service/save/[[${libJoin.id}]]/[[${libVip.id}]]";
					var params ={
			            'startTime' : $("#start_time").val(),
			            'serviceNum' : $("#service_num").val(),
			            'correctType' : $("#correct_type").val(),
			            'takeType' : 2
			        };
					$.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});
						}
					});
					
				}
			}else{
				parent.layer.msg(data.meta.message,{icon:11});
			}
		});
	});
}


function closeWin(){
	parent.location.reload();
	parent.layer.close(parent.layer.getFrameIndex(window.name));
}

</script>
</html>