Authored by htoooth

refactor

@@ -20,9 +20,10 @@ const index = (req, res, next)=> { @@ -20,9 +20,10 @@ const index = (req, res, next)=> {
20 let sort = req.query.sort_id || 0; 20 let sort = req.query.sort_id || 0;
21 let reduction = req.query.is_reduction || 'N'; 21 let reduction = req.query.is_reduction || 'N';
22 let promotion = req.query.is_promotion || 'N'; 22 let promotion = req.query.is_promotion || 'N';
23 - let limit = 10, data = {}; 23 + let limit = 10;
  24 + let data = {};
24 25
25 - data.tabs = favoriteService.getFavoriteTabs(type); 26 + data.tabs = favoriteService.getFavoriteTabs('product');
26 27
27 switch (type) { 28 switch (type) {
28 case 'brand': 29 case 'brand':
@@ -30,7 +31,7 @@ const index = (req, res, next)=> { @@ -30,7 +31,7 @@ const index = (req, res, next)=> {
30 31
31 break; 32 break;
32 case 'article': 33 case 'article':
33 - data.favArticles = yield favoriteService.favoriteArticleList(uid, udid, page, limit, type); 34 + data.favArticles = yield favoriteService.favoriteArticleListAsync(uid, udid, page, limit);
34 35
35 break; 36 break;
36 default: 37 default:
@@ -48,8 +49,8 @@ const index = (req, res, next)=> { @@ -48,8 +49,8 @@ const index = (req, res, next)=> {
48 49
49 const reductionAction = ()=> { 50 const reductionAction = ()=> {
50 51
51 -} 52 +};
52 53
53 module.exports = { 54 module.exports = {
54 index 55 index
55 -} 56 +};
@@ -20,9 +20,7 @@ const getFavoriteTabs = (type) => { @@ -20,9 +20,7 @@ const getFavoriteTabs = (type) => {
20 type = type || 'product'; 20 type = type || 'product';
21 21
22 return TABS.map((item) => { 22 return TABS.map((item) => {
23 - if (item.type === type) {  
24 - item.active = true;  
25 - } 23 + item.active = item.type === type;
26 item.url = helpers.urlFormat('/home/favorite', {type: item.type}); 24 item.url = helpers.urlFormat('/home/favorite', {type: item.type});
27 return item; 25 return item;
28 }); 26 });
@@ -149,13 +147,13 @@ const favoriteBrandList = (uid, page, limit, type)=> { @@ -149,13 +147,13 @@ const favoriteBrandList = (uid, page, limit, type)=> {
149 })(); 147 })();
150 }; 148 };
151 149
152 -const favoriteArticleList = (uid, udid, page, limit, type)=> { 150 +const favoriteArticleListAsync = (uid, udid, page, limit)=> {
153 return co(function*() { 151 return co(function*() {
154 let result = {articles: [], pager: {}}; 152 let result = {articles: [], pager: {}};
155 - let article = yield favoriteApi.favoriteArticleData(uid, udid, page, limit); 153 + let articles = yield favoriteApi.favoriteArticleData(uid, udid, page, limit);
156 154
157 - if (!article.data && !article.data.data) {  
158 - article.data.data.forEach((item, i)=> { 155 + if (!articles.data && !articles.data.data) {
  156 + articles.data.data.forEach((item)=> {
159 result.articles.push({ 157 result.articles.push({
160 id: item.id, 158 id: item.id,
161 name: item.title, 159 name: item.title,
@@ -165,11 +163,11 @@ const favoriteArticleList = (uid, udid, page, limit, type)=> { @@ -165,11 +163,11 @@ const favoriteArticleList = (uid, udid, page, limit, type)=> {
165 }); 163 });
166 }); 164 });
167 165
168 - let total = article.data.total || 0;  
169 - let pageTotal = article.data.totalPage || 0;  
170 - let page = article.data.page || 0; 166 + let total = articles.data.total || 0;
  167 + let pageTotal = articles.data.totalPage || 0;
  168 + let pageNum = articles.data.page || 0;
171 169
172 - result.pager = getPager(page, total, pageTotal); 170 + result.pager = getPager(pageNum, total, pageTotal);
173 } else { 171 } else {
174 result.articles = {empty: '你尚未收藏任何文章!'}; 172 result.articles = {empty: '你尚未收藏任何文章!'};
175 } 173 }
@@ -261,5 +259,5 @@ const getSortInfo = (categoryList, sort)=> { @@ -261,5 +259,5 @@ const getSortInfo = (categoryList, sort)=> {
261 module.exports = { 259 module.exports = {
262 getFavoriteTabs, 260 getFavoriteTabs,
263 favoriteProductList, 261 favoriteProductList,
264 - favoriteArticleList 262 + favoriteArticleListAsync
265 }; 263 };
@@ -165,6 +165,7 @@ router.get('/vip', VipController.index); @@ -165,6 +165,7 @@ router.get('/vip', VipController.index);
165 165
166 router.get('/favorite', FavoriteController.index); 166 router.get('/favorite', FavoriteController.index);
167 167
  168 +
168 router.get('/coupons', CouponsController.index); 169 router.get('/coupons', CouponsController.index);
169 170
170 module.exports = router; 171 module.exports = router;
1 -'use strict';  
2 -let Promise = require('bluebird');  
3 -let co = Promise.coroutine;  
4 -  
5 -  
6 -co(function*() {  
7 - let a = yield Promise.reject(3);  
8 - console.log('here');  
9 - a = 4;  
10 - return a;  
11 -})().then(a=>console.log(a))  
12 -.catch(a=>console.log(a));