pageHome.js 8.4 KB
//注意:导航 依赖 element 模块,否则无法进行功能性操作
layui.use('element', function () {
    var element = layui.element;
});
layui.use('util', function () {
    var util = layui.util;
    //执行
    util.fixbar({
        top: true
    });
});
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);
    var mon = (time.getMonth() + 1) >= 10 ? time.getMonth() + 1 : '0' + (time.getMonth() + 1);
    var day = time.getDate() >= 10 ? time.getDate() : '0' + time.getDate();
    date.push([time.getFullYear(), mon, day].join('/'));
    for (var i = 1; i < 7; i++) {//控制需要的天数
        var now = new Date(base -= oneDay); //这里控制往前一周还是往后一周
        var nowMon = (now.getMonth() + 1) >= 10 ? now.getMonth() + 1 : '0' + (now.getMonth() + 1);
        var nowDay = now.getDate() >= 10 ? now.getDate() : '0' + now.getDate();
        date.push([now.getFullYear(), nowMon, nowDay].join('/'));
        data.push(Math.round((Math.random() - 0.5) * 20 + data[i - 1]));
    }
    return date.reverse();
}

//初始化方法
$(function () {
    $('.loadheader').hide();
    addTabs('#index');
    initData();
    recentlyDay = getDate();
    // NoticeData();
    // LawsData();
    // policiesData();
});
function initData() {
    // 获取当前页面的url
    setItem('indexUrl',window.location.pathname)
    // 新闻模块
    if ($('.hotspot-list li').eq(0).attr('url')) {
        $('.news-img').attr('src', $('.hotspot-list li').eq(0).attr('url'));
    } else {
        $('.news-img').attr('src', '/staticImages/default-news.png');
    }
    $(document).on("mouseover", ".news-module-box .hotspot-list li", function (e) {
        if ($(this).attr('url')) {
            $('.news-img').attr('src', $(this).attr('url'));
        } else {
            $('.news-img').attr('src', '/staticImages/default-news.png');
        }
    })
    // 在这里处理置顶的头部
    let topTitle = $('.top-title').html();
    if (strLength(topTitle) > 7) {
        let html = topTitle.slice(0, 7) + '<br/>' + topTitle.slice(7);
        $('.top-title').html(html)
    }
    $('#appointment_inquiry').click(function () {
        if (isLogin()) {
            window.open('./staticViews/wdyy.html', '_self')
        }
    })
    $('#onlineBooking').click(function () {
        if (isLogin()) {
            window.open('./staticViews/wdyy.html', '_self')
        }
    })
    // 新闻头部切换
    $('.news-title .item-title').click(function () {
        $('.news-title .item-title').removeClass('news-active');
        $(this).addClass('news-active');
        let indexId = $(this).attr('data-id');
        $('.item-list').hide();
        if (indexId == '1') {
            $('.hotspot-list').show();
            $('.policies-regulations-href').attr('href','/staticViews/lawList/1.html');
        } else {
            $('.news-information-list').show();
            $('.policies-regulations-href').attr('href','/staticViews/policyList/1.html');
        }
    })
    // 便民服务
    $(".convenient-service-list li").mouseover(function () {
        $(this).find('img').attr('src', $(this).find('img').attr('url'));
    })
    $(".convenient-service-list li").mouseout(function () {
        $(this).find('img').attr('src', $(this).find('img').attr('pre'));
    })
    if (getItem('myCookie') && getItem('myCookie').username) {
        $('.login-list a').hide();
        $('.login-list-subtitle').show();
    }
    // 业务列表进行跳转
    $('.business-list-rightItem .business-search li').click(function () {
        let urlId = $(this).attr('url-id');
        if(urlId == 'appointment') {
            if (isLogin()) {
                window.open(getSearchUrl(urlId), '_self')
            }
        }else {
            window.open(getSearchUrl(urlId), '_self')
        }
    })
    // 政策法规
    $('.policies-regulations-title .item-title').click(function () {
        let index =  $(this).attr('data-id');
        $('.policies-regulations-title .item-title').removeClass('regulations-active');
        $(this).addClass('regulations-active');
        $('.item-policies').hide();
        if (index =='2') {
            $('.corresponding-policies').show();
        }else {
            $('.laws-regulations').show(); 
        }
    })
}
function getSearchUrl(level) {
    const resultMap = {
        archives: '/staticViews/convenienceService/fileQuery.html',
        progress: '/staticViews/convenienceService/progressInquiry.html',
        appointment : '/staticViews/yyxz.html',
        certificate: '/staticViews/convenienceService/certificateVerification.html',
        business: '/staticViews/convenienceService/businessInquiry.html',
        guide: '/staticViews/bszn.html',
        pay: '/staticViews/zxjf.html',
        default: 'gologin',
    }
    return resultMap[level] || resultMap.default;
}

// 获取汉字长度
function strLength(str) {
    ///<summary>获得字符串实际长度,中文2,英文1</summary>
    ///<param name="str">要获得长度的字符串</param>
    var realLength = 0, len = str.length, charCode = -1;
    for (var i = 0; i < len; i++) {
        charCode = str.charCodeAt(i);
        if (charCode >= 0 && charCode <= 128)
            realLength += 1;
        else
            realLength += 2;
    }
    return realLength;
};
//加载公告数据
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/notice/' + result.data[i].id + '.html" 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/law/' + result.data[i].id + '.html" 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/policy/' + result.data[i].id + '.html" title="' + result.data[i].headline + '" target="_blank">' + result.data[i].headline;
                    li += '</a></li>';
                    policies.append(li);
                }
            }
        }
    });
}