// 户型、详情 ----------------------------------------------------
// $('.qhshow[qhid="'+2+'"]').show(); //默认户型展示



var height= ''; //处理户型模块的高度

$('.m_album_title span').on('click',function(){
	$('.qhshow').hide();
	var _qhid = $(this).attr('qhid');
	$('.qhshow[qhid="'+_qhid+'"]').show();
	$(this).attr('class','on').siblings().attr('class','');

	height = $('.m_album_r_lsit').height() +20;//处理户型模块的高度
    $('.m_hxswitch').height(height);
   
})	
$('.m_album_title span').eq(0).click(); //默认选中第一个户型



// 户型ajax
$('.m_album_l_title span').on('click',function(){
      var _hid = $(this).attr('hid');
	  var _value = $(this).attr('value');
	  $(this).attr('class','on').siblings().attr('class','');
	  // console.log(_hid);
	  // console.log(_value);

	  var html = '';
	  $.ajax({
	    url: "requesthousetype",
	    type: "GET",
	    data:{id:_hid,value:_value},    //传ID
	    dataType: "json",
	    success: function(data) {//请求成功完成后要执行的方法

	    	if(data.code == 200){

		       $.each(data.data, function (i, data) {    //左边楼盘列表

					html+='<div class="m_lsitImg c"  data-index="'+i+'" data-src="'+data.img+'">';
					html+='<img src="'+data.img+'" data-lazy-src="" alt="">';
					html+='<div class="m_lsittext">';
					html+='<em>'+data.title+'</em>';
					html+='<span>'+data.indoor_info+'</span>';
					if(data.area == '' || data.area == null){
                        html+='<i>建筑面积:暂无资料</i>';
					}else{
                        html+='<i>建筑面积:'+data.area+'</i>';
					}
					html+='</div>';
					html+='</div>';

		       });

			   $(".m_album_r_lsit").html(html);

			   height = $('.m_album_r_lsit').height() + 20;
    		   $('.m_hxswitch').height(height);
			  

				var _imgid;

				// 相册
				$('.m_album_r_lsit .m_lsitImg').on('click',function(){
				    _imgid = $(this).attr('data-index');// 索引第几张图片
				    // console.log(_imgid);
				    $('.m_swiper_xc').show();
				    StitchingData(_imgid);
				})

			}
		}


	 });



})	
$('.m_album_l_title span').eq(0).click(); //默认选中第一个户型


$(function(){
	// 处理资讯详情图片变形问题
	$('.m_xqswitchtext').find('img').each(function(){
		var $that = $(this);
		var _alt = $that.attr('alt');
		if(_alt != 'code'){
			if(_alt != 'zixun'){
				$that.removeAttr('width');
				$that.removeAttr('height');
				$that.css({'display':'block','width':'100%','height':'auto'});
			}

		}
		// 咨询图标大小修改
		if (_alt == 'call') {
			$that.css({'display':'inline-block','width':'80px','height':'auto'});
		};

	})

})
// 公众号展开收起------------------------------------------------------------------------------
$('.sweepcode_title .zk').on('click',function(){
	$('.sweepcode_switch .gzh').show();
	$('.sweepcode_switch .zb').hide();
	$(this).hide();
	$('.sweepcode_title .sq').show();
})
$('.sweepcode_title .sq').on('click',function(){
	$('.sweepcode_switch .gzh').hide();
	$('.sweepcode_switch .zb').show();
	$(this).hide();
	$('.sweepcode_title .zk').show();
})



// 户型弹窗------------------------------------------------------------------------------

function StitchingData(imgid){
  lpxc=new Array();   //定义数组存放图片
   $('.m_album_r_lsit .m_lsitImg ').each(function(){
       var _src = $(this).attr('data-src');
       lpxc.push(_src);
   })
   lpindex_xc(lpxc , imgid);
   // console.log(lpxc)
}


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

    html+='<div class="m_swiper_head">';
    html+='<div class="m_swiper_fh"><img src="./image/lpindex3.png" alt=""></div>';
    html+='<div class="swiper-pagination" id="swiperzs"></div>';
    html+='</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',
        lazyLoading : true,
        lazyLoadingInPrevNext : true,

        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(){
        $('.m_swiper_xc').hide();
    })

}
// --------------------------------------------------------------------------

