/**
 * Created by Administrator on 2021/4/5.
 */
define(['jquery', "template", "Tools", "echarts", 'swiper'], function ($, template, Tools, echarts, swiper) {
    //数据存储
    var module = {
        data: {
            //服务器地址
            serverApi:'',
            //焦点图数据
            focusList: [],
            communicateList: [],
        },
    };
    var tools = new Tools();

    module.init = function (page) {
        //新闻管理列表
        // tools.doGet(news + '/003//7', {}, module.focusNews , true);

        tools.doGet(getTopDeptId, {}, module.getInformation , true);
    };

    module.getInformation = function (data) {
        console.log(data)
        tools.doGet(news + '/003/'+data.data+'/7', {}, module.newList , true);
        tools.doGet(news + '/001/'+data.data+'/7', {}, module.noticeList , true);
        tools.doGet(news + '/002/'+data.data+'/7', {}, module.enforcementList , true);
        tools.doGet(getScheme + '/'+data.data+'/7', {}, module.schemeList , true);

        var tabs = $('.nyzf').find('p');

        tabs.on('click', function (e) {

            e.preventDefault();//防止打开链接

            var id = $(this).data('id');

            tabs.removeClass('active');

            $(this).addClass('active');

            tools.doGet(news + '/'+id+'/'+data.data+'/7', {}, module.enforcementList , true);
        });
    }

    //新闻列表
    module.newList = function (data) {
        if (data.code == 200) {
            var content = data.data;

            var focusList = [];
            for (var i = 0; i < content.length; i++) {
                var imgStrs = content[i].content.match(/<img.*?>/g)
                var title = content[i].title;
                var id = content[i].id;
                if (imgStrs != null && imgStrs != '') {
                    focusList.push({img:imgStrs[0],title:title,id:id})
                }
            }
            module.data.focusList = focusList;
            var bannerFocusData = template('bannerFocusData', module.data);
            $("#bannerFocusContent").html(bannerFocusData);
            new Swiper('#bannerFocusWrap', {
                pagination: '.page-pagination',
                paginationClickable: true,
                autoplay : 2000,
                loop:true
            })
            console.log(focusList)
            module.data.newList = content;
            var newData = template('newData', module.data);
            $("#newContent").html(newData);
        }
    }

    //公告列表
    module.noticeList = function (data) {
        if (data.code == 200) {
            var content = data.data;
            module.data.noticeList = content;
            var noticeData = template('noticeData', module.data);
            $("#noticeContent").html(noticeData);
        }
    }

    //执法依据
    module.enforcementList = function (data) {
        if (data.code == 200) {
            var content = data.data;
            module.data.enforcementList = content;
            var enforcementData = template('enforcementData', module.data);
            $("#enforcementContent").html(enforcementData);
        }
    }

    //方案公开
    module.schemeList = function (data) {
        if (data.code == 200) {
            var content = data.data;
            module.data.schemeList = content;
            var schemeData = template('schemeData', module.data);
            $("#schemeContent").html(schemeData);
        }
    }

    //焦点图数据
    module.focusNews = function (data) {
        if (data.code == 200) {
            var content = data.data;
            var focusList = [];
            for (var i = 0; i < content.length; i++) {
                var imgStrs = content[i].content.match(/<img.*?>/g)
                var title = content[i].title;
                var id = content[i].id;
                if (imgStrs != null && imgStrs != '') {
                    focusList.push({img:imgStrs[0],title:title,id:id})
                }
            }
            //console.log(focusList)
            module.data.focusList = focusList;
            var bannerFocusData = template('bannerFocusData', module.data);
            $("#bannerFocusContent").html(bannerFocusData);
            new Swiper('#bannerFocusWrap', {
                pagination: '.page-pagination',
                paginationClickable: true,
                autoplay : 2000,
                loop:true
            })

        }
    }

    goDetail = function(id){
        tools.skip('/agriculturalLawEnforcement/view/workDynamics/workDetail.html?id='+id);
    }

    goNotice = function(id){
        tools.skip('/agriculturalLawEnforcement/view/noticeAnnouncement/noticeDetail.html?id='+id);
    }

    goScheme = function(id){
        tools.skip('/agriculturalLawEnforcement/view/schemeDisclosure/schemeDetail.html?id='+id);
    }

    goEnforcement = function(id){
        tools.skip('/agriculturalLawEnforcement/view/basis/basisDetail.html?id='+id);
    }

    goInteractSearch = function(){
        tools.skip('view/interact/interactList.html?keyWord='+$('#interactInput').val());
    }
    return module;
});