var gd1 = "";
var gd2 = "";
var gj1 = "";
var gj2 = "";
var gf1 = "";
var gf2 = "";
var fz1 = "";
var fz2 = "";
var zt1 = "";
var zt2 = "";
var jg1 = -0.01;
var jg2 = -0.01;
var sf = "";
var type = "";
var url1 =url+"/info/supply/selectForSupply0";
var ttArr = window.location.href.split("?search=");
var title = decodeURI(window.location.href.split("?search=")[1]);
if(title==null||title.trim().length<2||ttArr.length!=2){
	title = "";
	url1 = url+"/info/supply/selectForSupply";
}
$(function () {
	ADB();
	$("#Sou").val(title);
	region_init("capital","city","area");
	$("#capital").on("change",function () {
		$("#more1").html($("#capital option:selected").text()+"▼");
		$("#more1").css("color","#7AAC4B");
		$(".address").css("color", "#333333");
		sf = $("#capital option:selected").text();
		getInfo(1);
		getTotal();
	});
	getInfo(1);
	getTotal();
	$("#SX").click(function () {
		setSX();
		getInfo(1);
		getTotal();
	});
	$("#formSX").on("reset", function () {
		clearInfo();
		getInfo(1);
		getTotal();
	});
	$("#mm-type").mouseleave(function () {
		$("#mm-type-list").hide();
	});
	$("#mm-type-list").mouseleave(function () {
		$("#mm-type-list").hide();
		$("#mm-type-more").hide();
	});
	$("#mm-type-more").mouseleave(function () {
		$("#mm-type-list").hide();
		$("#mm-type-more").hide();
	});
	$(".address").click(function () {
		if ($(this).css("color") != "rgb(122, 172, 75)") {
			$("#more1").html("更多▼");
			$("#more1").css("color","#333333");
			$(this).css("color", "#7AAC4B");
			$(this).parent().siblings().children().css("color", "#333333");
			if($(this).html() == "不限"){
				sf = "";
			}else{
				sf = $(this).html();
			}
			getInfo(1);
			getTotal();
		}
	});
	$(".type").click(function () {
		if ($(this).css("color") != "rgb(122, 172, 75)") {
			$(this).css("color", "#7AAC4B");
			$(this).parent().siblings().children().css("color", "#333333");
			if($(this).html() == "不限"){
				type = "";
			}else{
				type = $(this).html();
			}
			getInfo(1);
			getTotal();
		}
	});
	$(".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;
			}
		}
	});
});

