Authored by htoooth

add hbs

@@ -8,7 +8,6 @@ const Promise = require('bluebird'); @@ -8,7 +8,6 @@ const Promise = require('bluebird');
8 const co = Promise.coroutine; 8 const co = Promise.coroutine;
9 const requestIp = require('request-ip'); 9 const requestIp = require('request-ip');
10 const md5 = require('md5'); 10 const md5 = require('md5');
11 -const helpers = global.yoho.helpers;  
12 11
13 const favoriteService = require('../models/favorite-service'); 12 const favoriteService = require('../models/favorite-service');
14 13
@@ -50,13 +49,13 @@ const index = (req, res, next)=> { @@ -50,13 +49,13 @@ const index = (req, res, next)=> {
50 49
51 switch (type) { 50 switch (type) {
52 case TABS.brand: 51 case TABS.brand:
53 - data.favBrands = yield favoriteService.favoriteBrandList(uid, page, limit); 52 + data.favBrands = yield favoriteService.favoriteBrandListAsync(uid, page, limit);
54 break; 53 break;
55 case TABS.article: 54 case TABS.article:
56 data.favArticles = yield favoriteService.favoriteArticleListAsync(uid, udid, page, limit); 55 data.favArticles = yield favoriteService.favoriteArticleListAsync(uid, udid, page, limit);
57 break; 56 break;
58 default: 57 default:
59 - data.favProducts = yield favoriteService.favoriteProductList( 58 + data.favProducts = yield favoriteService.favoriteProductListAsync(
60 uid, page, limit, selectedSort, 'N', reduction, promotion, req.query 59 uid, page, limit, selectedSort, 'N', reduction, promotion, req.query
61 ); 60 );
62 break; 61 break;
@@ -71,7 +70,42 @@ const index = (req, res, next)=> { @@ -71,7 +70,42 @@ const index = (req, res, next)=> {
71 }).catch(next); 70 }).catch(next);
72 }; 71 };
73 72
  73 +const newProduct = (req, res, next) => {
  74 + let uid = req.user.uid;
  75 + let page = +req.query.page || 1;
  76 + let limit = +req.query.limit || 10;
  77 + let id = +req.query.id || 0;
  78 +
  79 + if (!id) {
  80 + return res.json({
  81 + code: 400,
  82 + message: '缺少参数'
  83 + });
  84 + }
  85 +
  86 + favoriteService.newProductAsync(uid, page, limit, id).then((result) => {
  87 + return res.json({
  88 + code: 200,
  89 + data: result
  90 + });
  91 + }).catch(next);
  92 +};
  93 +
  94 +const reduction = (req, res, next) => {
  95 + let page = +req.query.page || 1;
  96 + let type = req.query.type || '';
  97 + let limit = 10;
  98 +
  99 + favoriteService.reduction().then((result) => {
  100 + return res.render('reduction', result);
  101 + }).catch(next);
  102 +};
  103 +
