<%@ 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,1);//左边菜单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 id="companyForm" class="form-horizontal">
                            <div class="form-group">
                            	<label class="col-sm-2 control-label">
                            		公司LOGO
                            	</label>
                                <div class="col-sm-10 text-left">
                                	<div id="div11" class="checkbox-inline"></div>
									<button class="btn btn-primary btn-white checkbox-inline" type="button" onclick="uploadPic(11)">上传图片</button>
                                    <span> 尺寸 2:1，不超过1M</span> 
								</div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                            	<label class="col-sm-2 control-label">
                            		公司宣传图
                            	</label>
                                <div class="col-sm-10 text-left">
                                	<div id="div12" class="checkbox-inline"></div>
									<button class="btn btn-primary btn-white checkbox-inline" type="button" onclick="uploadPic(12)">上传图片</button>
                                    <span> 尺寸 16:9，不超过1M</span> 
								</div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                            	<label class="col-sm-2 control-label">
                            		公司营业执照
                            	</label>
                                <div class="col-sm-10 text-left">
		                            <div id="div13" class="checkbox-inline"></div>
									<button class="btn btn-primary btn-white checkbox-inline" type="button" onclick="uploadPic(13)">上传图片</button>
								</div>
                            </div>
                            
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                            	<label class="col-sm-2 control-label">
                            		保函样式
                            	</label>
                                <div class="col-sm-10 text-left">
		                            <div id="div21" class="checkbox-inline"></div>
									<button class="btn btn-primary btn-white checkbox-inline" type="button" onclick="uploadPic(21)">上传图片</button>
								</div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                            	<label class="col-sm-2 control-label">
                            		保单样式
                            	</label>
                                <div class="col-sm-10 text-left">
		                            <div id="div22" class="checkbox-inline"></div>
									<button class="btn btn-primary btn-white checkbox-inline" type="button" onclick="uploadPic(22)">上传图片</button>
								</div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                            	<label class="col-sm-2 control-label">
                            		<c:if test="${sessionScope.SESSION_COMPANY.companyType==0}">
                            			服务合同<br/>
                            		</c:if>
                            		<c:if test="${sessionScope.SESSION_COMPANY.companyType==1}">
                            			保险条款<br/>
                            		</c:if>
                            	</label>
                                <div class="col-sm-10 text-left">
		                                <div id="div23" class="checkbox-inline"></div>
										<button class="btn btn-primary btn-white checkbox-inline" type="button" onclick="uploadFile(23)">上传文件</button>
								</div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                            	<label class="col-sm-2 control-label">
                            		公司简介
                            	</label>
                                <div class="col-sm-5 text-left">
		                             <textarea class="form-control" rows="4" id="info">${sessionScope.SESSION_COMPANY.info}</textarea> 
		                             <span class="help-block m-b-none" id="maxtext">不超过500字</span>
								</div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                            	<label class="col-sm-2 control-label">
                            		客服电话
                            	</label>
                                <div class="col-sm-5 text-left">
		                             <input type="text" id="tel" class="form-control" value="${sessionScope.SESSION_COMPANY.tel}">
								</div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                            	<label class="col-sm-2 control-label">
                            		批复文号
                            	</label>
                                <div class="col-sm-5 text-left">
		                             <input type="text" id="noReply" class="form-control" value="${sessionScope.SESSION_COMPANY.noReply}">
								</div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                            	<label class="col-sm-2 control-label">
                            		备案编号
                            	</label>
                                <div class="col-sm-5 text-left">
		                             <input type="text" id="noRegister" class="form-control" value="${sessionScope.SESSION_COMPANY.noRegister}">
								</div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                            	<label class="col-sm-2 control-label">
                            		报备文件编号
                            	</label>
                                <div class="col-sm-5 text-left">
		                             <input type="text" id="noFile" class="form-control" value="${sessionScope.SESSION_COMPANY.noFile}">
								</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="saveButton">保存本页面</button>
                                </div>
                            </div>
                        </form>
					</div>
				</div>
			</div>
		</div>
