layui.use(['form', 'upload', 'jquery'],
function() {
    var form = layui.form,
    upload = layui.upload,
    jq = layui.jquery;
    //上传图片
    upload.render({
        elem: '.upimg',
        url: "/index.php/admin/up/up.html",
        accept: 'file',
        //size: 100,
        exts: 'jpg|png|gif|bmp|jpeg',
        done: function(res) {
            if (res.code == '1') {
                var up = jq('.upimg').attr('up');
                jq('input[id=' + up + ']').val(res.path);
                return layer.msg(res.msg);
            } else {
                return layer.msg(res.msg);
            }
        }
    });
    //附件
    upload.render({
        elem: '.up',
        url: "/index.php/admin/up/up.html",
        accept: 'file',
        done: function(res) {
            if (res.code == '1') {
                var up = jq('.up').attr('up');
                jq('input[id=' + up + ']').val(res.path);
                return layer.msg(res.msg);
            } else {
                return layer.msg(res.msg);
            }
        }
    });

})
//通用表单提交跳转
layui.use(['jquery', 'form'],
function() {
    var form = layui.form,
    jq = layui.jquery;
    form.on('submit(cms)',
    function(data) {
        loading = layer.load(2, {
            shade: [0.2, '#000']
        });
        var urls = jq('.form').attr('url');
        var t_url = jq('.form').attr('t_url');
        var param = data.field;
        jq.post(urls, param,
        function(data) {
            if (data.code == 1) {
                layer.close(loading);
                layer.msg(data.msg, {
                    icon: 1,
                    time: 1000
                },
                function() {
                    location.href = t_url;
                });
            } else {
                layer.close(loading);
                layer.msg(data.msg, {
                    icon: 2,
                    anim: 6,
                    time: 1000
                });
            }
        });
        return false;
    });
    //通用表单提交跳转1
    form.on('submit(cms1)',
    function(data) {
        loading = layer.load(2, {
            shade: [0.2, '#000']
        });
        var urls = jq('.form1').attr('url');
        var t_url = jq('.form1').attr('t_url');
        var param = data.field;
        jq.post(urls, param,
        function(data) {
            if (data.code == 1) {
                layer.close(loading);
                layer.msg(data.msg, {
                    icon: 1,
                    time: 1000
                },
                function() {
                    location.href = t_url;
                });
            } else {
                layer.close(loading);
                layer.msg(data.msg, {
                    icon: 2,
                    anim: 6,
                    time: 1000
                });
            }
        });
        return false;
    });
    //通用表单提交跳转2
    form.on('submit(cms2)',
    function(data) {
        loading = layer.load(2, {
            shade: [0.2, '#000']
        });
        var urls = jq('.form2').attr('url');
        var t_url = jq('.form2').attr('t_url');
        var param = data.field;
        jq.post(urls, param,
        function(data) {
            if (data.code == 1) {
                layer.close(loading);
                layer.msg(data.msg, {
                    icon: 1,
                    time: 1000
                },
                function() {
                    location.href = t_url;
                });
            } else {
                layer.close(loading);
                layer.msg(data.msg, {
                    icon: 2,
                    anim: 6,
                    time: 1000
                });
            }
        });
        return false;
    });
    //无弹出触发链接弹出收藏
    jq('.del').click(function() {
        var url = jq(this).attr('url');
        loading = layer.load(2, {
            shade: [0.2, '#000']
        });
        jq.post(url,
        function(data) {
            if (data.code == 1) {
                layer.close(loading);
                layer.msg(data.msg, {
                    icon: 1,
                    time: 1000
                },
                function() {
                    location.reload();
                });
            } else {
                layer.close(loading);
                layer.msg(data.msg, {
                    icon: 2,
                    anim: 6,
                    time: 1000
                });
            }
        });
    });

    //弹出触发链接弹出
    jq('.del_t').click(function() {
        var name = jq(this).attr('name');
        var url = jq(this).attr('url');
        layer.confirm(name,
        function(index) {
            loading = layer.load(2, {
                shade: [0.2, '#000']
            });
            jq.post(url,
            function(data) {
                if (data.code == 1) {
                    layer.close(loading);
                    layer.msg(data.msg, {
                        icon: 1,
                        time: 1000
                    },
                    function() {
                        location.reload();
                    });
                } else {
                    layer.close(loading);
                    layer.msg(data.msg, {
                        icon: 2,
                        anim: 6,
                        time: 1000
                    });
                }
            });
        });
    });
})

