|
|
/**
|
|
|
* 商品列表页
|
|
|
* @author: xuqi<qi.xu@yoho.cn>
|
|
|
* @date: 2015/10/20
|
|
|
*/
|
|
|
|
|
|
let $ = require('yoho-jquery'),
|
|
|
Hammer = require('yoho-hammer'),
|
|
|
ellipsis = require('yoho-mlellipsis'),
|
|
|
lazyLoad = require('yoho-jquery-lazyload');
|
|
|
|
|
|
// 品牌页参数
|
|
|
let $brandHeader = $('#brand-header'),
|
|
|
$introBox = $('#intro-box');
|
|
|
|
|
|
let filter = require('plugin/filter');
|
|
|
|
|
|
let writeSearch = require('./write-search');
|
|
|
|
|
|
let tip = require('plugin/tip');
|
|
|
let loading = require('plugin/loading');
|
|
|
|
|
|
let $goodsContainer = $('#goods-container'),
|
|
|
$defaultgc = $goodsContainer.children('.default-goods'),
|
|
|
$ngc = $goodsContainer.children('.new-goods'),
|
|
|
$sgc = $goodsContainer.children('.sale-goods'),
|
|
|
$pgc = $goodsContainer.children('.price-goods'),
|
|
|
$dgc = $goodsContainer.children('.discount-goods'),
|
|
|
$popularity = $goodsContainer.children('.popularity-goods');
|
|
|
|
|
|
let winH = $(window).height();
|
|
|
|
|
|
window.$ = $;
|
|
|
let $input = $('#search-input').find('input[name="query"]'),
|
|
|
$clear = $('#search-input .clear-input'),
|
|
|
$buriedpoint = $('.buriedpoint'),
|
|
|
$search = $('#search'),
|
|
|
$dropList = $('.drop-list'),
|
|
|
$searchDivide = $('.search-divide');
|
|
|
|
|
|
let shopId, sort, brand, outlets, app_type, age_level, msort, misort, coin, app_version, students, couponId, searchFrom;
|
|
|
let size, color, style, standard, gender, price, p_d, oldquery, query, limited, specialoffer, specialsale_id, promotion;
|
|
|
let couponCode, categoryId;
|
|
|
|
|
|
// 默认筛选条件
|
|
|
let defaultOpt = require('common/query-param');
|
|
|
|
|
|
require('common');
|
|
|
|
|
|
// 首屏加载标志
|
|
|
let firstScreen = $('.default-goods').children().size() > 0;
|
|
|
let isRecYas = window.queryString.needSuggestion === 'Y' || $('.word-content').length ? 'Y' : 'N'; // 是否是关键词
|
|
|
|
|
|
let $listNav = $('#list-nav'),
|
|
|
|
|
|
// 导航数据信息
|
|
|
navInfo = {
|
|
|
price: {
|
|
|
order: 1,
|
|
|
reload: true,
|
|
|
page: 0,
|
|
|
end: false
|
|
|
},
|
|
|
discount: {
|
|
|
order: 1,
|
|
|
reload: true,
|
|
|
page: 0,
|
|
|
end: false
|
|
|
},
|
|
|
default: {
|
|
|
order: 0,
|
|
|
reload: true,
|
|
|
page: 0,
|
|
|
end: false
|
|
|
},
|
|
|
new: {
|
|
|
order: 0,
|
|
|
reload: true,
|
|
|
page: 0,
|
|
|
end: false
|
|
|
},
|
|
|
sale: {
|
|
|
order: 0,
|
|
|
reload: true,
|
|
|
page: 0,
|
|
|
end: false
|
|
|
},
|
|
|
popularity: {
|
|
|
order: 0,
|
|
|
reload: true,
|
|
|
page: 0,
|
|
|
end: false
|
|
|
}
|
|
|
},
|
|
|
$pre = $listNav.find('.active'), // 纪录进入筛选前的active项,初始为选中项
|
|
|
searching,
|
|
|
btnIntroHammer,
|
|
|
introHammer,
|
|
|
brandColHammer;
|
|
|
|
|
|
let C_ID, RES_QTY, argument, optype, filext = {};
|
|
|
|
|
|
let category = $('#category-point').val();
|
|
|
|
|
|
let noResultHbs = require('product/search/no-result-new.hbs');
|
|
|
|
|
|
C_ID = window._ChannelVary[window.cookie('_Channel')];
|
|
|
|
|
|
// 首屏无数据
|
|
|
if (!firstScreen) {
|
|
|
$goodsContainer.html(noResultHbs());
|
|
|
window.rePosFooter();
|
|
|
}
|
|
|
|
|
|
ellipsis.init();
|
|
|
|
|
|
// pageCache 获取是否收藏
|
|
|
(function() {
|
|
|
if ($('.domain').val()) {
|
|
|
$.ajax({
|
|
|
url: '/product/index/brandFav',
|
|
|
data: {
|
|
|
domain: $('.domain').val()
|
|
|
},
|
|
|
dataType: 'json',
|
|
|
success: function(data) {
|
|
|
if (data.data) {
|
|
|
$('.brand-header .btn-col').addClass('coled');
|
|
|
}
|
|
|
},
|
|
|
error: function() {
|
|
|
tip.show('网络断开连接了~');
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
}());
|
|
|
|
|
|
// 搜索输入联动
|
|
|
function inputAction() {
|
|
|
let $searchAssociate = $('.search-associate');
|
|
|
let $icon = $('.search-icon');
|
|
|
let $searchItems = $('.search-items');
|
|
|
|
|
|
$input.on('input', function() {
|
|
|
if ($input.val() === '') {
|
|
|
$icon.css('color', '#b2b2b2');
|
|
|
$clear.addClass('hide');
|
|
|
$searchAssociate.html('');
|
|
|
$searchItems.show();
|
|
|
$searchAssociate.hide();
|
|
|
} else {
|
|
|
$icon.css('color', '#666');
|
|
|
$clear.removeClass('hide');
|
|
|
$searchAssociate.show();
|
|
|
}
|
|
|
|
|
|
// 联动搜索
|
|
|
$.ajax({
|
|
|
url: '/product/search/fuzzyDatas',
|
|
|
data: {
|
|
|
keyword: $input.val()
|
|
|
},
|
|
|
dataType: 'json',
|
|
|
success: function(data) {
|
|
|
let ajaxHtml = '';
|
|
|
let i;
|
|
|
|
|
|
if (data.length > 0) {
|
|
|
for (i = 0; i < data.length; i++) {
|
|
|
ajaxHtml += '<li><span class="keyword">' + data[i].keyword + '</span><span class="count">' +
|
|
|
data[i].count + ' items<i class="iconfont"></i></span></li>';
|
|
|
}
|
|
|
|
|
|
$searchAssociate.html(ajaxHtml);
|
|
|
$searchItems.hide();
|
|
|
} else {
|
|
|
$searchAssociate.html('');
|
|
|
}
|
|
|
|
|
|
$searchAssociate.find('li').on('touchend', function() {
|
|
|
$buriedpoint.val($(this).find('.keyword').html());
|
|
|
$search.closest('form').submit();
|
|
|
});
|
|
|
},
|
|
|
error: function() {
|
|
|
tip.show('网络断开连接了~');
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
|
|
|
inputAction();
|
|
|
|
|
|
$clear.on('touchend', function() {
|
|
|
$input.val('').trigger('input');
|
|
|
});
|
|
|
|
|
|
/**
|
|
|
* 手动触发搜索
|
|
|
*/
|
|
|
$search.on('touchend', function() {
|
|
|
$(this).closest('form').submit();
|
|
|
return false;
|
|
|
});
|
|
|
|
|
|
/**
|
|
|
* 获取url参数
|
|
|
*/
|
|
|
function getQueryString(name) {
|
|
|
let reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
|
|
|
let r = decodeURI(window.location.search).substr(1).match(reg);
|
|
|
|
|
|
if (r !== null) {
|
|
|
return decodeURIComponent(r[2]);
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
shopId = getQueryString('shop_id');
|
|
|
sort = getQueryString('sort');
|
|
|
outlets = getQueryString('outlets');
|
|
|
age_level = getQueryString('ageLevel');
|
|
|
app_type = getQueryString('app_type');
|
|
|
msort = getQueryString('msort');
|
|
|
misort = getQueryString('misort');
|
|
|
coin = getQueryString('coin');
|
|
|
app_version = getQueryString('app_version') || getQueryString('appVersion');
|
|
|
size = getQueryString('size');
|
|
|
color = getQueryString('color');
|
|
|
style = getQueryString('style');
|
|
|
standard = getQueryString('standard');
|
|
|
gender = getQueryString('gender');
|
|
|
price = getQueryString('price');
|
|
|
p_d = getQueryString('p_d');
|
|
|
brand = getQueryString('brand');
|
|
|
oldquery = getQueryString('query');
|
|
|
query = $('.query-param[data-attr="query"]').val() || oldquery;
|
|
|
limited = getQueryString('limited');
|
|
|
specialoffer = getQueryString('specialoffer');
|
|
|
specialsale_id = getQueryString('specialsale_id');
|
|
|
promotion = getQueryString('promotion');
|
|
|
students = getQueryString('students');
|
|
|
couponId = getQueryString('coupon_id');
|
|
|
couponCode = getQueryString('coupon_code');
|
|
|
searchFrom = getQueryString('from');
|
|
|
categoryId = getQueryString('categoryId');
|
|
|
|
|
|
if ($defaultgc.children().length > 0) {
|
|
|
let fsgcgoods = [],
|
|
|
firstop,
|
|
|
firstyasparm = {};
|
|
|
|
|
|
$defaultgc.find('.good-info').each(function() {
|
|
|
let fsgcgood = $(this).data('good-id');
|
|
|
|
|
|
if (fsgcgood) {
|
|
|
fsgcgoods.push(fsgcgood);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
if (category) {
|
|
|
firstop = 'YB_CATEGORY_GOODS_LIST_L';
|
|
|
firstyasparm = Object.assign(firstyasparm, {
|
|
|
CATEGORY_ID: window.queryString.msort || window.queryString.sort || ''
|
|
|
});
|
|
|
} else {
|
|
|
firstop = 'YB_KEYWORD_GOODS_LIST_L';
|
|
|
firstyasparm = Object.assign(firstyasparm, {
|
|
|
KEYWORD: query || '',
|
|
|
IS_REC: isRecYas
|
|
|
});
|
|
|
}
|
|
|
|
|
|
firstyasparm = Object.assign(firstyasparm, {
|
|
|
C_ID: C_ID,
|
|
|
RES_QTY: $defaultgc.children().length,
|
|
|
PRD_LIST: JSON.stringify(fsgcgoods).replace(/\[|\]/g, ''),
|
|
|
PAGE_NUM: 1,
|
|
|
FILTER_VALUE: '',
|
|
|
SORT_TYPE: 'default'
|
|
|
});
|
|
|
|
|
|
setTimeout(function() {
|
|
|
if (window._yas && window._yas.sendCustomInfo) {
|
|
|
window._yas.sendCustomInfo({
|
|
|
op: firstop,
|
|
|
param: JSON.stringify(firstyasparm)
|
|
|
}, true);
|
|
|
}
|
|
|
}, 200);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 筛选注册的回调,筛选子项点击后逻辑
|
|
|
* 需要执行search的场景:1.点选筛选项;2.relaod为true时切换导航;3.下拉加载
|
|
|
* @param opt {type, id}
|
|
|
*/
|
|
|
function search(opt) {
|
|
|
let setting = {},
|
|
|
ext,
|
|
|
att,
|
|
|
nav,
|
|
|
navType,
|
|
|
page,
|
|
|
$this,
|
|
|
$title,
|
|
|
params;
|
|
|
|
|
|
if (searching) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (opt) {
|
|
|
// 筛选项变更则重置reload为true
|
|
|
for (att in navInfo) {
|
|
|
if (navInfo.hasOwnProperty(att)) {
|
|
|
navInfo[att].reload = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 处理active状态
|
|
|
$listNav.children('.active').removeClass('active');
|
|
|
$pre.addClass('active');
|
|
|
switch (opt.type) {
|
|
|
case 'shop_id':
|
|
|
ext = {
|
|
|
shop_id: opt.id
|
|
|
};
|
|
|
break;
|
|
|
case 'gender':
|
|
|
ext = {
|
|
|
gender: opt.id
|
|
|
};
|
|
|
break;
|
|
|
case 'brand':
|
|
|
ext = {
|
|
|
brand: opt.id
|
|
|
};
|
|
|
break;
|
|
|
case 'sort':
|
|
|
ext = {
|
|
|
sort: opt.id
|
|
|
};
|
|
|
break;
|
|
|
case 'color':
|
|
|
ext = {
|
|
|
color: opt.id
|
|
|
};
|
|
|
break;
|
|
|
case 'ageLevel':
|
|
|
ext = {
|
|
|
age_level: opt.id
|
|
|
};
|
|
|
break;
|
|
|
case 'size':
|
|
|
ext = {
|
|
|
size: opt.id
|
|
|
};
|
|
|
break;
|
|
|
case 'price':
|
|
|
ext = {
|
|
|
price: opt.id
|
|
|
};
|
|
|
break;
|
|
|
case 'discount':
|
|
|
ext = {
|
|
|
discount: opt.id
|
|
|
};
|
|
|
break;
|
|
|
case 'outlets':
|
|
|
ext = {
|
|
|
outlets: opt.id
|
|
|
};
|
|
|
break;
|
|
|
case 'p_d':
|
|
|
ext = {
|
|
|
p_d: opt.id
|
|
|
};
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
|
|
|
$.extend(filext, ext);
|
|
|
$.extend(defaultOpt, ext); // 扩展筛选项
|
|
|
}
|
|
|
|
|
|
// 导航类别
|
|
|
if ($pre.hasClass('new')) {
|
|
|
navType = 'new';
|
|
|
} else if ($pre.hasClass('price')) {
|
|
|
navType = 'price';
|
|
|
} else if ($pre.hasClass('discount')) {
|
|
|
navType = 'discount';
|
|
|
} else if ($pre.hasClass('default')) {
|
|
|
navType = 'default';
|
|
|
} else if ($pre.hasClass('sale')) {
|
|
|
navType = 'sale';
|
|
|
} else if ($pre.hasClass('popularity')) {
|
|
|
navType = 'popularity';
|
|
|
}
|
|
|
|
|
|
nav = navInfo[navType];
|
|
|
|
|
|
page = nav.page + 1;
|
|
|
|
|
|
if (nav.reload) {
|
|
|
page = 1;
|
|
|
} else if (nav.end) {
|
|
|
// 不需要重新加载并且数据请求结束
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
params = {
|
|
|
type: navType,
|
|
|
order: nav.order,
|
|
|
page: page,
|
|
|
noLazy: true
|
|
|
};
|
|
|
|
|
|
if (shopId) {
|
|
|
params.shop_id = shopId;
|
|
|
}
|
|
|
|
|
|
if (age_level) {
|
|
|
params.age_level = age_level;
|
|
|
}
|
|
|
|
|
|
if (sort) {
|
|
|
params.sort = sort;
|
|
|
}
|
|
|
|
|
|
if (brand) {
|
|
|
params.brand = brand;
|
|
|
}
|
|
|
|
|
|
if (outlets) {
|
|
|
params.outlets = outlets;
|
|
|
}
|
|
|
|
|
|
if (app_type) {
|
|
|
params.app_type = app_type;
|
|
|
}
|
|
|
|
|
|
if (msort) {
|
|
|
params.msort = msort;
|
|
|
}
|
|
|
|
|
|
if (misort) {
|
|
|
params.misort = misort;
|
|
|
}
|
|
|
|
|
|
if (coin) {
|
|
|
params.coin = coin;
|
|
|
}
|
|
|
|
|
|
if (app_version) {
|
|
|
params.app_version = app_version;
|
|
|
}
|
|
|
|
|
|
if (size) {
|
|
|
params.size = size;
|
|
|
}
|
|
|
|
|
|
if (color) {
|
|
|
params.color = color;
|
|
|
}
|
|
|
|
|
|
if (style) {
|
|
|
params.style = style;
|
|
|
}
|
|
|
|
|
|
if (standard) {
|
|
|
params.standard = standard;
|
|
|
}
|
|
|
|
|
|
if (gender) {
|
|
|
params.gender = gender;
|
|
|
}
|
|
|
|
|
|
if (price) {
|
|
|
params.price = price;
|
|
|
}
|
|
|
|
|
|
if (p_d) {
|
|
|
params.p_d = p_d;
|
|
|
}
|
|
|
|
|
|
if (query) {
|
|
|
params.query = query;
|
|
|
}
|
|
|
|
|
|
if (limited) {
|
|
|
params.limited = limited;
|
|
|
}
|
|
|
|
|
|
if (specialoffer) {
|
|
|
params.specialoffer = specialoffer;
|
|
|
}
|
|
|
|
|
|
if (specialsale_id) {
|
|
|
params.specialsale_id = specialsale_id;
|
|
|
}
|
|
|
|
|
|
if (promotion) {
|
|
|
params.promotion = promotion;
|
|
|
}
|
|
|
|
|
|
if (students) {
|
|
|
params.students = students;
|
|
|
}
|
|
|
|
|
|
if (couponId) {
|
|
|
params.coupon_id = couponId;
|
|
|
}
|
|
|
|
|
|
if (couponCode) {
|
|
|
params.coupon_code = couponCode;
|
|
|
}
|
|
|
|
|
|
if (searchFrom) {
|
|
|
params.from = searchFrom;
|
|
|
}
|
|
|
|
|
|
if (categoryId) {
|
|
|
params.categoryId = categoryId;
|
|
|
}
|
|
|
|
|
|
$.extend(setting, defaultOpt, params, {
|
|
|
currentUrl: location.pathname
|
|
|
});
|
|
|
searching = true;
|
|
|
loading.showLoadingMask();
|
|
|
|
|
|
argument = setting;
|
|
|
|
|
|
$searchDivide.removeClass('hide');
|
|
|
|
|
|
$.ajax({
|
|
|
type: 'GET',
|
|
|
url: location.protocol + '//m.yohobuy.com/product/search/category',
|
|
|
data: setting,
|
|
|
xhrFields: {
|
|
|
withCredentials: true
|
|
|
},
|
|
|
success: function(data) {
|
|
|
let num,
|
|
|
$container,
|
|
|
goodIds = [],
|
|
|
yasparm,
|
|
|
PRD_LIST;
|
|
|
|
|
|
switch (navType) {
|
|
|
case 'new':
|
|
|
$container = $ngc;
|
|
|
break;
|
|
|
case 'price':
|
|
|
$container = $pgc;
|
|
|
break;
|
|
|
case 'discount':
|
|
|
$container = $dgc;
|
|
|
break;
|
|
|
case 'default':
|
|
|
$container = $defaultgc;
|
|
|
break;
|
|
|
case 'popularity':
|
|
|
$container = $popularity;
|
|
|
break;
|
|
|
case 'sale':
|
|
|
$container = $sgc;
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
yasparm = {
|
|
|
C_ID: C_ID,
|
|
|
PAGE_NUM: setting.page,
|
|
|
SORT_TYPE: setting.type,
|
|
|
FILTER_VALUE: opt ? JSON.stringify(filext).replace(/\{|\}|\"/g, '') : ''
|
|
|
};
|
|
|
|
|
|
if (category) {
|
|
|
optype = 'YB_CATEGORY_GOODS_LIST_L';
|
|
|
yasparm = Object.assign(yasparm, {
|
|
|
CATEGORY_ID: window.queryString.msort || window.queryString.sort || ''
|
|
|
});
|
|
|
} else {
|
|
|
optype = 'YB_KEYWORD_GOODS_LIST_L';
|
|
|
yasparm = Object.assign(yasparm, {
|
|
|
KEYWORD: setting.query || '',
|
|
|
IS_REC: isRecYas
|
|
|
});
|
|
|
}
|
|
|
|
|
|
if (data === '' || (data.list && data.list.length <= 0) || data.length === 0) {
|
|
|
nav.end = true;
|
|
|
if (nav.reload && !firstScreen) {
|
|
|
if (data.total === 0) {
|
|
|
$container.html(noResultHbs());
|
|
|
}
|
|
|
|
|
|
yasparm = Object.assign(yasparm, {
|
|
|
PRD_LIST: '',
|
|
|
RES_QTY: 0
|
|
|
});
|
|
|
|
|
|
setTimeout(function() {
|
|
|
if (window._yas && window._yas.sendCustomInfo) {
|
|
|
window._yas.sendCustomInfo({
|
|
|
op: optype,
|
|
|
param: JSON.stringify(yasparm)
|
|
|
}, true);
|
|
|
}
|
|
|
}, 200);
|
|
|
}
|
|
|
} else {
|
|
|
if (nav.reload) {
|
|
|
$container.html(data);
|
|
|
num = $container.find('.good-info').length;
|
|
|
|
|
|
lazyLoad($container.find('.lazy'));
|
|
|
|
|
|
RES_QTY = $container.find('.total').data('id');
|
|
|
|
|
|
$container.find('.good-info').each(function() {
|
|
|
let goodid = $(this).data('good-id');
|
|
|
|
|
|
if (goodid) {
|
|
|
goodIds.push(goodid);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
PRD_LIST = JSON.stringify(goodIds).replace(/\[|\]/g, '');
|
|
|
|
|
|
yasparm = Object.assign(yasparm, {
|
|
|
PRD_LIST: PRD_LIST,
|
|
|
RES_QTY: RES_QTY
|
|
|
});
|
|
|
|
|
|
setTimeout(function() {
|
|
|
if (window._yas && window._yas.sendCustomInfo) {
|
|
|
window._yas.sendCustomInfo({
|
|
|
op: optype,
|
|
|
param: JSON.stringify(yasparm)
|
|
|
}, true);
|
|
|
}
|
|
|
}, 200);
|
|
|
} else {
|
|
|
num = $container.find('.good-info').length;
|
|
|
|
|
|
$container.append(data);
|
|
|
|
|
|
if ($container.find('.total')[1]) {
|
|
|
$container.find('.total').eq(1).remove();
|
|
|
}
|
|
|
|
|
|
RES_QTY = $container.find('.total').data('id');
|
|
|
|
|
|
$container.find('.good-info:gt(' + (num - 1) + ')').each(function() {
|
|
|
let goodid = $(this).data('good-id');
|
|
|
|
|
|
if (goodid) {
|
|
|
goodIds.push(goodid);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
PRD_LIST = JSON.stringify(goodIds).replace(/\[|\]/g, '');
|
|
|
|
|
|
yasparm = Object.assign(yasparm, {
|
|
|
PRD_LIST: PRD_LIST,
|
|
|
RES_QTY: RES_QTY
|
|
|
});
|
|
|
|
|
|
setTimeout(function() {
|
|
|
if (window._yas && window._yas.sendCustomInfo) {
|
|
|
window._yas.sendCustomInfo({
|
|
|
op: optype,
|
|
|
param: JSON.stringify(yasparm)
|
|
|
}, true);
|
|
|
}
|
|
|
}, 200);
|
|
|
|
|
|
// lazy good-infos who append in
|
|
|
lazyLoad($container.find('.good-info:gt(' + (num - 1) + ') .lazy'));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$searchDivide.addClass('hide');
|
|
|
nav.reload = false;
|
|
|
nav.page = page;
|
|
|
|
|
|
searching = false;
|
|
|
loading.hideLoadingMask();
|
|
|
|
|
|
window.rePosFooter();
|
|
|
|
|
|
firstScreen = false;
|
|
|
|
|
|
$('.good-detail-text .name').each(function() {
|
|
|
$this = $(this);
|
|
|
$title = $this.find('a');
|
|
|
|
|
|
$title[0].mlellipsis(2);
|
|
|
});
|
|
|
|
|
|
// 用于统计点击了商品列表的第几个商品,序号从1开始计算。
|
|
|
if (window._yas) {
|
|
|
switch (navType) {
|
|
|
case 'new':
|
|
|
window._yas(1 * new Date(), '1.0.16', 'yohobuy_m', window._ozuid,
|
|
|
'', $('.new-goods .good-info .good-detail-img .good-thumb'));
|
|
|
break;
|
|
|
case 'price':
|
|
|
window._yas(1 * new Date(), '1.0.16', 'yohobuy_m', window._ozuid,
|
|
|
'', $('.price-goods .good-info .good-detail-img .good-thumb'));
|
|
|
break;
|
|
|
case 'discount':
|
|
|
window._yas(1 * new Date(), '1.0.16', 'yohobuy_m', window._ozuid,
|
|
|
'', $('.discount-goods .good-info .good-detail-img .good-thumb'));
|
|
|
break;
|
|
|
case 'default':
|
|
|
window._yas(1 * new Date(), '1.0.16', 'yohobuy_m', window._ozuid,
|
|
|
'', $('.firstscreen-goods .default-goods .good-info .good-detail-img .good-thumb'));
|
|
|
break;
|
|
|
case 'sale':
|
|
|
window._yas(1 * new Date(), '1.0.16', 'yohobuy_m', window._ozuid,
|
|
|
'', $('.sale-goods .good-info .good-detail-img .good-thumb'));
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
error: function() {
|
|
|
let $divide = $searchDivide;
|
|
|
|
|
|
$divide.html('加载失败,点击重试');
|
|
|
$divide.one('click', function() {
|
|
|
$divide.html('正在加载...');
|
|
|
nav.reload = false;
|
|
|
searching = false;
|
|
|
search();
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
require('common/suspend-cart'); // 悬浮购物车
|
|
|
/* tar add 160914 */
|
|
|
if ($brandHeader.data('isbaseshop') === true) {
|
|
|
Object.assign(defaultOpt, {shop_id: $brandHeader.data('id')});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取筛选面板数据
|
|
|
*/
|
|
|
function getFilter() {
|
|
|
let pars = {};
|
|
|
|
|
|
if (age_level) {
|
|
|
pars.age_level = age_level;
|
|
|
}
|
|
|
|
|
|
if (size) {
|
|
|
pars.size = size;
|
|
|
}
|
|
|
|
|
|
if (color) {
|
|
|
pars.color = color;
|
|
|
}
|
|
|
|
|
|
if (style) {
|
|
|
pars.style = style;
|
|
|
}
|
|
|
|
|
|
if (standard) {
|
|
|
pars.standard = standard;
|
|
|
}
|
|
|
|
|
|
if (gender) {
|
|
|
pars.gender = gender;
|
|
|
}
|
|
|
|
|
|
if (price) {
|
|
|
pars.price = price;
|
|
|
}
|
|
|
|
|
|
if (p_d) {
|
|
|
pars.p_d = p_d;
|
|
|
}
|
|
|
|
|
|
if (brand) {
|
|
|
pars.brand = brand;
|
|
|
}
|
|
|
|
|
|
if (sort) {
|
|
|
pars.sort = sort;
|
|
|
}
|
|
|
|
|
|
if (msort) {
|
|
|
pars.msort = msort;
|
|
|
}
|
|
|
|
|
|
if (misort) {
|
|
|
pars.misort = misort;
|
|
|
}
|
|
|
|
|
|
if (outlets) {
|
|
|
pars.outlets = outlets;
|
|
|
}
|
|
|
|
|
|
if (app_type) {
|
|
|
pars.app_type = app_type;
|
|
|
}
|
|
|
|
|
|
if (query) {
|
|
|
pars.query = query;
|
|
|
}
|
|
|
|
|
|
if (limited) {
|
|
|
pars.limited = limited;
|
|
|
}
|
|
|
|
|
|
if (specialoffer) {
|
|
|
pars.specialoffer = specialoffer;
|
|
|
}
|
|
|
|
|
|
if (specialsale_id) {
|
|
|
pars.specialsale_id = specialsale_id;
|
|
|
}
|
|
|
|
|
|
if (promotion) {
|
|
|
pars.promotion = promotion;
|
|
|
}
|
|
|
|
|
|
if (shopId) {
|
|
|
pars.shop_id = shopId;
|
|
|
}
|
|
|
|
|
|
if (couponId) {
|
|
|
pars.coupon_id = couponId;
|
|
|
}
|
|
|
|
|
|
if (couponCode) {
|
|
|
pars.coupon_code = couponCode;
|
|
|
}
|
|
|
|
|
|
$.extend(defaultOpt, pars);
|
|
|
$.ajax({
|
|
|
type: 'GET',
|
|
|
url: location.protocol + '//m.yohobuy.com/product/search/filter',
|
|
|
xhrFields: {
|
|
|
withCredentials: true
|
|
|
},
|
|
|
data: defaultOpt,
|
|
|
success: function(data) {
|
|
|
if (data === '') {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
$goodsContainer.append(data);
|
|
|
|
|
|
// 初始化filter&注册filter回调
|
|
|
filter.initFilter({
|
|
|
fCbFn: search,
|
|
|
hCbFn: function() {
|
|
|
|
|
|
// 切换active状态到$pre上
|
|
|
$pre.addClass('active');
|
|
|
$pre.siblings('.filter').removeClass('active');
|
|
|
}
|
|
|
});
|
|
|
loading.hideLoading();
|
|
|
filter.showFilter();
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
lazyLoad($('.lazy'));
|
|
|
|
|
|
writeSearch.bindWirteLocal($('#search-form'));
|
|
|
|
|
|
// 导航栏点击逻辑说明:
|
|
|
// 1.点击非active项时切换active状态
|
|
|
// 2.价格和折扣active状态时继续点击切换排序
|
|
|
// 3.筛选无active时点击展开筛选面板
|
|
|
// 4.筛选有active时点击隐藏筛选面板并恢复点击筛选前active项的active状态
|
|
|
// 5.当前active为筛选并且点击其他项时,隐藏筛选面板
|
|
|
|
|
|
$listNav.bind('contextmenu', function() {
|
|
|
return false;
|
|
|
});
|
|
|
|
|
|
$dropList.on('touchend', 'li', function(e) {
|
|
|
let navType,
|
|
|
nav,
|
|
|
bpIdData = $(this).attr('data-bp-id') || '',
|
|
|
$firstLiDom = $listNav.find('li.first-li-more');
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
if ($(this).hasClass('default')) {
|
|
|
navType = 'default';
|
|
|
} else {
|
|
|
navType = 'discount';
|
|
|
firstScreen = false;
|
|
|
}
|
|
|
|
|
|
if ($(this).hasClass('active')) {
|
|
|
$dropList.addClass('hide');
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
$(this).addClass('active').siblings().removeClass('active');
|
|
|
$firstLiDom.find('.nav-txt').text($(this).data('text'));
|
|
|
$firstLiDom.attr('data-bp-id', bpIdData).addClass('active').siblings().removeClass('active');
|
|
|
$listNav.find('.first-li-more').removeClass('new default sale discount').addClass(navType);
|
|
|
|
|
|
nav = navInfo[navType];
|
|
|
|
|
|
if ($(this).hasClass('asc')) {
|
|
|
nav.order = 1;
|
|
|
nav.reload = true;
|
|
|
} else {
|
|
|
nav.order = 0;
|
|
|
nav.reload = true;
|
|
|
}
|
|
|
|
|
|
$defaultgc.removeClass('hide');
|
|
|
|
|
|
$goodsContainer.children('.container:not(.hide)').addClass('hide');
|
|
|
|
|
|
switch (navType) {
|
|
|
case 'new':
|
|
|
$ngc.removeClass('hide');
|
|
|
break;
|
|
|
|
|
|
case 'price':
|
|
|
$pgc.removeClass('hide');
|
|
|
break;
|
|
|
|
|
|
case 'discount':
|
|
|
$dgc.removeClass('hide');
|
|
|
break;
|
|
|
|
|
|
case 'default':
|
|
|
$defaultgc.removeClass('hide');
|
|
|
break;
|
|
|
|
|
|
case 'popularity':
|
|
|
$popularity.removeClass('hide');
|
|
|
break;
|
|
|
|
|
|
case 'sale':
|
|
|
$sgc.removeClass('hide');
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
$pre = $firstLiDom;
|
|
|
|
|
|
if (nav.reload) {
|
|
|
$(document).trigger('shouldSendBpData', [bpIdData]);
|
|
|
search({filtering: true});
|
|
|
}
|
|
|
|
|
|
if (!$('.filter-mask').hasClass('hide')) {
|
|
|
filter.hideFilter();
|
|
|
}
|
|
|
|
|
|
$dropList.addClass('hide');
|
|
|
});
|
|
|
|
|
|
/**
|
|
|
* 顶部排序等点击事件处理
|
|
|
*/
|
|
|
$listNav.on('touchend touchcancel', function(e) {
|
|
|
let $this = $(e.target).closest('li'),
|
|
|
nav,
|
|
|
navType,
|
|
|
$active;
|
|
|
let bpIdData = $(this).find('.buriedpoint').attr('data-bp-id') || '';
|
|
|
|
|
|
if ($this.hasClass('first-li-more') && $this.hasClass('active')) {
|
|
|
$dropList.toggleClass('hide');
|
|
|
|
|
|
$this.addClass('active').siblings().removeClass('active');
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
if ($this.hasClass('filter')) {
|
|
|
|
|
|
// 筛选面板切换状态
|
|
|
if ($this.hasClass('active')) {
|
|
|
filter.hideFilter();
|
|
|
|
|
|
// 点击筛选钱的active项回复active
|
|
|
$pre.addClass('active');
|
|
|
$this.removeClass('active');
|
|
|
} else {
|
|
|
$pre = $this.siblings('.active');
|
|
|
|
|
|
$pre.removeClass('active');
|
|
|
$this.addClass('active');
|
|
|
|
|
|
if ($('.filter-body').length < 1) {
|
|
|
loading.init($('.yoho-page'));
|
|
|
loading.showLoading();
|
|
|
getFilter();
|
|
|
} else {
|
|
|
filter.showFilter();
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
|
|
|
// 判断选择navtype
|
|
|
if ($this.hasClass('new')) {
|
|
|
navType = 'new';
|
|
|
} else if ($this.hasClass('price')) {
|
|
|
navType = 'price';
|
|
|
} else if ($this.hasClass('discount')) {
|
|
|
navType = 'discount';
|
|
|
} else if ($this.hasClass('default')) {
|
|
|
navType = 'default';
|
|
|
} else if ($this.hasClass('sale')) {
|
|
|
navType = 'sale';
|
|
|
} else if ($this.hasClass('popularity')) {
|
|
|
navType = 'popularity';
|
|
|
}
|
|
|
|
|
|
nav = navInfo[navType];
|
|
|
|
|
|
if ($this.hasClass('active')) {
|
|
|
|
|
|
// 默认、最新无排序切换
|
|
|
if ($this.hasClass('default') || $this.hasClass('new') || $this.hasClass('popularity')) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if ($this.hasClass('price') || $this.hasClass('discount')) {
|
|
|
|
|
|
// 价格/折扣切换排序状态
|
|
|
$this.find('.icon > .iconfont').toggleClass('cur');
|
|
|
$pre = $this; // 更新pre为当前项
|
|
|
nav.reload = true; // 重置reload,HTML会被替换为逆序的HTML
|
|
|
nav.order = nav.order === 0 ? 1 : 0; // 切换排序
|
|
|
}
|
|
|
} else {
|
|
|
$active = $this.siblings('.active');
|
|
|
|
|
|
$pre = $this; // $pre为除筛选导航的其他导航项,若当前active的为筛选,则把$pre置为当前点击项
|
|
|
|
|
|
if ($active.hasClass('filter')) {
|
|
|
|
|
|
// 若之前active项为筛选,则隐藏筛选面板
|
|
|
filter.hideFilter();
|
|
|
} else {
|
|
|
|
|
|
// 切换container显示
|
|
|
$goodsContainer.children('.container:not(.hide)').addClass('hide');
|
|
|
|
|
|
switch (navType) {
|
|
|
case 'new':
|
|
|
$ngc.removeClass('hide');
|
|
|
break;
|
|
|
|
|
|
case 'popularity':
|
|
|
$popularity.removeClass('hide');
|
|
|
break;
|
|
|
|
|
|
case 'price':
|
|
|
$pgc.removeClass('hide');
|
|
|
break;
|
|
|
|
|
|
case 'discount':
|
|
|
$dgc.removeClass('hide');
|
|
|
break;
|
|
|
|
|
|
case 'default':
|
|
|
$defaultgc.removeClass('hide');
|
|
|
break;
|
|
|
|
|
|
case 'sale':
|
|
|
$sgc.removeClass('hide');
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$active.removeClass('active');
|
|
|
$this.addClass('active');
|
|
|
}
|
|
|
if (nav.reload) {
|
|
|
$(document).trigger('shouldSendBpData', [bpIdData]);
|
|
|
search({filtering: true});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (!$dropList.hasClass('hide')) {
|
|
|
$dropList.addClass('hide');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
function scrollHandler() {
|
|
|
|
|
|
// 当scroll到1/2$goodsContainer高度后继续请求下一页数据
|
|
|
if ($(window).scrollTop() + winH >
|
|
|
$(document).height() - 0.5 * $goodsContainer.height()) {
|
|
|
if ($('.first-li-more').hasClass('active') && navInfo.default.page === 0) {
|
|
|
navInfo.default.page = 1;
|
|
|
navInfo.default.reload = false;
|
|
|
}
|
|
|
search();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// srcoll to load more
|
|
|
$(window).scroll(function() {
|
|
|
window.requestAnimationFrame(scrollHandler);
|
|
|
});
|
|
|
|
|
|
if ($brandHeader.length > 0) {
|
|
|
|
|
|
// 品牌介绍
|
|
|
btnIntroHammer = new Hammer($brandHeader.children('.btn-intro')[0]);
|
|
|
btnIntroHammer.on('tap', function() {
|
|
|
$introBox.removeClass('hide');
|
|
|
|
|
|
// 防止混合scroll发生
|
|
|
$('body').addClass('overflow-hidden');
|
|
|
});
|
|
|
|
|
|
// 关闭品牌介绍
|
|
|
introHammer = new Hammer(document.getElementById('intro-box'));
|
|
|
introHammer.on('tap', function(e) {
|
|
|
let $this = $(e.target);
|
|
|
|
|
|
e.srcEvent.preventDefault();
|
|
|
|
|
|
// 关闭品牌介绍box
|
|
|
if ($this.closest('#brand-intro').length === 0 || $this.hasClass('close-intro')) {
|
|
|
$introBox.addClass('hide');
|
|
|
$('body').removeClass('overflow-hidden');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// 品牌收藏
|
|
|
brandColHammer = new Hammer($brandHeader.children('.btn-col')[0]);
|
|
|
brandColHammer.on('tap', function(e) {
|
|
|
let $this = $(e.target).closest('.btn-col');
|
|
|
|
|
|
let id = $brandHeader.data('id'),
|
|
|
opt;
|
|
|
|
|
|
if ($this.hasClass('coled')) {
|
|
|
opt = 'cancel';
|
|
|
} else {
|
|
|
opt = 'ok';
|
|
|
}
|
|
|
|
|
|
$.ajax({
|
|
|
type: 'GET',
|
|
|
url: location.protocol + '//m.yohobuy.com/product/opt/favoriteBrand',
|
|
|
data: {
|
|
|
id: id,
|
|
|
opt: opt,
|
|
|
type: $brandHeader.data('isbaseshop') ? 'shop' : 'brand'
|
|
|
},
|
|
|
xhrFields: {
|
|
|
withCredentials: true
|
|
|
},
|
|
|
success: function(data) {
|
|
|
if (data.code === 200) {
|
|
|
$this.toggleClass('coled');
|
|
|
|
|
|
// 提示
|
|
|
if (opt === 'ok') {
|
|
|
tip.show('添加收藏成功');
|
|
|
} else {
|
|
|
tip.show('取消收藏成功');
|
|
|
}
|
|
|
} else if (data.code === 400) {
|
|
|
location.href = data.data;// 未登录跳转登录页
|
|
|
} else {
|
|
|
tip.show(data.message);
|
|
|
}
|
|
|
},
|
|
|
error: function() {
|
|
|
tip.show('网络断开连接了~');
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
|
|
|
$listNav.on('touchstart', 'li', function() {
|
|
|
$listNav.find('li').removeClass('bytouch');
|
|
|
$(this).addClass('bytouch');
|
|
|
}).on('touchend touchcancel', 'li', function() {
|
|
|
$listNav.find('li').removeClass('bytouch');
|
|
|
});
|
|
|
|
|
|
$('#goods-container').on('click', '.good-info', function() {
|
|
|
let PRD_ID = $(this).data('good-id'),
|
|
|
PRD_NUM = $(this).index() + 1,
|
|
|
FILTER_VALUE = filext ? JSON.stringify(filext).replace(/\{|\}|\"/g, '') : '',
|
|
|
yasparms,
|
|
|
firstType;
|
|
|
|
|
|
yasparms = {
|
|
|
C_ID: C_ID,
|
|
|
PRD_ID: PRD_ID,
|
|
|
PRD_NUM: PRD_NUM,
|
|
|
PAGE_NUM: Math.ceil(PRD_NUM / 60),
|
|
|
FILTER_VALUE: FILTER_VALUE,
|
|
|
SORT_TYPE: argument ? argument.type : firstType
|
|
|
};
|
|
|
|
|
|
if (category) {
|
|
|
optype = 'YB_CATEGORY_GOODS_LIST_C';
|
|
|
yasparms = Object.assign(yasparms, {
|
|
|
CATEGORY_ID: window.queryString.msort || window.queryString.sort || ''
|
|
|
});
|
|
|
} else {
|
|
|
optype = 'YB_KEYWORD_GOODS_LIST_C';
|
|
|
yasparms = Object.assign(yasparms, {
|
|
|
KEYWORD: argument ? argument.query : query,
|
|
|
IS_REC: isRecYas
|
|
|
});
|
|
|
}
|
|
|
|
|
|
if (window._yas && window._yas.sendCustomInfo) {
|
|
|
window._yas.sendCustomInfo({
|
|
|
op: optype,
|
|
|
param: JSON.stringify(yasparms)
|
|
|
}, true);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
$('.more-shop').on('click', function() {
|
|
|
if ($(this).hasClass('down')) {
|
|
|
$('.brand-enter').css('max-height', '100%');
|
|
|
$('.more-shop').removeClass('down').find('span').html('');
|
|
|
} else {
|
|
|
$('.brand-enter').removeAttr('style');
|
|
|
$('.more-shop').addClass('down').find('span').html('');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// 筛选改为点击加载
|
|
|
// (function() {
|
|
|
// getFilter();
|
|
|
// }());
|
|
|
|
|
|
// 进入店铺埋点
|
|
|
$('.brand-way a').on('click', function() {
|
|
|
if (window._yas && window._yas.sendCustomInfo) {
|
|
|
window._yas.sendCustomInfo({
|
|
|
op: 'YB_BRAND_SHOP_C',
|
|
|
param: JSON.stringify({
|
|
|
BRAND_ID: $('.brand-enter a').data('brandid'),
|
|
|
SHOP_ID: $('.brand-enter a').data('shopid'),
|
|
|
POS_ID: 101
|
|
|
})
|
|
|
}, true);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
require('channel/maybe-like')({recpose: 100101, isExecute: true}); |
...
|
...
|
|