$(function (){
var mySwiper1= new Swiper(".swiper-container1",{
        // loop : true,
        loopedSlides:4,
        autoplay:5500,
        autoplayDisableOnInteraction : false,
        // 如果需要分页器


            pagination : '.swiper-pagination',
            paginationType : 'custom',
            paginationCustomRender: function (swiper, current, total) {
                return current + ' / ' + total;
            },
    });




var mySwiper1= new Swiper("#swiper1",{
    loop : true,
    loopedSlides:4,
    autoplay:5500,
    autoplayDisableOnInteraction : false,
    // 如果需要分页器
    // pagination: '.swiper-pagination',
    slidesPerView :"auto"
});

var mySwiper = new Swiper ('.y_lphomepc_cent_list .swiper-container2', {
    loop : true,
    loopedSlides:4,
    autoplay:5500,
    // 如果需要分页器
    pagination: '.swiper-pagination',
    // 如果需要前进后退按钮
    prevButton:'.swiper-button-prev',
    nextButton:'.swiper-button-next',
    slidesPerView :"auto"
})


})



// 报名切换
var mySwiper = new Swiper('#wcon',{
    // loop : true,
    // spaceBetween: 20,
    // centeredSlides: true,
    slidesPerView: 'auto',
    touchRatio: 0.5,
    slideToClickedSlide: true
})




// var m_Huxing_lunbo = new Swiper('.m_zx_lunbo', {
//     loop : true,
//     spaceBetween: 10,
//     centeredSlides: true,
//     slidesPerView: 'auto',
//     touchRatio: 0.5,
//     slideToClickedSlide: true
// });


// $('.m_lunbo_box ul li').on('click',function(){
//   var _value = $(this).attr('value');
//   var _hid = $(this).attr('hid');
//   var _mindex = $(this).attr('mindex');
  
//   window.location='/house/pvimage/'+_hid+'?album_id='+_value+'&mindex='+_mindex+'&hid='+_hid+'';

// })


// 楼盘首页地图
$(function(){
    //获取周边配套
    $('.y_lpdt_list ul li a').on('click',function(){
        $('.y_lpdt_list ul li a').removeClass('on');
        $(this).addClass('on');
        var _data = $(this).find('p.y_text').text(); //选择中的内容

        var _longitude =$('#y_lpmap').attr('data-jwd'); //获取经纬度

        var pintx = _longitude.split(',')[0];
        var pinty = _longitude.split(',')[1];
        _longitude = new BMap.Point(pintx,pinty);
        doSearch(_data,_longitude);//调用地图弹窗

    })

});

// 百度地图API功能
var map = new BMap.Map("y_lpmap");
var _lTude =$('#y_lpmap').attr('data-jwd');         //获取经纬度
var _lJg =$('#y_lpmap').attr('data-jg');         //获取楼盘价格
var _lTitle =$('#y_lpmap').attr('data-title');         //获取楼盘标题

var pintx = _lTude.split(',')[0];
var pinty = _lTude.split(',')[1];
_lTude = new BMap.Point(pintx,pinty);

map.centerAndZoom(_lTude, 15);
map.enableScrollWheelZoom(); //启用滚轮放大缩小,默认禁用

