Authored by 郭成尧

all-goods-tab

... ... @@ -29,7 +29,7 @@
</li>
<em>|</em>
<li class="shop-tab-nav tab-nav">
<a href="#all-goods" data-trigger="tab">全部商品</a>
<a href="#all-goods" data-trigger="tab" data-funGetFilter data-funGetGoodsList>全部商品</a>
</li>
</ul>
<div class="tab-panels">
... ... @@ -58,11 +58,11 @@
</div>
{{!--视--}}
{{!--视--}}
<div class="shop-video shop-section">
<header>
<i class="section-more iconfont">&#xe606;</i>
<h4 class="section-title">直播</h4>
<h4 class="section-title">直播</h4>
</header>
<div class="video-player">
<div class="video-poster">
... ... @@ -72,8 +72,8 @@
</div>
</div>
<div class="video-intro">
<h6 class="video-title">这是视屏标题</h6>
<p class="text-line-2">这是视屏内容这是视屏内容这是视屏内容这是视屏内容这是视屏内容这是视屏内容这是视屏内容这是视屏内容</p>
<h6 class="video-title">这是视频标题</h6>
<p class="text-line-2">视频内容视频内容视频内容视频内容视频内容视频内容视频内容视频内容</p>
</div>
</div>
... ... @@ -135,7 +135,23 @@
</div>
</div>
{{!--shop-tab: 全部商品--}}
<div id="all-goods" class="tab-panel"></div>
<div id="all-goods" class="tab-panel">
<div class="good-list-page yoho-page">
{{!--筛选tab--}}
{{> product/filter-tab}}
<div id="goods-container" class="goods-container">
<div class="firstscreen-goods container clearfix"></div>
<div class="search-divide">正在加载...</div>
<div class="default-goods container clearfix"></div>
<div class="new-goods container clearfix"></div>
<div class="sale-goods container clearfix"></div>
<div class="price-goods container clearfix hide"></div>
<div class="discount-goods container clearfix hide"></div>
{{> common/filter}}
</div>
</div>
</div>
</div>
</div>
</div>
... ...
... ... @@ -75,12 +75,23 @@ $.fn.yoTab.constructor = Tab;
$(document).on('click', '[data-trigger=tab]', function(event) {
var $nav = $(event.target);
var fun = '';
$.each($nav.data(), function(index) {
if (index.substr(0, 3) === 'fun') {
fun = index.substr(3, index.length - 3);
if ($.isFunction(Tab.prototype[fun])) {
Plugin.call($nav, fun);
}
}
});
event.preventDefault();
event.stopPropagation();
var $nav = $(event.target);
Plugin.call($nav, 'show');
});
module.exports = Tab;
... ...
// const tip = require('../plugin/tip');
const filter = require('../plugin/filter');
// const loading = require('../plugin/loading');
require('product/search/list.page.css');
require('product/shop/redshop.page.css');
require('plugin/sticky');
require('plugin/tab');
require('./shop/coupon');
let Tab = require('plugin/tab');
let defaultOpt = require('../common/query-param');
let defaultOptCopy = {};
let $goodsContainer = $('#goods-container');
let $fsgc = $goodsContainer.children('.firstscreen-goods');
let $defaultgc = $goodsContainer.children('.default-goods');
let $ngc = $goodsContainer.children('.new-goods');
let $sgc = $goodsContainer.children('.sale-goods');
let $pgc = $goodsContainer.children('.price-goods');
let $dgc = $goodsContainer.children('.discount-goods');
let $listNav = $('#list-nav'); // 筛选项列表
let $pre = $listNav.find('.active'); // 记录进入筛选前的active项,初始为选中项
let allGoodsTabClickTimes = 0;
let 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
}
};
/**
* 判断两个对象是否相等
* @param {*} a
* @param {*} b
*/
function isObjectValueEqual(a, b) {
let aProps = Object.getOwnPropertyNames(a);
let bProps = Object.getOwnPropertyNames(b);
if (aProps.length != bProps.length) { // eslint-disable-line
return false;
}
for (let i = 0; i < aProps.length; i++) {
let propName = aProps[i];
if (a[propName] !== b[propName]) {
return false;
}
}
return true;
}
/**
* 获取商品列表
*/
function getGoodsList() {
console.log('ok');
}
/**
* 加载筛选数据
*/
function getFilter() {
if (allGoodsTabClickTimes === 0 || !isObjectValueEqual(defaultOptCopy, defaultOpt)) {
// 第一次点进来或者改变了筛选参数时调用
defaultOptCopy = $.extend(true, {}, defaultOpt);
allGoodsTabClickTimes++;
$.ajax({
type: 'GET',
url: location.protocol + '//m.yohobuy.com/product/search/filter',
data: defaultOpt,
success: function(data) {
$goodsContainer.append(data);
// 初始化filter&注册filter回调
filter.initFilter({
fCbFn: getGoodsList,
hCbFn: function() {
// 切换active状态到$pre上
$pre.addClass('active');
$pre.siblings('.filter').removeClass('active');
}
});
}
});
}
}
// 绑定 getfilter 方法,在点击全部商品时调用
Tab.prototype.getfilter = getFilter;
Tab.prototype.getgoodslist = getGoodsList;
$listNav.bind('contextmenu', function() {
return false;
});
$listNav.on('touchend touchcancel', function(e) {
var $this = $(e.target).closest('li'),
nav,
navType,
$active;
var bpIdData = $(this).find('.buriedpoint').attr('data-bp-id') || '';
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');
filter.showFilter();
}
} else {
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';
}
nav = navInfo[navType];
if ($this.hasClass('active')) {
// 默认、最新无排序切换
if ($this.hasClass('default') || $this.hasClass('new')) {
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 'price':
$pgc.removeClass('hide');
break;
case 'discount':
$dgc.removeClass('hide');
break;
case 'default':
$defaultgc.removeClass('hide');
$fsgc.removeClass('hide');
break;
case 'sale':
$sgc.removeClass('hide');
break;
default:
break;
}
}
$active.removeClass('active');
$this.addClass('active');
}
if (nav.reload) {
$(document).trigger('shouldSendBpData', [bpIdData]);
getGoodsList({filtering: true});
}
}
});
... ...