|
|
/**
|
|
|
* 店铺收藏页
|
|
|
*/
|
|
|
|
|
|
var $ = require('yoho-jquery'),
|
|
|
Swiper = require('yoho-swiper'),
|
|
|
tip = require('../plugin/tip');
|
|
|
|
|
|
var searching,
|
|
|
shopId,
|
|
|
stoping,
|
|
|
navSwiper,
|
|
|
navType;
|
|
|
|
|
|
var shopNav = require('shopCollect/shop-nav.hbs'),
|
|
|
shopList = require('shopCollect/shop-list.hbs');
|
|
|
|
|
|
require('../common');
|
|
|
require('../common/share');
|
|
|
|
|
|
navType = window.queryString;
|
|
|
|
|
|
// 店铺列表数据
|
|
|
function shopListData(tabName, stoping) {
|
|
|
|
|
|
if (stoping) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
$.ajax({
|
|
|
method: 'get',
|
|
|
url: '/activity/shopList',
|
|
|
data: {
|
|
|
tabName: tabName
|
|
|
},
|
|
|
success: function(data) {
|
|
|
|
|
|
var list = shopList({
|
|
|
shopList: data
|
|
|
});
|
|
|
|
|
|
$('.shop-list').html(list);
|
|
|
|
|
|
stoping = false;
|
|
|
|
|
|
// 店铺收藏
|
|
|
$('.collect-btn').on('click', function() {
|
|
|
var opt,
|
|
|
$this = $(this);
|
|
|
|
|
|
shopId = $this.parents('.shop-info').data('id');
|
|
|
|
|
|
if (searching) {
|
|
|
return;
|
|
|
}
|
|
|
searching = true;
|
|
|
|
|
|
if ($this.hasClass('already-collect')) {
|
|
|
opt = 'cancel';
|
|
|
} else {
|
|
|
opt = 'ok';
|
|
|
}
|
|
|
|
|
|
$.ajax({
|
|
|
method: 'get',
|
|
|
url: location.protocol + '//m.yohobuy.com' + '/product/opt/favoriteBrand',
|
|
|
data: {
|
|
|
id: shopId,
|
|
|
opt: opt,
|
|
|
type: 'shop',
|
|
|
},
|
|
|
xhrFields: {
|
|
|
withCredentials: true
|
|
|
},
|
|
|
success: function(list) {
|
|
|
var url;
|
|
|
|
|
|
if (list.code === 200) {
|
|
|
if ($this.hasClass('already-collect')) {
|
|
|
$this.removeClass('already-collect');
|
|
|
tip.show('店铺取消收藏成功');
|
|
|
} else {
|
|
|
$this.addClass('already-collect');
|
|
|
tip.show('店铺收藏成功');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (list.code === 400) {
|
|
|
|
|
|
url = list.data;
|
|
|
if ($('#jump-login').length <= 0) {
|
|
|
$('body').append('<a href=\'' + url + '\'><span id="jump-login"><span></a>');
|
|
|
}
|
|
|
$('#jump-login').click();
|
|
|
}
|
|
|
searching = false;
|
|
|
},
|
|
|
error: function() {
|
|
|
tip.show('网络断开连接了~');
|
|
|
searching = false;
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
},
|
|
|
error: function() {
|
|
|
tip.show('网络断开连接了~');
|
|
|
stoping = false;
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 导航数据
|
|
|
function shopNavData() {
|
|
|
$.ajax({
|
|
|
method: 'get',
|
|
|
url: '/activity/shopNav',
|
|
|
|
|
|
success: function(data) {
|
|
|
|
|
|
var navString = shopNav({
|
|
|
navList: data
|
|
|
});
|
|
|
|
|
|
$('.shop-nav').html(navString);
|
|
|
|
|
|
// 导航滑动效果
|
|
|
navSwiper = new Swiper('.shop-nav', {
|
|
|
grabCursor: true,
|
|
|
slidesPerView: 'auto',
|
|
|
slideElement: 'li'
|
|
|
});
|
|
|
|
|
|
// 加载第一页数据
|
|
|
if (navType.id) {
|
|
|
$('.shop-nav').find('li').each(function() {
|
|
|
if (navType.id === $(this).data('type')) {
|
|
|
$(this).addClass('active');
|
|
|
shopListData($(this).data('type'));
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
$('.shop-nav').find('li').eq(0).addClass('active');
|
|
|
shopListData($('.shop-nav').find('li').eq(0).data('type'));
|
|
|
}
|
|
|
|
|
|
// 导航点击事件
|
|
|
$('.shop-nav').find('li').on('click', function() {
|
|
|
var $this = $(this),
|
|
|
tabName = $this.data('type');
|
|
|
|
|
|
if ($this.hasClass('active')) {
|
|
|
stoping = true;
|
|
|
} else {
|
|
|
stoping = false;
|
|
|
}
|
|
|
|
|
|
shopListData(tabName, stoping);
|
|
|
|
|
|
$this.addClass('active').siblings().removeClass('active');
|
|
|
});
|
|
|
|
|
|
},
|
|
|
error: function() {
|
|
|
// tip.show('网络断开连接了~');
|
|
|
$('.shop-nav').hide();
|
|
|
$('.shop-list').hide();
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
$(function() {
|
|
|
shopNavData();
|
|
|
|
|
|
if ($('.banner-swiper').find('li').size() > 1) {
|
|
|
bannerSwiper = new Swiper('.banner-swiper', {
|
|
|
lazyLoading: true,
|
|
|
lazyLoadingInPrevNext: true,
|
|
|
loop: true,
|
|
|
autoplay: 3000,
|
|
|
autoplayDisableOnInteraction: false,
|
|
|
paginationClickable: true,
|
|
|
slideElement: 'li',
|
|
|
pagination: '.banner-top .pagination-inner'
|
|
|
});
|
|
|
}
|
|
|
|
|
|
|
|
|
}); |
...
|
...
|
|