// 复杂的自定义覆盖物
function ComplexCustomOverlay(_lTude, text, mouseoverText){
    this._point = _lTude;
    this._text = text;
    this._overText = mouseoverText;
}
ComplexCustomOverlay.prototype = new BMap.Overlay();
ComplexCustomOverlay.prototype.initialize = function(map){
    this._map = map;
    var div = this._div = document.createElement("div");
    div.style.position = "absolute";
    div.style.zIndex = BMap.Overlay.getZIndex(this._point.lat);
    div.style.backgroundColor = "#fff";
    div.style.border = "1px solid #e1e1e1";
    div.style.color = "666";
    // div.style.height = "18px";
    div.style.padding = "5px 10px";
    // div.style.lineHeight = "10px";
    div.style.whiteSpace = "nowrap";
    // div.style.MozUserSelect = "none";
    div.style.fontSize = "14px"
    var span = this._span = document.createElement("span");
    div.appendChild(span);
    span.appendChild(document.createTextNode(this._text));
    var that = this;

    var arrow = this._arrow = document.createElement("div");
    arrow.style.background = "url(../../image/ico_map1.png) no-repeat center";
    arrow.style.backgroundSize = "100%";
    arrow.style.position = "absolute";
    arrow.style.width = "20px";
    arrow.style.height = "28px";
    arrow.style.top = "30px";
    arrow.style.left = "25px";
    arrow.style.overflow = "hidden";
    div.appendChild(arrow);

    div.onmouseover = function(){
        this.style.backgroundColor = "#6BADCA";
        this.style.borderColor = "#3487ab";
        this.getElementsByTagName("span")[0].innerHTML = that._overText;
        arrow.style.backgroundPosition = "0px -20px";
    }

    div.onmouseout = function(){
        this.style.backgroundColor = "#EE5D5B";
        this.style.borderColor = "#BC3B3A";
        this.getElementsByTagName("span")[0].innerHTML = that._text;
        arrow.style.backgroundPosition = "0px 0px";
    }

    map.getPanes().labelPane.appendChild(div);

    return div;
}
ComplexCustomOverlay.prototype.draw = function(){
    var map = this._map;
    var pixel = map.pointToOverlayPixel(this._point);
    this._div.style.left = pixel.x - parseInt(this._arrow.style.left) -13 + "px";
    this._div.style.top  = pixel.y - 45 + "px";
}
var txt = _lTitle, mouseoverTxt = txt + " " + _lJg ;
var myCompOverlay = new ComplexCustomOverlay(_lTude, _lTitle ,mouseoverTxt);

map.addOverlay(myCompOverlay);

//map展现结果的地图实例
//autoViewport检索结束后是否自动调整地图视野,false 不调整地图视野
var local = new BMap.LocalSearch(map,{renderOptions:{map:map,autoViewport:true}});

//地址检索
function doSearch(Odata,Opoint){
    var address = Odata;
    local.searchNearby(address,Opoint);
}


$(function(){
    $('.y_centerpc').find('img').each(function(){
        var $that = $(this);
        var _alt = $that.attr('alt');
        if(_alt != 'code'){
            $that.removeAttr('width');
            $that.removeAttr('height');
            $that.css({'display':'block','width':'100%','height':'auto'});
        }

    })
    $('.y_lphomejg p.y_yxq span').text(yxqtime);
})




