'我的收藏改为ajax分页/意见反馈功能性修改'
Showing
9 changed files
with
264 additions
and
94 deletions
@@ -18,18 +18,18 @@ class Yohobuy | @@ -18,18 +18,18 @@ class Yohobuy | ||
18 | { | 18 | { |
19 | /* 正式环境 */ | 19 | /* 正式环境 */ |
20 | 20 | ||
21 | - // const API_URL = 'http://api2.open.yohobuy.com/'; | ||
22 | - // const API_URL2 = 'http://api.open.yohobuy.com/'; | ||
23 | - // const SERVICE_URL = 'http://service.api.yohobuy.com/'; | ||
24 | - // const YOHOBUY_URL = 'http://www.yohobuy.com/'; | 21 | + const API_URL = 'http://api2.open.yohobuy.com/'; |
22 | + const API_URL2 = 'http://api.open.yohobuy.com/'; | ||
23 | + const SERVICE_URL = 'http://service.api.yohobuy.com/'; | ||
24 | + const YOHOBUY_URL = 'http://www.yohobuy.com/'; | ||
25 | 25 | ||
26 | /* 测试环境 */ | 26 | /* 测试环境 */ |
27 | - const API_URL = 'http://test2.open.yohobuy.com/'; | ||
28 | - const SERVICE_URL = 'http://test.service.api.yohobuy.com/'; | ||
29 | - const YOHOBUY_URL = 'http://www.yohobuy.com/'; | ||
30 | - const API_URL_MYCENTER = 'http://192.168.102.205:8081/api-gateway-web/'; // 我的个人中心接口URL | ||
31 | - const API_URL_SHOPINGCART = 'http://192.168.102.213:8080/api-gateway-web/'; // 我的购物车接口URL | ||
32 | - const API_URL_PRODUCTDETAIL = 'http://192.168.102.209:18080/yoho-product/'; // 商品详情页 | 27 | + // const API_URL = 'http://test2.open.yohobuy.com/'; |
28 | + // const SERVICE_URL = 'http://test.service.api.yohobuy.com/'; | ||
29 | + // const YOHOBUY_URL = 'http://www.yohobuy.com/'; | ||
30 | + // const API_URL_MYCENTER = 'http://192.168.102.205:8081/api-gateway-web/'; // 我的个人中心接口URL | ||
31 | + // const API_URL_SHOPINGCART = 'http://192.168.102.213:8080/api-gateway-web/'; // 我的购物车接口URL | ||
32 | + // const API_URL_PRODUCTDETAIL = 'http://192.168.102.209:18080/yoho-product/'; // 商品详情页 | ||
33 | 33 | ||
34 | /** | 34 | /** |
35 | * 私钥列表 | 35 | * 私钥列表 |
@@ -12,44 +12,117 @@ var diaLog = require('./dialog'); | @@ -12,44 +12,117 @@ var diaLog = require('./dialog'); | ||
12 | 12 | ||
13 | var $navLi = $('#fav-tab > li'), | 13 | var $navLi = $('#fav-tab > li'), |
14 | $favContainer = $('.fav-content > .fav-type'), | 14 | $favContainer = $('.fav-content > .fav-type'), |
15 | - $swiperList = $('.swiper-container'), | 15 | + $swiperList = '', |
16 | swiperObj = {}, | 16 | swiperObj = {}, |
17 | favTabHammer, | 17 | favTabHammer, |
18 | - favContentHammer; | 18 | + favContentHammer, |
19 | + footerH = $('#yoho-footer').height(), | ||
20 | + $loadMore = $('.fav-load-more'), | ||
21 | + $brandLoadMore = $('.fav-brand-load-more'), | ||
22 | + winH = $(window).height(), | ||
23 | + $favProductList = $('.fav-product-list'), | ||
24 | + $favBrandList = $('.fav-brand-swiper'), | ||
25 | + pageId = 1, | ||
26 | + brandPageId = 1, //收藏品牌的当前页数 | ||
27 | + lockId = true, | ||
28 | + brandLockId = true, //收藏品牌是否可下拉加载更多 | ||
29 | + brandTab = false; //当前是否停留在收藏品牌页 | ||
19 | 30 | ||
20 | function showFavTab(index) { | 31 | function showFavTab(index) { |
21 | - var i, | ||
22 | - id; | ||
23 | - | ||
24 | $navLi.filter('.active').removeClass('active'); | 32 | $navLi.filter('.active').removeClass('active'); |
25 | $navLi.eq(index).addClass('active'); | 33 | $navLi.eq(index).addClass('active'); |
26 | 34 | ||
27 | $favContainer.filter('.show').removeClass('show'); | 35 | $favContainer.filter('.show').removeClass('show'); |
28 | $favContainer.eq(index).addClass('show'); | 36 | $favContainer.eq(index).addClass('show'); |
37 | +} | ||
29 | 38 | ||
30 | - if (index === 1) { | ||
31 | - | ||
32 | - //导航 | ||
33 | - for (i = 0; i < $swiperList.length; i++) { | ||
34 | - id = $swiperList.eq(i).attr('data-id'); | ||
35 | - swiperObj[id] = new Swiper('#swiper-container-' + id, { | ||
36 | - slidesPerView: 'auto', | ||
37 | - grabCursor: true, | ||
38 | - slideElement: 'li', | ||
39 | - wrapperClass: 'swiper-wrapper-' + id, | ||
40 | - lazyLoading: true, | ||
41 | - watchSlidesVisibility: true | ||
42 | - }); | 39 | +//初始化swiper |
40 | +function initSwiper() { | ||
41 | + var i, | ||
42 | + id; | ||
43 | + | ||
44 | + $swiperList = $('.swiper-container'); | ||
45 | + for (i = 0; i < $swiperList.length; i++) { | ||
46 | + id = $swiperList.eq(i).attr('data-id'); | ||
47 | + console.log(id); | ||
48 | + | ||
49 | + if (!!swiperObj[id]) { | ||
50 | + swiperObj[id].destroy(true, true); | ||
43 | } | 51 | } |
52 | + swiperObj[id] = new Swiper('#swiper-container-' + id, { | ||
53 | + slidesPerView: 'auto', | ||
54 | + grabCursor: true, | ||
55 | + slideElement: 'li', | ||
56 | + wrapperClass: 'swiper-wrapper-' + id, | ||
57 | + lazyLoading: true, | ||
58 | + watchSlidesVisibility: true | ||
59 | + }); | ||
60 | + } | ||
61 | +} | ||
44 | 62 | ||
63 | +// 上拉加载更多 | ||
64 | +function loadData($parent, url, page) { | ||
65 | + if (url === 'favBrand') { | ||
66 | + brandLockId = true; | ||
67 | + } else { | ||
68 | + lockId = true; | ||
45 | } | 69 | } |
70 | + $.ajax({ | ||
71 | + method: 'post', | ||
72 | + url: '/home/' + url, | ||
73 | + data: { | ||
74 | + page: page | ||
75 | + }, | ||
76 | + success: function(data) { | ||
77 | + | ||
78 | + //setTimeout(function() { //模拟延时 | ||
79 | + | ||
80 | + if (url === 'favBrand') { | ||
81 | + $brandLoadMore.addClass('hide'); | ||
82 | + } else { | ||
83 | + $loadMore.addClass('hide'); | ||
84 | + } | ||
85 | + | ||
86 | + if (data === ' ') { | ||
87 | + $parent.closest('.fav-type').find('.fav-null-box').removeClass('hide'); | ||
88 | + } else if (data === 'end') { | ||
89 | + $parent.closest('.fav-type').find('.fav-load-background') | ||
90 | + .removeClass('fav-load-background').html('没有更多了'); | ||
91 | + | ||
92 | + } else if (data.length > 10) { | ||
93 | + $parent.append(data); | ||
94 | + | ||
95 | + if (url === 'favBrand') { | ||
96 | + initSwiper();//如果是收藏品牌需要初始化swiper | ||
97 | + | ||
98 | + brandLockId = false;//请求成功后解锁品牌收藏page++ | ||
99 | + } else { | ||
100 | + lockId = false;//请求成功后解锁商品收藏page++ | ||
101 | + } | ||
102 | + | ||
103 | + window.rePosFooter(); | ||
104 | + | ||
105 | + } else { | ||
106 | + return; | ||
107 | + } | ||
108 | + window.rePosFooter(); | ||
109 | + | ||
110 | + //},1000); | ||
111 | + } | ||
112 | + }); | ||
46 | } | 113 | } |
47 | 114 | ||
48 | // 如果从品牌收藏入口进入 | 115 | // 如果从品牌收藏入口进入 |
49 | if ($('#fav-tab').hasClass('brand-tab')) { | 116 | if ($('#fav-tab').hasClass('brand-tab')) { |
50 | showFavTab(1); | 117 | showFavTab(1); |
118 | + loadData($favBrandList, 'favBrand', 1); | ||
119 | + brandTab = true; | ||
120 | + window.rePosFooter(); | ||
51 | } else { | 121 | } else { |
52 | showFavTab(0); | 122 | showFavTab(0); |
123 | + loadData($favProductList, 'favProduct', 1); | ||
124 | + brandTab = false; | ||
125 | + window.rePosFooter(); | ||
53 | } | 126 | } |
54 | 127 | ||
55 | favTabHammer = new Hammer(document.getElementById('fav-tab')); | 128 | favTabHammer = new Hammer(document.getElementById('fav-tab')); |
@@ -62,7 +135,20 @@ favTabHammer.on('tap', function(e) { | @@ -62,7 +135,20 @@ favTabHammer.on('tap', function(e) { | ||
62 | } | 135 | } |
63 | 136 | ||
64 | index = $cur.index(); | 137 | index = $cur.index(); |
138 | + | ||
139 | + if (index === 0) { | ||
140 | + if ($favProductList.find('li').length === 0 && | ||
141 | + $favProductList.closest('.fav-type').find('.fav-null-box').hasClass('hide')) { | ||
142 | + loadData($favProductList, 'favProduct', 1); | ||
143 | + } | ||
144 | + } else { | ||
145 | + if ($favBrandList.find('div').length === 0 && | ||
146 | + $favBrandList.closest('.fav-type').find('.fav-null-box').hasClass('hide')) { | ||
147 | + loadData($favBrandList, 'favBrand', 1); | ||
148 | + } | ||
149 | + } | ||
65 | showFavTab(index); | 150 | showFavTab(index); |
151 | + window.rePosFooter(); | ||
66 | 152 | ||
67 | }); | 153 | }); |
68 | 154 | ||
@@ -117,4 +203,31 @@ favContentHammer.on('tap', function(e) { | @@ -117,4 +203,31 @@ favContentHammer.on('tap', function(e) { | ||
117 | //TODO | 203 | //TODO |
118 | }); | 204 | }); |
119 | }); | 205 | }); |
206 | +}); | ||
207 | + | ||
208 | +// 上拉加载更多 | ||
209 | +$(document).scroll(function() { | ||
210 | + | ||
211 | + if ($(window).scrollTop() + winH >= $(document).height() - footerH) { | ||
212 | + | ||
213 | + if (brandTab) { | ||
214 | + | ||
215 | + $brandLoadMore.filter('.hide').removeClass('hide'); | ||
216 | + | ||
217 | + if (!brandLockId) { | ||
218 | + | ||
219 | + brandPageId++; | ||
220 | + } | ||
221 | + | ||
222 | + } else { | ||
223 | + | ||
224 | + $loadMore.filter('.hide').removeClass('hide'); | ||
225 | + | ||
226 | + if (!lockId) { | ||
227 | + console.log(222); | ||
228 | + pageId++; | ||
229 | + loadData($favProductList, 'favProduct', pageId); | ||
230 | + } | ||
231 | + } | ||
232 | + } | ||
120 | }); | 233 | }); |
@@ -99,6 +99,7 @@ if (document.getElementById('img-form') !== null) { | @@ -99,6 +99,7 @@ if (document.getElementById('img-form') !== null) { | ||
99 | 99 | ||
100 | // 点赞与取消点赞 | 100 | // 点赞与取消点赞 |
101 | $likeBtn.bind('click', function() { | 101 | $likeBtn.bind('click', function() { |
102 | + | ||
102 | var id = $(this).closest('.suggest-item').attr('data-id'), | 103 | var id = $(this).closest('.suggest-item').attr('data-id'), |
103 | $that = $(this); | 104 | $that = $(this); |
104 | 105 | ||
@@ -110,13 +111,8 @@ $likeBtn.bind('click', function() { | @@ -110,13 +111,8 @@ $likeBtn.bind('click', function() { | ||
110 | } | 111 | } |
111 | }).then(function(data) { | 112 | }).then(function(data) { |
112 | if (data.code === 200) { | 113 | if (data.code === 200) { |
113 | - if ($that.hasClass('active')) { | ||
114 | - $that.closest('.suggest-type').removeClass('active') | ||
115 | - .prev('.suggest-type').addClass('active'); | ||
116 | - } else { | ||
117 | - $that.closest('.suggest-type').addClass('active') | ||
118 | - .next('.suggest-type').removeClass('active'); | ||
119 | - } | 114 | + $that.closest('.suggest-type').removeClass('show'); |
115 | + $('.suggest-good').addClass('show'); | ||
120 | } | 116 | } |
121 | }).fail(function(data) { | 117 | }).fail(function(data) { |
122 | 118 | ||
@@ -125,6 +121,7 @@ $likeBtn.bind('click', function() { | @@ -125,6 +121,7 @@ $likeBtn.bind('click', function() { | ||
125 | }); | 121 | }); |
126 | 122 | ||
127 | $disLikeBtn.bind('click', function() { | 123 | $disLikeBtn.bind('click', function() { |
124 | + | ||
128 | var id = $(this).closest('.suggest-item').attr('data-id'), | 125 | var id = $(this).closest('.suggest-item').attr('data-id'), |
129 | $that = $(this); | 126 | $that = $(this); |
130 | 127 | ||
@@ -136,7 +133,8 @@ $disLikeBtn.bind('click', function() { | @@ -136,7 +133,8 @@ $disLikeBtn.bind('click', function() { | ||
136 | } | 133 | } |
137 | }).then(function(data) { | 134 | }).then(function(data) { |
138 | if (data.code === 200) { | 135 | if (data.code === 200) { |
139 | - $that.toggleClass('active'); | 136 | + $that.closest('.suggest-type').removeClass('show'); |
137 | + $('.suggest-bad').addClass('show'); | ||
140 | } | 138 | } |
141 | }).fail(function(data) { | 139 | }).fail(function(data) { |
142 | 140 |
@@ -137,6 +137,7 @@ | @@ -137,6 +137,7 @@ | ||
137 | bottom: pxToRem(20px); | 137 | bottom: pxToRem(20px); |
138 | left: 0; | 138 | left: 0; |
139 | width: 100%; | 139 | width: 100%; |
140 | + min-height: pxToRem(24px); | ||
140 | 141 | ||
141 | &.save-price-number { | 142 | &.save-price-number { |
142 | text-indent: $width + pxToRem(10px); | 143 | text-indent: $width + pxToRem(10px); |
@@ -276,4 +277,18 @@ | @@ -276,4 +277,18 @@ | ||
276 | } | 277 | } |
277 | } | 278 | } |
278 | } | 279 | } |
280 | + | ||
281 | + //上拉加载更多 | ||
282 | + .fav-load-more,.fav-brand-load-more { | ||
283 | + width: 100%; | ||
284 | + height: 2rem; | ||
285 | + line-height: 2rem; | ||
286 | + text-align: center; | ||
287 | + color: #444; | ||
288 | + | ||
289 | + &.load-background { | ||
290 | + background: image_url('loading.gif') center center no-repeat; | ||
291 | + @include background-size(auto 40%); | ||
292 | + } | ||
293 | + } | ||
279 | } | 294 | } |
@@ -66,22 +66,47 @@ $suggest: sprite-map("me/suggest/*.png",$spacing: 5px); | @@ -66,22 +66,47 @@ $suggest: sprite-map("me/suggest/*.png",$spacing: 5px); | ||
66 | color: #b0b0b0; | 66 | color: #b0b0b0; |
67 | font-size: pxToRem(26px); | 67 | font-size: pxToRem(26px); |
68 | display: none; | 68 | display: none; |
69 | + text-align: center; | ||
70 | + | ||
71 | + &.suggest-active { | ||
72 | + > div { | ||
73 | + width: 50%; | ||
74 | + float: left; | ||
75 | + text-align: left; | ||
76 | + padding-left: pxToRem(128px); | ||
77 | + @include box-sizing(); | ||
78 | + | ||
79 | + &:nth-last-of-type(1) { | ||
80 | + padding-left: pxToRem(0); | ||
81 | + padding-right: pxToRem(128px); | ||
82 | + text-align: right; | ||
83 | + float: right; | ||
84 | + | ||
85 | + > span { | ||
86 | + | ||
87 | + display: inline-block; | ||
88 | + height: 100%; | ||
89 | + overflow: hidden; | ||
90 | + | ||
91 | + &:nth-of-type(1) { | ||
92 | + @include rotate(180deg); | ||
93 | + } | ||
94 | + } | ||
95 | + } | ||
96 | + } | ||
97 | + } | ||
69 | 98 | ||
70 | - > div { | ||
71 | - width: 50%; | ||
72 | - float: left; | ||
73 | - text-align: left; | ||
74 | - padding-left: pxToRem(128px); | ||
75 | - @include box-sizing(); | 99 | + > .active { |
100 | + color: #444; | ||
101 | + } | ||
76 | 102 | ||
77 | - &:nth-last-of-type(1) { | ||
78 | - padding-left: pxToRem(0); | ||
79 | - padding-right: pxToRem(128px); | ||
80 | - text-align: right; | ||
81 | - float: right; | 103 | + &.show { |
104 | + display: block; | ||
105 | + } | ||
82 | 106 | ||
107 | + &.suggest-bad { | ||
108 | + > div { | ||
83 | > span { | 109 | > span { |
84 | - | ||
85 | display: inline-block; | 110 | display: inline-block; |
86 | height: 100%; | 111 | height: 100%; |
87 | overflow: hidden; | 112 | overflow: hidden; |
@@ -91,18 +116,6 @@ $suggest: sprite-map("me/suggest/*.png",$spacing: 5px); | @@ -91,18 +116,6 @@ $suggest: sprite-map("me/suggest/*.png",$spacing: 5px); | ||
91 | } | 116 | } |
92 | } | 117 | } |
93 | } | 118 | } |
94 | - | ||
95 | - &.active { | ||
96 | - color: #444; | ||
97 | - } | ||
98 | - } | ||
99 | - | ||
100 | - &.active { | ||
101 | - text-align: center; | ||
102 | - color: #444; | ||
103 | - } | ||
104 | - &.show { | ||
105 | - display: block; | ||
106 | } | 119 | } |
107 | } | 120 | } |
108 | } | 121 | } |
@@ -119,6 +132,7 @@ $suggest: sprite-map("me/suggest/*.png",$spacing: 5px); | @@ -119,6 +132,7 @@ $suggest: sprite-map("me/suggest/*.png",$spacing: 5px); | ||
119 | font-size: pxToRem(30px); | 132 | font-size: pxToRem(30px); |
120 | border-top: 1px solid #e0e0e0; | 133 | border-top: 1px solid #e0e0e0; |
121 | border-bottom: 1px solid #e0e0e0; | 134 | border-bottom: 1px solid #e0e0e0; |
135 | + margin-top: -1px; | ||
122 | 136 | ||
123 | > span { | 137 | > span { |
124 | color: #b0b0b0; | 138 | color: #b0b0b0; |
@@ -7,22 +7,22 @@ | @@ -7,22 +7,22 @@ | ||
7 | </ul> | 7 | </ul> |
8 | <div class="fav-content" id="fav-content"> | 8 | <div class="fav-content" id="fav-content"> |
9 | <div class="fav-type"> | 9 | <div class="fav-type"> |
10 | - <ul class="fav-product-list"> | ||
11 | - {{> home/favorite_product_list}} | ||
12 | - </ul> | 10 | + <ul class="fav-product-list"></ul> |
13 | 11 | ||
14 | - {{^ hasFavProduct}} | ||
15 | - <span class="fav-null">您暂无收藏任何商品</span> | ||
16 | - <a class="go-shopping" href="{{productUrl}}">随便逛逛</a> | ||
17 | - {{/ hasFavProduct}} | 12 | + <div class="fav-null-box hide"> |
13 | + <span class="fav-null">您暂无收藏任何商品</span> | ||
14 | + <a class="go-shopping" href="{{productUrl}}">随便逛逛</a> | ||
15 | + </div> | ||
16 | + <div class="fav-load-more fav-load-background hide"></div> | ||
18 | </div> | 17 | </div> |
19 | <div class="fav-type"> | 18 | <div class="fav-type"> |
20 | - {{> home/favorite_brand_list}} | 19 | + <div class="fav-brand-swiper"></div> |
21 | 20 | ||
22 | - {{^ hasFavBrand}} | ||
23 | - <span class="fav-null">您暂无收藏任何品牌</span> | ||
24 | - <a class="go-shopping" href="{{brandUrl}}">随便逛逛</a> | ||
25 | - {{/ hasFavBrand}} | 21 | + <div class="fav-null-box hide"> |
22 | + <span class="fav-null">您暂无收藏任何品牌</span> | ||
23 | + <a class="go-shopping" href="{{brandUrl}}">随便逛逛</a> | ||
24 | + </div> | ||
25 | + <div class="fav-brand-load-more load-background hide"></div> | ||
26 | </div> | 26 | </div> |
27 | </div> | 27 | </div> |
28 | {{/ favorite}} | 28 | {{/ favorite}} |
@@ -13,22 +13,33 @@ | @@ -13,22 +13,33 @@ | ||
13 | <h2>{{title}}</h2> | 13 | <h2>{{title}}</h2> |
14 | <p>{{content}}</p> | 14 | <p>{{content}}</p> |
15 | 15 | ||
16 | - <div class="suggest-type {{^ good}}show{{/ good}}"> | 16 | + <div class="suggest-type suggest-good"> |
17 | + <div class="active"> | ||
18 | + <span class="iconfont"></span> | ||
19 | + <span>靠谱,谢谢您的反馈</span> | ||
20 | + </div> | ||
21 | + </div> | ||
22 | + <div class="suggest-type suggest-bad"> | ||
23 | + <div class="active"> | ||
24 | + <span class="iconfont"></span> | ||
25 | + <span>不靠谱,谢谢您的反馈</span> | ||
26 | + </div> | ||
27 | + </div> | ||
28 | + | ||
29 | + {{# none}} | ||
30 | + <div class="suggest-type suggest-active show"> | ||
17 | <div class="like-btn"> | 31 | <div class="like-btn"> |
18 | <span class="iconfont"></span> | 32 | <span class="iconfont"></span> |
19 | <span>靠谱</span> | 33 | <span>靠谱</span> |
20 | </div> | 34 | </div> |
21 | - <div class="dislike-btn {{# bad}}active{{/ bad}}"> | 35 | + <div class="dislike-btn"> |
22 | <span class="iconfont"></span> | 36 | <span class="iconfont"></span> |
23 | <span>不靠谱</span> | 37 | <span>不靠谱</span> |
24 | </div> | 38 | </div> |
25 | </div> | 39 | </div> |
26 | - | ||
27 | - <div class="like-btn active suggest-type {{# good}}show{{/ good}}"> | ||
28 | - <span class="iconfont"></span> | ||
29 | - <span>靠谱,谢谢您的反馈</span> | ||
30 | - </div> | 40 | + {{/ none}} |
31 | </div> | 41 | </div> |
42 | + | ||
32 | {{/ suggestContent}} | 43 | {{/ suggestContent}} |
33 | </div> | 44 | </div> |
34 | <a class="create-new-suggest" href="./suggestSub"> | 45 | <a class="create-new-suggest" href="./suggestSub"> |
@@ -95,20 +95,13 @@ class HomeController extends AbstractAction | @@ -95,20 +95,13 @@ class HomeController extends AbstractAction | ||
95 | $this->setNavHeader('我的收藏', true, SITE_MAIN); | 95 | $this->setNavHeader('我的收藏', true, SITE_MAIN); |
96 | 96 | ||
97 | $tab = $this->get('tab', ''); | 97 | $tab = $this->get('tab', ''); |
98 | - $uid = $this->getUid(); | ||
99 | - $gender = Helpers::getGenderByCookie(); | ||
100 | - | ||
101 | - $favProducts = UserModel::getFavProductData($this->_uid, 1, 10); | ||
102 | - $favBrands = UserModel::getFavBrandData($this->_uid, 10, 1, 10); | ||
103 | 98 | ||
104 | $data = array( | 99 | $data = array( |
105 | 'favPage' => true, //加载js | 100 | 'favPage' => true, //加载js |
106 | 'pageFooter' => true, | 101 | 'pageFooter' => true, |
107 | 'favorite' => true, | 102 | 'favorite' => true, |
108 | - 'hasFavProduct' => $favProducts, | ||
109 | 'productUrl' => '/product/new', | 103 | 'productUrl' => '/product/new', |
110 | - 'hasFavBrand' => $favBrands, | ||
111 | - 'brandUrl' => '/product/new' | 104 | + 'brandUrl' => '/product/new', |
112 | ); | 105 | ); |
113 | // 判断是否为品牌收藏页 | 106 | // 判断是否为品牌收藏页 |
114 | if ($tab === 'brand') { | 107 | if ($tab === 'brand') { |
@@ -132,6 +125,8 @@ class HomeController extends AbstractAction | @@ -132,6 +125,8 @@ class HomeController extends AbstractAction | ||
132 | 125 | ||
133 | if (empty($result)) { | 126 | if (empty($result)) { |
134 | echo ' '; | 127 | echo ' '; |
128 | + } else if (isset($result['end'])) { | ||
129 | + echo 'end'; | ||
135 | } else { | 130 | } else { |
136 | $this->_view->display('favorite_product', $result); | 131 | $this->_view->display('favorite_product', $result); |
137 | } | 132 | } |
@@ -145,12 +140,15 @@ class HomeController extends AbstractAction | @@ -145,12 +140,15 @@ class HomeController extends AbstractAction | ||
145 | 140 | ||
146 | if ($this->isAjax()) { | 141 | if ($this->isAjax()) { |
147 | $page = $this->post('page', 1); | 142 | $page = $this->post('page', 1); |
143 | + $gender = Helpers::getGenderByCookie(); | ||
148 | 144 | ||
149 | - $result = UserModel::getFavBrandData($this->_uid, 10, $page, 10); | 145 | + $result = UserModel::getFavBrandData($this->_uid, $gender, $page, 10); |
150 | } | 146 | } |
151 | 147 | ||
152 | if (empty($result)) { | 148 | if (empty($result)) { |
153 | echo ' '; | 149 | echo ' '; |
150 | + } else if (isset($result['end'])) { | ||
151 | + echo 'end'; | ||
154 | } else { | 152 | } else { |
155 | $this->_view->display('favorite_brand', $result); | 153 | $this->_view->display('favorite_brand', $result); |
156 | } | 154 | } |
@@ -157,8 +157,16 @@ class UserModel | @@ -157,8 +157,16 @@ class UserModel | ||
157 | $favProduct = UserData::favoriteProductData($uid, $page, $limit); | 157 | $favProduct = UserData::favoriteProductData($uid, $page, $limit); |
158 | 158 | ||
159 | // 处理用户收藏的商品数据 | 159 | // 处理用户收藏的商品数据 |
160 | - if (isset($favProduct['data']) && !empty($favProduct['data'])) { | 160 | + if (isset($favProduct['data']) && !empty($favProduct['data']['product_list'])) { |
161 | + if ($page > $favProduct['data']['page_total']) { | ||
162 | + $result['end'] = true; | ||
163 | + | ||
164 | + return $result; | ||
165 | + } | ||
166 | + | ||
167 | + $datas = array(); | ||
161 | $product = array(); | 168 | $product = array(); |
169 | + | ||
162 | foreach ($favProduct['data']['product_list'] as $val) { | 170 | foreach ($favProduct['data']['product_list'] as $val) { |
163 | $product = array(); | 171 | $product = array(); |
164 | $product['fav_id'] = $val['product_id']; | 172 | $product['fav_id'] = $val['product_id']; |
@@ -169,9 +177,10 @@ class UserModel | @@ -169,9 +177,10 @@ class UserModel | ||
169 | $product['savePrice'] = ($val['market_price'] - $val['sales_price'] > 0) ? '¥'.($val['market_price'] - $val['sales_price']) . '.00' : false; | 177 | $product['savePrice'] = ($val['market_price'] - $val['sales_price'] > 0) ? '¥'.($val['market_price'] - $val['sales_price']) . '.00' : false; |
170 | $product['sellOut'] = (bool)($val['price_down']); | 178 | $product['sellOut'] = (bool)($val['price_down']); |
171 | 179 | ||
172 | - $result[] = $product; | 180 | + $datas[] = $product; |
173 | } | 181 | } |
174 | 182 | ||
183 | + !empty($datas) && $result['hasFavProduct'] = $datas; | ||
175 | } | 184 | } |
176 | 185 | ||
177 | return $result; | 186 | return $result; |
@@ -182,9 +191,11 @@ class UserModel | @@ -182,9 +191,11 @@ class UserModel | ||
182 | * | 191 | * |
183 | * @param int $uid 用户ID | 192 | * @param int $uid 用户ID |
184 | * @param string $gender 性别 1,3表示男,2,3表示女,1,2,3表示全部 | 193 | * @param string $gender 性别 1,3表示男,2,3表示女,1,2,3表示全部 |
194 | + * @param int $page 第几页 | ||
195 | + * @param int $limit 限制读取的数目 | ||
185 | * @return array|mixed 处理之后的收藏的品牌数据 | 196 | * @return array|mixed 处理之后的收藏的品牌数据 |
186 | */ | 197 | */ |
187 | - public static function getFavBrandData($uid, $gender) | 198 | + public static function getFavBrandData($uid, $gender, $page, $limit) |
188 | { | 199 | { |
189 | $result = array(); | 200 | $result = array(); |
190 | 201 | ||
@@ -192,8 +203,16 @@ class UserModel | @@ -192,8 +203,16 @@ class UserModel | ||
192 | $favBrand = UserData::favoriteBrandData($uid, $gender); | 203 | $favBrand = UserData::favoriteBrandData($uid, $gender); |
193 | 204 | ||
194 | // 处理用户收藏的品牌数据 | 205 | // 处理用户收藏的品牌数据 |
195 | - if (isset($favBrand['data']) && !empty($favBrand['data'])) { | ||
196 | - $brand = array(); | 206 | + if (isset($favBrand['data']) && !empty($favBrand['data']['brand_list'])) { |
207 | + if ($page > $favBrand['data']['page_total']) { | ||
208 | + $result['end'] = true; | ||
209 | + | ||
210 | + return $result; | ||
211 | + } | ||
212 | + | ||
213 | + $datas = array(); | ||
214 | + $brand = array(); | ||
215 | + | ||
197 | foreach ($favBrand['data']['brand_list'] as $val) { | 216 | foreach ($favBrand['data']['brand_list'] as $val) { |
198 | $brand = array(); | 217 | $brand = array(); |
199 | $brand['id'] = $val['brand_id']; | 218 | $brand['id'] = $val['brand_id']; |
@@ -214,8 +233,10 @@ class UserModel | @@ -214,8 +233,10 @@ class UserModel | ||
214 | $brand['productList'][] = $product; | 233 | $brand['productList'][] = $product; |
215 | } | 234 | } |
216 | 235 | ||
217 | - $result[] = $brand; | 236 | + $datas[] = $brand; |
218 | } | 237 | } |
238 | + | ||
239 | + !empty($datas) && $result['hasFavBrand'] = $datas; | ||
219 | } | 240 | } |
220 | 241 | ||
221 | return $result; | 242 | return $result; |
-
Please register or login to post a comment