// 过滤模块
function filterTemplateToCols(type) {
	var windowWidth = document.documentElement.clientWidth;
	if(type == "max8") {
		if( windowWidth <= 450 ) return 1;
		if( windowWidth <= 800 ) return 2 ;
		if( windowWidth <= 1000 ) return 3;
		if( windowWidth <= 1200 ) return 4;
		if( windowWidth <= 1600 ) return 5;
		if( windowWidth <= 2000 ) return 7;
		return 8;
	}else if(type == "max6"){
		if( windowWidth <= 1000 ) return 1;
		if( windowWidth <= 1200 ) return 2;
		if( windowWidth <= 1600 ) return 4;
		if( windowWidth <= 1800 ) return 5;
		return 6;
	}else if(type == "max5"){
		if( windowWidth <= 480 ) return 1;
		if( windowWidth <= 1000 ) return 2;
		if( windowWidth <= 1100 ) return 3;
		if( windowWidth <= 1400 ) return 4;
		return 5;
	}else if(type == "max3"){
		if( windowWidth <= 800 ) return 1;
		if( windowWidth <= 1200 ) return 2;
		return 3;
	}else{
		if( windowWidth <= 800 ) return 1;
		if( windowWidth <= 1200 ) return 2;
		if( windowWidth <= 1600 ) return 3;
		return 4;
	}
}

// 获取banner配置
function getBannerConfig(type, parentClass){
	return {
		slidesPerView: filterTemplateToCols(type), // 每次滚动显示3个slides
		slidesPerGroup: 1, // 每次滚动移动1个slide
		spaceBetween: 20, // 每个slide之间的距离
		navigation: {
			nextEl: parentClass + ' .swiper-button-next',
			prevEl: parentClass + ' .swiper-button-prev',
		}
	};
}

