...
|
...
|
@@ -2,10 +2,10 @@ |
|
|
* 品牌店铺首页
|
|
|
*/
|
|
|
|
|
|
var $ = require('jquery'),
|
|
|
IScroll = require('iscroll/iscroll-probe'),
|
|
|
lazyLoad = require('yoho.lazyload'),
|
|
|
Swiper = require('yoho.iswiper'),
|
|
|
var $ = require('yoho-jquery'),
|
|
|
IScroll = require('yoho-iscroll/build/iscroll-probe'),
|
|
|
lazyLoad = require('yoho-jquery-lazyload'),
|
|
|
Swiper = require('yoho-swiper'),
|
|
|
bannerSwiper,
|
|
|
multiSwiper,
|
|
|
myScroll,
|
...
|
...
|
@@ -20,11 +20,13 @@ var $ = require('jquery'), |
|
|
$nav2 = $('#pos-list'),
|
|
|
sTop;
|
|
|
|
|
|
var tip = require('../plugin/tip'),
|
|
|
filter = require('../plugin/filter'),
|
|
|
loading = require('../plugin/loading');
|
|
|
var tip = require('../../plugin/tip'),
|
|
|
filter = require('../../plugin/filter'),
|
|
|
loading = require('../../plugin/loading');
|
|
|
|
|
|
var $subNav = $('.home-sub-nav'),
|
|
|
$collect = $('#collect'),
|
|
|
$categoryList = $('.category-list'),
|
|
|
$goodsContainer = $('#goods-container'),
|
|
|
$goodsChildren = $goodsContainer.children(),
|
|
|
$ngc = $($goodsChildren.get(0)),
|
...
|
...
|
@@ -38,12 +40,12 @@ var $subNav = $('.home-sub-nav'), |
|
|
var winH = $(window).height(),
|
|
|
noResult = '<p class="no-result">未找到相关搜索结果</p>';
|
|
|
|
|
|
//默认筛选条件
|
|
|
var defaultOpt = require('./query-param');
|
|
|
// 默认筛选条件
|
|
|
var defaultOpt = require('../../common/query-param');
|
|
|
|
|
|
var $listNav = $('#list-nav'),
|
|
|
|
|
|
//导航数据信息
|
|
|
// 导航数据信息
|
|
|
navInfo = {
|
|
|
new: {
|
|
|
order: 1,
|
...
|
...
|
@@ -76,17 +78,22 @@ var $listNav = $('#list-nav'), |
|
|
end: false
|
|
|
}
|
|
|
},
|
|
|
$pre = $listNav.find('.active'), //纪录进入筛选前的active项,初始为选中项
|
|
|
$pre = $listNav.find('.active'), // 纪录进入筛选前的active项,初始为选中项
|
|
|
searching;
|
|
|
|
|
|
var viewType = 1,// 1-首页,2-上新,3-人气
|
|
|
var viewType = 1, // 1-首页,2-上新,3-人气
|
|
|
listCount = $('.category-list li').length,
|
|
|
listModValue = 4 - listCount % 4,
|
|
|
listIndex;
|
|
|
|
|
|
require('../../common');
|
|
|
lazyLoad($('img.lazy'));
|
|
|
|
|
|
//焦点效果
|
|
|
$('.main-wrap').css({
|
|
|
position: 'static'
|
|
|
});
|
|
|
|
|
|
// 焦点效果
|
|
|
if ($('.banner-swiper').find('li').size() > 1) {
|
|
|
bannerSwiper = new Swiper('.banner-swiper', {
|
|
|
lazyLoading: true,
|
...
|
...
|
@@ -112,25 +119,25 @@ if ($('.multi-browse').find('li').size() > 1) { |
|
|
});
|
|
|
}
|
|
|
|
|
|
//根据热门品类的个数来改变样式展示
|
|
|
// 根据热门品类的个数来改变样式展示
|
|
|
//
|
|
|
if ($('.category-list li').length % 4 !== 0) {
|
|
|
if ($categoryList.find('li').length % 4 !== 0) {
|
|
|
$('.category-list li:last-child').addClass('category-list-last-li');
|
|
|
}
|
|
|
|
|
|
if ($('.category-list li').length < 4) {
|
|
|
$('.category-list').addClass('category-list-top-board');
|
|
|
$('.category-list').find('.buriedpoint').addClass('category-list-only-one-row');
|
|
|
if ($categoryList.find('li').length < 4) {
|
|
|
$categoryList.addClass('category-list-top-board');
|
|
|
$categoryList.find('.buriedpoint').addClass('category-list-only-one-row');
|
|
|
}
|
|
|
|
|
|
if ($('.category-list li').length >= 5) {
|
|
|
if ($categoryList.find('li').length >= 5) {
|
|
|
for (listIndex = listModValue; listIndex >= 0; listIndex--) {
|
|
|
$('.category-list li').eq(listCount - 4 + listIndex - 1).addClass('category-list-last-full-row');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
function getPageGoods(info) {
|
|
|
var nav,navType;
|
|
|
var nav, navType;
|
|
|
|
|
|
if (searching) {
|
|
|
return;
|
...
|
...
|
@@ -139,7 +146,7 @@ function getPageGoods(info) { |
|
|
navType = info.data.type;
|
|
|
nav = navInfo[navType];
|
|
|
|
|
|
//不需要重新加载并且数据请求结束
|
|
|
// 不需要重新加载并且数据请求结束
|
|
|
if (nav.end) {
|
|
|
|
|
|
return;
|
...
|
...
|
@@ -148,10 +155,10 @@ function getPageGoods(info) { |
|
|
searching = true;
|
|
|
$.ajax({
|
|
|
type: 'GET',
|
|
|
url: info.url,
|
|
|
url: '/product/search/search',
|
|
|
data: info.data,
|
|
|
success: function(data) {
|
|
|
if (data === ' ') {
|
|
|
if (data === '') {
|
|
|
nav.end = true;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -177,7 +184,6 @@ function getParam(req) { |
|
|
function newData(callback) {
|
|
|
var req = {};
|
|
|
|
|
|
req.url = '/index/search/search';
|
|
|
req.data = {
|
|
|
type: 'newest',
|
|
|
order: '1',
|
...
|
...
|
@@ -202,7 +208,6 @@ function newData(callback) { |
|
|
function hotData(callback) {
|
|
|
var req = {};
|
|
|
|
|
|
req.url = '/index/search/search';
|
|
|
req.data = {
|
|
|
type: 'hot',
|
|
|
order: '1',
|
...
|
...
|
@@ -234,7 +239,7 @@ function tabChange(dom, index) { |
|
|
li.addClass('color');
|
|
|
}
|
|
|
|
|
|
//首页导航
|
|
|
// 首页导航
|
|
|
$.jqtab = function(nav, posNav, main) {
|
|
|
|
|
|
$(nav + ' li, ' + posNav + ' li').not('li.all-goods').on('touchstart', function() {
|
...
|
...
|
@@ -271,8 +276,6 @@ $.jqtab = function(nav, posNav, main) { |
|
|
$.jqtab('#nav', '#pos-nav', '.main');
|
|
|
$('#wrapper').addClass('scroll-wrapper');
|
|
|
|
|
|
// lazyLoad($('img.lazy'));
|
|
|
|
|
|
myScroll = new IScroll('#wrapper', {
|
|
|
probeType: 3,
|
|
|
mouseWheel: true,
|
...
|
...
|
@@ -309,14 +312,14 @@ myScroll.on('scroll', function() { |
|
|
}
|
|
|
if (!$nav2.hasClass('hide')) {
|
|
|
$nav2.addClass('hide');
|
|
|
} //滑动距离不到导航1
|
|
|
} // 滑动距离不到导航1
|
|
|
} else if (sTop < imgH + nav1H + main1oH) {
|
|
|
if ($nav1.hasClass('hide')) {
|
|
|
$nav1.removeClass('hide');
|
|
|
}
|
|
|
if (!$nav2.hasClass('hide')) {
|
|
|
$nav2.addClass('hide');
|
|
|
}//滑动距离不到导航2
|
|
|
}// 滑动距离不到导航2
|
|
|
|
|
|
if (sTop < imgH + main1H) {
|
|
|
if (!$nav1.hasClass('fixed-top')) {
|
...
|
...
|
@@ -369,12 +372,7 @@ document.addEventListener('touchmove', function(e) { |
|
|
e.preventDefault();
|
|
|
}, false);
|
|
|
|
|
|
/*if (!isIphone) {
|
|
|
return;
|
|
|
}*/
|
|
|
|
|
|
|
|
|
//window onload 后重新refresh iscroll
|
|
|
// window onload 后重新refresh iscroll
|
|
|
$(window).load(function() {
|
|
|
myScroll && myScroll.refresh();
|
|
|
imgH = $('#nav-top').outerHeight();
|
...
|
...
|
@@ -400,16 +398,12 @@ function search(opt) { |
|
|
page;
|
|
|
|
|
|
if (searching) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (!opt.url) {
|
|
|
opt.url = '/index/search/search';
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
if (!opt.nextPage) {
|
|
|
|
|
|
//筛选项变更则重置reload为true
|
|
|
// 筛选项变更则重置reload为true
|
|
|
for (att in navInfo) {
|
|
|
if (navInfo.hasOwnProperty(att)) {
|
|
|
navInfo[att].reload = true;
|
...
|
...
|
@@ -466,11 +460,11 @@ function search(opt) { |
|
|
};
|
|
|
break;
|
|
|
}
|
|
|
$.extend(defaultOpt, ext); //扩展筛选项
|
|
|
$.extend(defaultOpt, ext); // 扩展筛选项
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//导航类别
|
|
|
// 导航类别
|
|
|
if ($pre.hasClass('new')) {
|
|
|
navType = 'newest';
|
|
|
} else if ($pre.hasClass('price')) {
|
...
|
...
|
@@ -485,7 +479,7 @@ function search(opt) { |
|
|
page = 1;
|
|
|
} else if (nav.end) {
|
|
|
|
|
|
//不需要重新加载并且数据请求结束
|
|
|
// 不需要重新加载并且数据请求结束
|
|
|
return;
|
|
|
}
|
|
|
$.extend(setting, defaultOpt, {
|
...
|
...
|
@@ -506,7 +500,7 @@ function search(opt) { |
|
|
|
|
|
$.ajax({
|
|
|
type: 'GET',
|
|
|
url: opt.url ? opt.url : '',
|
|
|
url: '/product/search/search',
|
|
|
data: setting,
|
|
|
success: function(data) {
|
|
|
var $container,
|
...
|
...
|
@@ -524,7 +518,7 @@ function search(opt) { |
|
|
break;
|
|
|
}
|
|
|
|
|
|
if (data === ' ') {
|
|
|
if (data === '') {
|
|
|
nav.end = true;
|
|
|
|
|
|
if (nav.reload) {
|
...
|
...
|
@@ -578,7 +572,7 @@ function getQueryString(name) { |
|
|
|
|
|
$.ajax({
|
|
|
type: 'GET',
|
|
|
url: '/search/filter',
|
|
|
url: '/product/search/filter',
|
|
|
data: {
|
|
|
shop_id: brand ? '' : shopId,
|
|
|
brand: brand,
|
...
|
...
|
@@ -588,12 +582,12 @@ $.ajax({ |
|
|
success: function(data) {
|
|
|
$goodsContainer.append(data);
|
|
|
|
|
|
//初始化filter&注册filter回调
|
|
|
// 初始化filter&注册filter回调
|
|
|
filter.initFilter({
|
|
|
fCbFn: search,
|
|
|
hCbFn: function() {
|
|
|
|
|
|
//切换active状态到$pre上
|
|
|
// 切换active状态到$pre上
|
|
|
$pre.addClass('active');
|
|
|
$pre.siblings('.filter').removeClass('active');
|
|
|
},
|
...
|
...
|
@@ -628,11 +622,11 @@ $subNav.on('touchend touchcancel', function(e) { |
|
|
|
|
|
if ($this.hasClass('filter')) {
|
|
|
|
|
|
//筛选面板切换状态
|
|
|
// 筛选面板切换状态
|
|
|
if ($this.hasClass('active')) {
|
|
|
filter.hideFilter();
|
|
|
|
|
|
//点击筛选钱的active项回复active
|
|
|
// 点击筛选钱的active项回复active
|
|
|
$pre.addClass('active');
|
|
|
$this.removeClass('active');
|
|
|
} else {
|
...
|
...
|
@@ -659,7 +653,7 @@ $subNav.on('touchend touchcancel', function(e) { |
|
|
|
|
|
if ($this.hasClass('active')) {
|
|
|
|
|
|
//最新无排序切换
|
|
|
// 最新无排序切换
|
|
|
if ($this.hasClass('new')) {
|
|
|
return;
|
|
|
}
|
...
|
...
|
@@ -669,9 +663,9 @@ $subNav.on('touchend touchcancel', function(e) { |
|
|
|
|
|
// 价格/折扣切换排序状态
|
|
|
$this.find('.icon > .iconfont').toggleClass('cur');
|
|
|
$pre = $this; //更新pre为当前项
|
|
|
nav.reload = true; //重置reload,HTML会被替换为逆序的HTML
|
|
|
nav.order = nav.order === 0 ? 1 : 0; //切换排序
|
|
|
$pre = $this; // 更新pre为当前项
|
|
|
nav.reload = true; // 重置reload,HTML会被替换为逆序的HTML
|
|
|
nav.order = nav.order === 0 ? 1 : 0; // 切换排序
|
|
|
|
|
|
$goodsContainer.children('.container:not(.hide)').addClass('hide');
|
|
|
|
...
|
...
|
@@ -693,15 +687,15 @@ $subNav.on('touchend touchcancel', function(e) { |
|
|
} else {
|
|
|
$active = $subNav.find('.active');
|
|
|
|
|
|
$pre = $this; //$pre为除筛选导航的其他导航项,若当前active的为筛选,则把$pre置为当前点击项
|
|
|
$pre = $this; // $pre为除筛选导航的其他导航项,若当前active的为筛选,则把$pre置为当前点击项
|
|
|
|
|
|
if ($active.hasClass('filter')) {
|
|
|
|
|
|
//若之前active项为筛选,则隐藏筛选面板
|
|
|
// 若之前active项为筛选,则隐藏筛选面板
|
|
|
filter.hideFilter();
|
|
|
} else {
|
|
|
|
|
|
//切换container显示
|
|
|
// 切换container显示
|
|
|
$goodsContainer.children('.container:not(.hide)').addClass('hide');
|
|
|
|
|
|
switch (navType) {
|
...
|
...
|
@@ -728,7 +722,6 @@ $subNav.on('touchend touchcancel', function(e) { |
|
|
type: 'shop_id',
|
|
|
id: shopId,
|
|
|
brand: brand,
|
|
|
url: '/index/search/search',
|
|
|
nextPage: false
|
|
|
});
|
|
|
}
|
...
|
...
|
@@ -741,7 +734,7 @@ function scrollHandler() { |
|
|
|
|
|
sTop = -myScroll.y;
|
|
|
|
|
|
//当scroll到1/4$goodsContainer高度后继续请求下一页数据
|
|
|
// 当scroll到1/4$goodsContainer高度后继续请求下一页数据
|
|
|
myScroll && myScroll.refresh();
|
|
|
if (sTop + winH > $('#scroller').height() - 0.25 * $goodsContainer.height() - 50) {
|
|
|
if ($pre !== undefined) {
|
...
|
...
|
@@ -749,25 +742,23 @@ function scrollHandler() { |
|
|
type: 'shop_id',
|
|
|
id: shopId,
|
|
|
brand: brand,
|
|
|
url: '/index/search/search',
|
|
|
nextPage: true
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//srcoll to load more
|
|
|
// srcoll to load more
|
|
|
$(window).scroll(function() {
|
|
|
window.requestAnimationFrame(scrollHandler);
|
|
|
});
|
|
|
|
|
|
|
|
|
//初始请求最新第一页数据
|
|
|
// 初始请求最新第一页数据
|
|
|
search({
|
|
|
type: 'shop_id',
|
|
|
id: shopId,
|
|
|
brand: brand,
|
|
|
url: '/index/search/search',
|
|
|
nextPage: false
|
|
|
});
|
|
|
|
...
|
...
|
@@ -785,7 +776,7 @@ $nav2.on('touchstart', 'li', function(e) { |
|
|
myScroll.refresh();
|
|
|
});
|
|
|
|
|
|
//底部导航点击
|
|
|
// 底部导航点击
|
|
|
function fotterClick(group) {
|
|
|
$(group + ' li').on('touchstart', function() {
|
|
|
$('.sub-group').addClass('hide');
|
...
|
...
|
@@ -813,31 +804,41 @@ $('.shop-foot-wrapper').bind('touchstart', function(e) { |
|
|
stopPropagation(e);
|
|
|
});
|
|
|
|
|
|
//收藏
|
|
|
function postCollect(info) {
|
|
|
var url = '';
|
|
|
// 店铺收藏 || 取消收藏
|
|
|
$collect.on('touchstart', function() {
|
|
|
var opt;
|
|
|
|
|
|
if (searching) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
searching = true;
|
|
|
|
|
|
$.ajax({
|
|
|
method: 'post',
|
|
|
url: info.url,
|
|
|
data: info.data,
|
|
|
if ($collect.hasClass('alreadyCollect')) {
|
|
|
opt = 'cancel';
|
|
|
} else {
|
|
|
opt = 'ok';
|
|
|
}
|
|
|
|
|
|
$.ajax({
|
|
|
type: 'POST',
|
|
|
url: '/product/opt/favoriteBrand',
|
|
|
data: {
|
|
|
id: favId ? favId : shopId,
|
|
|
appVersion: appVersion,
|
|
|
opt: opt,
|
|
|
type: 'shop'
|
|
|
},
|
|
|
success: function(data) {
|
|
|
|
|
|
if (data.code === 200) {
|
|
|
if ($('#collect').hasClass('alreadyCollect')) {
|
|
|
$('#collect').attr('class', 'notCollect');
|
|
|
if ($collect.hasClass('alreadyCollect')) {
|
|
|
$collect.attr('class', 'notCollect');
|
|
|
} else {
|
|
|
$('#collect').attr('class', 'alreadyCollect');
|
|
|
$collect.attr('class', 'alreadyCollect');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (data.code === 401) {
|
|
|
if (data.code === 400) {
|
|
|
url = data.url;
|
|
|
$('body').append('<a href=\'' + url + '\'><span class="jump-login"><span></a>');
|
|
|
|
...
|
...
|
@@ -851,38 +852,8 @@ function postCollect(info) { |
|
|
searching = false;
|
|
|
},
|
|
|
error: function() {
|
|
|
alert('网络断开连接了~');
|
|
|
tip.show('网络断开连接了~');
|
|
|
searching = false;
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
function collectShop() {
|
|
|
var qew = {};
|
|
|
|
|
|
qew.url = '/product/index/shopFav';
|
|
|
qew.data = {
|
|
|
shop_id: favId ? favId : shopId,
|
|
|
app_version: appVersion
|
|
|
};
|
|
|
postCollect(qew);
|
|
|
}
|
|
|
|
|
|
function cancelShop() {
|
|
|
var qew = {};
|
|
|
|
|
|
qew.url = '/product/index/cancelShopFav';
|
|
|
qew.data = {
|
|
|
shop_id: favId ? favId : shopId,
|
|
|
app_version: appVersion
|
|
|
};
|
|
|
postCollect(qew);
|
|
|
}
|
|
|
|
|
|
$('#collect').on('touchstart', function(e) {
|
|
|
if ($('#collect').hasClass('alreadyCollect')) {
|
|
|
cancelShop();
|
|
|
} else {
|
|
|
collectShop();
|
|
|
}
|
|
|
}); |
|
|
\ No newline at end of file |
|
|
}); |
...
|
...
|
|