jQuery(".push_pm").slide({mainCell:".bd ul",autoPlay:true,effect:"leftMarquee",interTime:40,trigger:"click"});



// 评论-----------------------------------------------------------------------

// 聊天记录置底
function Bottomsetting(){
	$('#j-comments').scrollTop($('#j-comments')[0].scrollHeight);
}


// 发送按钮
$('.send-button').on('click',function(){
	var _textarea = $('.bottom-bar textarea').val();  //获取输入信息
	// console.log(_textarea);
})




// $(function(){

//     var video = document.getElementById('myVideo');
//     video.addEventListener("timeupdate",function(){
//         var timeDisplay;
//         //用秒数来显示当前播放进度
//         timeDisplay = Math.floor(video.currentTime);
//         // console.log(Math.floor(video.currentTime))
//         //当视频播放到 4s的时候做处理
//         if(timeDisplay == 4){
//             //处理代码
//             console.log('播放了4秒');
//             video.pause();
//         }
//     },false);
// });



//处理视频播放图标----------------------------------------------------
// $('.m_video_img').on('click',function(){  
//     var _video = document.getElementById("myVideo");
//     // myVideo.play();   //点击图标视频播放
//     $('.m_video_sp').attr('controls','controls');    //点击 显示默认的控件
//     $(this).hide();
// })



//视频播放js
var cubicle = "";

