<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>企业信息管理</title>
	<meta name="decorator" content="default"/>
	<style type="text/css">
		img{
			/*width: 50px;*/
			/*height: 50px;*/
			max-width: 50px;
			max-height: 50px;
		}
	</style>
	<script type="text/javascript">
        // $(function(){
        //     $("img").not(".upload_ico").each(function () {
        //         var num = 1 ;
        //         $(this).click(function () {
        //             var flag = num%2;
        //             if(flag == 1){
        //                 $(this).css("width","90%");
        //                 $(this).css("height","90%");
        //                 num++;
        //             }else if(flag ==0){
        //                 $(this).css("width","50px");
        //                 $(this).css("height","50px");
        //                 num++;
        //             }
        //         })
        //     });
        // });

	var validateForm;
        String.prototype.endsWith=function(str){
            var reg=new RegExp(str+"$");
            return reg.test(this);
        }
        function submit(callback){
		if(validateForm.form()){
            var obj =$("#this_upload_file_1")[0].files[0];
            var r=false;
            if(obj != null && obj != undefined && obj != ""){
                var fileType = obj.type;
                r = fileType.endsWith("png")||fileType.endsWith("bmp")||fileType.endsWith("jpg")||fileType.endsWith("jpeg");
            }
			if(r){
                $("#inputForm").submit();
                callback();
                return true;
            }else{
                parent.layer.msg("请上传营业执照!!!",{icon:5});
                $("#this_upload_msg").css({"color":"red"});
                return false;
            }
		}
		return false;
	}
	function reset(){
	     $('#inputForm').reset();
	}
	function tijiao(){
	    submit(reset);
	}
	
		var validateForm;
		function doSubmit(){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
//			var nameT = $("#nameT").val();
//            if(!/[\u4e00-\u9fa5]+/.test( value )){
//                parent.layer.msg("必须包含汉字");
//                return false;
//			}
		  if(validateForm.form()){
			  $("#inputForm").submit();
			  return true;
		  }
	
		  return false;
		}
		$(document).ready(function() {
            $.validator.addMethod("checkName",function(value,element,params){
                var checkEmail = /[\u4e00-\u9fa5]+/i;
                return this.optional(element)||(checkEmail.test(value));
            },"必须包含汉字!");
            $.validator.addMethod("checkNumber",function(value,element,params){
                var regExp = /^[0-9A-Z]{0,18}$/;
                return this.optional(element)||(regExp.test(value));
            },"请输入18位数字或大写字母组合!");
			validateForm = $("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
					/*$("#messageBox").succuss("提交成功。");*/
				},
                rules : {
                    name: {
                        checkName: true,
                        remote: "${ctx}/sys/company/validateCompany"
                    },
                    number:{
                        checkNumber:true,
                        remote: "${ctx}/sys/company/checkNumber"
					},
                },
                messages: {
                    name:{remote: "此公司名称已经被注册!", required: "公司名称不能为空."},
                    number:{remote: "此组织机构代码已存在!", required: "组织机构代码不能为空."},
                },
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});


    <%--//上传营业执照--%>
        function this_upload_image_button(index){
            $("#this_upload_file_"+index).click();
        }
        function this_upload_show_image(index){
            var obj =$("#this_upload_file_"+index)[0].files[0];
            var fileType = obj.type;
            var url ;
            if(fileType.endsWith("png")||fileType.endsWith("bmp")||fileType.endsWith("jpg")||fileType.endsWith("jpeg")||fileType.endsWith("gif")){
                url = window.URL.createObjectURL(obj);
            }else {
                $("#this_upload_msg").css({"color":"red"});
                this_close_img(index);
                return false ;
            }
            $("#this_upload_msg" + "index").removeAttr("style");
            $("#this_upload_image_"+index).attr("src",url);

            var span = '<span id="this_upload_close_'+index+'" class="pic_close glyphicon glyphicon-remove" onclick="this_close_img('+index+');"></span>';
            $("#this_upload_image_" + index).before(span);
        }

        function this_close_img(index) {
            $("#this_upload_div_"+index).remove();
            this_add_div(index);
        }

        function this_add_div(index) {
            var this_upload_div_1 =
                '<div id="this_upload_div_'+ index + '" style="position:relative;">'+
                '<img  id="this_upload_image_' + index + '" class="upload_ico" style="cursor:pointer;"  src="${pageContext.request.contextPath}/static/common/img/pic_add.png"  onclick="this_upload_image_button('+index+')"/>'+
                '<input id="this_upload_file_'+ index + '" type="file" style="display:none"  name="this_upload_files"  onchange="this_upload_show_image('+index+ ')" /><br>'+
                '</div>';
            $("#this_upload_image_div_"+ index).html("").append(this_upload_div_1);
        }
    <%--function this_upload_image_button(index){--%>
        <%--$("#this_upload_file_"+index).click();--%>
    <%--}--%>
    <%--function this_upload_show_image(index){--%>
        <%--var obj =$("#this_upload_file_"+index)[0].files[0];--%>
        <%--var fileType = obj.type;--%>
        <%--var url ;--%>
        <%--if(fileType.endsWith("png")||fileType.endsWith("bmp")||fileType.endsWith("jpg")||fileType.endsWith("jpeg")){--%>
            <%--url = window.URL.createObjectURL(obj);--%>
        <%--}else {--%>
            <%--$("#this_upload_msg").css({"color":"red"});--%>
            <%--this_close_img(index);--%>
            <%--return false ;--%>
        <%--}--%>
        <%--$("#this_upload_msg").removeAttr("style");--%>
        <%--$("#this_upload_image_"+index).attr("src",url);--%>
        <%--var length = $("#this_upload_image_div :file").length;--%>
        <%--if( index == length &&  length < 1 ){--%>
            <%--this_upload_image_append(index);--%>
            <%--this_add_x(index);--%>
        <%--}else if(index == length && length ==1){--%>
            <%--var span = '<span id="this_upload_close_'+index+'" class="close_ico" style="cursor:pointer; position: absolute;top:-1px;right: -1px; display:inline-block;z-index:1;color: red;" onclick="this_close_img('+index+');">x</span>';--%>
            <%--$("#this_upload_image_1").before(span);--%>
        <%--}--%>
    <%--}--%>
    <%--function this_upload_image_append(index){--%>
        <%--var div1 = "<div id='this_upload_div_"+(index+1)+"' style='float:left;position:relative;width: 57px;height: 57px;'>";--%>
        <%--var img = '<img  id="this_upload_image_'+(index+1)+'" class="upload_ico" width="50px" height="50px"  onclick="this_upload_image_button('+(index+1)+')" src = "${pageContext.request.contextPath}/static/uploadify/upload_ico.png" style="cursor:pointer;"/>';--%>
        <%--var input = '<input id="this_upload_file_'+(index+1)+'" type="file" style="display:none;" name="this_upload_files" onChange="this_upload_show_image('+(index+1)+')" /><br>';--%>
        <%--var div2 = "</div>";--%>

        <%--$("#this_upload_image_div").append(div1+img+input+div2);--%>
    <%--}--%>
    <%--function this_close_img(index) {--%>
        <%--$("#this_upload_div_"+index).remove();--%>
        <%--var length = $("#this_upload_image_div :file").length;--%>
        <%--if(length == 0){--%>
            <%--this_add_div();--%>
        <%--}else if(length == 1){--%>
            <%--var x = $("#this_upload_image_div").find("span").text();--%>
            <%--if("x" != x){--%>
                <%--this_add_div();--%>
            <%--}--%>
        <%--}--%>
    <%--}--%>
    <%--function this_add_x(index) {--%>
        <%--var span = '<span id="this_upload_close_'+index+'" class="close_ico" style="cursor:pointer; position: absolute;top:-1px;right: -1px; display:inline-block;z-index:1;color: red;" onclick="this_close_img('+index+');">x</span>';--%>
        <%--$("#this_upload_image_div").find("img:eq(-2)").before(span);--%>
    <%--}--%>
    <%--function this_add_div() {--%>
        <%--var this_upload_div_1 =--%>
            <%--'<div id="this_upload_div_1" style="float: left;position:relative;width: 57px;height: 57px;" >'+--%>
            <%--'<img  id="this_upload_image_1" class="upload_ico" style="cursor:pointer;"  src="${pageContext.request.contextPath}/static/uploadify/upload_ico.png"  onclick="this_upload_image_button(1)"/>'+--%>
            <%--'<input id="this_upload_file_1" type="file" style="display:none"  name="this_upload_files"  onchange="this_upload_show_image(1)" /><br>'+--%>
            <%--'</div>';--%>
        <%--$("#this_upload_image_div").html("").append(this_upload_div_1);--%>
    <%--}--%>


    //上传公司logo
    function next_upload_image_button(index){
        $("#next_upload_file_"+index).click();
    }

    function next_upload_show_image(index){
        var obj =$("#next_upload_file_"+index)[0].files[0];
        var fileType = obj.type;
        var url ;
        if(fileType.endsWith("png")||fileType.endsWith("bmp")||fileType.endsWith("jpg")||fileType.endsWith("jpeg")){
            url = window.URL.createObjectURL(obj);
        }else {
			$("#next_upload_msg").css({"color":"red"});
			next_close_img(index);
		    return false ;
		}
		$("#next_upload_msg").removeAttr("style");
        $("#next_upload_image_"+index).attr("src",url);
        var length = $("#next_upload_image_div :file").length;
        // if( index == length &&  length < 1 ){
        //     next_upload_image_append(index);
        //     next_add_x(index);
        // }else if(index == length && length ==1){
            var span = '<span id="this_upload_close_'+index+'" class="pic_close glyphicon glyphicon-remove" onclick="next_close_img('+index+');"></span>';
            // var span = '<span id="next_upload_close_'+index+'" class="close_ico" style="cursor:pointer; position: absolute;top:-1px;right: -1px; display:inline-block;z-index:1;color: red;" onclick="next_close_img('+index+');">x</span>';
            $("#next_upload_image_1").before(span);
        // }
    }
    <%--function next_upload_image_append(index){--%>
        <%--var div1 = "<div id='next_upload_div_"+(index+1)+"' style='float:left;position:relative;width: 57px;height: 57px;'>";--%>
        <%--var img = '<img  id="next_upload_image_'+(index+1)+'" class="upload_ico" width="50px" height="50px"  onclick="next_upload_image_button('+(index+1)+')" src = "${pageContext.request.contextPath}/static/uploadify/upload_ico.png" style="cursor:pointer;"/>';--%>
        <%--var input = '<input id="next_upload_file_'+(index+1)+'" type="file" style="display:none;" name="next_upload_files" onChange="next_upload_show_image('+(index+1)+')" /><br>';--%>
        <%--var div2 = "</div>";--%>

        <%--$("#next_upload_image_div").append(div1+img+input+div2);--%>
    <%--}--%>
    function next_close_img(index) {
        $("#next_upload_div_"+index).remove();
        // var length = $("#next_upload_image_div :file").length;
        // if(length == 0){
            next_add_div();
        // }else if(length == 1){
        //     var x = $("#next_upload_image_div").find("span").text();
        //     if("x" != x){
        //         next_add_div();
        //     }
        // }
    }
    // function next_add_x(index) {
    //     var span = '<span id="next_upload_close_'+index+'" class="close_ico" style="cursor:pointer; position: absolute;top:-1px;right: -1px; display:inline-block;z-index:1;color: red;" onclick="next_close_img('+index+');">x</span>';
    //     $("#next_upload_image_div").find("img:eq(-2)").before(span);
    // }
    function next_add_div() {
        var next_upload_div_1 =
            '<div id="next_upload_div_1" style="position:relative;" >'+
            '<img  id="next_upload_image_1" class="upload_ico" style="cursor:pointer;"  src="${pageContext.request.contextPath}/static/common/img/pic_add.png"  onclick="next_upload_image_button(1)"/>'+
            '<input id="next_upload_file_1" type="file" style="display:none"  name="next_upload_files"  onchange="next_upload_show_image(1)" /><br>'+
            '</div>';
        $("#next_upload_image_div").html("").append(next_upload_div_1);
    }

	</script>

	<script type="text/javascript">
		$(function () {
		    //检查统一社会信用代码：
//            $("#reditcode").bind("input propertychange",function(){
//                var defValue = this.defaultValue;
//                var currValue = $(this).val();
//                var  regExp = /(^[0-9A-Z]{0,18}$)/;
//                if(! regExp.test(currValue)){
//                    $(this).val(defValue);
//                }else{
//                    this.defaultValue = currValue;
//                }
//            });
        })
        String.prototype.endWith=function(str) {
            if (str == null || str == "" || this.length == 0 || str.length > this.length) return false;
            if (this.substring(this.length - str.length) == str) return true; else return false;
            return true;
        }
	</script>
	<c:if test="${empty company.id}">
		<style>
			body{
				background-color:transparent;
				filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#26FFFFFF, endColorstr=#26FFFFFF);
				background-color:rgba(255,255,255,0);
				height:100%;
			}
		</style>
	</c:if>