// 
function initMethod(){}
// 公用事件
initMethod.prototype.common = function() {
	if ($('.common_bg_template').length <= 0) {
		$("body").append(`<div class="common_bg_template"></div>`);
	}
	function showBgModel(){
		$(".common_bg_template").toggleClass("active");
	}

	// 显示隐藏菜单
	$(".mobile_menu_icon").click(function(){
		showBgModel();
		$(".nav_menu_item").toggleClass("active");
	});
	// 折叠展开菜单
	$(".nav_menu_item").on("click",".drop_menu_arrow_icon",function(){
		$(this).parent().toggleClass("active").siblings().removeClass("active");
	});

	//
	$(".common_bg_template").click(function(){
		showBgModel();
		$(".nav_menu_item").removeClass("active");
		$(".language_select_box").removeClass("active");
	});

	// 搜索事件
	$(".mobile_search").click(function(){
		$(this).parents(".w12_box").addClass("active");
	});
	$(".cancel_btn").click(function(){
		$(this).parents(".w12_box").removeClass("active");
	});
	if($(".index_banner_template").length > 0){
		// banner
		var mySwiper = new Swiper('.index_banner_template', {
			loop: true, // 循环模式选项
			spaceBetween: 10, // 每个slide之间的距离
			autoplay: {
				delay: 4000
			},
			navigation: {
				nextEl: '.index_swiper_banner .swiper-button-next',
				prevEl: '.index_swiper_banner .swiper-button-prev',
			},
			// 如果需要分页器
			pagination: {
				el: '.swiper-pagination',
				clickable: true
			},
			effect : 'coverflow',
			slidesPerView: 3,
			centeredSlides: true,
			coverflowEffect: {
				rotate: 30,
				stretch: 10,
				depth: 60,
				modifier: 2,
				slideShadows : true
			},
		});
		window.addEventListener('resize', function() {
			// 当窗口大小变化时，更新Swiper的布局
			mySwiper.update();
		});
	}
	$(".language_select_box").click(function(event){
		event.stopPropagation();
		showBgModel();
		$(this).toggleClass("active");
	});
	document.addEventListener('click', function(event) {
		let popup = document.getElementById("language_select_box");
		// 检查点击事件的目标是否为弹窗及其子元素之外
		if (event.target !== popup && !popup.contains(event.target)) {
			$(".language_select_box").removeClass("active");
		}
	});
	// 开发工具
	$(".development,.development_model .close,.development_model .modal_bg,.development_model  .confirm").click(function(){
		$(".development_model").toggleClass("active");
		$("body").toggleClass("active");
	})
}
// 首页
initMethod.prototype.index = function(){
	this.common();
	// 装机必备
	$(".switch_box .switch_list").click(function(){
		if($(this).attr("class").indexOf("active") > -1) return
		var index = $(this).index();
		$(this).addClass("active").siblings().removeClass("active");
		$(this).parents(".common_box").find(".content .content_list").eq(index).addClass("active").siblings().removeClass("active");
	})
	var max8 = "max8";
	var max4 = "max4";
	// 热门免费
	var essx_swiper = new Swiper('#essx_banner', getBannerConfig(max4, ".essx_box"));
	// 创意应用
	var cyyy_swiper = new Swiper('#cyyy_banner', getBannerConfig(max4, ".cyyy_box"));
	// 热门免费
	var rmmf_swiper = new Swiper('#rmmf_banner', getBannerConfig(max4, ".rmmf_box"));
	// 收藏
	var sc_swiper = new Swiper('#sc_banner', getBannerConfig(max4, ".sc_box"));
	// 生产力应用
	var scl_swiper = new Swiper('#scl_banner', getBannerConfig(max8, ".scl_box"));
	// 电脑游戏
	var dnyx_swiper = new Swiper('#dnyx_banner', getBannerConfig(max8, ".dnyx_box"));
	// 最佳游戏
	var zjyx_swiper = new Swiper('#zjyx_banner', getBannerConfig(max8, ".zjyx_box"));
	// Latest Uploads
	var zxsc_swiper = new Swiper('#zxsc_banner', getBannerConfig(max8, ".zxsc_box"));
	// 竞速游戏
	var zxxx_swiper = new Swiper('#zxxx_banner', getBannerConfig("max3", ".zxxx_box"));
	
	window.addEventListener('resize', function() {
		// 当窗口大小变化时，更新Swiper的布局
		// 热门免费
		essx_swiper.params.slidesPerView = filterTemplateToCols(max4);
		essx_swiper.update();
		// 创意应用
		cyyy_swiper.params.slidesPerView = filterTemplateToCols(max4);
		cyyy_swiper.update();
		// 热门免费
		rmmf_swiper.params.slidesPerView = filterTemplateToCols(max4);
		rmmf_swiper.update();
		// 收藏
		sc_swiper.params.slidesPerView = filterTemplateToCols(max4);
		sc_swiper.update();
		// 生产力应用
		scl_swiper.params.slidesPerView = filterTemplateToCols(max8);
		scl_swiper.update();
		// 电脑游戏
		dnyx_swiper.params.slidesPerView = filterTemplateToCols(max8);
		dnyx_swiper.update();
		// 最佳游戏
		zjyx_swiper.params.slidesPerView = filterTemplateToCols(max8);
		zjyx_swiper.update();
		// 最佳游戏
		zxsc_swiper.params.slidesPerView = filterTemplateToCols(max8);
		zxsc_swiper.update();
		// 竞速游戏
		zxxx_swiper.params.slidesPerView = filterTemplateToCols("max3");
		zxxx_swiper.update();
	});
}

