/**----重复方法和参数都放在了共通index.js文件中---**/
var typeName = "资讯首页";
var pages = 0;
var storage = window.sessionStorage;
$(function () {
    $(".logo button").click(function () {
        var content = $("#Sou").val();
        var type = $("#selectType").val();
        if(content.trim().length<2){
            layer.tips("请至少输入两个字符","#Sou");
        }else{
            if(type=="供应"){
                window.location.href="../spzs/?search="+content;
            }else if(type=="采购"){
                window.location.href="../syjh/qiugou.htm?search="+content;
            }else if(type=="企业"){
                window.location.href="../qyml/?search="+content;
            }else if(type=="资讯"){
                window.location.href="../hyxx/informationSearch.html?search="+content;
            }else if(type=="百科"){
                window.location.href="../qyfw/encyclopediaSearch.html?search="+content;
            }
        }
    });
    //加载所有列表
    getALLInfo();
    /**
     * 设置本地缓存
     */
    $(".address").click(function(){
        typeName = $(this).html();
        storage["url"] = $(this).html();
        storage["addressActive"] = $(this).html();
        // 修改颜色
        $(this).parent().siblings().children().css("color", "#333333");
        $(this).css("color", "#ff774d");
        if($(this).html() != "资讯首页"){
            window.location.href="informationIndustryNews.html?type="+$(this).html();
        }
    });
    //getSwiper()
});

function getALLInfo(){
    //获取最新新闻
    getInfo("展览会议",1);
    getInfo("业界新闻",1);
    getInfo("市场行情",1);
    getInfo("绿化招标",1);
    getOtherNews();
    getOtherNews_1();
    getOtherNews_2();
}
/**
 * 查询列表
 * @param page
 */
function getInfo(typeName,page) {
    var data = {
        "typename":typeName,
        "page": page
    };
    $.ajax({
        url:url+"/news/zxbk/zxByType",
        data: data,
        type: "get",
        dateType: "json",
        async: true,
        success: function success(response, status, xhr) {
            var result_0 = "";
            console.log(response);
            $.each(response, function (i, list) {
                if(i < 15){
                    result_0 += "<div class='ul_img font_size_15_rem one_line' title='"+list.title+"'><span></span><a href='shownews/"+list.newsid+".html' target='_blank'>"+list.title+"</a></div>";
                }else{
                    return false;
                }
            });
            if (typeName == "展览会议"){
                $("#result_1").html(result_0);
            } else if (typeName == "业界新闻"){
                $("#result_3").html(result_0);
            } else if (typeName == "市场行情"){
                $("#result_4").html(result_0);
            } else if (typeName == "绿化招标"){
                $("#result_6").html(result_0);
            }

        },
        error: function error( a,b,c) {
            console.log("error:="+JSON.stringify(a));
            layer.msg('未知错误,请联系客服!', { icon: 5 });
            $(".list").attr("style","display: none");
            $(".page").attr("style","display: none");
            $(".list_00").attr("style","display: block");
        }
    });
}

/**
 * 获取最新新闻
 */
function getOtherNews(){
    $.ajax({
        url:url+"/news/zxbk/latestZx",
        data: {
            page: 1
        },
        type: "get",
        dateType: "json",
        async: true,
        success: function success(response, status, xhr) {
            var result_0 = "";
            $.each(response, function (i, list) {
                if(i < 15){
                    result_0 += "<div class='ul_img font_size_15_rem one_line' title='"+list.title+"'><span></span><a href='shownews/"+list.newsid+".html' target='_blank'>"+list.title+"</a></div>";
                }
            });
            $("#result_0").html(result_0);
        },
        error: function error() {
            layer.msg('未知错误,请联系客服!', { icon: 5 });
        }
    });
}
/**
 * 获取绿化招标第二部分
 */
function getOtherNews_1(){
    $.ajax({
        url:url+"/news/zxbk/zxByType",
        data: {
            typename: '绿化招标',
            page: 2
        },
        type: "get",
        dateType: "json",
        async: true,
        success: function success(response, status, xhr) {
            var result_0 = "";
            $.each(response, function (i, list) {
                if(i < 15){
                    result_0 += "<div class='ul_img font_size_15_rem one_line' title='"+list.title+"'><span></span><a href='shownews/"+list.newsid+".html' target='_blank'>"+list.title+"</a></div>";
                }else{
                    return false;
                }
            });
            $("#result_7").html(result_0);
        },
        error: function error() {
            layer.msg('未知错误,请联系客服!', { icon: 5 });
        }
    });
}
/**
 * 获取热点新闻第二部分
 */
function getOtherNews_2(){
    $.ajax({
        url:url+"/news/zxbk/hotZx",
        data: {
            page: 1
        },
        type: "get",
        dateType: "json",
        async: true,
        success: function success(response, status, xhr) {
            var result_0 = "";
            $.each(response, function (i, list) {
                if(i < 15){
                    result_0 += "<div class='ul_img font_size_15_rem one_line' title='"+list.title+"'><span></span><a href='shownews/"+list.newsid+".html' target='_blank'>"+list.title+"</a></div>";
                }else{
                    return false;
                }
            });
            $("#result_2").html(result_0);
        },
        error: function error() {
            layer.msg('未知错误,请联系客服!', { icon: 5 });
        }
    });
}
/**
 * 获取详细内容
 */
function getContent(str){
    console.log(str);
    storage["addressActive"] = $("a[class='address active']").html();
    storage["contentNewsId"] = str;
    if(str != ''){
        window.location.href="../hyxx/shownews.html";
    } else {
        layer.msg("无详细内容")
    }
}
/**
 * 加载swiper动画
 */
function getSwiper(){
    var mySwiper = new Swiper ('.swiper-container', {
        direction: 'horizontal', // 垂直切换选项
        autoplay: false,//可选选项,自动滑动
        freeMode : false,
        slidesPerView :4, //设置同时显示的数量
        // 如果需要前进后退按钮
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        }
    })
}