pageHome.js 6.96 KB
layui.use('carousel', function () {
    var carousel = layui.carousel;
    //建造实例
    carousel.render({
        elem: '#banner_swiper'
        , width: '100%' //设置容器宽度
        , arrow: 'always' //始终显示箭头
        , autoplay: true
        , height: '500px'
    });
});
//注意:导航 依赖 element 模块,否则无法进行功能性操作
layui.use('element', function () {
    var element = layui.element;
    //…
});
layui.use('util', function () {
    var util = layui.util;
    //执行
    util.fixbar({
        bar1: true,
        bar2: true,
        top: true
        , click: function (type) {
            if (type === 'bar1') {
                alert('点击了bar1')
            }
        }
    });
});

var recentlyDay;

function getDate() {
    var date = new Date();
    var base = new Date(date).getTime();
    var oneDay = 24 * 3600 * 1000;
    var date = [];
    var data = [Math.random() * 300];
    var time = new Date(base);
    date.push([time.getFullYear(), time.getMonth() + 1, time.getDate()].join('/'));
    for (var i = 1; i < 7; i++) {//控制需要的天数
        var now = new Date(base -= oneDay); //这里控制往前一周还是往后一周
        date.push([now.getFullYear(), now.getMonth() + 1, now.getDate()].join('/'));
        data.push(Math.round((Math.random() - 0.5) * 20 + data[i - 1]));
    }
    return date.reverse();    
}

//初始化方法
$(function () {
    $('.loadheader').hide();
    addTabs('#index');
    initData();
    recentlyDay = getDate();
    NewsData();
    NoticeData();
    LawsData();
    policiesData();
});
function initData() {
    $('#appointment_inquiry').click (function(){
        if (isLogin()) {
            window.open('./staticViews/wdyy.html')
        }
    })
    $('#onlineBooking').click (function(){
        if (isLogin()) {
            window.open('./staticViews/wdyy.html')
        }
    })
}
//加载新闻数据
function NewsData() {
    var ulNews = $("#ulNews");
    ulNews.empty();
    var li, publishTime;
    $.ajax({
        type: "get",  //提交方式  
        url: portal.api_url + "/portal/MhNews/getNewsList",//路径  
        dataType: "json",
        //数据,这里使用的是Json格式进行传输  
        success: function (result) {//返回数据根据结果进行相应的处理         
            if (result.code == 200 && result.data != null) {
                if(result.data[0].preViewUrl) {
                    $('.news-img img').attr('src',result.data[0].preViewUrl);
                }else {
                    $('.news-img img').attr('src','./staticImages/news_demo.jpg');
                }
                for (var i = 0; i < result.data.length; i++) {
                    if (i == 6) return;
                    publishTime = CutDate(result.data[i].publishTime);
                    if (result.data[i].preViewUrl) {
                        li = '<li url="'+result.data[i].preViewUrl+'"><a href="./staticViews/xwxq.html?id='+result.data[i].id+'" title="' + result.data[i].headline + '" target="_blank">';
                    }else {
                        li = '<li><a href="./staticViews/xwxq.html?id='+result.data[i].id+'" title="' + result.data[i].headline + '" target="_blank">';
                    }
                    li += '<div class="news_item">';
                    if (recentlyDay.indexOf(publishTime) > -1) {
                        li += '<svg class="icon svg-icon" aria-hidden="true"> <use xlink:href="#iconzuixin"></use> </svg>';
                    }
                    li += result.data[i].headline + '</div>';
                    li += '<span>' + publishTime + '</span></a></li>';
                    ulNews.append(li);
                }
            }
        }
    });

    $(document).on("mouseover", "#ulNews li", function (e) {
        if($(this).attr('url')) {
            $('.news-img img').attr('src',$(this).attr('url'));
        }else {
            $('.news-img img').attr('src','./staticImages/news_demo.jpg');
        }
    })
}

//加载公告数据
function NoticeData() {
    var ulTag = $("#ulNotice");
    ulTag.empty();
    var li;
    $.ajax({
        type: "get",  //提交方式  
        url: portal.api_url + "/portal/MhNotice/getMHNotice",//路径  
        dataType: "json",
        //数据,这里使用的是Json格式进行传输  
        success: function (result) {//返回数据根据结果进行相应的处理           
            if (result.code == 200 && result.data != null) {
                for (var i = 0; i < result.data.length; i++) {
                    if (i == 6) return;
                    li = '<li class="item_notice"><a href="./staticViews/ggxq.html?id='+result.data[i].id+'" title="' + result.data[i].title + '" target="_blank">';
                    li += '<p>' + result.data[i].title + '</P>';
                    if (result.data[i].noticeType == 1) {
                        li += '<svg class="icon svg-icon" aria-hidden="true"> <use xlink:href="#icongongshi"></use> </svg>';
                    }
                    else {
                        li += '<svg class="icon svg-icon" aria-hidden="true"> <use xlink:href="#icongonggao1"></use> </svg>';
                    }
                    li += '</a></li>';
                    ulTag.append(li);
                }
            }
        }
    });
}


//加载法律法规数据
function LawsData() {
    var ulTag = $("#ulLaws");
    ulTag.empty();
    var li;
    $.ajax({
        type: "get",  //提交方式  
        url: portal.api_url + "/portal/MhLaws/getLawsList",//路径  
        dataType: "json",
        //数据,这里使用的是Json格式进行传输  
        success: function (result) {//返回数据根据结果进行相应的处理           
            if (result.code == 200 && result.data != null) {
                for (var i = 0; i < result.data.length; i++) {
                    if (i == 6) return;
                    li = '<li><a href="./staticViews/flfgxq.html?id='+result.data[i].id+'" title="' + result.data[i].headline + '" target="_blank">'+ result.data[i].headline;
                    li += '</a></li>';
                    ulTag.append(li);
                }
            }
        }
    });
}
//加载相应政策数据
function policiesData() {
    var policies = $("#policies");
    policies.empty();
    var li;
    $.ajax({
        type: "get",  //提交方式  
        url: portal.api_url + "/portal/MhPolicy/getPolicyList",//路径  
        dataType: "json",
        //数据,这里使用的是Json格式进行传输  
        success: function (result) {//返回数据根据结果进行相应的处理           
            if (result.code == 200 && result.data != null) {
                for (var i = 0; i < result.data.length; i++) {
                    if (i == 6) return;
                    li = '<li><a href="./staticViews/xyzcxq.html?id='+result.data[i].id+'" title="' + result.data[i].headline + '" target="_blank">'+ result.data[i].headline;
                    li += '</a></li>';
                    policies.append(li);
                }
            }
        }
    });
}