Showing
7 changed files
with
133 additions
and
61 deletions
@@ -21,18 +21,19 @@ const singleDay = (req, res) => { | @@ -21,18 +21,19 @@ const singleDay = (req, res) => { | ||
21 | }; | 21 | }; |
22 | 22 | ||
23 | const getSingleData = (req, res) => { | 23 | const getSingleData = (req, res) => { |
24 | - Promise.all([singleDayModel.getResourceData(), singleDayModel.getProductData()]).then((result) => { | 24 | + Promise.all([singleDayModel.getResourceData(), singleDayModel.getTabData()]).then((result) => { |
25 | res.json(result); | 25 | res.json(result); |
26 | }); | 26 | }); |
27 | }; | 27 | }; |
28 | 28 | ||
29 | -// const getProductData = (req, res) => { | ||
30 | -// singleDayModel.getProductData().then(result => { | ||
31 | -// res.json(result); | ||
32 | -// }); | ||
33 | -// }; | 29 | +const getProductData = (req, res) => { |
30 | + singleDayModel.getProductData(req.query.tab_name).then(result => { | ||
31 | + res.json(result); | ||
32 | + }); | ||
33 | +}; | ||
34 | 34 | ||
35 | module.exports = { | 35 | module.exports = { |
36 | singleDay, | 36 | singleDay, |
37 | - getSingleData | 37 | + getSingleData, |
38 | + getProductData | ||
38 | }; | 39 | }; |
@@ -25,9 +25,10 @@ const getResourceData = () => { | @@ -25,9 +25,10 @@ const getResourceData = () => { | ||
25 | }); | 25 | }); |
26 | }; | 26 | }; |
27 | 27 | ||
28 | -const getProductData = () => { | 28 | +const getProductData = (tabName) => { |
29 | return api.get('', { | 29 | return api.get('', { |
30 | - method: '' | 30 | + method: '', |
31 | + tab_name: tabName | ||
31 | }, { | 32 | }, { |
32 | cache: true | 33 | cache: true |
33 | }).then((result) => { | 34 | }).then((result) => { |
@@ -40,7 +41,23 @@ const getProductData = () => { | @@ -40,7 +41,23 @@ const getProductData = () => { | ||
40 | }); | 41 | }); |
41 | }; | 42 | }; |
42 | 43 | ||
44 | +const getTabData = () => { | ||
45 | + return api.get('', { | ||
46 | + method: '' | ||
47 | + }, { | ||
48 | + cache: true | ||
49 | + }).then((result) => { | ||
50 | + if (result && result.code === 200) { | ||
51 | + return result; | ||
52 | + } else { | ||
53 | + logger.error('get tab data code no 200'); | ||
54 | + return []; | ||
55 | + } | ||
56 | + }); | ||
57 | +}; | ||
58 | + | ||
43 | module.exports = { | 59 | module.exports = { |
44 | getResourceData, | 60 | getResourceData, |
45 | - getProductData | 61 | + getProductData, |
62 | + getTabData | ||
46 | }; | 63 | }; |
@@ -85,6 +85,7 @@ router.post('/vip-day/msg/save.json', vipDay.beforeIn, vipDay.saveMsg); | @@ -85,6 +85,7 @@ router.post('/vip-day/msg/save.json', vipDay.beforeIn, vipDay.saveMsg); | ||
85 | router.get('/vip-day/msg/fetch.json', vipDay.fetchMsg); | 85 | router.get('/vip-day/msg/fetch.json', vipDay.fetchMsg); |
86 | router.get('/single-day', singleDay.singleDay); | 86 | router.get('/single-day', singleDay.singleDay); |
87 | router.get('/single-day/getSingleData', singleDay.getSingleData); | 87 | router.get('/single-day/getSingleData', singleDay.getSingleData); |
88 | +router.get('/single-day/getProductData', singleDay.getProductData); | ||
88 | 89 | ||
89 | 90 | ||
90 | module.exports = router; | 91 | module.exports = router; |
1 | <div class="single-day-page yoho-page"> | 1 | <div class="single-day-page yoho-page"> |
2 | <div class="banner"></div> | 2 | <div class="banner"></div> |
3 | - <div class="swiper-tab"> | ||
4 | - <ul class="swiper-wrapper"> | ||
5 | - <li class="swiper-slide">联名限定</li> | ||
6 | - <li class="swiper-slide">首发</li> | ||
7 | - <li class="swiper-slide">热卖</li> | ||
8 | - <li class="swiper-slide">明星单品</li> | ||
9 | - </ul> | ||
10 | - </div> | 3 | + <div class="swiper-tab"></div> |
11 | 4 | ||
12 | <div class="product-list"> | 5 | <div class="product-list"> |
13 | - <ul> | ||
14 | - <li> | ||
15 | - <a href=""> | ||
16 | - <img src=""/> | ||
17 | - <div class="product-info"> | ||
18 | - <h3>AVIREX L-2 PATCH YING TIGERS男款上海别注夹克</h3> | ||
19 | - <p class="prompt-info">下单后25个工作日发货</p> | ||
20 | - <p class="price"><span class="sale-price">¥589</span><span class="market-price">¥1234</span></p> | ||
21 | - <p class="info-txt">#Yoho!Buy限定联名T恤#</p> | ||
22 | - </div> | ||
23 | - </a> | ||
24 | - </li> | ||
25 | - <li> | ||
26 | - <a href=""> | ||
27 | - <img src=""/> | ||
28 | - <div class="product-info"> | ||
29 | - <h3>AVIREX L-2 PATCH YING TIGERS男款上海别注夹克</h3> | ||
30 | - <p class="prompt-info">下单后25个工作日发货</p> | ||
31 | - <p class="price"><span class="sale-price">¥589</span><span class="market-price">¥1234</span></p> | ||
32 | - <p class="info-txt">#Yoho!Buy限定联名T恤#</p> | ||
33 | - </div> | ||
34 | - </a> | ||
35 | - </li> | ||
36 | - </ul> | 6 | + <!--<ul>--> |
7 | + <!--<li>--> | ||
8 | + <!--<a href="">--> | ||
9 | + <!--<img src=""/>--> | ||
10 | + <!--<div class="product-info">--> | ||
11 | + <!--<h3>AVIREX L-2 PATCH YING TIGERS男款上海别注夹克</h3>--> | ||
12 | + <!--<p class="prompt-info">下单后25个工作日发货</p>--> | ||
13 | + <!--<p class="price"><span class="sale-price">¥589</span><span class="market-price">¥1234</span></p>--> | ||
14 | + <!--<p class="info-txt">#Yoho!Buy限定联名T恤#</p>--> | ||
15 | + <!--</div>--> | ||
16 | + <!--</a>--> | ||
17 | + <!--</li>--> | ||
18 | + <!--<li>--> | ||
19 | + <!--<a href="">--> | ||
20 | + <!--<img src=""/>--> | ||
21 | + <!--<div class="product-info">--> | ||
22 | + <!--<h3>AVIREX L-2 PATCH YING TIGERS男款上海别注夹克</h3>--> | ||
23 | + <!--<p class="prompt-info">下单后25个工作日发货</p>--> | ||
24 | + <!--<p class="price"><span class="sale-price">¥589</span><span class="market-price">¥1234</span></p>--> | ||
25 | + <!--<p class="info-txt">#Yoho!Buy限定联名T恤#</p>--> | ||
26 | + <!--</div>--> | ||
27 | + <!--</a>--> | ||
28 | + <!--</li>--> | ||
29 | + <!--</ul>--> | ||
37 | </div> | 30 | </div> |
38 | </div> | 31 | </div> |
@@ -4,25 +4,57 @@ | @@ -4,25 +4,57 @@ | ||
4 | * @date: 2016/10/17 | 4 | * @date: 2016/10/17 |
5 | */ | 5 | */ |
6 | var $ = require('yoho-jquery'), | 6 | var $ = require('yoho-jquery'), |
7 | - tip = require('../plugin/tip'), | ||
8 | Swiper = require('yoho-swiper'), | 7 | Swiper = require('yoho-swiper'), |
9 | - share = require('../common/share'), | 8 | + tip = require('../plugin/tip'), |
9 | + loading = require('../plugin/loading'), | ||
10 | banner = require('../../template/resources/banner-top.hbs'), | 10 | banner = require('../../template/resources/banner-top.hbs'), |
11 | + tab = require('../../template/activity/single-day/tab.hbs'), | ||
11 | product = require('../../template/activity/single-day/product-list.hbs'); | 12 | product = require('../../template/activity/single-day/product-list.hbs'); |
12 | 13 | ||
13 | var hash = window.location.hash.replace('#', ''); | 14 | var hash = window.location.hash.replace('#', ''); |
15 | +var $productList = $('.product-list'); | ||
16 | +var getFlag = false; | ||
14 | 17 | ||
15 | -share({ | ||
16 | - title: '有货【会员日】潮集狂欢,限时六大福利,还不快参与起来?!', | ||
17 | - link: location.href, | ||
18 | - desc: '每月28日,尽情释放!', | ||
19 | - imgUrl: 'http://img10.static.yhbimg.com/taobaocms/2016/09/23/18/010ccac2955e7e50ffb66b75110e73e3e1.png' | ||
20 | -}); | 18 | +var getProductData = function(index, tabName) { |
19 | + if (getFlag) { | ||
20 | + return; | ||
21 | + } | ||
22 | + getFlag = true; | ||
23 | + loading.showLoadingMask(); | ||
24 | + $.ajax({ | ||
25 | + type: 'GET', | ||
26 | + url: '', | ||
27 | + data: { | ||
28 | + tab_name: tabName | ||
29 | + }, | ||
30 | + success: function(data) { | ||
31 | + if (data) { | ||
32 | + $('.product-tab').eq(index).append(product(data)); | ||
33 | + } | ||
21 | 34 | ||
22 | -$.ajax({ | 35 | + getFlag = false; |
36 | + loading.hideLoadingMask(); | ||
37 | + }, | ||
38 | + error: function() { | ||
39 | + tip.show('网络断开连接了~'); | ||
40 | + loading.hideLoadingMask(); | ||
41 | + getFlag = false; | ||
42 | + } | ||
43 | + }); | ||
44 | +}; | ||
45 | + | ||
46 | +var tabName = function(index) { | ||
47 | + return $('.swiper-tab li').eq(index).html(); | ||
48 | +}; | ||
49 | + | ||
50 | +var getInitData = function() { | ||
51 | + $.ajax({ | ||
23 | type: 'GET', | 52 | type: 'GET', |
24 | url: '/activity/single-day/getSingleData', | 53 | url: '/activity/single-day/getSingleData', |
25 | success: function(data) { | 54 | success: function(data) { |
55 | + var i = 0; | ||
56 | + | ||
57 | + data[1] = ['限定名额', '首发', '热卖', '明星单品']; | ||
26 | if (data[0]) { | 58 | if (data[0]) { |
27 | $('.banner').append(banner(data[0][0])); | 59 | $('.banner').append(banner(data[0][0])); |
28 | 60 | ||
@@ -41,16 +73,41 @@ $.ajax({ | @@ -41,16 +73,41 @@ $.ajax({ | ||
41 | } | 73 | } |
42 | 74 | ||
43 | if (data[1]) { | 75 | if (data[1]) { |
44 | - $('.product-list').append(product(data[1])); | 76 | + $('.swiper-tab').append(tab(data[1])); |
77 | + | ||
78 | + new Swiper('.swiper-tab', { | ||
79 | + slidesPerView: 'auto' | ||
80 | + }); | ||
81 | + | ||
82 | + for (i; i < data[1].length; i++) { | ||
83 | + $productList.append('<ul class="product-tab"></ul>'); | ||
84 | + } | ||
85 | + | ||
86 | + getProductData(hash, tabName(hash)); | ||
87 | + | ||
88 | + $('.swiper-tab li') | ||
89 | + .eq(hash) | ||
90 | + .addClass('active') | ||
91 | + .on('click', function() { | ||
92 | + var index = $(this).index(); | ||
93 | + | ||
94 | + if ($('.product-tab').eq(index).find('li').length > 0) { | ||
95 | + return false; | ||
96 | + } else { | ||
97 | + getProductData(index, tabName(index)); | ||
45 | } | 98 | } |
99 | + }); | ||
100 | + } | ||
101 | + | ||
102 | + loading.hideLoadingMask(); | ||
46 | }, | 103 | }, |
47 | error: function() { | 104 | error: function() { |
48 | tip.show('网络断开连接了~'); | 105 | tip.show('网络断开连接了~'); |
49 | } | 106 | } |
50 | -}); | ||
51 | - | ||
52 | -$('.swiper-tab li').eq(hash).addClass('active'); | 107 | + }); |
108 | +}; | ||
53 | 109 | ||
54 | -new Swiper('.swiper-tab', { | ||
55 | - slidesPerView: 'auto' | 110 | +$(function() { |
111 | + loading.showLoadingMask(); | ||
112 | + getInitData(); | ||
56 | }); | 113 | }); |
1 | -<ul> | ||
2 | - {{#each data}} | 1 | +{{#each data}} |
3 | <li> | 2 | <li> |
4 | <a href="{{url}}"> | 3 | <a href="{{url}}"> |
5 | <img src="{{image src 274 368}}"/> | 4 | <img src="{{image src 274 368}}"/> |
@@ -11,5 +10,4 @@ | @@ -11,5 +10,4 @@ | ||
11 | </div> | 10 | </div> |
12 | </a> | 11 | </a> |
13 | </li> | 12 | </li> |
14 | - {{/each}} | ||
15 | -</ul> | 13 | +{{/each}} |
-
Please register or login to post a comment