xwdt.js 3.67 KB
layui.use('element', function () {
    let element = layui.element; //导航的hover效果、二级菜单等功能,需要依赖element模块
});
$(function () {
    // LoadNewsData();
    HotArticle();
    PolicyHotArticle();
    addTabs('#news');
});
//加载新闻列表数据
function LoadNewsData(currentPage) {
    var currentPage = currentPage   ||  1;
    $.ajax({
        type: "get",  //提交方式  
        url: portal.api_url + "/portal/MhNews/getNewsArticleList",//路径 
        data: {
            "currentPage": currentPage,
            "pageSize": 5
        },
        async: false,
        dataType: "json",
        //数据,这里使用的是Json格式进行传输  
        success: function (result) {
            if (result.code == 200 && result.data != null) {
                data.total = result.data.total;
                data.list = result.data.records;
            }else {
                data.total = 0;
            }
            layui.use('laytpl', function () {
                laytpl = layui.laytpl;
                var getTpl = document.getElementById('demo').innerHTML
                    , view = document.getElementById('ulNews');
                laytpl(getTpl).render(data, function (html) {
                    view.innerHTML = html;
                })
            })
        }
    })
}
// 获取新闻动态的推荐数据
function HotArticle() {
    var recommend = $("#news_recommendation");
    recommend.empty();
    var li = '';
    $.ajax({
        type: "get",  //提交方式  
        url: portal.api_url + "/portal/MhNews/getNewsHotArticleList",//路径 
        dataType: "json",
        //数据,这里使用的是Json格式进行传输  
        success: function (result) {//返回数据根据结果进行相应的处理 
            if (result.code == 200 && result.data != null) {
                for (var i = 0; i < result.data.length; i++) {
                    if (i == 3) return;
                    li = '<li class="tj"><a href="/staticViews/news/'+result.data[i].id+'.html" target="_blank">';
                    if ( result.data[i].preViewUrl ) {
                        li += '<img src="' + result.data[i].preViewUrl + '">';
                    }
                    li += '<span class="tj-title">' + result.data[i].headline + '</span>';
                    li += '<span class="tj-date">' + result.data[i].deadtime + '</span>';
                    li += '</a></li>';
                    recommend.append(li);
                }
            }
        }
    })
}
// 相应政策推荐
function PolicyHotArticle() {
    var regulation = $("#regulation");
    regulation.empty();
    var li = '';
    $.ajax({
        type: "get",  //提交方式  
        url: portal.api_url + "/portal/MhPolicy/getPolicyHotArticleList",//路径 
        dataType: "json",
        //数据,这里使用的是Json格式进行传输  
        success: function (result) {//返回数据根据结果进行相应的处理 
            if (result.code == 200 && result.data != null) {
                for (var i = 0; i < result.data.length; i++) {
                    li = '<li class="zcfg">'
                    li += '<a href="/staticViews/policy/'+result.data[i].id+'.html" title="' + result.data[i].headline + '" target="_blank">'
                    li += '<div class="zcfg-top">' + result.data[i].headline + '</div>'
                    li += '<p class="zcfg-body">' + result.data[i].summary + '</p>'
                    li += '<div class="zcfg-bottom">' + result.data[i].deadtime + '</div>'
                    li += '</a>';
                    li += '</li>'
                    regulation.append(li);
                }
            }
        }
    })
}

var data = { //数据
    "list": [],
    total: 0
};