Authored by zhangxiaoru

模糊搜索

... ... @@ -145,6 +145,15 @@ const getBrandByChannel = (channel) => {
});
};
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}),
3: helpers.urlFormat('/product/global/list/', {brand: row.global_brand_id})
}[key];
};
const getBrandListByChannel = (channel) => {
return _packageList(channel).then(result => {
let resu = {
... ... @@ -168,16 +177,12 @@ const getBrandListByChannel = (channel) => {
};
allList[key].forEach(row => {
obj.list.push({
name: row.brand_name,
isHot: row.is_hot === 'Y' ? true : false,
isNew: row.is_show_new === 'Y' ? true : false,
url: parseInt(row.type, 10) !== 3 ? helpers.urlFormat('/product/index/brand', {
domain: row.brand_domain,
shopType: row.type
}) : helpers.urlFormat('/product/global/list/', {
brand: row.global_brand_id
})
url: _urlJump(parseInt(row.type, 10), row)
});
});
resu.brandList.push(obj);
... ...
... ... @@ -43,7 +43,6 @@ const shop = {
let title = '';
let uid = req.user.uid || 0;
let shopEnter;
let shopType = req.query.shopType;
if (req.query.shop_id) {
return shop.shop(req, res, next);
... ... @@ -82,11 +81,11 @@ const shop = {
searchParam.uid = uid;
}
if (req.query.from !== 'search' && brandLogo.type === '2' && brandLogo.shopId && shopType !== '1') {
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' || shopType === '1') {
} else if (req.query.from === 'search') {
return Promise.all([
listModel.getBrandShops(brandLogo.brandDomain, req),
searchModel.getSearchData(searchParam)
... ...
... ... @@ -24,7 +24,7 @@ const list = (req, res, next) => {
let title = '';
let isQueryFirstClass = false; // 标识用户搜的是不是一级品类
let isQuerySecondClass = false; // 标识用户搜的是不是二级品类
let domain = null;
// let domain = null;
let uid = req.user.uid || 0;
if (params.shop_id) {
... ... @@ -65,26 +65,30 @@ const list = (req, res, next) => {
params.newquery = result[2].suggestion.termsSuggestion[0].name;
}
if (result[2] && result[2].brandWay) {
params.brandWay = result[2].brandWay;
}
if (params.query) {
domain = result[0];
// domain = result[0];
// 跳转到品牌商品列表页
if (domain !== null && !params.shop_id) {
let urlPro = {
from: 'search',
query: params.query
};
if (req.query.app_type) {
urlPro = _.assign(urlPro, {
app_type: req.query.app_type
});
}
let url = helpers.urlFormat('', urlPro, domain);
return res.redirect(url);
}
// if (domain !== null && !params.shop_id) {
// let urlPro = {
// from: 'search',
// query: params.query
// };
// if (req.query.app_type) {
// urlPro = _.assign(urlPro, {
// app_type: req.query.app_type
// });
// }
// let url = helpers.urlFormat('', urlPro, domain);
// return res.redirect(url);
// }
// 品类名称为空时跳出
if (!result[1]) {
... ...
... ... @@ -981,5 +981,6 @@ module.exports = {
getShopDecorator: _getShopDecorator,
getShopCategoryApi: _getShopCategory,
formShopData: _formShopData,
getBrandShopSeo: _getBrandShopSeo
getBrandShopSeo: _getBrandShopSeo,
processBrandShops: _processBrandShops
};
... ...
... ... @@ -11,7 +11,9 @@ const _ = require('lodash');
const logger = global.yoho.logger;
const api = global.yoho.API;
const cache = require('memory-cache');
const helpers = global.yoho.helpers;
// const listModel = require('./list');
/**
* 封面图
... ... @@ -118,10 +120,12 @@ const _searchGoods = (params) => {
if (params.shop_id && !params.productPool) {
method = 'app.search.li';
} else if (params.brand && !params.productPool) {
method = 'app.search.brand';
}
// else if (params.brand && !params.productPool) {
// method = 'app.search.brand';
// }
if (params.channel) {
params.yh_channel = searchProcess.getChannelType(params.channel);
delete params.channel;
... ... @@ -188,6 +192,41 @@ const _searchGoods = (params) => {
};
/**
* 获取店铺列表
*/
const _processBrandShops = (list) => {
let formatDat = [];
_.forEach(list, item => {
if (item.shop_type === 'yoho_shop') {
formatDat.push({
url: helpers.urlFormat('/product/index/brand/', {
shop_id: item.shop_id
}),
thumb: helpers.image(item.shop_logo, 75, 40),
name: item.shop_name,
shopId: item.shop_id
});
} else if (item.shop_type === 'tbl_brand') {
formatDat.push({
url: helpers.urlFormat('/product/global/list/', {
brand: item.global_brand_id
}),
thumb: helpers.image(item.brand_ico, 75, 40),
name: item.brand_name,
brandId: item.global_brand_id
});
}
});
if (formatDat.length > 2) {
formatDat.moreShop = true;
}
return formatDat;
};
/**
* 获取商品数据
*/
const getSearchData = (params) => {
... ... @@ -197,6 +236,11 @@ const getSearchData = (params) => {
let newList = {};
let suggestion = {};
if (result.data.shopList && result.data.shopList.length !== 0) {
newList.brandWay = _processBrandShops(result.data.shopList);
}
newList.list = productProcess.processProductList(result.data.product_list || [], {
isApp: params.isApp || (params.appVersion && params.appVersion !== 'false'),
gender: _coverChannel[params.coverChannel]
... ...
... ... @@ -13,18 +13,29 @@
<ul class="search-associate"></ul>
{{/ search}}
{{# brandWay}}
{{#if brandWay}}
<div class="brand-way">
<a href={{url}}>
<img class="brand-thumb" src={{thumb}}>
<span class="brand-name">{{name}}</span>
<span class="entry">
进入店铺
<i class="iconfont">&#xe614;</i>
</span>
</a>
<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>
{{#if brandId}}<span class="global"></span>{{/if}}
<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>
{{/ brandWay}}
{{/if}}
{{# shopBanner}}
<div class="brand-header">
... ...
... ... @@ -10,19 +10,19 @@ const isProduction = process.env.NODE_ENV === 'production';
const isTest = process.env.NODE_ENV === 'test';
const domains = {
// liveApi: 'http://testapi.live.yohops.com:9999/',
// singleApi: 'http://api-test3.yohops.com:9999/',
liveApi: 'http://testapi.live.yohops.com:9999/',
singleApi: 'http://api-test3.yohops.com:9999/',
// api: 'http://api-test3.yohops.com:9999/',
// service: 'http://service-test3.yohops.com:9999/',
api: 'http://api-test3.yohops.com:9999/',
service: 'http://service-test3.yohops.com:9999/',
// liveApi: 'http://api.live.yoho.cn/',
// singleApi: 'http://single.yoho.cn/',
api: 'http://dev-api.yohops.com:9999/',
service: 'http://dev-service.yohops.com:9999/',
liveApi: 'http://testapi.live.yohops.com:9999/',
singleApi: 'http://api-test1.yohops.com:9999/',
// api: 'http://dev-api.yohops.com:9999/',
// service: 'http://dev-service.yohops.com:9999/',
// liveApi: 'http://testapi.live.yohops.com:9999/',
// singleApi: 'http://api-test1.yohops.com:9999/',
// api: 'http://api.yoho.cn/',
// service: 'http://service.yoho.cn/',
... ... @@ -36,7 +36,7 @@ const domains = {
module.exports = {
app: 'h5',
appVersion: '5.5.2', // 调用api的版本
appVersion: '5.6.0', // 调用api的版本
port: 6001,
siteUrl: '//m.yohobuy.com',
assetUrl: '//127.0.0.1:5001',
... ...
... ... @@ -1151,6 +1151,31 @@ $('#goods-container').on('click', '.good-info', function() {
}
});
$('.more-shop').on('click', function() {
if ($(this).hasClass('down')) {
$('.brand-enter').css('max-height', '100%');
$('.more-shop').removeClass('down').find('span').html('&#xe615;');
} else {
$('.brand-enter').removeAttr('style');
$('.more-shop').addClass('down').find('span').html('&#xe616;');
}
});
// 进入店铺埋点
$('.brand-way a').on('click', function() {
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo({
op: 'YB_BRAND_SHOP_C',
param: JSON.stringify({
BRAND_ID: $('.brand-enter a').data('brandid'),
SHOP_ID: $('.brand-enter a').data('shopid'),
POS_ID: 101
})
}, true);
}
});
let fuckNum = $('.good-info').length;
fuckNum < 12 && $('.search-divide').remove();
... ...
... ... @@ -72,7 +72,7 @@
a {
display: block;
height: 80px;
height: 84px;
line-height: 80px;
padding: 0 20px;
border-top: 1px solid #e6e6e6;
... ... @@ -94,7 +94,7 @@
}
.brand-name {
width: 40%;
max-width: 35%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
... ... @@ -105,12 +105,24 @@
.brand-thumb {
float: left;
width: 150px;
height: 80px;
width: 110px;
height: 84px;
margin: 0;
display: inline-block;
}
.global {
background-image: resolve("product/global.png");
display: inline-block;
width: 92px;
height: 34px;
background-size: 100%;
background-repeat: no-repeat;
position: relative;
top: -30%;
margin-left: 10px;
}
.entry {
color: #999;
font-size: 28px;
... ...