// 应用
initMethod.prototype.apps = function(){
	this.common();
	var max8 = "max8";
	var max6 = "max6";
	var max5 = "max5";
	var max4 = "max4";
	
	// 热门免费
	var rmmf_swiper = new Swiper('#rmmf_banner', getBannerConfig(max4, ".rmmf_box"));
	// 装机必备
	var zjbb_swiper = new Swiper('#zjbb_banner', getBannerConfig(max8, ".zjbb_box"));
	// 照片视频
	var zpsp_swiper = new Swiper('#zpsp_banner', getBannerConfig(max6, ".zpsp_box"));
	// 社交网络
	var sjwl_swiper = new Swiper('#sjwl_banner', getBannerConfig(max8, ".sjwl_box"));
	// 创意应用
	var cyyy_swiper = new Swiper('#cyyy_banner', getBannerConfig(max8, ".cyyy_box"));
	// 实用应用
	var syyy_swiper = new Swiper('#syyy_banner', getBannerConfig(max6, ".syyy_box"));
	// 热门应用
	var rmyy_swiper = new Swiper('#rmyy_banner', getBannerConfig(max4, ".rmyy_box"));
	// 付费应用
	var ffyy_swiper = new Swiper('#ffyy_banner', getBannerConfig(max8, ".ffyy_box"));
	// 特殊优惠
	var tsyh_swiper = new Swiper('#tsyh_banner', getBannerConfig(max5, ".tsyh_box"));
	// 收藏
	var sc_swiper = new Swiper('#sc_banner', getBannerConfig(max4, ".sc_box"));
	// Latest Uploads
	var zxsc_swiper = new Swiper('#zxsc_banner', getBannerConfig(max8, ".zxsc_box"));
	
	window.addEventListener('resize', function() {
		// 当窗口大小变化时，更新Swiper的布局
		// 热门免费
		rmmf_swiper.params.slidesPerView = filterTemplateToCols(max4);
		rmmf_swiper.update();
		// 装机必备
		zjbb_swiper.params.slidesPerView = filterTemplateToCols(max8);
		zjbb_swiper.update();
		// 照片视频
		zpsp_swiper.params.slidesPerView = filterTemplateToCols(max6);
		zpsp_swiper.update();
		// 社交网络
		sjwl_swiper.params.slidesPerView = filterTemplateToCols(max8);
		sjwl_swiper.update();
		// 创意应用
		cyyy_swiper.params.slidesPerView = filterTemplateToCols(max8);
		cyyy_swiper.update();
		// 实用应用
		syyy_swiper.params.slidesPerView = filterTemplateToCols(max6);
		syyy_swiper.update();
		// 热门应用
		rmyy_swiper.params.slidesPerView = filterTemplateToCols(max4);
		rmyy_swiper.update();
		// 付费应用
		ffyy_swiper.params.slidesPerView = filterTemplateToCols(max8);
		ffyy_swiper.update();
		// 特殊优惠
		tsyh_swiper.params.slidesPerView = filterTemplateToCols(max5);
		tsyh_swiper.update();
		// 收藏
		sc_swiper.params.slidesPerView = filterTemplateToCols(max4);
		sc_swiper.update();
		// Latest Uploads
		zxsc_swiper.params.slidesPerView = filterTemplateToCols(max8);
		zxsc_swiper.update();
	});
}

// 游戏
initMethod.prototype.games = function(){
	this.common();
	var max8 = "max8";
	var max5 = "max5";
	var max4 = "max4";
	var max3 = "max3";
	
	
	
	// 新电脑游戏
	var xdnyx_swiper = new Swiper('#xdnyx_banner', getBannerConfig(max8, ".xdnyx_box"));
	// 畅销游戏
	var cxyx_swiper = new Swiper('#cxyx_banner', getBannerConfig(max8, ".cxyx_box"));
	// 最佳游戏
	var zjyx_swiper = new Swiper('#zjyx_banner', getBannerConfig(max8, ".zjyx_box"));
	
	// 特殊优惠
	var tsyh_swiper = new Swiper('#tsyh_banner', getBannerConfig(max5, ".tsyh_box"));
	// 解谜游戏
	var jmyx_swiper = new Swiper('#jmyx_banner', getBannerConfig(max8, ".jmyx_box"));
	
	// 建造自己的世界
	var jzsj_swiper = new Swiper('#jzsj_banner', getBannerConfig(max4, ".jzsj_box"));
	// 热门付费游戏
	var ffyx_swiper = new Swiper('#ffyx_banner', getBannerConfig(max8, ".ffyx_box"));
	// 竞速游戏
	var jsyx_banner = new Swiper('#jsyx_banner', getBannerConfig(max3, ".jsyx_box"));
	// twenty four hours
	var essx_swiper = new Swiper('#essx_banner', getBannerConfig(max4, ".essx_box"));
	
	// 收藏
	var sc_swiper = new Swiper('#sc_banner', getBannerConfig(max4, ".sc_box"));
	
	window.addEventListener('resize', function() {
		// 当窗口大小变化时，更新Swiper的布局
		// 新电脑游戏
		xdnyx_swiper.params.slidesPerView = filterTemplateToCols(max8);
		xdnyx_swiper.update();
		// 畅销游戏
		cxyx_swiper.params.slidesPerView = filterTemplateToCols(max8);
		cxyx_swiper.update();
		// 最佳游戏
		zjyx_swiper.params.slidesPerView = filterTemplateToCols(max8);
		zjyx_swiper.update();
		
		// 特殊优惠
		tsyh_swiper.params.slidesPerView = filterTemplateToCols(max5);
		tsyh_swiper.update();
		// 解谜游戏
		jmyx_swiper.params.slidesPerView = filterTemplateToCols(max8);
		jmyx_swiper.update();
		// 建造自己的世界
		jzsj_swiper.params.slidesPerView = filterTemplateToCols(max4);
		jzsj_swiper.update();
		// 热门付费游戏
		ffyx_swiper.params.slidesPerView = filterTemplateToCols(max8);
		ffyx_swiper.update();
		// 竞速游戏
		jsyx_banner.params.slidesPerView = filterTemplateToCols(max3);
		jsyx_banner.update();
		// 收藏
		sc_swiper.params.slidesPerView = filterTemplateToCols(max4);
		sc_swiper.update();
		// twenty four hours
		essx_swiper.params.slidesPerView = filterTemplateToCols(max4);
		essx_swiper.update();
		
	});
}

