<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <base th:href="${#request.getContextPath() + '/'} ">
    <meta charset="utf-8">
    <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.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="assets/fonts/font-awesome/css/font-awesome.css"/>
    <link rel="stylesheet" href="assets/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="assets/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="assets/js/vendor/viewer/viewer.min.css">
</head>
<body>
<div class="layui-fluid layui-anim layui-anim-fadein" style="padding: 0;">
    <div class="layui-card">
        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form layui-form-pane" lay-filter="dataForm">
                <input type="hidden" id="join" th:name="${joinKey}" th:value="${joinId}"/>
                <div th:each="dynamicFormFormShowFieldDTO, state: ${dynamicFormFormShowFieldDTOList}">
                    <div class="layui-form-item" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'string'}">
                        <label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
                        <div class="layui-input-block">
                            <input type="text" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}">
                        </div>
                    </div>
                    <div class="layui-form-item" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'datetime' or dynamicFormFormShowFieldDTO.fieldType eq 'date'}">
                        <label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
                        <div class="layui-input-block">
                            <input type="text" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请选择'+ dynamicFormFormShowFieldDTO.fieldExplain}" lay-verify="required" readonly style="cursor: pointer;">
                        </div>
                    </div>
                    <div class="layui-form-item" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'number'}">
                        <label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
                        <div class="layui-input-block">
                            <input type="number" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}">
                        </div>
                    </div>
                    <div class="layui-form-item" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'double'}">
                        <label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
                        <div class="layui-input-block">
                            <input type="number" step="0.01" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-input" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}">
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'textarea'}">
                        <label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
                        <div class="layui-input-block">
                            <textarea th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" class="layui-textarea" th:placeholder="${'请输入'+ dynamicFormFormShowFieldDTO.fieldExplain}"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'richText'}">
                        <label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
                        <div class="layui-input-block">
                            <div th:id="${dynamicFormFormShowFieldDTO.fieldName}"></div>
                        </div>
                    </div>
                    <div class="layui-form-item" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'select'}">
                        <label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
                        <div class="layui-input-block">
                            <select th:each="selectMap: ${selectMapList}" th:if="${selectMap.name eq dynamicFormFormShowFieldDTO.fieldName}" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}">
                                <option value="">请选择</option>
                                <option th:each="select: ${selectMap.list}" th:value="${select.dictionaryId}" th:text="${select.dictionaryName}"></option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'checkbox'}" pane>
                        <label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
                        <div class="layui-input-block">
                            <div th:each="checkboxMap: ${checkboxMapList}" th:if="${checkboxMap.name eq dynamicFormFormShowFieldDTO.fieldName}">
                                <input type="checkbox" th:each="checkbox: ${checkboxMap.list}" th:name="${dynamicFormFormShowFieldDTO.fieldName +'['+ checkbox.dictionaryId +']'}" th:title="${checkbox.dictionaryName}">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'radio'}" pane>
                        <label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
                        <div class="layui-input-block">
                            <div th:each="radioMap: ${radioMapList}" th:if="${radioMap.name eq dynamicFormFormShowFieldDTO.fieldName}">
                                <input type="radio" th:each="radio: ${radioMap.list}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" th:value="${radio.dictionaryId}" th:title="${radio.dictionaryName}">
                            </div>
                        </div>
                    </div>
                    <!--/* 上传文件 */-->
                    <div class="layui-form-item layui-form-text" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'file'}">
                        <label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
                        <div class="layui-input-block">
                            <input type="hidden" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}">
                            <div class="layui-btn-container" th:id="${dynamicFormFormShowFieldDTO.fieldName +'FileBox'}" style="border: 1px solid #e6e6e6;"></div>
                            <script th:id="${dynamicFormFormShowFieldDTO.fieldName +'FileDownload'}" type="text/html" th:inline="javascript">
                                {{# var fileName = [[${dynamicFormFormShowFieldDTO.fieldName}]]; }}
                                {{# if(d[fileName] != '') { }}
                                {{#    var files = d[fileName];}}
                                {{#    for(var i = 0, item = files[i]; item = files[i++];) { }}
                                <span class="layui-btn-group">
                                    <div class="upload-file-box">
                                        <a class="upload-file-a" href="route/file/downloadfile/false/{{item.fileId}}" title="{{item.fileName}} - 点击下载">
                                            {{# if(item.fileType == 'doc' || item.fileType == 'docx') { }}
                                            <img src="assets/images/filetype/word.png"/>
                                            {{# } else if(item.fileType == 'xls' || item.fileType == 'xlsx') { }}
                                            <img src="assets/images/filetype/excel.png"/>
                                            {{# } else if(item.fileType == 'ppt' || item.fileType == 'pptx') { }}
                                            <img src="assets/images/filetype/ppt.png"/>
                                            {{# } else if(item.fileType == 'apk') { }}
                                            <img src="assets/images/filetype/apk.png"/>
                                            {{# } else if(item.fileType == 'pdf') { }}
                                            <img src="assets/images/filetype/pdf.png"/>
                                            {{# } else if(item.fileType == 'rar') { }}
                                            <img src="assets/images/filetype/rar.png"/>
                                            {{# } else if(item.fileType == 'zip') { }}
                                            <img src="assets/images/filetype/zip.png"/>
                                            {{# } else if(item.fileType == 'txt') { }}
                                            <img src="assets/images/filetype/txt.png"/>
                                            {{# } else { }}
                                            <img src="assets/images/filetype/file.png"/>
                                            {{# } }}
                                        </a>
                                        <span class="upload-file-title">{{item.fileName}}</span>
                                        <a class="layui-btn layui-btn-xs layui-btn-danger text-danger remove-file" href="javascript:void(0);" lay-form-button data-id="{{item.fileId}}" data-name="{{fileName}}" th:attr="lay-filter=${dynamicFormFormShowFieldDTO.fieldName +'RemoveFile'}">
                                            <i class="fa fa-trash-o"></i>
                                        </a>
                                    </div>
                                </span>
                                {{#    } }}
                                {{# } }}
                                {{# if(d[fileName].length < 9) { }}
                                <div class="upload-image-box" style="width: auto; height: auto; padding: 5px;">
                                    <a href="javascript:void(0);" lay-form-button th:attr="data-explain=${dynamicFormFormShowFieldDTO.fieldExplain}, data-name=${dynamicFormFormShowFieldDTO.fieldName}, lay-filter=${dynamicFormFormShowFieldDTO.fieldName +'UploadFile'}">
                                        <i class="fa fa-plus-square-o" style="font-size: 70px;"></i>
                                    </a>
                                </div>
                                {{# } }}
                            </script>
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'image'}">
                        <label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
                        <div class="layui-input-block">
                            <input type="hidden" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}">
                            <div class="layui-btn-container" th:id="${dynamicFormFormShowFieldDTO.fieldName +'FileBox'}" style="border: 1px solid #e6e6e6;"></div>
                            <script th:id="${dynamicFormFormShowFieldDTO.fieldName +'FileDownload'}" type="text/html" th:inline="javascript">
                                {{# var fileName = [[${dynamicFormFormShowFieldDTO.fieldName}]] }}
                                {{# if(d[fileName].length > 0) { }}
                                {{#    var files = d[fileName];}}
                                {{#    for(var i = 0, item = files[i]; item = files[i++];) { }}
                                <div class="upload-image-box">
                                    <span class="upload-image-span">
                                        <img src="route/file/downloadfile/false/{{item.fileId}}" align="加载失败">
                                    </span>
                                    <a class="layui-btn layui-btn-xs layui-btn-danger text-danger remove-image" href="javascript:void(0);" lay-form-button data-id="{{item.fileId}}" data-name="{{fileName}}" th:attr="lay-filter=${dynamicFormFormShowFieldDTO.fieldName +'RemoveFile'}">
                                        <i class="fa fa-trash-o"></i>
                                    </a>
                                </div>
                                {{#    } }}
                                {{# } }}
                                {{# if(d[fileName].length < 9) { }}
                                <div class="upload-image-box" style="width: auto; height: auto; padding: 5px;">
                                    <a href="javascript:void(0);" lay-form-button th:attr="data-explain=${dynamicFormFormShowFieldDTO.fieldExplain}, data-name=${dynamicFormFormShowFieldDTO.fieldName}, lay-filter=${dynamicFormFormShowFieldDTO.fieldName +'UploadFile'}">
                                        <i class="fa fa-plus-square-o" style="font-size: 70px;"></i>
                                    </a>
                                </div>
                                {{# } }}
                            </script>
                        </div>
                    </div>
                    <!--/* 上传视频 */-->
                    <div class="layui-form-item layui-form-text" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'video'}">
                        <label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
                        <div class="layui-input-block">
                            <input type="hidden" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}">
                            <div class="layui-btn-container" th:id="${dynamicFormFormShowFieldDTO.fieldName +'FileBox'}" style="border: 1px solid #e6e6e6;"></div>
                            <script th:id="${dynamicFormFormShowFieldDTO.fieldName +'FileDownload'}" type="text/html" th:inline="javascript">
                                {{# var fileName = [[${dynamicFormFormShowFieldDTO.fieldName}]] }}
                                {{# if(d[fileName] != '') { }}
                                {{#    var files = d[fileName];}}
                                {{#    for(var i = 0, item = files[i]; item = files[i++];) {}}
                                <div class="upload-video-box">
                                    <div id="video{{i}}" style="width:300px; height:200px;"></div>
                                    <a class="layui-btn layui-btn-xs layui-btn-danger text-danger remove-video" href="javascript:void(0);" lay-form-button data-id="{{item.fileId}}" data-name="{{fileName}}" th:attr="lay-filter=${dynamicFormFormShowFieldDTO.fieldName +'RemoveFile'}">
                                        <i class="fa fa-trash-o"></i>
                                    </a>
                                </div>
                                {{#    } }}
                                {{# } }}
                                {{# if(d[fileName].length < 1) { }}
                                <div class="upload-image-box" style="width: auto; height: auto; padding: 5px;">
                                    <a href="javascript:void(0);" lay-form-button th:attr="data-explain=${dynamicFormFormShowFieldDTO.fieldExplain}, data-name=${dynamicFormFormShowFieldDTO.fieldName}, lay-filter=${dynamicFormFormShowFieldDTO.fieldName +'UploadFile'}">
                                        <i class="fa fa-plus-square-o" style="font-size: 70px;"></i>
                                    </a>
                                </div>
                                {{# } }}
                            </script>
                        </div>
                    </div>
                    <!--/* 上传音频 */-->
                    <div class="layui-form-item layui-form-text" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'audio'}">
                        <label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
                        <div class="layui-input-block">
                            <input type="hidden" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}">
                            <div class="layui-btn-container" th:id="${dynamicFormFormShowFieldDTO.fieldName +'FileBox'}" style="border: 1px solid #e6e6e6;"></div>
                            <script th:id="${dynamicFormFormShowFieldDTO.fieldName +'FileDownload'}" type="text/html" th:inline="javascript">
                                {{# var fileName = [[${dynamicFormFormShowFieldDTO.fieldName}]] }}
                                {{# if(d[fileName] != '') { }}
                                {{#    var files = d[fileName];}}
                                {{#    for(var i = 0, item = files[i]; item = files[i++];) {}}
                                <div class="upload-audio-box">
                                    <audio src="route/file/downloadfile/true/{{item.fileId}}" controls="controls">您的浏览器不支持 audio 标签。</audio>
                                    <a class="layui-btn layui-btn-xs layui-btn-danger text-danger remove-audio" href="javascript:void(0);" lay-form-button data-id="{{item.fileId}}" data-name="{{fileName}}" th:attr="lay-filter=${dynamicFormFormShowFieldDTO.fieldName +'RemoveFile'}">
                                        <i class="fa fa-trash-o"></i>
                                    </a>
                                </div>
                                {{#    } }}
                                {{# } }}
                                {{# if(d[fileName].length < 1) { }}
                                <div class="upload-image-box" style="width: auto; height: auto; padding: 5px;">
                                    <a href="javascript:void(0);" lay-form-button th:attr="data-explain=${dynamicFormFormShowFieldDTO.fieldExplain}, data-name=${dynamicFormFormShowFieldDTO.fieldName}, lay-filter=${dynamicFormFormShowFieldDTO.fieldName +'UploadFile'}">
                                        <i class="fa fa-plus-square-o" style="font-size: 70px;"></i>
                                    </a>
                                </div>
                                {{# } }}
                            </script>
                        </div>
                    </div>
                    <!--/* 选择人员 */-->
                    <div class="layui-form-item" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'selectUser'}">
                        <label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
                        <div class="layui-input-block">
                            <input type="hidden" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}">
                            <input type="text" th:id="${dynamicFormFormShowFieldDTO.fieldName +'SelectUser'}" class="layui-input" th:placeholder="${'请选择'+ dynamicFormFormShowFieldDTO.fieldExplain}" th:attr="data-name=${dynamicFormFormShowFieldDTO.fieldName}" readonly style="cursor:pointer;">
                        </div>
                    </div>
                    <!--/* 选择部门 */-->
                    <div class="layui-form-item" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'selectDepartment'}">
                        <label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
                        <div class="layui-input-block">
                            <input type="hidden" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" th:value="${dynamicFormFormShowFieldDTO.fieldDefault}">
                            <input type="text" th:id="${dynamicFormFormShowFieldDTO.fieldName +'SelectDepartment'}" class="layui-input" th:placeholder="${'请选择'+ dynamicFormFormShowFieldDTO.fieldExplain}" th:attr="data-name=${dynamicFormFormShowFieldDTO.fieldName}" readonly style="cursor:pointer;">
                        </div>
                    </div>
                    <!--/* 当前用户 */-->
                    <div class="layui-form-item" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'currentUser'}">
                        <label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
                        <div class="layui-input-block">
                            <input type="hidden" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" th:value="${userIdAndValue}">
                            <input type="text" class="layui-input" th:id="${dynamicFormFormShowFieldDTO.fieldName +'CurrentUser'}" th:value="${userNameValue}" readonly>
                        </div>
                    </div>
                    <!--/* 当前组织 */-->
                    <div class="layui-form-item" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'currentDepartment'}">
                        <label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
                        <div class="layui-input-block">
                            <input type="hidden" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" th:value="${departmentIdAndNamesValue}">
                            <input type="text" class="layui-input" th:id="${dynamicFormFormShowFieldDTO.fieldName +'CurrentDepartment'}" th:value="${departmentNamesValue}" readonly>
                        </div>
                    </div>
                    <!--/* 当前角色 */-->
                    <div class="layui-form-item" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'currentRole'}">
                        <label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
                        <div class="layui-input-block">
                            <input type="hidden" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" th:value="${roleIdAndNamesValue}">
                            <input type="text" class="layui-input" th:id="${dynamicFormFormShowFieldDTO.fieldName +'CurrentRole'}" th:value="${roleNamesValue}" readonly>
                        </div>
                    </div>
                    <!--/* 当前组 */-->
                    <div class="layui-form-item" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'currentGroup'}">
                        <label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
                        <div class="layui-input-block">
                            <input type="hidden" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" th:value="${groupIdAndNamesValue}">
                            <input type="text" class="layui-input" th:id="${dynamicFormFormShowFieldDTO.fieldName +'CurrentGroup'}" th:value="${groupNamesValue}" readonly>
                        </div>
                    </div>
                    <!--/* 当前职位 */-->
                    <div class="layui-form-item" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'currentPosition'}">
                        <label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
                        <div class="layui-input-block">
                            <input type="hidden" th:id="${dynamicFormFormShowFieldDTO.fieldName}" th:name="${dynamicFormFormShowFieldDTO.fieldName}" th:value="${positionIdAndNamesValue}">
                            <input type="text" class="layui-input" th:id="${dynamicFormFormShowFieldDTO.fieldName +'CurrentPosition'}" th:value="${positionNamesValue}" readonly>
                        </div>
                    </div>
                    <!--/* 选择联表 */-->
                    <div class="layui-form-item" th:if="${dynamicFormFormShowFieldDTO.fieldType eq 'leftJoin' or dynamicFormFormShowFieldDTO.fieldType eq 'innerJoin' or dynamicFormFormShowFieldDTO.fieldType eq 'rightJoin'}">
                        <label class="layui-form-label" th:text="${dynamicFormFormShowFieldDTO.fieldExplain}"></label>
                        <div class="layui-input-block layui-form" th:id="${dynamicFormFormShowFieldDTO.fieldName} +'TemplateBox'" th:attr="lay-filter=${dynamicFormFormShowFieldDTO.fieldName} +'TemplateBox'"></div>
                        <script th:id="${dynamicFormFormShowFieldDTO.fieldName} +'Template'" type="text/html">
                            <select th:name="${dynamicFormFormShowFieldDTO.fieldName}">
                                <option value="" th:text="'选择'+ ${dynamicFormFormShowFieldDTO.fieldExplain}"></option>
                                {{# for(var i = 0, item; item = d[i++];) { }}
                                <option th:value="'{{item.'+ ${dynamicFormFormShowFieldDTO.joinTable} +'Id}}'" th:text="'{{item.'+ ${dynamicFormFormShowFieldDTO.joinTableFormShow} +'}}'"></option>
                                {{# } }}
                            </select>
                        </script>
                    </div>
                </div>

                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-input-block">
                        <div class="layui-footer" style="left: 0;">
                            <button type="button" class="layui-btn" lay-submit lay-filter="submitForm">提交编辑</button>
                            <button type="button" class="layui-btn layui-btn-primary close">返回上级</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<input type="hidden" id="tableName" th:value="${tableName}"/>
<input type="hidden" id="joinKey" th:value="${joinKey}"/>
<input type="hidden" id="joinId" th:value="${joinId}"/>
<script src="assets/js/vendor/wangEditor/wangEditor.min.js"></script>
<script src="assets/js/vendor/ckplayer/ckplayer/ckplayer.js"></script>
<script src="assets/js/vendor/viewer/viewer.min.js"></script>
<script src="assets/layuiadmin/layui/layui.js"></script>
<script th:inline="javascript">
    layui.config({
        base: 'assets/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'laydate', 'laytpl'], function(){
        var $ = layui.$;
        var form = layui.form;
        var laytpl = layui.laytpl;
        var laydate = layui.laydate;
        var saveOrEdit = 'save';
        var wangEditor = window.wangEditor;
        var wangEditorArray = [];
        var formFieldList = [[${dynamicFormFormShowFieldDTOList}]];
        var viewerObj = {};

        function closeBox() {
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        }

        function refreshDownloadTemplet(fileName, file) {
            var dataRander = {};
            dataRander[fileName] = file;

            laytpl(document.getElementById(fileName +'FileDownload').innerHTML).render(dataRander, function(html) {
                document.getElementById(fileName +'FileBox').innerHTML = html;
            });
        }

        // 初始化文件列表
        function initFileList(fileName, ids, callback) {
            var dataForm = {};
            dataForm[fileName] = ids;
            form.val('dataForm', dataForm);

            if(!ids) {
                refreshDownloadTemplet(fileName, []);
                if(callback) {
                    callback(fileName, []);
                }
                return;
            }

            top.restAjax.get(top.restAjax.path('api/file/listfilebyfileid', []), {
                ids: ids
            }, null, function(code, data) {
                refreshDownloadTemplet(fileName, data);
                if(callback) {
                    callback(fileName, data);
                }
            }, function(code, data) {
                top.dialog.msg(data.msg);
            });
        }

        // 初始化视频
        function initVideo(fileName, data) {
            for(var i = 0, item; item = data[i++];) {
                var player = new ckplayer({
                    container: '#'+ fileName + i,
                    variable: 'player',
                    flashplayer: false,
                    video: {
                        file: 'route/file/downloadfile/true/'+ item.fileId,
                        type: 'video/mp4'
                    }
                });
            }
        }

        // 初始化
        function initData() {
            var loadLayerIndex;
            top.restAjax.get(top.restAjax.path('api/dynamicdata/getdynamicjoindata/{tableName}/{joinKey}/{joinId}', [$('#tableName').val(), $('#joinKey').val(), $('#joinId').val()]), {}, null, function(code, data) {
                if(Object.keys(data).length > 0) {
                    saveOrEdit = 'update'
                }
                // 处理返回内容
                var dataFormData = {}
                for(var i in data) {
                    dataFormData[i] = data[i];
                }
                form.val('dataForm', dataFormData);
                // 处理checkbox
                for(var i = 0, item = formFieldList[i]; item = formFieldList[i++];) {
                    if(item.fieldType === 'checkbox') {
                        if(typeof(data[item.fieldName]) === 'undefined') {
                            continue;
                        }
                        var checkboxValue = data[item.fieldName].split(',');
                        var checkboxObj = {};
                        for(var j = 0, checkbox = checkboxValue[j]; checkbox = checkboxValue[j++];) {
                            checkboxObj[item.fieldName +'['+ checkbox +']'] = true;
                            form.val('dataForm', checkboxObj);
                        }
                    }
                }
                form.render(null, 'dataForm');
                for(var i = 0, item; item = formFieldList[i++];) {
                    if(item.fieldType === 'date') {
                        laydate.render({
                            elem: '#'+ item.fieldName,
                            type: 'date',
                            value: new Date(),
                            trigger: 'click'
                        });
                    } else if(item.fieldType === 'datetime') {
                        laydate.render({
                            elem: '#'+ item.fieldName,
                            type: 'datetime',
                            value: new Date(),
                            trigger: 'click'
                        });
                    } else if(item.fieldType === 'richText') {
                        var editor = new wangEditor('#'+ item.fieldName);
                        editor.customConfig.zIndex = 1000;
                        editor.customConfig.uploadImgMaxSize = 5 * 1024 * 1024;
                        editor.customConfig.uploadImgMaxLength = 1;
                        editor.customConfig.uploadFileName = 'image';
                        editor.customConfig.uploadImgServer = 'api/file/wangeditorimage';
                        editor.customConfig.uploadImgHooks = {
                            fail: function (xhr, editor, result) {
                                top.dialog.msg('系统错误，图片上传失败');
                            },
                            error: function (xhr, editor) {
                                top.dialog.msg('网络异常');
                            },
                            timeout: function (xhr, editor) {
                                top.dialog.msg('网络请求超时');
                            }
                        };
                        editor.create();
                        editor.txt.html(dataFormData[item.fieldName]);
                        var wangEditorObj = {};
                        wangEditorObj[item.fieldName] = editor;
                        wangEditorArray.push(wangEditorObj);
                    } else if(item.fieldType === 'file') {
                        var files = $('#'+ item.fieldName).val();
                        initFileList(item.fieldName, files);

                        form.on('button('+ item.fieldName +'UploadFile)', function(obj) {
                            var name = this.dataset.name;
                            var explain = this.dataset.explain;
                            top.dialog.file({
                                type: 'file',
                                title: '上传'+ explain,
                                width: '400px',
                                height: '420px',
                                maxFileCount: '1',
                                onClose: function() {
                                    var uploadFileArray = top.dialog.dialogData.uploadFileArray;
                                    if(typeof(uploadFileArray) != 'undefined' && uploadFileArray.length > 0) {
                                        var files = $('#'+ name).val();
                                        for(var j = 0, file = uploadFileArray[j]; file = uploadFileArray[j++];) {
                                            if(files.length > 0) {
                                                files += ',';
                                            }
                                            files += file.data;
                                        }
                                        initFileList(name, files, function() {});
                                    }
                                }
                            });
                        });
                        form.on('button('+ item.fieldName +'RemoveFile)', function(obj) {
                            var name = this.dataset.name;
                            var id = this.dataset.id;
                            var files = $('#'+ name).val().replace(id, '');
                            files = files.replace(/\,+/g, ',');
                            if(files.charAt(0) == ',') {
                                files = files.substring(1);
                            }
                            if(files.charAt(files.length - 1) == ',') {
                                files = files.substring(0, files.length - 1);
                            }
                            initFileList(name, files, function() {});
                        });
                    } else if(item.fieldType === 'image') {
                        var files = $('#'+ item.fieldName).val();
                        initFileList(item.fieldName, files, function(fileName) {
                            var viewer = new Viewer(document.getElementById(fileName +'FileBox'), {navbar: false});
                            viewerObj[fileName] = viewer;
                        });

                        form.on('button('+ item.fieldName +'UploadFile)', function(obj) {
                            var name = this.dataset.name;
                            var explain = this.dataset.explain;
                            top.dialog.file({
                                type: 'image',
                                title: '上传'+ explain,
                                width: '400px',
                                height: '420px',
                                maxFileCount: '1',
                                onClose: function() {
                                    var uploadFileArray = top.dialog.dialogData.uploadFileArray;
                                    if(typeof(uploadFileArray) != 'undefined' && uploadFileArray.length > 0) {
                                        var files = $('#'+ name).val();
                                        for(var j = 0, file = uploadFileArray[j]; file = uploadFileArray[j++];) {
                                            if(files.length > 0) {
                                                files += ',';
                                            }
                                            files += file.data;
                                        }
                                        initFileList(name, files, function() {
                                            viewerObj[name].update();
                                        });
                                    }
                                }
                            });
                        });

                        form.on('button('+ item.fieldName +'RemoveFile)', function(obj) {
                            var name = this.dataset.name;
                            var id = this.dataset.id;
                            var files = $('#'+ name).val().replace(id, '');
                            files = files.replace(/\,+/g, ',');
                            if(files.charAt(0) == ',') {
                                files = files.substring(1);
                            }
                            if(files.charAt(files.length - 1) == ',') {
                                files = files.substring(0, files.length - 1);
                            }
                            initFileList(name, files, function(fileName) {
                                viewerObj[fileName].update();
                            });
                        });
                    } else if(item.fieldType === 'video') {
                        var files = $('#'+ item.fieldName).val();
                        initFileList(item.fieldName, files, initVideo);

                        form.on('button('+ item.fieldName +'UploadFile)', function(obj) {
                            var name = this.dataset.name;
                            var explain = this.dataset.explain;
                            top.dialog.file({
                                type: 'video',
                                title: '上传'+ explain,
                                width: '400px',
                                height: '420px',
                                maxFileCount: '1',
                                onClose: function() {
                                    var uploadFileArray = top.dialog.dialogData.uploadFileArray;
                                    if(typeof(uploadFileArray) != 'undefined' && uploadFileArray.length > 0) {
                                        var files = $('#'+ name).val();
                                        for(var j = 0, file = uploadFileArray[j]; file = uploadFileArray[j++];) {
                                            if(files.length > 0) {
                                                files += ',';
                                            }
                                            files += file.data;
                                        }
                                        initFileList(name, files, initVideo);
                                    }
                                }
                            });
                        });

                        form.on('button('+ item.fieldName +'RemoveFile)', function(obj) {
                            var name = this.dataset.name;
                            var id = this.dataset.id;
                            var files = $('#'+ name).val().replace(id, '');
                            files = files.replace(/\,+/g, ',');
                            if(files.charAt(0) == ',') {
                                files = files.substring(1);
                            }
                            if(files.charAt(files.length - 1) == ',') {
                                files = files.substring(0, files.length - 1);
                            }
                            initFileList(name, files, initVideo);
                        });
                    } else if(item.fieldType === 'audio') {
                        var files = $('#'+ item.fieldName).val();
                        initFileList(item.fieldName, files);

                        form.on('button('+ item.fieldName +'UploadFile)', function(obj) {
                            var name = this.dataset.name;
                            var explain = this.dataset.explain;
                            top.dialog.file({
                                type: 'audio',
                                title: '上传'+ explain,
                                width: '400px',
                                height: '420px',
                                maxFileCount: '1',
                                onClose: function() {
                                    var uploadFileArray = top.dialog.dialogData.uploadFileArray;
                                    if(typeof(uploadFileArray) != 'undefined' && uploadFileArray.length > 0) {
                                        var files = $('#'+ name).val();
                                        for(var j = 0, file = uploadFileArray[j]; file = uploadFileArray[j++];) {
                                            if(files.length > 0) {
                                                files += ',';
                                            }
                                            files += file.data;
                                        }
                                        initFileList(name, files);
                                    }
                                }
                            });
                        });

                        form.on('button('+ item.fieldName +'RemoveFile)', function(obj) {
                            var name = this.dataset.name;
                            var id = this.dataset.id;
                            var files = $('#'+ name).val().replace(id, '');
                            files = files.replace(/\,+/g, ',');
                            if(files.charAt(0) == ',') {
                                files = files.substring(1);
                            }
                            if(files.charAt(files.length - 1) == ',') {
                                files = files.substring(0, files.length - 1);
                            }
                            initFileList(name, files);
                        });
                    } else if(item.fieldType === 'selectUser') {
                        var showSelectedUsersVal = '';
                        var selectDepartmentUser = $('#'+ item.fieldName).val().split(',');
                        for(var selectDepartmentUserIndex = 0, selectDepartmentUserItem = selectDepartmentUser[selectDepartmentUserIndex]; selectDepartmentUserItem = selectDepartmentUser[selectDepartmentUserIndex++];) {
                            var userInfo = selectDepartmentUserItem.split('|');
                            if(showSelectedUsersVal.length > 0) {
                                showSelectedUsersVal += ',';
                            }
                            showSelectedUsersVal += userInfo[2];
                        }
                        $('#'+ item.fieldName +'SelectUser').val(showSelectedUsersVal);
                        //----//
                        $(document.body).on('click', '#'+ item.fieldName +'SelectUser', function() {
                            var name = this.dataset.name;
                            var selectedUsers = [];
                            var selectDepartmentUser = $('#'+ name).val().split(',');
                            for(var selectDepartmentUserIndex = 0, item = selectDepartmentUser[selectDepartmentUserIndex]; item = selectDepartmentUser[selectDepartmentUserIndex++];) {
                                var userInfo = item.split('|');
                                selectedUsers.push({
                                    userId: userInfo[0],
                                    departmentId: userInfo[1]
                                });
                            }
                            top.dialog.dialogData.selectedUsers = selectedUsers;
                            top.dialog.open({
                                url: top.restAjax.path('route/tree/treeuser', []),
                                title: '选择组织部门人员',
                                width: '500px',
                                height: '500px',
                                onClose: function() {
                                    var selectedUsers = top.dialog.dialogData.selectedDepartmentUsers;
                                    if(selectedUsers != null && selectedUsers.length > 0) {
                                        var selectedUsersVal = '';
                                        var showSelectedUsersVal = '';
                                        for(var j = 0, selectUser = selectedUsers[j]; selectUser = selectedUsers[j++];) {
                                            if(selectedUsersVal.length > 0) {
                                                selectedUsersVal += ',';
                                            }
                                            if(showSelectedUsersVal.length > 0) {
                                                showSelectedUsersVal += ',';
                                            }
                                            selectedUsersVal += (selectUser.userId +'|'+ selectUser.departmentId +'|'+ selectUser.userName +'|'+ selectUser.userTitle);
                                            showSelectedUsersVal += selectUser.userName;
                                        }
                                        $('#'+ name).val(selectedUsersVal);
                                        $('#'+ name +'SelectUser').val(showSelectedUsersVal);
                                    } else {
                                        $('#'+ name).val('');
                                        $('#'+ name +'SelectUser').val('');
                                    }
                                }
                            });
                        });
                    } else if(item.fieldType === 'selectDepartment') {
                        var showSelectedDepartmentsVal = '';
                        var selectDepartment = $('#'+ item.fieldName).val().split(',');
                        for(var selectDepartmentIndex = 0, selectDepartmentItem = selectDepartment[selectDepartmentIndex]; selectDepartmentItem = selectDepartment[selectDepartmentIndex++];) {
                            var departmentInfo = selectDepartmentItem.split('|');
                            if(showSelectedDepartmentsVal.length > 0) {
                                showSelectedDepartmentsVal += ',';
                            }
                            showSelectedDepartmentsVal += departmentInfo[1];
                        }
                        $('#'+ item.fieldName +'SelectDepartment').val(showSelectedDepartmentsVal);
                        //----//
                        $(document.body).on('click', '#'+ item.fieldName +'SelectDepartment', function() {
                            var name = this.dataset.name;
                            var selectedNodes = [];
                            var selectDepartment = $('#'+ name).val().split(',');
                            for(var selectDepartmentIndex = 0, item = selectDepartment[selectDepartmentIndex]; item = selectDepartment[selectDepartmentIndex++];) {
                                var departmentInfo = item.split('|');
                                selectedNodes.push({
                                    id: departmentInfo[0],
                                    name: departmentInfo[1],
                                    title: departmentInfo[1]
                                });
                            }
                            top.dialog.tree({
                                title: '选择部门',
                                apiUri: top.restAjax.path('api/department/listztreedepartment', []),
                                width: '250px',
                                height: '400px',
                                dataFilter: function(treeId, parentNode, childNodes) {
                                    return childNodes;
                                },
                                check: {
                                    enable: true,
                                    selectType: 'checkbox',
                                    checkboxType: {Y: 'ps', N: 'ps'},
                                    radioType: 'level',
                                },
                                selectedNodes: selectedNodes,
                                onClose: function() {
                                    var selectNodes = top.dialog.dialogTreeData.selectedNodes;
                                    if(typeof(selectNodes) != 'undefined' && selectNodes != null) {
                                        if(selectNodes.length > 0) {
                                            var selectedDepartmentVal = '';
                                            var showSelectedDepartmentsVal = '';
                                            for(var j = 0, selectNode = selectNodes[j]; selectNode = selectNodes[j++];) {
                                                if(selectedDepartmentVal.length > 0) {
                                                    selectedDepartmentVal += ',';
                                                }
                                                if(showSelectedDepartmentsVal.length > 0) {
                                                    showSelectedDepartmentsVal += ',';
                                                }
                                                selectedDepartmentVal += (selectNode.id +'|'+ selectNode.name);
                                                showSelectedDepartmentsVal += selectNode.name;
                                            }
                                            $('#'+ name).val(selectedDepartmentVal);
                                            $('#'+ name +'SelectDepartment').val(showSelectedDepartmentsVal);
                                        } else {
                                            $('#'+ name).val('');
                                            $('#'+ name +'SelectDepartment').val('');
                                        }
                                    }
                                }
                            });
                        });
                    } else if(item.fieldType === 'leftJoin' || item.fieldType === 'innerJoin' || item.fieldType === 'rightJoin') {
                        top.restAjax.get(top.restAjax.path('api/dynamicdata/listdynamicdata/{tableName}', [item.joinTable]), {}, {fieldName: item.fieldName}, function(code, data, args) {
                            laytpl(document.getElementById(args.fieldName +'Template').innerHTML).render(data, function(html) {
                                document.getElementById(args.fieldName +'TemplateBox').innerHTML = html;
                            });
                            // 初始化选择
                            var formSelectData = {};
                            formSelectData[args.fieldName] = dataFormData[args.fieldName];
                            form.val('dataForm', formSelectData);
                            // 刷新
                            form.render('select', args.fieldName +'TemplateBox');
                        }, function(code, data) {
                            top.dialog.msg(data.msg);
                        });
                    } else if(item.fieldType === 'currentUser') {
                        var formData = {};
                        var idAndNameValue = dataFormData[item.fieldName];
                        var nameValue = (typeof(idAndNameValue) != 'undefined' && idAndNameValue != null && idAndNameValue != '') ? idAndNameValue.split('|')[1] : '';
                        formData[item.fieldName] = idAndNameValue;
                        formData[item.fieldName +'CurrentUser'] = nameValue;
                        form.val('dataForm', formData);
                    } else if(item.fieldType === 'currentDepartment') {
                        var formData = {};
                        var idAndNameValue = dataFormData[item.fieldName];
                        var nameValue = (typeof(idAndNameValue) != 'undefined' && idAndNameValue != null && idAndNameValue != '') ? idAndNameValue.split('|')[1] : '';
                        formData[item.fieldName] = idAndNameValue;
                        formData[item.fieldName +'CurrentDepartment'] = nameValue;
                        form.val('dataForm', formData);
                    } else if(item.fieldType === 'currentRole') {
                        var formData = {};
                        var idAndNameValue = dataFormData[item.fieldName];
                        var nameValue = (typeof(idAndNameValue) != 'undefined' && idAndNameValue != null && idAndNameValue != '') ? idAndNameValue.split('|')[1] : '';
                        formData[item.fieldName] = idAndNameValue;
                        formData[item.fieldName +'CurrentRole'] = nameValue;
                        form.val('dataForm', formData);
                    } else if(item.fieldType === 'currentGroup') {
                        var formData = {};
                        var idAndNameValue = dataFormData[item.fieldName];
                        var nameValue = (typeof(idAndNameValue) != 'undefined' && idAndNameValue != null && idAndNameValue != '') ? idAndNameValue.split('|')[1] : '';
                        formData[item.fieldName] = idAndNameValue;
                        formData[item.fieldName +'CurrentGroup'] = nameValue;
                        form.val('dataForm', formData);
                    } else if(item.fieldType === 'currentPosition') {
                        var formData = {};
                        var idAndNameValue = dataFormData[item.fieldName];
                        var nameValue = (typeof(idAndNameValue) != 'undefined' && idAndNameValue != null && idAndNameValue != '') ? idAndNameValue.split('|')[1] : '';
                        formData[item.fieldName] = idAndNameValue;
                        formData[item.fieldName +'CurrentPosition'] = nameValue;
                        form.val('dataForm', formData);
                    }
                }
            }, function(code, data) {
                top.dialog.msg(data.msg);
            }, function() {
                loadLayerIndex = top.dialog.msg(top.dataMessage.loading, {icon: 16, time: 0, shade: 0.3});
            }, function() {
                top.dialog.close(loadLayerIndex);
            });
        }
        initData();

        // 提交表单
        form.on('submit(submitForm)', function(formData) {
            top.dialog.confirm(top.dataMessage.commit, function(index) {
                top.dialog.close(index);
                var loadLayerIndex;
                // 处理富文本
                for(var i = 0, item = wangEditorArray[i]; item = wangEditorArray[i++];) {
                    for(var j in item) {
                        formData.field[j] = item[j].txt.html();
                    }
                }
                // 处理checkbox
                for(var i = 0, item = formFieldList[i]; item = formFieldList[i++];) {
                    if(item.fieldType === 'checkbox') {
                        var checkboxValue = top.restAjax.checkBoxToString(formData.field, item.fieldName);
                        formData.field[item.fieldName] = checkboxValue;
                    }
                }
                if(saveOrEdit === 'save') {
                    top.restAjax.post(top.restAjax.path('api/dynamicdata/savedynamicdata/{tableName}', [$('#tableName').val()]), formData.field, null, function(code, data) {
                        var layerIndex = top.dialog.msg(top.dataMessage.commitSuccess, {
                            time: 0,
                            btn: [top.dataMessage.button.yes, top.dataMessage.button.no],
                            shade: 0.3,
                            yes: function(index) {
                                top.dialog.close(index);
                                window.location.reload();
                            },
                            btn2: function() {
                                closeBox();
                            }
                        });
                    }, function(code, data) {
                        top.dialog.msg(data.msg);
                    }, function() {
                        loadLayerIndex = top.dialog.msg(top.dataMessage.committing, {icon: 16, time: 0, shade: 0.3});
                    }, function() {
                        top.dialog.close(loadLayerIndex);
                    });
                } else {
                    top.restAjax.put(top.restAjax.path('api/dynamicdata/updatedynamicjoindata/{tableName}/{joinKey}/{joinId}', [$('#tableName').val(), $('#joinKey').val(), $('#joinId').val()]), formData.field, null, function(code, data) {
                        var layerIndex = top.dialog.msg(top.dataMessage.commitSuccess, {
                            time: 0,
                            btn: [top.dataMessage.button.yes, top.dataMessage.button.no],
                            shade: 0.3,
                            yes: function(index) {
                                top.dialog.close(index);
                                window.location.reload();
                            },
                            btn2: function() {
                                closeBox();
                            }
                        });
                    }, function(code, data) {
                        top.dialog.msg(data.msg);
                    }, function() {
                        loadLayerIndex = top.dialog.msg(top.dataMessage.committing, {icon: 16, time: 0, shade: 0.3});
                    }, function() {
                        top.dialog.close(loadLayerIndex);
                    });
                }
            });
            return false;
        });
        $('.close').on('click', function() {
            closeBox();
        });
    });
</script>
</body>
</html>