<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/jsp/common/taglibs.jspf"%>
<%@ page isELIgnored="false" %>
<!DOCTYPE html>
<html lang="zh-CN">
	<head>
		<hejin:header title="用户编辑"></hejin:header>
		<link rel="stylesheet" href="static/js/select2/select2.css">
		<link rel="stylesheet" href="static/js/select2/select2-bootstrap.css">
		<link rel="stylesheet" type="text/css" href="static/css/font/font-awesome.min.css">
		<!-- fileupload ui css -->
		<link rel="stylesheet" type="text/css" href="static/css/bootstrap/jquery.fileupload-ui.css">
		<!-- datetimepicker css -->
		<link rel="stylesheet" type="text/css" href="static/css/bootstrap/bootstrap-datetimepicker.min.css">
		<style type="text/css">
		.span {
		    position: absolute;
		    left: 50%;
		    top: 50%;
		    font-weight: bold;
		    line-height: 34px;
		}
		.row {
		    margin-right: 0px;
		    margin-left: 0px;
		}
		.op_wrap_con_box {
    		width: 1000px;
    		margin: 0px auto;
		}
		.op_wrap_con_box {
			margin-bottom: 100px;
			border: 1px solid #F1F1F1;
		}
		.container-fluid {
		    padding-right: 0px;
		    padding-left: 0px;
		    margin-right: auto;
		    margin-left: auto;
		}
		.product-title {
		    margin-bottom: 30px;
		    border-bottom: 1px solid #E1E1DF;
		    height: 15px;
		}
		.product-title .span-test {
		    font-size: 20px;
		    word-break: normal;
		    float: left;
		    padding-right: 10px;
		    background: none repeat scroll 0% 0% #FFF;
		}
		</style>
	</head>
	<body>
		<!-- 菜单 -->
		<jsp:include page="../../menu.jsp"/>
		<!-- BEGIN -->
		<article>
			<div class="op_wrap">
				<div class="op_wrap_con_box">
					<!-- 面包屑 -->
					<div class="container-fluid">
						<ol class="breadcrumb">
							<li><a href="javascript:void(0);">系统管理</a></li>
							<li><a href="<%=request.getContextPath() %>/system/user/userIndex.do">用户管理</a></li>
							<li><a href="javascript:void(0);">编辑</a></li>
						</ol>
					</div>
					<div class="container-fluid" style="margin-left: 30px;margin-right: 30px;">
						<!-- BEGIN 用户信息 -->
						<!-- BEGIN FORM -->
						<form action="system/user/addUser.do" id="form_user_tables" method="post">
						<input name="userId" id="userId" type="hidden" value="${user.userId}">
						<div class="product-function" data-target="#navbar-example" data-spy="scroll">
							<div class="product-title">
								<span class="span-test">用户信息</span>
							</div>
							<!-- 用户名称  -->
							<div class="row form-group">
			                	<div class="col-sm-2">
									<label class="span">用户名称</label>
								</div>
								<div class="col-sm-4">
			                        <input name="userName" id="userName" type="text" value="${user.userName}" class="form-control" placeholder="请输入用户名称">
			                    </div>
			                     <div class="col-sm-2">
										<label class="span">登录名称</label>
								</div>
								<div class="col-sm-4">
			                        <input name="loginName" id="loginName" disabled="disabled" type="text" value="${user.loginName}" class="form-control" placeholder="请输入登录名称">
			                    </div>
		                 	</div>
							<%--
                                     <!-- 证件类型 -->
                                    <div class="row form-group">
                                        <div class="col-sm-2">
                                            <label class="span">证件类型</label>
                                        </div>
                                        <div class="col-sm-4">
                                            <select id="certType" name="certType" class="form-control">
                                               <option value="">请选择</option>
                                                <c:forEach items="${certTypeMap}" var="map">
                                                    <option value="${map.key}"
                                                        <c:if test="${map.key eq user.certType}">
                                                            selected="true"
                                                        </c:if>
                                                    >${map.value}</option>
                                                </c:forEach>
                                          </select>
                                         </div>
                                         <div class="col-sm-2">
                                            <label class="span">电话</label>
                                        </div>
                                        <div class="col-sm-4">
                                               <input name="mobile" id="mobile" type="tel" value="${user.mobile }" class="form-control" placeholder="请输入电话">
                                         </div>
                                    </div>
                                    <!-- 证件号码  -->
                                    <div class="row form-group">
                                        <div class="col-sm-2">
                                            <label class="span">证件号码</label>
                                        </div>
                                        <div class="col-sm-4">
                                               <input name="certNo" id="certNo" type="text" value="${user.certNo }" class="form-control" placeholder="请输入证件号码">
                                         </div>
                                         <div class="col-sm-2">
                                            <label class="span">邮箱</label>
                                        </div>
                                        <div class="col-sm-4">
                                               <input name="email" id="email" type="email" value="${user.email }" class="form-control" placeholder="请输入邮箱">
                                         </div>
                                    </div>
                                    <div class="row form-group">
                                        <div class="col-sm-2">
                                            <label class="span">用户角色</label>
                                        </div>
                                        <div class="col-sm-4">
                                            <select id="roleId"  name="roleId" class="form-control">
                                                <option value="">请选择</option>
                                                <c:forEach items="${roleList}" var="roleList">
                                                    <option value="${roleList.roleId}"
                                                        <c:if test="${roleList.roleId eq role.roleId}">
                                                            selected="true"
                                                        </c:if>
                                                    >${roleList.roleName}</option>
                                                </c:forEach>
                                              </select>
                                         </div>
                                        <div class="col-sm-2">
                                            <label class="span">性别</label>
                                        </div>
                                        <div class="col-sm-4">
                                            <select id="sex" name="sex" class="form-control">
                                                <option value="">请选择</option>
                                                <c:forEach items="${sexMap}" var="sexMap">
                                                    <option value="${sexMap.key}"
                                                        <c:if test="${sexMap.key eq user.sex}">
                                                            selected="true"
                                                        </c:if>
                                                    >${sexMap.value}</option>
                                                </c:forEach>
                                            </select>
                                         </div>
                                    </div>
                                    <!-- 用户角色  -->
                                    <div class="row form-group">
                                         <div class="col-sm-2">
                                            <label class="span">用户类型</label>
                                        </div>
                                        <div class="col-sm-4">
                                            <select id="userType" name="userType" class="form-control">
                                               <option value="">请选择</option>
                                                <c:forEach items="${userTypeMap}" var="typeMap">
                                                    <option value="${typeMap.key}"
                                                        <c:if test="${typeMap.key eq user.userType}">
                                                            selected="true"
                                                        </c:if>
                                                    >${typeMap.value}</option>
                                                </c:forEach>
                                             </select>
                                         </div>
                                         <div class="col-sm-2">
                                            <label class="span">生日</label>
                                        </div>
                                        <div class="col-sm-4">
                                               <input name="birthday" id="birthday" type="text" value="${user.birthday }" class="form-control" readonly="readonly" placeholder="请输入生日">
                                         </div>
                                    </div>
                                    <!-- 只有企业用户才有主账号 -->
                                    <div class="row form-group">
                                        <c:if test="${user.userType == '20'}">
                                            <c:choose>
                                                <c:when test="${user.parentId eq '' || user.parentId eq '0' }">
                                                </c:when>
                                                <c:otherwise>
                                                    <div class="col-sm-2">
                                                        <label class="span">主账号</label>
                                                    </div>
                                                       <div class="col-sm-4">
                                                        <div class="controls">
                                                            <input class="form-control select2" id="parentAccountNameId" name="parentAccountName" placeholder="请输入主账号登录名称,支持模糊匹配" value="${parentSysUser.loginName}"/>
                                                            <input type="hidden" class="form-control" id="parentId" name="parentId" value="${parentSysUser.parentId }"/>
                                                        </div>
                                                    </div>
                                                </c:otherwise>
                                            </c:choose>
                                        </c:if>
                                        <div class="col-sm-2">
                                            <label class="span">职位</label>
                                        </div>
                                        <div class="col-sm-4">
                                               <input name="userPosition" id="userPosition" type="text" value="${user.userPosition }" class="form-control" placeholder="请输入职位">
                                         </div>
                                    </div>
                                <!-- END 公司信息 -->
                                <!-- BEGIN 公司信息 -->
                                <div class="product-title">
                                    <span class="span-test">公司信息</span>
                                </div>
                                <div class="row form-group">
                                    <div class="col-sm-2">
                                        <label class="span">公司名称</label>
                                    </div>
                                    <div class="col-sm-4">
                                           <input name="companyName" id="companyName" type="text" value="${user.companyName }" class="form-control" placeholder="请输入公司名称">
                                     </div>
                                    <div class="col-sm-2">
                                        <label class="span">公司地址</label>
                                    </div>
                                    <div class="col-sm-4">
                                           <input name="address" id="address" type="text" value="${user.address }" class="form-control" placeholder="请输入公司地址">
                                     </div>
                                </div>
                                <div class="row form-group">
                                       <div class="col-sm-2">
                                        <label class="span">公司网址</label>
                                    </div>
                                    <div class="col-sm-4">
                                           <input name="website" id="website" type="text" value="${user.website }" class="form-control" placeholder="请输入公司网址">
                                     </div>
                                     <div class="col-sm-2">
                                        <label class="span">公司电话</label>
                                    </div>
                                    <div class="col-sm-4">
                                           <input name="companyPhome" id="companyPhome" type="tel" value="${user.companyPhome }" class="form-control" placeholder="请输入公司电话">
                                     </div>
                                </div>

                                <div class="product-title">
                                    <span class="span-test">关联企业</span>
                                </div>
                                <div class="row form-group">
                                       <div class="col-sm-2">
                                        <label class="span">修改所属</label>
                                    </div>
                                       <div class="col-sm-4">
                                        <div class="controls">
                                            <input class="form-control select2" id="dubbo_companyName" name="dubbo_companyName" placeholder="请输入主账号登录名称,支持模糊匹配" value="${connectedCompanyName }"/>
                                            <input type="hidden" class="form-control" id="companyId" name="companyId" value="${user.companyId }" />
                                        </div>
                                    </div>
                                </div>

                                <div class="row form-group" style="margin-bottom: 50px;">
                                       <div class="col-sm-2">
                                        <label class="span">所属企业</label>
                                    </div>
                                       <div class="col-sm-4">
                                            <span style="text-align: left;line-height: 34px;position: absolute;">${connectedCompanyName}</span>
                                    </div>
                                    <div class="col-sm-2">
                                        <label class="span">所属企业ID</label>
                                    </div>
                                       <div class="col-sm-4">
                                        <span style="text-align: left;line-height: 34px;position: absolute;">${user.companyId}</span>
                                    </div>
                                </div>






                                <!-- 证照信息  -->
                                <div class="product-title">
                                    <span class="span-test">证照信息</span>
                                </div>

                                    <!-- begin 营业执照 -->
                                    <div class="row form-group">
                                           <div class="col-sm-2">
                                            <label class="span">营业执照</label>
                                        </div>
                                        <div class="col-sm-4">
                                            <span class="btn blue fileinput-button">
                                                <span class="btn btn-block btn-primary">选择缩略图(600*800)</span>
                                                <input type="file" name="businessLicensesImage" id="input_file_businessLicense"
                                                    onchange="platformAjaxFileUpload(this,'input_hidden_businessLicense','businessLicense_view',{},'800px','600px','jpg,png,jpeg,bmp')"/>
                                                <input type="hidden" name="businessLicenses" id="input_hidden_businessLicense" />
                                            </span>
                                         </div>
                                    </div>
                                    <!-- BEGIN 组织机构代码证   -->
                                    <div class="row form-group">
                                            <div class="col-sm-12">
                                            <div class="controls">
                                                <input type="hidden" name="icon" id="businessLicenses_icon" value="<c:if test="${not empty user.businessLicense}">${user.businessLicense }</c:if>">
                                                <div id="businessLicense_view">
                                                    <c:if test="${not empty user.businessLicense}">
                                                        <img width='800px' height='600px' src='attach/image.do?attachmentId=${user.businessLicense }'/>
                                                    </c:if>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row form-group">
                                        <div class="col-sm-2">
                                            <label class="span">组织机构代码证</label>
                                        </div>
                                        <div class="col-sm-4">
                                            <span class="btn blue fileinput-button">
                                                <span class="btn btn-block btn-primary">选择缩略图(600*800)</span>
                                                <input type="file" name="orgCodeImage" id="input_file_orgCodes"
                                                    onchange="platformAjaxFileUpload(this,'input_hidden_orgCodes','orgCode_view',{},'800px','600px','jpg,png,jpeg,bmp')"/>
                                                <input type="hidden" name="orgCodes" id="input_hidden_orgCodes"/>
                                            </span>
                                        </div>
                                    </div>
                                    <div class="row form-group">
                                        <div class="col-sm-12">
                                            <div class="controls">
                                                <input type="hidden" name="icon" id="orgCodes_icon" value="<c:if test="${not empty user.orgCode}">${user.orgCode}</c:if>">
                                                <div id="orgCode_view">
                                                    <c:if test="${not empty user.orgCode}">
                                                        <img width='800px' height='600px' src='attach/image.do?attachmentId=${user.orgCode}'/>
                                                    </c:if>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div> --%>
            			<div class="product-title">
							<span class="span-test"></span>
						</div>
						
						<div class="row form-group">
							<div class="col-sm-3"></div>
							<div class="col-sm-2">
								<button type="submit" class="btn btn-primary pull-left" style="width: 99px;"><i class="fa fa-envelope"></i>确定</button>
							</div>
							<div class="col-sm-2"></div>
							<div class="col-sm-2">
								<a class="btn btn-danger" style="width: 99px;" href="<%=request.getContextPath() %>/system/user/userIndex.do">取消</a>
							</div>
							<div class="col-sm-3"></div>
						</div>
					</div>
				</div>
			</div>
		</article>
		<!-- jquery js -->
		<script src="static/js/bootstrap/jquery.min.js"></script>
		<script src="static/js/bootstrap/bootstrap.min.js"></script>
		<!-- validate js -->
		<script src="static/js/bootstrap/jquery.validate.min.js" type="text/javascript"></script>
		<!-- platformcomp js -->
		<script src="static/js/common/platform_comp.js" type="text/javascript"></script>
		<!-- select2 -->
		<script type="text/javascript" src="static/js/select2/select2.min.js"></script>
		<script type="text/javascript" src="static/js/select2/select2_locale_zh-CN.js"></script>
	    <!-- datetimepicker -->
	    <script type="text/javascript" src="static/js/bootstrap/bootstrap-datetimepicker.min.js"></script>
	    <script type="text/javascript" src="static/js/bootstrap/bootstrap-datetimepicker.zh-CN.js"></script>
	    <!-- 通过登录用户选中的菜单获取当前菜单所有的权限 -->
		<script type="text/javascript" src="static/js/common/currentUserPermission.js" ></script>
	   	<!-- 用户验证用户账户是否能能作为主账户存在 -->
		<%--  <script type="text/javascript" src="static/js/common/checkUserParentAccount.js"></script> --%>

            <script type="text/javascript" src="static/js/bootstrap/ajaxfileupload.js"></script>
         <%-- <script type="text/javascript" src="static/js/common/platform_fileupload.js"></script> --%>
		<script type="text/javascript">
			//时间插件加载
			$("#birthday").datetimepicker({
				language : 'zh-CN',
				format : 'yyyy-mm-dd',
				todayBtn : true,
				autoclose : true,
				todayHighlight : true,
				startView : 2,
				minView : 2,
				maxView : 4,
				endDate : new Date()
			});
		
		$(function() {
			//主账号的搜索功能
			getUserListByLoginName('#parentAccountNameId', '#parentId' ,'system/user/getUserByUserLoginName.do');
			//初始化主账号值
			$(".select2-chosen").html('${parentSysUser.loginName}');
			
			var form = $('#form_user_tables');
			
		    form.validate({
				errorElement : 'span',errorClass : 'help-inline',focusInvalid : false,ignore : "",
		      	rules : {userName : {required : true,maxlength : 25},//用户名称
		    			loginName : {required : true,maxlength : 25},// 用户登录名称
						email : {required : true,email : true},//自带邮箱验证
		    	  		userType : {required : true},
		    	  		companyName : {required :true},
		    	  		userPosition : {required : true,maxlength : 50},
		    	  		businessLicense : {required :true,filetype : ["jpg", "png"]},
		    	  		orgCode : {required : true,filetype : ["jpg", "png"]}
		      },
		      messages : {userName : {required : "请输入用户名称!", maxlength : "用户名称最大长度为25"},
			    	  loginName : {required : "请输入登录名称!", maxlength : "登录名称最大长度为25"},
			          email : {required : "请输入Email地址", email : "请输入正确的email地址"},
			          userType : {required : "请选择用户类型!"},
			          companyName : {required : "请输入公司名称!"},
			          userPosition : {required : "请输入职位!"},
			    	  businessLicense : {required : "请选择图片文件!",filetype : "只能上传 jpg, png 格式文件"},
			    	  orgCode:{required : "请选择图片文件!", filetype : "只能上传 jpg, png 格式文件"}
			  },
			  highlight: function (element) {
		          $(element).closest('.help-inline').removeClass('ok');
		          $(element).closest('.control-group').removeClass('success').addClass('error');
		      },
		      unhighlight: function (element) {
		          $(element).closest('.control-group').removeClass('error');
		      },
			  submitHandler: function (form) {
				  form.submit();
		      }
		  	});
			
			$("#dubbo_companyName").select2({
		    	minimumInputLength: 2,
		    	ajax: {
					url: "system/user/queryCompanyInfo.do",
					dataType: 'json',
					data: function (term, page) {
						return {
							companyName: term
						};
					},
					results: function (data, page) {
						var arr = [];
						$.each(data, function(index, item) {
							var tmp = {};
							tmp.id=item.CODE;
							tmp.text=item.NAME;
							arr.push(tmp);
						});
						return {results: arr};
					}
				},
		    }).on("change", function(e){$("#companyId").val(e.added.id);});
		});
		</script>
	</body>
</html>