// 工具
initMethod.prototype.tool = function(){
	this.common();
	// 
	$(".tool_content").on("click",".left_box dd",function(){
		var index = $(this).index();
		$(this).addClass("active").siblings("dd").removeClass("active");
		$(this).parent().find("dt").css("top",((index - 1) * 50 + 22) + 'px');
	})
	// 
	$('.hover_text_tips').on("mouseenter","li",function(){
		// 获取鼠标悬停时元素的坐标
		var offset = $(this).offset();
		var tips = $(this).data("tips");
		var width = parseInt($(this).width());
		var maxWidth = width + "px";
		// 输出坐标
		if(tips) {
			$(this).append(`<div class='triangle_template' style="top:-55px;width: ${maxWidth}">${tips}</div>`);
			let height = $(".triangle_template").height() - 22;
			if(height >= 22 ){
				$(".triangle_template").css({'top':(-55 - height) + 'px'});
			}
			$(".triangle_template").show();
		}
	});
	$('.hover_text_tips').on("mouseleave","li",function(){
		$(".triangle_template").remove();
	})
	// 
	$(".card_box").on("click",".switch_list",function(){
		if($(this).attr("class").indexOf("active") > -1) return
		var index = $(this).index();
		$(this).addClass("active").siblings().removeClass("active");
		$(this).parents(".card_box").find(".switch_content ul").eq(index).addClass("active").siblings().removeClass("active");
	});
	
	// 定义一个节流函数
	function throttle(fn, threshold, scope) {
	  threshold || (threshold = 250);
	  var last;
	  return function () {
	    var context = scope || this;
	    var now = +new Date();
	    if (last && now < last + threshold) {
	      // 如果两次调用的间隔小于设定的阈值，则不执行
	      return;
	    }
	    last = now;
	    fn.apply(context, arguments);
	  };
	}
	var clickFlag = true;
	// 
	$(document).ready(function() {
		var height = $(".header_template").height() + 20;
		$('.left_box').on('click','dd', function(e) {
			clickFlag = false;
			var target = $(this).find("a").attr("href"); 
			$('html, body').animate({
			  scrollTop: $(target).offset().top - height
			}, 200,function(){
				clickFlag = true;
			}); //
		});
		var scrollArr = [];
		$(".right_box .card_box").each(function(){
			var scrollTop = $(this).offset().top;
			scrollArr.push(scrollTop);
		});
		function handleScroll(event) {
			if(clickFlag){
				var scrollTop = $(window).scrollTop();
				var index = scrollArr.findIndex(item => { return item >= scrollTop});
				$('.left_box dd').eq(index).addClass("active").siblings("dd").removeClass("active").parent().find("dt").css("top",((index) * 50 + 22) + 'px');
			}
			
		  // 执行滚动时需要的操作
		}
		window.onscroll = throttle(handleScroll,50);
		
	});
}

