<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="utf-8">
	<title>修改密码</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="/resources/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="/resources/css/public.css" media="all" />
</head>
<body class="childrenBody">
<form class="layui-form layui-row changePwd" method="post" id="formChange" lay-filter="formChange">
	<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
		<div class="layui-input-block layui-red pwdTips">旧密码请输入“123456”，新密码必须两次输入一致才能提交</div>
		<div class="layui-form-item">
			<label class="layui-form-label">用户名</label>
			<div class="layui-input-block">
				<input type="text" value="" id="name" th:value="${session.user.name}" disabled  class="layui-input layui-disabled" autocomplete="false">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">旧密码</label>
			<div class="layui-input-block">
				<input type="password" value="" id="oldPassword" placeholder="请输入旧密码" lay-verify="required" class="layui-input pwd" autocomplete="false">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">新密码</label>
			<div class="layui-input-block">
				<input type="password" value="" id="newPwdOne" placeholder="请输入新密码" lay-verify="required|newPwd"  class="layui-input pwd" autocomplete="false">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">确认密码</label>
			<div class="layui-input-block">
				<input type="password" value="" id="newPwdTwo" placeholder="请确认密码" lay-verify="required|confirmPwd" class="layui-input pwd" autocomplete="false">
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit="" lay-filter="changePwd">立即修改</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</div>
</form>
<script type="text/javascript" src="/resources/layui/layui.js"></script>
<script type="text/javascript" src="/resources/page/user/user.js"></script>

<script type="text/javascript">
	// 使用layui模块，包括jquery、form和layer
	layui.use(['jquery', 'form', 'layer'], function () {
		// 获取layui的jquery模块
		var $ = layui.jquery;
		// 获取layui的form模块
		var form = layui.form;
		// 获取layui的layer模块
		var layer = layui.layer;

		// 监听表单提交事件，当触发changePwd时执行回调函数
		form.on("submit(changePwd)", function () {
			// 获取用户名输入框的值
			var name = $("#name").val();
			// 获取旧密码输入框的值
			var oldPassword = $("#oldPassword").val();
			// 获取新密码第一个输入框的值
			var newPwdOne = $("#newPwdOne").val();
			// 获取新密码第二个输入框的值
			var newPwdTwo = $("#newPwdTwo").val();

			// 弹出确认对话框，询问用户是否确定修改密码
			layer.confirm('你确定要修改【' + name + '】这个用户的密码吗？', {icon: 3, title: '提示'}, function (index) {
				// 发送POST请求到服务器，尝试修改密码
				$.post('/user/changePassword', {oldPassword: oldPassword, newPwdOne: newPwdOne, newPwdTwo: newPwdTwo}, function (res) {
					// 显示服务器返回的消息
					layer.msg(res.msg);
				});
				// 关闭确认对话框
				layer.close(index);
			});

			// 阻止表单默认提交行为
			return false;
		});
	});

</script>

</body>
</html>