/*
*  楼盘预售许可证弹窗
*  
*/
$(function(){
    var lic_id;  //为了这些变量在其它地方用;
    $('.y_ckysz').on('click',function(){
        var $that = $(this);
        var height =  $('.y_licence').outerHeight();
        var width =  $('.y_licence').outerWidth();
        CreatePopLayerDiv2(width,width,'/public/licence');
        $('#offDiv1').css({'top':height+'px'}).animate({top:'20%'})
        // 向弹窗传数据
        parent.lic_id = $that.attr('data-id');                        //把楼盘名称传向父级
    })

    // 看房定制数量修改
    var random = Math.floor(Math.random()*150+101);
    // console.log(random)
    $('.y_lpkfdz_dzrs span em').html(random)



    // 房贷计算户型面积处理
    $('.info_xllist li').each(function(){
        var acreage = $(this).attr("size");
        
        
        if(acreage.indexOf('m') != -1){

            var akx = acreage.split("m");
            $(this).attr("size",parseInt(akx[0]));

            if(akx[0].indexOf('-') != -1){
                var ak = acreage.split("-");
                $(this).attr("size",parseInt(ak[0]));
            }
        }
        if(acreage.indexOf('-') != -1){
            var ak = acreage.split("-");
            $(this).attr("size",parseInt(ak[0]));
        }

    })

    //房贷参考
   var _listhtml = $('.info_xllist li').eq(0).html();   
   $('.info_xl span').html(_listhtml);   //默认第一个

   var doughnutData;
   var _jiage = $('.jiage').html();  //楼盘价格
   var unit = $('.unit').html()   //价格单位

   var _Size = $('.info_xllist li').eq(0).attr('Size');   //默认面积

   // 当面积内容出来 “约” 时的处理
   _Size = (_Size.indexOf('约') != -1) ?  _Size.slice(_Size.indexOf('约')+1) : _Size;


   var price = (unit.indexOf('万') != -1) ?  _jiage : Math.ceil((_jiage * _Size) /10000);       //计算总价

   if(!(unit.indexOf('万') != -1)){
        $('body').on('click','.info_xl',function(){
            $('.info_xllist').toggle();
       })
   }else{
        $('.info_xl').css({"background":"#fff"});
        $('.info_xl').html('主力户型');
   }

   Calculation();

   
   $('.info_xllist li').on('click',function(){
       _Size = $(this).attr('Size');  //面积
       _Size = (_Size.indexOf('约') != -1) ?  _Size.slice(_Size.indexOf('约')+1) : _Size;     // 当面积内容出来 “约” 时的处理
       _listhtml = $(this).html(); 
        $('.info_xl span').html(_listhtml);   

       price = Math.ceil((_jiage * _Size) /10000)
       // console.log(price);
       $('.info_xllist').hide();
       Calculation();
   })


function Calculation(){

        var cal = new Calculator();

        var firstPay=Math.round(price * 0.3 * 100) / 100;
        var biz=Math.round((price - firstPay) * 100) / 100;
        var data1 = cal.loanResult({
            type: 2, //商贷
            total:price,firstPay: firstPay,acc:0,biz:biz,rate:0,year: 20,calType:2
        }, 2);    //本金

        $(".perMonth").text(Math.round(data1.perMonthPay*10000*100)/100);
        $("#totalPay").text(price);
        $("#firstPay").text(firstPay);
        $("#loanPrice").text(biz);
        $("#interset").text(data1.interestPay);
         
        doughnutData = [{
            value: firstPay,
            color: "#007AF5"
        },{
            value: biz,
            color: "#FFA245"
        },{
            value: Math.round(data1.interestPay * 100) / 100,
            color: "#62BE4B"
        }];
        
       
}

 var myDoughnut = new Chart(document.getElementById("canvas_fdck").getContext("2d")).Doughnut(doughnutData, {
            animation: true,
            animationEasing : "easeOutQuart",
            height:145,
            width:145,

        });


})
//创建一个弹出层,width 宽度,height 高度,url
function CreatePopLayerDiv2(width,height,url){
    var Iheight=$(window).outerHeight(); 
    var Iwidth =$(window).outerWidth(); 
    var heights = height || 300; 
    var widths = width || 500; 
    var Oheight= (Iheight -heights) / 2; 
    var Owidth = (Iwidth - widths) /2;
    var div ='<div id="InDiv1" style="width:'+Iwidth+'px;height:'+Iheight+'px;background:rgba(0,0,0,0.6);position:fixed;z-index:10000;top:0;left:0;">';
        div+='<div id="offDiv1" style=" width:100%; height:100%; left:0px; top:30%; position:fixed;z-index:100003;">';
        div+='<div id="Content1"></div>';
        div+='</div>';
        div+='</div>';
    $(document.body).append(div); 
    if(url != ""){ 
        $("#Content1").load(url); 
    } 
} 
//移除弹出层 
function RemoveDiv1(){
    $("#InDiv1").remove();
    $("#offDiv1").remove();
} 
function btnCloses1(){ 
    RemoveDiv1(); 
}


// 限制时间
function getNextMonth(date) {
    var arr = date.split('/');  
    var year = arr[0]; 
    var month = arr[1]; 
    var day = arr[2];  
    var days = new Date(year, month, 0);  
    days = days.getDate(); 
    var year2 = year;  
    var month2 = parseInt(month) + 2;  
    if (month2 > 13) {  
        year2 = parseInt(year2) + 1;
        if (parseInt(month)==11) {
            month2 = 1;
        }else if (parseInt(month)==12) {
            month2 = 2;
        };
    }  
    var day2 = day;  
    var days2 = new Date(year2, month2, 0);  
    days2 = days2.getDate();  
    if (day2 > days2) {  
        day2 = days2;  
    }  
    if (month2 < 10) {  
        month2 = '0' + month2;  
    }
    var t2 = year2 + '/' + month2 + '/' + day2;  
    return t2;  
} 
var myDate = new Date;
var year = myDate.getFullYear(); 
var yue = myDate.getMonth()+1;
if (yue<10) {
    yue= '0' + yue; 
};

var time = year+'/'+yue+'/01';
var time_yxq= year+'/'+yue+'/01-'+getNextMonth(time);
var yxqtime=time+'-'+getNextMonth(time);


