//检查更新
//     $.get(window.location.href,'checked=1&updatime='+pageConfig.updatime,function(d){
//         if(d!=='false'){
//             window.location.reload();
//         }
//         return false;
//     });

//初始化ct_fy高度
var fyms_h = $(".ct_fy").height();
if (fyms_h > 100) {
    $(".ct_fy").css({
        "height": "75px",
        "overflow": "hidden",
        "margin-bottom": "-20px",
        "word-wrap": "break-word",
        "line-height": "24px",
        "text-align": "justify"
    });
} else {
    $(".ct_fy").next().hide();
}

//初始化ct_fy-2高度
var fyms_h_2 = $(".ct_fy-2").height();
if (fyms_h_2 > 100) {
    $(".ct_fy-2").css({
        "height": "75px",
        "overflow": "hidden",
        "margin-bottom": "-20px",
        "word-wrap": "break-word",
        "line-height": "24px",
        "text-align": "justify"
    });
} else {
    $(".ct_fy-2").next().hide();
}

//房源详情抽屉
$('#ct_fy_open a').on('click', function () {
    if ($(this).hasClass('open')) {
        $(this).removeClass('open').html('查看更多&nbsp;&nbsp;' + '<img src="/themes/'+style+'/images/detail/unfold.png"/>');
        $(".ct_fy").css({
            "height": "75px",
            "overflow": "hidden",
            "margin-bottom": "-20px",
            "word-wrap": "break-word",
            "line-height": "24px",
            "text-align": "justify"
        });
    } else {
        $(this).addClass('open').html('收起&nbsp;&nbsp;' + '<img src="/themes/'+style+'/images/detail/pack-up.png"/>');
        $(".ct_fy").css({
            "height": "auto",
            "overflow": "hidden",
            "margin-bottom": "-20px",
            "word-wrap": "break-word",
            "line-height": "24px",
            "text-align": "justify"
        });
    }
});

//小区信息及配套抽屉
$('#ct_sq_open a').on('click', function () {
    if ($(this).hasClass('open')) {
        $(this).removeClass('open').html('查看更多&nbsp;&nbsp;' + '<img src="/themes/'+style+'/images/detail/unfold.png"/>');
        $(".ct_fy-2").css({
            "height": "75px",
            "overflow": "hidden",
            "margin-bottom": "-20px",
            "word-wrap": "break-word",
            "line-height": "24px",
            "text-align": "justify"
        });
    } else {
        $(this).addClass('open').html('收起&nbsp;&nbsp;' + '<img src="/themes/'+style+'/images/detail/pack-up.png"/>');
        $(".ct_fy-2").css({
            "height": "auto",
            "overflow": "hidden",
            "margin-bottom": "-20px",
            "word-wrap": "break-word",
            "line-height": "24px",
            "text-align": "justify"
        });
    }
});

//点击查看房租月付弹层
$('.huabei-box').on('click', function () {
    $('.huabei-fixed').show();
    return false;
});
$('.huabei-fixed-box').on('click', function () {
    return false;
});

//点击关闭房租月付弹层
$('.huabei-fixed-box-hide').on('click', function () {
    $('.huabei-fixed').hide();
});

function addHistory() {
    var caseIds = $.cookie(pageConfig['caseType'] + '_history') || "";
    caseIds = caseIds ? caseIds.indexOf("_") >= 0 ? caseIds.split("_") : [caseIds] : [];
    if (!pageConfig || !pageConfig['caseId']) return;

    var newCaseId = pageConfig['caseId'] || "";
    var newCaseIds = [];
    for (var i = 0;i<caseIds.length;i++) {
        if (newCaseId === caseIds[i]) {
            continue;
        }

        newCaseIds.push(caseIds[i]);
    }
    if (newCaseId) {
        newCaseIds.unshift(newCaseId);
    }
    if (newCaseIds.length > 5) {
    	var delCaseIds = newCaseIds.slice(5);
        newCaseIds = newCaseIds.slice(0, 5);
        for(var i = 0;i<delCaseIds.length;i++){
        	$.cookie(pageConfig['caseType'] + '_history_' + delCaseIds[i], '', {expires: -1,path: '/'});
        }
    }
    $.cookie(pageConfig['caseType'] + '_history_' + pageConfig['caseId'], encodeURI(hisJson), {expires: 30});
    $.cookie(pageConfig['caseType'] + '_history', newCaseIds.join("_"), {expires: 30});
}