$(function(){
/*-----------------------------------音频--------------------------------------------*/ 
    // 音频播放
    var audio = document.getElementById("myVideo");
    var btn = document.getElementById("live_id");
    var musitime= 0;
    
    if (btn) {
        btn.onclick = function () {
        $('.m_video_img').hide();
        cubicle = $('#live_id').attr('data-boole');
        // console.log(cubicle)
        if (audio.paused) { //判断当前的状态是否为暂停,若是则点击播放,否则暂停
            if(musitime >= 300 && cubicle == "true"){
                AudioWind();    //语音讲房报名窗口
                return false;
            }
             audio.play();
             watchMusicTime()
         }else{
            audio.pause();
         }
        }
    };


    // // 获取全部语音
    $('.y_reduced2_bg , .y_reduced2_gb a').on('click',function(){
        $('.y_reduced2').hide();
        $('.m_form_button2').removeClass('wcontrol')
        $('.y_reduced2_bg').hide();

        $('.m_videobj').hide();
        $('.m_video_sp').show();
    })

    // // 语音讲房报名窗口
    function AudioWind(){
        $('.y_reduced2').show();
        $('.y_reduced2_bg').show();

        $('.m_videobj').show();
        $('.m_video_sp').hide();
    }
    
    

    //监听音乐实时播放的时间
    function watchMusicTime(){
        let _this = this;
        //监听播放时间
        // let musicDom = document.getElementsByTagName('audio')[0];//获取Audio的DOM节点
        let musicDom =audio;//获取Audio的DOM节点

        //使用事件监听方式捕捉事件
        musicDom.addEventListener("timeupdate",function(){//监听音频播放的实时时间事件
            // console.log(musicDom.duration)//播放时间
            let timeDisplay;
            //用秒数来显示当前播放进度
            timeDisplay = Math.floor(musicDom.currentTime);//获取实时时间
            musitime = timeDisplay;
            // console.log(timeDisplay)

            // 处理 10秒内试听
            // console.log(cubicle)
            if(timeDisplay >= 300 && cubicle == "true"){
                audio.pause();
                AudioWind();    //语音讲房报名窗口
            }
            //处理时间
            //分钟
            let minute = timeDisplay / 60;
            let minutes = parseInt(minute);
            if (minutes < 10) {
                minutes = "0" + minutes;
            }
            //秒
            let second = timeDisplay % 60;
            let seconds = Math.round(second);
            if (seconds < 10) {
                seconds = "0" + seconds;
            }
            let shun= minutes+":"+seconds;//将实时时间存储到vuex中
            // console.log(shun)
            // console.log(_this.$store.state.realMusicTime);
        },false);
    }
    /*-------------------------------------------------------------------------------*/   
    

    /*-------------------------------------------------------------------------------*/   
// 获取验证码 


    var domeid=$('#sxbmdata').attr('data-id');
    if (domeid!='' && domeid!=null ) {
        $('#sxbmdata').attr('data-type','false')
        $('#live_id').attr('data-boole','false')
    }else{
        $('#sxbmdata').attr('data-type','true')
        $('#live_id').attr('data-boole','true')
    }

    var urlstr = window.location.href;
    // var matchdata = urlstr.match(/\.com(\/\w+)/)[1];

    var phoneReg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;//手机号正则 
    var count = 60; //间隔函数,1秒执行
    var InterValObj1; //timer变量,控制时间
    var curCount1;//当前剩余秒数

    $('#btnSendCode1').on('click',function(){
        sendMessage1();
    })

    // 提交
    $('#buttom_m').on('click',function(){
        var phoneReg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;//手机号正则
        var phone    = $.trim($('#phone1').val());
        var code    = $.trim($('#code').val());
        if (!phoneReg.test(phone)) {
            // alert(" 请输入有效的手机号码");
            $('.zhanghao b.hint-text').show();
            $('#phone1').addClass('on');
            return false;
        }else{
            $('.zhanghao b.hint-text').hide();
            $('#phone1').removeClass('on');
        }
        if (code!='') {
            $('.mima b.hint-text').hide();
            $('#code').removeClass('on');
        }else{
            // alert(data.msg);
            $('.mima b.hint-text').show();
            $('#code').addClass('on');
            return false;
        }
        // alert(password);
        $.ajax({
            type: "POST",
            url: "/home/checkcode",
            data: {mobile:phone,code:code},
            dataType: "json",
            success:function(data){
                if(data.code == 200) {
                    // loginAlert('报名成功!',2000)
                    $('.y_reduced2').hide();
                    $('.y_reduced2_bg').hide();   
                    $('#sxbmdata').attr('data-type','false');
                    $('#live_id').attr('data-boole','false');
                    $('.m_videobj').hide();
                    $('.m_video_sp').show();
                    cubicle='false';
                    $('.buttom_m2').click();
                }else{
                    loginAlert(data.msg,2000)
                    return false;
                }
            }
        });
        PublicAction.AjaxSend(
            {
                CORID:'buttom_m2',                  /*操作ID*/
            }
        );
        
    })



    /*第一*/
    function sendMessage1() {
        curCount1 = count;               
        var phone = $.trim($('#phone1').val());
        if (!phoneReg.test(phone)) {
            $('.zhanghao b.hint-text').show();
            $('#phone1').addClass('on');
            return false;
        }else{
            $('.zhanghao b.hint-text').hide();
            $('#phone1').removeClass('on');
        }
        //设置button效果,开始计时
        $("#btnSendCode1").attr("disabled", "true");
        $("#btnSendCode1").val( '('+ curCount1 + ")秒再获取");
        InterValObj1 = window.setInterval(SetRemainTime1, 1000); //启动计时器,1秒执行一次
        //向后台发送处理数据
        $.ajax({
            type: "POST",
            url: "/home/sendcode",
            data: {mobilephone:phone},
            dataType: "json",
            success:function(data){
                // console.log(data.code);
                if(data.code == 200){
                    //短信成功弹窗
                    loginAlert(data.msg,2000)
                    $('.mima b.hint-text').hide();
                    $('#code').removeClass('on');
                }else{
                    loginAlert(data.msg+',请重新发送!',2000)
                    curCount1 = 0;
                    window.clearInterval(InterValObj1);//停止计时器
                    $("#btnSendCode1").removeAttr("disabled");//启用按钮
                    $("#btnSendCode1").val("重新发送");
                    $('.mima b.hint-text').show();
                    $('#code').addClass('on');
                    return false;
                }
            }
        });
    }
    function SetRemainTime1() {
        if (curCount1 == 0) {                
            window.clearInterval(InterValObj1);//停止计时器
            $("#btnSendCode1").removeAttr("disabled");//启用按钮
            $("#btnSendCode1").val("重新发送");
            $("#btnSendCode1").css('color','#2DB1FB')
        }else {
            curCount1--;
            $("#btnSendCode1").val( '('+ curCount1 + ")秒再获取");
            $("#btnSendCode1").css('color','#999')
        }
    }


    function loginAlert(txt,time){
        /*调用方法*/
        var M = {};
        if(M.dialog1){
            return M.dialog1.show();
        }
        M.dialog1 = jqueryAlert({
            'content' : txt,                //txt 提示内容
            'closeTime' : time,
        })
    }
})