Authored by zhangxiaoru

favorite

@@ -35,10 +35,15 @@ let favProduct = (req, res, next) => { @@ -35,10 +35,15 @@ let favProduct = (req, res, next) => {
35 let limit = 10; 35 let limit = 10;
36 36
37 favoriteModel.favProduct(uid, page, limit).then((result) => { 37 favoriteModel.favProduct(uid, page, limit).then((result) => {
38 - res.render('favorite/favorite-product', {  
39 - layout: false,  
40 - hasFavProduct: result  
41 - }); 38 +
  39 + if (typeof(result.total) === "undefined") {
  40 + res.render('favorite/favorite-product', {
  41 + layout: false,
  42 + hasFavProduct: result.hasFavProduct
  43 + });
  44 + } else {
  45 + res.json(result);
  46 + }
42 }).catch(next); 47 }).catch(next);
43 }; 48 };
44 49
@@ -48,10 +53,16 @@ let favfavBrand = (req, res, next) => { @@ -48,10 +53,16 @@ let favfavBrand = (req, res, next) => {
48 let limit = 10; 53 let limit = 10;
49 54
50 favoriteModel.favfavBrand(uid, page, limit).then((result) => { 55 favoriteModel.favfavBrand(uid, page, limit).then((result) => {
51 - res.render('favorite/favorite-brand', {  
52 - layout: false,  
53 - hasFavBrand: result  
54 - }); 56 +
  57 + if (typeof(result.total) === "undefined") {
  58 + res.render('favorite/favorite-brand', {
  59 + layout: false,
  60 + hasFavBrand: result.hasFavBrand
  61 + });
  62 + } else {
  63 + res.json(result);
  64 + }
  65 +
55 }).catch(next); 66 }).catch(next);
56 }; 67 };
57 68
@@ -23,7 +23,7 @@ const favProduct = (uid, page, limit) => { @@ -23,7 +23,7 @@ const favProduct = (uid, page, limit) => {
23 page: page, 23 page: page,
24 limit: limit 24 limit: limit
25 }).then((result) => { 25 }).then((result) => {
26 - // console.log(result) 26 +
27 let resu = { 27 let resu = {
28 hasFavProduct: [] 28 hasFavProduct: []
29 }; 29 };
@@ -34,7 +34,10 @@ const favProduct = (uid, page, limit) => { @@ -34,7 +34,10 @@ const favProduct = (uid, page, limit) => {
34 34
35 if (page > 1 && list === []) { 35 if (page > 1 && list === []) {
36 resu.end = true; 36 resu.end = true;
37 - return; 37 + }
  38 +
  39 + if (list.data.total === 0) {
  40 + resu.total = 0;
38 } 41 }
39 42
40 if (page <= list.data.pageTotal) { 43 if (page <= list.data.pageTotal) {
@@ -101,12 +104,10 @@ const favProduct = (uid, page, limit) => { @@ -101,12 +104,10 @@ const favProduct = (uid, page, limit) => {
101 }); 104 });
102 105
103 } else { 106 } else {
104 - resu.push({  
105 - end: true  
106 - }); 107 + resu.end = true;
107 } 108 }
108 109
109 - return resu.hasFavProduct; 110 + return resu;
110 } else { 111 } else {
111 logger.error('收藏商品 cood 不是 200'); 112 logger.error('收藏商品 cood 不是 200');
112 } 113 }
@@ -121,16 +122,20 @@ const favfavBrand = (uid, page, limit) => { @@ -121,16 +122,20 @@ const favfavBrand = (uid, page, limit) => {
121 page: page, 122 page: page,
122 limit: limit 123 limit: limit
123 }).then((result) => { 124 }).then((result) => {
124 - let hasFavBrand = []; 125 + console.log(result)
  126 + let resu = {
  127 + hasFavBrand: []
  128 + }
125 129
126 if (result && result.code === 200) { 130 if (result && result.code === 200) {
127 let list = camelCase(result); 131 let list = camelCase(result);
128 132
129 if (page > 1 && list === []) { 133 if (page > 1 && list === []) {
130 - hasFavBrand.push({  
131 - end: true  
132 - });  
133 - return; 134 + resu.end = true;
  135 + }
  136 +
  137 + if (list.data.total === 0) {
  138 + resu.total = 0;
134 } 139 }
135 140
136 if (page <= list.data.pageTotal) { 141 if (page <= list.data.pageTotal) {
@@ -179,17 +184,15 @@ const favfavBrand = (uid, page, limit) => { @@ -179,17 +184,15 @@ const favfavBrand = (uid, page, limit) => {
179 } 184 }
180 }); 185 });
181 186
182 - hasFavBrand.push(obj);  
183 - });  
184 -  
185 - // console.log(hasFavBrand);  
186 - return hasFavBrand; 187 + resu.hasFavBrand.push(obj);
  188 + });
  189 +