function getHistoryHtml() {
    var caseIds = $.cookie(pageConfig['caseType'] + '_history') || "";
    // 使用缓存的，不用请求接口
    // $.ajax({
    //     type: "get",
    //     url: "/history/" + pageConfig['caseType'] + "/" + caseIds,
    //     dataType: 'html',
    //     success: function (data) {
    //         console.error(data);
    //         $("#historyUl").html(data);
    //     }
    // });
    if (!caseIds) {
        $("#historyUl").hide();
        return;
    }

    caseIds = caseIds.indexOf("_") >= 0 ? caseIds.split("_") : [caseIds];
    $("#historyUl").empty();
    for (var i =0;i<caseIds.length;i++) {
        var caseId = caseIds[i];
        var historyItem = $.cookie(pageConfig['caseType'] + '_history_' + caseId);
        if (!historyItem) continue;

        historyItem = decodeURI(historyItem);
        historyItem = JSON.parse(historyItem);
        if (!historyItem.url) continue;
        var liItem = '<li>' +
            '<a href="' + historyItem.url + '">' +
            '<span class="name">' + (historyItem.name || "") + '</span>' +
            '<span class="type">' +
            (historyItem.useage || "")
            + ((historyItem.room && historyItem.room > 0) ? historyItem.room + "室" : "")
            + (historyItem.useage || (historyItem.room && historyItem.room > 0) ? "," : "")
            + (historyItem.area || "") +
            '</span>' +
            '<span class="price">' +
            (historyItem.price || "暂无价格") +
            '</span'+
            '</a>' +
            '</li>';

        $("#historyUl").append(liItem);
    }
}

addHistory();
getHistoryHtml();
//判断是不是二手房页面，从而是否执行查询房价趋势
if (typeof pageConfig.assessDataUrl !== "undefined") {
    getAssessData();
}

// 计算价格走势的平均价格
function getPriceTrendEveryVal(list) {
    list = list || [];
    var cityNoZeroNum = 0;
    var cityNoZeroIndex = 0;
    var cityNoZeroEveryVal = 0;
    for (var i = 0; i < list.length; i++) {
        if (list[i].price && list[i].price > 0) {
            cityNoZeroIndex++;
        }
        cityNoZeroNum += (list[i].price || 0);
    }
    if (cityNoZeroIndex !== 0) {
        cityNoZeroEveryVal = parseInt(cityNoZeroNum/cityNoZeroIndex);
    }
    return cityNoZeroEveryVal;
}