// 探索
initMethod.prototype.search = function(){
	this.common();
	$('.result_content').on("mouseenter",".result_list",function(){
		// 获取鼠标悬停时元素的坐标
		var offset = $(this).offset();
		var tips = $(this).find("h3").text();
		var width = parseInt($(this).width());
		var maxWidth = width + "px";
		// 输出坐标
		if(tips) {
			$(this).append(`<div class='triangle_template' style="top:-30px;width: ${maxWidth};">${tips}</div>`);
			let height = $(".triangle_template").height() - 22;
			if(height >= 22 ){
				$(".triangle_template").css({'top':(-30 - height) + 'px'});
			}
			$(".triangle_template").show();
		}
	});
	$('.result_content').on("mouseleave",".result_list",function(){
		$(".triangle_template").remove();
	})
	// 装机必备
	$(".switch_box .switch_list").click(function(){
		if($(this).attr("class").indexOf("active") > -1) return
		var index = $(this).index();
		$(this).addClass("active").siblings().removeClass("active");
		$(this).parents(".common_box").find(".switch_content .result_content").eq(index).addClass("active").siblings().removeClass("active");
	})
}

// 落地页评价弹窗
initMethod.prototype.comment = function() {
	if(localStorage.getItem("top")){
		window.scrollTo(0,localStorage.getItem("top"));
	}
	window.addEventListener('scroll', function() {
		localStorage.setItem("top",window.pageYOffset);
	});

	// 新建评论
	window.startComment = function(_this) {
		var id = $(_this).parent().data("id");
		var gid = $(_this).parent().data("gid");
		var $parent = $(_this).parents(".time").parent();
		if ($parent.find("#form_" + id).length > 0) {
			$parent.find("#form_" + id).remove();
		} else {
			var textareaHtml = `<div class="comment_form" id="form_${id}">
										<form action="/comment" method="post">
											<input type="hidden" name="gid" value="${gid}"/>
											<input type="hidden" name="pid" value="${id}"/>
											<textarea name="content" oninput="autoResizeTextarea (this)" placeholder="理性发言,友善互动"></textarea>
											<div class="comment_btn">
												<button type="button" class="comment_release">发布</button>
											</div>
										</form>
									</div>`;
			$(_this).parents(".time").after(textareaHtml);
		}
		event.stopPropagation();
	}

	// 高度自适应
	window.autoResizeTextarea = function(_this) {
		_this.style.height = 'inherit'; // 重置高度以获取内容的正确高度
		_this.style.height = _this.scrollHeight + 'px'; // 设置实际高度
		if (_this.value.length > 0) {
			if ($(_this).parent().find("button").prop("type") == "submit") return;
			$(_this).parent().find("button").prop("type", "submit");
		} else {
			$(_this).parent().find("button").prop("type", "button");
		}
	}

	function showMessage(text, type) {
		if ($('#alert_message').length <= 0) {
			let styleCss = `<style>
						.alert_message{position: fixed;pointer-events: none;top: 8px;width: 100%;z-index: 1010;text-align: center;}
						.alert_message .text{
							position: relative;top: 0px;display: inline-block;color: #000;font-size: 16px;font-weight: 500;padding: 10px 15px;border-radius: 3px;background-color: #fff;border: 1px solid #eee;opacity: 0;
							transition: opacity 0.3s, transform 0.3s, visibility 0.3s;visibility: hidden;
						}
						.alert_message.success .text{color: #6ADC98;border: 1px solid #9AD766;}
						.alert_message.error .text{color: #e4393c;}
						.alert_message.show .text{opacity: 1;visibility: visible;transform: translateY(80px);}
						.alert_message.hide .text{opacity: 0; visibility: hidden;transform: translateY(10px);}
						</style>`
			$("body").append(`${styleCss}<div id="alert_message" class="alert_message">
														<div class="text"></div>
													</div>
													<div class="spinning" id="spinning">
														<span class="spin_box">
															<i class="spin_item"></i>
															<i class="spin_item"></i>
															<i class="spin_item"></i>
															<i class="spin_item"></i>
														</span>
													</div>`);
		}
		var className = type == 1 ? "alert_message show success" : "alert_message show error";
		$('#alert_message').attr("class", className).find(".text").text(text);

		// 3秒后隐藏消息
		setTimeout(function () {
			$('#alert_message').addClass('hide').removeClass('show');
		}, 3000);
	}

	function loading(type) {
		if ($('#spinning').length <= 0) {
			let styleCss = `<style>
					 	.spinning{display: none;position: fixed;background-color: rgba(0,0,0,.5);z-index: 1000;left: 0;top: 0;right: 0;bottom: 0;}.spinning .spin_box{left: 50%;margin: -10px;position: absolute;top: 50%;animation: antRotate 1.2s linear infinite;transform: rotate(0deg);}.spinning .spin_box .spin_item{background-color: #ff5151;border-radius: 100%;display: block;width: 12px;height: 12px;opacity: .3;position: absolute;transform: scale(.75);transform-origin: 50% 50%;margin: 0;animation: antSpinMove 1s linear infinite alternate;}.spinning .spin_box .spin_item:nth-child(1){left: 0;top: 0;}.spinning .spin_box .spin_item:nth-child(2){animation-delay: .4s;right: 0;top: 0;}.spinning .spin_box .spin_item:nth-child(3){animation-delay: .8s;bottom: 0;right: 0;}.spinning .spin_box .spin_item:nth-child(4){animation-delay: 1.2s;bottom: 0;left: 0;}@keyframes antRotate {to {transform: rotate(360deg)}}@keyframes antSpinMove {to {opacity: 1}}
					 	</style>`
			$("body").append(`${styleCss}
						<div class="spinning" id="spinning">
							<span class="spin_box">
								<i class="spin_item"></i>
								<i class="spin_item"></i>
								<i class="spin_item"></i>
								<i class="spin_item"></i>
							</span>
							<div style="left: 50%;position: absolute;top: 51%;font-size: 16px;transform: translateX(-50%);color: #fff;" class="loading-text"></div>
						</div>`);
		}
		if (type == "show") {
			$("#spinning").show();
		} else {
			$("#spinning").hide();
		}
	}

	function loadingUpdateText(text) {
		$("#spinning .loading-text").text(text);
	}

	// 喜欢like 不喜欢dislike
	window.reqEvaluate = function(_this) {
		var status = $(_this).attr("class").indexOf("active") > -1 ? "reduce" : "add";
		$(_this).toggleClass("active");
		var id = $(_this).parent().data("id");
		var type = $(_this).data("type");
		// type good/fail
		var url = type == "like" ? "like" : "dislike";
		$.ajax({
			url: "/evaluate/" + url, // 你要请求的 URL
			type: "post",
			data: {id: id, type: type,status: status},
			dataType: "json",
			beforeSend: function () {
				loading("show");
			},
			success: function (response) {
				// 提交成功
				if (response.code == 1) {
					// 隐藏loading
					$(_this).text(response.data)
					loading("hide");
				} else {
					showMessage(response.msg, 2);
					$(_this).toggleClass("active");
				}
			},
			error: function (jqXHR, textStatus, errorThrown) {
				showMessage(errorThrown, 2);
				loading("hide");
				$(_this).toggleClass("active");
			},
			complete: function () {
			}
		});

	}

	// 组装html
	function mergeCommentHtml(data){
		var gid = data[0].gid;
		var statusHtml = "<span class=\"remark\"  onclick=\"startComment(this)\">回复</span>";
		var commentHtml = "";
		for (var i=0; i<data.length;i++) {
			var item = data[i];
			if(i == 0){
				statusHtml = '';
			}
			commentHtml += `<div class="comment_list">
									<div class="user_img">
										<img src="${item.logo}" alt="">
									</div>
									<div class="content">
										<div class="user_name">
											<span class="name">${item.username}</span>
										</div>
										<p class="info">${item.content}</p>
										<div class="time">
											<span class="user">${item.time}</span>
											<div class="stats" data-id="${item.id}">
												${statusHtml}
												<span class="like" data-type="good" onclick="reqEvaluate(this)">${item.upvotes}</span>
												<span class="dislike" data-type="fail" onclick="reqEvaluate(this)">${item.downvotes}</span>
											</div>
										</div>
									</div>
								</div>`;
		}
		var releaseHtml = `<div class="comment_form" data-id="${data[0].id}" data-pid="${data[0].pid}">
							<form action="/comment" method="post">
								<input type="hidden" name="pid" value="${data[0].id}"/>
								<input type="hidden" name="gid" value="${gid}"/>
								<textarea name="content" oninput="autoResizeTextarea(this)" placeholder="理性发言,友善互动"></textarea>
								<div class="comment_btn">
									<button type="button" class="comment_release">发布</button>
								</div>
							</form>
						</div>`
		return commentHtml + releaseHtml;

	}

	// 加载数据
	function reqCommentById(id){
		$.ajax({
			url: "/comment/all", // 你要请求的 URL
			type: "post",
			data: {
				id: id
			},
			dataType: "json",
			beforeSend: function() {
				loading("show");
			},
			success: function(response) {
				// 提交成功
				if (response.code == 1) {

					$(".comment_modal").toggleClass("active").find(".comment_template").html(mergeCommentHtml(response.data));
					$("body").toggleClass("active");
					// 隐藏loading
					loading("hide");
				} else {
					showMessage(response.msg, 2);
				}
			},
			error: function(jqXHR, textStatus, errorThrown) {
				showMessage(errorThrown, 2);
				loading("hide");
			},
			complete: function() {
			}
		});
	}

	// 评价弹窗
	$(".show_more_comment,.comment_modal .close,.comment_modal .modal_bg").click(function(){
		var className = $(this).attr("class");
		if(className.indexOf("show_more_comment") > -1 ){
			var id = $(this).data("id");
			reqCommentById(id);
		}else{
			$(".comment_modal").toggleClass("active");
			$("body").toggleClass("active");
		}
	})
}

