<div id="to-top" class="to-top" title="返回顶部">
    <img src="https://oss.zc10000.com/static/images/totop.png" alt="">
</div>
</body>
<script>
    //加载模块
    layui.use(function(){ //亦可加载特定模块:layui.use(['layer', 'laydate', function(){
        //得到各种内置组件
        var layer = layui.layer //弹层
            ,laypage = layui.laypage //分页
            ,laydate = layui.laydate //日期
            ,table = layui.table //表格
            ,carousel = layui.carousel //轮播
            ,upload = layui.upload //上传
            ,element = layui.element //元素操作
            ,slider = layui.slider //滑块
            ,dropdown = layui.dropdown //下拉菜单
            ,$ = layui.$;

        carousel.render({
            elem: '#banner'
            ,arrow: 'always'
        });

        //回到顶部
        $(document).on('scroll', function() {
            var $pageScrollTop = $(this).scrollTop()
            if ($pageScrollTop > 200) {
                $('#to-top').show()
            } else {
                $('#to-top').hide()
            }
        })

        $('#to-top').on('click', function() {
            $('html, body').stop().animate({
                scrollTop: 0
            })
        });

        //自定义按钮打开客服
        //使用模拟点击
        $(".open_shangqiao").click(function(event) {
            if ($('#aff-im-root .embed-icon-default').length > 0) {
                $('#aff-im-root .embed-icon-default').click();
            }
        });

        //提示暂未开放
        $('.no_open').click(function(event) {
            layer.msg("该功能暂未开放");
        });

        //产品详情页 锚文本 导航
        $(document).ready(function() {
            $("#div1Link1").click(function() {
                $("html, body").animate({
                    scrollTop: $("#divcon1").offset().top }, {duration: 500,easing: "swing"});
                return false;
            });
            $("#div1Link2").click(function() {
                $("html, body").animate({
                    scrollTop: $("#divcon2").offset().top }, {duration: 500,easing: "swing"});
                return false;
            });
            $("#div1Link3").click(function() {
                $("html, body").animate({
                    scrollTop: $("#divcon3").offset().top }, {duration: 500,easing: "swing"});
                return false;
            });
            $("#div1Link4").click(function() {
                $("html, body").animate({
                    scrollTop: $("#divcon4").offset().top }, {duration: 500,easing: "swing"});
                return false;
            });
            $("#div1Link5").click(function() {
                $("html, body").animate({
                    scrollTop: $("#divcon5").offset().top }, {duration: 500,easing: "swing"});
                return false;
            });
        });

        //省站和城市站 tab切换
        $('.list-s-11-content .top .tab-a').on('click',function (){
            var index = $(this).index();
            console.log(index);
            if(index === 2){
                var ins = 2;
            }
            if(index === 3){
                var ins = 1;
            }
            if(index === 4){
               var ins = 0;
            }
            $('.list-s-11-content .center .box_1').hide();
            $('.list-s-11-content .center .box_1:eq('+ins+')').show();

            $('.list-s-11-content .bottom .box-bot-1').hide();
            $('.list-s-11-content .bottom .box-bot-1:eq('+ins+')').show();


            $('.list-s-11-content .top a').removeClass('tab-a-active');
            $(this).addClass('tab-a-active');
        });
        
        //下载文件函数
        function downFile(title,url){
            const filePath = url;
            const fileExt = filePath.substr(filePath.lastIndexOf('.') + 1);
            var title = title + '.' + fileExt;
            
            // 【步骤1】创建一个文件,该文件支持写入操作
            const fileStream = streamSaver.createWriteStream(title);
            // 这里传入的是下载后的文件名,这个名字可以自定义
            
            // 【步骤2】使用 fetch 方法访问文件的url,将内容一点点的放到 StreamSaver 创建的文件里
            fetch(url).then(res => {
                        const readableStream = res.body
                        if (window.WritableStream && readableStream.pipeTo) {
                            return readableStream.pipeTo(fileStream)
                                    .then(() => console.log('完成写入'))
                        }
                        
                        // 【步骤3】监听文件内容是否读取完整,读取完就执行“保存并关闭文件”的操作。
                        window.writer = fileStream.getWriter()
                        const reader = res.body.getReader()
                        const pump = () => reader.read()
                                .then(res => res.done
                                        ? writer.close()
                                        : writer.write(res.value).then(pump)
                                )
                        pump()
                    });
        }
        
        //点击下载文档
        $('#down_btn').click(function (){
            layer.msg('正在处理');
            var aid = $(this).attr('aid');
            var title = $(this).attr('title');
            $.ajax({
                type: "POST",
                url: '/api/Ajax/get_user_download',
                data: {del_id:0,_ajax:1,aid:aid},
                dataType: 'json',
                success: function (data) {
                    layer.closeAll();
                    if(parseInt(data.code) == 1){
                        layer.msg(data.msg, {icon: 1});
                        //window.location.reload();
                        //window.location.href = data.data.down;
                        /*启动下载*/
                        downFile(title,data.data.down);
                    }else{
                        //layer.alert(data.msg, {icon: 5});
                        layer.confirm(data.msg, {icon: 3}, function(){
                            if(data.url != ''){
                                window.open('https://www.zc10000.com/?m=user&c=Users&a=login', '_blank');
                            }else{
                                layer.closeAll();
                            }
                        }, function(){
                            //layer.msg('点击取消的回调');
                        });
                    }
                },
                error:function(e){
                    layer.closeAll();
                    layer.alert(e.responseText, {icon: 5});
                }
            });
            return false;
        });
        
        //文档点赞
        $('#like_btn').click(function (){
            layer.msg('正在处理');
            var aid = $(this).attr('aid');
            var title = $(this).attr('title');
            $.ajax({
                type: "POST",
                url: '/api/Ajax/get_user_like',
                data: {del_id:0,_ajax:1,aid:aid},
                dataType: 'json',
                success: function (data) {
                    layer.closeAll();
                    if(parseInt(data.code) == 1){
                        layer.msg(data.msg, {icon: 1});
                        //window.location.reload();
                        //window.location.href = data.data.down;
                        /*增加点赞数*/
                        //data.data.likecount
                        $("#likecount").html(data.data.likecount);
                        //复选框
                        if(data.data.type == 1 || data.data.type == '1'){
                            console.log('1111');
                            //勾选
                            $('.btn-e').addClass('btn-e-active');
                        }else{
                            $('.btn-e').removeClass('btn-e-active');
                        }
                    }else{
                        //layer.alert(data.msg, {icon: 5});
                        layer.confirm(data.msg, {icon: 3}, function(){
                            if(data.url != ''){
                                window.open('https://www.zc10000.com/?m=user&c=Users&a=login', '_blank');
                            }else{
                                layer.closeAll();
                            }
                        }, function(){
                            //layer.msg('点击取消的回调');
                        });
                    }
                },
                error:function(e){
                    layer.closeAll();
                    layer.alert(e.responseText, {icon: 5});
                }
            });
            return false;
        });
        
        //文档收藏
        $('#collect_btn').click(function (){
            layer.msg('正在处理');
            var aid = $(this).attr('aid');
            var title = $(this).attr('title');
            $.ajax({
                type: "POST",
                url: '/api/Ajax/get_user_collect',
                data: {del_id:0,_ajax:1,aid:aid},
                dataType: 'json',
                success: function (data) {
                    layer.closeAll();
                    if(parseInt(data.code) == 1){
                        layer.msg(data.msg, {icon: 1});
                        //window.location.reload();
                        //window.location.href = data.data.down;
                        /*增加点赞数*/
                        //data.data.likecount
                        $("#collection").html(data.data.collection);
                        //复选框
                        if(data.data.type == 1 || data.data.type == '1'){
                            console.log('1111');
                            //勾选
                            $('.btn-d').addClass('btn-e-active');
                        }else{
                            $('.btn-d').removeClass('btn-e-active');
                        }
                    }else{
                        //layer.alert(data.msg, {icon: 5});
                        layer.confirm(data.msg, {icon: 3}, function(){
                            if(data.url != ''){
                                window.open('https://www.zc10000.com/?m=user&c=Users&a=login', '_blank');
                            }else{
                                layer.closeAll();
                            }
                        }, function(){
                            //layer.msg('点击取消的回调');
                        });
                    }
                },
                error:function(e){
                    layer.closeAll();
                    layer.alert(e.responseText, {icon: 5});
                }
            });
            return false;
        });
        
        //点击分享
        $('#share_btn').on('click',function (){
            $('#share-box').toggle();
            if ($(this).hasClass('btn-e-active')) {
                // 存在class
                $('.btn-c').removeClass('btn-e-active');
            } else {
                // 不存在class
                $('.btn-c').addClass('btn-e-active');
            }
        });
    });
</script>
</html>