function priceTrend(buildTrendData) {
    if (typeof echarts == "undefined") {
        return;
    }
    if ($('#movements-pic').length > 0) {
        var myChart = echarts.init(document.getElementById('movements-pic'));
        var data = buildTrendData;
        var city = data.city || [];
        var region = data.region || [];
        var house = data.house || [];
        var cityArr = [], houseArr = [], regionArr = [], timeArr = [];
        var cityEveryPrice = getPriceTrendEveryVal(city);
        var regionEveryPrice = getPriceTrendEveryVal(region);
        var houseEveryPrice = getPriceTrendEveryVal(house);
        for (var i = 0; i < city.length; i++) {
            if (i !== 0 && (!city[i].price || city[i].price == 0)
                && (city[i-1].price && city[i-1].price != 0)) {
                city[i].price = cityEveryPrice;
            }
            cityArr.push(city[i].price);
            if (city[i].priceMonths.length == 7) {
                timeArr.push(city[i].priceMonths.substr(2, 5));
            }
        }
        for (var i = 0; i < house.length; i++) {
            if (i !== 0 && (!house[i].price || house[i].price == 0)
                && (house[i-1].price && house[i-1].price != 0)) {
                house[i].price = houseEveryPrice;
            }
            houseArr.push(house[i].price);
        }
        for (var i = 0; i < region.length; i++) {
            if (i !== 0 && (!region[i].price || region[i].price == 0)
                && (region[i-1].price && region[i-1].price != 0)) {
                region[i].price = regionEveryPrice;
            }
            regionArr.push(region[i].price);
        }
        var numArr = [];
        numArr = numArr.concat(regionArr, houseArr, cityArr);
        for (var i = 0; i < numArr.length; i++) {
            var maxNum = Math.max.apply(Math, numArr);
            var minNum = Math.min.apply(Math, numArr);
        }
        var max = getMaxNum(maxNum);
        var min = formatNum(minNum);
        // 指定图表的配置项和数据
        var option = {
            title: {
                text: ''
            },
            tooltip: {
                trigger: 'axis',           // 触发类型，默认数据触发，见下图，可选为：'item' ¦ 'axis'
                showDelay: 20,             // 显示延迟，添加显示延迟可以避免频繁切换，单位ms
                hideDelay: 100,            // 隐藏延迟，单位ms
                transitionDuration: 0.4,  // 动画变换时间，单位s
                backgroundColor: 'rgba(0,0,0,0.7)',     // 提示背景颜色，默认为透明度为0.7的黑色
                borderColor: '#333',       // 提示边框颜色
                borderRadius: 4,           // 提示边框圆角，单位px，默认为4
                borderWidth: 0,            // 提示边框线宽，单位px，默认为0（无边框）
                padding: 5,                // 提示内边距，单位px，默认各方向内边距为5，
                triggerOn: "click",
                axisPointer: {
                    // 坐标轴指示器，坐标轴触发有效
                    type: 'line',         // 默认为直线，可选为：'line' | 'shadow'
                    lineStyle: {          // 直线指示器样式设置
                        color: '#48b',
                        width: 1,
                        type: 'solid'
                    },
                    shadowStyle: {                       // 阴影指示器样式设置
                        width: 'auto',                   // 阴影大小
                        color: 'rgba(150,150,150,0.3)'  // 阴影颜色
                    }
                },
                textStyle: {
                    color: '#fff'
                }
            },
            legend: {
                data: [
                    {
                        name: data.buildName,
                        textStyle: {
                            color: "#16C866"
                        }
                    },
                    {
                        name: data.regionName,
                        textStyle: {
                            color: "#FFA913"
                        }
                    }, {
                        name: data.cityName,
                        textStyle: {
                            color: "#19BFE9"
                        }
                    }],
                bottom: 20
            },
            xAxis: {
                gridIndex: 0,
                type: 'category',
                name: '时间',
                data: timeArr,
                boundaryGap: false,
                axisLabel: {
                    show: true,
                    margin: 10,
                    interval: 1,
                    textStyle: {
                        color: '#666666'
                    }
                },
                axisTick: {
                    alignWithLabel: true
                },
                splitLine: {
                    show: true,
                    lineStyle: {
                        type: 'dashed'
                    }
                }
            },
            yAxis: {
                name: '均价(元/平)',
                axisLabel: {
                    show: true,
                    interval: 2,
                    textStyle: {
                        color: '#333'
                    }
                },
                axisTick: {
                    alignWithLabel: true,
                    interval: 5
                },
                splitLine: {
                    show: true,
                    lineStyle: {
                        type: 'dashed'
                    }
                },
                min: min,
                splitNumber: 5
            },
            series: [
                {
                    name: data.buildName,
                    type: 'line',
                    smooth: 'true',
                    lineStyle: {
                        normal: {
                            width: 1,  //连线粗细
                            color: "#16C866"  //连线颜色
                        }
                    },
                    itemStyle: {
                        normal: {
                            color: '#16C866'
                        }
                    },
                    data: houseArr
                },
                {
                    name: data.regionName,
                    type: 'line',
                    smooth: 'true',
                    lineStyle: {
                        normal: {
                            width: 1,  //连线粗细
                            color: "#FFA913"  //连线颜色
                        }
                    },
                    itemStyle: {
                        normal: {
                            color: '#FFA913'
                        }
                    },
                    data: regionArr
                },
                {
                    name: data.cityName,
                    type: 'line',
                    smooth: 'true',
                    lineStyle: {
                        normal: {
                            width: 1,  //连线粗细
                            color: "#19BFE9"  //连线颜色
                        }
                    },
                    itemStyle: {
                        normal: {
                            color: '#19BFE9'
                        }
                    },
                    data: cityArr
                }],
            grid: {
                top: '40',
                x: 0,
                y: 0,
                containLabel: true,
                borderWidth: 1
            }
        };
        myChart.setOption(option);
        $(".xiaoqu-zoushi").show();
    } else {
        $(".average,#movements-pic,.area-name").hide();
    }
}