// 落地页
initMethod.prototype.detail = function(){
	this.common();
	var pmjt_swiper = new Swiper('#pmjt_banner',{
		slidesPerView: 'auto', // 每次滚动移动1个slide
		spaceBetween: 20, // 每个slide之间的距离
		navigation: {
			nextEl: '.swiper-button-next',
			prevEl: '.swiper-button-prev',
		}
	});

	// 说明，其他版本
	$(".show_more_sm,.show_more_version,.show_all_comment").click(function(){
		var className = $(this).prev().attr("class");
		if(className.indexOf("active") > -1) {
			$(this).text($(this).data("more"));
		}else{
			$(this).text($(this).data("less"));
		}
		$(this).prev().toggleClass("active");
	})

	// 更多语言
	$("#language_more,.language_show_model .model_bg").click(function(){
		$(".language_show_model").toggleClass("active");
		$("body").toggleClass("active");
	})
	window.onscroll = function(){
		var scrollTop = $(window).scrollTop();
		if(scrollTop > 300){
			if($(".sticky_box").attr("class").indexOf("active") < 0){
				$(".sticky_box").addClass("active");
			}
		}else{
			if($(".sticky_box").attr("class").indexOf("active") > -1){
				$(".sticky_box").removeClass("active");
			}
		}
	}
	// 
	$(".sticky_box").click(function(){
		$('html, body').animate({
		  scrollTop: 0
		}, 200);
	});
	$('#pmjt_banner').viewer({
		zoomRatio: 0.8
	});
}

// 落地页
initMethod.prototype.column = function(){
	this.common();
	// 装机必备
	$(".switch_box .switch_list").click(function(){
		if($(this).attr("class").indexOf("active") > -1) return
		var index = $(this).index();
		$(this).addClass("active").siblings().removeClass("active");
		$(this).parents(".common_box").find(".switch_content .result_content").eq(index).addClass("active").siblings().removeClass("active");
	})
}


var $footer = $(".footer_template");
$footer.after("<div id='location_ele'></div>");
initMethod.prototype.footerPosition = function(){
	var screenH = $(window).height();
	var footerT = $("#location_ele").offset().top;
	if(footerT < screenH){
		$footer.addClass("sticky");
	}else{
		$footer.removeClass("sticky");
	}
}

var commonMethod = new initMethod();
