<!doctype html>
<html lang="en">
<head>
    <base href="/${context}/">
    <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" type="text/css" href="assets/js/vendor/viewer/viewer.min.css">
</head>
<body>
<div class="layui-fluid layui-anim layui-anim-fadein">
    <div class="layui-card">
        <div class="layui-card-header">
            <span class="layui-breadcrumb" lay-filter="breadcrumb" style="visibility: visible;">
              <a class="close" href="javascript:void(0);">上级列表</a><span lay-separator="">/</span>
              <a href="javascript:void(0);"><cite>新增内容</cite></a>
            </span>
        </div>
        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form layui-form-pane" lay-filter="dataForm">
                <#list fieldList! as field>
                    <#if field.formShow == 1>
                        <#if field.fieldType == "datetime" || field.fieldType == "date">
                <div class="layui-form-item">
                    <label class="layui-form-label">${field.fieldExplain}</label>
                    <div class="layui-input-block">
                        <input type="text" id="${field.fieldName}" name="${field.fieldName}" class="layui-input" value="${field.fieldDefault}" placeholder="请选择${field.fieldExplain}" readonly style="cursor: pointer;" lay-verify="required">
                    </div>
                </div>
                        <#elseif field.fieldType == "number">
                <div class="layui-form-item">
                    <label class="layui-form-label">${field.fieldExplain}</label>
                    <div class="layui-input-block">
                        <input type="number" id="${field.fieldName}" name="${field.fieldName}" class="layui-input" value="${field.fieldDefault}" placeholder="请输入${field.fieldExplain}" lay-verify="required">
                    </div>
                </div>
                        <#elseif field.fieldType == "double">
                <div class="layui-form-item">
                    <label class="layui-form-label">${field.fieldExplain}</label>
                    <div class="layui-input-block">
                        <input type="number" step="0.01" id="${field.fieldName}" name="${field.fieldName}" class="layui-input" value="${field.fieldDefault}" placeholder="请输入${field.fieldExplain}" lay-verify="required">
                    </div>
                </div>
                        <#elseif field.fieldType == "textarea">
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">${field.fieldExplain}</label>
                    <div class="layui-input-block">
                        <textarea id="${field.fieldName}" name="${field.fieldName}" class="layui-textarea" placeholder="请输入${field.fieldExplain}"></textarea>
                    </div>
                </div>
                        <#elseif field.fieldType == "richText">
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">${field.fieldExplain}</label>
                    <div class="layui-input-block">
                        <div id="${field.fieldName}"></div>
                    </div>
                </div>
                        <#elseif field.fieldType == "select">
                <div class="layui-form-item">
                    <label class="layui-form-label">${field.fieldExplain}</label>
                    <div class="layui-input-block layui-form" id="${field.fieldName}SelectTemplateBox" lay-filter="${field.fieldName}SelectTemplateBox"></div>
                    <script id="${field.fieldName}SelectTemplate" type="text/html">
                        <select id="${field.fieldName}" name="${field.fieldName}">
                            <option value="">请选择${field.fieldExplain}</option>
                            {{# for(var i = 0, item; item = d[i++];) { }}
                            <option value="{{item.dictionaryId}}">{{item.dictionaryName}}</option>
                            {{# } }}
                        </select>
                    </script>
                </div>
                        <#elseif field.fieldType == "checkbox">
                <div class="layui-form-item" pane>
                    <label class="layui-form-label">${field.fieldExplain}</label>
                    <div class="layui-input-block layui-form" id="${field.fieldName}CheckboxTemplateBox" lay-filter="${field.fieldName}CheckboxTemplateBox"></div>
                    <script id="${field.fieldName}CheckboxTemplate" type="text/html">
                        {{# for(var i = 0, item; item = d[i++];) { }}
                        <input type="checkbox" name="${field.fieldName}[{{item.dictionaryId}}]" value="{{item.dictionaryId}}" title="{{item.dictionaryName}}">
                        {{# } }}
                    </script>
                </div>
                        <#elseif field.fieldType == "radio">
                <div class="layui-form-item" pane>
                    <label class="layui-form-label">${field.fieldExplain}</label>
                    <div class="layui-input-block layui-form" id="${field.fieldName}RadioTemplateBox" lay-filter="${field.fieldName}RadioTemplateBox"></div>
                    <script id="${field.fieldName}RadioTemplate" type="text/html">
                        {{# for(var i = 0, item; item = d[i++];) { }}
                        <input type="radio" name="${field.fieldName}" value="{{item.dictionaryId}}" title="{{item.dictionaryName}}">
                        {{# } }}
                    </script>
                </div>
                        <#elseif field.fieldType == "file">
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">${field.fieldExplain}</label>
                    <div class="layui-input-block">
                        <input type="hidden" id="${field.fieldName}" name="${field.fieldName}">
                        <div class="layui-btn-container" id="${field.fieldName}FileBox" style="border: 1px solid #e6e6e6;"></div>
                        <script id="${field.fieldName}FileDownload" type="text/html">
                            {{# var fileName = '${field.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}}" lay-filter="${field.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 data-explain="${field.fieldExplain}" data-name="${field.fieldName}" lay-filter="${field.fieldName}UploadFile">
                                    <i class="fa fa-plus-square-o" style="font-size: 70px;"></i>
                                </a>
                            </div>
                            {{# } }}
                        </script>
                    </div>
                </div>
                        <#elseif field.fieldType == "image">
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">${field.fieldExplain}</label>
                    <div class="layui-input-block">
                        <input type="hidden" id="${field.fieldName}" name="${field.fieldName}">
                        <div class="layui-btn-container" id="${field.fieldName +'FileBox'}" style="border: 1px solid #e6e6e6;"></div>
                        <script id="${field.fieldName}FileDownload" type="text/html">
                            {{# var fileName = '${field.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}}" lay-filter="${field.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 data-explain="${field.fieldExplain}" data-name="${field.fieldName}" lay-filter="${field.fieldName}UploadFile">
                                    <i class="fa fa-plus-square-o" style="font-size: 70px;"></i>
                                </a>
                            </div>
                            {{# } }}
                        </script>
                    </div>
                </div>
                        <#elseif field.fieldType == "video">
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">${field.fieldExplain}</label>
                    <div class="layui-input-block">
                        <input type="hidden" id="${field.fieldName}" name="${field.fieldName}">
                        <div class="layui-btn-container" id="${field.fieldName}FileBox" style="border: 1px solid #e6e6e6;"></div>
                        <script id="${field.fieldName}FileDownload" type="text/html">
                            {{# var fileName = '${field.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="{{fileName}}{{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}}" lay-filter="${field.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 data-explain="${field.fieldExplain}" data-name="${field.fieldName}" lay-filter="${field.fieldName}UploadFile">
                                    <i class="fa fa-plus-square-o" style="font-size: 70px;"></i>
                                </a>
                            </div>
                            {{# } }}
                        </script>
                    </div>
                </div>
                        <#elseif field.fieldType == "audio">
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">${field.fieldExplain}</label>
                    <div class="layui-input-block">
                        <input type="hidden" id="${field.fieldName}" name="${field.fieldName}">
                        <div class="layui-btn-container" id="${field.fieldName}FileBox" style="border: 1px solid #e6e6e6;"></div>
                        <script id="${field.fieldName}FileDownload" type="text/html">
                            {{# var fileName = '${field.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}}" lay-filter="${field.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 data-explain="${field.fieldExplain}" data-name="${field.fieldName}" lay-filter="${field.fieldName}UploadFile">
                                    <i class="fa fa-plus-square-o" style="font-size: 70px;"></i>
                                </a>
                            </div>
                            {{# } }}
                        </script>
                    </div>
                </div>
                        <#elseif field.fieldType == "selectUser">
                <div class="layui-form-item">
                    <label class="layui-form-label">${field.fieldExplain}</label>
                    <div class="layui-input-block">
                        <input type="hidden" id="${field.fieldName}" name="${field.fieldName}" value="${field.fieldDefault}">
                        <input type="text" id="${field.fieldName}SelectUser" class="layui-input" placeholder="请选择${field.fieldExplain}" data-name="${field.fieldName}" readonly style="cursor:pointer;">
                    </div>
                </div>
                        <#elseif field.fieldType == "selectDepartment">
                <div class="layui-form-item">
                    <label class="layui-form-label">${field.fieldExplain}</label>
                    <div class="layui-input-block">
                        <input type="hidden" id="${field.fieldName}" name="${field.fieldName}" value="${field.fieldDefault}">
                        <input type="text" id="${field.fieldName}SelectDepartment" class="layui-input" placeholder="请选择${field.fieldExplain}" data-name="${field.fieldName}" readonly style="cursor:pointer;">
                    </div>
                </div>
                        <#elseif field.fieldType == "currentUser">
                <div class="layui-form-item">
                    <label class="layui-form-label">${field.fieldExplain}</label>
                    <div class="layui-input-block">
                        <input type="hidden" id="${field.fieldName}" name="${field.fieldName}">
                        <input type="text" class="layui-input" id="${field.fieldName}CurrentUser" name="${field.fieldName}CurrentUser" readonly>
                    </div>
                </div>
                        <#elseif field.fieldType == "currentDepartment">
                <div class="layui-form-item">
                    <label class="layui-form-label">${field.fieldExplain}</label>
                    <div class="layui-input-block">
                        <input type="hidden" id="${field.fieldName}" name="${field.fieldName}">
                        <input type="text" class="layui-input" id="${field.fieldName}CurrentDepartment" name="${field.fieldName}CurrentDepartment" readonly>
                    </div>
                </div>
                        <#elseif field.fieldType == "currentRole">
                <div class="layui-form-item">
                    <label class="layui-form-label" >${field.fieldExplain}</label>
                    <div class="layui-input-block">
                        <input type="hidden" id="${field.fieldName}" name="${field.fieldName}">
                        <input type="text" class="layui-input" id="${field.fieldName}CurrentRole" name="${field.fieldName}CurrentRole" readonly>
                    </div>
                </div>
                        <#elseif field.fieldType == "currentGroup">
                <div class="layui-form-item">
                    <label class="layui-form-label">${field.fieldExplain}</label>
                    <div class="layui-input-block">
                        <input type="hidden" id="${field.fieldName}" name="${field.fieldName}">
                        <input type="text" class="layui-input" id="${field.fieldName}CurrentGroup" name="${field.fieldName}CurrentGroup" readonly>
                    </div>
                </div>
                        <#elseif field.fieldType == "currentPosition">
                <div class="layui-form-item">
                    <label class="layui-form-label">${field.fieldExplain}</label>
                    <div class="layui-input-block">
                        <input type="hidden" id="${field.fieldName}" name="${field.fieldName}">
                        <input type="text" class="layui-input" id="${field.fieldName}CurrentPosition" name="${field.fieldName}CurrentPosition" readonly>
                    </div>
                </div>
                        <#elseif field.fieldType == "leftJoin" || field.fieldType == "innerJoin" || field.fieldType == "rightJoin">
                <div class="layui-form-item">
                    <label class="layui-form-label">${field.fieldExplain}</label>
                    <div class="layui-input-block layui-form" id="${field.fieldName}JoinTemplateBox" lay-filter="${field.fieldName}JoinTemplateBox"></div>
                    <script id="${field.fieldName}JoinTemplate" type="text/html">
                        <select name="${field.fieldName}">
                            <option value="">选择${field.fieldExplain}</option>
                            {{# for(var i = 0, item; item = d[i++];) { }}
                            <option value="{{item.${field.joinTable}Id}}">{{item.${field.joinTableFormShow}}}</option>
                            {{# } }}
                        </select>
                    </script>
                </div>
                        <#elseif field.fieldType == "string">
                <div class="layui-form-item">
                    <label class="layui-form-label">${field.fieldExplain}</label>
                    <div class="layui-input-block">
                        <input type="text" id="${field.fieldName}" name="${field.fieldName}" class="layui-input" value="${field.fieldDefault}" placeholder="请输入${field.fieldExplain}" <#if field.verifyType?? && field.verifyType != "none">lay-verify="<#if field.verifyType == "phone">phone<#elseif field.verifyType == "email">email<#elseif field.verifyType == "url">url<#elseif field.verifyType == "number">number<#elseif field.verifyType == "date">date<#elseif field.verifyType == "identity">identity<#elseif field.verifyType == "custom">${field.fieldName}CustomVerify<#elseif field.verifyType == "required">required</#if>"</#if>>
                    </div>
                </div>
                        </#if>
                    </#if>
                </#list>
                <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>
<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>
    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 wangEditor = window.wangEditor;
        var wangEditorObj = {};
        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'
                    }
                });
            }
        }

        <#list fieldList! as field>
            <#if field.formShow == 1>
                <#if field.fieldType == "date">
        // 初始化${field.fieldExplain}日期
        function init${field.firstUpperFieldName}Date() {
            laydate.render({
                elem: '#${field.fieldName}',
                type: 'date',
                value: new Date(),
                trigger: 'click'
            });
        }

                <#elseif field.fieldType == "datetime">
        // 初始化${field.fieldExplain}时间戳
        function init${field.firstUpperFieldName}DateTime() {
            laydate.render({
                elem: '#${field.fieldName}',
                type: 'datetime',
                value: new Date(),
                trigger: 'click'
            });
        }

                <#elseif field.fieldType == "richText">
        // 初始化${field.fieldExplain}富文本
        function init${field.firstUpperFieldName}RichText() {
            var editor = new wangEditor('#${field.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();
            wangEditorObj['${field.fieldName}'] = editor;
        }

                <#elseif field.fieldType == "select">
        // 初始化${field.fieldExplain}下拉选择
        function init${field.firstUpperFieldName}Select() {
            top.restAjax.get(top.restAjax.path('api/datadictionary/listdictionarybyparentid/${field.dictionaryId}', []), {}, null, function(code, data, args) {
                laytpl(document.getElementById('${field.fieldName}SelectTemplate').innerHTML).render(data, function(html) {
                    document.getElementById('${field.fieldName}SelectTemplateBox').innerHTML = html;
                });
                form.render('select', '${field.fieldName}SelectTemplateBox');
            }, function(code, data) {
                top.dialog.msg(data.msg);
            });
        }

                <#elseif field.fieldType == "checkbox">
        // 初始化${field.fieldExplain}复选
        function init${field.firstUpperFieldName}Checkbox() {
            top.restAjax.get(top.restAjax.path('api/datadictionary/listdictionarybyparentid/${field.dictionaryId}', []), {}, null, function(code, data, args) {
                laytpl(document.getElementById('${field.fieldName}CheckboxTemplate').innerHTML).render(data, function(html) {
                    document.getElementById('${field.fieldName}CheckboxTemplateBox').innerHTML = html;
                });
                form.render('checkbox', '${field.fieldName}CheckboxTemplateBox');
            }, function(code, data) {
                top.dialog.msg(data.msg);
            });
        }

                <#elseif field.fieldType == "radio">
        // 初始化${field.fieldExplain}单选
        function init${field.firstUpperFieldName}Radio() {
            top.restAjax.get(top.restAjax.path('api/datadictionary/listdictionarybyparentid/${field.dictionaryId}', []), {}, null, function(code, data, args) {
                laytpl(document.getElementById('${field.fieldName}RadioTemplate').innerHTML).render(data, function(html) {
                    document.getElementById('${field.fieldName}RadioTemplateBox').innerHTML = html;
                });
                form.render('radio', '${field.fieldName}RadioTemplateBox');
            }, function(code, data) {
                top.dialog.msg(data.msg);
            });
        }

                <#elseif field.fieldType == "file">
        // 初始化${field.fieldExplain}文件上传
        function init${field.firstUpperFieldName}UploadFile() {
            var files = $('#${field.fieldName}').val();
            initFileList('${field.fieldName}', files);

            form.on('button(${field.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(${field.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);
            });
        }

                <#elseif field.fieldType == "image">
        // 初始化${field.fieldExplain}图片上传
        function init${field.firstUpperFieldName}UploadFile() {
            var files = $('#${field.fieldName}').val();
            initFileList('${field.fieldName}', files, function(fileName) {
                var viewer = new Viewer(document.getElementById(fileName +'FileBox'), {navbar: false});
                viewerObj[fileName] = viewer;
            });

            form.on('button(${field.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(fileName) {
                                viewerObj[fileName].update();
                            });
                        }
                    }
                });
            });

            form.on('button(${field.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();
                });
            });
        }

                <#elseif field.fieldType == "video">
        // 初始化${field.fieldExplain}视频上传
        function init${field.firstUpperFieldName}UploadFile() {
            var files = $('#${field.fieldName}').val();
            initFileList('${field.fieldName}', files, initVideo);

            form.on('button(${field.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(${field.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);
            });
        }

                <#elseif field.fieldType == "audio">
        // 初始化${field.fieldExplain}音频上传
        function init${field.firstUpperFieldName}UploadFile() {
            var files = $('#${field.fieldName}').val();
            initFileList('${field.fieldName}', files);

            form.on('button(${field.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(${field.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);
            });
        }

                <#elseif field.fieldType == "selectUser">
        // 初始化${field.fieldExplain}选择人员
        function init${field.firstUpperFieldName}SelectUser() {
            $(document.body).on('click', '#${field.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('');
                        }
                    }
                });
            });
        }

                <#elseif field.fieldType == "selectDepartment">
        // 初始化${field.fieldExplain}选择部门
        function init${field.firstUpperFieldName}SelectDepartment() {
            $(document.body).on('click', '#${field.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('');
                            }
                        }
                    }
                });
            });
        }

                <#elseif field.fieldType == "currentUser">
        // 初始化${field.fieldExplain}当前用户
        function init${field.firstUpperFieldName}CurrentUser(userIdAndValue, userNameValue) {
            var currentUserObj = {};
            currentUserObj['${field.fieldName}'] = userIdAndValue;
            currentUserObj['${field.fieldName}CurrentUser'] = userNameValue;
            form.val('dataForm', currentUserObj);
        }

                <#elseif field.fieldType == "currentDepartment">
        // 初始化${field.fieldExplain}当前部门
        function init${field.firstUpperFieldName}CurrentDepartment(departmentIdAndNamesValue, departmentNamesValue) {
            var currentUserObj = {};
            currentUserObj['${field.fieldName}'] = departmentIdAndNamesValue;
            currentUserObj['${field.fieldName}CurrentDepartment'] = departmentNamesValue;
            form.val('dataForm', currentUserObj);
        }

                <#elseif field.fieldType == "currentRole">
        // 初始化${field.fieldExplain}当前角色
        function init${field.firstUpperFieldName}CurrentRole(roleIdAndNamesValue, roleNamesValue) {
            var currentUserObj = {};
            currentUserObj['${field.fieldName}'] = roleIdAndNamesValue;
            currentUserObj['${field.fieldName}CurrentRole'] = roleNamesValue;
            form.val('dataForm', currentUserObj);
        }

                <#elseif field.fieldType == "currentGroup">
        // 初始化${field.fieldExplain}当前组
        function init${field.firstUpperFieldName}CurrentGroup(groupIdAndNamesValue, groupNamesValue) {
            var currentUserObj = {};
            currentUserObj['${field.fieldName}'] = groupIdAndNamesValue;
            currentUserObj['${field.fieldName}CurrentGroup'] = groupNamesValue;
            form.val('dataForm', currentUserObj);
        }

                <#elseif field.fieldType == "currentPosition">
        // 初始化${field.fieldExplain}当前职位
        function init${field.firstUpperFieldName}CurrentPosition(positionIdAndNamesValue, positionNamesValue) {
            var currentUserObj = {};
            currentUserObj['${field.fieldName}'] = positionIdAndNamesValue;
            currentUserObj['${field.fieldName}CurrentPosition'] = positionNamesValue;
            form.val('dataForm', currentUserObj);
        }

                <#elseif field.fieldType == "leftJoin" || field.fieldType == "innerJoin" || field.fieldType == "rightJoin">
        // 初始化${field.fieldExplain}联表
        function init${field.firstUpperFieldName}JoinTable(){
            top.restAjax.get(top.restAjax.path('api/${field.lowerJoinTable}/list${field.lowerJoinTable}', []), {}, null, function(code, data, args) {
                laytpl(document.getElementById('${field.fieldName}JoinTemplate').innerHTML).render(data, function(html) {
                    document.getElementById('${field.fieldName}JoinTemplateBox').innerHTML = html;
                });
                form.render('select', '${field.fieldName}JoinTemplateBox');
            }, function(code, data) {
                top.dialog.msg(data.msg);
            });
        }

                </#if>
            </#if>
        </#list>

        // 初始化内容
        function initData() {
            top.restAjax.get(top.restAjax.path('api/${lowerTableName}/getcurrentuseridinfo', []), {}, null, function(code, data) {
            <#list fieldList! as field>
                <#if field.formShow == 1>
                    <#if field.fieldType == "date">
            init${field.firstUpperFieldName}Date();
                    <#elseif field.fieldType == "datetime">
            init${field.firstUpperFieldName}DateTime();
                    <#elseif field.fieldType == "richText">
            init${field.firstUpperFieldName}RichText();
                    <#elseif field.fieldType == "select">
            init${field.firstUpperFieldName}Select();
                    <#elseif field.fieldType == "checkbox">
            init${field.firstUpperFieldName}Checkbox();
                    <#elseif field.fieldType == "radio">
            init${field.firstUpperFieldName}Radio();
                    <#elseif field.fieldType == "file" || field.fieldType == "image" || field.fieldType == "video" || field.fieldType == "audio">
            init${field.firstUpperFieldName}UploadFile();
                    <#elseif field.fieldType == "selectUser">
            init${field.firstUpperFieldName}SelectUser();
                    <#elseif field.fieldType == "selectDepartment">
            init${field.firstUpperFieldName}SelectDepartment();
                    <#elseif field.fieldType == "currentUser">
            init${field.firstUpperFieldName}CurrentUser(data.userIdAndValue, data.userNameValue);
                    <#elseif field.fieldType == "currentDepartment">
            init${field.firstUpperFieldName}CurrentDepartment(data.departmentIdAndNamesValue, data.departmentNamesValue);
                    <#elseif field.fieldType == "currentRole">
            init${field.firstUpperFieldName}CurrentRole(data.roleIdAndNamesValue, data.roleNamesValue);
                    <#elseif field.fieldType == "currentGroup">
            init${field.firstUpperFieldName}CurrentGroup(data.groupIdAndNamesValue, data.groupNamesValue);
                    <#elseif field.fieldType == "currentPosition">
            init${field.firstUpperFieldName}CurrentPosition(data.positionIdAndNamesValue, data.positionNamesValue);
                    <#elseif field.fieldType == "leftJoin" || field.fieldType == "innerJoin" || field.fieldType == "rightJoin">
            init${field.firstUpperFieldName}JoinTable();
                    </#if>
                </#if>
            </#list>
            }, 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;
                <#list fieldList! as field>
                    <#if field.formShow == 1>
                        <#if field.fieldType == "checkbox">
                formData.field['${field.fieldName}'] = top.restAjax.checkBoxToString(formData.field, '${field.fieldName}');
                        <#elseif field.fieldType == "richText">
                formData.field['${field.fieldName}'] = wangEditorObj['${field.fieldName}'].txt.html();
                        </#if>
                    </#if>
                </#list>
                top.restAjax.post(top.restAjax.path('api/${lowerTableName}/save${lowerTableName}', []), 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();
        });

        // 校验
        form.verify({
            <#list fieldList! as field>
                <#if field.formShow == 1>
                    <#if field.fieldType == "string">
                        <#if field.verifyType??>
                            <#if field.verifyType == "custom">
            ${field.fieldName}CustomVerify: function(value, item){
                if(!new RegExp('${field.verifyRegular}').test(value)){
                    return '${field.fieldExplain}格式错误';
                }
            }
                            </#if>
                        </#if>
                    </#if>
                </#if>
            </#list>
        });
    });
</script>
</body>
</html>