<!DOCTYPE html>
<html lang="en" xml:th="http://www.thymeleaf.org">
<head>
    <!-- 公共部分 -->
    <!--/*/<th:block th:replace="_fragment :: head(~{::title})">/*/-->
    <title>权限管理系统-密码修改</title>
    <!--/*/</th:block>/*/-->
</head>
<body>
<div class="layui-container" style="width:400px;">
    <form action="" class="layui-form" id="passForm">
        <div class="layui-form-item">
            <label class="layui-form-label">旧密码</label>
            <div class="layui-input-block">
                <input type="password" name="oldPwd" class="layui-input" lay-verify="required" />
            </div>

        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">新密码</label>
            <div class="layui-input-block">
                <input type="password" name="newPwd" id="newPwd" class="layui-input" lay-verify="required" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">确认密码</label>
            <div class="layui-input-block">
                <input type="password" name="rePass" lay-verify="required|repass" class="layui-input" verify="required" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="baseSubmit">保存</button>
            </div>
        </div>

    </form>
</div>
</body>
<!-- 注释的方式引入公共部分 _fragment -->
<!--/*/<th:block th:replace="_fragment :: script"/>/*/-->
<!-- 私有部分 -->
<script>
    layui.use(['common','form','layer','jquery'],function () {
        var form = layui.form,
            layer= layui.layer,
            common= layui.common,
            $ =layui.jquery;
        form.verify({
            repass: function(value) {
                var pass = $("#newPwd").val();
                if(pass!=value) {
                    return '两次输入的密码不一致';
                }
            }
        });
        form.on('submit(baseSubmit)',function (data) {
            common.ajax("/api/user/password",JSON.stringify(data.field),function (res) {
                layer.msg("密码已经变更请重新登录");
                top.window.location.href="/index/login";
            },"PUT",true);
            return false;
        })
    });
</script>
</html>