</head>
<body>

<c:if test="${empty company.id}">
<%--<div class="wrapper wrapper-content">--%>
	<%--<div class="layui-row">--%>
<%--<div class="full-width fl" id="formDiv">--%>
<div class="single-form contentShadow fl" style="background-color: #ffffff;">
	<div class="container1">
</c:if>
<c:if test="${not empty company.id}">
	<div class="single-form">
		<div class="container">
</c:if>

		<form:form id="inputForm" modelAttribute="company" enctype="multipart/form-data" action="${ctx}/sys/company/add" method="post" class="form-horizontal">
		<form:hidden path="id"/>

			<div class="form-group layui-row first lw12">
				<div class="form-group-label"><h2>企业信息</h2></div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>公司名称：</label>
					<div class="layui-input-block">
						<c:choose>
							<c:when test="${empty company.id}">
								<form:input path="name" htmlEscape="false" id="nameT" class="form-control layui-input required"/>
							</c:when>
							<c:otherwise>
								<input readonly="true" class="form-control layui-input required" value="${company.name}"/>
							</c:otherwise>
						</c:choose>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>申请人邮箱：</label>
					<div class="layui-input-block">
						<form:input path="email" htmlEscape="false"  value="${fns:getUser().email}"    class="form-control required email layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label double-line"><span class="require-item">*</span>统一社会信用代码（注册号）：</label>
					<div class="layui-input-block">
						<form:input path="number" htmlEscape="false"  maxlength="18" minlength="18" id="reditcode"   class="form-control required layui-input" placeholder="请输入18位数字或大写字母组合"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>申请人姓名：</label>
					<div class="layui-input-block">
						<c:choose>
							<c:when test="${empty company.id}">
								<form:input type="text" id="tuser" style="display:none" path="tuser.id"  value="${fns:getUser().id}" htmlEscape="false"   class="form-control layui-input" readonly="true" />
								<form:input type="text" id="tuser" path="tuser.name"  value="${fns:getUser().name}" htmlEscape="false"   class="form-control layui-input" readonly="true" />
							</c:when>
							<c:otherwise>
								<input readonly="true" class="form-control layui-input required" value="${company.tuser.name}"/>
							</c:otherwise>
						</c:choose>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label double-line"><span class="require-item">*</span>法人：</label>
					<div class="layui-input-block">
						<c:choose>
							<c:when test="${empty company.id}">
								<form:input path="legalPerson" htmlEscape="false"    class="form-control required layui-input"/>
							</c:when>
							<c:otherwise>
								<input readonly="true" class="form-control layui-input required" value="${company.legalPerson}"/>
							</c:otherwise>
						</c:choose>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label double-line"><span class="require-item">*</span>申请人电话：</label>
					<div class="layui-input-block">
						<form:input path="phone" htmlEscape="false"  value="${fns:getUser().mobile}"  class="form-control required layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6" style="height:180px;">
					<label class="layui-form-label double-line"><span class="require-item">*</span>营业执照：</label>
					<div class="layui-input-block">
						<c:choose>
							<c:when test="${empty company.licences}">
								<div class="pic_box_wrapper">
									<div class="pic_box">
										<div id="this_upload_image_div_1">
											<div id="this_upload_div_1" style="position:relative;">
												<img alt="_blank" id="this_upload_image_1" class="upload_ico" style="cursor:pointer;"   src="${pageContext.request.contextPath}/static/common/img/pic_add.png"  onclick="this_upload_image_button(1)"/>
												<input id="this_upload_file_1" type="file" style="display:none"  name="this_upload_files"  onchange="this_upload_show_image(1)"  class="form-control required"/>
											</div>
										</div>
									</div>
								</div>
								<span id="this_upload_msg">请上传*.png,*.bmp,*.jpg/jpeg格式的图片</span>
								<%--<div>--%>
									<%--<span id="this_upload_msg">请上传*.png,*.bmp,*.jpg/jpeg格式的图片</span><br>--%>
									<%--<div id="this_upload_image_div">--%>
										<%--<div id="this_upload_div_1" style="float: left;position:relative;width: 57px;height: 57px;">--%>
											<%--<img alt="_blank" id="this_upload_image_1" class="upload_ico" style="cursor:pointer;"  src="${pageContext.request.contextPath}/static/uploadify/upload_ico.png"  onclick="this_upload_image_button(1)"/>--%>
											<%--<input id="this_upload_file_1" type="file" style="display:none"  name="this_upload_files"  onchange="this_upload_show_image(1)"  class="form-control required"/><br>--%>
										<%--</div>--%>
									<%--</div>--%>
								<%--</div>--%>
							</c:when>
							<c:otherwise>
								<c:forTokens items="${company.licences}" delims="," var="licenceStr">

										<c:if test="${empty company.licences}"></c:if>
										<c:if test="${not empty company.licences}">
											<c:forTokens items="${company.licences}" delims="," var="licenceStr">
												<div class="pic_box_wrapper">
													<div class="pic_box">
														<div id="this_upload_image_div_1">
															<div id="this_upload_div_1" style="position:relative;">
																<img alt="_blank" id="this_upload_image_1" class="upload_ico" style="cursor:pointer;"  src="${licenceStr}?x-oss-process=image/resize,w_150,limit_0" onclick="openDialogView('预览','${ctx}/sys/picturepreview/picturePreview?url=${licenceStr}','90%','90%')"/>
															</div>
														</div>
													</div>
												</div>

											</c:forTokens>
										</c:if>

								</c:forTokens>
							</c:otherwise>
						</c:choose>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label double-line">公司logo：</label>
					<div class="layui-input-block">
						<div class="pic_box_wrapper">
							<div class="pic_box">
								<div id="next_upload_image_div">
									<div id="next_upload_div_1" style="position:relative;">
										<c:choose>
											<c:when test="${empty company.logo}">
												<img alt="_blank" id="next_upload_image_2" class="upload_ico" style="cursor:pointer;"  src="${pageContext.request.contextPath}/static/common/img/pic_add.png"  onclick="next_upload_image_button(2)"/>
											</c:when>
											<c:otherwise>
												<c:forTokens items="${company.logo}" delims="," var="logoStr">
													<span id="this_upload_close_1" class="pic_close glyphicon glyphicon-remove" onclick="next_close_img(1)"></span>
													<img alt="_blank" id="next_upload_image_2" class="upload_ico" style="cursor:pointer;"  src="${logoStr}?x-oss-process=image/resize,w_150,limit_0"  onclick="next_upload_image_button(2)"/>
												</c:forTokens>
											</c:otherwise>
										</c:choose>
										<input id="next_upload_file_2" type="file" style="display:none"  name="next_upload_files"  onchange="next_upload_show_image(2)" />
									</div>
								</div>
							</div>
						</div>
						<span id="next_upload_msg">请上传*.png,*.bmp,*.jpg/jpeg格式的图片</span><br>

						<%--<div id="next_upload_image_div">--%>
							<%--<div id="next_upload_div_1" style="float: left;position:relative;width: 57px;height: 57px;">--%>
								<%--<c:choose>--%>
									<%--<c:when test="${empty company.logo}">--%>
										<%--<img alt="_blank" id="next_upload_image_2" class="upload_ico" style="cursor:pointer;"  src="${pageContext.request.contextPath}/static/uploadify/upload_ico.png"  onclick="next_upload_image_button(2)"/>--%>
									<%--</c:when>--%>
									<%--<c:otherwise>--%>
										<%--<c:forTokens items="${company.logo}" delims="," var="logoStr">--%>
											<%--<img alt="_blank" id="next_upload_image_2" class="upload_ico" style="cursor:pointer;"  src="${logoStr}"  onclick="next_upload_image_button(2)"/>--%>
										<%--</c:forTokens>--%>
									<%--</c:otherwise>--%>
								<%--</c:choose>--%>
								<%--<input id="next_upload_file_2" type="file" style="display:none"  name="next_upload_files"  onchange="next_upload_show_image(2)" /><br>--%>
							<%--</div>--%>
						<%--</div>--%>
					</div>
				</div>
				<div class="layui-item layui-col-sm12 with-textarea">
					<label class="layui-form-label double-line">备注信息：</label>
					<div class="layui-input-block">
						<form:textarea path="remarks" htmlEscape="false" rows="4"    class="form-control "/>
					</div>
				</div>
			</div>
		</form:form>
	<c:if test="${empty company.id}">
		<div class="layui-layer-btn">
			<a class="layui-layer-btn0" onclick="document.getElementById('inputForm').reset()">重置</a>
			<a class="layui-layer-btn0" onclick="tijiao()">提交</a>
		</div>
		</div>
	</div>
	<%--</div>--%>
	<%--</div>--%>
<%--</div>--%>
	<script>
        resizeFormWindow();
        $(window).resize(function(){
            resizeFormWindow();
        });
	</script>
	</c:if>
	<c:if test="${not empty company.id}">
		</div>
	</div>
	</c:if>
</body>
</html>