/**
 * 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(otherPublicDetail, {
            id:getQueryVariable('id'),
            bookId: JSON.parse(tools.getCookie('user')).bookId,
            deptId: JSON.parse(tools.getCookie('user')).deptId
        }, module.newsDetail , true);
        //新闻列表
        tools.doGet(otherPublicList, {
            pageNum:1,
            pageSize:10,
            isAsc: 'desc',
            bookId: JSON.parse(tools.getCookie('user')).bookId,
            deptId: JSON.parse(tools.getCookie('user')).deptId,
            otherType: 13
        }, 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);
            $('#ewm').attr('src', 'static/images/'+content.top.bz);
        }
    }

    module.newsDetail = function (data) {
        if (data.code == 200) {
            var content = data.data;
            $('#openName')[0].innerHTML = content.otherName;
            $('#openNy')[0].innerHTML = '公开年月：'+content.openAt;

            $('#openPic')[0].innerHTML = '公开图片：<br/>';

            if (content.openPic){
                let arr = content.openPic.split(',');
                for (let i = 0;i < arr.length; i++){
                    $('#openPic')[0].innerHTML += '<img onclick="openDialog(\'/api'+arr[i]+'\')" src="/api'+arr[i]+'" style="width: 200px;height: 150px;margin-right: 10px;">';
                }
            }

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

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

            $('#content')[0].innerHTML = '内容：'+(content.openContent || '');
            $('#remark')[0].innerHTML = '备注：'+(content.remark || '');

        }
    }

    openDialog = function (src){
        $("#dialogOp").css('display','block');
        $('#dialogImg').attr('src', src);
    }

    closeDia = function (){
        $("#dialogOp").css('display','none');
        $('#dialogImg').attr('src', '');
    }

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