function getInfo(page) {
	var limit =(page-1)*10;
	var data = {
		"gd1": gd1,
		"gd2": gd2,
		"gj1": gj1,
		"gj2": gj2,
		"fz1": fz1,
		"fz2": fz2,
		"jg1": jg1,
		"jg2": jg2,
		"zt1": zt1,
		"zt2": zt2,
		"gf1": gf1,
		"gf2": gf2,
		"page":limit,
		"sf":sf,
		"type":type,
		"cpmc":title
	};
	console.log(data);
	console.log(url1);
	$.ajax({
		url: url1,
		data: data,
		type: "post",
		dateType: "json",
		async: false,
		success: function (response, status, xhr) {
			if(response.length>0){
				$(".list").empty();
				$.each(response,function (i, list) {
					var pic = "../images/无图片.jpg";
					if(list.picture!=null&&list.picture!=""){
						pic = list.picture;
						pic = formatImgUrl(pic);
					}
					var bz = "无详细说明";
					if(list.bz!=null&&list.bz!=""){
						bz = list.bz;
					}
					var gg = list.cpgg;
					if(list.type=="苗木资材"||list.type=="苗木种子"||list.type=="地被草坪"){
						gg = bz;
					}
					var title = gg;
					if(gg.length>25){
						gg = gg.slice(0,25)+"...";
					}
					var company = "无数据";
					if(list.sccj!=null&&list.sccj!=""){
						company = list.sccj;
					}
					var price = "面议";
					var dw = "";
					if(list.cpjg!=null&&list.cpjg!=""&&list.cpjg!=0&&list.cpjg!="0"&&list.cpjg!="无"){
						price = list.cpjg;
						if(!isNaN(price)){
							price+="元";
						}
						if(list.dw!=null&&list.dw!=""){
							dw = "("+list.dw+")";
						}else{
							dw = "(株)";
						}
					}
					var sm = "";
					var zz = "";
					var db = "";
					var hy = "";
					switch (list.hyjb) {
						case 5:
							hy="<img src='../images/皇冠级别.png' title='皇冠VIP'>";
							break;
						case 4:
							hy="<img src='../images/黄钻级别.png' title='黄钻VIP'>";
							break;
						case 3:
							hy="<img src='../images/红钻级别.png' title='红钻VIP'>";
							break;
						case 2:
							hy="<img src='../images/绿钻级别.png' title='绿钻VIP'>";
							break;
						case 1:

							break;
						default:

							break;
					}
					if(list.sm==1){
						sm = "<img src='../images/三级详情页供应改身份验证.png' title='已通过实名认证'>";
					}
					if(list.zzFlag==1){
						zz = "<img src='../images/三级详情页供应改danbao_23.png' title='已通过执照认证'>";
					}
					if(list.db==1){
						db = "<img src='../images/三级详情页供应改danbao_30.png' title='已缴费担保认证'>"
					}
					var rz = hy+sm + zz + db;
					if(!rz){
						rz = '无';
					}
					$(".list").append("<div>" +
						"<table>" +
						"<tr>" +
						"<td><a href='../spzs/Show_product/"+list.id+".html' target='_blank'><img src='"+pic+"'></a></td>" +
						"<td title='"+bz+"'><a href='../spzs/Show_product/"+list.id+".html' target='_blank'><p>"+list.cpmc+"</p></a><span title='"+title+"'>"+gg+"</span></td>" +
						"<td>"+list.sf+","+list.city+"</td>" +
						"<td>"+price+dw+"</td>" +
						"<td><a href='../company/vip/"+list.gsid+".html' target='_blank'><img src=\"../images/店铺.png\">"+company+"</a><div>认证:"+rz+"</div><a href='javascript:void(0);' onclick='showTel("+list.phone+")'>联系卖家</a><br><a href='../spzs/Show_product/"+list.id+".html' target='_blank'>查看详情</a></td>" +
						"</tr>" +
						"</table>" +
						"</div>");
				});
			}else{
				$(".list").html("<div>无符合条件的内容</div>");
				layer.msg("无符合条件的内容",{icon:2});
			}
			document.title=sf+'苗木价格|苗木供应信息|苗木报价|苗木图片-中国苗木网miaomu.com';
			$("meta[name='keywords']").attr('content',sf+'苗木价格,苗木供应信息,苗木报价,苗木图片');
			$("meta[name='description']").attr('content','中国苗木网miaomu.com苗木供应大厅为您提供'+sf+'最新苗木供应信息,苗木价格,苗木报价,苗木图片等苗木信息。');
		},
		error: function (e) {
			layer.msg('未知错误,请联系客服!', { icon: 5 });
			console.log("getInfo");
			console.log(e.status);
			console.log(e.responseText);
		}
	});
}
function getTotal() {
	var total = 0;
	var data = {
		"gd1": gd1,
		"gd2": gd2,
		"gj1": gj1,
		"gj2": gj2,
		"fz1": fz1,
		"fz2": fz2,
		"jg1": jg1,
		"jg2": jg2,
		"zt1": zt1,
		"zt2": zt2,
		"gf1": gf1,
		"gf2": gf2,
		"sf":sf,
		"type":type,
		"cpmc":title
	};
	$.ajax({
		url:url+"/info/supply/countForSupply",
		data: data,
		type: "post",
		dateType: "json",
		async: false,
		success: function (response, status, xhr) {
			total = response;
		},
		error: function error() {
			layer.msg('未知错误,请联系客服!', { icon: 5 });
			console.log("countForSupply");
			console.log(e.status);
			console.log(e.responseText);
		}
	});
	$("#myPage").sPage({
		page: 1, //当前页码,必填
		total: total, //数据总条数,必填
		pageSize: 10, //每页显示多少条数据,默认10条
		showTotal: false, //是否显示总条数,默认关闭:false
		totalTxt: "共{total}条", //数据总条数文字描述,{total}为占位符,默认"共{total}条"
		noData: true, //没有数据时是否显示分页,默认false不显示,true显示第一页
		showSkip: true, //是否显示跳页,默认关闭:false
		showPN: true, //是否显示上下翻页,默认开启:true
		prevPage: "上一页", //上翻页文字描述,默认“上一页”
		nextPage: "下一页", //下翻页文字描述,默认“下一页”
		backFun: function backFun(page) {
			//点击分页按钮回调函数,返回当前页码
			//$("#pNum").text(page);
			scrollTo(0, 0);
			getInfo(page);
		}
	});
}
function setSX() {
	gd1 = rePlace2($("#gd1").val());
	gd2 = rePlace2($("#gd2").val());
	gj1 = rePlace2($("#gj1").val());
	gj2 = rePlace2($("#gj2").val());
	gf1 = rePlace2($("#gf1").val());
	gf2 = rePlace2($("#gf2").val());
	fz1 = rePlace2($("#fz1").val());
	fz2 = rePlace2($("#fz2").val());
	zt1 = rePlace2($("#zt1").val());
	zt2 = rePlace2($("#zt2").val());
	jg1 = rePlace($("#jg1").val());
	jg2 = rePlace($("#jg2").val());
}
function clearInfo() {
	gd1 = "";
	gd2 = "";
	gj1 = "";
	gj2 = "";
	gf1 = "";
	gf2 = "";
	fz1 = "";
	fz2 = "";
	zt1 = "";
	zt2 = "";
	jg1 = -0.01;
	jg2 = -0.01;
}
function rePlace(temp) {
	if (temp == null || temp.trim() == "") {
		return -0.01;
	} else {
		return parseInt(temp) - 0.0;
	}
}
function rePlace2(temp) {
	if (temp == null || temp.trim() == "") {
		return "";
	} else {
		return parseInt(temp);
	}
}
function showTel(tel) {
	layer.alert(tel,{title:"联系方式",scrollbar:false});
}

function ADB() {
	$.ajax({
		url:url+"/ad/adb/selectAll",
		data:{},
		type: "post",
		dateType: "json",
		async: false,
		success: function (response, status, xhr) {
			if(response.length==20){
				$.each(response,function (i, list) {
					if(i>=15){
						if(list.picture!=null&&list.picture!=""){
							$("#"+list.position).html("<img src='"+formatImgUrl(list.picture)+"'><div style='padding: 2px 4px;color: #ffffff;background-color: rgba(0,0,0,0.3);font-size: 12px;position: absolute;right: 30px;bottom: 8px;border-radius: 5px;height: 21px;width: 32px;opacity: 0.7'>广告</div>");
							$("#"+list.position).attr("href",setHref(list.link));
						}
					}
				});
			}else{
				layer.msg("系统错误",{icon:5});
				console.log("广告位数据库错误");
			}
		},
		error: function (e) {
			layer.msg("系统错误,请联系客服!", { icon: 5 });
			console.log("ADB");
			console.log(e.status);
			console.log(e.responseText);
		}
	});
}
function setHref(href) {
	if(href==null||href==""){
		return "#";
	}else{
		return href;
	}
}