<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:set var="contextPath" value="${pageContext.request.contextPath}"></c:set>
  
<%@include file="/WEB-INF/page/header.jsp" %>
<script>changeMenu(3,4);//左边菜单active</script>
<div class="row wrapper border-bottom white-bg page-heading">
	<div class="col-lg-10">
		<h2>资料设置</h2>
		<ol class="breadcrumb">
			<li>主页</li>
			<li><a>资料设置</a></li>
			<li class="active"><strong>服务承诺</strong></li>
		</ol>
	</div>
	<div class="col-lg-2">
		<div style="padding-top:25px">
		<c:if test="${sessionScope.SESSION_COMPANY.canApply}">
			<button class="btn btn-primary btn-lg" type="button" onclick="submitAll()">提交全部页面</button>
		</c:if>
		<c:if test="${sessionScope.SESSION_COMPANY.companyState==1}">
			认证申请中
		</c:if>
		</div>
	</div>
</div>

<div class="wrapper wrapper-content animated fadeInRight">
		<div class="row">
			<div class="col-md-12">
				<div class="ibox float-e-margins">
					<div class="ibox-content lightBoxGallery">
					<form class="form-horizontal">
						<div class="form-group">
							<label class="col-sm-10 control-label">
								<h3 class="text-left">服务承诺</h3>
							</label>
						</div>
						<div class="hr-line-dashed"></div>
						<div class="form-group">
							<label class="col-sm-2 control-label">审核承诺 </label>
							<div class="col-sm-2"> </div>
							<div class="col-sm-2 text-center">
								<select class="form-control" id="checkDays">
									<option value="">选择天数</option>
									<option value="0">0工作日</option>
									<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>
								</select>
							</div>
							<div class="col-sm-2 text-center" id="checkHoursDiv">
								<select class="form-control" id="checkHours">
									<option value="">选择小时</option>
									<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>
								</select>
							</div>
							<div class="col-sm-2"><p class="form-control-static text-left">内出审核结果。</p></div>
						</div>
						<div class="hr-line-dashed"></div>
						<div class="form-group">
							<label class="col-sm-2 control-label">确认收款承诺 </label>
							<div class="col-sm-2"> </div>
							<div class="col-sm-2 text-center">
								<select class="form-control" id="confirmDays">
									<option value="">选择天数</option>
									<option value="0">0工作日</option>
									<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>
								</select>
							</div>
							<div class="col-sm-2 text-center" id="confirmHoursDiv">
								<select class="form-control" id="confirmHours">
									<option value="">选择小时</option>
									<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>
								</select>
							</div>
							<div class="col-sm-2"><p class="form-control-static text-left">内确认收款。</p></div>
						</div>
						<div class="hr-line-dashed"></div>
						<div class="form-group">
							<label class="col-sm-2 control-label">出函承诺 </label>
							<div class="col-sm-2"><p class="form-control-static text-right">申请人付款后</p></div>
							<div class="col-sm-2 text-center">
								<select class="form-control" id="sendDays">
									<option value="">选择天数</option>
									<option value="0">0工作日</option>
									<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>
								</select>
							</div>
							<div class="col-sm-2 text-center" id="sendHoursDiv">
								<select class="form-control" id="sendHours">
									<option value="">选择小时</option>
									<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>
								</select>
							</div>
							<div class="col-sm-2"><p class="form-control-static text-left">内出保函。</p></div>
						</div>
						<div class="hr-line-dashed"></div>
						<div class="form-group">
							<label class="col-sm-2 control-label">保单发票送达 </label>
							<div class="col-sm-2"><p class="form-control-static text-right">提供</p></div>
							<div class="col-sm-4 text-center">
								 	<label class="checkbox-inline"> <input type="checkbox" id="file2Deliver1"> 上门配送 </label> <label class="checkbox-inline">
                                        <input type="checkbox" id="file2Deliver2"> 快递配送（顺丰/EMS） </label>
							</div>
							
							<div class="col-sm-2"><p class="form-control-static text-left">服务。</p></div>
						</div>
						<div class="hr-line-dashed"></div>
						<div class="form-group">
							<div class="col-sm-12 text-center">
								<button class="btn btn-primary" type="button" id="saveParam">保存</button>
							</div>
						</div>
						</form>
					</div>
				</div>
			</div>
		</div>