187 } else { 190 } else {
188 - hasFavBrand.push({  
189 - end: true  
190 - }); 191 + resu.end = true;
191 } 192 }
192 193
  194 + console.log(resu);
  195 + return resu;
193 } else { 196 } else {
194 logger.error('收藏品牌 cood 不是 200'); 197 logger.error('收藏品牌 cood 不是 200');
195 } 198 }
@@ -23,10 +23,10 @@ var $navLi = $('#fav-tab > li'), @@ -23,10 +23,10 @@ var $navLi = $('#fav-tab > li'),
23 $favProductList = $('.fav-product-list'), 23 $favProductList = $('.fav-product-list'),
24 $favBrandList = $('.fav-brand-swiper-wrapper'), 24 $favBrandList = $('.fav-brand-swiper-wrapper'),
25 pageId = 1, 25 pageId = 1,
26 - brandPageId = 1, // 收藏品牌的当前页数 26 + brandPageId = 1, //收藏品牌的当前页数
27 lockId = true, 27 lockId = true,
28 - brandLockId = true, // 收藏品牌是否可下拉加载更多  
29 - brandTab = false; // 当前是否停留在收藏品牌页 28 + brandLockId = true, //收藏品牌是否可下拉加载更多
  29 + brandTab = false; //当前是否停留在收藏品牌页
