Authored by 毕凯

Merge remote-tracking branch 'origin/feature/shopEntry' into gray

... ... @@ -22,9 +22,9 @@ const _getProductBySkns = function(productObj) {
};
if (val.shop_id) {
obj.brandurl = `//m.yohobuy.com/product/index/brand?domain=${val.brand_domain}&openby:yohobuy={"action":"go.shop","params":{"shop_id":${val.shop_id},"shop_template_type":${val.shop_template_type}}}`; // eslint-disable-line
obj.brandurl = `//m.yohobuy.com/product/shop?domain=${val.brand_domain}&openby:yohobuy={"action":"go.shop","params":{"shop_id":${val.shop_id},"shop_template_type":${val.shop_template_type}}}`; // eslint-disable-line
} else {
obj.brandurl = `//m.yohobuy.com/product/index/brand?domain=${val.brand_domain}&openby:yohobuy={"action":"go.brand","params":{"brand_id":${val.brand_id}}}`; // eslint-disable-line
obj.brandurl = `//m.yohobuy.com/product/shop?domain=${val.brand_domain}&openby:yohobuy={"action":"go.brand","params":{"brand_id":${val.brand_id}}}`; // eslint-disable-line
}
productObj.defaultPros.push(obj);
... ...
... ... @@ -31,7 +31,7 @@ const shopList = (uid, tabName, channelId) => {
}).then((result) => {
if (result && result.code === 200) {
_.forEach(result.data, function(data) {
let href = '//m.yohobuy.com/product/index/brand?shop_id=' +
let href = '//m.yohobuy.com/product/shop?shop_id=' +
data.shopsId + '&openby:yohobuy={"action":"go.shop","params":{"shop_id":"' +
data.shopsId + '","shop_template_type":"' +
data.shopTemplateType + '","shop_name":"' + data.shopName + '"}}';
... ...
... ... @@ -149,7 +149,7 @@ const _urlJump = (key, row) => {
return {
1: helpers.urlFormat('', {from: 'search', query: row.brand_name}, 'search'),
2: helpers.urlFormat('/product/index/brand', {domain: row.brand_domain}),
2: helpers.urlFormat('/product/shop', {domain: row.brand_domain}),
3: helpers.urlFormat('/product/global/list/', {brand: row.global_brand_id})
}[key];
};
... ...
... ... @@ -153,7 +153,7 @@ const favfavBrand = (uid, page, limit) => {
// }
if (val.brandOrShopType === 'brandOrShopType') {
obj = _.assign(obj, {
link: helpers.urlFormat('/product/index/brand', {
link: helpers.urlFormat('/product/shop', {
shop_id: val.shopId
})
});
... ...
... ... @@ -14,6 +14,7 @@ const crypto = global.yoho.crypto;
const helpers = global.yoho.helpers;
const productProcess = require(`${utils}/product-process`);
const searchModel = require(`${mRoot}/search`);
const shopModel = require(`${mRoot}/shop`);
const searchProcess = require(`${utils}/search-process`);
/**
... ... @@ -123,7 +124,7 @@ const _shop = (req, res, shopId) => {
/* 若店铺使用基础模板跳转基础模板 */
_baseShop(req, res, result.goBrand, shopId);
} else {
listModel.searchProductBySkn(result.hotListproductSkn).then(hotList => {
searchModel.searchProductBySkn(result.hotListproductSkn).then(hotList => {
result = _.assign(result, pageHeader, {
hotList: productProcess.processProductList(hotList, {isApp: isApp})
});
... ... @@ -282,7 +283,7 @@ const brand = (req, res, next) => {
return;
}
listModel.getBrandLogoByDomain(domain).then(result => {
shopModel.getBrandLogoByDomain(domain).then(result => {
if (!result) {
return next();
}
... ... @@ -321,7 +322,7 @@ const brand = (req, res, next) => {
}, params);
} else if (brandId && brandId !== 0 &&
brandId !== '' && brandId !== 'undefined') { // 品牌一览过来的展示品牌介绍和LOGO
return Promise.all([listModel.getBrandIntro(brandId, uid), listModel.getBrandBanner(brandId)]).then((resData) => { //eslint-disable-line
return Promise.all([shopModel.getBrandIntro(brandId, uid), shopModel.getBrandBanner(brandId)]).then((resData) => { //eslint-disable-line
title = resData[0].title;
delete resData[0].title;
... ... @@ -364,7 +365,7 @@ const brandFav = (req, res) => {
let uid = req.user.uid;
let brandId = 0;
listModel.getBrandLogoByDomain(domain).then((result) => {
shopModel.getBrandLogoByDomain(domain).then((result) => {
brandId = result.id;
listModel.getBrandFavStatus({
uid: uid,
... ...
... ... @@ -5,379 +5,66 @@
'use strict';
const mRoot = '../models';
const utils = '../../../utils';
const listModel = require(`${mRoot}/list`);
const shopModel = require(`${mRoot}/shop`);
const searchModel = require(`${mRoot}/search`);
const redsShopModel = require(`${mRoot}/popular-shop`);
const headerModel = require('../../../doraemon/models/header');
const _ = require('lodash');
const helpers = global.yoho.helpers;
const productProcess = require(`${utils}/product-process`);
const redShopPrcs = require(`${utils}/redshop-process`);
const co = require('bluebird').coroutine;
const tdk = require('../../../utils/getTDK');
/**
* 从 useragent 获取 uid
* @returns {*}
* @private
*/
const _getUidFromUserAgent = (req) => {
let userAgent = _.split(req.headers['user-agent'], ';');
let uidString = '';
_.forEach(userAgent, value => {
if (_.startsWith(value, 'uid')) {
uidString = value;
return;
}
});
return _.split(uidString, '=')[1];
};
const shop = {
index(req, res, next) {
let params = Object.assign({}, req.query);
let domain = req.query.domain;
let brandId = 0;
let brandLogo = {};
let title = '';
let uid = req.user.uid || 0;
let shopEnter;
if (req.query.shop_id) {
return shop.shop(req, res, next);
}
if (!domain) {
res.redirect('/?go=1');
return;
/**
* 店铺统一入口
*/
entry(req, res, next) {
const {
shop_id: shopId,
brand_id: brandId,
domain
} = req.query;
const uid = req.user.uid;
req.shopInfo = {};
if (brandId) {
return shop.brand(req, res, next); // 品牌列表,有品牌ID就直接展示为品牌
}
listModel.getBrandLogoByDomain(domain).then(result => {
if (!result) {
return next();
}
brandLogo = result;
return co(function*() {
title = brandLogo.name;
return co(function*() {
if (shopId) {
let shopInfoApi = (yield shopModel.getShopInfo(shopId, uid)) || {};
let shopInfo = _.get(shopInfoApi, 'data', {});
if (brandLogo && brandLogo.id) {
brandId = brandLogo.id;
if (shopInfo && shopInfo.is_red_shop === 1) {
shopInfo.shopId = _.get(shopInfo, 'shops_id', '');
}
if (brandLogo && brandLogo.shopId) {
let TDKObj = yield tdk('shop', brandLogo.shopId, req);
if (TDKObj[0]) {
req.tdk = {
title: TDKObj[1],
keywords: TDKObj[2],
description: TDKObj[3]
};
}
}
params.brand = brandId;
// 唤起 APP 的路径
res.locals.appPath = `yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.brand","params":{"brand_id":"${brandId}"}}`;
req.shopInfo = shopInfo;
} else if (domain) {
let domainInfo = (yield shopModel.getBrandLogoByDomain(domain)) || {}; // 通过域名查询店铺类型,或者品牌信息
let searchParam = Object.assign({
isApp: req.yoho.isApp,
brand: brandId,
type: 'default',
order: '0',
page: 1,
limit: 4,
}, params);
if (domainInfo.shopId && domainInfo.type === '2') { // 红人店铺
let shopInfoApi = yield shopModel.getShopInfo(domainInfo.shopId, uid);
let shopInfo = _.get(shopInfoApi, 'data', {});
if (uid) {
searchParam.uid = uid;
_.assign(req.shopInfo, domainInfo, shopInfo);
} else { // 品牌
req.shopInfo = domainInfo;
}
if (req.query.from !== 'search' && brandLogo.type === '2' && brandLogo.shopId) {
req.query.shop_id = brandLogo.shopId;
shop.shop(req, res, next);
return false;
} else if (req.query.from === 'search') {
return Promise.all([
listModel.getBrandShops(brandLogo.brandDomain, req),
searchModel.getSearchData(searchParam)
]).then(shopResult => {
let brandShop = shopResult[0];
let newGoods = shopResult[1];
params.newGoods = newGoods.list || [];
params.suggestion = newGoods.suggestion || [];
// 推荐词条件判断 redmine: 18567
if (params.suggestion && params.suggestion.isNeedSuggestion &&
params.suggestion.termsSuggestion.length) {
params.newquery = params.suggestion.termsSuggestion[0].name;
}
if (brandId === 0) {
params.query = domain;
}
if (req.query.app_type && parseInt(req.query.app_type, 10) === 1) {
shopEnter = false;
} else {
shopEnter = true;
}
if (brandShop.length > 0 || brandLogo && shopEnter) {
params = _.assign({
brandWay: _.isEmpty(brandShop) ? brandLogo : brandShop,
search: {
default: req.query.query || req.query.domain,
url: helpers.urlFormat('', null, 'search')
}
}, params);
}
return true;
});
} else {
params.brandHome = {
title: result.name,
id: result.id
};
return Promise.all([
listModel.getBrandBanner(brandId),
searchModel.getSearchData(searchParam)
]).then(brandResult => {
let brandBanner = brandResult[0];
let newGoods = brandResult[1];
if (!brandBanner || !newGoods) {
res.set('Cache-Control', 'no-cache');
}
// 品牌没有 Banner 整个头部不显示
if (!brandBanner) {
params.brandHome = null;
} else {
params.brandHome.banner = brandBanner;
}
params.newGoods = newGoods.list;
return true;
});
}
})();
}).then((isBrand) => {
if (isBrand) {
params.isBrand = isBrand;
res.render('newshop/brand', {
module: 'product',
page: 'brand-index',
pageHeader: headerModel.setNav({
navTitle: title !== '' ? title : domain
}),
goodList: params,
suggestion: params.suggestion || [],
showDownloadApp: true,
pageFooter: true,
title: title + '|' + title + '潮流服装服饰-Yoho!Buy有货',
keywords: title + ',' + title + '服装服饰,' + title + '潮流服装服饰',
description: title + '|Yoho!Buy有货' + title + '潮流服饰官方授权店!100%品牌正品保证,支持货到付款。',
domain: req.query.domain,
shopPage: true,
_noLazy: true,
localCss: true
});
}
}).catch(next);
},
shop(req, res, next) {
let isApp = req.query.app_version || req.query.appVersion || false;
let shopId = req.query.shop_id;
let uid = req.user.uid || req.query.uid;
let channel = req.yoho.channel || 'boys';
let pageHeader = {};
let appType = req.query.app_type;
// pagecache前端判断
if (!isApp) {
pageHeader = {
pageHeader: _.assign({
shopPage: {
text: '分类',
url: helpers.urlFormat('/product/index/category', {
shop_id: shopId
})
}
}, headerModel.setNav({
navTitle: false
}))
};
}
return listModel.getShopIntro(shopId).then(shopInfoResult => {
let searchParam = {
isApp: req.yoho.isApp,
shop_id: shopId,
app_type: appType,
type: 'default',
order: '0',
page: 1,
limit: 4
};
let shopInfo = shopInfoResult;
let seoResult = listModel.getBrandShopSeo(channel, shopInfoResult, req.query);
if (uid) {
searchParam.uid = uid;
}
/* 红人店铺直接跳转 */
if (shopInfoResult && shopInfoResult.is_red_shop) {
shop.redShop(req, res, next);
return false;
}
/* 基础店铺返回程序内的跳转信号,跳转到基础店铺 */
if (shopInfoResult && shopInfoResult.shop_template_type) {
if (parseInt(shopInfoResult.shop_template_type, 10) === 1) {
return Promise.all([
listModel.getBaseShopData(req.query, shopInfo),
searchModel.getSearchData(searchParam)
]).then(fResult => {
let baseShop = fResult[0];
let newGoods = fResult[1];
baseShop.newGoods = newGoods.list;
if (baseShop && baseShop.baseShopHome && baseShop.baseShopHome.banner) {
if (baseShop.baseShopHome.banner.indexOf('?') < 0) {
baseShop.baseShopHome.banner +=
'?imageMogr2/auto-orient/strip/thumbnail/x150/crop/640x150';
}
}
let appPath = 'yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.shop","params":{"shop_template_type":"1","shop_id":"' +
shopId + '","shop_name":"' + shopInfo.shop_name + '"}}';
if (shopInfoResult.is_red_shop === 1) {
appPath = 'yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.shop","params":{"shop_template_type":"1","is_red_shop":"1","shop_id":"' +
shopId + '","shop_name":"' + shopInfo.shop_name + '"}}';
}
if (shopId) {
baseShop.shopId = shopId;
}
res.render('newshop/shop-base', {
module: 'product',
page: 'shop.base',
pageHeader: headerModel.setNav({
navTitle: shopInfo.shop_name
}),
goodList: baseShop,
showDownloadApp: true,
pageFooter: true,
title: shopInfo.shop_name + '|' + shopInfo.shop_name + '潮流服装服饰-Yoho!Buy有货',
keywords: shopInfo.shop_name + ',' + shopInfo.shop_name + '服装服饰,' +
shopInfo.shop_name + '潮流服装服饰',
description: shopInfo.shop_name + '|Yoho!Buy有货' + shopInfo.shop_name +
'潮流服饰官方授权店!100%品牌正品保证,支持货到付款。',
shopId: shopId,
shopPage: true,
_noLazy: true,
appPath: appPath,
localCss: true
});
});
} else if (parseInt(shopInfoResult.shop_template_type, 10) === 2) {
// 经典装修店铺
return Promise.all([
listModel.getShopDecorator(shopId).then(),
listModel.getShopCategoryApi(shopId, channel)
]).then(fResult => {
let shopDeco = fResult[0];
let shopCategory = fResult[1];
let shopData = {
decorator: shopDeco, // 店铺装修资源数据
shopInfo: shopInfo, // 店铺信息
shopCategory: shopCategory
};
let result = listModel.formShopData(shopData, shopId, isApp);
result = _.assign(result, pageHeader,
{shopId: shopId, coverChannel: channel, seoResult: seoResult});
res.render('newshop/shop-classics', {
module: 'product',
page: 'shop.classics',
shopIndex: result,
shopHeadHide: true,
gender: req.query.gender,
channel: req.query.channel,
title: result.seoTitle + '|' + result.seoTitle + '潮流服装服饰-Yoho!Buy有货',
keywords: result.seoTitle + ',' + result.seoTitle + '服装服饰,' + result.seoTitle + '潮流服装服饰',
description: result.seoTitle + '|Yoho!Buy有货' + result.seoTitle +
'潮流服饰官方授权店!100%品牌正品保证,支持货到付款。',
shopId: shopId,
shopPage: true,
appPath: 'yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.shop","params":{"shop_template_type":"2","shop_id":"' +
shopId + '","shop_name":"' + result.seoTitle + '"}}',
localCss: true,
isMarsApp: req.yoho.isMarsApp
});
});
} else {
shop.redShop(req, res, next);
}
} else {
shop.redShop(req, res, next);
}
}).catch(next);
},
_getUidFromUserAgent(req) {
let userAgent = _.split(req.headers['user-agent'], ';');
let uidString = '';
_.forEach(userAgent, value => {
if (_.startsWith(value, 'uid')) {
uidString = value;
return;
if (req.shopInfo.shopId) { // 店铺
return shop.redShop(req, res, next);
} else if (req.shopInfo.id) { // 品牌,id 来自 domainInfo
return shop.brand(req, res, next);
} else if (shopId) { // 没有查到店铺数据但是有 shopId 的请求
return shop.list(req, res, next);
} else { // 什么都没有,去首页
return res.redirect(helpers.urlFormat('', {go: '-1'}));
}
});
return _.split(uidString, '=')[1];
},
/**
*
* 基础模板收藏
*/
baseShopFav(req, res, next) {
let allowOrigin = _.get(req, 'headers.origin', null) ?
req.headers.origin : req.protocol + '://' + req.headers.host;
res.setHeader('Access-Control-Allow-Origin', allowOrigin);
res.setHeader('Access-Control-Allow-Credentials', 'true');
let uid = req.user.uid || req.query.uid || _getUidFromUserAgent(req);
let shopId = req.query.shopId;
return listModel.getShopIntro(shopId, uid).then(result => {
res.json(Object.assign({code: 200}, result));
}).catch(next);
})().catch(next);
},
/**
... ... @@ -392,16 +79,19 @@ const shop = {
if (!brandId) {
return res.json({code: 404});
}
return listModel.getBrandIntro(brandId, uid).then(result => {
return shopModel.getBrandIntro(brandId, uid).then(result => {
res.json(result);
}).catch(next);
},
/**
* 一个横向商品列表
*/
shopHotList(req, res, next) {
let skns = req.query.skns;
let isApp = req.query.app_version || req.query.appVersion || false;
return listModel.searchProductBySkn(skns).then(hotList => {
return searchModel.searchProductBySkn(skns).then(hotList => {
hotList = productProcess.processProductList(hotList, {isApp: isApp});
_.forEach(hotList, (value, key) => {
hotList[key].tags = {};
... ... @@ -417,10 +107,58 @@ const shop = {
},
/**
* 品牌
*/
brand(req, res, next) {
let brandId = req.query.brand_id || req.shopInfo.id;
let uid = req.user.uid;
let searchParam = {
isApp: req.yoho.isApp,
brand_id: brandId,
app_type: req.query.app_type,
type: 'default',
order: '0',
page: 1
};
co(function* () {
let [banner, brandInfo, goodsListApi] = yield Promise.all([
shopModel.getBrandBanner(brandId),
shopModel.getBrandIntro(brandId, uid),
searchModel.getBrandGoods(searchParam)
]);
let title = brandInfo.title;
let goodsList = productProcess.processProductList(_.get(goodsListApi, 'data.product_list', []));
brandInfo.banner = banner;
res.render('newshop/shop-brand', {
module: 'product',
page: 'shop-brand',
pageHeader: headerModel.setNav({
navTitle: title
}),
showDownloadApp: true,
pageFooter: true,
title: title + '|' + title + '潮流服装服饰-Yoho!Buy有货',
keywords: title + ',' + title + '服装服饰,' + title + '潮流服装服饰',
description: title + '|Yoho!Buy有货' + title + '潮流服饰官方授权店!100%品牌正品保证,支持货到付款。',
brandId: brandId,
brandInfo: brandInfo,
goodsList: goodsList,
shopPage: true,
_noLazy: true,
localCss: true
});
})().catch(next);
},
/**
* 红人店铺
*/
redShop(req, res, next) {
let shopId = req.query.shop_id; // test3 792
let shopId = req.shopInfo.shopId;
let channel = req.yoho.channel || 'boys';
let uid = req.user.uid || 0;
let udid = req.sessionID || 'yoho';
... ... @@ -430,20 +168,23 @@ const shop = {
}
co(function* () {
let bannerData = yield redsShopModel.getBanner(shopId);
let shopData = yield redsShopModel.getIntro(shopId);
let favCountData = yield redsShopModel.favCount(shopId, uid, channel, udid);
let decoratorsData = yield redsShopModel.getShopsdecorator(shopId);
let categoryData = yield redsShopModel.getShopCategory(shopId, channel);
let [bannerData, favCountData, decoratorsData, categoryData] = yield Promise.all([
shopModel.getBanner(shopId),
shopModel.favCount(shopId, uid, channel, udid),
shopModel.getShopsdecorator(shopId),
shopModel.getShopCategory(shopId, channel)
]);
let banner = _.get(bannerData, 'data.banner');
let shopInfo = redShopPrcs.shopIntro(_.get(shopData, 'data', {}));
let shopInfo = req.shopInfo;
let favCount = _.get(favCountData, 'data[0].approximateCount', '2.1w');
let decoratorsAll = redShopPrcs.floor(_.get(decoratorsData, 'data.modules', []));
let category = redShopPrcs.category(_.get(categoryData, 'data', []), shopId);
let goodsList = yield listModel.searchProductBySkn(decoratorsAll.skns);
let decorators = redShopPrcs.pushGoodsInfo(decoratorsAll.decorators, goodsList);
let goodsListBySkn = yield searchModel.searchProductBySkn(decoratorsAll.skns);
let decorators = redShopPrcs.pushGoodsInfo(decoratorsAll.decorators, goodsListBySkn);
shopInfo.shop_intro_link = helpers.urlFormat('/product/index/intro', {shop_id: shopId});
res.render('newshop/shop-reds', {
title: shopInfo.shop_name + '|' + shopInfo.shop_name + '潮流服装服饰-Yoho!Buy有货',
... ... @@ -471,7 +212,7 @@ const shop = {
width750: true,
localCss: true,
module: 'product',
page: 'reds-shop',
page: 'shop-reds',
shopId,
banner, shopInfo, favCount, decorators, category
});
... ... @@ -479,6 +220,46 @@ const shop = {
},
/**
* 没有店铺的店铺商品列表
*/
list(req, res, next) {
co(function* () {
let title = '店铺商品列表';
let shopId = req.query.shop_id;
let searchParam = {
isApp: req.yoho.isApp,
shop_id: shopId,
app_type: req.query.app_type,
type: 'default',
order: '0',
page: 1
};
let goodsListApi = yield searchModel.getShopGoods(searchParam);
let goodsList = productProcess.processProductList(_.get(goodsListApi, 'data.product_list', []));
res.render('newshop/shop-list', {
module: 'product',
page: 'shop-list',
pageHeader: headerModel.setNav({
navTitle: title
}),
showDownloadApp: true,
pageFooter: true,
title: title + '|' + title + '潮流服装服饰-Yoho!Buy有货',
keywords: title + ',' + title + '服装服饰,' + title + '潮流服装服饰',
description: title + '|Yoho!Buy有货' + title + '潮流服饰官方授权店!100%品牌正品保证,支持货到付款。',
shopId: shopId,
goodsList: goodsList,
shopPage: true,
_noLazy: true,
localCss: true
});
})().catch(next);
},
/**
* 店铺全部品牌页面
*/
allBrand(req, res, next) {
... ...
... ... @@ -12,7 +12,9 @@ const searchModel = require(`${mRoot}/search`);
const _ = require('lodash');
const helpers = global.yoho.helpers;
const searchProcess = require(`${utils}/search-process`);
const productProcess = require(`${utils}/product-process`);
const stringCode = require(`${utils}/string-code`);
const co = require('bluebird').coroutine;
/**
* 搜索落地页
... ... @@ -339,6 +341,62 @@ const keyId = (req, res, next) => {
}).catch(next);
};
/**
* 搜索品牌下的商品
*/
const searchBrandGoods = (req, res, next) => {
let allowOrigin = _.get(req, 'headers.origin', null) ?
req.headers.origin : req.protocol + '://' + req.headers.host;
res.setHeader('Access-Control-Allow-Origin', allowOrigin);
res.setHeader('Access-Control-Allow-Credentials', 'true');
co(function* () {
let goodListApi = yield searchModel.getBrandGoods(req.query);
let goodsData = _.get(goodListApi, 'data', []);
let goodsList = productProcess.processProductList(_.get(goodListApi, 'data.product_list', []));
if (goodsList) {
res.render('search/goods-list-ajax', {
layout: false,
goodsList: goodsList,
_noLazy: req.query.noLazy || false
});
} else {
res.json(goodsData);
}
})().catch(next);
};
/**
* 搜索店铺下的商品
*/
const searchShopGoods = (req, res, next) => {
let allowOrigin = _.get(req, 'headers.origin', null) ?
req.headers.origin : req.protocol + '://' + req.headers.host;
res.setHeader('Access-Control-Allow-Origin', allowOrigin);
res.setHeader('Access-Control-Allow-Credentials', 'true');
co(function* () {
let goodListApi = yield searchModel.getShopGoods(req.query);
let goodsData = _.get(goodListApi, 'data', []);
let goodsList = productProcess.processProductList(_.get(goodListApi, 'data.product_list', []));
if (goodsList) {
res.render('search/goods-list-ajax', {
layout: false,
goodsList: goodsList,
_noLazy: req.query.noLazy || false
});
} else {
res.json(goodsData);
}
})().catch(next);
};
module.exports = {
list,
filter,
... ... @@ -346,5 +404,7 @@ module.exports = {
index,
fuzzyDatas,
keyword,
keyId
keyId,
searchBrandGoods,
searchShopGoods
};
... ...
... ... @@ -56,7 +56,7 @@ const _processShopsInfo = (data) => {
};
if (value.shop_id) {
shopInfo.url = helpers.urlFormat('/product/index/brand', {
shopInfo.url = helpers.urlFormat('/product/shop', {
shop_id: value.shop_id
});
} else {
... ... @@ -540,7 +540,7 @@ const _detailDataPkgAsync = (origin, uid, vipLevel, ua) => {
let storeUrl = '';
if (origin.shop_id) {
storeUrl = helpers.urlFormat('/product/index/brand', {
storeUrl = helpers.urlFormat('/product/shop', {
shop_id: origin.shop_id
});
}
... ...
... ... @@ -31,7 +31,7 @@ const _processBrandShops = (list) => {
_.forEach(list, item => {
if (item.shop_type === 'yoho_shop') {
formatDat.push({
url: helpers.urlFormat('/product/index/brand/', {
url: helpers.urlFormat('/product/shop', {
shop_id: item.shop_id
}),
thumb: helpers.image(item.shop_logo, 126, 80),
... ... @@ -303,21 +303,6 @@ const getShopBrands = (shopId) => {
});
};
/**
* 通过 skn 搜索商品
* @param productSkn
* @returns {*|Promise.<TResult>}
* @private
*/
const searchProductBySkn = (productSkn) => {
return api.get('', {
method: 'h5.product.batch',
productSkn: productSkn
}, {code: 200, cache: true}).then(result => {
return _.get(result, 'data.product_list', []);
});
};
/**
* 组织店铺页面数据
... ... @@ -701,95 +686,6 @@ const getShopFav = (req, shopId, uid) => {
};
/**
* 获取品牌信息数据
* @param {int} brandId 品牌ID
* @return array banner数据
*/
const getBrandIntro = (brandId, uid) => {
let param = {
uid: uid
};
if (!brandId || brandId === '' || brandId === 'undefined') {
return Promise.resolve({});
}
return api.get('', _.assign({
method: 'app.brand.getBrandIntro',
brand_id: brandId
}, param), {
code: 200
}).then(result => {
if (result && result.data) {
let list = result.data;
return {
id: list.brand_id,
intro: list.brand_intro,
collected: list.is_favorite && list.is_favorite === 'Y',
title: list.brand_name ? list.brand_name : ''
};
} else {
return false;
}
});
};
/**
* 获取品牌banner数据
* @param {int} brandId 品牌ID
* @return array banner数据
*/
const getBrandBanner = (brandId) => {
return api.get('', {
method: 'app.brand.banner',
brand_id: brandId
}, {
cache: true
}).then((result) => {
if (result && result.code === 200 && result.data) {
if (result.data.banner) {
return helpers.image(result.data.banner, 640, 150);
} else {
return '';
}
} else {
return {};
}
});
};
/**
* 根据品牌域名获取品牌LOGO
* @param {string} domain 品牌域名
* @return array | false
*/
const getBrandLogoByDomain = (domain) => {
return api.get('', {
method: 'web.brand.byDomain',
domain: domain
}, {
cache: true
}).then(result => {
if (result && result.data) {
let formatData = result.data;
return {
id: formatData.id,
url: helpers.urlFormat('', null, formatData.brand_domain),
thumb: helpers.image(formatData.brand_ico, 75, 40),
name: formatData.brand_name,
shopId: formatData.shop_id ? formatData.shop_id : 0, // 店铺id
type: formatData.type ? formatData.type : 0,
brandDomain: formatData.brand_domain
};
} else {
return false;
}
});
};
/**
* 根据brandId 获取相关店铺列表
* @param brandId
* @param req
... ... @@ -982,10 +878,7 @@ const brandCouponsList = (params) => {
module.exports = {
getBaseShopData,
getShopData,
getBrandLogoByDomain,
getBrandIntro,
getBrandShops,
getBrandBanner,
setFavorite,
setFavoriteCancel,
getShopIntro,
... ... @@ -995,7 +888,6 @@ module.exports = {
shopCouponsList,
brandCouponsList,
getShopFav,
searchProductBySkn,
getBrandFavStatus,
getShopDecorator: _getShopDecorator,
getShopCategoryApi: _getShopCategory,
... ...
/**
* desc: 店铺装修----红人店铺
*/
'use strict';
const api = global.yoho.API;
const singleAPI = global.yoho.SingleAPI;
const stringProcess = require(`${global.utils}/string-process`);
/**
* 频道
* @type {{}}
*/
const yhChannel = {
boys: 1,
girls: 2,
kids: 3,
lifestyle: 4
};
/**
* 获取红人店铺 banner
* doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/商品列表/店铺装修.md
* @param int shopId 店铺id
*/
exports.getBanner = shopId => {
let params = {
method: 'app.popular.shop.banner',
shop_id: shopId
};
return api.get('', params, {cache: true, code: 200});
};
/**
* 获取店铺 介绍
* @param int shopId 店铺id
*/
exports.getIntro = shopId => {
let params = {
method: 'app.shops.getIntro',
shop_id: shopId
};
if (!shopId || !stringProcess.isNumeric(shopId)) {
return Promise.resolve({});
}
return api.get('', params, {cache: true, code: 200});
};
/**
* 查询红人店铺对应的装修元素
*
* @param int shopId 店铺id
*/
exports.getShopsdecorator = shopId => {
let params = {
method: 'app.popular.shopsdecorator',
shop_id: shopId
};
return api.get('', params, {cache: true, code: 200});
};
/**
* 获取店铺下面的所有分类
* @param {int} shopId 店铺id
* @param {string} channel 频道
* @return array
*/
exports.getShopCategory = (shopId, channel) => {
return api.get('', {
method: 'app.shop.getSortInfo',
yh_channel: yhChannel[channel],
shop_id: shopId
});
};
/**
* 店铺收藏数量
*/
exports.favCount = (shopId, uid, channel, udid) => {
let finalParams = {
method: 'app.favorite.queryFavoriteCountByShopIds',
favIds: shopId,
type: 'shop',
udid: udid,
physical_channel: yhChannel[channel],
};
if (uid) {
Object.assign(finalParams, {
uid: uid
});
}
return singleAPI.get('favorite', finalParams);
};
... ... @@ -14,6 +14,7 @@ const api = global.yoho.API;
const cache = require('memory-cache');
const helpers = global.yoho.helpers;
const redis = global.yoho.redis;
const co = require('bluebird').coroutine;
/**
* 封面图
... ... @@ -92,6 +93,7 @@ const _processClassNames = (list) => {
/**
* 商品搜索接口请求
* TODO 按接口拆分
* @param {[object]} params
* @return {[array]}
*/
... ... @@ -122,10 +124,6 @@ const _searchGoods = (params) => {
method = 'app.search.li';
}
// else if (params.brand && !params.productPool) {
// method = 'app.search.brand';
// }
if (params.channel) {
params.yh_channel = searchProcess.getChannelType(params.channel);
delete params.channel;
... ... @@ -209,7 +207,7 @@ const _processBrandShops = (list) => {
_.forEach(list, item => {
if (item.shop_type === 'yoho_shop') {
formatDat.push({
url: helpers.urlFormat('/product/index/brand/', {
url: helpers.urlFormat('/product/shop', {
shop_id: item.shop_id
}),
thumb: helpers.image(item.shop_logo, 126, 80),
... ... @@ -271,7 +269,7 @@ const getSearchData = (params) => {
for (let i = 0; i < result.data.rec_shop_list.length; i++) {
if (parseInt(result.data.rec_shop_list[i].show_type, 10) === 1) {
result.data.rec_shop_list[i].is_shop = true;
result.data.rec_shop_list[i].shopUrl = '//m.yohobuy.com/product/index/brand?domain=' +
result.data.rec_shop_list[i].shopUrl = '//m.yohobuy.com/product/shop?domain=' +
result.data.rec_shop_list[i].shop_domain;
newList.list.splice(parseInt(result.data.rec_shop_list[i].insert_index, 10) - 1, 0,
result.data.rec_shop_list[i]);
... ... @@ -313,25 +311,71 @@ const getSearchData = (params) => {
};
/**
* 模糊搜索,获取商品数据
*/
const getSearchGoods = (params) => {
let finalParams = {
method: 'app.search.li',
};
finalParams = _.assign(finalParams, searchProcess.getSearchParamsWithoutMethod(params));
return api.get('', finalParams);
};
/**
* 搜索品牌的商品
*/
const getBrandGoods = (params) => {
let finalParams = {
method: 'app.search.brand',
};
finalParams = _.assign(finalParams, searchProcess.getSearchParamsWithoutMethod(params));
return api.get('', finalParams);
};
/**
* 搜索店铺的商品
*/
const getShopGoods = (params) => {
let finalParams = {
method: 'app.search.shop',
};
finalParams = _.assign(finalParams, searchProcess.getSearchParamsWithoutMethod(params));
return api.get('', finalParams);
};
/**
* 获取筛选数据
* @param {[object]} params
* @return {[array]}
*/
const getFilterData = (params) => {
return _searchGoods(params).then((result) => {
if (result && result.code === 200) {
return productProcess.processFilter(result.data.filter || []);
return co(function* () {
let filterDataResult = {};
if (params.isShopBrand === 'Y') { // 店铺之品牌
filterDataResult = yield getBrandGoods(params);
} else if (params.isShopList === 'Y') { // 无店铺有店铺 ID 的商品列表
filterDataResult = yield getShopGoods(params);
} else {
filterDataResult = yield _searchGoods(params);
}
let filterData = _.get(filterDataResult, 'data.filter', []);
if (filterData) {
return productProcess.processFilter(filterData);
} else {
logger.error('get filter data api return code is not 200');
return [];
}
});
})();
};
/**
* 获取筛选数据
* @param {[object]} params
* @return {[array]}
* TODO 这个可能不用了,待确定
*/
const getFilterSearchData = (params) => {
return _searchGoods(params).then((result) => {
... ... @@ -575,6 +619,21 @@ const getSearchKeywordDataById = (id, params, uid) => {
});
};
/**
* 通过 skn 搜索商品
* @param productSkn
* @returns {*|Promise.<TResult>}
* @private
*/
const searchProductBySkn = (productSkn) => {
return api.get('', {
method: 'h5.product.batch',
productSkn: productSkn
}, {code: 200, cache: true}).then(result => {
return _.get(result, 'data.product_list', []);
});
};
module.exports = {
getSearchData,
getFilterData,
... ... @@ -586,5 +645,9 @@ module.exports = {
searchKeyActivity,
getBrandDomain,
getSearchKeywordData,
getSearchKeywordDataById
getSearchKeywordDataById,
getSearchGoods,
getBrandGoods,
getShopGoods,
searchProductBySkn
};
... ...
... ... @@ -5,6 +5,19 @@
const _ = require('lodash');
const helpers = global.yoho.helpers;
const api = global.yoho.API;
const singleAPI = global.yoho.SingleAPI;
const stringProcess = require(`${global.utils}/string-process`);
/**
* 频道
* @type {{}}
*/
const yhChannel = {
boys: 1,
girls: 2,
kids: 3,
lifestyle: 4
};
/**
* 店铺品牌列表
... ... @@ -30,6 +43,192 @@ const getShopBrands = (shopId) => {
});
};
/**
* 获取店铺信息
* @param {int} shopId 店铺id
* @param {int} uid 用户id 判断用户是否收藏店铺
* @return array
*/
const getShopInfo = (shopId, uid) => {
let finalParams = {
method: 'app.shops.getIntro',
shop_id: shopId,
};
if (!shopId || !stringProcess.isNumeric(shopId)) {
return Promise.resolve({});
}
if (uid && uid !== 'undefined') {
Object.assign(finalParams, {
uid: uid
});
}
return api.get('', finalParams);
};
/**
* 根据品牌域名获取品牌LOGO
* @param {string} domain 品牌域名
* @return array | false
*/
const getBrandLogoByDomain = (domain) => {
return api.get('', {
method: 'web.brand.byDomain',
domain: domain
}, {
cache: true
}).then(result => {
if (result && result.data) {
let formatData = result.data;
return {
id: formatData.id,
url: helpers.urlFormat('', null, formatData.brand_domain),
thumb: helpers.image(formatData.brand_ico, 75, 40),
name: formatData.brand_name,
shopId: formatData.shop_id ? formatData.shop_id : 0, // 店铺id
type: formatData.type ? formatData.type : 0,
brandDomain: formatData.brand_domain
};
} else {
return false;
}
});
};
/**
* 获取品牌信息数据
* @param {int} brandId 品牌ID
* @return array banner数据
*/
const getBrandIntro = (brandId, uid) => {
let param = {
uid: uid
};
if (!brandId || brandId === '' || brandId === 'undefined') {
return Promise.resolve({});
}
return api.get('', _.assign({
method: 'app.brand.getBrandIntro',
brand_id: brandId
}, param), {
code: 200
}).then(result => {
if (result && result.data) {
let list = result.data;
return {
id: list.brand_id,
intro: list.brand_intro,
collected: list.is_favorite && list.is_favorite === 'Y',
title: list.brand_name ? list.brand_name : ''
};
} else {
return false;
}
});
};
/**
* 获取品牌banner数据
* @param {int} brandId 品牌ID
* @return array banner数据
*/
const getBrandBanner = (brandId) => {
return api.get('', {
method: 'app.brand.banner',
brand_id: brandId
}, {
cache: true
}).then((result) => {
if (result && result.code === 200 && result.data) {
if (result.data.banner) {
return helpers.image(result.data.banner, 640, 150);
} else {
return '';
}
} else {
return {};
}
});
};
/**
* 获取红人店铺 banner
* doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/商品列表/店铺装修.md
* @param int shopId 店铺id
*/
const getBanner = shopId => {
let params = {
method: 'app.popular.shop.banner',
shop_id: shopId
};
return api.get('', params, {cache: true, code: 200});
};
/**
* 查询红人店铺对应的装修元素
*
* @param int shopId 店铺id
*/
const getShopsdecorator = shopId => {
let params = {
method: 'app.popular.shopsdecorator',
shop_id: shopId
};
return api.get('', params, {cache: true, code: 200});
};
/**
* 获取店铺下面的所有分类
* @param {int} shopId 店铺id
* @param {string} channel 频道
* @return array
*/
const getShopCategory = (shopId, channel) => {
return api.get('', {
method: 'app.shop.getSortInfo',
yh_channel: yhChannel[channel],
shop_id: shopId
});
};
/**
* 店铺收藏数量
*/
const favCount = (shopId, uid, channel, udid) => {
let finalParams = {
method: 'app.favorite.queryFavoriteCountByShopIds',
favIds: shopId,
type: 'shop',
udid: udid,
physical_channel: yhChannel[channel],
};
if (uid) {
Object.assign(finalParams, {
uid: uid
});
}
return singleAPI.get('favorite', finalParams);
};
module.exports = {
getShopBrands
getShopBrands,
getShopInfo,
getBrandLogoByDomain,
getBrandIntro,
getBrandBanner,
getBanner,
getShopsdecorator,
getShopCategory,
favCount
};
... ...
... ... @@ -147,9 +147,9 @@ router.get('/search/filter', search.filter);
// fuzzyDatas
router.get('/search/fuzzyDatas', search.fuzzyDatas);
// ajax 请求商品数据
router.get('/search/search', search.search);
router.get('/search/search', search.search); // ajax 请求商品数据
router.get('/search/brand/goods', search.searchBrandGoods); // 搜索品牌下的商品
router.get('/search/shop/goods', search.searchShopGoods); // 搜索店铺下的商品
// 品类
router.get('/index/index', rewrite.sortParams, list.category);
router.get('/list/index', rewrite.sortParams, list.category); // 兼容 PC 的链接
... ... @@ -164,8 +164,8 @@ router.get('/index/getShopCouponsList', list.getShopCouponsList);
router.get('/index/getBrandCouponsList', list.getBrandCouponsList);
// 店铺重构
router.get('/index/brand', newShop.index);
router.get('/index/baseShopFav', newShop.baseShopFav);
router.get('/shop', newShop.entry); // 统一店铺入口
router.get('/index/brand', newShop.entry); // 旧的路由,走到新的 controller
router.get('/index/brandFav', newShop.brandFav);
router.get('/new/shop/hotlist', newShop.shopHotList);
... ...
<div class="good-list-page yoho-page">
{{# goodList}}
{{# search}}
<div id="search-input" class="search-input">
<form id="search-form" action="{{url}}" method="get">
<i class="search-icon iconfont">&#xe60f;</i>
<input type="text" value="{{default}}" name="query" class="buriedpoint" data-bp-id="shop-search_input_1" autocomplete="off">
<input type="hidden" value="search" name="from">
<i class="clear-input iconfont hide">&#xe626;</i>
<span id="search" class="search buriedpoint" type="submit" data-bp-id="shop-search_btn_0">搜索</span>
</form>
</div>
<ul class="search-associate"></ul>
{{/ search}}
{{#if brandWay}}
<div class="brand-way">
<div class="brand-enter">
{{# brandWay}}
<a href={{url}} data-shopid="{{shopId}}" data-brandid="{{brandId}}">
<img class="brand-thumb" src={{image2 thumb q=60}}>
<span class="brand-name">{{name}}</span>
<span class="entry">
进入店铺
<i class="iconfont">&#xe614;</i>
</span>
</a>
{{/ brandWay}}
</div>
{{#if brandWay.moreShop}}
<div class="more-shop down">
<span class="iconfont">&#xe616;</span>
</div>
{{/if}}
</div>
{{/if}}
<!-- 品牌页面 -->
{{# brandHome}}
<div id="brand-header" class="brand-header" data-id={{id}}>
<img src={{image2 banner q=60}}>
<a class="btn-intro" href="javascript:void(0);">
品牌介绍
</a>
<a class="btn-col" href="javascript:void(0);">
<span class="iconfont">&#xe622;</span>
<span class="txt"></span>
</a>
</div>
<div id="intro-box" class="brand-intro-box hide">
<div id="brand-intro" class="brand-intro">
<h2>品牌介绍</h2>
<div class="con">
{{{intro}}}
</div>
<p class="fo">
<span class="iconfont">&#xe629;</span> 100%品牌授权正品
</p>
<span class="iconfont close-intro">&#xe623;</span>
</div>
</div>
{{/ brandHome}}
<!-- 优惠卷 -->
<div class="coupon-group"></div>
<!-- /品牌页面 -->
{{!--筛选tab--}}
{{> product/filter-tab-new}}
<div id="goods-container" class="goods-container">
<div class="default-goods container clearfix">
{{!--搜索推荐词模板--}}
{{> search/search-word-content}}
{{#newGoods}}
{{> common/goods}}
{{/newGoods}}
</div>
<div class="new-goods container clearfix hide"></div>
<div class="price-goods container clearfix hide"></div>
<div class="discount-goods container clearfix hide"></div>
<div class="popularity-goods container clearfix hide"></div>
{{> common/filter}}
</div>
{{!--搜索列表显示过少,显示猜您喜欢--}}
{{#if @root.suggestion.isMaybeLike}}
<div class="maybe-like-search">你可能喜欢</div>
<div class='maybe-like'>
<div id="goods-list" class="goods-list clearfix"></div>
</div>
{{/if}}
{{> common/query-param}}
{{> common/suspend-cart}}
{{/ goodList}}
<input type="text" class="domain" style="display:none" value={{domain}}>
</div>
<div class="good-list-page yoho-page">
{{# goodList}}
<!-- 基础店铺页面 -->
{{# baseShopHome}}
<div id="brand-header" class="brand-header" data-id={{id}} data-isbaseshop="{{isBaseShop}}">
{{#if brandInfo.banner}}
{{# brandInfo}}
<div id="brand-header" class="brand-header" data-id={{id}}>
<img src={{image2 banner q=60}}>
<a class="btn-intro" href="javascript:void(0);">
店铺介绍
</a>
品牌介绍
</a>
<a class="btn-col" href="javascript:void(0);">
<span class="iconfont">&#xe622;</span>
<span class="txt"></span>
... ... @@ -14,43 +13,36 @@
</div>
<div id="intro-box" class="brand-intro-box hide">
<div id="brand-intro" class="brand-intro">
<h2>店铺介绍</h2>
<h2>品牌介绍</h2>
<div class="con">
{{{intro}}}
</div>
<p class="fo">
<span class="iconfont">&#xe629;</span>
100%品牌授权正品
<span class="iconfont">&#xe629;</span> 100%品牌授权正品
</p>
<span class="iconfont close-intro">&#xe623;</span>
</div>
</div>
<input type="hidden" name="app_version" value="{{appVersion}}">
{{/ baseShopHome}}
{{/ brandInfo}}
{{/if}}
<!-- 优惠卷 -->
<div class="coupon-group"></div>
<!-- /基础店铺页面 -->
<!-- /品牌页面 -->
{{!--筛选tab--}}
{{> product/filter-tab-new}}
<div class="filter-box">
{{> product/filter-tab-new}}
{{> common/filter}}
</div>
<div id="goods-container" class="goods-container">
<div class="default-goods container clearfix">
{{#newGoods}}
{{#goodsList}}
{{> common/goods}}
{{/newGoods}}</div>
<div class="new-goods container clearfix hide"></div>
<div class="price-goods container clearfix hide"></div>
<div class="discount-goods container clearfix hide"></div>
<div class="popularity-goods container clearfix hide"></div>
{{> common/filter}}
{{/goodsList}}
</div>
</div>
{{> common/query-param}}
{{> common/suspend-cart}}
{{/ goodList}}
<input type="text" class="shopId" style="display:none" value={{shopId}}>
<input type="hidden" id="brandId" value={{brandId}}>
</div>
... ...
{{# shopIndex}}
<div class="shop-index yoho-page scroll-wrapper new-shop" id="wrapper">
<div id="scroller">
<div id="nav-top">
{{> header}}
<!-- tar modifield 160826 -->
<input type="hidden" name="app_version" value="{{appVersion}}">
<input type="hidden" name="shop_id" value="{{../shopId}}">
<input type="hidden" name="brand" value="{{brand}}">
<input type="hidden" name="favId" value="{{favId}}">
<input type="hidden" name="coverChannel" value="{{coverChannel}}">
<input type="hidden" name="uid" value="{{uid}}">
{{#unless appVersion}}
<div class="search-area">
<div id="search-input" class="search-input">
<form id="search-form" action={{url}} method="get">
<i class="search-icon iconfont">&#xe60f;</i>
<input type="text" placeholder="搜索店铺内潮品" name="query" class="buriedpoint">
<input type="hidden" name="shop_id" value="{{../shopId}}">
<input type="hidden" name="coverChannel" value="{{coverChannel}}">
<i class="clear-input iconfont hide">&#xe626;</i>
<button id="search" class="search buriedpoint" type="submit"
data-bp-id="shop_search_btn_0">搜索
</button>
</form>
</div>
</div>
{{/unless}}
<!-- /tar modifield 160826 -->
<div class="branner-top">
<img class="shop-back-img" src="{{image2 branerImg w=640 h=200 mode=1 q=60}}">
{{#if logoImg}}
<img class="logo" src="{{image2 logoImg w=500 h=500 q=60}}">
{{/if}}
<p class="store-name">{{storeName}}</p>
<div class="collect">
<div class="not-collect buriedpoint" id="collect" data-bp-id="shop_branner_collect_1"></div>
</div>
</div>
</div>
<ul id="nav" class="nav">
<li class="active color buriedpoint" tab="home-page" data-bp-id="shop_nav_index_1"><div class="text">首页</div></li>
<li tab="new-arrival" data-bp-id="shop_nav_new_1" class="buriedpoint"><div class="text">上新</div></li>
<li tab="popularity" data-bp-id="shop_nav_populary_1" class="buriedpoint"><div class="text">人气</div></li>
<li data-bp-id="shop_nav_all_1" class="all-goods buriedpoint">
<div class="text"><a href="{{allGoods}}" target="_blank">全部商品</a></div>
</li>
</ul>
<div id="home-page" class="main">
<div id="nav-main" class="nav-main">
<!-- 优惠卷 -->
<div class="coupon-group"></div>
<!-- 大导航 -->
{{#if brandList}}
<div class="multi-brands first">
<p>品牌一览</p>
<div class="multi-browse">
<ul class="swiper-wrapper">
{{#each brandList.list}}
<li class="swiper-slide brand-img buriedpoint"
data-bp-id="shop_brand_{{img}}_0">
<a href="{{url}}">
<img src="{{image2 img q=60}}">
</a>
<p>{{brandName}}</p>
</li>
{{/each}}
</ul>
</div>
</div>
{{/if}}
<div class="banner-area first">
{{# bannerTop}}
{{> resources/banner-top}}
{{/ bannerTop}}
</div>
<ul class="spring">
{{#each spring}}
<li class="buriedpoint" data-bp-id="shop_spring_{{url}}_0">
{{#if url}}
<a href="{{url}}">
<img src="{{image2 springType q=60}}">
</a>
{{^}}
<a href="javascript:;">
<img src="{{image2 springType q=60}}">
</a>
{{/if}}
</li>
{{/each}}
</ul>
{{! 热门品类}}
<div class="first">
{{# hotCategory}}
{{> shop/hot-category}}
{{/ hotCategory}}
</div>
<div class="popularity-title" data-skns="{{hotListproductSkn}}">
人气单品
<a class="more buriedpoint" href="{{more_url}}" data-bp-id="shop_popularity_{{more_url}}">
&#xe618;</a>
</div>
<div class="product-warp">
<div class="goods-container clearfix">
</div>
</div>
</div>
<div class="discount-area first" id="navlist2">
<ul id="list-nav" class="home-sub-nav list-nav pos-list clearfix">
<li class="default active buriedpoint first-li-more" data-bp-id="shop_listnav_default_1">
<a href="javascript:void(0);">
<span class="nav-txt">默认</span>
<span class="iconfont drop">&#xe613;</span>
</a>
</li>
<li class="new buriedpoint" data-bp-id="shop_listnav_new_1">
<a href="javascript:void(0);">
<span class="nav-txt">新品</span>
</a>
</li>
<li class="popu buriedpoint" data-bp-id="shop_listnav_new_1">
<a href="javascript:void(0);">
<span class="nav-txt">人气</span>
</a>
</li>
<li class="price buriedpoint" data-bp-id="shop_listnav_price_1">
<a href="javascript:void(0);">
<span class="spanTest">价格</span>
<span class="icon">
<i class="iconfont up cur">&#xe615;</i>
<i class="iconfont down">&#xe616;</i>
</span>
</a>
</li>
<!-- <li class="discount buriedpoint" data-bp-id="shop_listnav_discount_1">
<a href="javascript:void(0);">
<span class="spanTest">折扣</span>
<span class="icon">
<i class="iconfont up cur">&#xe615;</i>
<i class="iconfont down">&#xe616;</i>
</span>
</a>
</li> -->
<li class="filter buriedpoint" data-bp-id="shop_listnav_filter_1">
<a href="javascript:void(0);">
<span class="spanTest">筛选</span>
<span class="iconfont cur">&#xe613;</span>
</a>
</li>
</ul>
<ul class="drop-list first-list hide">
<li class="default active first-li-more" data-bp-id="shop_listnav_default_1" data-text="默认">
<span>默认</span>
<span class="chose"></span>
</li>
<li class="discount dec" data-bp-id="shop_listnav_popularity_1" data-text="折扣">
<span>折扣从高到低</span>
<span class="chose"></span>
</li>
<li class="discount asc" data-bp-id="shop_listnav_popularity_1" data-text="折扣">
<span>折扣从低到高</span>
<span class="chose"></span>
</li>
</ul>
</div>
<div class="discount-area first">
<div id="goods-container" class="goods-container">
<div class="default-goods container clearfix">
{{#newGoods}}
{{> common/goods}}
{{/newGoods}}</div>
<div class="new-goods container clearfix hide"></div>
<div class="price-goods container hide clearfix"></div>
<div class="discount-goods container hide clearfix"></div>
<div class="popularity-goods container clearfix hide"></div>
</div>
</div>
</div>
<div id="new-arrival" class="new-arrival main hide"></div>
<div id="popularity" class="popularity main hide"></div>
</div>
{{#unless appVersion}}
{{> shop/shop-footer}}
{{/unless}}
<ul id="pos-nav" class="nav hide">
<li class="active color buriedpoint" tab="home-page" data-bp-id="shop_posnav_index_1"><div class="text">首页</div></li>
<li tab="new-arrival" class="buriedpoint" data-bp-id="shop_posnav_new_1"><div class="text">上新</div></li>
<li tab="popularity" class="buriedpoint" data-bp-id="shop_posnav_populary_1"><div class="text">人气</div></li>
<li class="all-goods buriedpoint" data-bp-id="shop_posnav_all_1">
<div class="text"><a href="{{allGoods}}" target="_blank">全部商品</a></div>
</li>
</ul>
<!-- <div class="pos-list-area"> -->
<ul id="pos-list" class="home-sub-nav pos-list hide">
<li class="default active buriedpoint first-li-more" data-bp-id="shop_listnav_default_1">
<a href="javascript:void(0);">
<span class="nav-txt">默认</span>
<span class="iconfont drop">&#xe613;</span>
</a>
</li>
<li class="new buriedpoint" data-bp-id="shop_listnav_new_1">
<a href="javascript:void(0);">
<span class="nav-txt">新品</span>
</a>
</li>
<li class="popu buriedpoint" data-bp-id="shop_listnav_popularity_1">
<a href="javascript:void(0);">
<span class="nav-txt">人气</span>
</a>
</li>
<li class="price buriedpoint" data-bp-id="shop_poslist_price_1">
<a href="javascript:void(0);">
<span class="spanTest">价格</span>
<span class="icon">
<i class="iconfont up cur">&#xe615;</i>
<i class="iconfont down">&#xe616;</i>
</span>
<b></b>
</a>
</li>
<!-- <li class="discount buriedpoint" data-bp-id="shop_poslist_discount_1">
<a href="javascript:void(0);">
<span class="spanTest">折扣</span>
<span class="icon">
<i class="iconfont up cur">&#xe615;</i>
<i class="iconfont down">&#xe616;</i>
</span>
<b></b>
</a>
</li> -->
<li class="filter buriedpoint" data-bp-id="shop_poslist_filter_1">
<a href="javascript:void(0);">
<span class="spanTest">筛选</span>
<span class="iconfont cur">&#xe613;</span>
</a>
</li>
</ul>
<ul class="drop-list pos-drop hide">
<li class="default active" data-bp-id="shop_listnav_default_1" data-text="默认">
<span>默认</span>
<span class="chose"></span>
</li>
<li class="discount dec" data-bp-id="shop_listnav_popularity_1" data-text="折扣">
<span>折扣从高到低</span>
<span class="chose"></span>
</li>
<li class="discount asc" data-bp-id="shop_listnav_popularity_1" data-text="折扣">
<span>折扣从低到高</span>
<span class="chose"></span>
</li>
</ul>
<!-- </div> -->
</div>
{{> common/filter}}
{{/ shopIndex}}
{{> common/query-param}}
<input type="text" class="shopId" style="display:none" value={{shopId}}>
<div class="good-list-page yoho-page">
{{!--筛选tab--}}
<div class="filter-box">
{{> product/filter-tab-new}}
{{> common/filter}}
</div>
<div id="goods-container" class="goods-container">
<div class="default-goods container clearfix">
{{#goodsList}}
{{> common/goods}}
{{/goodsList}}
</div>
</div>
{{> common/suspend-cart}}
<input type="hidden" id="shopId" value={{shopId}}>
</div>
\ No newline at end of file
... ...
{{# goodsList}}
{{> common/goods}}
{{/ goodsList}}
\ No newline at end of file
... ...
... ... @@ -62,6 +62,7 @@ const cachePage = {
'/product/list/index': 1 * MINUTE,
'/product/index/index': 1 * MINUTE,
'/product/index/brand': 1 * MINUTE,
'/product/shop': 1 * MINUTE,
'/product/search/search': 1 * MINUTE,
*/
... ...
... ... @@ -14,8 +14,8 @@ const domains = {
// api: 'http://192.168.103.59:8080/gateway',
// service: 'http://192.168.103.59:8080/gateway',
api: 'http://api-test3.yohops.com:9999/',
service: 'http://service-test3.yohops.com:9999/',
api: 'http://api.yoho.cn/',
service: 'http://service.yoho.cn/',
singleApi: 'http://api-test2.yohops.com:9999/',
global: 'http://global-test-soa.yohops.com:9999',
liveApi: 'http://testapi.live.yohops.com:9999/',
... ...
... ... @@ -80,7 +80,7 @@ module.exports = () => {
req.query = Object.assign(req.query, {
domain: req.subdomains[0]
});
req.url = `/product/index/brand?${querystring.stringify(req.query)}`;
req.url = `/product/shop?${querystring.stringify(req.query)}`;
}
break;
}
... ...
... ... @@ -9,6 +9,6 @@
<h5>{{shop_name}}</h5>
</div>
<div class="count">上新{{new_product_num}}<i class="iconfont">&#xe604;</i></div>
<a class="link" href="http://m.yohobuy.com/product/index/brand?domain={{shop_domain}}"></a>
<a class="link" href="http://m.yohobuy.com/product/shop?domain={{shop_domain}}"></a>
</div>
{{/each}}
\ No newline at end of file
... ...
... ... @@ -4,13 +4,18 @@ import {
Controller
} from 'yoho-mvc';
const allProduct = require('../../product/shop/all-product');
const ProductListWithFilter = require('product/list/product-list-with-filter');
const lazyLoad = require('yoho-jquery-lazyload');
let productListWithFilter = new ProductListWithFilter({
page: 2,
material: true,
unionType: window.queryString.union_type
});
class MaterialController extends Controller {
constructor() {
super();
allProduct.getFilter();
productListWithFilter.getFilter();
lazyLoad($('img.lazy'));
}
}
... ...
/**
* {{!--筛选tab--}}
<div class="filter-box">
{{> product/filter-tab-new}}
{{> common/filter}}
</div>
<div id="goods-container" class="goods-container">
<div class="default-goods container clearfix"></div>
</div>
*/
const filter = require('plugin/filter');
const noResultHbs = require('product/search/no-result-new.hbs');
const lazyLoad = require('yoho-jquery-lazyload');
class ProductListWithFilter {
constructor(filterParams, searchUrl, extra) {
this.scrollActived = true; // 是否激活滚动加载,默认激活
this.filterParams = filterParams;
this.searchUrl = location.protocol + '//m.yohobuy.com/' + (searchUrl || 'product/search/search');
this.filterUrl = location.protocol + '//m.yohobuy.com/product/search/filter';
this.goodsTotal = extra && extra.goodsTotal; // YAS 需要数据
this.view = {
goodsContainer: $('#goods-container'),
container: $('#goods-container').children('.default-goods'),
listNav: $('#list-nav'),
pre: $('#list-nav').find('.active'),
filterBody: $('.filter-body'),
dropList: $('.drop-list'),
firstText: $('.first-li-more').find('.nav-txt')
};
this.navInfo = {
price: {
order: 1,
end: false
},
discount: {
order: 1,
end: false
},
default: {
order: 0,
end: false,
type: 'default'
},
new: {
order: 0,
end: false
},
sale: {
order: 0,
end: false
},
popularity: {
order: 0,
end: false
}
};
this.beforeScroll = document.body.scrollTop; // 滚动前位置记录
this.navType = 'default'; // 目前激活的导航页面
this.nav = this.navInfo[this.navType];
this.defaultOpt = Object.assign({}, this.navInfo.default, this.filterParams); // 默认参数
this.onSearching = false; // 是否正在搜索
this.isScrollLoad = false; // 是否是滚动加载
this.page = filterParams.page || 1;
this.view.listNav.bind('contextmenu', function() {
return false;
});
this.view.listNav.on('touchend touchcancel', this.listNavTouch.bind(this));
/**
* 滚动加载
*/
$(window).scroll(() => {
if (this.scrollActived) {
setTimeout(() => {
let afterScroll = document.body.scrollTop;
if (afterScroll - this.beforeScroll > 0) {
window.requestAnimationFrame(() => {
this.scrollHandler();
});
this.beforeScroll = afterScroll;
} else {
this.beforeScroll = afterScroll;
return false;
}
}, 5);
}
});
}
/**
* 处理筛选参数
*/
handleChoseFilter() {
$.each(this.view.filterBody.find('.chosed'), (index, elem) => {
let choseOpt = {};
choseOpt[$(elem).parent().data('type')] = $(elem).data('id');
Object.assign(this.defaultOpt, choseOpt);
});
}
/**
* 获取商品列表
*/
getGoodsList(params) {
this.handleChoseFilter();
if (!this.onSearching) {
Object.assign(this.defaultOpt, {
page: this.page++
});
}
// 有参数,参数优先,滚动加载相关参数重置
if (params && !params.filtering) {
Object.assign(this.defaultOpt, params);
if (params.page) {
this.page = params.page + 1;
}
this.isScrollLoad = false;
this.beforeScroll = document.body.scrollTop;
}
if (this.nav && this.nav.end) {
return false;
}
if (!this.onSearching) {
this.onSearching = true;
$.ajax({
type: 'GET',
url: this.searchUrl,
data: this.defaultOpt,
xhrFields: {
withCredentials: true
},
beforeSend: () => {
if ($('.no-result-new').length > 0) {
$('.no-result-new').remove();
}
this.view.container.after(() => {
return '<div class="search-divide">正在加载...</div>';
});
},
success: (result) => {
// 去掉正在加载
$('.search-divide').remove();
let noResult = !result || result.length < 1 || (result.list && result.list.length < 1);
// 没有结果输出没有结果页面
if (noResult) {
if (this.isScrollLoad) {
this.view.container.after(() => {
return '<div class="search-divide">没有更多内容了...</div>';
});
} else {
this.view.container.html(noResultHbs());
}
if (this.nav) {
this.nav.end = true;
}
this.onSearching = false;
return false;
}
if (this.isScrollLoad) {
this.view.container.append(result);
} else {
this.view.container.html(result);
}
lazyLoad(this.view.container.find('img[class=lazy]').not('img[src]'));
this.onSearching = false;
},
error: () => {
let $divide = $('.search-divide');
$divide.text('加载失败,点击重试');
$divide.one('click', function() {
$divide.text('正在加载...');
this.getGoodsList();
});
this.onSearching = false;
}
});
}
}
/**
* 加载筛选数据
*/
getFilter() {
$.ajax({
type: 'GET',
url: this.filterUrl,
data: this.filterParams,
success: (data) => {
if (!data) {
return false;
}
this.view.goodsContainer.append(data);
// 初始化filter&注册filter回调
filter.initFilter({
fCbFn: () => {
this.getGoodsList();
},
hCbFn: () => {
// 切换active状态到$pre上
this.view.pre.addClass('active');
this.view.pre.siblings('.filter').removeClass('active');
}
});
this.view.filterBody = $('.filter-body');
}
});
}
popularityFilter(thisLi, type) {
if (thisLi.hasClass('active')) {
this.view.dropList.hide();
return false;
}
this.view.thisLi.addClass('active').siblings('li').removeClass('active');
this.defaultOpt.type = type;
this.nav = this.navInfo[type];
if (thisLi.hasClass('asc')) {
this.nav.order = 1;
} else {
this.nav.order = 0;
}
Object.assign(this.defaultOpt, this.nav);
this.getGoodsList();
this.view.dropList.hide();
}
listNavTouch(elem) {
this.page = 1;
this.beforeScroll = $(window).scrollTop();
this.isScrollLoad = false;
let $this = $(elem.target).closest('li'); // 被点击的 Tab
let $active;
// 默认列表增加人气筛选
if ($this.hasClass('first-li-more') && $this.hasClass('active')) {
$this.siblings('.active').removeClass('active');
$this.addClass('active');
this.view.dropList.toggle();
this.view.dropList.find('.default').on('touchend touchcancel', (e) => {
this.view.thisLi = $(e.target);
this.view.firstText.html('默认');
this.popularityFilter(this.view.thisLi, 'default');
return false;
});
this.view.dropList.find('.discount').on('touchend touchcancel', (e) => {
this.view.thisLi = $(e.target);
this.view.firstText.html(this.view.thisLi.data('text'));
this.popularityFilter(this.view.thisLi, 'discount');
$('.first-li-more').removeClass('new default sale discount').addClass('discount');
return false;
});
} else if ($this.hasClass('filter')) { // 筛选面板
this.view.dropList.css('display', 'none');
// 筛选面板切换状态
if ($this.hasClass('active')) {
filter.hideFilter();
// 点击筛选前的 active 项恢复 active
this.view.pre.addClass('active');
$this.removeClass('active');
} else {
this.view.pre = $this.siblings('.active');
this.view.pre.removeClass('active');
$this.addClass('active');
filter.showFilter();
}
} else { // 排序改变
this.view.dropList.css('display', 'none');
if ($this.hasClass('new')) {
this.navType = 'new';
} else if ($this.hasClass('price')) {
this.navType = 'price';
} else if ($this.hasClass('discount')) {
this.navType = 'discount';
} else if ($this.hasClass('default')) {
this.navType = 'default';
} else if ($this.hasClass('sale')) {
this.navType = 'sale';
} else if ($this.hasClass('popularity')) {
this.navType = 'popularity';
}
// 更新当前排序:默认、最新、价格、折扣
this.nav = this.navInfo[this.navType];
if ($this.hasClass('active')) {
// 默认、最新无排序切换
if ($this.hasClass('default') || $this.hasClass('new') || $this.hasClass('popularity')) {
return false;
}
if ($this.hasClass('price') || $this.hasClass('discount')) {
// 价格或折扣切换排序状态
$this.find('.icon > .iconfont').toggleClass('cur');
this.view.pre = $this; // 更新 pre 为当前项
this.nav.order = this.nav.order === 0 ? 1 : 0; // 切换排序
}
} else {
$active = $this.siblings('.active');
this.view.$pre = $this; // $pre为除筛选导航的其他导航项,若当前active的为筛选,则把$pre置为当前点击项
if ($active.hasClass('filter')) {
// 若之前active项为筛选,则隐藏筛选面板
filter.hideFilter();
}
$active.removeClass('active');
$this.addClass('active');
}
/* 排序条件更新 */
this.defaultOpt.type = this.navType;
Object.assign(this.defaultOpt, this.nav);
this.getGoodsList();
}
}
/**
* 当scroll到1/2$goodsContainer高度后继续请求下一页数据
*/
scrollHandler() {
let goodsContainerHeight = this.view.goodsContainer.height();
if ($(window).scrollTop() > goodsContainerHeight * 0.6) {
this.isScrollLoad = true;
this.getGoodsList();
}
}
}
module.exports = ProductListWithFilter;
... ...
... ... @@ -132,22 +132,6 @@ ellipsis.init();
tip.show('网络断开连接了~');
}
});
} else if ($('.shopId').val() && $('.shopId').val() !== 'undefined') {
$.ajax({
url: '/product/index/baseShopFav',
data: {
shopId: $('.shopId').val()
},
dataType: 'json',
success: function(data) {
if (data.collect) {
$('.brand-header .btn-col').addClass('coled');
}
},
error: function() {
tip.show('网络断开连接了~');
}
});
}
}());
... ...
require('product/shop/shop.page.css');
let ProductListWithFilter = require('product/list/product-list-with-filter');
const brandId = $('#brandId').val();
let productListWithFilterModel =
new ProductListWithFilter({
brand_id: brandId,
page: 2, // 首页服务端已经渲染
isShopBrand: 'Y' // 传给 filter,表明调用哪个接口获取筛选面板的数据
}, 'product/search/brand/goods');
productListWithFilterModel.getFilter();
... ...
require('product/shop/shop.page.css');
let ProductListWithFilter = require('product/list/product-list-with-filter');
const shopId = $('#shopId').val();
let productListWithFilterModel =
new ProductListWithFilter({
shop_id: shopId,
page: 2, // 首页服务端已经渲染
isShopList: 'Y' // 传给 filter,表明调用哪个接口获取筛选面板的数据
}, 'product/search/shop/goods');
productListWithFilterModel.getFilter();
... ...
... ... @@ -3,25 +3,38 @@ require('product/search/list.page.css');
require('product/shop/redshop.page.css');
const $ = require('yoho-jquery');
const allProduct = require('./shop/all-product');
const shopId = $('#shopId').val();
const ProductListWithFilter = require('product/list/product-list-with-filter');
let Tab = require('../plugin/tab');
let $filterBox = $('.filter-box');
let $shopCategory = $('#shop-category');
let $listNav = $('#list-nav'); // 筛选项列表
/**
* 初始化全部商品 TAB 页
*/
let productListWithFilter = new ProductListWithFilter({
shop_id: shopId
});
productListWithFilter.scrollActived = false;
Tab.prototype.home = function() { // 隐藏筛选 TAB
$filterBox.css('display', 'none');
productListWithFilter.scrollActived = false;
};
Tab.prototype.getallgoods = function() { // 显示筛选 TAB
$listNav.find('li').removeClass('active');
$listNav.find('.default').addClass('active');
$filterBox.css('display', 'block');
allProduct.getGoodsList({type: 'default', page: 1});
productListWithFilter.getGoodsList({type: 'default', page: 1});
productListWithFilter.scrollActived = true;
};
Tab.prototype.getnewgoods = function() {
$filterBox.css('display', 'none');
allProduct.getGoodsList({type: 'new', page: 1});
productListWithFilter.getGoodsList({type: 'new', page: 1});
productListWithFilter.scrollActived = true;
};
/**
... ... @@ -35,7 +48,7 @@ if ($shopCategory.length > 0) {
// 页面打开直接加载筛选项
allProduct.getFilter();
productListWithFilter.getFilter();
require('../plugin/sticky');
require('./shop/coupon');
... ...
/*
* @Author: Targaryen
* @Date: 2017-03-24 13:43:55
* @Last Modified by: Targaryen
* @Last Modified time: 2017-06-20 09:50:01
*/
/** *****************************
* 红人店铺使用的全部商品页面碎片
*******************************/
const filter = require('../../plugin/filter');
const lazyLoad = require('yoho-jquery-lazyload');
let noResultHbs = require('product/search/no-result-new.hbs');
let $goodsContainer = $('#goods-container');
let $container = $goodsContainer.children('.default-goods'); // 承载商品列表的容器
let $listNav = $('#list-nav'); // 筛选项列表
let $pre = $listNav.find('.active'); // 记录进入筛选前的active项,初始为选中项
let $allGoodsTabPage = $(document.getElementById('all-goods'));
let $filterBody = $('.filter-body');
let $dropList = $('.drop-list');
const shopId = $('#shopId').val();
let navInfo = {
price: {
order: 1,
end: false
},
discount: {
order: 1,
end: false
},
default: {
order: 0,
end: false,
type: 'default'
},
new: {
order: 0,
end: false
},
sale: {
order: 0,
end: false
},
popularity: {
order: 0,
end: false
}
};
let beforeScroll = document.body.scrollTop; // 滚动前位置记录
let navType = 'default'; // 目前激活的导航页面
let defaultOpt = Object.assign({}, navInfo.default, {shop_id: shopId}); // 默认参数
let onSearching = false; // 是否正在搜索
let isScrollLoad = false; // 是否是滚动加载
let page = 1; // 页码
let nav;
let $firstText = $('.first-li-more').find('.nav-txt');
let $thisLi = '';
// 物料商品列表标记
if ($('#material-flag').val() === 'material') {
let material = true;
if ($('.first-li-more').hasClass('active')) {
page = 2; // 已在服务端渲染第一页
}
Object.assign(defaultOpt, {
material: material,
unionType: window.queryString.union_type
});
}
/**
* 处理筛选参数
*/
const handleChoseFilter = function() {
$.each($filterBody.find('.chosed'), function(index, elem) {
let choseOpt = {};
choseOpt[$(elem).parent().data('type')] = $(elem).data('id');
Object.assign(defaultOpt, choseOpt);
});
};
/**
* 获取商品列表
*/
const getGoodsList = params => {
handleChoseFilter();
if (!onSearching) {
Object.assign(defaultOpt, {
page: page++
});
}
// 有参数,参数优先,滚动加载相关参数重置
if (params && !params.filtering) {
Object.assign(defaultOpt, params);
if (params.page) {
page = params.page + 1;
}
isScrollLoad = false;
beforeScroll = document.body.scrollTop;
}
if (nav && nav.end) {
return false;
}
if (!onSearching) {
onSearching = true;
$.ajax({
type: 'GET',
url: location.protocol + '//m.yohobuy.com/product/search/search',
data: defaultOpt,
xhrFields: {
withCredentials: true
},
beforeSend: function() {
if ($('.no-result-new').length > 0) {
$('.no-result-new').remove();
}
$container.append('<div class="search-divide">正在加载...</div>');
},
success: function(result) {
// 去掉正在加载
$('.search-divide').remove();
let noResult = !result || result.length < 1 || (result.list && result.list.length < 1);
// 没有结果输出没有结果页面
if (noResult) {
if (isScrollLoad) {
$container.append('<div class="search-divide">没有更多内容了...</div>');
} else {
$container.html(noResultHbs());
}
if (nav) {
nav.end = true;
}
onSearching = false;
return false;
}
if (isScrollLoad) {
$container.append(result);
} else {
$container.html(result);
}
lazyLoad($container.find('img[class=lazy]').not('img[src]'));
onSearching = false;
},
error: function() {
let $divide = $('.search-divide');
$divide.text('加载失败,点击重试');
$divide.one('click', function() {
$divide.text('正在加载...');
getGoodsList();
});
onSearching = false;
}
});
}
};
/**
* 加载筛选数据
*/
const getFilter = function() {
$.ajax({
type: 'GET',
url: location.protocol + '//m.yohobuy.com/product/search/filter',
data: defaultOpt,
success: function(data) {
if (!data) {
return false;
}
$goodsContainer.append(data);
// 初始化filter&注册filter回调
filter.initFilter({
fCbFn: getGoodsList,
hCbFn: function() {
// 切换active状态到$pre上
$pre.addClass('active');
$pre.siblings('.filter').removeClass('active');
}
});
$filterBody = $('.filter-body');
}
});
};
$listNav.bind('contextmenu', function() {
return false;
});
const popularityFilter = function(thisLi, type) {
if (thisLi.hasClass('active')) {
$dropList.hide();
return false;
}
$thisLi.addClass('active').siblings('li').removeClass('active');
defaultOpt.type = type;
nav = navInfo[type];
if (thisLi.hasClass('asc')) {
nav.order = 1;
} else {
nav.order = 0;
}
Object.assign(defaultOpt, nav);
getGoodsList();
$dropList.hide();
};
$listNav.on('touchend touchcancel', function(e) {
page = 1;
beforeScroll = $(window).scrollTop();
isScrollLoad = false;
let $this = $(e.target).closest('li'); // 被点击的 Tab
let $active;
// 默认列表增加人气筛选
if ($this.hasClass('first-li-more') && $this.hasClass('active')) {
$this.siblings('.active').removeClass('active');
$this.addClass('active');
$dropList.toggle();
$dropList.find('.default').on('touchend touchcancel', function() {
$thisLi = $(this);
$firstText.html('默认');
popularityFilter($thisLi, 'default');
return false;
});
$dropList.find('.discount').on('touchend touchcancel', function() {
$thisLi = $(this);
$firstText.html($(this).data('text'));
popularityFilter($thisLi, 'discount');
$('.first-li-more').removeClass('new default sale discount').addClass('discount');
return false;
});
} else if ($this.hasClass('filter')) { // 筛选面板
$dropList.css('display', 'none');
// 筛选面板切换状态
if ($this.hasClass('active')) {
filter.hideFilter();
// 点击筛选前的 active 项恢复 active
$pre.addClass('active');
$this.removeClass('active');
} else {
$pre = $this.siblings('.active');
$pre.removeClass('active');
$this.addClass('active');
filter.showFilter();
}
} else { // 排序改变
$dropList.css('display', 'none');
if ($this.hasClass('new')) {
navType = 'new';
} else if ($this.hasClass('price')) {
navType = 'price';
} else if ($this.hasClass('discount')) {
navType = 'discount';
} else if ($this.hasClass('default')) {
navType = 'default';
} else if ($this.hasClass('sale')) {
navType = 'sale';
} else if ($this.hasClass('popularity')) {
navType = 'popularity';
}
// 更新当前排序:默认、最新、价格、折扣
nav = navInfo[navType];
if ($this.hasClass('active')) {
// 默认、最新无排序切换
if ($this.hasClass('default') || $this.hasClass('new') || $this.hasClass('popularity')) {
return false;
}
if ($this.hasClass('price') || $this.hasClass('discount')) {
// 价格或折扣切换排序状态
$this.find('.icon > .iconfont').toggleClass('cur');
$pre = $this; // 更新 pre 为当前项
nav.order = nav.order === 0 ? 1 : 0; // 切换排序
}
} else {
$active = $this.siblings('.active');
$pre = $this; // $pre为除筛选导航的其他导航项,若当前active的为筛选,则把$pre置为当前点击项
if ($active.hasClass('filter')) {
// 若之前active项为筛选,则隐藏筛选面板
filter.hideFilter();
}
$active.removeClass('active');
$this.addClass('active');
}
/* 排序条件更新 */
defaultOpt.type = navType;
Object.assign(defaultOpt, nav);
getGoodsList();
}
});
/**
* 当scroll到1/2$goodsContainer高度后继续请求下一页数据
*/
const scrollHandler = function() {
if ($allGoodsTabPage.hasClass('active') && $(window).scrollTop() > $goodsContainer.height() * 0.6) {
isScrollLoad = true;
getGoodsList();
}
};
/**
* 滚动加载
*/
$(window).scroll(function() {
setTimeout(function() {
let afterScroll = document.body.scrollTop;
if (afterScroll - beforeScroll > 0) {
window.requestAnimationFrame(scrollHandler);
beforeScroll = afterScroll;
} else {
return false;
}
}, 5);
});
module.exports = {
getGoodsList,
getFilter
};
... ... @@ -11,12 +11,11 @@ shopCoupon = {
appVersion: window.queryString.app_version || window.queryString.appVersion,
uid: window.queryString.uid,
shopId: parseInt($('.shop-id').val() || $('.shopId').val(), 10) || null,
brandId: parseInt($('.brand-header').data('id'), 10) || null,
couponTemplate: require('product/shop/coupon.hbs')
},
init: function() {
// 如果都为空,则不请求
if (!this.common.shopId && !this.common.brandId) {
// 如果为空,则不请求
if (!this.common.shopId) {
return true;
}
... ... @@ -27,26 +26,17 @@ shopCoupon = {
},
getShopCouponsList: function() {
let that = this,
_url = location.protocol + '//m.yohobuy.com';
_url = location.protocol + '//m.yohobuy.com/product/index/getShopCouponsList';
if ($('.coupon-group').length <= 0) {
return false;
}
if (that.common.shopId) {
// 店铺领券
_url += '/product/index/getShopCouponsList';
} else {
// 品牌领券
_url += '/product/index/getBrandCouponsList';
}
$.ajax({
method: 'GET',
url: _url,
data: {
shopId: that.common.shopId,
brandId: that.common.brandId,
uid: that.common.uid
},
xhrFields: {
... ...
... ... @@ -112,23 +112,6 @@ C_ID = window._ChannelVary[window.cookie('_Channel')];
tip.show('网络断开连接了~');
}
});
} else if ($('.shopId').val().length > 0) {
$.ajax({
url: '/product/index/baseShopFav',
data: {
shopId: $('.shopId').val()
},
dataType: 'json',
success: function(data) {
if (data.is_favorite === 'Y') {
$('.brand-header .btn-col').addClass('coled');
}
$('.con').html(data.shop_intro);
},
error: function() {
tip.show('网络断开连接了~');
}
});
}
}());
... ...
... ... @@ -594,3 +594,9 @@
border-top: none;
}
}
.reds-shop {
.search-divide {
margin-bottom: 100px;
}
}
... ...
... ... @@ -149,7 +149,7 @@ class DetailProcess {
};
if (value.shop_id) {
shopInfo.url = helpers.urlFormat('/product/index/brand', {
shopInfo.url = helpers.urlFormat('/product/shop', {
shop_id: value.shop_id
});
} else {
... ...
... ... @@ -130,7 +130,7 @@ exports.processProductList = (list, options) => {
if (extraAttr === '_isHotShop' && parseInt(product.data.show_type, 10) === 1) {
product.reShop = true;
product.data.shopUrl = '//m.yohobuy.com/product/index/brand?domain=' + product.data.shop_domain;
product.data.shopUrl = '//m.yohobuy.com/product/shop?domain=' + product.data.shop_domain;
}
pruductList.push(product);
... ...
... ... @@ -94,9 +94,74 @@ const getListSeoData = (gender, sort_name) => {
return seoData;
};
/**
* 获取筛选的参数,不包括方法名
*/
const getSearchParamsWithoutMethod = (params) => {
let finalParams = {};
if (params.yh_channel) {
finalParams.yh_channel = params.yh_channel;
}
if (params.brand_id) {
finalParams.brand = params.brand_id;
}
if (params.shop_id) {
finalParams.shop_id = params.shop_id;
}
if (params.order) {
finalParams.order = getTypeCont(params.type, params.order);
}
if (params.limit) {
finalParams.limit = params.limit;
}
if (params.page) {
finalParams.page = params.page;
}
if (params.gender) {
finalParams.gender = params.gender;
}
if (params.color && params.color !== '0') {
finalParams.color = params.color;
}
if (params.price && params.price !== '0') {
finalParams.price = params.price;
}
if (params.size && params.size !== '0') {
finalParams.size = params.size;
}
if (params.p_d) {
finalParams.p_d = params.p_d;
}
if (params.sort && params.sort !== '0') {
finalParams.sort = params.sort;
}
if (params.tags_filter) {
finalParams.tags_filter = params.tags_filter;
}
if (params.type) {
finalParams.type = params.type;
}
return finalParams;
};
module.exports = {
getGenderByChannel,
getChannelType,
getTypeCont,
getListSeoData
getListSeoData,
getSearchParamsWithoutMethod
};
... ...