Authored by htoooth

add hbs

... ... @@ -8,7 +8,6 @@ const Promise = require('bluebird');
const co = Promise.coroutine;
const requestIp = require('request-ip');
const md5 = require('md5');
const helpers = global.yoho.helpers;
const favoriteService = require('../models/favorite-service');
... ... @@ -50,13 +49,13 @@ const index = (req, res, next)=> {
switch (type) {
case TABS.brand:
data.favBrands = yield favoriteService.favoriteBrandList(uid, page, limit);
data.favBrands = yield favoriteService.favoriteBrandListAsync(uid, page, limit);
break;
case TABS.article:
data.favArticles = yield favoriteService.favoriteArticleListAsync(uid, udid, page, limit);
break;
default:
data.favProducts = yield favoriteService.favoriteProductList(
data.favProducts = yield favoriteService.favoriteProductListAsync(
uid, page, limit, selectedSort, 'N', reduction, promotion, req.query
);
break;
... ... @@ -71,7 +70,42 @@ const index = (req, res, next)=> {
}).catch(next);
};
const newProduct = (req, res, next) => {
let uid = req.user.uid;
let page = +req.query.page || 1;
let limit = +req.query.limit || 10;
let id = +req.query.id || 0;
if (!id) {
return res.json({
code: 400,
message: '缺少参数'
});
}
favoriteService.newProductAsync(uid, page, limit, id).then((result) => {
return res.json({
code: 200,
data: result
});
}).catch(next);
};
const reduction = (req, res, next) => {
let page = +req.query.page || 1;
let type = req.query.type || '';
let limit = 10;
favoriteService.reduction().then((result) => {
return res.render('reduction', result);
}).catch(next);
};
module.exports = {
index,
newProduct,
reduction,
udidRequired
};
... ...
... ... @@ -122,7 +122,7 @@ const _redutionCount = (uid)=> {
};
const favoriteProductList = (uid, page, limit, selectedSort, subscribe, reduction, promotion, query) => {
const favoriteProductListAsync = (uid, page, limit, selectedSort, subscribe, reduction, promotion, query) => {
return co(function*() {
let result = {
sort: {},
... ... @@ -205,7 +205,7 @@ const favoriteProductList = (uid, page, limit, selectedSort, subscribe, reductio
})();
};
const favoriteBrandList = (uid, page, limit)=> {
const favoriteBrandListAsync = (uid, page, limit)=> {
return co(function*() {
let result = {
brands: {
... ... @@ -277,14 +277,38 @@ const favoriteArticleListAsync = (uid, udid, page, limit)=> {
})();
};
const newProductAsync = (uid, page, limit, id) => {
return co(function * () {
let products = yield favoriteApi.favoriteBrandData(uid, page, limit);
return _.get(products, 'data.brand_list', []).reduce((total, cur) => {
if (id !== cur.brand_id) {
return total;
}
if (cur.new_product_num === 0) {
return total;
}
total = _.concat(total, _.take(_.get(cur, 'new_product', []), 20).map((pro) => {
return {
img: pro.default_images,
url: helpers.getUrlBySkc(pro.product_id, _.get(pro, 'goods[0].id', ''), _.get(pro, 'cnAlphabet')),
name: pro.product_name,
salePrice: pro.sales_price === pro.market_price ? '' : pro.sales_price,
marketPrice: pro.market_price
};
}));
return total;
}, []);
})();
};
module.exports = {
getFavoriteTabs,
favoriteBrandList,
favoriteProductList,
favoriteArticleListAsync
favoriteBrandListAsync,
favoriteProductListAsync,
favoriteArticleListAsync,
newProductAsync
};
... ...
... ... @@ -215,7 +215,11 @@ router.get('/favorite', [getCommonHeader, getHomeNav],
favoriteController.index
);
//
// 品牌页新品到着
router.get('/favorite/newproduct', favoriteController.newProduct);
router.get('/favorite/reduction', favoriteController.reduction);
// router.get('/coupons', CouponsController.index);
router.get('/user', [getCommonHeader, getHomeNav], UserController.index);
... ...
{{#if naGoods}}
<span class="na-pre hidden">
<i class="iconfont">&#xe622;</i>
</span>
<div class="na-goods">
<ul class="na-goods-ul clearfix">
{{# naGoods}}
<li class="na-good">
<a href="{{url}}">
<img class="na-good-thumb" src="{{image2 img w=100 h=100}}">
<p class="na-good-name">{{name}}</p>
</a>
<span class="na-price{{#if salePrice}} has-sale{{/if}}">{{marketPrice}}</span>
{{#if salePrice}}
<span class="na-price">{{salePrice}}</span>
{{/if}}
</li>
{{/ naGoods}}
</ul>
</div>
<span class="na-next hidden">
<i class="iconfont">&#xe621;</i>
</span>
{{^}}
<p class="has-no-na">暂无新产品</p>
{{/if}}
... ...
... ... @@ -4,8 +4,7 @@
* @date: 2016/2/23
*/
var $ = require('yoho-jquery'),
Handlebars = require('yoho-handlebars');
var $ = require('yoho-jquery');
var phoneReg = require('../passport/mail-phone-regx').phoneRegx['+86'];
... ... @@ -306,7 +305,7 @@ require('../common');
return;
}
naTpl = Handlebars.compile($('#na-tpl').html());
naTpl = require('hbs/home/favorite/new-notify.hbs');
// 新品到着【重要信息:最多显示20个新品到着商品】
$('.na-trigger').click(function() {
... ... @@ -345,6 +344,7 @@ require('../common');
tplData = res.length === 0 ? {} : {
naGoods: res
};
html = naTpl(tplData);
$naList.removeClass('hide').find('.na-content').html(html);
... ... @@ -444,7 +444,7 @@ $('#me-del-checked').click(function() {
id: ids.join(','),
type: favType
}
}).then(function(data) {
}).then(function() {
history.go(0);
});
}
... ...