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

    module.init = function (page) {
        //新闻详情
        tools.doGet(newsDetail+getQueryVariable('id'), {}, module.newsDetail , true);
        //新闻列表
        tools.doGet(newsList, {pageNum:1,pageSize:8}, module.newsList , true);
        tools.doGet(webList, {}, module.webList , true);
    };

    //获取地址栏参数
    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.webList = function (data) {
        if (data.code == 200) {
            var content = data.data;
            module.data.webList = content;
            var webData = template('webData', module.data);
            $("#webContent").html(webData);
            var titData = template('titData', module.data);
            $("#titContent").html(titData);
            $('#ewm').attr('src', 'static/images/'+content.top.bz);
        }
    }

    module.newsDetail = function (data) {
        if (data.code == 200) {
            var content = data.data;
            $('#content')[0].innerHTML = content.infoContent
            $('#name')[0].innerHTML = content.infoName
            $('#creatBy')[0].innerHTML = content.infoDept+' 的报道'
            $('#creatTime')[0].innerHTML = '&nbsp;·&nbsp;'+content.infoTime

            $('#infoImg')[0].innerHTML = '附件：<br/>';

            if (content.infoImg){
                let arr = content.infoImg.split(',');
                for (let i = 0;i < arr.length; i++){
                    $('#infoImg')[0].innerHTML += '<a style="color: #2a39fb;display: block;" target="_blank" href="/api'+arr[i]+'">'+arr[i].substr(27,arr[i].length)+'</a>';
                }
            }

            // $('#infoFile')[0].innerHTML = '附件：<br/>';
            //
            if (content.infoFile){
                let arr2 = content.infoFile.split(',');
                for (let i = 0;i < arr2.length; i++){
                    $('#infoImg')[0].innerHTML += '<a style="color: #2a39fb;display: block;" target="_blank" href="/api'+arr2[i]+'">'+arr2[i].substr(27,arr2[i].length)+'</a>';
                }
            }
        }
    }

    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);
        }
    }

    return module;
});