</div>

<div id="mod-pic" class="modal fade" tabindex="-1">
	<div class="modal-dialog" style="max-width: 500px;">
		<div class="modal-content">
			<div class="modal-header no-padding">
				<div class="table-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
						<span class="white">&times;</span>
					</button>
					图片上传
				</div>
			</div>
			<div class="modal-body">
				<div class="row">
					<div class="col-xs-12">
						<!-- PAGE CONTENT BEGINS -->
						<form id="picform" method="post" action="${applicationScope.ServerC}/ssdbExampleUpload">
							<input  type="file" name="avatar" multiple />
							<input type="hidden" name="attachType" id="mod-pic-attachType"/>
							<input type="hidden" name="companyId" value="${sessionScope.SESSION_COMPANY.id}"/>
							<div class="hr hr-12 dotted"></div>
							<div class="text-center">
							<button type="submit" class="btn btn-sm btn-primary">上传</button>
							<button type="reset" class="btn btn-sm">清除</button>
							</div>
						</form>
					</div><!-- /.col -->
				</div><!-- /.row -->
				
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal-dialog -->
</div>

<div id="mod-file" class="modal fade" tabindex="-1">
	<div class="modal-dialog" style="max-width: 500px;">
		<div class="modal-content">
			<div class="modal-header no-padding">
				<div class="table-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
						<span class="white">&times;</span>
					</button>
					文件上传
				</div>
			</div>
			<div class="modal-body">
				<div class="row">
					<div class="col-xs-12">
						<!-- PAGE CONTENT BEGINS -->
						<form id="fileform" method="post" action="${applicationScope.ServerC}/ssdbExampleUpload">
							<input  type="file" name="avatar" multiple />
							<input type="hidden" name="attachType" id="mod-file-attachType"/>
							<input type="hidden" name="companyId" value="${sessionScope.SESSION_COMPANY.id}"/>
							<div class="hr hr-12 dotted"></div>
							<div class="text-center">
							<button type="submit" class="btn btn-sm btn-primary">上传</button>
							<button type="reset" class="btn btn-sm">清除</button>
							</div>
						</form>
					</div><!-- /.col -->
				</div><!-- /.row -->
				
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal-dialog -->
</div>

<div id="mod-show" class="modal fade" tabindex="-1">
	<div class="modal-dialog"  style="max-width: 800px;">
		<div class="modal-content">
			<div class="modal-body text-center no-padding">
				<input type="hidden" id="mod-show-id">
				<input type="hidden" id="mod-show-type">
				<img id="mod-show-img">
			</div>
			
		</div><!-- /.modal-content -->
		<div >
      	<button class="btn  btn-danger" type="button" id="deletePicButton"><strong> 删除</strong></button>
        </div>
	</div><!-- /.modal-dialog -->
</div>

<%@include file="/WEB-INF/page/footer.jsp" %>

<link rel="stylesheet" href="${contextPath}/static/ssdb/ace.fileinput.css"/>
<script type="text/javascript" src="${contextPath}/static/ssdb/ace.fileinput.js"></script>  
<script type="text/javascript" src="${contextPath}/static/ssdb/picupload.js?v=2"></script>
<script type="text/javascript" src="${contextPath}/static/ssdb/fileupload.js?v=2"></script>
  