function formatNum($num) {
    if ($num >= 10000) {
        return Math.floor($num / 10000) * 10000;
    } else if ($num >= 1000 && $num < 10000) {
        return Math.floor($num / 1000) * 1000;
    } else {
        return 0;
    }
}

function getMaxNum($num) {
    if ($num >= 10000) {
        $wan = Math.floor($num / 10000);
        $qian = Math.floor((($num - $wan * 10000) / 1000));
        if ($qian % 2 > 0) {
            return $wan * 10000 + $qian * 1000 + 3 * 1000;
        } else {
            return $wan * 10000 + $qian * 1000 + 2 * 1000;
        }
    }
}

function getAssessData() {
    $.ajax({
        url: pageConfig.assessDataUrl,
        data: {},
        success: function (res) {
            var htmlStr = '', ratioMonth = '', ratioYear = '', assessData;
            if (res.STATUS == 1 && res.DATA.buildTrendData.house.length > 0) {
                assessData = res.DATA;
                assessData.buildData.ratioByLastMonthForPrice = (assessData.buildData.ratioByLastMonthForPrice * 100).toFixed(2);
                assessData.buildData.ratioByLastYearForPrice = (assessData.buildData.ratioByLastYearForPrice * 100).toFixed(2);
                if (!!assessData.buildData.unitPrice) {
                    $('.m-post-2').show();
                    if (assessData.buildData.ratioByLastMonthForPrice > 0) {
                        ratioMonth = '<div>环比上月<span class="assessUp assessNum">' + Math.abs(assessData.buildData.ratioByLastMonthForPrice) + '%</span></div>';
                    } else if (assessData.buildData.ratioByLastMonthForPrice < 0) {
                        ratioMonth = '<div>环比上月<span class="assessDown assessNum">' + Math.abs(assessData.buildData.ratioByLastMonthForPrice) + '%</span></div>';
                    } else {
                        ratioMonth = '<div>环比上月<span class="assessUp assessNum">0%</span></div>';
                    }
                    if (assessData.buildData.ratioByLastYearForPrice > 0) {
                        ratioYear = '<div>同比去年<span class="assessUp assessNum">' + Math.abs(assessData.buildData.ratioByLastYearForPrice) + '%</span></div>';
                    } else if (assessData.buildData.ratioByLastYearForPrice < 0) {
                        ratioYear = '<div>同比去年<span class="assessDown assessNum">' + Math.abs(assessData.buildData.ratioByLastYearForPrice) + '%</span></div>';
                    } else {
                        ratioYear = '<div>同比去年<span class="assessUp assessNum">0%</span></div>';
                    }
                    htmlStr = '<div class="community">' +
                        '<div style="padding: 10px 0">' +
                        '<div class="houseAssessTitle">' +
                        '<span class="houseAssessByMonth">' + pageConfig.buildName + '本月均价</span>' +
                        '<span class="txt-col">' + assessData.buildData.unitPrice + '</span>' +
                        '<i class="assessUnit">元/㎡</i>' +
                        '</div>' +
                        '<ul class="community-list">' +
                        '<li class="community-li">' + ratioMonth + '</li>' +
                        '<li class="community-li">' + ratioYear + '</li>' +
                        '<li style="clear: both;"></li>' +
                        '</ul>' +
                        '</div>' +
                        '</div>' +
                        '<div class="movements comment">' +
                        '<div id="movements-pic"></div>' +
                        '</div>';
                    $('.assessBox').html(htmlStr);
                    priceTrend(assessData.buildTrendData);
                }
            }
        }
    })
}

