Authored by 周少峰

add brand

... ... @@ -45,12 +45,32 @@ exports.new = (req, res, next) => {
* @param {[type]} res [description]
* @return {[type]} [description]
*/
exports.new = (req, res, next) => {
let resData = {};
exports.brand = (req, res, next) => {
let resData = {},
brandDomain = req.brandDomain || 'vans';
list.getListNewData(req.query).then(result => {
// 获取品牌信息
list.getBrandInfo({domain: brandDomain}).then(brandInfo => {
return list.getBrandData(req.query, Object.assign({uid: req.user.id}, brandInfo));
}).then(result => {
Object.assign(resData, result);
res.render('list/index', resData);
res.render('list/brand', resData);
}).catch(next);
};
/**
* ajax调用品牌页左侧水牌
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
exports.getNodeContent = (req, res, next) => {
if (!req.xhr || !req.body.node) {
return next();
}
list.getNodeContentData(req.body).then(result => {
res.json(result);
}).catch(next);
};
... ...
... ... @@ -10,6 +10,7 @@ const searchApi = require('./search-api');
const headerModel = require('../../../doraemon/models/header');
const productProcess = require(`${utils}/product-process`);
const searchHandler = require('./search-handler');
const helpers = global.yoho.helpers;
// 搜索分类信息需要的参数
const positionId = 10;
... ... @@ -87,6 +88,7 @@ exports.getListData = (params) => {
* 获取新品到着数据
*/
exports.getListNewData = (params) => {
// 调用接口
let apiMethod = [
headerModel.requestHeaderData(),
... ... @@ -133,3 +135,108 @@ exports.getListNewData = (params) => {
return finalResult;
});
};
/**
* 根据品牌域名查询品牌信息
*/
exports.getBrandInfo = (params) => {
return searchApi.getBrandData(params).then(result => {
if (result.code !== 200 || !result.data) {
return {};
}
return {
brandId: result.data.id,
brandNameEn: result.data.brand_name_en || '',
brandNameCn: result.data.brand_name_cn || '',
brandBanner: result.data.brand_banner || '',
node: result.data.static_content_code || '',
brandAbout: result.data.brand_intro || '',
shopTemplateType: result.data.shop_template_type || 0,
url: helpers.urlFormat('', '', result.data.brand_domain),
name: result.data.brand_name,
shopId: result.data.shop_id || 0,
type: result.data.type || 0,
brandDomain: result.data.brand_domain
};
});
};
/**
* 获取品牌页面数据
*/
exports.getBrandData = (params, extra) => {
// 设置品牌默认排序方式
let order = params.order || 'b_w_desc';
// 调用接口
let apiMethod = [
headerModel.requestHeaderData(),
searchApi.getSortList({brand: extra.brandId}),
searchApi.getProductList(Object.assign({order: order, brand: extra.brandId}, params))
];
return api.all(apiMethod).then(result => {
let finalResult = {
headerData: Object.assign(result[0].headerData, {
header: true
}),
brand: {
brandBanner: searchHandler.handleBrandBanner(extra),
leftContent: {},
node: extra.node || ''
}
};
// 获取左侧类目数据
if (result[1].code === 200) {
Object.assign(finalResult.brand, {
leftContent: searchHandler.handleSortData(result[1].data.sort, params),
pathNav: searchHandler.handlePathNavData(extra, params, 'brand')
});
}
// 获取商品数据和顶部筛选条件
if (result[2].code === 200) {
Object.assign(finalResult.brand, {
filters: searchHandler.handleFilterData(result[2].data.filter, params),
opts: searchHandler.handleOptsData(params, result[2].data.total, result[2].data.filter),
totalCount: result[2].data.total,
footPager: searchHandler.handlePagerData(result[2].data.total, params),
goods: productProcess.processProductList(result[2].data.product_list,
Object.assign({showDiscount: false}, params))
});
}
// 品牌页不显示品牌筛选项
delete finalResult.brand.filters.brand;
return finalResult;
});
};
/**
* 获取品牌页面水牌
*/
exports.getNodeContentData = (params) => {
return searchApi.getNodeContent(params).then(result => {
if (result.code === 200 && result.data) {
return result.data;
}
});
};
/**
* 获取品牌页面系列
*/
exports.getAdnav = (params) => {
return searchApi.getNodeContent(params).then(result => {
return result;
});
};
... ...
... ... @@ -76,6 +76,16 @@ const getBrandFolder = (params) => {
return yohoApi.get('', params);
};
const getNodeContent = (params) => {
let finalParams = {
method: 'web.html.content',
mode: params.mode || 'release',
node: params.node || ''
};
return yohoApi.get('', finalParams);
};
/**
* 一周新品上架
* @return
... ... @@ -118,6 +128,20 @@ const getSuggest = (params) => {
};
/**
* 根据品牌域名获取品牌信息
* @return
*/
const getBrandData = (params) => {
let finalParams = {
method: 'web.brand.byDomain',
domain: params.domain || ''
};
return yohoApi.get('', finalParams);
};
module.exports = {
getSortByConditionAsync,
getProductList,
... ... @@ -127,7 +151,9 @@ module.exports = {
getBrandFolder,
getWeekNew,
getBrandShop,
getSuggest
getSuggest,
getBrandData,
getNodeContent
};
... ...
... ... @@ -624,6 +624,7 @@ exports.handlePathNavData = (data, params, page) => {
}
break;
case 'brand':
// 品牌
pathNav.push(
{
... ... @@ -632,9 +633,8 @@ exports.handlePathNavData = (data, params, page) => {
href: helpers.urlFormat('brand')
},
{
name: data.brandName,
pathTitle: data.brandName,
href: helpers.urlFormat('', '', data.brandDomain)
name: data.brandNameEn + data.brandNameCn,
pathTitle: data.brandNameEn + data.brandNameCn
}
);
break;
... ... @@ -862,6 +862,17 @@ exports.handleSuggest = (data) => {
return suggest;
};
exports.handleBrandBanner = (data) => {
return {
bannerHeight: 150,
banner: data.brandBanner.split('?')[0],
brandHome: data.url,
brandIntro: helpers.urlFormat('/about', '', data.brandDomain),
dataId: data.brandId
};
};
/**
* 筛选类链接处理的对外接口
* @type {[type]}
... ...
... ... @@ -68,4 +68,13 @@ router.get('/list/index', list.index);
// 新品到着
router.get('/list/new', list.new);
// 品牌页
router.get('/list/brand', list.brand);
// 品牌页水牌
router.post('/index/getNodeContent', list.getNodeContent);
// 品牌页系列
// router.post('/index/getAdnav', list.getAdnav);
module.exports = router;
... ...
<div class="product-page yoho-page product-list-page">
{{# brand}}
{{> list/list}}
{{/brand}}
</div>
\ No newline at end of file
... ...
... ... @@ -111,3 +111,17 @@
{{#if node}}
<div id="brand-card" class="brand-card" data-node="{{node}}"></div>
{{/if}}
{{!-- 水牌广告-基础模板 --}}
{{#signboard}}
<div class="sell-signboard left-modular">
<h2 class="title">{{title}}</h2>
<ul class="left-list">
{{#each list}}
<li>
<a target="_blank" href="{{url}}"><img src="{{img}}" alt="{{title}}" /></a>
</li>
{{/each}}
</ul>
</div>
{{/signboard}}
\ No newline at end of file
... ...
/**
* 品牌页面
* @auhtor: bikai<kai.bi@yoho.cn>
* @date: 2016/1/21
*/
var $ = require('yoho-jquery');
var $brandFavor = $('#brand-favor'),
$shopFavor = $('#shop-favor'),
shopId = $shopFavor.data('id'),
id = $brandFavor.data('id'),
isFavorite = $shopFavor.find('i').hasClass('coled');
/**
* 品牌收藏
*/
$brandFavor.on('click', function() {
$.ajax({
type: 'post',
url: '/product/index/favoriteBrand',
data: {
brandId: id
}
}).then(function(res) {
if (res.code === 200) {
$brandFavor.find('i').toggleClass('coled');
} else if (res.code === 403) {
location.href = '//www.yohobuy.com/signin.html?refer=' + encodeURIComponent(location.href);
}
});
});
/**
* 店铺收藏
*/
$shopFavor.on('click', function() {
$.ajax({
type: 'post',
url: '/product/index/favoriteShop',
data: {
isFavorite: isFavorite ? 0 : 1,
shopId: shopId
}
}).then(function(res) {
if (res.code === 200) {
$shopFavor.find('i').toggleClass('coled');
} else if (res.code === 403) {
location.href = '//www.yohobuy.com/signin.html?refer=' + encodeURIComponent(location.href);
}
});
});
// 页面进入更新收藏状态
$.ajax({
type: 'POST',
url: '/product/index/isFavoriteBrand',
data: {
brandId: id
}
}).then(function(data) {
if (data.code === 200) {
// 已收藏
$brandFavor.find('i').addClass('coled');
} else if (data.code === 404) {
// 未收藏
$brandFavor.find('i').removeClass('coled');
}
});
... ...
... ... @@ -11,6 +11,10 @@ var product = require('./index/product');
require('../common');
require('../plugins/filter');
require('../plugins/sort-pager');
require('../plugins/sort-pager');
// 品牌
require('./index/brand');
product.init(4);
... ...