|
|
/**
|
|
|
* 单品日
|
|
|
* @author: wsl<shuiling.wang@yoho.cn>
|
|
|
* @date: 2016/10/17
|
|
|
*/
|
|
|
|
|
|
var $ = require('yoho-jquery'),
|
|
|
Swiper = require('yoho-swiper'),
|
|
|
tip = require('../plugin/tip'),
|
|
|
loading = require('../plugin/loading'),
|
|
|
lazyload = require('yoho-jquery-lazyload'),
|
|
|
banner = require('../../template/resources/banner-top.hbs'),
|
|
|
tab = require('../../template/activity/single-day/tab.hbs'),
|
|
|
product = require('../../template/activity/single-day/product-list.hbs');
|
|
|
|
|
|
var $productList = $('.product-list');
|
|
|
var getFlag = false;
|
|
|
|
|
|
var getProductData = function(index, tabName) {
|
|
|
if (getFlag) {
|
|
|
return;
|
|
|
}
|
|
|
getFlag = true;
|
|
|
loading.showLoadingMask();
|
|
|
$.ajax({
|
|
|
type: 'GET',
|
|
|
url: '/activity/single-day/getProductData',
|
|
|
data: {
|
|
|
tab_name: tabName
|
|
|
},
|
|
|
success: function(data) {
|
|
|
var $productTab = $('.product-tab');
|
|
|
|
|
|
if (data) {
|
|
|
$productTab.eq(index).append(product(data));
|
|
|
}
|
|
|
|
|
|
$productTab.hide().eq(index).show();
|
|
|
|
|
|
lazyload($('img.lazy'));
|
|
|
getFlag = false;
|
|
|
loading.hideLoadingMask();
|
|
|
},
|
|
|
error: function() {
|
|
|
tip.show('网络断开连接了~');
|
|
|
loading.hideLoadingMask();
|
|
|
getFlag = false;
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
var tabName = function(index) {
|
|
|
return $('.swiper-tab li').eq(index).html();
|
|
|
};
|
|
|
|
|
|
var getInitData = function() {
|
|
|
$.ajax({
|
|
|
type: 'GET',
|
|
|
url: '/activity/single-day/getSingleData',
|
|
|
success: function(data) {
|
|
|
var i = 0, $swiperTab, $productTab;
|
|
|
var tabNum = window.queryString.tabNum ? window.queryString.tabNum - 1 : 0;
|
|
|
|
|
|
if (data[0]) {
|
|
|
$('.banner').append(banner(data[0][0]));
|
|
|
|
|
|
if ($('.banner-swiper').find('li').size() > 1) {
|
|
|
new Swiper('.banner-swiper', {
|
|
|
lazyLoading: true,
|
|
|
lazyLoadingInPrevNext: true,
|
|
|
loop: true,
|
|
|
autoplay: 3000,
|
|
|
autoplayDisableOnInteraction: false,
|
|
|
paginationClickable: true,
|
|
|
slideElement: 'li',
|
|
|
pagination: '.banner-top .pagination-inner'
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (data[1]) {
|
|
|
$('.swiper-tab').append(tab(data[1]));
|
|
|
|
|
|
$swiperTab = $('.swiper-tab li');
|
|
|
|
|
|
new Swiper('.swiper-tab', {
|
|
|
slidesPerView: 'auto'
|
|
|
});
|
|
|
|
|
|
for (i; i < data[1].length; i++) {
|
|
|
$productList.append('<ul class="product-tab"></ul>');
|
|
|
}
|
|
|
|
|
|
$productTab = $('.product-tab');
|
|
|
|
|
|
getProductData(tabNum, tabName(tabNum));
|
|
|
$swiperTab.eq(tabNum).addClass('active');
|
|
|
|
|
|
$swiperTab.on('click', function() {
|
|
|
var index = $(this).index();
|
|
|
|
|
|
$swiperTab.removeClass('active').eq(index).addClass('active');
|
|
|
|
|
|
if ($productTab.eq(index).find('li').length > 0) {
|
|
|
$productTab.hide().eq(index).show();
|
|
|
} else {
|
|
|
getProductData(index, tabName(index));
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
loading.hideLoadingMask();
|
|
|
},
|
|
|
error: function() {
|
|
|
tip.show('网络断开连接了~');
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
require('../common');
|
|
|
require('../common/share');
|
|
|
|
|
|
$(function() {
|
|
|
loading.showLoadingMask();
|
|
|
getInitData();
|
|
|
}); |
...
|
...
|
|