//多个经纪人点击
$('.listing-ul .perf-info').on('click',function(){
    var that= this;
	var mobile = $(this).data('mobile');
    var cityId = $(this).data('cityid');
    //$(".xcx-code-box").hide();
    //$(".agent-box").hide();
    $(".xcx-code-box").removeClass('show');
     $(".agent-box").removeClass('show');
    if (!mobile || !cityId) {
    	$(this).find('.xcx-code-box').show();
    	$(that).find(".agent-box").hide();
        return;
    }
    if($(that).find(".agent-box").is(":visible")) {
    	$(".xcx-code-box").hide();
    	$(".agent-box").hide();
    	$(that).find(".agent-box").hide();
    	return;
    }
    
    if($(that).find(".xcx-code-box").is(":visible")) {
    	$(".xcx-code-box").hide();
    	$(".agent-box").hide();
    	$(that).find(".xcx-code-box").hide();
    	return;
    }
    
    $(".xcx-code-box").hide();
	$(".agent-box").hide();
    if (!$(this).find(".agent-box .info-box .info-mobile>span").text()) {
        $.ajax({
            data: {
                mobile: mobile,
                cityId: cityId
            },
            url: '/home/Sale/getNormalBroker400',
            success: function (data) {
                if (!!data) {
                	data = data.replace(',', ' 转 ');
                	$(that).find(".agent-box .info-box .info-mobile>span").text(data);
                	$(that).find(".agent-box").show();
                	$(that).find('.xcx-code-box').hide();
                }else{
                	$(that).find('.xcx-code-box').show();
                	$(that).find(".agent-box").hide();
                }
            }
        })
    } else {
    	$(this).find(".agent-box").show();
    	$(that).find('.xcx-code-box').hide();
    }
})

//个人房源咨询业主
$('.zixun-yezhu').on('click', function () {
    if ($(".zixun-app-download").css("display") == 'none') {
        $('.zixun-app-download').show();
    } else {
        $('.zixun-app-download').hide();
    }
    return false;
});

// 点击查看400号码
$('.call-broker-phone').on('click', function () {
    var mobile = $(this).data('phone');
    var cityId = $(this).data('cityid');
    
    $('.phone-num-bomp').removeClass('show')
    $('.xcx-code-box').removeClass('show')
    if (!mobile || !cityId) {
    	$('.xcx-code-box').show();
        return;
    }
    
    if($(".phone-num-bomp").is(":visible")) {
    	$(".xcx-code-box").hide();
    	$(".phone-num-bomp").hide();
    	return;
    }
    
    if($(".xcx-code-box").is(":visible")) {
    	$(".xcx-code-box").hide();
    	$(".phone-num-bomp").hide();
    	return;
    }
    
    if (!$('.phone-num-bomp .txt-400-con .number').text()) {
        $.ajax({
            data: {
                mobile: mobile,
                cityId: cityId
            },
            url: '/home/Sale/getNormalBroker400',
            success: function (data) {
                if (!!data) {
                	data = data.replace(',', ' 转 ');
                	$('.phone-num-bomp .txt-400-con .number').text(data);
                	$('.phone-num-bomp').show();
                	$('.xcx-code-box').hide();
                }else{
                	$('.xcx-code-box').show();
                	$('.phone-num-bomp').hide();
                }
            }
        })
    } else {
        $('.phone-num-bomp').show();
        $('.xcx-code-box').hide();
    }
    return false;
});

