Authored by 陈峰

merge feature/band

/**
* 品牌页
* <jing.li@yoho.cn>
* 2016/09/19
*/
'use strict';
const headerModel = require('../../../doraemon/models/header'); // 头部model
const indexModel = require('../models/brand');
/**
* 品牌一览
*
* @param string gender 老版本中使用的参数, 做兼容判断
* @param int channel 1表示男生频道, 2表示女生频道, 3表示潮童频道, 4表示创意生活频道
*/
let index = (req, res, next) => {
let headerData = headerModel.setNav({
navTitle: '品牌一览'
});
let responseData = {
pageHeader: headerData,
module: 'channel',
page: 'brand',
title: '品牌一览 | Yoho!Buy有货 | 潮流购物逛不停',
//pageFooter: true
};
let param = {
channel: req.query.channel || '1',
gender: req.query.gender || '1,3'
};
indexModel.getBrandByChannel(param.channel).then(result => {
res.render('brand/index', Object.assign(responseData, result));
}).catch(next);
};
/**
* 品牌一览搜索页
*
* @param string gender 老版本中使用的参数, 做兼容判断
* @param int channel 1表示男生频道, 2表示女生频道, 3表示潮童频道, 4表示创意生活频道
*/
let search = (req, res, next) => {
let headerData = headerModel.setNav({
navTitle: '品牌一览'
});
let responseData = {
pageHeader: headerData,
module: 'channel',
page: 'brand',
title: '品牌一览 | Yoho!Buy有货 | 潮流购物逛不停',
pageFooter: true
};
let param = {
uid: req.user.uid,
channel: req.query.channel || '1'
};
indexModel.branchSearch(param).then(result => {
res.render('brand/search', Object.assign(responseData, result));
}).catch(next);
};
/**
* 添加品牌搜索记录
*/
let addBrandSearch = (req, res, next) => {
let uid = req.user.uid;
let brandName = req.query.brandName;
let timestamp = Date.parse(new Date());
timestamp = timestamp / 1000;
let records = timestamp + '_' + brandName;
let param = {uid, records};
indexModel.addSearchHistory(param).then((result) => {
res.json(result);
}).catch(next);
};
/**
* 删除品牌搜索记录
*/
let delBrandHistory = (req, res, next) => {
let param = {
uid: req.user.uid,
};
indexModel.delBrandSearchHistory(param).then((result) => {
res.json(result);
}).catch(next);
};
/**
* [品牌搜索异步数据]
*/
let searchAsync = (req, res, next) => {
if (!req.xhr) {
return next();
}
let uid = req.user.uid;
if (!uid) {
return res.json({code: 200, data: {}})
}
return indexModel.branchSearchHistoryAsync(uid).then((result) => {
return res.json({code: 200, data: { history: result }})
})
}
module.exports = {
index,
search,
delBrandHistory,
addBrandSearch,
searchAsync
};
... ...
/**
* 品牌页
* @param params
* @returns {function()}
*/
'use strict';
var api = global.yoho.API;
const service = global.yoho.ServiceAPI;
const helpers = global.yoho.helpers;
// const utils = '../../../utils';
// const floorProcess = require(`${utils}/floor-process`);
/* 男生频道取品牌广告及热门品牌数据的位置码 */
let CODE_TOPPOS_BOYS = 'ce6ac059493ec26241a8cbe0bfa1b17a';
/* 女生频道取品牌广告及热门品牌数据的位置码 */
let CODE_TOPPOS_GIRLS = 'dac99cdedc1f948e84c145aca561f7d2';
/* 潮童频道取品牌广告及热门品牌数据的位置码 */
let CODE_TOPPOS_KIDS = '713784f93f52bb1a7b93916b2bb15510';
/* 创意生活频道取品牌广告及热门品牌数据的位置码 */
let CODE_TOPPOS_LIFESTYLE = 'f1aa914fd23cbcda71a87de6f5416c75';
/**
* 获取频道接口
*/
const _packageAd = (params) => {
return service.get('/operations/api/v5/resource/get', {
content_code: params.contentCode,
gender: 1,
limit: 1000,
page: 1
}).then(result => {
return result;
});
};
const _packageList = (params) => {
return api.get('', {
method: 'app.brand.newBrandList',
yh_channel: params.channel
}, { code: 200 }).then(result => {
return result;
});
};
const getBrandByChannel = (channel) => {
let params = {};
/* 根据频道调用接口 */
switch (channel) {
case '1': // 男生
params = {
contentCode: CODE_TOPPOS_BOYS,
channel: 1
};
break;
case '2': // 女生
params = {
contentCode: CODE_TOPPOS_GIRLS,
channel: 2
};
break;
case '3': // 潮童
params = {
contentCode: CODE_TOPPOS_KIDS,
channel: 3
};
break;
case '4': // 创意生活
params = {
contentCode: CODE_TOPPOS_LIFESTYLE,
channel: 4
};
break;
default:
}
return api.all([
_packageAd(params),
_packageList(params)
]).then(result => {
let resu = {
channel: {
channels: [{
name: 'Boy'
}, {
name: 'Girl'
}, {
name: 'Kid'
}, {
name: 'Lifestyle'
}],
topData: {
bannerTop: {},
hotBrandsScroll: {}
},
searchUrl: helpers.urlFormat('/brands/search', null),
brandPage: true,
// pageFooter: true,
showDownloadApp: true,
brandType: '全部品牌',
secondBrandType: '新入驻品牌',
thirdBrandType: '热门品牌',
brandList: [],
newBrandWall: [],
recommandBrandWall: []
}
};
resu.channel.channels[channel - 1].active = true;
if (result && result[0] && result[0].data) {
if (result[0].data[0] && result[0].data[0].data) {
// 轮播图资源位
let adList = result[0].data[0].data;
let build = [];
adList.forEach(ad => {
build.push({
img: helpers.image(ad.src, 640, 240),
url: ad.url
});
});
resu.channel.topData.bannerTop.list = build;
}
if (result[0].data[1] && result[0].data[1].data) {
// 推荐品牌资源位
let brandList = result[0].data[1].data.list;
let brand = [];
brandList.forEach(ad => {
brand.push({
img: helpers.image(ad.src, 140, 140),
url: ad.url,
textCn: ad.title
});
});
resu.channel.topData.hotBrandsScroll.name = result[0].data[1].data.title.title;
resu.channel.topData.hotBrandsScroll.list = brand;
}
}
/* 按字母'A-Z'分组的品牌列表 */
if (result && result[1] && result[1].data) {
let allList = result[1].data.all_list;
for (let key in allList) {
let obj = {};
obj = Object.assign(obj, {title: key});
let list = [];
allList[key].forEach(row => {
list.push({
name: row.brand_name,
isHot: row.is_hot === 'Y' ? true : false,
isNew: row.is_show_new === 'Y' ? true : false,
url: helpers.urlFormat('', null, row.brand_domain)
});
});
obj = Object.assign(obj, {list});
resu.channel.brandList.push(obj);
}
}
// 新入驻品牌
if (result && result[1] && result[1].data) {
let newList = result[1].data.new_list;
for (let key in newList) {
let obj = {};
let list = [];
list.push({
brandName: newList[key].brand_name,
url: helpers.urlFormat('', null, newList[key].brand_domain),
img: helpers.image(newList[key].brand_ico, 186, 115),
});
obj = Object.assign(obj, {list});
resu.channel.newBrandWall.push(obj);
}
}
// 推荐品牌
if (result && result[1] && result[1].data) {
let hotList = result[1].data.hot_list;
for (let key in hotList) {
let obj = {};
let list = [];
list.push({
brandName: hotList[key].brand_name,
url: helpers.urlFormat('', null, hotList[key].brand_domain),
img: helpers.image(hotList[key].brand_ico, 186, 115),
});
obj = Object.assign(obj, {list});
resu.channel.recommandBrandWall.push(obj);
}
}
return resu;
});
};
/**
* 获取搜索的品牌列表
*
* @param int $channel 1表示男生频道, 2表示女生频道, 3表示潮童频道, 4表示创意生活频道
* @return array
*/
const getBrandForSearch = (channel) => {
return api.get('', {
method: 'app.brand.brandlist',
yh_channel: channel || 1
}, { code: 200 }).then(result => {
return result;
});
};
/**
* 品牌搜索历史
* @param int $uid
* @author sefon 2016-5-17 12:12:28
* @return array
*/
const branchSearchHistory = (params) => {
return api.get('', {
method: 'app.search.hotBrandRecords',
uid: params.uid,
records: params.records || ''
}, { code: 200 }).then(result => {
return result;
});
};
const addSearchHistory = (param) => {
return api.get('', {
method: 'app.search.hotBrandRecords',
uid: param.uid,
records: param.records
}, { code: 200 });
};
/**
* 热搜品牌
* @author sefon 2016-5-17 12:20:26
* @return array
*/
const branchSearchHot = () => {
return api.get('', {
method: 'app.search.hotBrands'
}, { code: 200 }).then(result => {
return result;
});
};
// /**
// * 获取搜索的品牌列表
// *
// * @param int $channel 1表示男生频道, 2表示女生频道, 3表示潮童频道, 4表示创意生活频道
// * @return array
// */
// const branchSearch = (params) => {
// return api.all([
// getBrandForSearch(params.channel),
// branchSearchHistory(params),
// branchSearchHot(),
// ]).then(result => {
// let resu = {
// brandPage: true,
// showDownloadApp: true,
// pageFooter: true,
// hot: [],
// history: [],
// brandList: []
// };
// if (result && result[0] && result[0].data) {
// let brandList = result[0].data.brands;
// let obj = {};
// for (let key in brandList) {
// let build = [];
// brandList[key].forEach(row => {
// build.push({
// name: row.brand_name,
// isHot: row.is_hot === 'Y' ? true : false,
// isNew: row.is_show_new === 'Y' ? true : false,
// url: helpers.urlFormat('', null, row.brand_domain),
// brandId: row.id,
// brandDomain: row.brand_domain,
// searchName: row.brand_name_en + row.brand_name_cn
// });
// obj[key] = build;
// });
// }
// resu.brandList = JSON.stringify(obj);
// }
// if (result && result[2] && result[2].data) {
// let hotList = result[2].data;
// for (let key in hotList) {
// let obj = {};
// obj = Object.assign(obj, {name: hotList[key].brandName});
// resu.hot.push(obj);
// }
// }
// if (result && result[1] && result[1].data) {
// let hisList = result[1].data;
// let obj = [];
// let build = {
// list: []
// };
// for (let key in hisList) {
// obj.push({
// name: hisList[key].searchTerms,
// searchTime: hisList[key].searchTime
// });
// }
// build.list = obj;
// resu.history = build;
// }
// return resu;
// });
// };
/**
* 获取搜索的品牌列表 pagecache重构
*
* @param int $channel 1表示男生频道, 2表示女生频道, 3表示潮童频道, 4表示创意生活频道
* @return array
*/
const branchSearch = (params) => {
return api.all([
getBrandForSearch(params.channel),
// branchSearchHistory(params),
branchSearchHot(),
]).then(result => {
let resu = {
brandPage: true,
showDownloadApp: true,
pageFooter: true,
hot: [],
history: [],
brandList: []
};
if (result && result[0] && result[0].data) {
let brandList = result[0].data.brands;
let obj = {};
for (let key in brandList) {
let build = [];
brandList[key].forEach(row => {
build.push({
name: row.brand_name,
isHot: row.is_hot === 'Y' ? true : false,
isNew: row.is_show_new === 'Y' ? true : false,
url: helpers.urlFormat('', null, row.brand_domain),
brandId: row.id,
brandDomain: row.brand_domain,
searchName: row.brand_name_en + row.brand_name_cn
});
obj[key] = build;
});
}
resu.brandList = JSON.stringify(obj);
}
if (result && result[1] && result[1].data) {
let hotList = result[1].data;
for (let key in hotList) {
let obj = {};
obj = Object.assign(obj, {name: hotList[key].brandName});
resu.hot.push(obj);
}
}
// if (result && result[1] && result[1].data) {
// let hisList = result[1].data;
// let obj = [];
// let build = {
// list: []
// };
// for (let key in hisList) {
// obj.push({
// name: hisList[key].searchTerms,
// searchTime: hisList[key].searchTime
// });
// }
// build.list = obj;
// resu.history = build;
// }
return resu;
});
};
const delBrandSearchHistory = (param) => {
return api.get('', {
method: 'app.search.clearHotBrandRecords',
uid: param.uid
}, { code: 200 }).then(result => {
return result;
});
};
/**
* [异步获取用户最近搜索词]
*/
const branchSearchHistoryAsync = (uid) => {
return branchSearchHistory({uid}).then((result) => {
let hisList = result.data;
let obj = [];
let build = {
list: []
};
for (let key in hisList) {
obj.push({
name: hisList[key].searchTerms,
searchTime: hisList[key].searchTime
});
}
build.list = obj;
return build;
});
}
module.exports = {
getBrandByChannel,
branchSearch,
delBrandSearchHistory,
addSearchHistory,
branchSearchHistoryAsync
};
... ...
... ... @@ -10,6 +10,7 @@ const express = require('express');
const cRoot = './controllers';
const channel = require(cRoot);
const cate = require(cRoot + '/cate');
const brandController = require(`${cRoot}/brand`);
const router = express.Router(); // eslint-disable-line
... ... @@ -22,5 +23,10 @@ router.get('/lifestyle', channel.switchChannel, channel.lifestyle);
router.get('/channel/bottomBanner', channel.bottomBanner);
router.get('/cate', cate.index);
router.get('/brands', brandController.index); // 品牌首页
router.get('/brands/search', brandController.search); // 品牌搜索页
router.post('/brands/searchAsync', brandController.searchAsync); // 品牌搜索异步数据
router.post('/brands/addBrandSearch', brandController.addBrandSearch); // 添加品牌搜索记录
router.get('/brands/delBrandHistory', brandController.delBrandHistory); // 删除品牌搜索记录
module.exports = router;
... ...
<div class="brand-page yoho-page">
{{# channel}}
<div class="genderNav">
<ul>
{{# channels}}
<li {{#if active}}class="active"{{/if}} data-id="{{@index}}">
<span>{{name}}</span>
<span class="split-border"></span>
</li>
{{/channels}}
</ul>
</div>
<div class="newbrand-search re-pos-search">
<div class="search-box clearfix">
<a href="{{searchUrl}}" >
<input type="text" class="search-input" placeholder="查找品牌" readonly="true">
<i class="search-icon iconfont">&#xe60f;</i>
</a>
</div>
</div>
<div class="hide-when-loading">
{{# topData}}
{{! 头部banner}}
{{# bannerTop}}
{{> brand/banner_top}}
{{/ bannerTop}}
{{! 热门品牌可滑动}}
{{# hotBrandsScroll}}
{{> brand/hot_brands_swipe}}
{{/ hotBrandsScroll}}
{{/ topData}}
<div class="brandNav">
<ul>
<li class="allbrand active" data-id="0">
<span>{{brandType}}</span>
<span class="split-border"></span>
</li>
<li class="newbrand" data-id="1">
<span>{{secondBrandType}}</span>
<span class="split-border"></span>
</li>
<li class="recommandbrand" data-id="2">
<span>{{thirdBrandType}}</span>
<span class="split-border"></span>
</li>
</ul>
</div>
<div class="second-level-brand">
{{# brandList}}
<div class="brand-list bar-{{@index}}">
<div class="title-bar">
<h2 style="position: static;">{{title}}</h2>
</div>
{{# list}}
<p>
<a href="{{url}}">{{name}}
{{# isHot}}
<i class="icon-hot">HOT</i>
{{/ isHot}}
{{# isNew}}
<i class="icon-new">NEW</i>
{{/ isNew}}
</a>
</p>
{{/ list}}
</div>
{{/ brandList}}
{{# newBrandWall}}
<div class="new-brand-wall branding-wall hide">
{{# list}}
<div class="brand-wall-box">
<a href="{{url}}">
<img class="lazy" data-original="{{img}}"></img>
<div class="brand-name">{{brandName}}</div>
</a>
</div>
{{/ list}}
</div>
{{/ newBrandWall}}
{{# recommandBrandWall}}
<div class="recommand-brand-wall branding-wall hide">
{{# list}}
<div class="brand-wall-box">
<a href="{{url}}">
<img class="lazy" data-original="{{img}}"></img>
<div class="brand-name">{{brandName}}</div>
</a>
</div>
{{/ list}}
</div>
{{/ recommandBrandWall}}
</div>
</div>
{{/channel}}
</div>
... ...
<div class="brand-page brand-search-page yoho-page">
<div class="newbrand-search">
<form class="search-box clearfix">
<input type="text" class="search-input" id="keyword" placeholder="查找品牌">
<i class="search-icon iconfont">&#xe60f;</i>
<div class="search-action">
<span class="iconfont clear-text">&#xe623;</span>
<a class="cancel-btn" href="javascript: history.go(-1);">取消</a>
</div>
</form>
</div>
<div class="search-result">
</div>
</div>
<div class="search-brand-page">
<div class="search-items">
<div class="net-history hide">
<div class="history-search net-search hide">
<ul class="history clearfix net">
<li>
<a href="{{url}}" brandName="{{name}}" collectTime="{{searchTime}}">{{name}}</a>
</li>
</ul>
</div>
</div>
<div class="history-search local-search">
<h3><span class="iconfont left-icon">&#xe64a;</span>最近搜索
<button id="clear-history" class="clear-icon iconfont">&#xe64c;</button>
</h3>
<ul class="history clearfix local-history">
</ul>
</div>
{{#if hot}}
<div class="hot-search">
<h3><span class="iconfont left-icon">&#xe64b;</span>热门搜索</h3>
<ul class="hot clearfix">
{{# hot}}
<li>
<a href="{{url}}" brandName="{{name}}">{{name}}</a>
</li>
{{/ hot}}
</ul>
</div>
{{/if}}
</div>
</div>
<script id="brands-data" type="text/tmpl">
{{{brandList}}}
</script>
... ...
<div class="banner-top">
<div class="banner-swiper swiper-container">
<ul class="swiper-wrapper">
{{#each list}}
{{#if @first}}
<li class="swiper-slide buriedpoint" data-bp-id="shop_bannerarea_{{url}}_0">
<a href="{{url}}">
<img src="{{img}}">
</a>
</li>
{{^}}
<li class="swiper-slide buriedpoint" data-bp-id="shop_bannerarea_two_0">
<a href="{{url}}">
<img class="swiper-lazy" data-src="{{img}}">
</a>
<div class="swiper-lazy-preloader"></div>
</li>
{{/if}}
{{/each}}
</ul>
</div>
<div class="swiper-pagination">
<div class="pagination-inner">
</div>
</div>
</div>
\ No newline at end of file
... ...
{{# name}}
<div class="floor-header">
<h2>{{.}}</h2>
</div>
{{/ name}}
\ No newline at end of file
... ...
<div class="hot-brands">
{{> brand/floor_header}}
<div class="brands-swiper">
<ul class="brands-list swiper-wrapper clearfix">
{{# list}}
<li class="swiper-slide">
<a href="{{url}}">
<img src="{{img}}" alt="">
<span class="brands-title">{{textCn}}</span>
</a>
</li>
{{/ list}}
</ul>
</div>
</div>
... ...
... ... @@ -20,11 +20,6 @@ module.exports = {
service: 'http://service.yoho.cn/',
liveApi: 'http://api.live.yoho.cn/',
singleApi: 'http://single.yoho.cn/'
// api: 'http://api-test1.yohops.com:9999/',
// service: 'http://service-test1.yohops.com:9999/',
// liveApi: 'http://testapi.live.yohops.com:9999/',
// singleApi: 'http://api-test1.yohops.com:9999/'
},
subDomains: {
host: '.m.yohobuy.com',
... ...
var $ = require('yoho-jquery'),
dbClass = 'data-bind';
module.exports = function(callback) {
$.ajax({
type: 'POST',
url: '/brands/searchAsync',
success: function(data) {
render(data.data);
callback && callback(data);
}
});
};
function render(data) {
console.log(data)
if (data.history && data.history.list && data.history.list.length) {
var hisEl = $('.history>li').remove();
$.each(data.history.list, function(i, his) {
var itemEl = hisEl.clone();
itemEl.find('a')
.attr('href', his.url)
.attr('brandName', his.name)
.attr('collectTime', his.searchTime)
.text(his.name);
$('.history').append(itemEl);
})
$('.net-history').removeClass(dbClass);
} else {
$('.net-history').remove();
}
}
\ No newline at end of file
... ...
/**
* 品牌一览
* @author: liangzhifeng<zhifeng.liang@yoho.cn>
* @date: 2015/10/23
*/
var $ = require('yoho-jquery'),
Hammer = require('yoho-hammer'),
Swiper = require('yoho-swiper'),
loading = require('../plugin/loading'),
lazyLoad = require('yoho-jquery-lazyload');
var ranToken = ' ??++ ';
var ranToken2 = ' ???--- ';
var swiper,
$fixTitleBar,
$brandList = $('.brand-list'),
$icon = $('.search-icon'),
$genderItem = $('.genderNav li'),
$brandItem = $('.brandNav li'),
$newBrandWall = $('.new-brand-wall'),
$recommandBrandWall = $('.recommand-brand-wall'),
$searchAction = $('.search-action'),
$homebuttom = $('.homebuttom'),
$genderNav = $('.genderNav'),
$newSearch = $('.newbrand-search'),
$netHistory = $('.net-history'),
$navBtn = $('.nav-home'),
hotBrandsSwiper;
var searchH = $('.newbrand-search').outerHeight(),
headerH = $('.yoho-header').outerHeight(),
brandSwipe = parseInt(searchH) + parseInt(headerH) - 1,
minBrandListTop;
var brandsData,
$keyword = $('#keyword'),
clearTextHammer;
var $history = $('.local-history');
var $searchPage = $('.search-brand-page');
var $historySearch = $('.history-search');
var $hotSearch = $('.hot-search');
var $clearHistory = $('#clear-history');
var chHammer;
require('../common');
require('../footer');
function changeBackground() {
var $brandList = $('.brand-list').find('p');
$brandList.on('touchstart', function() {
$brandList.css('background', '#fff');
$(this).css('background', '#eee');
}).on('touchend touchcancel', function() {
$(this).css('background', '#fff');
});
}
changeBackground();
/**
* 增加单条记录
*/
function addHistory(brandName) {
$.ajax({
type: 'POST',
url: '/brands/addBrandSearch',
data: 'brandName=' + encodeURIComponent(brandName),
success: function(data) {
},
error: function() {
}
});
}
// 比较大小
function sequence(a, b) {
if (a.time > b.time) {
return 1;
} else if (a.time < b.time) {
return -1;
} else {
return 0;
}
}
function searchInput() {
if ($keyword.val().length) {
$icon.css('color', '#444');
// $(this).closest('.search-box').css('width', '11.25rem');
$searchAction.show().find('.clear-text').show();
} else {
$icon.css('color', '#b2b2b2');
// $(this).closest('.search-box').css('width', '12.5rem');
$searchAction.find('.clear-text').hide();
}
searchResult();
}
function isLocalStorageSupported() {
var testKey = 'test',
storage = Window.prototype.localStorage;
try {
storage.setItem(testKey, 'testValue');
storage.removeItem(testKey);
return true;
} catch (error) {
return false;
}
}
// 绑定提交前的存local操作
function bindWriteLocal($brandList, list) {
$brandList.on('click', 'p , li', function(e) {
var brandName, brandId, brandDomain, url;
var a = $(this).find('a');
var myDate = new Date();
var query = a.attr('brandName') + ranToken2 + myDate.getTime(),
historys;
brandName = a.attr('brandName');
brandId = a.attr('brandId');
brandDomain = a.attr('brandDomain');
url = a.attr('href');
e.preventDefault();
if ($netHistory.length > 0) {
addHistory(brandName);
if (list) {
location.href = url;
return;
}
$keyword.val(brandName);
searchInput();
return;
}
if (localStorage) {
if (isLocalStorageSupported()) {
historys = localStorage.getItem('historys-brand');
}
historys = historys ? historys : '';
if (historys.indexOf(ranToken + query + ranToken) > -1) {
$keyword.val(brandName);
searchInput();
return;
}
if (historys === '') {
query = ranToken + query;
}
historys += query + ranToken;
if (isLocalStorageSupported()) {
localStorage.setItem('historys-brand', historys);
}
}
if (list) {
location.href = url;
return;
}
$keyword.val(brandName);
searchInput();
});
}
function searchResult() {
var keyword = ($keyword.val() + '').toLowerCase();
var result = {},
i = 0,
html = '';
if (keyword !== '') {
// 遍历首字母搜索
$.each(brandsData, function(k, v) {
if ($.isArray(v)) {
// 遍历品牌,进行匹配
$.each(v, function(i, brand) {
if (brand.searchName.toLowerCase().indexOf(keyword) > -1) {
result[k] = result[k] || [];
result[k].push(brand);
}
});
}
});
// 根据搜索结果生成 HTML
$.each(result, function(k, v) {
var brandHtml = ['<div class="brand-list bar-', i, '">'];
i++;
brandHtml.push('<div class="title-bar"><h2>');
brandHtml.push(k);
brandHtml.push('</h2></div>');
$.each(v, function(i, brand) {
brandHtml.push('<p><a href="' + brand.url + '" brandName = "' + brand.name +
'" brandId = "' + brand.brandId + '" brandDomain = "' + brand.brandDomain + '">' + brand.name);
if (brand.isNew) {
brandHtml.push('<i class="icon-new">NEW</i>');
}
if (brand.isHot) {
brandHtml.push('<i class="icon-hot">HOT</i>');
}
brandHtml.push('</a></p>');
});
brandHtml.push('</div>');
html += brandHtml.join('');
});
}
// 没填入关键词时显示最热搜索
if (keyword.length > 0) {
$('.search-brand-page').addClass('hide');
} else {
$('.search-brand-page').removeClass('hide');
}
// 插入 dom,绑定事件
$('.search-result').html(html);
changeBackground();
bindWriteLocal($('.brand-list'), true);
}
loading.showLoadingMask();
lazyLoad($('img.lazy'));
$('.yoho-header').css({
'z-index': 2,
position: 'fixed',
top: 0
});
$homebuttom.css('top', '47px');
$homebuttom.css('position', 'fixed');
$navBtn.on('touchstart', function() {
if ($homebuttom.hasClass('hide')) {
$genderNav.css('top', '47px');
$newSearch.css('margin-top', '0px');
$searchPage.css('margin-top', '0px');
$('.banner-top').css('margin-top', '0px');
} else {
$genderNav.css('top', '97px');
$newSearch.css('margin-top', '47px');
$searchPage.css('margin-top', '47px');
$('.banner-top').css('margin-top', '47px');
}
});
(function() {
if ($('.banner-top').length > 0) {
$('.hot-brands').css('padding-top', '0');
}
$('.hide-when-loading').show();
loading.hideLoadingMask();
// banner滑动
swiper = new Swiper('.swiper-container', {
lazyLoading: true,
loop: true,
autoplay: 3000,
pagination: '.swiper-pagination .pagination-inner'
});
// 热门品牌滑动
hotBrandsSwiper = new Swiper('.brands-swiper', {
grabCursor: true,
slidesPerView: 'auto',
wrapperClass: 'brands-list',
slideElement: 'li'
});
})();
$fixTitleBar = $('<div class="title-bar fixed-title-bar"><h2></h2></div>');
$fixTitleBar.css({
position: 'fixed',
top: brandSwipe
}).hide();
minBrandListTop = brandSwipe + $('.hot-brands').outerHeight() + $('.banner-top').outerHeight();
$brandList.last().append($fixTitleBar);
function scrollHandler() {
var scrTop = $(window).scrollTop();
if ($brandList.eq(0).offset().top < minBrandListTop) {
$fixTitleBar.hide();
}
$brandList.each(function() {
var offTop = $(this).offset().top - brandSwipe;
if (scrTop >= offTop) {
$fixTitleBar.css({
display: 'block'
}).find('h2').html($(this).find('.title-bar').text());
}
});
}
if ($('.brand-index-page').length > 0) {
/**
* srcoll to load more
*/
$(window).scroll(function() {
window.requestAnimationFrame(scrollHandler);
});
}
if ($('.history-search').length > 0) {
bindWriteLocal($('.history-search'), false);
}
if ($('.hot-search').length > 0) {
bindWriteLocal($('.hot-search'), false);
}
if ($('.brand-search-page').length > 0) {
brandsData = $.parseJSON($('#brands-data').html());
$keyword.on('input', function() {
searchInput();
});
// 2016.1.13 产品(高扬)要求进入页面默认显示取消按钮
$icon.css('color', '#444');
$keyword.closest('.search-box').css('width', '13rem');
$searchAction.show().find('.clear-text').hide();
clearTextHammer = new Hammer($('.clear-text')[0]);
clearTextHammer.on('tap', function(e) {
$('.search-result').html('');
$('#keyword').val('').trigger('input');
e.preventDefault();
e.srcEvent.stopPropagation();
});
$('form.search-box').on('submit', function() {
return false;
});
}
if ($genderItem.length > 0) {
$genderItem.on('touchstart', function() {
var index = $(this).data('id') + 1;
$('.genderNav ul .active').removeClass('active');
$(this).addClass('active');
$('.hide-when-loading').hide();
loading.showLoadingMask();
function reload() {
window.location.search = 'channel=' + index;
}
setTimeout(reload.bind(this), 100);
});
}
if ($brandItem.length > 0) {
$brandItem.on('click', function() {
var index = $(this).data('id');
$('.brandNav ul .active').removeClass('active');
$(this).addClass('active');
if (index === 0) {
$recommandBrandWall.not('.hide').addClass('hide');
$newBrandWall.not('.hide').addClass('hide');
$brandList.removeClass('hide');
} else if (index === 1) {
$newBrandWall.removeClass('hide');
$brandList.not('.hide').addClass('hide');
$recommandBrandWall.not('.hide').addClass('hide');
} else {
$recommandBrandWall.removeClass('hide');
$brandList.not('.hide').addClass('hide');
$newBrandWall.not('.hide').addClass('hide');
}
});
}
/**
* 清除记录
*/
function removeHistory() {
$.ajax({
type: 'GET',
url: '/brands/delBrandHistory',
data: '',
success: function(data) {
},
error: function() {
}
});
}
// 初始化历史搜索的内容
require('./brand-render')(function() {
$netHistory = $('.net-history')
if ($('.brand-search-page').length > 0) {
chHammer = new Hammer($clearHistory[0]);
chHammer.on('tap', function() {
if (isLocalStorageSupported()) {
localStorage.removeItem('historys-brand');
}
$history.html('');
$historySearch.hide();
$clearHistory.hide();
if ($('.net-search').length > 0) {
removeHistory();
}
window.rePosFooter();
});
// 搜索页面
(function() {
var html = '',
history,
historys, i,
localHistory,
brand, data,
time, netArr, dict, dictc, localArr,
combinArr, key, date, temp;
localArr = [];
combinArr = [];
netArr = [];
$netHistory.find('li').each(function() {
brand = $(this).find('a').attr('brandName');
time = $(this).find('a').attr('collectTime');
dict = {
brand: brand,
time: time
}, dictc, dict;
netArr.push(dict);
});
if (localStorage) {
if (isLocalStorageSupported()) {
historys = localStorage.getItem('historys-brand');
}
if (historys && historys.length > 0) {
historys = historys.split(ranToken);
for (i = historys.length; i > 0; i--) {
history = historys[i - 1];
if (history === '') {
continue;
}
localHistory = history.split(ranToken2);
brand = localHistory[0];
time = localHistory[1];
dict = {
brand: brand,
time: time
};
localArr.push(dict);
}
}
}
if (localArr.length === 0 && netArr.length === 0) {
$historySearch.addClass('hide');
return;
}
date = {};
temp = {};
if (localArr.length > 0) {
for (dictc in localArr) {
if (localArr.hasOwnProperty(dictc)) {
temp = localArr[dictc];
if (!date[temp.brand] || date[temp.brand] < temp.time) {
date[temp.brand] = temp.time;
}
}
}
}
if (netArr.length > 0) {
for (dict in netArr) {
if (netArr.hasOwnProperty(dict)) {
temp = netArr[dict];
if (!date[temp.brand] || date[temp.brand] < temp.time) {
date[temp.brand] = temp.time;
}
}
}
}
data = {};
for (key in date) {
if (date.hasOwnProperty(key)) {
data = {
brand: key,
time: date[key]
};
combinArr.push(data);
}
}
combinArr.sort(sequence);
if (combinArr.length > 0) {
for (i = combinArr.length - 1; i >= ((combinArr.length > 10) ? (combinArr.length - 10) : 0); i--) {
brand = combinArr[i].brand;
time = combinArr[i].time;
html += '<li><a brandName = "' + brand +
'">' + brand + '</li>';
$history.removeClass('hide');
$history.html(html);
$clearHistory.removeClass('hide');
$hotSearch.removeClass('hide');
window.rePosFooter();
}
} else {
$history.addClass('hide');
}
}());
}
})
... ...
/**
* 底部JS
* @author: liangzhifeng<zhifeng.liang@yoho.cn>
* @date: 2015/10/26
*/
var $ = require('yoho-jquery'),
Hammer = require('yoho-hammer');
var floatLayerBtnHammer;
require('./common');
/**
* 获取url参数
*/
function getQueryString(name) {
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
var r = window.location.search.substr(1).match(reg);
if (r != null) {
return window.unescape(r[2]);
}
return null;
}
function downLoadApp() {
var appUrl = 'http://www.yohoshow.com/about/index/yohobuyqr/';
var clickedAt = new Date();
setTimeout(function() {
var mkt = getQueryString('mkt_code');
if ((new Date()) - clickedAt < 2000) {
if (mkt) {
appUrl += '?union_type=' + mkt;
}
window.location = appUrl;
}
}, 500);
}
$('#float-layer-close').on('touchend', function(e) {
$('#float-layer-app').hide();
window.setCookie('_float-layer-app', 'id490655927',
{
domain: '.yohobuy.com'
});
window.setCookie('_float-layer-app-close', 1,
{
domain: '.yohobuy.com',
expires: 1
});
return false;
});
if ($('#float-layer-btn') && $('#float-layer-btn')[0]) {
floatLayerBtnHammer = new Hammer($('#float-layer-btn')[0]);
floatLayerBtnHammer.on('tap', function(e) {
downLoadApp('bottom');
e.srcEvent.stopPropagation();
});
if (typeof window.cookie === 'function' && !window.cookie('_float-layer-app')) {
$('#float-layer-app').show();
} else {
$('#float-layer-app').hide();
}
}
... ...
@import "search";
.brand-page {
.re-pos-search {
top: 170px !important;
}
.hide-when-loading {
display: none;
}
.genderNav {
display: block;
width: 100%;
height: 80px;
line-height: 80px;
overflow: hidden;
color: #aeaeae;
z-index: 3;
position: fixed;
top: 90px;
border-bottom: 1px solid #e1e1e1;
background-color: #fff;
ul {
width: 100%;
height: 90%;
overflow: hidden;
li {
width: 25%;
height: 100%;
overflow: hidden;
float: left;
text-align: center;
position: relative;
font-size: 28px;
i {
width: 100%;
height: 40%;
overflow: hidden;
display: block;
}
span:not(.split-border) {
width: 100%;
height: auto;
overflow: hidden;
display: block;
}
.split-border {
display: inline-block;
width: 2px;
height: 1rem;
background-color: #e1e1e1;
position: absolute;
top: 30%;
right: 0;
}
}
li:last-child {
.split-border {
display: none;
}
}
li.active {
color: #444;
}
}
}
.brandNav {
display: block;
width: 100%;
line-height: 80px;
overflow: hidden;
color: #aeaeae;
z-index: 3;
border-top: 30px solid #f4f4f4;
background-color: #fff;
border-bottom: 1px solid #f4f4f4;
ul {
width: 100%;
height: 90%;
overflow: hidden;
li {
width: 33%;
height: 100%;
overflow: hidden;
float: left;
text-align: center;
position: relative;
font-size: 28px;
i {
width: 100%;
height: 40%;
overflow: hidden;
display: block;
}
span:not(.split-border) {
width: 100%;
height: auto;
overflow: hidden;
display: block;
}
.split-border {
display: inline-block;
width: 2px;
height: 1rem;
background-color: #e1e1e1;
position: absolute;
top: 30%;
right: 0;
}
}
li:last-child {
.split-border {
display: none;
}
}
li.active {
color: #444;
}
}
}
.newbrand-search {
width: 100%;
height: 88px;
padding: 14px 3.125%;
background-color: #f8f8f8;
left: 0;
top: 90px;
position: fixed;
z-index: 2;
.search-box {
position: relative;
height: 60px;
background-color: #fff;
border-radius: 30px;
padding: 0 32px 0 52px;
a {
width: 100%;
height: 60px;
border: 0;
display: block;
span {
line-height: 60px;
color: #bdbdbd;
font-size: 1.2em;
padding-left: 18px;
}
}
.search-icon {
position: absolute;
font-size: 24px;
top: 0;
left: 24px;
line-height: 60px;
color: #bdbdbd;
}
.search-input {
border: none;
width: 95%;
height: 60px;
font-size: 1.2em;
padding: 0 10px;
}
.search-action {
display: none;
position: absolute;
top: 0;
right: -74px;
font-size: 32px;
line-height: 60px;
color: #666;
.clear-text {
font-size: 40px;
}
}
.cancel-btn {
display: inline;
font-size: 28px;
vertical-align: middle;
color: #666;
}
.clear-text {
margin-right: 20px;
}
}
}
.banner-top {
padding-top: 258px;
background-color: #f8f8f8;
}
.hot-brands {
padding-top: 178px;
border-top: 30px solid #f4f4f4;
.floor-header {
padding: 0;
}
.brands-swiper {
border-top: 0;
}
}
.hot-brand {
margin: 30px 0 0;
.hot-brand-list {
background: #fff;
li {
float: left;
width: 158px;
height: 158px;
.img-box {
display: table-cell;
vertical-align: middle;
text-align: center;
width: 158px;
height: 158px;
}
img {
max-width: 140px;
max-height: 140px;
}
}
}
}
.brand-list {
width: 100%;
.title-bar {
width: 100%;
background: #eee;
color: #999;
position: relative;
h2 {
padding: 0 20px;
height: 50px;
line-height: 50px;
font-size: 34px;
border-top: 1px solid #e6e6e6;
background-color: #f4f4f4;
}
}
p {
cursor: pointer;
padding: 0 20px;
a {
display: block;
height: 76px;
line-height: 76px;
font-size: 28px;
border-bottom: 1px solid #f3f3f3;
border-top: 1px solid #f9f9f9;
i {
display: inline-block;
margin-top: -4px;
width: 108px;
height: 42px;
text-align: center;
vertical-align: middle;
font-size: 28px;
line-height: 44px;
color: #fff;
border-radius: 50px;
transform: scale(0.8);
}
.icon-hot {
background: #f00;
}
.icon-new {
background: #86c048;
}
}
}
}
.branding-wall {
padding: 0;
width: 98%;
margin-left: 1%;
}
.brand-wall-box {
margin-top: 20px;
width: 32%;
float: left;
}
.brand-name {
margin-top: 10px;
text-align: center;
vertical-align: middle;
font-size: 24px;
line-height: 70px;
height: 70px;
overflow: hidden;
color: #b8b8b8;
}
.right-bar {
width: 60px;
height: 75%;
top: 20%;
overflow: auto;
position: fixed;
right: 2px;
border-radius: 12px;
background: rgba(0, 0, 0, 0.8);
z-index: 2;
display: none;
b {
height: 36px;
line-height: 36px;
text-align: center;
display: block;
color: #999;
font-weight: bold;
}
}
.right-bar::-webkit-scrollbar {
display: none;
}
.con {
padding-top: 10px;
}
.search-result {
padding-top: 165px;
}
}
... ...
... ... @@ -189,4 +189,148 @@
}
}
.category-page {
font-size: 30px;
.search-input {
position: relative;
background-color: #f8f8f8;
padding: 13px 20px;
p {
box-sizing: border-box;
width: 100%;
height: 60px;
line-height: 60px;
border: none;
padding-left: 66px;
border-radius: 60px;
font-size: 26px;
background: #fff;
color: #999;
}
}
.search-icon {
position: absolute;
top: 0;
bottom: 0;
left: 43px;
line-height: 86px;
color: #999;
}
.category-nav {
height: 70px;
border-bottom: 1px solid #e6e6e6;
li {
display: block;
box-sizing: border-box;
float: left;
height: 100%;
padding: 20px 0;
width: 25%;
text-align: center;
color: #999;
&:last-child {
border-right: none;
}
&.focus {
color: #000;
}
&.bytouch {
background: #eee;
}
}
span {
display: block;
width: 100%;
height: 30px;
line-height: 30px;
font-size: 30px;
border-right: 1px solid #e6e6e6;
}
li:last-child span {
border-right: 0;
}
}
.content {
background: #f8f8f8;
&.hide {
display: none;
}
}
.primary-level {
float: left;
box-sizing: border-box;
width: 45%;
> li {
height: 89px;
line-height: 89px;
padding: 0 32px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
&.focus {
background-color: #fff;
}
&.highlight {
background-color: #eee;
}
}
}
.sub-level-container {
float: left;
box-sizing: border-box;
background: #fff;
width: 55%;
height: 100%;
}
.sub-level {
width: 100%;
&.hide {
display: none;
}
> li {
box-sizing: border-box;
height: 89px;
line-height: 89px;
border-bottom: 1px solid #e6e6e6;
padding-left: 20px;
&.highlight {
background: #eee;
}
&:last-child {
border-bottom: none;
}
}
a {
display: block;
height: 100%;
width: 100%;
color: #000;
}
}
}
@import "brand";
@import "home";
... ...
.search-page {
.search-input {
position: relative;
padding: 14px 22px;
background: #f8f8f8;
form {
width: 100%;
}
.search-icon {
position: absolute;
font-size: 24px;
top: 26px;
left: 36px;
color: #b2b2b2;
}
input {
height: 56px;
width: 378px;
border-radius: 28px;
padding: 0 52px;
font-size: 24px;
background: #fff;
border: none;
}
.clear-input {
position: absolute;
top: 20px;
right: 145px;
font-size: 32px;
color: #666;
}
.search {
position: absolute;
top: 18px;
right: 40px;
border: none;
background: transparent;
color: #666;
font-size: 30px;
line-height: 56px;
}
}
.search-items {
padding: 40px 20px;
h3 {
font-size: 24px;
margin-bottom: 20px;
}
li {
float: left;
margin-right: 20px;
margin-bottom: 20px;
max-width: 100%;
overflow: hidden;
}
a {
display: block;
height: 68px;
line-height: 68px;
padding: 0 20px;
font-size: 28px;
background: #f8f8f8;
color: #000;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.clear-icon {
float: right;
background: #fff;
}
span {
margin-right: 5px;
}
.search-group {
border-bottom: 1px solid #e6e6e6;
.ico-hot {
width: 22px;
height: 30px;
display: inline-block;
background: url('/search/hot-ico.png') no-repeat;
margin-right: 20px;
position: relative;
top: 2px;
}
h3 {
color: #b0b0b0;
font-size: 28px;
}
}
.search-content-title {
height: 40px;
.ico-lately {
width: 26px;
height: 26px;
display: inline-block;
background: url('/search/time-ico.png') no-repeat;
margin-right: 20px;
position: relative;
top: 2px;
}
.ico-del {
width: 24px;
height: 26px;
display: inline-block;
background: url('/search/del-ico.png') no-repeat;
}
.left {
float: left;
}
.right {
float: right;
}
}
.search-content{
clear: both;
padding-left: 47px;
box-sizing: border-box;
padding-bottom: 18px;
a {
border-radius: 8px;
border: 2px solid #b0b0b0;
background: #fff;
color: #b0b0b0;
font-size: 28px;
}
}
.hot-search {
margin-top: 38px;
}
}
}
.search-associate {
width: 100%;
background: #f8f8f8;
display: none;
position: absolute;
z-index: 1;
li {
height: 84px;
line-height: 84px;
width: 100%;
padding: 0 20px;
clear: both;
margin-bottom: 5px;
background: #fff;
box-sizing: border-box;
}
.keyword {
float: left;
font-size: 30px;
}
.count {
float: right;
color: #b0b0b0;
font-size: 18px;
i {
font-size: 12PX;
margin-left: 10px;
position: relative;
top: 3px;
}
}
}
.search-brand-page {
.search-input {
position: relative;
padding: 14px 22px;
background: #f8f8f8;
form {
width: 100%;
}
.search-icon {
position: absolute;
font-size: 24px;
top: 26px;
left: 36px;
color: #b2b2b2;
}
input {
height: 56px;
width: 378px;
border-radius: 28px;
padding: 0 52px;
font-size: 24px;
background: #fff;
border: none;
}
.clear-input {
position: absolute;
top: 20px;
right: 145px;
font-size: 32px;
color: #666;
}
.search {
position: absolute;
top: 18px;
right: 40px;
border: none;
background: transparent;
color: #666;
font-size: 30px;
line-height: 56px;
}
}
.search-items {
padding: 40px 20px;
h3 {
font-size: 24px;
margin-bottom: 20px;
color: #b8b8b8;
}
li {
float: left;
margin-right: 20px;
margin-bottom: 20px;
max-width: 100%;
overflow: hidden;
}
a {
display: block;
height: 68px;
line-height: 68px;
padding: 0 20px;
font-size: 28px;
background: white;
color: #b8b8b8;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
border:1px solid #b8b8b8;
border-radius: 0.2rem;
}
.clear-history {
font-size: 28px;
}
.clear-icon{
float: right;
color: #b8b8b8;
border: none;
background: white;
}
span{
margin-right: 10px;
font-size: 14px;
}
.history-search{
border-bottom:1px solid #f3f3f3;
}
.hot-search{
margin-top: 20px;
}
.clearfix{
margin-left: 30px;
}
.left-icon {
font-size: 24px;
}
}
}
\ No newline at end of file
... ...
.data-bind {
display: none;
}
\ No newline at end of file
... ...
... ... @@ -49,6 +49,14 @@ button {
outline: none;
}
.hide {
display: none;
}
.overflow-hidden {
overflow: hidden;
}
.main-wrap {
position: relative;
margin-right: auto;
... ... @@ -63,8 +71,8 @@ button {
@font-face {
font-family: "iconfont";
src: resolve("iconfont.eot"); /* IE9 */
src: resolve("iconfont.eot?#iefix") format("embedded-opentype"), resolve("iconfont.woff") format("woff"), resolve("iconfont.ttf") format("truetype"), resolve("iconfont.svg#iconfont") format("svg"); /* iOS 4.1- */
src: resolve('iconfont.eot'); /* IE9 */
src: resolve('iconfont.eot?#iefix') format('embedded-opentype'), resolve('iconfont.woff') format('woff'), resolve('iconfont.ttf') format('truetype'), resolve('iconfont.svg#iconfont') format('svg'); /* iOS 4.1- */
}
.iconfont {
... ... @@ -82,7 +90,7 @@ button {
display: none;
text-align: center;
width: 70%;
padding: 18PX 55PX;
padding: 34PX 0;
top: 50%;
left: 50%;
margin-left: -35%;
... ... @@ -96,12 +104,12 @@ button {
}
.order-failure {
background-image: resolve("common/order-good.jpg");
background-image: resolve('common/order-good.jpg');
background-size: 100%;
}
.good-failure {
background-image: resolve("common/order-good.jpg");
background-image: resolve('common/order-good.jpg');
background-position-x: 40%;
background-size: 132px !important;
}
... ...
@import "common";
@import "register";
@import "login";
@import "sms-login";
@import "back";
@import "code";
@import "bind";
... ...
/**
* 品牌处理类
*/
'use strict';
const helpers = global.yoho.helpers;
const getContent = (data, type) => {
let resu = {
}
return resu;
};
module.exports = {
getContent
};
... ...