<script>
	
	function showPic(url,id,type){
		$("#mod-show-id").val(id);
		$("#mod-show-type").val(type);
		$("#mod-show-img").attr("src",url);
		$("#mod-show").modal("toggle");
	}
	
    function uploadPic(attachType){
    	$("#mod-pic").modal("toggle");
    	$("#mod-pic-attachType").val(attachType);
    }
    
    function uploadSuccess(){
    	$("#mod-pic").modal("toggle");
    	var t = $("#mod-pic-attachType").val();
    	loadPic(t);
    }
    
    function uploadFile(attachType){
    	$("#mod-file").modal("toggle");
    	$("#mod-file-attachType").val(attachType);
    }
    
    function uploadFileSuccess(){
    	$("#mod-file").modal("toggle");
    	var t = $("#mod-file-attachType").val();
    	loadPic(t);
    }
    
    function loadPic(attachType){
    	var d = "#div"+attachType;
    	$(d).html('');
    	$.getJSON('${contextPath}/company/setting1GetPic?attachType='+attachType,function(result){
    		var sec='';
    		$.each(result, function(i, v){
    			//alert("${ServerC}/ssdbExamplePic?companyAttachId="+v.id);
    			var url = "${applicationScope.ServerC}/ssdbExamplePic?companyAttachId="+v.id+"&ver="+Math.random();
    			var height=100;
    			var width=100;
    			if(attachType==11){height=50;}
    			if(attachType==12){height=90;width=160;}
				/*
    			if(attachType==23){
    				sec+='<a href="'+url+'" target="_blank"><i class="fa fa-file"></i>投保单</a>&nbsp;';
    			}else{
    				sec+='<a href="javascript:void(0);" onclick="showPic(\''+url+'\',\''+v.id+'\',\''+attachType+'\')">';
        			sec+='<img src="'+url+'" height="'+height+'" width="'+width+'" id="'+v.id+'">';
        			sec+='</a>&nbsp;';
    			}*/
				sec+='<a href="javascript:void(0);" onclick="showPic(\''+url+'\',\''+v.id+'\',\''+attachType+'\')">';
				sec+='<img src="'+url+'" height="'+height+'" width="'+width+'" id="'+v.id+'">';
				sec+='</a>&nbsp;';
    		 });
    		$(d).html(sec);
    	});
    }
    
    function submitAll(){
    	$.getJSON('${contextPath}/company/submitAll',function(result){
    		if(result.success){
				alert('提交成功！');
				location.reload();
			}else
				alert(result.message);
    	});
    }
    
    jQuery(function($) {
    	
    	loadPic(11);
    	loadPic(12);
    	loadPic(13);
    	loadPic(21);
    	loadPic(22);
    	loadPic(23);
    	
    	$('#info').on('keyup',function(){
    	      var txtval = $('#info').val().length;
    	      var str = parseInt(500-txtval);
    	      if(str > 0 ){
    	          $('#maxtext').html('剩余可输入'+str+'字');
    	      }else{
    	          $('#maxtext').html('剩余可输入0字');
    	          $('#info').val($('#info').val().substring(0,500)); //这里意思是当里面的文字小于等于0的时候，那么字数不能再增加，只能是600个字
    	        }
    	    });
    	
    	$('#saveButton').on('click', function() {
    		var infoText = $("#info").val();
    		if(infoText.length >500){
    			alert('公司简介不能超过500字');
    			return;
    		}
    		$.ajax({
    			url : "${contextPath}/company/setting1Save",
    			data : {
    				info : infoText,
    				tel : $("#tel").val(),
    				noReply : $("#noReply").val(),
    				noRegister : $("#noRegister").val(),
    				noFile : $("#noFile").val()
    			},
    			type : 'POST',
    			dataType : 'json',
    			success : function(data) {
    				if(data.success){
    					alert('保存成功！');
    				}else
    					alert(data.message);
    			}
    		});
    	});
    	
    	$('#deletePicButton').on('click', function() {
    		var id = $("#mod-show-id").val();
    		var type = $("#mod-show-type").val();
    		if (confirm("确定删除吗?")) {
    			$.getJSON('${contextPath}/company/setting1DeletePic?id='+id,function(result){
    				if(result.success){
    					loadPic(type);
    				}else
    					alert(result.message);
    				$("#mod-show").modal("toggle");
    			});
    		}
    	});
    });
</script>