//点击楼盘地址直接滚动到位置及配套
$(".buildAddr").on("click", function (a) {
    if (pageConfig.caseType == "sale") {
        var id = $("#_md5").attr("data");
    } else {
        id = $("#_md4").attr("data");
    }

    scrollToMd(id);
    a.preventDefault();
});

//顶部导航栏效果
$("body").on("click", "#m-navbar div", function (a) {
    var id = $(this).attr("data");
    scrollToMd(id);
    a.preventDefault();
});
// 点击悬浮菜单滚动至对应详情
// 添加防抖机制
let flag= true
function scrollToMd(id) {
    if (!$("#" + id) || !$("#" + id).offset() || $("#" + id).offset().top == undefined) return;
    var top = $("#" + id).offset().top;
    if (!flag)
        return
    flag= false
    $("html,body").animate({scrollTop: top - 40}, 660, function () {
        var top1 = $("#" + id).offset().top;
        if (top != top1) {
            $("html,body").scrollTop(top1 - 40);
        }
        flag= true;
    });
}

//点击空白处,一些弹框层隐藏
$("body").on('click', function () {
    if ($(".zixun-app-download").css("display") == 'block') {
        $('.zixun-app-download').hide();
    }
    
    if ($(".phone-num-bomp.show").css("display") == 'block') {
        $('.phone-num-bomp').toggleClass('show');
    }
});

$(function () {
    if ($(".wraper") && $(".wraper .u-bread")) {
        $(".u-bread").parents(".wraper").css({overflow: "visible"});
    }
});


// 一个经纪人
var oneAgentMap = {
    liNode: ".g_nav_agent_item",
    parentNode: ".g_nav_agent_view",

    init() {
        this.onEvent();
    },
    onEvent() {
        var that = this;
        if ($(that.parentNode) && $(this.liNode)) {
            $("body " + that.parentNode).on("click", this.liNode, function (e) {
                e.stopPropagation();
                // 业主房源
                if ($(this).data("type") === "yezhu") {
                    var yeZhuTop = $(".owner") && $(".owner").offset() ? $(".owner").offset().top || 0 : 0;
                    yeZhuTop = yeZhuTop > 0 ? yeZhuTop - 10 : yeZhuTop;
                    $("html,body").animate({scrollTop: yeZhuTop+"px"}, 500);
                    if ($(".zixun-app-download")) {
                        $('.zixun-app-download').show();
                    }
                    return;
                }

                that.getPhone($(this).data('phone'), $(this).data("cityid"));
            });
        } 

        if ($(".m-navbar") && $(".g_agent_400")) {
            $("body .m-navbar").on("click", ".g_agent_400", function (e) {
                e.stopPropagation();
            });
        }


        // 全局点击隐藏经纪人弹窗
        $("body").click(function () {
            if($('.g_agent_400')) {
                $('.g_agent_400').hide();
            }
        });
    },

    // 获取400电话
    getPhone(mobile, cityId) {
        if (!mobile || !cityId) {
            return;
        }

        if ($('.g_agent_400 .g_agent_400_cont .g_agent_400_phone').text()) {
            $('.g_agent_400').show();
            return;
        }

        this.get400Phone(mobile, cityId, function (data) {
            $('.g_agent_400 .g_agent_400_cont .g_agent_400_phone').text(data);
            $('.g_agent_400').show();
        });
    },
    // 获取400电话 api
    get400Phone(mobile, cityId, callback) {
        callback = callback || function () {};
        if (!mobile || !cityId) {
            return;
        }

        $.ajax({
            data: {
                mobile: mobile,
                cityId: cityId
            },
            url: '/home/Sale/getNormalBroker400',
            success: function (data) {
                if (!!data) {
                    data = data.replace(',', ' 转 ');
                    callback(data);
                    return;
                }
                
                callback("");
            }
        });
    }
};