// $('.w-commonality span').html(time_yxq); //制限时间
// $('.sell_conter_right .date').html('有效期 | '+ time_yxq);


// 2018-12-8 --------------
$(function(){




    // 用户点评

    var  obj = new Object();

    // 马上提交 
    $('.remark-btn').on('click',function(){
        var _this = $(this);
        var txt = _this.siblings('textarea[name="content"]').val();

        if(txt != ''){
            obj.content = txt;
            $('.w_up_ap').fadeIn();
            $('.w_up_ap').animate({top:"50%"});
            $('.cover').fadeIn();
        }else{
            var M = {};
            if(M.dialog1){
                return M.dialog1.show();
            }
            M.dialog1 = jqueryAlert({
                'content' : '点评内容不能为空!',
                'closeTime' : 2000,
            })
        }

    })

    // 确定按钮
    $('.w_sbtn').on('click',function(){

        var hid = $('.w_up_info').find('input[name="hid"]').val();
        var tel = $('.w_up_info').find('input[name="mobile"]').val();
        tel = FilterHTMLTag(tel);
        if(PhoneVerification(tel)){
            obj.mobile = tel;
            obj.hid = hid;

            DataAjax(obj);    //提交数据
        }else{
            var M = {};
            if(M.dialog1){
                return M.dialog1.show();
            }
            M.dialog1 = jqueryAlert({
                'content' : '请输入正确的电话码!',
                'closeTime' : 2000,
            })
        }
        
    })
    /* 过滤代码标签 */
    function FilterHTMLTag(htmlStr){
        var msg = htmlStr.replace(/<\/?[^>]*>/g, ''); //去除HTML Tag
        return msg;
    }
    /* 电话验证 */
    function PhoneVerification(tel) {
        var pattern = /(13\d|14[57]|15[^4,\D]|17[678]|18\d)\d{8}$|170[059]\d{7}$/;
        return pattern.test(tel);
    }
    // 用户点击关闭按钮
    $('.cover').on('click',function(){
        $('.w_up_ap').fadeOut();
        $('.w_up_ap').animate({top:"-100%"});
        $(this).fadeOut();
    })

    $('.ws_up_cls').on('click',function(){
        $('.w_up_ap').fadeOut();
        $('.w_up_ap').animate({top:"-100%"});
        $('.cover').fadeOut();
    })

    // 数据提交 
    function DataAjax(data){
        $.ajax({
            url:'/house/remarkfrom',
            type:'post',
            data:data,
            dataType:"json",
            success:function(data){
                if(data.code == 200){
                    var M = {};
                    if(M.dialog1){
                        return M.dialog1.show();
                    }
                    M.dialog1 = jqueryAlert({
                        'content' : '提交成功!',
                        'closeTime' : 2000,
                    })

                    $('.w_up_ap').fadeOut();
                    $('.w_up_ap').animate({top:"-100%"});
                    $('.cover').fadeOut();
                }
            }
        });
    }
})

                                
$(window).scroll(function (){
    var st = $(this).scrollTop();
    if(st >250){
        $('.y_lpindexnav').show();
        // $('.y_header').hide();
    }else{
        $('.y_lpindexnav').hide();
        // $('.y_header').show();
    }
});                               


var  Homeurl=window.location.href
$(function(){
    var telurl=$('.y_modtel .y_modtel_text p.y_call span').html();
    if(Homeurl.indexOf("?source=pc")!=-1){
        return window.location.href = 'tel:'+telurl;
    };
})






// 开发商弹窗

var ster = 0;

$(window).scroll(function (){
    ster = $(this).scrollTop();
// console.log(ster);
});

var _top = '';

$('.m_Article_click a').on('click',function(){
    $('.Developers_tc').fadeIn(80);
    $('.Developers_tx').animate({bottom:'0%'},400);

    _top = $(window).scrollTop();   // 弹窗开启  遮罩层以外的东西不移动
    $('body').css("top",-ster+"px");
    $('body').addClass('add');
    // console.log(_top);

  $('.m_lpdescribe_text').scrollTop(0);
})



