<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header(#{system.profile.title})" />
    <style type="text/css">
        .user-info-head{
            position:relative;
            display:inline-block;
        }
        .user-info-head:hover:after{
            content:'\f030';
            position:absolute;
            left:0;
            right:0;
            top:0;
            bottom:0;
            color:#eee;
            background:rgba(0,0,0,0.5);
            font-family:FontAwesome;
            font-size:24px;
            font-style:normal;
            -webkit-font-smoothing:antialiased;
            -moz-osx-font-smoothing:grayscale;
            cursor:pointer;
            line-height:110px;
            border-radius:50%;
        }
        .logo-img {
            width: auto; /* 保持图片比例 */
            height: 50px; /* 设置图片高度 */
        }
    </style>
</head>

<body class="gray-bg" style="font: 14px Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif !important;">
<input id="userId" name="userId" type="hidden" th:value="${user.userId}" />
<section class="section-content">
    <div class="row">
        <div class="col-sm-3 pr5">
            <div class="ibox float-e-margins">
                <div class="ibox-title ibox-title-gray dashboard-header gray-bg">
                    <h5 th:text="#{system.profile.logo.title}">系统logo</h5>
                </div>
                <div class="ibox-content">
                    <div class="text-center">
                        <p class="user-info-head" onclick="logo()"><img class="logo-img" th:src="(${#strings.isEmpty(user.logo)}) ? @{/img/logo.png} : @{${user.logo}}" th:onerror="'this.src=\'' + @{'/img/logo.png'} + '\''"></p>
                        <p><a href="javascript:logo()" th:text="#{system.profile.logo.edit}">修改logo</a></p>
                    </div>
                </div>
                <div class="ibox-title ibox-title-gray dashboard-header gray-bg">
                    <h5 th:text="#{system.profile.info.title}">个人资料</h5>
                </div>
                <div class="ibox-content">
                    <div class="text-center">
                        <p class="user-info-head" onclick="avatar()"><img class="img-circle img-lg" th:src="(${#strings.isEmpty(user.avatar)}) ? @{/img/profile.png} : @{${user.avatar}}" th:onerror="'this.src=\'' + @{'/img/profile.png'} + '\''"></p>
                        <p><a href="javascript:avatar()" th:text="#{system.profile.avatar.edit}">修改头像</a></p>
                    </div>
                    <ul class="list-group list-group-striped">
                        <li class="list-group-item"><i class="fa fa-user"></i>
                            <b class="font-noraml" th:text="#{system.profile.info.loginName}">登录名称：</b>
                            <p class="pull-right">[[${user.loginName}]]</p>
                        </li>
                        <li class="list-group-item"><i class="fa fa-phone"></i>
                            <b  class="font-noraml" th:text="#{system.profile.info.phone}">手机号码：</b>
                            <p class="pull-right">[[${user.phonenumber}]]</p>
                        </li>
                        <li class="list-group-item" th:if="${user.dept?.deptName != null}"><i class="fa fa-group"></i>
                            <b  class="font-noraml" th:text="#{system.profile.info.dept}">所属部门：</b>
                            <p class="pull-right" style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;width:120px;">[[${user.dept?.deptName}]] / [[${#strings.defaultString(postGroup,'无岗位')}]]</p>
                        </li>
                        <li class="list-group-item"><i class="fa fa-envelope-o"></i>
                            <b  class="font-noraml" th:text="#{system.profile.info.email}">邮箱地址：</b>
                            <p class="pull-right" th:title="${user.email}">[[${#strings.abbreviate(user.email, 16)}]]</p>
                        </li>
                        <li class="list-group-item"><i class="fa fa-calendar"></i>
                            <b  class="font-noraml" th:text="#{system.profile.info.createTime}">创建时间：</b>
                            <p class="pull-right">[[${#dates.format(user.createTime, 'yyyy-MM-dd')}]]</p>
                        </li>
                    </ul>
                </div>
            </div>
        </div>

        <div class="col-sm-9 about">
            <div class="ibox float-e-margins">
                <div class="ibox-title ibox-title-gray dashboard-header">
                    <h5 th:text="#{system.profile.basic.title}">基本资料</h5>
                </div>
                <div class="ibox-content">
                    <div class="nav-tabs-custom">
                        <ul class="nav nav-tabs">
                            <li class="active"><a href="#user_info" data-toggle="tab" aria-expanded="true" th:text="#{system.profile.tab.basic}">基本资料</a></li>
                            <li><a href="#modify_password" data-toggle="tab" aria-expanded="false" th:text="#{system.profile.tab.password}">修改密码</a></li>
                        </ul>
                        <div class="tab-content">
                            <!--用户信息-->
                            <div class="tab-pane active" id="user_info" th:object="${user}">
                                <form class="form-horizontal" id="form-user-edit">
                                    <!--隐藏ID-->
                                    <input name="id" id="id" type="hidden">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label" th:text="#{system.profile.form.userName}">用户名称：</label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" name="userName" th:field="*{userName}" th:placeholder="#{system.profile.form.userName.placeholder}">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label" th:text="#{system.profile.form.phone}">手机号码：</label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" name="phonenumber" maxlength="11" th:field="*{phonenumber}" th:placeholder="#{system.profile.form.phone.placeholder}">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label" th:text="#{system.profile.form.email}">邮箱：</label>
                                        <div class="col-sm-10">
                                            <input type="text" maxlength="50" class="form-control" name="email" th:field="*{email}" th:placeholder="#{system.profile.form.email.placeholder}">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label" th:text="#{system.profile.form.sex}">性别：</label>
                                        <div class="col-sm-10">
                                            <div class="radio-box">
                                                <input type="radio" id="radio1" th:field="*{sex}" name="sex" value="0">
                                                <label for="radio1" th:text="#{system.profile.sex.male}">男</label>
                                            </div>
                                            <div class="radio-box">
                                                <input type="radio" id="radio2" th:field="*{sex}" name="sex" value="1">
                                                <label for="radio2" th:text="#{system.profile.sex.female}">女</label>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-offset-2 col-sm-10">
                                            <button type="button" class="btn btn-sm btn-primary" onclick="submitUserInfo()"><i class="fa fa-check"></i><span th:text="#{btn.save}">保 存</span></button>&nbsp;
                                            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i><span th:text="#{btn.close}">关 闭</span></button>
                                        </div>
                                    </div>
                                </form>
                            </div>

                            <!--修改密码-->
                            <div class="tab-pane" id="modify_password">
                                <form class="form-horizontal" id="form-user-resetPwd">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label" th:text="#{system.profile.password.old}">旧密码：</label>
                                        <div class="col-sm-10">
                                            <input type="password" class="form-control" name="oldPassword" th:placeholder="#{system.profile.password.old.placeholder}">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label" th:text="#{system.profile.password.new}">新密码：</label>
                                        <div class="col-sm-10">
                                            <input type="password" class="form-control" name="newPassword" id="newPassword" th:placeholder="#{system.profile.password.new.placeholder}">
                                            <th:block th:with="chrtype=${@config.getKey('sys.account.chrtype')}">
                                                <th:block th:if="${chrtype != '0'}">
						                            <span class="help-block m-b-none">
								                        <th:block th:if="${chrtype == '1'}"><i class="fa fa-info-circle" style="color: red;"></i> <span th:text="#{system.profile.password.rule.number}">密码只能为0-9数字</span></th:block>
								                        <th:block th:if="${chrtype == '2'}"><i class="fa fa-info-circle" style="color: red;"></i> <span th:text="#{system.profile.password.rule.letter}">密码只能为a-z和A-Z字母</span></th:block>
								                        <th:block th:if="${chrtype == '3'}"><i class="fa fa-info-circle" style="color: red;"></i> <span th:text="#{system.profile.password.rule.mix}">密码必须包含（字母，数字）</span></th:block>
								                        <th:block th:if="${chrtype == '4'}"><i class="fa fa-info-circle" style="color: red;"></i> <span th:text="#{system.profile.password.rule.special}">密码必须包含（字母，数字，特殊字符!@#$%^&*()-=_+）</span></th:block>
						                            </span>
                                                </th:block>
                                            </th:block>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label" th:text="#{system.profile.password.confirm}">确认密码：</label>
                                        <div class="col-sm-10">
                                            <input type="password" class="form-control" name="confirmPassword" th:placeholder="#{system.profile.password.confirm.placeholder}">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-offset-2 col-sm-10">
                                            <button type="button" class="btn btn-sm btn-primary" onclick="submitChangPassword()"><i class="fa fa-check"></i><span th:text="#{btn.save}">保 存</span></button>&nbsp;
                                            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i><span th:text="#{btn.close}">关 闭</span></button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

<th:block th:include="include :: footer" />
<script>
    /*用户管理-头像*/
    function avatar() {
        var url = ctx + 'system/user/profile/avatar';
        top.layer.open({
            type: 2,
            area: [$(window).width() + 'px', $(window).height() + 'px'],
            fix: false,
            //不固定
            maxmin: true,
            shade: 0.3,
            title: i18n("system.profile.avatar.modal.title"),
            content: url,
            btn: [i18n("btn.confirm"), i18n("btn.close")],
            // 弹层外区域关闭
            shadeClose: true,
            yes: function(index, layero) {
                var iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.submitHandler(index, layero);
            },
            cancel: function(index) {
                return true;
            }
        });
    }

    /*用户管理-自定义logo*/
    function logo() {
        var url = ctx + 'system/user/profile/logo';
        top.layer.open({
            type: 2,
            area: [$(window).width() + 'px', $(window).height() + 'px'],
            fix: false,
            //不固定
            maxmin: true,
            shade: 0.3,
            title: i18n("system.profile.logo.modal.title"),
            content: url,
            btn: [i18n("btn.confirm"), i18n("btn.close")],
            // 弹层外区域关闭
            shadeClose: true,
            yes: function(index, layero) {
                var iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.submitHandler(index, layero);
            },
            cancel: function(index) {
                return true;
            }
        });
    }

    /*用户信息-修改*/
    $("#form-user-edit").validate({
        onkeyup: false,
        rules:{
            userName:{
                required:true,
            },
            email:{
                required:true,
                email:true,
                remote: {
                    url: ctx + "system/user/checkEmailUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "userId": function() {
                            return $("#userId").val();
                        },
                        "email": function() {
                            return $.common.trim($("#email").val());
                        }
                    }
                }
            },
            phonenumber:{
                required:true,
                isPhone:true,
                remote: {
                    url: ctx + "system/user/checkPhoneUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "userId": function() {
                            return $("#userId").val();
                        },
                        "phonenumber": function() {
                            return $.common.trim($("#phonenumber").val());
                        }
                    }
                }
            },
        },
        messages: {
            "userName": {
                required: i18n("system.profile.validate.userName.required"),
            },
            "email": {
                required: i18n("system.profile.validate.email.required"),
                remote: i18n("system.profile.validate.email.exists")
            },
            "phonenumber":{
                required: i18n("system.profile.validate.phone.required"),
                remote: i18n("system.profile.validate.phone.exists")
            }
        },
        focusCleanup: true
    });

    function submitUserInfo() {
        if ($.validate.form()) {
            $.operate.saveModal(ctx + "system/user/profile/update", $('#form-user-edit').serialize());
        }
    }

    /*用户管理-修改密码*/
    $("#form-user-resetPwd").validate({
        onkeyup: false,
        rules:{
            oldPassword:{
                required:true,
                remote: {
                    url: ctx + "system/user/profile/checkPassword",
                    type: "get",
                    dataType: "json",
                    data: {
                        password: function() {
                            return $("input[name='oldPassword']").val();
                        }
                    }
                }
            },
            newPassword: {
                required: true,
                minlength: 6,
                maxlength: 20,
                specialSign: true
            },
            confirmPassword: {
                required: true,
                equalTo: "#newPassword"
            }
        },
        messages: {
            oldPassword: {
                required: i18n("system.profile.password.validate.old.required"),
                remote: i18n("system.profile.password.validate.old.error")
            },
            newPassword: {
                required: i18n("system.profile.password.validate.new.required"),
                minlength: i18n("system.profile.password.validate.new.minlength"),
                maxlength: i18n("system.profile.password.validate.new.maxlength")
            },
            confirmPassword: {
                required: i18n("system.profile.password.validate.confirm.required"),
                equalTo: i18n("system.profile.password.validate.confirm.equalTo")
            }

        },
        focusCleanup: true
    });

    function submitChangPassword () {
        var chrtype = [[${#strings.defaultString(@config.getKey('sys.account.chrtype'), 0)}]];
        var password = $("#newPassword").val();
        if ($.validate.form("form-user-resetPwd") && checkpwd(chrtype, password)) {
            $.operate.saveModal(ctx + "system/user/profile/resetPwd", $('#form-user-resetPwd').serialize());
        }
    }
</script>
</body>
</html>