</div>

<%@include file="/WEB-INF/page/footer.jsp" %>    
<script>
function submitAll(){
	$.getJSON('${contextPath}/company/submitAll',function(result){
		if(result.success){
			alert('提交成功！');
			location.reload();
		}else
			alert(result.message);
	});
}

jQuery(function($) {
	
		$('#checkDays').val('${p.checkDays}');
		$('#checkHours').val('${p.checkHours}');
		$('#confirmDays').val('${p.confirmDays}');
		$('#confirmHours').val('${p.confirmHours}');
		$('#sendDays').val('${p.sendDays}');
		$('#sendHours').val('${p.sendHours}');
		var value = ${p.deliver2};
		if(value == 0){
			$('#file2Deliver1').attr("checked","checked");
		}else if(value == 1){
			$('#file2Deliver2').attr("checked","checked");
		}else if(value == 2){
			$('#file2Deliver1').attr("checked","checked");
			$('#file2Deliver2').attr("checked","checked");
		}
		
		if(${p.checkDays>0}) $('#checkHoursDiv').hide();
		if(${p.confirmDays>0}) $('#confirmHoursDiv').hide();
		if(${p.sendDays>0}) $('#sendHoursDiv').hide();
		
		$('#saveParam').on('click', function() {
	   		if($("#checkDays").val()==''||$("#confirmDays").val()==''||$("#sendDays").val()==''){
	   			alert("请选择天数！");
	   			return;
	   		}
	   		var checkDays= $("#checkDays").val();
	   		var checkHours= $("#checkHours").val();
	   		var sendDays= $("#sendDays").val();
	   		var sendHours= $("#sendHours").val();
	   		var confirmDays= $("#confirmDays").val();
	   		var confirmHours= $("#confirmHours").val();
			
			if(checkDays>0) checkHours=0;
			if(confirmDays>0) confirmHours=0;
			if(sendDays>0) sendHours=0;
			var delivers = [-1,-1];
			var deliverChecked1,deliverChecked2,deliverMsg = null;
			for(var i=2;i<3;i++){
				deliverChecked1 = document.getElementById('file' + i + 'Deliver1').checked;
				deliverChecked2 = document.getElementById('file' + i + 'Deliver2').checked;
				if(deliverChecked1 && deliverChecked2){
					delivers[i - 1] = 2;
				}else if(deliverChecked1){
					delivers[i - 1] = 0;
				}else if(deliverChecked2){
					delivers[i - 1] = 1;
				}else{
					if(i == 1){
						deliverMsg = '请选择保函送达方式';
					}else{
						deliverMsg = '请选择保单发票送达方式';
					}
					alert(deliverMsg);
					return;
				}
			}
			$.ajax({
				url : "${contextPath}/company/setting4Save",
				data : {
					checkDays: checkDays,
					checkHours: checkHours,
					sendDays: sendDays,
					sendHours: sendHours,
					confirmDays: confirmDays,
					confirmHours: confirmHours,
					deliver2: delivers[1],
				},
				type : 'POST',
				dataType : 'json',
				complete : function(response) {
					if(response.success){
						alert('保存成功！');
					}else
						alert(response.message);
					
				}
			});
		});
		
		
		$('#checkDays').on('change', function() {
	   		if($('#checkDays').val()>0){
	   			$('#checkHoursDiv').hide();
	   			$('#checkHours').val("0");
	   		}else{
	   			$('#checkHoursDiv').show();
	   		}
		});
		$('#confirmDays').on('change', function() {
	   		if($('#confirmDays').val()>0){
	   			$('#confirmHoursDiv').hide();
	   			$('#confirmHours').val("0");
	   		}else{
	   			$('#confirmHoursDiv').show();
	   		}
		});
		$('#sendDays').on('change', function() {
	   		if($('#sendDays').val()>0){
	   			$('#sendHoursDiv').hide();
	   			$('#sendHours').val("0");
	   		}else{
	   			$('#sendHoursDiv').show();
	   		}
		});
	});
</script>