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

    module.init = function (page) {
        tools.doGet(webList, { configKey: 'web.open' }, module.webList , true);
        //新闻列表
    };

    module.newsList = function (data) {
        if (data.code == 200) {
            var content = data.rows;
            module.data.newList = content;
            var newListData = template('newListData', module.data);
            $("#newListContent").html(newListData);

            var newImgList = [];
            content.map(rr=>{
                if (rr.infoImg!=null&&rr.infoImg!=""){
                    newImgList.push(rr.infoImg);
                }
            })
            module.data.newImgList = newImgList;
            var newListDataImg = template('newListDataImg', module.data);
            $("#bannerFocusNextContent").html(newListDataImg);
            if ( content.length > 7){
                roll(20)
            }
            new Swiper('#bannerFocusNextWrap', {
                paginationClickable: true,
                pagination: '.a2',
                autoplay : 2000,
                loop:true
            })
        }
    }

    module.webList = function (data) {
        if (data.code == 200) {
            var content = data.rows;

            content.map(rr=>{
                if (rr.configKey == 'web.open.technique'){
                    $("#zcdw").html(rr.configValue);
                }
                if (rr.configKey == "web.open.phone"){
                    $("#phone").html(rr.configValue);
                }
                if (rr.configKey == "web.open.qrcode"){
                    $('#ewm').attr('src', rr.configValue);
                }
                if (rr.configKey == "web.open.title"){
                    $("#tt").html(rr.configValue);
                }
            })

        }
    }

    searchChange = function () {
        tools.doGet(newsList, {pageNum:1,pageSize:8,infoName:$("#searchInput").val()}, module.newsList , true);
    }

    function roll(t) {
        var ul1 = document.getElementById("newListContent");
        var ul2 = document.getElementById("newListContent2");
        var ulbox = document.getElementById("review_box");
        ul2.innerHTML = ul1.innerHTML;
        ulbox.scrollTop = 0; // 开始无滚动时设为0
        var timer = setInterval(rollStart, t); // 设置定时器，参数t用在这为间隔时间（单位毫秒），参数t越小，滚动速度越快
        // 鼠标移入div时暂停滚动
        ulbox.onmouseover = function () {
            clearInterval(timer);
        }
        // 鼠标移出div后继续滚动
        ulbox.onmouseout = function () {
            timer = setInterval(rollStart, t);
        }
    }

    // 开始滚动函数
    function rollStart() {
        // 上面声明的DOM对象为局部对象需要再次声明
        var ul1 = document.getElementById("newListContent");
        var ul2 = document.getElementById("newListContent2");
        var ulbox = document.getElementById("review_box");
        // 正常滚动不断给scrollTop的值+1,当滚动高度大于列表内容高度时恢复为0
        console.log(ulbox.scrollTop+'--------'+ul1.scrollHeight)
        if (ulbox.scrollTop >= ul1.scrollHeight) {
            ulbox.scrollTop = 0;
        } else {
            ulbox.scrollTop += 1;
        }
    }

    return module;
});
