/**
 * Created by Administrator on 2021/4/5.
 */
define(['jquery', "template", "Tools", "newApi", 'swiper'], function ($, template, Tools ) {
    //数据存储
    var module = {
        data: {
            //焦点图数据
            focusListTop: [],
            newsInformationList:''
        },
    };
    var tools = new Tools();

    module.init = function (page) {
        //获取焦点图信息
        tools.doGet(websitePicture, {picType:1,status:0,orderByColumn:'picSort',isAsc:'desc'}, module.focusNewsTop , true);
        //底部友情链接
        tools.doGet(friendsLinks, {}, module.bottomFriendsLinks, true);
        console.log(getQueryVariable('id'))
        var titName = getQueryVariable('type')
        if(titName == 'zcfg'){
           document.getElementById('titIndex').innerText = '政策法规'
        }
        if(titName == 'jygz'){
            document.getElementById('titIndex').innerText = '交易规则'
        }
        if(titName == 'zlxz'){
            document.getElementById('titIndex').innerText = '资料下载'
        }

        //新闻资讯
        tools.doGet(newDetail + '/'+getQueryVariable('id'), {}, module.NewsInformation,true);

        //网站配置信息（网站名称 底部联系方式 公安备案号 网站备案号）
        tools.getWebConfig();
    };

    //焦点图数据
    module.focusNewsTop = function (data) {
        if (data.code == 200) {

            let focusArray = [];

            if(data.data.length<1){
                focusArray.push({
                    picUrl:'../../../static/images/banner1.png'
                },{
                    picUrl:'../../../static/images/banner2.png'
                },{
                    picUrl:'../../../static/images/banner3.png'
                })
            }else{
                data.data.forEach(res=>{
                    focusArray.push({
                        picUrl:'/api'+res.picUrl
                    })
                })
            }

            module.data.focusListTop = focusArray;
            var bannerFocusDataTop = template('bannerFocusDataTop', module.data);
            $("#bannerFocusTopContent").html(bannerFocusDataTop);

            new Swiper('#bannerFocusWrapTop', {
                paginationClickable: true,
                autoplay : 4000,
                loop:true
            })

        }
    }
    //底部友情链接
    module.bottomFriendsLinks = function (data) {
        if (data.code == 200) {
            var content = data.data;
            console.log(content)
            module.data.friendsLinksList = content;
            var friendsLinksData = template('friendsLinksData', module.data);
            $("#friendsLinksContent").html(friendsLinksData);
        }
    }

    //获取地址栏参数
    function getQueryVariable(variable){
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i=0;i<vars.length;i++) {
            var pair = vars[i].split("=");
            if(pair[0] == variable){return pair[1];}
        }
        return(false);
    }

    //新闻资讯数据
    module.NewsInformation = function (data) {
        console.log(data)
        if (data.code == 200) {
            var content = data.data;
            $("#newTitle").html(content.title);
            $("#newTime").html(content.newsTime);
            $("#newCome").html(content.createBy);
            $("#newContent").html(content.content);

            if(content.attachment){
                var content = content.attachment.split(',');
                let list = [];
                content.map(rr=>{
                    list.push({
                        fileUrl:rr,
                        fileName:rr.substr(27,rr.length)
                    })
                })

                module.data.attachmentList = list;
                var attachmentListData = template('attachmentListData', module.data);
                $("#attachmentListContent").html(attachmentListData);
            }

        }
    }

    return module;
});
