<!DOCTYPE html>
<html lang="en" 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">
    <link rel="stylesheet" th:href="@{/lib/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/public.css}" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form" style="margin-left: -20px; margin-right: 20px">
    <div class="layui-form-item">
        <label class="layui-form-label">账号</label>
        <div class="layui-input-block">
            <input type="hidden" name="userId" th:value="${userInfo.userId}">
            <input type="text" name="account" th:value="${userInfo.account}" class="layui-input" readonly>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-block">
            <input type="text" name="name" th:value="${userInfo.name}" class="layui-input" readonly>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">所属部门</label>
        <div class="layui-input-block">
            <input type="text" name="deptName" th:value="${userInfo.deptName}" class="layui-input" readonly>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
            <input type="text" name="sex" th:value="${userInfo.sex}" class="layui-input" readonly>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">手机</label>
        <div class="layui-input-block">
            <input type="text" name="phone" th:value="${userInfo.phone}" class="layui-input" readonly>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <input type="text" name="status" th:value="${userInfo.status}" class="layui-input" readonly>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-block">
            <input type="text" name="email" th:value="${userInfo.email}" class="layui-input" readonly>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">岗位</label>
        <div class="layui-input-block">
            <input type="postSelect" name="postSelect" th:value="${userInfo.userPostName}" class="layui-input" readonly>
        </div>
    </div>

    <!--    <div class="layui-form-item">-->
    <!--        <label class="layui-form-label">用户头像</label>-->
    <!--        <div class="layui-input-block">-->
    <!--            <input type="hidden" name="avatar" th:value="${userInfo.avatar}">-->
    <!--            <div style="height: 100px;width: 100px;position: relative;">-->
    <!--                <input type="file" accept="image/*" id="pic-input"-->
    <!--                       style="position: absolute;left: 0;top: 0;opacity: 0;filter: alpha(opacity=0);height: 100%;width: 100%;z-index: 99">-->
    <!--                <img th:src="${userInfo.avatarPreUrl}" alt="" id="pic-img"-->
    <!--                     style="height: 100%;width: 100%;position: absolute;left: 0;top: 0;border: 1px solid #1E9FFF;">-->
    <!--            </div>-->
    <!--        </div>-->
    <!--    </div>-->


    <!-- 右侧悬浮按钮 -->
    <div class="right-bottom-btn">
        <button class="layui-btn" lay-filter="cancleBtn">
            <i class="layui-icon layui-icon-close"></i>关闭
        </button>
    </div>

</div>
<script th:src="@{/lib/jquery-3.4.1/jquery-3.4.1.min.js}" charset="utf-8"></script>
<script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
<script th:src="@{/lib/coco-message/coco-message.js}" charset="utf-8"></script>
<script th:src="@{/lib/xm-select-v1.2.2/xm-select.js}" charset="utf-8"></script>
<script th:src="@{/js/lay-config.js}" charset="utf-8"></script>
<script type="text/javascript" th:inline="javascript">
    AjaxUtil.ctx = /*[[@{/}]]*/'';
    layui.use(['form', 'layCascader'], function () {
        var layer = layui.layer;

        $('#pic-input').change(function () {
            var formData = new FormData();
            formData.append("files", $("#pic-input")[0].files[0]);
            formData.append("fileName", $("#pic-input")[0].files[0].name); // 文件名字
            var index = layer.load(0, {shade: 0.1}); //0代表加载的风格，支持0-2

            AjaxUtil.upload({
                url: AjaxUtil.ctx + 'fileupload/put',
                data: formData,
                success: function (res) {
                    layer.close(index);
                    if (0 === res.code) {
                        $("input[name='avatar']").val(res.data.fileId);
                        $('#pic-img').attr('src', res.data.previewUrl);
                        Message.success(res.message, 1000);
                    } else {
                        Message.error(res.message, 1000);
                    }
                },
                error: function (error) {
                    layer.close(index);
                    Message.error("服务器异常！", 1000);
                }
            });

        });

        // 监听取消按钮
        $("button[lay-filter='cancleBtn']").click(function () {
            var iframeIndex = parent.layer.getFrameIndex(window.name);
            parent.layer.close(iframeIndex);
        });
    });

    /**
     *  扁平数据转树结构
     * @returns {[]}
     * @param data
     * @param firstPid
     */
    function arrayToTree(data, firstPid) {
        const result = [];
        getChildren(data, result, firstPid)
        return result;
    }

    function getChildren(data, result, parentId) {
        for (const item of data) {
            if (item.parentId === parentId) {
                const newItem = {...item, children: []};
                result.push(newItem);
                getChildren(data, newItem.children, item.deptId);
            }
        }
    }
</script>
</body>
</html>