74 module.exports = { 104 module.exports = {
75 index, 105 index,
  106 + newProduct,
  107 + reduction,
  108 +
76 udidRequired 109 udidRequired
  110 +
77 }; 111 };
@@ -122,7 +122,7 @@ const _redutionCount = (uid)=> { @@ -122,7 +122,7 @@ const _redutionCount = (uid)=> {
122 }; 122 };
123 123
124 124
125 -const favoriteProductList = (uid, page, limit, selectedSort, subscribe, reduction, promotion, query) => { 125 +const favoriteProductListAsync = (uid, page, limit, selectedSort, subscribe, reduction, promotion, query) => {
126 return co(function*() { 126 return co(function*() {
127 let result = { 127 let result = {
128 sort: {}, 128 sort: {},
@@ -205,7 +205,7 @@ const favoriteProductList = (uid, page, limit, selectedSort, subscribe, reductio @@ -205,7 +205,7 @@ const favoriteProductList = (uid, page, limit, selectedSort, subscribe, reductio
205 })(); 205 })();
206 }; 206 };
207 207
208 -const favoriteBrandList = (uid, page, limit)=> { 208 +const favoriteBrandListAsync = (uid, page, limit)=> {
209 return co(function*() { 209 return co(function*() {
210 let result = { 210 let result = {
211 brands: { 211 brands: {
@@ -277,14 +277,38 @@ const favoriteArticleListAsync = (uid, udid, page, limit)=> { @@ -277,14 +277,38 @@ const favoriteArticleListAsync = (uid, udid, page, limit)=> {
277 })(); 277 })();
278 }; 278 };
279 279
  280 +const newProductAsync = (uid, page, limit, id) => {
  281 + return co(function * () {
  282 + let products = yield favoriteApi.favoriteBrandData(uid, page, limit);
280 283
  284 + return _.get(products, 'data.brand_list', []).reduce((total, cur) => {
  285 + if (id !== cur.brand_id) {
  286 + return total;
  287 + }
281 288
  289 + if (cur.new_product_num === 0) {
  290 + return total;
  291 + }
282 292
  293 + total = _.concat(total, _.take(_.get(cur, 'new_product', []), 20).map((pro) => {
  294 + return {
  295 + img: pro.default_images,
  296 + url: helpers.getUrlBySkc(pro.product_id, _.get(pro, 'goods[0].id', ''), _.get(pro, 'cnAlphabet')),
  297 + name: pro.product_name,
  298 + salePrice: pro.sales_price === pro.market_price ? '' : pro.sales_price,
  299 + marketPrice: pro.market_price
  300 + };
  301 + }));
283 302
  303 + return total;
  304 + }, []);
  305 + })();
  306 +};
284 307
285 module.exports = { 308 module.exports = {
286 getFavoriteTabs, 309 getFavoriteTabs,
287 - favoriteBrandList,  
288 - favoriteProductList,  
289 - favoriteArticleListAsync 310 + favoriteBrandListAsync,
  311 + favoriteProductListAsync,
  312 + favoriteArticleListAsync,
  313 + newProductAsync
290 }; 314 };
@@ -215,7 +215,11 @@ router.get('/favorite', [getCommonHeader, getHomeNav], @@ -215,7 +215,11 @@ router.get('/favorite', [getCommonHeader, getHomeNav],
215 favoriteController.index 215 favoriteController.index
216 ); 216 );
217 217
218 -// 218 +// 品牌页新品到着
  219 +router.get('/favorite/newproduct', favoriteController.newProduct);
  220 +
  221 +router.get('/favorite/reduction', favoriteController.reduction);
  222 +
219 // router.get('/coupons', CouponsController.index); 223 // router.get('/coupons', CouponsController.index);
220 224
221 router.get('/user', [getCommonHeader, getHomeNav], UserController.index); 225 router.get('/user', [getCommonHeader, getHomeNav], UserController.index);
  1 +{{#if naGoods}}
  2 +<span class="na-pre hidden">
  3 + <i class="iconfont">&#xe622;</i>
  4 + </span>
  5 +<div class="na-goods">
  6 + <ul class="na-goods-ul clearfix">
  7 + {{# naGoods}}
  8 + <li class="na-good">
  9 + <a href="{{url}}">
  10 + <img class="na-good-thumb" src="{{image2 img w=100 h=100}}">
  11 +
  12 + <p class="na-good-name">{{name}}</p>
  13 + </a>
  14 +
  15 + <span class="na-price{{#if salePrice}} has-sale{{/if}}">{{marketPrice}}</span>
  16 +
  17 + {{#if salePrice}}
  18 + <span class="na-price">{{salePrice}}</span>
  19 + {{/if}}
  20 + </li>
  21 + {{/ naGoods}}
  22 + </ul>
  23 +</div>
  24 +<span class="na-next hidden">
  25 + <i class="iconfont">&#xe621;</i>
  26 + </span>
  27 +{{^}}
  28 + <p class="has-no-na">暂无新产品</p>
  29 +{{/if}}
@@ -4,8 +4,7 @@ @@ -4,8 +4,7 @@
4 * @date: 2016/2/23 4 * @date: 2016/2/23
5 */ 5 */
6 6
7 -var $ = require('yoho-jquery'),  
8 - Handlebars = require('yoho-handlebars'); 7 +var $ = require('yoho-jquery');
9 8
10 var phoneReg = require('../passport/mail-phone-regx').phoneRegx['+86']; 9 var phoneReg = require('../passport/mail-phone-regx').phoneRegx['+86'];
11 10
@@ -306,7 +305,7 @@ require('../common'); @@ -306,7 +305,7 @@ require('../common');
306 return; 305 return;
307 } 306 }
308 307
309 - naTpl = Handlebars.compile($('#na-tpl').html()); 308 + naTpl = require('hbs/home/favorite/new-notify.hbs');
310 309
311 // 新品到着【重要信息:最多显示20个新品到着商品】 310 // 新品到着【重要信息:最多显示20个新品到着商品】
312 $('.na-trigger').click(function() { 311 $('.na-trigger').click(function() {
@@ -345,6 +344,7 @@ require('../common'); @@ -345,6 +344,7 @@ require('../common');
345 tplData = res.length === 0 ? {} : { 344 tplData = res.length === 0 ? {} : {
346 naGoods: res 345 naGoods: res
347 }; 346 };
  347 +
348 html = naTpl(tplData); 348 html = naTpl(tplData);
349 349
350 $naList.removeClass('hide').find('.na-content').html(html); 350 $naList.removeClass('hide').find('.na-content').html(html);
@@ -444,7 +444,7 @@ $('#me-del-checked').click(function() { @@ -444,7 +444,7 @@ $('#me-del-checked').click(function() {
444 id: ids.join(','), 444 id: ids.join(','),
445 type: favType 445 type: favType
446 } 446 }
447 - }).then(function(data) { 447 + }).then(function() {
448 history.go(0); 448 history.go(0);
449 }); 449 });
450 } 450 }