//用户充值
$(".cz_user").click(function() {
    layer.prompt({
        title: '充值-多少元',
        formType: 3
    },
    function(text, index) {
        $.ajax({
            url: "/index.php/index/alipay/paysubmit?jiage=" + text,
            type: "GET",
            dataType: "json",
            success: function(data) {
                loading = layer.load(3);
                if (data.code == 1) {
                    layer.close(loading);
                    layer.msg(data.msg, {
                        icon: 1,
                        time: 1000
                    },
                    function() {
                        $('body').append(data.url);
                    });
                } else {
                    layer.close(loading);
                    layer.msg(data.msg, {
                        icon: 2,
                        anim: 6,
                        time: 1000
                    });
                }
            }
        });
    });
});
//用户提现
$(".tixian_user").click(function() {
    layer.prompt({
        title: '提现',
        formType: 3
    },
    function(text, index) {
        $.ajax({
            url: "/index.php/index/api/tixian_user?jiage=" + text,
            type: "GET",
            dataType: "json",
            success: function(data) {
                loading = layer.load(3);
                if (data.code == 1) {
                    layer.close(loading);
                    layer.msg(data.msg, {
                        icon: 1,
                        time: 1000
                    },
                    function() {
                        location.reload();
                    });
                } else {
                    layer.close(loading);
                    layer.msg(data.msg, {
                        icon: 2,
                        anim: 6,
                        time: 1000
                    });
                }
            }
        });
    });
});
// 文章回复
$(".huifu").click(function() {
    var data = $(this).attr('data');
    var name = $(this).attr('name');
    layer.prompt({
        title: '回复' + name,
        formType: 2
    },
    function(content, index) {
        $.ajax({
            url: data + "?content=" + content,
            type: "GET",
            dataType: "json",
            success: function(data) {
                loading = layer.load(3);
                if (data.code == 1) {
                    layer.close(loading);
                    layer.msg(data.msg, {
                        icon: 1,
                        time: 1000
                    },
                    function() {
                        location.reload();
                    });
                } else {
                    layer.close(loading);
                    layer.msg(data.msg, {
                        icon: 2,
                        anim: 6,
                        time: 1000
                    });
                }
            }
        });
    });
});
//发送验证邮箱或者手机
layui.use('form',
function() {
    var form = layui.form,
    jq = layui.jquery;
    jq('#phoneormail').click(function() {
        var obj = $(this);
        var options = {
            seconds: 60,
            type: 'REG'
        };
        var name = $("#name").val();　
        var t_url = $(this).attr('t_url');
        if (name == "") {　　　
            layer.msg('邮箱或者手机号码必填');　　　　
            return false;　　
        } 
        loading = layer.load(0, {
            shade: [0.2, '#000']
        });
        jq.getJSON(t_url+'?name=' + name,
        function(data) {
            if (data.code == 1) {
                layer.close(loading);
                layer.msg(data.msg, {
                    icon: 1,
                    time: 1000
                },
                function() {
                    countDown(60, obj);
                });
            } else {
                layer.close(loading);
                layer.msg(data.msg, {
                    icon: 2,
                    anim: 6,
                    time: 1000
                });
            }
        });
    });
});
function countDown(seconds, obj) {
    if (seconds > 1) {
        seconds--;
        $(obj).attr('disabled', true).html(seconds + "秒"); //禁用按钮
        setTimeout(function() {
            countDown(seconds, obj);
        },
        1000);
    } else {
        $(obj).attr('disabled', false).html("获取验证码"); //启用按钮
    }
}
layui.use(['form', 'upload'],
function() {
    var form = layui.form,
    upload = layui.upload,
    jq = layui.jquery;
    //收藏
    jq('.shoucang').click(function() {
        var urls = jq('.shoucang').attr('url');
        loading = layer.load(2, {
            shade: [0.2, '#000']
        });
        jq.getJSON(urls,
        function(data) {
            if (data.code == 1) {
                layer.close(loading);
                layer.msg(data.msg, {
                    icon: 1,
                    time: 1000
                },
                function() {
                    $(".shoucang").html("收藏成功");
                });
            } else if (data.code == 0) {
                layer.close(loading);
                layer.msg(data.msg, {
                    icon: 1,
                    time: 1000
                },
                function() {
                    $(".shoucang").html("收藏");
                });
            } else {
                layer.close(loading);
                layer.msg(data.msg, {
                    icon: 2,
                    anim: 6,
                    time: 1000
                });
            }
        });
    });
    //点赞
    jq('.dianzan').click(function() {
        var urls = jq('.dianzan').attr('url');
        var zan = jq('.dianzan').attr('zan');
        loading = layer.load(2, {
            shade: [0.2, '#000']
        });
        jq.getJSON(urls,
        function(data) {
            if (data.code == 1) {
                layer.close(loading);
                layer.msg(data.msg, {
                    icon: 1,
                    time: 1000
                },
                function() {
                    $(".dianzans").html(zan);
                });
            } else {
                layer.close(loading);
                layer.msg(data.msg, {
                    icon: 2,
                    anim: 6,
                    time: 1000
                });
            }
        });
    });
})
// 编辑器
function bianjiqi() {
    var editor = new wangEditor('textarea');
    	editor.config.uploadImgUrl = 'index.php/admin/up/pic.html';
    	editor.config.uploadImgFileName = 'FileName';
        editor.config.jsFilter = false;
        editor.config.pasteFilter = false;
        editor.config.menus =  [
            'bold',
            'eraser',
            'forecolor',
            'quote',
            'fontsize',
            '|',
            'alignleft',
            'aligncenter',
            'alignright',
             'link',
             'unlink',
            'img',
            'insertcode',
        ];
    editor.create();
}