<%@ 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;}--%>
    <%--</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++;
//                    }
//                })
//            });
//        })

        //上传营业执照
        function this_upload_image_button(index){
            $("#this_upload_file_"+index).click();
        }
        function this_upload_show_image(index){
            var image =$("#this_upload_file_"+index)[0].files[0];
            var url = window.URL.createObjectURL(image);
            $("#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 image =$("#next_upload_file_"+index)[0].files[0];
            var url = window.URL.createObjectURL(image);
            $("#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="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="float: left;position:relative;width: 57px;height: 57px;" >'+
                '<img  id="next_upload_image_1" class="upload_ico" style="cursor:pointer;"  src="${pageContext.request.contextPath}/static/uploadify/upload_ico.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">
		var validateForm;
		function doSubmit(obj){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
		  if(validateForm.form()){
		      var id = $("#id").val();
		      var home = $("#home").val();
              if(obj == 1){
                  $("#inputForm").attr("action","${ctx}/sys/company/approve?id="+id+"&home="+home);
              }else if(obj == 2){
                  $("#inputForm").attr("action","${ctx}/sys/company/refuse?id="+id+"&home="+home);
              }else{
                  $("#inputForm").attr("action","${ctx}/sys/company/save");

              }
			  $("#inputForm").submit();
			  return true;
		  }
	
		  return false;
		}
		$(document).ready(function() {
			validateForm = $("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				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);
					}
				}
			});
            //只做查看时，禁用掉以下标签
            $('input,textarea,select').attr('disabled',<%=request.getAttribute("disabled")%>);

		});
	</script>
</head>
<body>
<div class="single-form">
    <div class="container">
		<form:form id="inputForm" modelAttribute="company" enctype="multipart/form-data"  method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<form:hidden path="home"/>

            <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">公司名称：</label>
                    <div class="layui-input-block">
                        <input desabled="true" class="form-control layui-input required" value="${company.name}"/>
                    </div>
                </div>
                <div class="layui-item layui-col-sm6">
                    <label class="layui-form-label">申请人邮箱：</label>
                    <div class="layui-input-block">
                        <input desabled="true" class="form-control layui-input required" value="${company.email}"/>
                    </div>
                </div>
                <div class="layui-item layui-col-sm6">
                    <label class="layui-form-label double-line">统一社会信用代码（注册号）：</label>
                    <div class="layui-input-block">
                        <input desabled="true" class="form-control layui-input required" value="${company.number}"/>
                    </div>
                </div>
                <div class="layui-item layui-col-sm6">
                    <label class="layui-form-label">申请人姓名：</label>
                    <div class="layui-input-block">
                        <input desabled="true" class="form-control layui-input required" value="${company.tuser.name}"/>
                    </div>
                </div>
                <div class="layui-item layui-col-sm6">
                    <label class="layui-form-label">法人：</label>
                    <div class="layui-input-block">
                        <input desabled="true" class="form-control layui-input required" value="${company.legalPerson}"/>
                    </div>
                </div>
                <div class="layui-item layui-col-sm6">
                    <label class="layui-form-label">申请人电话：</label>
                    <div class="layui-input-block">
                        <input desabled="true" class="form-control layui-input required" value="${company.phone}"/>
                    </div>
                </div>
                <div class="layui-item layui-col-sm6" style="height:160px;">
                    <label class="layui-form-label double-line">营业执照：</label>
                    <div class="layui-input-block">
                        <c:choose>
                            <c:when test="${requestScope.disabled}">
                                <div>
                                    <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>
                                                        <div style="position:relative;">
                                                            <img alt="_blank" class="upload_ico" style="cursor:pointer;"  src="${licenceStr}?x-oss-process=image/resize,w_130,limit_0" onclick="openDialogView('预览','${ctx}/sys/picturepreview/picturePreview?url=${licenceStr}','90%','90%')"/>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </c:forTokens>
                                    </c:if>

                            </c:when>
                            <c:otherwise>
                                <span id="this_upload_msg">点击已上传图片可更换</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)" /><br>
                                    </div>
                                </div>
                            </c:otherwise>
                        </c:choose>
                    </div>
                </div>
                </div>
                <div class="layui-item layui-col-sm6" style="height:160px;">
                    <label class="layui-form-label double-line">公司logo：</label>
                    <div class="layui-input-block">
                        <c:choose>
                            <c:when test="${requestScope.disabled}">
                                <div class="pic_box_wrapper">
                                    <div class="pic_box">
                                        <c:if test="${empty company.logo}">暂无</c:if>
                                        <c:if test="${not empty company.logo}">
                                        <c:forTokens items="${company.logo}" delims="," var="logoStr">
                                            <div>
                                                <div style="position:relative;">
                                                    <img alt="_blank" class="upload_ico" style="cursor:pointer;"  src="${logoStr}?x-oss-process=image/resize,w_130,limit_0" onclick="openDialogView('预览','${ctx}/sys/picturepreview/picturePreview?url=${logoStr}','90%','90%')"/>
                                                </div>
                                            </div>
                                        </c:forTokens>
                                        </c:if>
                                    </div>
                                </div>
                            </c:when>
                            <c:otherwise>
                                <span id="next_upload_msg">点击已上传图片可更换</span><br>
                                <div id="next_upload_image_div">
                                    <div id="next_upload_div_1" style="float: left;position:relative;width: 57px;height: 57px;">
                                        <img alt="_blank" id="next_upload_image_1" class="upload_ico" style="cursor:pointer;"  src="${pageContext.request.contextPath}/static/uploadify/upload_ico.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>
                                </div>
                            </c:otherwise>
                        </c:choose>
                    </div>
                </div>
                <div class="layui-item layui-col-sm12 with-textarea">
                    <label class="layui-form-label double-line">备注信息：</label>
                    <div class="layui-input-block">
                        <textarea htmlEscape="false" rows="4" class="form-control ">${company.remarks}</textarea>
                    </div>
                </div>
            </div>
	    </form:form>
    </div>
    </div>
</div>
</body>
</html>