$('.Developers_zhez').on('click',function(){

    $('.Developers_tx').animate({bottom:'-88%'},400);

    setTimeout(function(){
        $('.Developers_tc').fadeOut(80);
    },400)

    $('body').removeClass('add');//去掉给body的类
    $('body').attr('style','');
    $(window).scrollTop(_top);//设置页面滚动的高度,如果不设置,关闭弹出层时页面会回到顶部。
})

$('.Developers_gb').on('click',function(){

    $('.Developers_tx').animate({bottom:'-88%'},400);

    setTimeout(function(){
        $('.Developers_tc').fadeOut(80);
    },400)


    $('body').removeClass('add');//去掉给body的类
    $('body').attr('style','');
    $(window).scrollTop(_top);//设置页面滚动的高度,如果不设置,关闭弹出层时页面会回到顶部。
})




var _imgid ="";

// 相册
$('.m_lunbo_box ul li').on('click',function(){
   $('#LXB_CONTAINER_SHOW').hide();
   $('#LRdiv3').attr('class','none');
    _imgid = $(this).attr('data-hid')-1;// 索引第几张图片
    console.log(_imgid);
    $('.m_swiper_xc').show();
    StitchingData(_imgid);
})


// 相册
function StitchingData(imgid){
  lpxc=new Array();   //定义数组存放图片
   $('.m_lunbo_box ul li').each(function(){
       var _src = $(this).find('img').attr('src');
       lpxc.push(_src);
   })
   lpindex_xc(lpxc , imgid);
}



// 相册
function lpindex_xc(data , imgid){
    var html = '';
  console.log(imgid);
    html+=  '<div class="m_tcswiper_box">';

    html+='<div class="m_swiper_head">';
    html+='<div class="m_swiper_fh"><img src="/image/v2/lpindex3.png" alt=""></div>';
    html+='<div class="swiper-pagination" id="swiperzs"></div>';
    html+='<div class="m_swiper_qb"><a href="/house/album/1662">全部图片</a></div>';
    html+='</div>';

    // html+=  '<div class="m_swiper_gb"><img src="/image/guanbi.png" alt=""></div>';
    html+=  '<div class="m_swiper">';
    html+=  '<div class="m_swiper_ul swiper-wrapper">';


    $.each(data, function (i, data) {
        html+=  '<div class="m_swiper_li swiper-slide">';
        html+=  '<div class="swiper-zoom-container">';
        html+=  '<img src="'+data+'">';
        html+=  '</div>';
        html+=  '</div>';
    });


    html+=  '</div>';
    html+=  '<div class="swiper-button-prev"></div>';
    html+=  '<div class="swiper-button-next"></div>';
    html+=  '</div>';

    html+=  '</div>';


     $('.m_swiper_ajax').html(html);

    // 相册插件
    var swipercx = new Swiper('.m_swiper', {
        // loop : true,
        zoom: true,
        // autoHeight: true,
        initialSlide :imgid,
        nextButton: '.swiper-button-next',
        prevButton: '.swiper-button-prev',

        pagination : '.swiper-pagination',
        paginationType : 'custom',
        paginationCustomRender: function (swiper, current, total) {
            return current + ' / ' + total;
        },

        // onInit: function(swiper){
        //    $('#swiperzs').hide();
        // },
        observer:true,//修改swiper自己或子元素时,自动初始化swiper

       // onSlideChangeEnd: function(){
       //     $('#swiperzs').show();
       //  },


    });
    

    // 关闭相册
    $('.m_swiper_fh').on('click',function(){
        $('#LXB_CONTAINER_SHOW').show();
        $('.m_swiper_xc').hide();
    })

}



if($('.m_pm').attr('data-text') != '暂无资料'){
    jQuery(".m_pm").slide({mainCell:".bd ul",autoPlay:true,effect:"leftMarquee",interTime:50,trigger:"click"});
}




// 点评电话加密
$('.remark-list ul li').each(function(){
    var _tel = $(this).find('p em span').attr('tel-data').replace(/(\d{3})(\d{4})(\d{4})/,"$1****$3");
    $(this).find('p em span').html(_tel);
})





// var _dataid = $('.m_hq li.cur').attr('dataid');
//demo示例六 通过id调取    底部菜单插件
$('#demo05').navbarscroll({
    defaultSelect:0,
    scrollerWidth:6,
    fingerClick:1,
    endClickScroll:function(obj){
        // console.log(obj.text())
    }
});