<html>
<head>
    <title>网站设置</title>
    <% include("base/meta.html"){} %>
    <% include("base/ckeditor.html"){} %>
    <script src="/js/bootstrap3-wysihtml5.all.min.js"></script>
</head>
<body style="background-color: #fff">


<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                        <legend>网站设置</legend>
                    </fieldset>
                </div>

                <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                    <ul class="layui-tab-title">
                        <li class="layui-this">网站设置</li>
                        <li>开关设置</li>
                        <li>博主信息字段显示</li>
                        <li>主题设置</li>
                        <li>腾讯设置</li>
                        <li>微信设置</li>
                        <li>微博设置</li>
                    </ul>
                    <div class="layui-tab-content" style="height: 100px;">


                        <div class="layui-tab-item layui-show">

                            <div class="layui-card-body ">
                                <form class="layui-form layui-form-pane" action="" id="siteForm">

                                    <div class="layui-form-item">
                                        <label class="layui-form-label">网站名称</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="siteName" id="siteName" autocomplete="off"
                                                   value="${site.siteName!}"
                                                   placeholder="请输入网站名称" class="layui-input">
                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <label class="layui-form-label">网站描述</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="siteDesc" id="siteDesc" autocomplete="off"
                                                   value="${site.siteDesc!}"
                                                   placeholder="请输入网站描述" class="layui-input">
                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <label class="layui-form-label">版权声明</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="siteCopyRight" id="siteCopyRight" autocomplete="off"
                                                   value="${site.siteCopyRight!}"
                                                   placeholder="请输入版权声明" class="layui-input">
                                        </div>
                                    </div>


                                    <div class="layui-form-item">
                                        <label for="regRoleId" class="layui-form-label"
                                               style="width:140px;">注册用户角色</label>
                                        <div class="layui-input-inline">


                                            <%if(isNotEmpty(roles)){%>
                                            <select name="regRoleId">
                                                <option value="">-请选择-</option>
                                                <% for(data in roles){ %>

                                                <%if(data.id==site.regRoleId){%>
                                                <option value="${data.id}" selected>${data.cname}</option>
                                                <%}else{%>
                                                <option value="${data.id}">${data.cname}</option>
                                                <%}%>

                                                <%} %>
                                            </select>
                                            <%}%>

                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <button type="button" class="layui-btn layui-btn-normal" lay-submit
                                                lay-filter="saveWebSet">保存
                                        </button>
                                    </div>

                                </form>
                            </div>


                        </div>

                        <div class="layui-tab-item">

                            <div class="layui-card-body ">
                                <form class="layui-form layui-form-pane" action="" id="switchForm">


                                    <div class="layui-form-item">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">开启注册</label>
                                            <div class="layui-input-block">
                                                <input type="checkbox" name="open" lay-skin="switch"
                                                       lay-filter="openReg" lay-text="ON|OFF"
                                                <%if(site.openReg==true){%> checked <% }%> >
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">允许评论</label>
                                            <div class="layui-input-block">
                                                <input type="checkbox" name="open" lay-skin="switch"
                                                       lay-filter="openCmt" lay-text="ON|OFF"
                                                <%if(site.openCmt==true){%> checked <% }%> >
                                            </div>
                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <label class="layui-form-label" about="显示博主信息"
                                               style="width: 140px;">显示博主信息</label>
                                        <div class="layui-input-block">
                                            <input type="checkbox" name="open" lay-skin="switch"
                                                   lay-filter="showAdminInfo" lay-text="ON|OFF"
                                            <%if(site.showAdminInfo==true){%> checked <%}%> }>
                                        </div>
                                    </div>


                                    <div class="layui-form-item">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">微信登录</label>
                                            <div class="layui-input-block">
                                                <input type="checkbox" disabled name="open" lay-skin="switch"
                                                       lay-filter="wechatLoginSwitch" lay-text="ON|OFF">
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">微博登录</label>
                                            <div class="layui-input-block">
                                                <input type="checkbox" disabled name="open" lay-skin="switch"
                                                       lay-filter="weboLoginSwitch" lay-text="ON|OFF">
                                            </div>
                                        </div>

                                        <div class="layui-inline">
                                            <label class="layui-form-label">QQ登录</label>
                                            <div class="layui-input-block">
                                                <input type="checkbox" name="open" lay-skin="switch"
                                                       lay-filter="qqLoginSwitch" lay-text="ON|OFF"
                                                <%if(site.openQQLogin==true){%> checked <%}%> }>
                                            </div>
                                        </div>

                                    </div>

                                    <div class="layui-form-item">
                                        <label class="layui-form-label" style="width: 140px;">启用动态菜单</label>
                                        <div class="layui-input-block">
                                            <input type="checkbox" name="open" lay-skin="switch"
                                                   lay-filter="dynamicMenu" lay-text="ON|OFF"
                                            <%if(site.dynamicMenu==true){%> checked <% }%> >
                                        </div>
                                    </div>

                                </form>
                            </div>


                        </div>

                        <div class="layui-tab-item">

                            <div class="layui-card-body ">
                                <form class="layui-form layui-form-pane" action="" id="websiteFieldForm">

                                    <div class="layui-form-item">
                                        <label class="layui-form-label">字段显示</label>
                                        <div class="layui-input-block">
                                            <input type="checkbox" name="mobile" title="手机号" lay-filter="like"
                                            <%if(array.contain(site.showAdminFields,"mobile")){%> checked<%}%> >
                                            <input type="checkbox" name="email" title="邮箱" lay-filter="like"
                                            <%if(array.contain(site.showAdminFields,"email")){%> checked<%}%>>
                                            <input type="checkbox" name="school" title="毕业学校" lay-filter="like"
                                            <%if(array.contain(site.showAdminFields,"school")){%> checked<%}%>>
                                            <input type="checkbox" name="profession" title="专业" lay-filter="like"
                                            <%if(array.contain(site.showAdminFields,"profession")){%> checked<%}%>>
                                            <input type="checkbox" name="beginJobTime" title="开始工作时间" lay-filter="like"
                                            <%if(array.contain(site.showAdminFields,"beginJobTime")){%> checked<%}%>>
                                            <input type="checkbox" name="endJobTime" title="结束工作时间" lay-filter="like"
                                            <%if(array.contain(site.showAdminFields,"endJobTime")){%> checked<%}%>>
                                            <input type="checkbox" name="wechat" title="微信" lay-filter="like"
                                            <%if(array.contain(site.showAdminFields,"wechat")){%> checked<%}%>>
                                            <input type="checkbox" name="weibo" title="微博" lay-filter="like"
                                            <%if(array.contain(site.showAdminFields,"weibo")){%> checked<%}%>>
                                            <input type="checkbox" name="qq" title="QQ" lay-filter="like"
                                            <%if(array.contain(site.showAdminFields,"qq")){%> checked<%}%>>
                                            <input type="checkbox" name="twitter" title="Twitter" lay-filter="like"
                                            <%if(array.contain(site.showAdminFields,"twitter")){%> checked<%}%>>
                                            <input type="checkbox" name="facebook" title="Facebook" lay-filter="like"
                                            <%if(array.contain(site.showAdminFields,"facebook")){%> checked<%}%>>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>

                        <div class="layui-tab-item">
                            <div class="layui-card-body ">
                                <form class="layui-form layui-form-pane" action="" id="themeForm">


                                    <div class="layui-form-item">
                                        <label for="viewTheme" class="layui-form-label"
                                               style="width:140px;">前台主题</label>
                                        <div class="layui-input-inline">


                                            <%if(isNotEmpty(viewTheme)){%>
                                            <select name="viewTheme">
                                                <option value="">-请选择-</option>
                                                <% for(data in viewTheme){ %>

                                                <%if(data.ename==site.viewThemeEname){%>
                                                <option value="${data.ename}" selected>${data.cname}</option>
                                                <%}else{%>
                                                <option value="${data.ename}">${data.cname}</option>
                                                <%}%>

                                                <%} %>
                                            </select>
                                            <%}%>

                                        </div>
                                    </div>


                                    <div class="layui-form-item">
                                        <label for="adminTheme" class="layui-form-label" style="width:140px;">后台主题</label>
                                        <div class="layui-input-inline">


                                            <%if(isNotEmpty(adminTheme)){%>
                                            <select name="adminTheme">
                                                <option value="">-请选择-</option>
                                                <% for(data in adminTheme){ %>

                                                <%if(data.ename==site.adminThemeEname){%>
                                                <option value="${data.ename}" selected>${data.cname}</option>
                                                <%}else{%>
                                                <option value="${data.ename}">${data.cname}</option>
                                                <%}%>

                                                <%} %>
                                            </select>
                                            <%}%>

                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <button type="button" class="layui-btn layui-btn-normal" lay-submit lay-filter="saveTheme">保存
                                        </button>
                                    </div>

                                </form>
                            </div>
                        </div>


                        <div class="layui-tab-item">
                            <div class="layui-card-body ">
                                <form class="layui-form layui-form-pane" action="" id="tencentForm">

                                    <div class="layui-form-item">
                                        <label class="layui-form-label">appId</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="appId" id="appId" autocomplete="off"
                                                   value="${site.appId!}"
                                                   placeholder="请输入APPID" class="layui-input">
                                        </div>
                                    </div>


                                    <div class="layui-form-item">
                                        <label class="layui-form-label">appKey</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="appKey" id="appKey" autocomplete="off"
                                                   value="${site.appKey!}"
                                                   placeholder="请输入appKey" class="layui-input">
                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <label class="layui-form-label">callBackUrl</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="qqCallBackUrl" id="qqCallBackUrl" autocomplete="off"
                                                   value="${site.qqCallBackUrl!}"
                                                   placeholder="请输入与QQ互联预留的地址" class="layui-input">
                                        </div>
                                    </div>


                                    <div class="layui-form-item">
                                        <button type="button" class="layui-btn layui-btn-normal" lay-submit
                                                lay-filter="saveTencent">保存
                                        </button>
                                    </div>

                                </form>
                            </div>
                        </div>

                        <div class="layui-tab-item">
                            待开发
                        </div>

                        <div class="layui-tab-item">
                            待开发
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script>
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;


        //注册监听
        form.on('switch(openReg)', function (data) {
            switchConfig("openReg");
            return false;
        });

        form.on('switch(qqLoginSwitch)', function (data) {
            switchConfig("openQQLogin");
            return false;
        });

        //评论监听
        form.on('switch(openCmt)', function (data) {
            switchConfig("openCmt");
            return false;
        });

        form.on('switch(dynamicMenu)', function (data) {
            layer.confirm('关闭后普通成员将具有管理员布局!', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                switchConfig("dynamicMenu");
            }, function () {

            });
            return false;
        });

        //显示博主信息监听
        form.on('switch(showAdminInfo)', function (data) {
            switchConfig("showAdminInfo");
            return false;
        });

        function switchConfig(key) {
            $.ajax({
                cache: false,
                type: "POST",
                contentType: 'application/json',
                url: "/site/switch/" + key,
                async: false,
                success: function (data) {
                    if (data.code === 0) {
                        layer.msg(data.message);
                    } else {
                        layer.msg(data.message, {
                            time: 2000
                        });
                    }
                },
                error: function (data) {
                    layer.msg(data.message);
                }
            });
        }

        form.on('submit(saveTheme)', function (data) {

            if (!data.field.viewTheme) {
                layer.msg("前端主题不能为空", {
                    time: 2000
                });
                return;
            }

            if (!data.field.adminTheme) {
                layer.msg("后端主题不能为空", {
                    time: 2000
                });
                return;
            }

            $.ajax({
                cache: false,
                type: "POST",
                contentType: 'application/json',
                url: "/site/theme",
                data: JSON.stringify(data.field),
                async: false,
                success: function (data) {
                    if (data.code === 0) {
                        layer.msg(data.message);
                    } else {
                        layer.msg(data.message, {
                            time: 2000
                        });
                    }
                    parent.location.reload();
                },
                error: function (data) {
                    layer.msg(data.message);
                }
            });
            return false;
        });


        //网站设置保存
        form.on('submit(saveWebSet)', function (data) {

            if (!data.field.siteName) {
                layer.msg("网站名称不能为空", {
                    time: 2000
                });
                return;
            }

            if (!data.field.regRoleId) {
                layer.msg("注册角色不能为空", {
                    time: 2000
                });
                return;
            }

            $.ajax({
                cache: false,
                type: "POST",
                contentType: 'application/json',
                url: "/site/website",
                data: JSON.stringify(data.field),
                async: false,
                success: function (data) {
                    if (data.code === 0) {
                        layer.msg(data.message);
                    } else {
                        layer.msg(data.message, {
                            time: 2000
                        });
                    }
                },
                error: function (data) {
                    layer.msg(data.message);
                }
            });
            return false;
        });


        //腾讯设置
        form.on('submit(saveTencent)', function (data) {

            if (!data.field.appId) {
                layer.msg("appId不能为空", {
                    time: 2000
                });
                return;
            }

            if (!data.field.appKey) {
                layer.msg("appKey不能为空", {
                    time: 2000
                });
                return;
            }

            $.ajax({
                cache: false,
                type: "POST",
                contentType: 'application/json',
                url: "/site/tencent",
                data: JSON.stringify(data.field),
                async: false,
                success: function (data) {
                    if (data.code === 0) {
                        layer.msg(data.message);
                    } else {
                        layer.msg(data.message, {
                            time: 2000
                        });
                    }
                },
                error: function (data) {
                    layer.msg("发生未知异常,请检查权限或请求地址");
                }
            });
            return false;
        });

        // 显示字段监听
        form.on('checkbox(like)', function (data) {
            var key = data.elem.name
            $.ajax({
                cache: false,
                type: "POST",
                contentType: 'application/json',
                url: "/site/field/show/" + key,
                async: false,
                success: function (data) {
                    if (data.code === 0) {
                        layer.msg(data.message);
                    } else {
                        layer.msg(data.message, {
                            time: 2000
                        });
                    }
                },
                error: function (data) {
                    layer.msg(data.message);
                }
            });

            return false;
        });
    });
</script>


</body>
</html>