<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<%@include file="/views/common.jsp"%>
</head>
<body>
	<br>
	<div style="padding: 20px; background-color: #F2F2F2;">
		<div class="layui-row layui-col-space15">
			<div class="layui-col-md3"></div>
			<div class="layui-col-md6">
				<div class="layui-card"
					style="border-radius: 20px; border: 2px solid buttonface; box-shadow: 5px 5px 5px #F2F2F2 inset;">
					<div class="layui-card-body">
						<div class="layui-input-block layui-form" lay-filter="addUser"
							style="margin-top: 30px">
							<form class="layui-form " action="">
								<input type="hidden" name="userId" class="layui-input" id="userId"> 
								<div class="layui-form-item">
									<label class="layui-form-label">用户名</label>
									<div class="layui-input-inline">
										<input type="text" name="username" lay-verify="username"
											readonly="readonly" autocomplete="off" placeholder="请输入用户名"
											class="layui-input" id="username">
									</div>
									<div class="layui-form-mid layui-word-aux">不可修改</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">密码</label>
									<div class="layui-input-inline">
										<input type="password" name="password1" placeholder="请输入密码"
											autocomplete="off" class="layui-input" id="password1"
											lay-verify="pass">
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">确认密码</label>
									<div class="layui-input-inline">
										<input type="password" name="password" placeholder="请输入密码"
											autocomplete="off" class="layui-input" id="password"
											lay-verify="pass" >
									</div>
								</div>
								<div class="layui-form-item">
									<div class="layui-inline">
										<label class="layui-form-label">真实姓名</label>
										<div class="layui-input-inline">
											<input type="text" name="realname" id="realname"
												autocomplete="off" class="layui-input" placeholder="请输入真实姓名"
												lay-verify="required">
										</div>
									</div>
								</div>
								<div class="layui-form-item">
									<div class="layui-input-block">
										<button class="layui-btn" lay-submit="" lay-filter="enadd">确认修改</button>
									</div>
								</div>
							</form>
							<div style="height: 30px"></div>
						</div>
					</div>
				</div>
				<div style="height: 50px"></div>
			</div>
			<div class="layui-col-md3"></div>
		</div>
	</div>

	<script type="text/javascript">
		layui.use([ 'table', 'laydate', 'form', 'layer' ], function() {
			var $ = layui.jquery;
			var table = layui.table;
			var laydate = layui.laydate;
			var form = layui.form;
			var layer = layui.layer;
			$.getJSON("${path}/loginAttribute",function(d){
				var data = d.data.user
				$("#userId").val(data.userId);
				$("#username").val(data.username);
				$("#realname").val(data.realname);
				//$("#password").val(data.password);
//				$("#userpwd1").val(data.userpwd);
			})
			
			//修改用户信息
			form.on('submit(enadd)', function(data) {
				//console.log($("#userId").val());
				//console.log($(data.form).serialize());
				if($("#password1").val() === $("#password").val() && $("#password").val() !== ""){
					$.ajax({
						url : '${path}/updatePassword',
						dataType : 'json',
						data : $(data.form).serialize(),
						type : 'post',
						success : function(data) {
							if(data.code == 200){
								layer.msg('修改成功，请重新登录！', {
									icon : 6,
									offset : "auto",
									time : 2000
								});//提示框
								setTimeout("javascript:top.location.href='${path}/SysUser/logout'", 3000);
							}else{
								layer.msg('修改失败！', {
									icon : 5,
									offset : "auto",
									time : 2000
								});//提示框
								setTimeout(function(){
									location.reload();//重新加载页面
								}, 2100); 
							}
						}
					})
				}else{
					layer.msg('俩次密码不一致！', {
						icon : 5,
						offset : "auto",
						time : 2000
					});//提示框
					return false;
				}
				return false;
			});
		})
	</script>
</body>
</html>