/**
 * 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(siyigongkaiDetail, {id:getQueryVariable('id')}, module.newsDetail , true);
        //新闻列表
        tools.doGet(listSiyigongkai, {pageNum:1,pageSize:8, isAsc:'desc', orderByColumn:'createTime'}, 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;
            $('#name')[0].innerHTML = content.openName;
            $('#jueyiAt')[0].innerHTML = '决议公开日期：'+(content.jueyiAt || '');

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

            $('#shishiPic')[0].innerHTML = '实施结果公开图片：<br/>';
            if (content.shishiPic){
                let arr2 = content.shishiPic.split(',');
                for (let i = 0;i < arr2.length; i++){
                    $('#shishiPic')[0].innerHTML += '<img onclick="openDialog(\'/api'+arr2[i]+'\')" src="/api'+arr2[i]+'" style="width: 200px;height: 150px;margin-right: 10px;">';
                }
            }

            $('#shishiAt')[0].innerHTML = '实施结果公开日期：' + ( content.shishiAt || '' );

            $('#shishiguochengPic')[0].innerHTML = '实施过程公开图片：<br/>';
            if (content.shishiguochengPic){
                let arr3 = content.shishiguochengPic.split(',');
                for (let i = 0;i < arr3.length; i++){
                    $('#shishiguochengPic')[0].innerHTML += '<img onclick="openDialog(\'/api'+arr3[i]+'\')" src="/api'+arr3[i]+'" style="width: 200px;height: 150px;margin-right: 10px;">';
                }
            }

            $('#shishiguochengAt')[0].innerHTML = '实施过程公开日期：' + ( content.shishiguochengAt || '' );

            $('#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;
});
