<!doctype html>
<html 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">
    <style>
        .layui-form-select dl{
            z-index: 99999 !important;
        }
    </style>
</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">
                <div class="layui-form-item layui-form-text">
                    <div class="layui-input-block">
                        <input type="hidden" id="configColumnPhoto" name="configColumnPhoto">
                        <div class="layui-btn-container" id="configColumnPhotoFileBox" style="border: 1px solid #e6e6e6;"></div>
                        <script id="configColumnPhotoFileDownload" type="text/html">
                            {{# var fileName = 'configColumnPhoto'; }}
                            {{# 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/download/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="configColumnPhotoRemoveFile">
                                    <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="栏目图标" data-name="configColumnPhoto" lay-filter="configColumnPhotoUploadFile">
                                    <i class="fa fa-plus-square-o" style="font-size: 70px;"></i>
                                </a>
                            </div>
                            {{# } }}
                        </script>
                    </div>
                </div>
                <div class="layui-form-item layui-row ">
                    <div class="layui-col-lg6" >
                        <label class="layui-form-label">栏目编码<span style="color: red">*</span></label>
                        <div class="layui-input-block">
                            <input type="text" id="configColumnCode" name="configColumnCode" class="layui-input" value="" placeholder="请输入栏目编码"  maxlength="50">
                        </div>
                    </div>
                    <div class="layui-col-lg6" >
                        <label class="layui-form-label">栏目名称<span style="color: red">*</span></label>
                        <div class="layui-input-block">
                            <input type="text" id="configColumnName" name="configColumnName" class="layui-input" value="" placeholder="请输入栏目名称"  maxlength="100">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-row">
                    <div class="layui-col-lg6" >
                        <label class="layui-form-label">栏目样式<span style="color: red">*</span></label>
                        <div class="layui-input-block layui-form" id="configColumnTypeSelectTemplateBox" lay-filter="configColumnTypeSelectTemplateBox"></div>
                        <script id="configColumnTypeSelectTemplate" type="text/html">
                            <select id="configColumnType" name="configColumnType">
                                <option value="">请选择栏目样式</option>
                                {{# for(var i = 0, item; item = d[i++];) { }}
                                <option value="{{item.dataId}}">{{item.dataName}}</option>
                                {{# } }}
                            </select>
                        </script>
                    </div>
                    <div class="layui-col-lg6" >
                        <label class="layui-form-label">栏目说明<span style="color: red">*</span></label>
                        <div class="layui-input-block">
                            <input type="text" id="configColumnRemark" name="configColumnRemark" class="layui-input" value="" placeholder="请输入栏目说明"  maxlength="500">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-row ">
                    <div class="layui-col-lg6" >
                        <label class="layui-form-label">绑定栏目组<span style="color: red">*</span></label>
                        <div class="layui-input-block layui-form" id="configColumnGroupIdSelectTemplateBox" lay-filter="configColumnGroupIdSelectTemplateBox"></div>
                        <script id="configColumnGroupIdSelectTemplate" type="text/html">
                            <select id="configColumnGroupId" name="configColumnGroupId">
                                <option value="">请选择栏目组</option>
                                {{# for(var i = 0, item; item = d[i++];) { }}
                                <option value="{{item.configColumnGroupId}}">【{{item.configColumnGroupCode}}】{{item.configColumnGroupName}}</option>
                                {{# } }}
                            </select>
                        </script>
                    </div>
                    <div class="layui-col-lg6" >
                        <label class="layui-form-label">绑定表单<span style="color: red">*</span></label>
                        <div class="layui-input-block layui-form" id="configTableIdSelectTemplateBox" lay-filter="configTableIdSelectTemplateBox"></div>
                        <script id="configTableIdSelectTemplate" type="text/html">
                            <select id="configTableId" name="configTableId">
                                <option value="">请选择表单</option>
                                {{# for(var i = 0, item; item = d[i++];) { }}
                                <option value="{{item.configTableId}}">【{{item.configTableCode}}】{{item.configTableName}}</option>
                                {{# } }}
                            </select>
                        </script>
                    </div>
                </div>
                <div class="layui-form-item layui-row" pane >
                    <div class="layui-col-lg6" >
                        <label class="layui-form-label">列表跳转</label>
                        <div class="layui-input-block layui-form">
                            <input type="radio"  lay-verify="required" name="configColumnRowTargetMode" value="1" title="小程序页面">
                            <input type="radio" lay-verify="required" name="configColumnRowTargetMode" value="2"  title="其他小程序">
                            <input type="radio" lay-verify="required" name="configColumnRowTargetMode" value="3"  title="网址">
                        </div>
                    </div>
                    <div class="layui-col-lg6" >
                        <label class="layui-form-label">列表地址<span style="color: red">*</span></label>
                        <div class="layui-input-block layui-form" id="configColumnRowTargetUrlSelectTemplateBox" lay-filter="configColumnRowTargetUrlSelectTemplateBox"></div>
                        <script id="configColumnRowTargetUrlSelectTemplate" type="text/html">
                            <select id="configColumnRowTargetUrl" name="configColumnRowTargetUrl">
                                <option value="">请选择列表地址</option>
                                {{# for(var i = 0, item; item = d[i++];) { }}
                                <option value="{{item.dataName}}">{{item.dataName}}【{{item.dataSummary}}】</option>
                                {{# } }}
                            </select>
                        </script>
                        <!--<label class="layui-form-label">列表地址</label>
                        <div class="layui-input-block">
                            <input type="text" id="configColumnRowTargetUrl" name="configColumnTargetUrl" class="layui-input" value="" placeholder="请输入列表页页跳转地址"  maxlength="1000">
                        </div>-->
                    </div>
                </div>
                <div class="layui-form-item layui-row" pane >
                    <div class="layui-col-lg6" >
                        <label class="layui-form-label">详情跳转<span style="color: red">*</span></label>
                        <div class="layui-input-block layui-form">
                            <input type="radio"  lay-verify="required" name="configColumnTargetMode" value="1" title="小程序页面">
                            <input type="radio" lay-verify="required" name="configColumnTargetMode" value="2"  title="其他小程序">
                            <input type="radio" lay-verify="required" name="configColumnTargetMode" value="3"  title="网址">
                        </div>
                    </div>
                    <div class="layui-col-lg6" >
                        <label class="layui-form-label">详情地址<span style="color: red">*</span></label>
                        <div class="layui-input-block layui-form" id="configColumnTargetUrlSelectTemplateBox" lay-filter="configColumnTargetUrlSelectTemplateBox"></div>
                        <script id="configColumnTargetUrlSelectTemplate" type="text/html">
                            <select id="configColumnTargetUrl" name="configColumnTargetUrl">
                                <option value="">请选择详情地址</option>
                                {{# for(var i = 0, item; item = d[i++];) { }}
                                <option value="{{item.dataName}}">{{item.dataName}}【{{item.dataSummary}}】</option>
                                {{# } }}
                            </select>
                        </script>
                        <!--<label class="layui-form-label">详情地址<span style="color: red">*</span></label>
                        <div class="layui-input-block">
                            <input type="text" id="configColumnTargetUrl" name="configColumnTargetUrl" class="layui-input" value="" placeholder="请输入详情页跳转地址"  maxlength="1000">
                        </div>-->
                    </div>
                </div>
                <div class="layui-form-item" >
                    <div class="layui-col-lg6" >
                        <label class="layui-form-label">栏目排序<span style="color: red">*</span></label>
                        <div class="layui-input-block">
                            <input type="number" id="configColumnOrder" name="configColumnOrder" class="layui-input" value="" placeholder="请输入栏目排序" lay-verify="required">
                        </div>
                    </div>
                    <div class="layui-col-lg6" >
                        <label class="layui-form-label">列表显示<span style="color: red">*</span></label>
                        <div class="layui-input-block">
                            <input type="number" id="configColumnRowCount" name="configColumnRowCount" class="layui-input" value="" style="width:95%;float: left" placeholder="请输入列表显示最大数量" lay-verify="required"><b style="line-height: 36px;">条</b>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item" pane>
                    <div class="layui-col-lg6" >
                        <label class="layui-form-label">栏目状态<span style="color: red">*</span></label>
                        <div class="layui-input-block layui-form">
                            <input type="radio"  lay-verify="required" name="configColumnStatus" value="1" title="显示">
                            <input type="radio" lay-verify="required" name="configColumnStatus" value="0"  title="隐藏">
                        </div>
                    </div>
                    <div class="layui-col-lg6" >
                        <label class="layui-form-label">首页栏目<span style="color: red">*</span></label>
                        <div class="layui-input-block layui-form">
                            <input type="radio"  lay-verify="required" name="configColumnDefault" value="1" title="是">
                            <input type="radio" lay-verify="required" name="configColumnDefault" value="0"  title="否">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-row" pane >
                    <div class="layui-col-lg6" >
                        <label class="layui-form-label">转发开关<span style="color: red">*</span></label>
                        <div class="layui-input-block layui-form">
                            <input type="radio"  lay-verify="required" name="configColumnDispatch" value="1"  title="不开启">
                            <input type="radio"  lay-verify="required" name="configColumnDispatch" value="2"  title="列表">
                            <input type="radio" lay-verify="required" name="configColumnDispatch" value="3"  title="详情">
                            <input type="radio" lay-verify="required" name="configColumnDispatch" value="4"  title="列表+详情">
                        </div>
                    </div>
                    <div class="layui-col-lg6" >
                        <label class="layui-form-label">评论开关<span style="color: red">*</span></label>
                        <div class="layui-input-block layui-form">
                            <input type="radio"  lay-verify="required" name="configColumnComment" value="1"  title="不开启">
                            <input type="radio"  lay-verify="required" name="configColumnComment" value="2"  title="列表">
                            <input type="radio" lay-verify="required" name="configColumnComment" value="3"  title="详情">
                            <input type="radio" lay-verify="required" name="configColumnComment" value="4"  title="列表+详情">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-row" pane >
                    <div class="layui-col-lg6" >
                        <label class="layui-form-label">点赞开关<span style="color: red">*</span></label>
                        <div class="layui-input-block layui-form">
                            <input type="radio"  lay-verify="required" name="configColumnLike" value="1"  title="不开启">
                            <input type="radio"  lay-verify="required" name="configColumnLike" value="2"  title="列表">
                            <input type="radio" lay-verify="required" name="configColumnLike" value="3"  title="详情">
                            <input type="radio" lay-verify="required" name="configColumnLike" value="4"  title="列表+详情">
                        </div>
                    </div>
                    <div class="layui-col-lg6" >
                        <label class="layui-form-label">收藏开关<span style="color: red">*</span></label>
                        <div class="layui-input-block layui-form">
                            <input type="radio"  lay-verify="required" name="configColumnCollect" value="1"  title="不开启">
                            <input type="radio"  lay-verify="required" name="configColumnCollect" value="2"  title="列表">
                            <input type="radio" lay-verify="required" name="configColumnCollect" value="3"  title="详情">
                            <input type="radio" lay-verify="required" name="configColumnCollect" value="4"  title="列表+详情">
                        </div>
                    </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>
<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 initConfigColumnRowTargetUrl(configColumnRowTargetUrl) {
            top.restAjax.get(top.restAjax.path('api/data/listbyparentid/f73da2db-7256-4a21-8eb2-7bf1b5e9e243', []), {}, null, function (code, data, args) {
                laytpl(document.getElementById('configColumnRowTargetUrlSelectTemplate').innerHTML).render(data, function (html) {
                    document.getElementById('configColumnRowTargetUrlSelectTemplateBox').innerHTML = html;
                });
                form.render('select', 'configColumnRowTargetUrlSelectTemplateBox');
            }, function (code, data) {
                top.dialog.msg(data.msg);
            });
        }

        // 初始化详情跳转
        function initConfigColumnTargetUrl(configColumnTargetUrl) {
            top.restAjax.get(top.restAjax.path('api/data/listbyparentid/de0c31ed-5e33-4d26-8a16-9f5a93e6eb96', []), {}, null, function (code, data, args) {
                laytpl(document.getElementById('configColumnTargetUrlSelectTemplate').innerHTML).render(data, function (html) {
                    document.getElementById('configColumnTargetUrlSelectTemplateBox').innerHTML = html;
                });
                form.render('select', 'configColumnTargetUrlSelectTemplateBox');
            }, function (code, data) {
                top.dialog.msg(data.msg);
            });
        }

        // 初始化栏目图片上传
        function initConfigColumnPhotoUploadFile() {
            var files = $('#configColumnPhoto').val();
            initFileList('configColumnPhoto', files, function(fileName) {
                var viewer = new Viewer(document.getElementById(fileName +'FileBox'), {navbar: false});
                viewerObj[fileName] = viewer;
            });

            form.on('button(configColumnPhotoUploadFile)', 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(configColumnPhotoRemoveFile)', 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();
                });
            });
        }

        // 初始化表单
        function initConfigTableId() {
            top.restAjax.get(top.restAjax.path('api/configtable/list?configTableActivation=1', []), {}, null, function(code, data, args) {
                laytpl(document.getElementById('configTableIdSelectTemplate').innerHTML).render(data, function(html) {
                    document.getElementById('configTableIdSelectTemplateBox').innerHTML = html;
                });
                form.render('select', 'configTableIdSelectTemplateBox');
            }, function(code, data) {
                top.dialog.msg(data.msg);
            });
        }

        // 初始化栏目组
        function initConfigColumnGroupId() {
            top.restAjax.get(top.restAjax.path('api/configcolumngroup/list?configColumnGroupStatus=1', []), {}, null, function(code, data, args) {
                laytpl(document.getElementById('configColumnGroupIdSelectTemplate').innerHTML).render(data, function(html) {
                    document.getElementById('configColumnGroupIdSelectTemplateBox').innerHTML = html;
                });
                form.render('select', 'configColumnGroupIdSelectTemplateBox');
            }, function(code, data) {
                top.dialog.msg(data.msg);
            });
        }

        // 初始化样式
        function initConfigColumnType(configColumnType) {
            top.restAjax.get(top.restAjax.path('api/data/listbyparentid/0d92c960-0fad-4511-820b-c3c021fdbd00', []), {}, null, function(code, data, args) {
                laytpl(document.getElementById('configColumnTypeSelectTemplate').innerHTML).render(data, function(html) {
                    document.getElementById('configColumnTypeSelectTemplateBox').innerHTML = html;
                });
                form.render('select', 'configColumnTypeSelectTemplateBox');
            }, function(code, data) {
                top.dialog.msg(data.msg);
            });
        }

        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/list', []), {
                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/download/true/'+ item.fileId,
                        type: 'video/mp4'
                    }
                });
            }
        }

        // 初始化内容
        function initData() {
            initConfigColumnType();
            initConfigColumnGroupId();
            initConfigTableId();
            initConfigColumnPhotoUploadFile();
            initConfigColumnRowTargetUrl();
            initConfigColumnTargetUrl();
        }
        initData();

        // 提交表单
        form.on('submit(submitForm)', function(formData) {
            top.dialog.confirm(top.dataMessage.commit, function(index) {
                top.dialog.close(index);
                var loadLayerIndex;
                top.restAjax.post(top.restAjax.path('api/configcolumn/save', []), 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({
        });
    });
</script>
</body>
</html>