// 多个导航条经纪人
var navAgentMap = {
    parentNode: ".g_nav_agent_view",
    liNode: ".g_nav_more_agent_img_view",
    infoNode: ".g_nav_agent_ul",
    currentIndex: -1,

    init() {
        this.onEvent();
    },
    // 绑定需要的事件
    onEvent() {
        var that = this;
        // 动态显示切换按钮
        if ($(that.parentNode) && $(this.liNode)) {
            $("body " + that.parentNode).on("click", this.liNode, function (e) {
                e.stopPropagation();
                var mobile = $(this).data('phone') || "";
                var cityId = $(this).data("cityid") || "";
                var index = $(this).index();
                if (that.currentIndex === index) return;

                that.upAgentTcInfo(mobile, cityId, index, function () {
                    that.currentIndex = index;
                    that.setCurrentAgent();
                    mySwiperMap.isOtherMapEvent = true;
                    mySwiperMap.currentIndex = index;
                    mySwiperMap.init();
                });
            });
        }

        // 全局点击隐藏经纪人弹窗
        $("body").click(function () {
            $(that.infoNode).hide();
            that.currentIndex = -1;
            that.setCurrentAgent();
        });
    },

    // 如果有400 则更新弹窗信息
    upAgentTcInfo(mobile, cityId, index, callback) {
        var that = this;
        callback = callback || function () {};
        if (!mobile || !cityId) {
            callback("");
            return;
        }

        if ($(".g_nav_agent_ul_left").eq(index).find(".g_nav_agent_cont_phone").text()) {
            var haveData = $(".g_nav_agent_ul_left").eq(index).find(".g_nav_agent_cont_phone").text();
            $(".agent_ul_has_400").eq(index).show();
            $(".agent_ul_no_400").eq(index).hide();
            $(".g_nav_agent_ul_left").eq(index).find(".g_nav_agent_cont_phone").text(haveData);
            $(".g_nav_agent_ul_left").eq(index).find(".g_nav_agent_cont_phone").css({"font-size": "14px"});
            callback(haveData);
            return;
        }

        oneAgentMap.get400Phone(mobile, cityId, function (data) {
            if(!data) {
                if (index> 0) {
                    $(".agent_ul_no_400").show();
                } else {
                    $(".agent_ul_no_400").eq(index).show();
                    $(".agent_ul_has_400").eq(index).hide();
                }
                callback(data);
                return;
            }

            if (index > 0) {
                $(".agent_ul_has_400").show();
            } else {
                $(".agent_ul_no_400").eq(index).hide();
                $(".agent_ul_has_400").eq(index).show();
            }
            $(".g_nav_agent_ul_left").eq(index).find(".g_nav_agent_cont_phone").text(data);
            $(".g_nav_agent_ul_left").eq(index).find(".g_nav_agent_cont_phone").css({"font-size": "14px"});
            callback(data);
        });
    },

    setCurrentAgent() {
        var that = this;
        var zIndex = 35;
        for (var i = 0;i<$(that.liNode).length;i++) {
            zIndex -= 5;
            if (i === that.currentIndex) {
                $(that.liNode).eq(i).css({
                    "z-index" : 50,
                    "-webkit-transform": "scale(1.25)",
                    "-moz-transform": "scale(1.25)",
                    "-ms-transform": "scale(1.25)",
                    "-o-transform": "scale(1.25)",
                    "transform": "scale(1.25)"
                });
                continue;
            }

            $(that.liNode).eq(i).css({
                "z-index" : zIndex,
                "-webkit-transform": "scale(1)",
                "-moz-transform": "scale(1)",
                "-ms-transform": "scale(1)",
                "-o-transform": "scale(12)",
                "transform": "scale(1)"
            });
        }
    }
};

