(function ($) {
$.ZfySearchSelect = function (o) {
o = $.extend({
url: 'http://simplicity.mb.qkk.cn/search.aspx?action=shop',//搜索地址
showList: 0,//0 筛选并跳转 1 选择并返回筛选参数 2 Ajax筛选
channelid: 0,//频道ID,必须设置
class: true,//栏目是否参与筛选
classTitle: '商品分类:',//栏目说明
Special: false,//专题是否参与筛选
SpecialTtile:'专题分类:',
html1: '
- {$searchName}
- {$searchKeyword}
',
htmlId1: '#searchSelectOne',
price: false,
priceList: '全部,0-100,100-500,500-2000,2000-5000,5000-10000,10000-20000,20000-50000,50000以上',
priceName:'价格区间:',
html2: '- {$searchName}
- {$searchKeyword}
',
htmlId2: '#searchSelectTwo',
Elite: false,
EliteName:'推荐',
Hot: false,
HotName:'热门',
Xinpin: false,
XinpinName:'新品',
Cuxiao: false,
CuxiaoName: '促销',
PropertyName: '商品属性:',
html3: '- {$searchName}
- {$searchKeyword}
',
htmlId3: '#searchSelectThree',
order: false,
orderList: '默认|default,上架|time,价格|price,销量|sales,评价|comment,点击|hits',
orderName:'商品排序:',
html4: '- {$searchName}
- {$searchKeyword}
',
htmlId4: '#searchSelectFour'//,
//lid: 0,//指定智能排版ID
//heng: 0,
//shu: 0,
//showListId: '#searchSelectList'
}, o || {});
var strHtml = "";
var strSum = 1;
//筛选的排序方式:栏目 专题 自定义字段 属性 排序
//第1步:先加载所有需要筛选的数据类型
o.url += "&channelid=" + o.channelid;
//加载栏目ID
var GetClass = getQueryString("classid");//"";
var ThisClass = "";
if (o.class == true){
o.url += "&classid={$classid}";
}else{
if(ThisClass+"a"!="a"){o.url += "&classid=" + ThisClass;}else{o.url += "&classid=" + GetClass;}
}
//加载专题ID
var GetSpecial = getQueryString("Specialid");//"";
if (o.Special == true) {
o.url += "&Specialid={$Specialid}";
}
//开始循环出自定义字段
var GetFields = new Array();
//结束
//加载价格
var GetPrice1 = getQueryString("price1");//"";
var GetPrice2 = getQueryString("price2");//"";
if (o.price == true) {
o.url += "&price1={$price1}&price2={$price2}";
}
//加载推荐
var GetElite = getQueryString("Elite");//"";
if (o.Elite == true) {
o.url += "&Elite={$Elite}";
}
//加载热门
var GetHot = getQueryString("Hot");//"";
if (o.Hot == true) {
o.url += "&Hot={$Hot}";
}
//加载新品
var GetXinpin = getQueryString("Xinpin");//"";
if (o.Xinpin == true) {
o.url += "&Xinpin={$Xinpin}";
}
//加载促销
var GetCuxiao = getQueryString("Cuxiao");//"";
if (o.Cuxiao == true) {
o.url += "&Cuxiao={$Cuxiao}";
}
//加载排序
var GetOrder = getQueryString("order");//"";
if (o.order == true) {
o.url += "&order={$order}";
}
//栏目列表选择
if (o.class == true) {
var ClassList = "全部|0,洋酒|10011,饮用水|10012,功能饮料|10013,咖啡|10014,啤酒|10015,白酒|10016,果汁|10017,茶饮料|10018,碳酸饮料|10019,奶茶|10020,甜点|10021";
if (ClassList+"a"!="a"){
var ClassList_arr = ClassList.split(",");
if (ClassList_arr.length > 0) {
strHtml = "";
var ClassHtml = o.html1.replace("{$sum}", strSum);
strSum++;
ClassHtml = ClassHtml.replace("{$searchName}", o.classTitle);
for (var i = 0; i < ClassList_arr.length; i++) {
var ClassList_arr2 = ClassList_arr[i].split("|");
if (GetClass == ClassList_arr2[1] || (GetClass + "a" == "a" && ClassList_arr2[1] == "0")) {
var ThisUrl = o.url.replace("{$classid}", GetClass);
ThisUrl = MM_replace_link(ThisUrl, 1);
strHtml += '' + ClassList_arr2[0] + '';
} else {
var ThisUrl = o.url.replace("{$classid}", ClassList_arr2[1]);
ThisUrl = MM_replace_link(ThisUrl, 1);
strHtml += '' + ClassList_arr2[0] + '';
}
}
ClassHtml = ClassHtml.replace("{$searchKeyword}", strHtml);
if (ClassHtml + "a" != "a") {
$(o.htmlId1).append(ClassHtml);
}
}
}
}
//专题列表选择
if (o.Special == true) {
var SpecialList = "全部|0,品牌专区|10000";
if (SpecialList+"a"!="a"){
var SpeciaList_arr = SpecialList.split(",");
if (SpeciaList_arr.length > 0) {
strHtml = "";
var SpeciaHtml = o.html1.replace("{$sum}", strSum);
strSum++;
SpeciaHtml = SpeciaHtml.replace("{$searchName}", o.SpecialTtile);
for (var i = 0; i < SpeciaList_arr.length; i++) {
var SpeciaList_arr2 = SpeciaList_arr[i].split("|");
if (GetSpecial == SpeciaList_arr2[1] || (GetSpecial + "a" == "a" && SpeciaList_arr2[1] == "0")) {
var ThisUrl = o.url.replace("{$Specialid}", GetSpecial);
ThisUrl = MM_replace_link(ThisUrl, 2);
strHtml += '' + SpeciaList_arr2[0] + ''
} else {
var ThisUrl = o.url.replace("{$Specialid}", SpeciaList_arr2[1]);
ThisUrl = MM_replace_link(ThisUrl, 2);
strHtml += '' + SpeciaList_arr2[0] + '';
}
}
SpeciaHtml = SpeciaHtml.replace("{$searchKeyword}", strHtml);
if (SpeciaHtml + "a" != "a") {
$(o.htmlId1).append(SpeciaHtml);
}
}
}
}
//自定义字段
var ZdyFields = "";
if (ZdyFields+"a"!="a"){
var ZdyFieldValue = "";
var ZdyFieldName = "";
var ZdyFields_arr = ZdyFields.split("|");
var ZdyFieldValue_arr = ZdyFieldValue.split("|");
var ZdyFieldName_arr = ZdyFieldName.split("|");
if (ZdyFields_arr.length > 0) {
for (var i = 0; i < ZdyFields_arr.length; i++) {
var ZdyFields_arr_arr = ZdyFields_arr[i].split(",");
if (ZdyFields_arr_arr.length > 0) {
strHtml = "";
var ZdyFieldsHtml = o.html1.replace("{$sum}", strSum);
strSum++;
ZdyFieldsHtml = ZdyFieldsHtml.replace("{$searchName}", ZdyFieldName_arr[i]);
for (var j = 0; j < ZdyFields_arr_arr.length; j++) {
if (GetFields[i] == ZdyFields_arr_arr[j] || (GetFields[i] + "a" == "a" && ZdyFields_arr_arr[j] == "全部")) {
var ThisUrl = o.url.replace("{$MY_" + ZdyFieldValue_arr[i] + "}", GetFields[i]);
ThisUrl = MM_replace_link(ThisUrl, 3);
strHtml += '' + ZdyFields_arr_arr[j] + ''
} else {
var reZdyFields=ZdyFields_arr_arr[j];
if (reZdyFields=="全部"){
reZdyFields = ""
}
var ThisUrl = o.url.replace("{$MY_" + ZdyFieldValue_arr[i] + "}", escape(reZdyFields));
ThisUrl = MM_replace_link(ThisUrl, 3);
strHtml += '' + ZdyFields_arr_arr[j] + '';
}
}
ZdyFieldsHtml = ZdyFieldsHtml.replace("{$searchKeyword}", strHtml);
if (ZdyFieldsHtml + "a" != "a") {
$(o.htmlId1).append(ZdyFieldsHtml);
}
}
}
}
}
//价格
if (o.price == true) {
if(o.priceList+"a"!="a"){
var PriceList_arr = o.priceList.split(",");
if (PriceList_arr.length > 0) {
strHtml = "";
var priceHtml = o.html2.replace("{$sum}", strSum);
strSum++;
priceHtml = priceHtml.replace("{$searchName}", o.priceName);
for (var i = 0; i < PriceList_arr.length; i++) {
if (PriceList_arr[i].indexOf("-") > -1) {
var PriceList_arr2 = PriceList_arr[i].split("-");
if (GetPrice1 + "a" != "a" && GetPrice2 + "a" != "a" && parseInt(GetPrice1) >= parseInt(PriceList_arr2[0]) && parseInt(GetPrice1) <= parseInt(PriceList_arr2[1]) && parseInt(GetPrice2) >= parseInt(PriceList_arr2[0]) && parseInt(GetPrice2) <= parseInt(PriceList_arr2[1]) && parseInt(GetPrice2) > parseInt(GetPrice1)) {
var ThisUrl = o.url.replace("{$price1}", GetPrice1);
ThisUrl = ThisUrl.replace("{$price2}", GetPrice2);
ThisUrl = MM_replace_link(ThisUrl, 4);
strHtml += '' + PriceList_arr[i] + ''
} else {
var ThisUrl = o.url.replace("{$price1}", PriceList_arr2[0]);
ThisUrl = ThisUrl.replace("{$price2}", PriceList_arr2[1]);
ThisUrl = MM_replace_link(ThisUrl, 4);
strHtml += '' + PriceList_arr[i] + '';
}
} else {
if (PriceList_arr[i] == "全部") {
if (GetPrice1 + "a" == "a" && GetPrice2 + "a" == "a") {
var ThisUrl = o.url.replace("{$price1}", "");
ThisUrl = ThisUrl.replace("{$price2}", "");
ThisUrl = MM_replace_link(ThisUrl, 4);
strHtml += '' + PriceList_arr[i] + ''
} else {
var ThisUrl = o.url.replace("{$price1}", "");
ThisUrl = ThisUrl.replace("{$price2}", "");
ThisUrl = MM_replace_link(ThisUrl, 4);
strHtml += '' + PriceList_arr[i] + ''
}
} else {
var maxPrice = PriceList_arr[i].replace("以上", "");
if (GetPrice1 + "a" != "a" && GetPrice2 + "a" != "a" && parseInt(GetPrice1) >= maxPrice && parseInt(GetPrice2) >= maxPrice && parseInt(GetPrice2) > parseInt(GetPrice1)) {
var ThisUrl = o.url.replace("{$price1}", maxPrice);
ThisUrl = ThisUrl.replace("{$price2}", parseInt(maxPrice) * 100);
ThisUrl = MM_replace_link(ThisUrl, 4);
strHtml += '' + PriceList_arr[i] + '';
} else {
var ThisUrl = o.url.replace("{$price1}", maxPrice);
ThisUrl = ThisUrl.replace("{$price2}", parseInt(maxPrice) * 100);
ThisUrl = MM_replace_link(ThisUrl, 4);
strHtml += '' + PriceList_arr[i] + '';
}
}
}
}
priceHtml = priceHtml.replace("{$searchKeyword}", strHtml);
if (priceHtml + "a" != "a") {
$(o.htmlId2).append(priceHtml);
}
}
}
}
//属性
var PropertyList = "";
if (o.Elite == true) {
if (GetElite + "a" != "a") {
var ThisUrl = "";
if (GetElite == "1") {
ThisUrl = o.url.replace("{$Elite}", "");
} else {
ThisUrl = o.url.replace("{$Elite}", "1");
}
ThisUrl = MM_replace_link(ThisUrl, 5);
PropertyList += '' + o.EliteName + '';
} else {
var ThisUrl = o.url.replace("{$Elite}", "1");
ThisUrl = MM_replace_link(ThisUrl, 5);
PropertyList += '' + o.EliteName + '';
}
}
if (o.Hot == true) {
if (GetHot + "a" != "a") {
var ThisUrl = "";
if (GetHot == "1") {
ThisUrl = o.url.replace("{$Hot}", "");
} else {
ThisUrl = o.url.replace("{$Hot}", "1");
}
ThisUrl = MM_replace_link(ThisUrl, 5);
PropertyList += '' + o.HotName + '';
} else {
var ThisUrl = o.url.replace("{$Hot}", "1");
ThisUrl = MM_replace_link(ThisUrl, 5);
PropertyList += '' + o.HotName + '';
}
}
if (o.Xinpin == true) {
if (GetXinpin + "a" != "a") {
var ThisUrl = "";
if (GetXinpin == "1") {
ThisUrl = o.url.replace("{$Xinpin}", "");
} else {
ThisUrl = o.url.replace("{$Xinpin}", "1");
}
ThisUrl = MM_replace_link(ThisUrl, 5);
PropertyList += '' + o.XinpinName + '';
} else {
var ThisUrl = o.url.replace("{$Xinpin}", "1");
ThisUrl = MM_replace_link(ThisUrl, 5);
PropertyList += '' + o.XinpinName + '';
}
}
if (o.Cuxiao == true) {
if (GetCuxiao + "a" != "a") {
var ThisUrl = "";
if (GetCuxiao == "1") {
ThisUrl = o.url.replace("{$Cuxiao}", "");
} else {
ThisUrl = o.url.replace("{$Cuxiao}", "1");
}
ThisUrl = MM_replace_link(ThisUrl, 5);
PropertyList += '' + o.CuxiaoName + '';
} else {
var ThisUrl = o.url.replace("{$Cuxiao}", "1");
ThisUrl = MM_replace_link(ThisUrl, 5);
PropertyList += '' + o.CuxiaoName + '';
}
}
if (PropertyList + "a" != "a") {
var PropertyHtml = o.html3.replace("{$sum}", strSum);
strSum++;
PropertyHtml = PropertyHtml.replace("{$searchName}", o.PropertyName);
PropertyHtml = PropertyHtml.replace("{$searchKeyword}", PropertyList);
$(o.htmlId3).append(PropertyHtml);
}
//排序
if (o.order == true) {
if(o.orderList+"a"!="a"){
var orderList_arr = o.orderList.split(",");
if (orderList_arr.length > 0) {
strHtml = "";
var orderHtml = o.html4.replace("{$sum}", strSum);
strSum++;
orderHtml = orderHtml.replace("{$searchName}", o.orderName);
for (var i = 0; i < orderList_arr.length; i++) {
var orderList_arr2 = orderList_arr[i].split("|");
if (orderList_arr2[1] == "time" && GetOrder == "1") {
var ThisUrl = o.url.replace("{$order}", "2");
ThisUrl = MM_replace_link(ThisUrl,6);
strHtml += '' + orderList_arr2[0] + '';
} else if (orderList_arr2[1] == "time" && GetOrder == "2") {
var ThisUrl = o.url.replace("{$order}", "1");
ThisUrl = MM_replace_link(ThisUrl,6);
strHtml += '' + orderList_arr2[0] + '';
} else if (orderList_arr2[1] == "price" && GetOrder == "3") {
var ThisUrl = o.url.replace("{$order}", "4");
ThisUrl = MM_replace_link(ThisUrl,6);
strHtml += '' + orderList_arr2[0] + '';
} else if (orderList_arr2[1] == "price" && GetOrder == "4") {
var ThisUrl = o.url.replace("{$order}", "3");
ThisUrl = MM_replace_link(ThisUrl,6);
strHtml += '' + orderList_arr2[0] + '';
} else if (orderList_arr2[1] == "sales" && GetOrder == "5") {
var ThisUrl = o.url.replace("{$order}", "6");
ThisUrl = MM_replace_link(ThisUrl,6);
strHtml += '' + orderList_arr2[0] + '';
} else if (orderList_arr2[1] == "sales" && GetOrder == "6") {
var ThisUrl = o.url.replace("{$order}", "5");
ThisUrl = MM_replace_link(ThisUrl,6);
strHtml += '' + orderList_arr2[0] + '';
} else if (orderList_arr2[1] == "comment" && GetOrder == "7") {
var ThisUrl = o.url.replace("{$order}", "8");
ThisUrl = MM_replace_link(ThisUrl,6);
strHtml += '' + orderList_arr2[0] + '';
} else if (orderList_arr2[1] == "comment" && GetOrder == "8") {
var ThisUrl = o.url.replace("{$order}", "7");
ThisUrl = MM_replace_link(ThisUrl,6);
strHtml += '' + orderList_arr2[0] + '';
} else if (orderList_arr2[1] == "hits" && GetOrder == "9") {
var ThisUrl = o.url.replace("{$order}", "10");
ThisUrl = MM_replace_link(ThisUrl,6);
strHtml += '' + orderList_arr2[0] + '';
} else if (orderList_arr2[1] == "hits" && GetOrder == "10") {
var ThisUrl = o.url.replace("{$order}", "9");
ThisUrl = MM_replace_link(ThisUrl,6);
strHtml += '' + orderList_arr2[0] + '';
}
else if (orderList_arr2[1] == "default" && GetOrder == "")
{
var ThisUrl = o.url.replace("{$order}", "");
ThisUrl = MM_replace_link(ThisUrl,6);
strHtml += '' + orderList_arr2[0] + '';
}
else {
if (orderList_arr2[1] == "time") {
var ThisUrl = o.url.replace("{$order}", "2");
ThisUrl = MM_replace_link(ThisUrl,6);
} else if (orderList_arr2[1] == "price") {
var ThisUrl = o.url.replace("{$order}", "4");
ThisUrl = MM_replace_link(ThisUrl,6);
} else if (orderList_arr2[1] == "sales") {
var ThisUrl = o.url.replace("{$order}", "6");
ThisUrl = MM_replace_link(ThisUrl,6);
} else if (orderList_arr2[1] == "comment") {
var ThisUrl = o.url.replace("{$order}", "8");
ThisUrl = MM_replace_link(ThisUrl,6);
} else if (orderList_arr2[1] == "hits") {
var ThisUrl = o.url.replace("{$order}", "10");
ThisUrl = MM_replace_link(ThisUrl,6);
} else {
var ThisUrl = o.url.replace("{$order}", "");
ThisUrl = MM_replace_link(ThisUrl,6);
}
strHtml += '' + orderList_arr2[0] + '';
}
}
orderHtml = orderHtml.replace("{$searchKeyword}", strHtml);
if (orderHtml + "a" != "a") {
$(o.htmlId4).append(orderHtml);
}
}
}
}
//批量替换超链接
function MM_replace_link(str, sid) {
//栏目
if (o.class == true) {
str = str.replace("{$classid}", GetClass);
str = str.replace("classid=0", "classid=");
}
//专题
if (o.Special == true) {
str = str.replace("{$Specialid}", GetSpecial);
str = str.replace("Specialid=0", "Specialid=");
}
//自定义字段
var ZdyFieldValue = "";
var ZdyFieldValue_arr = ZdyFieldValue.split("|");
if (ZdyFieldValue_arr.length > 0) {
for (var i = 0; i < ZdyFieldValue_arr.length; i++) {
str = str.replace("{$MY_" + ZdyFieldValue_arr[i] + "}", escape(GetFields[i]));
}
}
//价格
if (o.price == true) {
str = str.replace("{$price1}", GetPrice1);
str = str.replace("{$price2}", GetPrice2);
}
//属性-推荐
if (o.Elite == true) {
str = str.replace("{$Elite}", GetElite);
}
//属性-执
if (o.Hot == true) {
str = str.replace("{$Hot}", GetHot);
}
//属性-新品
if (o.Xinpin == true) {
str = str.replace("{$Xinpin}", GetXinpin);
}
//属性-促销
if (o.Cuxiao == true) {
str = str.replace("{$Cuxiao}", GetCuxiao);
}
//排序
if (o.order == true) {
str = str.replace("{$order}", GetOrder);
}
str = str.replace("全部", "");
if(o.showList==1 && sid<5){
str = str.substring(str.indexOf("?") + 1);
str = str.replace(/&/g,"@@");
str = "javascript:void(0)\" onclick=\"MM_searchSelect(this, '" + str + "')";
}
return str;
}
//获取URL参数
function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]); return "";
}
}
})(jQuery);
function MM_searchSelect(obj, str){
$(obj).parent().find("a").removeClass("on");$(obj).addClass("on");alert($(obj).text());
alert(str);
var strArr=str.split("@@");
if (strArr.length>0){
//for(var i=0;i