30 30
31 require('../common'); 31 require('../common');
32 32
@@ -38,7 +38,7 @@ function showFavTab(index) { @@ -38,7 +38,7 @@ function showFavTab(index) {
38 $favContainer.eq(index).addClass('show'); 38 $favContainer.eq(index).addClass('show');
39 } 39 }
40 40
41 -// 初始化swiper 41 +//初始化swiper
42 function initSwiper(data) { 42 function initSwiper(data) {
43 var i, 43 var i,
44 idStrReg = /container-(\d+)['"]{1}/gi, 44 idStrReg = /container-(\d+)['"]{1}/gi,
@@ -47,10 +47,10 @@ function initSwiper(data) { @@ -47,10 +47,10 @@ function initSwiper(data) {
47 idArrLen = idArr.length, 47 idArrLen = idArr.length,
48 containerId; 48 containerId;
49 49
50 - // $swiperList = $('.swiper-container'); 50 + //$swiperList = $('.swiper-container');
51 for (i = 0; i < idArrLen; i++) { 51 for (i = 0; i < idArrLen; i++) {
52 52
53 - /* id = $swiperList.eq(i).attr('data-id'); 53 + /*id = $swiperList.eq(i).attr('data-id');
54 54
55 if (!!swiperObj[id]) { 55 if (!!swiperObj[id]) {
56 swiperObj[id].destroy(true, true); 56 swiperObj[id].destroy(true, true);
@@ -91,17 +91,18 @@ function loadData($parent, url, page) { @@ -91,17 +91,18 @@ function loadData($parent, url, page) {
91 $loadMore.addClass('hide'); 91 $loadMore.addClass('hide');
92 } 92 }
93 93
94 - if (data === ' ') { 94 + if (data.total === 0) {
  95 +
95 $loadingMask.addClass('hide'); 96 $loadingMask.addClass('hide');
96 $parent.closest('.fav-type').find('.fav-null-box').removeClass('hide'); 97 $parent.closest('.fav-type').find('.fav-null-box').removeClass('hide');
97 window.rePosFooter(); 98 window.rePosFooter();
98 - } else if (data === 'end') { 99 + } else if (data.end === true) {
99 100
100 - // 处理data等于end时如果loadingMask存在且没有hide样式的情况 101 + //处理data等于end时如果loadingMask存在且没有hide样式的情况
101 if ($loadingMask && !$loadingMask.hasClass('hide')) { 102 if ($loadingMask && !$loadingMask.hasClass('hide')) {
102 $loadingMask.addClass('hide'); 103 $loadingMask.addClass('hide');
103 104
104 - // $parent.closest('.fav-type').find('.fav-null-box').removeClass('hide'); 105 + //$parent.closest('.fav-type').find('.fav-null-box').removeClass('hide');
105 } 106 }
106 107
107 $parent.closest('.fav-type').find('.fav-load-background') 108 $parent.closest('.fav-type').find('.fav-load-background')
@@ -113,14 +114,14 @@ function loadData($parent, url, page) { @@ -113,14 +114,14 @@ function loadData($parent, url, page) {
113 } else if (data.length > 10) { 114 } else if (data.length > 10) {
114 $parent.append(data); 115 $parent.append(data);
115 116
116 - // 如果有数据loadingMask会被remove掉 117 + //如果有数据loadingMask会被remove掉
117 $loadingMask.remove(); 118 $loadingMask.remove();
118 if (url === 'favBrand') { 119 if (url === 'favBrand') {
119 - initSwiper(data);// 如果是收藏品牌需要初始化swiper 120 + initSwiper(data);//如果是收藏品牌需要初始化swiper
120 121
121 - brandLockId = false;// 请求成功后解锁品牌收藏page++ 122 + brandLockId = false;//请求成功后解锁品牌收藏page++
122 } else { 123 } else {
123 - lockId = false;// 请求成功后解锁商品收藏page++ 124 + lockId = false;//请求成功后解锁商品收藏page++
124 } 125 }
125 } 126 }
126 window.rePosFooter(); 127 window.rePosFooter();
@@ -170,7 +171,7 @@ favTabHammer.on('tap', function(e) { @@ -170,7 +171,7 @@ favTabHammer.on('tap', function(e) {
170 171
171 }); 172 });
172 173
173 -// 删除收藏的商品 174 +//删除收藏的商品
174 favContentHammer = new Hammer(document.getElementById('fav-content')); 175 favContentHammer = new Hammer(document.getElementById('fav-content'));
175 176
176 favContentHammer.on('tap', function(e) { 177 favContentHammer.on('tap', function(e) {
@@ -218,7 +219,7 @@ favContentHammer.on('tap', function(e) { @@ -218,7 +219,7 @@ favContentHammer.on('tap', function(e) {
218 } 219 }
219 }).fail(function() { 220 }).fail(function() {
220 221
221 - // TODO 222 + //TODO
222 223
223 diaLog.showDialog({ 224 diaLog.showDialog({
224 autoHide: true, 225 autoHide: true,
@@ -230,7 +231,7 @@ favContentHammer.on('tap', function(e) { @@ -230,7 +231,7 @@ favContentHammer.on('tap', function(e) {
230 231
231 function scrollHandler() { 232 function scrollHandler() {
232 233
233 - // 距离底部未1/4列表高度+底部高度的时候加载更多 234 + //距离底部未1/4列表高度+底部高度的时候加载更多
234 if ($(window).scrollTop() + winH >= $(document).height() - 0.25 * $favBrandList.height() - footerH) { 235 if ($(window).scrollTop() + winH >= $(document).height() - 0.25 * $favBrandList.height() - footerH) {
235 if (brandTab) { 236 if (brandTab) {
236 $brandLoadMore.filter('.hide').removeClass('hide'); 237 $brandLoadMore.filter('.hide').removeClass('hide');
@@ -252,7 +253,7 @@ function scrollHandler() { @@ -252,7 +253,7 @@ function scrollHandler() {
252 } 253 }
253 } 254 }
254 255
255 -// srcoll to load more 256 +//srcoll to load more
256 $(window).scroll(scrollHandler); 257 $(window).scroll(scrollHandler);
257 258
258 $(document).on('touchend', '.swiper-header', function() { 259 $(document).on('touchend', '.swiper-header', function() {