// 自定义swiper
var mySwiperMap = {
    viewNode: ".g_nav_agent_ul",
    parensNode: ".g_nav_agent_ul_view",
    leftChangeNode: ".f_agent_before_view",
    rightChangeNode: ".f_agent_after_view",
    liNode: ".g_nav_agent_ul_left",
    currentIndex: 0,
    liInfoMap: {height: 90, width: 305},
    isOnEventReady: false,
    isOtherMapEvent: false,  // 其他事件

    init() {
        var that = this;
        if (!$(that.parensNode)) return;

        setTimeout(function () {
            that.upLiNodeInfo();
            that.onEvent();
            that.changeIndex();
            $(that.viewNode).show();
        }, 100);
    },
    upLiNodeInfo() {
        var that = this;
        var width = 0, height = 0;
        for (var i = 0;i<$(that.liNode).length;i++) {
            if (width < $(that.liNode).eq(i).width()) {
                width = $(that.liNode).eq(i).width();
            }
            if (height < $(that.liNode).eq(i).height()) {
                height = $(that.liNode).eq(i).height();
            }
        }
        that.liInfoMap["height"] = height;
        that.liInfoMap["width"] = width;
        if (height < 90) {
            that.liInfoMap["height"] = 90;
        }
        if (width < 305) {
            that.liInfoMap["width"] = 305;
        }
        $(that.parensNode).width(that.liInfoMap["width"]*$(that.liNode).length);
        $(that.parensNode).height(that.liInfoMap["height"]);
        $(that.viewNode).width(that.liInfoMap["width"]);
        $(that.viewNode).height(that.liInfoMap["height"]);
    },

    // 绑定需要的事件
    onEvent() {
        var that = this;
        if (that.isOnEventReady) return;

        that.isOnEventReady = true;
        that.offEvent();
        // 动态显示切换按钮
        $("body").on("mouseover", this.viewNode, function () {
            that.isOtherMapEvent = false;
            that.upNextShow();
        });
        $("body").on("mouseout", this.viewNode, function () {
            $(that.leftChangeNode).hide();
            $(that.rightChangeNode).hide();
        });

        if ($(that.leftChangeNode)) {
            // 左侧按钮点击事件
            $("body " + that.viewNode).on("click", that.leftChangeNode, function (e) {
                e.stopPropagation();
                that.changeIndex(that.currentIndex - 1);
            });
            // 右侧按钮点击事件
            $("body " + that.viewNode).on("click", that.rightChangeNode, function (e) {
                e.stopPropagation();
                that.changeIndex(that.currentIndex + 1);
            });
        }
        if($(that.viewNode)) {
            $("body").on("click", that.viewNode, function (e) {
                e.stopPropagation();
            });
        }
    },
    offEvent() {
        if ($(this.viewNode)) {
            $(this.viewNode).off("mouseover");
            $(this.viewNode).off("mouseout");
        }
        if ($(this.viewNode) && $(this.leftChangeNode) && $(this.rightChangeNode)) {
            $("body " + this.viewNode + " " +  this.leftChangeNode).off("click");
            $("body " + this.viewNode + " " +  this.rightChangeNode).off("click");
        }
    },

    // 点击切换事件
    changeIndex(index) {
        index = index === undefined ? this.currentIndex : index;
        if (index < 0 || $(this.liNode).length - 1 < index) return;

        this.setLiNodeTransform(index);
        this.currentIndex = index;
        navAgentMap.currentIndex = index;
        navAgentMap.setCurrentAgent();
    },
    setLiNodeTransform(index) {
        var that = this;
        index = index === undefined ? this.currentIndex : index;
        that.upNextShow(index);
        $(that.parensNode).animate({
            left: -that.liInfoMap.width * (index)
        });
    },
    upNextShow(index) {
        if (this.isOtherMapEvent)  return;

        index = index === undefined ? this.currentIndex : index;
        if (index === 0) {
            $(this.leftChangeNode).hide();
        }else {
            $(this.leftChangeNode).show();
        }
        if (index >= $(this.liNode).length - 1) {
            $(this.rightChangeNode).hide();
        } else {
            $(this.rightChangeNode).show();
        }
    }
};

$(function () {
    navAgentMap.init();
    oneAgentMap.init();
});
