Authored by 王水玲

店铺页面

... ... @@ -7,25 +7,12 @@
'use strict';
const mRoot = '../models';
const headerModel = require('../../../doraemon/models/header');
//const resourcesProcess = require(`${utils}/resources-process`);
// const resourcesProcess = require(`${utils}/resources-process`);
const searchModel = require(`${mRoot}/search`);
const _ = require('lodash');
const helpers = global.yoho.helpers;
//const _processShopInfo = (list) => {
// let formatData = {
// logoImg: helpers.image(list.shopLogo, 500, 500),
// storeName: (list.isShowShopName === 'Y') ? list.shopName : '',
// collect: (list.isFavorite === 'Y') ? true : false
// };
//
// let allGoodsParam = {
// title: '全部商品'
// }
//
// return {};
//};
/**
* 组织店铺页面数据
* @param {array} data 接口返回的店铺页所需数据
... ... @@ -34,61 +21,130 @@ const helpers = global.yoho.helpers;
* @return array
*/
const _formShopData = (data, shopId, isApp) => {
let formatData = {},
single = false,
shopIdObj = {
shop_id: shopId
};
let formatData = {
shopId: shopId,
appVersion: isApp
},
single = false;
let brandId;
//signboard
//oneRowTwoColImages
//allHotProducts
//shopTopBanner
//brandBrowse
//recommend
//shopTopBannerApp
//hotRecommend
//oneRowTwoColImagesApp
//recommendApp
//navigationBar
//newProducts
//goodsTabBar
//hotProductsApp
//largeSlideImg
//shopTopBannerBase
//hotProducts
//largeSlideImgApp
//allNewProducts
//allHotProductsApp
// 组织店铺装修
if (data.decorator) {
_.forEach(data.decorator.list, (floor) => {
let resData = JSON.parse(floor.resourceData);
floor[_.camelCase(floor.resourceName)] = true;
// 店铺banner
if (floor.shopTopBannerApp) {
formatData.branerImg = helpers.image(JSON.parse(floor.resourceData)[0].shopSrc, 640, 200, 1);
formatData.branerImg = resData[0].shopSrc;
}
// 资源位小图 接口返回两组,取每组第一张
if (floor.oneRowTwoColImagesApp) {
let jsonData = JSON.parse(floor.resourceData);
_.forEach(jsonData, (key, item) => {
if (key === 0 && item.data) {
formatData.spring = {
url: item.data.url,
springType: helpers.image(item.data.src)
}
let spring = [];
_.forEach(resData, (item) => {
if (item.data) {
spring.push({
url: item.data[0].url,
springType: helpers.image(item.data[0].src)
});
}
});
formatData.spring = spring;
}
// 店铺品牌一览
if (floor.brandBrowse) {
let brandNumber = resData.length;
let brand = {
list: []
};
brandId = '';
// 少于2个不展示 单品店:单品店根据品牌id查询
if (brandNumber < 2) {
brandId = formatData.brand = resData[0].id;
single = true;
} else {
_.forEach(resData, (item) => {
if (item.brandDomain) {
brand.list.push({
url: helpers.urlFormat('', '', item.brandDomain) + (isApp ? `?openby:yohobuy={"action":"go.brand","params":{"shop_id":${shopId},"brand_id":${item.id}}}` : ''),
img: helpers.image(item.brandIco, 640, 400),
brandName: item.brandName
});
brandId += item.id + ',';
}
});
formatData.brandList = brand;
// 大于5个返回更多品牌链接
if (brandNumber > 5) {
formatData.brandList.url = helpers.urlFormat('/product/index/allBrand', {
shop_id: shopId
});
}
}
}
// 资源位大图幻灯
if (floor.largeSlideImgApp) {
let bannerTop = {
data: []
};
_.forEach(resData, (item) => {
if (item.data[0]) {
bannerTop.data.push({
url: item.data[0].url,
src: item.data[0].src
});
}
});
formatData.bannerTop = bannerTop;
}
// 热门品类
if (floor.recommendApp) {
let hotCategory = {
data: {
title: {
title: '热门品类'
},
list: []
}
};
_.forEach(resData, (cate) => {
hotCategory.data.list.push({
url: cate.url,
src: helpers.image(cate.src)
});
});
formatData.hotCategory = hotCategory;
}
// 人气单品
if (floor.hotProductsApp) {
let goods = [];
_.forEach(resData, (item) => {
goods.push({
url: helpers.urlFormat(item.productId, item.goodsId, item.cnAlphabet) + (isApp ? `?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":${item.productSkn}}` : ''),
img: helpers.image(item.src, 235, 314),
productName: item.productName,
salesPrice: item.salesPrice,
presentPrice: item.salesPrice
});
});
formatData.hotList = goods;
}
});
}
... ... @@ -99,17 +155,19 @@ const _formShopData = (data, shopId, isApp) => {
title: '全部商品'
};
formatData = {
logoImg: helpers.image(data.shopInfo.shopLogo, 500, 500),
formatData = _.assign({
logoImg: data.shopInfo.shopLogo,
storeName: (data.shopInfo.isShowShopName === 'Y') ? list.shopName : '',
collect: (data.shopInfo.isFavorite === 'Y') ? true : false,
url: helpers.urlFormat('', shopIdObj, 'search'), // 搜索链接
collect: data.shopInfo.isFavorite === 'Y',
url: helpers.urlFormat('', {
shop_id: shopId
}, 'search'), // 搜索链接
more_url: helpers.urlFormat('', {
shop_id: shopId,
order: 's_n_d',
title: '人气单品'
}, 'search') // 人气单品的链接
};
}, formatData);
if (single) { // 单品点
allGoodsParam.brand = brandId;
... ... @@ -119,22 +177,56 @@ const _formShopData = (data, shopId, isApp) => {
}
if (!isApp) {
_.assign({
formatData = _.assign({
allGoods: helpers.urlFormat('', allGoodsParam, 'search'),
shopIntroHref: helpers.urlFormat('/product/index/intro', shopIdObj) // 店铺简介页地址
shopIntroHref: helpers.urlFormat('/product/index/intro', {
shop_id: shopId
}) // 店铺简介页地址
}, formatData);
} else {
_.assign({
formatData = _.assign({
allGoods: `${helpers.urlFormat('', allGoodsParam, 'search')}&openby:yohobuy={"action":"go.list","params":{"title":"全部商品", "actiontype":"0","shop_id":"' . self::$shopId . '","page":"1"}}`,
shopIntroHref: helpers.urlFormat('/product/index/intro', {
shop_id: shopId,
app_version: isApp
}),
more_url: `openby:yohobuy{"action":"go.list","params":{"shop_id":${shopId},"title":"人气单品"}}`
more_url: formatData.more_url + `?openby:yohobuy{"action":"go.list","params":{"shop_id":${shopId},"title":"人气单品"}}`
}, formatData);
}
}
// 店铺下面的所有分类
if (data.shopCategory) {
let total = data.shopCategory.length;
let shopCategory = {
list: []
};
if (total > 6) {
shopCategory.url = helpers.urlFormat('/product/index/category', {
shop_id: shopId
});
} else {
_.forEach(data.shopCategory, (item) => {
shopCategory.list.push({
url: helpers.urlFormat('', {
shop_id: shopId,
sort: item.relationParameter.sort
}, 'search'),
categoryId: item.categoryId,
name: item.categoryName
});
});
}
formatData.shopCategory = shopCategory;
}
if (single) {
formatData.favId = shopId;
formatData.shopId = '';
}
return formatData;
};
... ... @@ -148,7 +240,6 @@ const _formShopData = (data, shopId, isApp) => {
const _getShopData = (req, shopId, uid, isApp) => {
let data = {};
let channel = req.yoho.channel;
isApp = isApp || '';
return Promise.all([searchModel.getShopDecorator(shopId), searchModel.getShopInfo(shopId, uid)]).then((result) => {
data = {
... ... @@ -160,17 +251,17 @@ const _getShopData = (req, shopId, uid, isApp) => {
if (data.shopInfo.shopTemplateType && data.shopInfo.shopTemplateType === '1') {
return {
goBrand: data.shopInfo
}
};
}
// 店铺分类
return searchModel.getShopCategory(shopId, channel);
}).then(shopCategory => {
_.assign({
shopCategory: shopCategory
}, data);
return searchModel.getShopCategory(shopId, channel).then(shopCategory => {
_.assign({
shopCategory: shopCategory
}, data);
return _formShopData(data, shopId, isApp); // 组织楼层数据
return _formShopData(data, shopId, isApp); // 组织楼层数据
});
});
};
... ... @@ -184,9 +275,18 @@ const _shop = (req, res, shopId) => {
let uid = 0;
if (!isApp) {
pageHeader = headerModel.setNav({
navTitle: ''
});
pageHeader = {
pageHeader: _.assign({
shopPage: {
text: '分类',
url: helpers.urlFormat('/product/index/category', {
shop_id: shopId
})
}
}, headerModel.setNav({
navTitle: false
}))
};
uid = req.user.uid;
} else {
uid = req.query.uid;
... ... @@ -200,20 +300,19 @@ const _shop = (req, res, shopId) => {
_getShopData(req, shopId, uid, isApp).then((result) => {
if (result.goBrand) {
// 跳转基础模板
//_baseShop(result.goBrand);
// _baseShop(result.goBrand);
}
res.render('shop/index', _.assign({
result = _.assign(result, pageHeader);
res.render('shop/index', {
module: 'product',
page: 'shop',
shopIndex: result,
shopPage: {
text: '分类',
url: helpers.urlFormat('/product/index/category', {
shop_id: shopId
})
},
shopHeadHide: true,
gender: req.query.gender,
channel: req.query.channel
}, pageHeader));
});
});
};
... ... @@ -336,7 +435,6 @@ const brand = (req, res, next) => {
let brandId = 0;
let brandLogo = {};
let title = '';
let brandHome = false;
if (!domain) {
res.redirect('/?go=1');
... ... @@ -347,12 +445,6 @@ const brand = (req, res, next) => {
title = brandLogo.name;
//无店铺:0--->品牌页 无单品店有多品店:1--->搜索页 有单品店:2--->店铺页面
if (brandLogo.type === '2' && brandLogo.shopId) {
_shop(req, res, brandLogo.shopId);
return false
}
if (brandLogo && brandLogo.id) {
brandId = brandLogo.id;
}
... ... @@ -361,45 +453,49 @@ const brand = (req, res, next) => {
brand: brandId
}, params);
//获取品牌店铺信息
return searchModel.getBrandShops(brandId);
}).then((brandShop) => {
if (brandId === 0) {
params.query = domain;
}
// 无店铺:0--->品牌页 无单品店有多品店:1--->搜索页 有单品店:2--->店铺页面
if (brandLogo.type === '2' && brandLogo.shopId) {
_shop(req, res, brandLogo.shopId);
} else { // 获取品牌店铺信息
searchModel.getBrandShops(brandId).then((brandShop) => {
if (brandId === 0) {
params.query = domain;
}
// 从搜索页过来的,显示搜索框, 和进入品牌引导信息 或者品牌关联多店铺
if (req.query.from === 'search' || brandShop.length > 0) {
params = {
brandWay: brandShop ? brandShop : brandLogo,
search: {
default: req.query.query,
url: helpers.urlFormat('', null, 'search')
// 从搜索页过来的,显示搜索框, 和进入品牌引导信息 或者品牌关联多店铺
if (req.query.from === 'search' || brandShop.length > 0) {
params = {
brandWay: brandShop ? brandShop : brandLogo,
search: {
default: req.query.query,
url: helpers.urlFormat('', null, 'search')
}
};
} else if (brandId !== 0) { // 品牌一览过来的展示品牌介绍和LOGO
return Promise.all([searchModel.getBrandIntro(brandId, uid), searchModel.getBrandBanner(brandId)]).then((result) => {
title = result[0].title;
delete result[0].title;
return _.assign({
banner: result[1]
}, result[0]);
});
}
};
} else if (brandId !== 0) { // 品牌一览过来的展示品牌介绍和LOGO
return Promise.all([searchModel.getBrandIntro(brandId, uid), searchModel.getBrandBanner(brandId)]).then((result) => {
title = result[0].title;
delete result[0].title;
return _.assign({
banner: result[1]
}, result[0]);
}).then((brandHome) => {
params.brandHome = brandHome;
res.render('search/goods-list', {
module: 'product',
page: 'search-list',
pageHeader: headerModel.setNav({
navTitle: title !== '' ? title : domain
}),
goodList: params,
showDownloadApp: true,
pageFooter: true
});
});
}
}).then((brandHome) => {
params.brandHome = brandHome;
res.render('search/goods-list', {
module: 'product',
page: 'search-list',
pageHeader: headerModel.setNav({
navTitle: title !== '' ? title : domain
}),
goodList: params,
showDownloadApp: true,
pageFooter: true
});
}).catch(next);
};
... ... @@ -441,7 +537,12 @@ const favoriteBrand = (req, res, next) => {
let id = req.body.id;
let uid = req.user.uid || 20000032;
let opt = req.body.opt || 'ok';
let type = req.body.type || 'product';
let appVersion = req.body.appVersion || false;
if (appVersion === 'true') {
uid = req.cookies.appUid;
}
if (_.isNumber(id)) {
res.json({
... ... @@ -460,13 +561,13 @@ const favoriteBrand = (req, res, next) => {
});
return false;
} else if (opt !== 'ok') { // 取消收藏
searchModel.setFavoriteCancel(id, uid).then((data) => {
searchModel.setFavoriteCancel(id, uid, type).then((data) => {
res.json(data);
return false;
}).catch(next);
}
searchModel.setFavorite(id, uid).then((result) => {
searchModel.setFavorite(id, uid, type).then((result) => {
if (!result.code) { // 收藏
result = {
code: 401,
... ...
... ... @@ -125,10 +125,10 @@ const _processBrandShops = (list) => {
if (item.shopId) {
formatDat.push({
url: helpers.urlFormat('/product/index/brand/', {
shop_id: item.brandId
}),
thumb: helpers.image(item.brandIco, 75, 40),
name: item.brandName
shop_id: item.brandId
}),
thumb: helpers.image(item.brandIco, 75, 40),
name: item.brandName
});
}
});
... ... @@ -284,9 +284,9 @@ const getBrandLogoByDomain = (domain) => {
url: helpers.urlFormat('', null, formatData.brandDomain),
thumb: helpers.image(formatData.brandIco, 75, 40),
name: formatData.brandName,
shopId: formatData.shopId ? formatData.shopId : 0,//店铺id
shopId: formatData.shopId ? formatData.shopId : 0, // 店铺id
type: formatData.type ? formatData.type : 0
}
};
} else {
return false;
}
... ... @@ -320,19 +320,18 @@ const getBrandShops = (brandId) => {
/**
* 收藏
* @param {int} id 品牌ID
* @param {int} id ID
* @param {int} uid 用户ID
* @param {bool} isBrand 是品牌还是商品
* @param type
* @return array
*/
const setFavorite = (id, uid, isBrand) => {
isBrand = isBrand || true;
const setFavorite = (id, uid, type) => {
return api.post('', {
method: 'app.favorite.add',
fav_id: id,
id: id,
uid: uid,
type: isBrand ? 'brand' : 'product'
type: type
});
};
... ... @@ -341,17 +340,16 @@ const setFavorite = (id, uid, isBrand) => {
*
* @param {int} id 品牌ID
* @param {int} uid 用户ID
* @param {bool} isBrand 是品牌还是商品
* @param type
* @return array
*/
const setFavoriteCancel = (id, uid, isBrand) => {
isBrand = isBrand || true;
const setFavoriteCancel = (id, uid, type) => {
return api.post('', {
method: 'app.favorite.cancel',
fav_id: id,
id: id,
uid: uid,
type: isBrand ? 'brand' : 'product'
type: type
});
};
... ...
{{# shopIndex}}
{{log this}}
<div class="shop-index yoho-page" id="wrapper">
<div id="scroller">
<div id="nav-top">
<!--{{!--{{# headerBanner}}-->
<!--{{> resources/banner-top}}-->
<!--{{/ headerBanner}}--}}-->
<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" data-bp-id="shop_search_input_1">
<input type="hidden" name="from" value="search">
<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>
{{> header}}
{{#if appVersion}}
<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}}">
{{else}}
<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="app_version" value="{{appVersion}}">
<input type="hidden" name="brand" value="{{brand}}">
<input type="hidden" name="favId" value="{{favId}}">
<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>
</div>
{{/if}}
<div class="branner-top">
<img src="{{branerImg}}">
<img class="logo" src=""></div>
<p class="name">Vans专营店</p>
<div class="collect"></div>
<img class="shop-back-img" src="{{image branerImg 640 200 1}}">
<img class="logo" src="{{image logoImg 500 500}}">
<p class="store-name">{{storeName}}</p>
<div class="collect">
{{#if collect}}
<div class="alreadyCollect" id="collect"></div>
{{else}}
<div class="notCollect buriedpoint" id="collect" data-bp-id="shop_branner_collect_1"></div>
{{/if}}
</div>
</div>
</div>
<ul id="nav" class="nav">
<li class="active color buriedpoint" tab="home-page" data-bp-id="shop_nav_index_1">首页</li>
<li tab="new-arrival" class="buriedpoint" data-bp-id="shop_nav_new_1">上新</li>
<li tab="popularity" class="buriedpoint" data-bp-id="shop_nav_populary_1">人气</li>
<li class="buriedpoint" data-bp-id="shop_nav_all_1">
<a href="#" target="_blank">全部商品</a>
<li tab="new-arrival" data-bp-id="shop_nav_new_1" class="buriedpoint">上新</li>
<li tab="popularity" data-bp-id="shop_nav_populary_1" class="buriedpoint">人气</li>
<li data-bp-id="shop_nav_all_1" class="all-goods buriedpoint">
<a href="{{allGoods}}" target="_blank">全部商品</a>
</li>
</ul>
<div id="home-page">
<div id="nav-main" class="main">
{{#unless brands}}
<div class="multi-brands">
<h2>品牌一览</h2>
<div class="multi-browse">
<ul class="swiper-wrapper">
{{#each multiList}}
<li class="swiper-slide brand-img buriedpoint" data-bp-id="shop_brand_{{img}}_0">
<a href="{{url}}">
<img src="{{img}}">
</a>
<p>{{brandName}}</p>
</li>
{{/each}}
</ul>
<div id="home-page" class="main">
<div id="nav-main" >
{{#if brandList}}
<div class="multi-brands">
<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="{{img}}">
</a>
<p>{{brandName}}</p>
</li>
{{/each}}
</ul>
</div>
</div>
</div>
{{/unless}}
{{/if}}
<div class="banner-area">
{{# bannerTop}}
{{> home/banner_top}}
{{> resources/banner-top}}
{{/ bannerTop}}
</div>
<ul class="spring">
{{#each spring}}
<li class="buriedpoint" data-bp-id="shop_spring_{{img}}_0" >
<a href="{{url}}">
<img src="{{springType}}">
</a>
</li>
<li class="buriedpoint" data-bp-id="shop_spring_{{url}}_0">
<a href="{{url}}">
<img src="{{springType}}">
</a>
</li>
{{/each}}
</ul>
... ... @@ -77,22 +90,22 @@
<div class="popularity-title">
人气单品
<a class="more" href="{{more_url}}">&#xe618;</a>
<a class="more buriedpoint" href="{{more_url}}" data-bp-id="shop_popularity_{{more_url}}">&#xe618;</a>
</div>
<ul class="product-list">
{{#each hotList}}
<li class="buriedpoint" data-bp-id="shop_hotcategory_{{listUrl}}_0">
<a href="{{url}}">
<img src="{{listUrl}}">
</a>
<div class="list-price">
<p>VANS AP M BERZE</p>
<p><span class="red">{{originalPrice}}</span>
<span>{{presentPrice}}</span>
</p>
</div>
</li>
<li class="buriedpoint" data-bp-id="shop_hotList_{{url}}">
<a href="{{url}}">
<img src="{{img}}">
</a>
<div class="list-price">
<p>{{productName}}</p>
<p><span class="red">{{originalPrice}}</span>
<span>{{presentPrice}}</span>
</p>
</div>
</li>
{{/each}}
</ul>
</div>
... ... @@ -101,45 +114,50 @@
{{> shop/goods-nav-top}}
</div>
</div>
<div id="new-arrival" class=""></div>
<div id="popularity" class=""></div>
<div id="new-arrival" class="new-arrival main hide"></div>
<div id="popularity" class="popularity main hide"></div>
</div>
{{> shop/shop-footer}}
{{#unless appVersion}}
{{> shop/shop-footer}}
{{/unless}}
<ul id="pos-nav" class="nav hide">
<li class="active color buriedpoint" data-bp-id="shop_nav_index_1">首页</li>
<li class="buriedpoint" data-bp-id="shop_nav_new_1">上新</li>
<li class="buriedpoint" data-bp-id="shop_nav_populary_1">人气</li>
<li class="buriedpoint" data-bp-id="shop_nav_all_1">
<a href="#" target="_blank">全部商品</a>
<li class="active color buriedpoint" tab="home-page" data-bp-id="shop_posnav_index_1">首页</li>
<li tab="new-arrival" class="buriedpoint" data-bp-id="shop_posnav_new_1">上新</li>
<li tab="popularity" class="buriedpoint" data-bp-id="shop_posnav_populary_1">人气</li>
<li class="all-goods buriedpoint" data-bp-id="shop_posnav_all_1">
<a href="{{allGoods}}" target="_blank">全部商品</a>
</li>
</ul>
<ul id="pos-list " class="list-nav hide">
<li class="new active buriedpoint" data-bp-id="shop_listnav_new_1">
<ul id="pos-list" class="home-sub-nav pos-list hide">
<li class="new active buriedpoint" data-bp-id="shop_poslist_new_1">
<a href="javascript:void(0);">
<span class="spanTest">最新</span>
<span class="iconfont cur">&#xe616;</span>
<b></b>
</a>
</li>
<li class="price buriedpoint" data-bp-id="shop_listnav_price_1">
<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_listnav_discount_true">
<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_listnav_filter_1">
<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>
... ... @@ -148,3 +166,4 @@
</ul>
</div>
{{/ shopIndex}}
{{> common/query-param}}
... ...
... ... @@ -32,7 +32,9 @@
{{> updata}}
{{/if}}
{{> header}}
{{#unless shopHeadHide}}
{{> header}}
{{/unless}}
{{{body}}}
{{> footer}}
</div>
... ...
... ... @@ -10,6 +10,9 @@
{{#navBtn}}
<span class="iconfont nav-home">&#xe638;</span>
{{/navBtn}}
{{#shopPage}}
<a href="{{url}}" class="nav-sub-right">{{text}}</a>
{{/shopPage}}
{{#currencyPage}}
<a href="/home/helpDetail?code=20151230-102233&caption=YOHO币介绍" class="iconfont nav-home">&#xe639;</a>
{{/currencyPage}}
... ...
... ... @@ -321,7 +321,7 @@ function search(opt) {
break;
}
if (data === ' ') {
if (data === '') {
nav.end = true;
if (nav.reload) {
... ... @@ -565,7 +565,8 @@ if ($brandHeader.length > 0) {
url: '/product/opt/favoriteBrand',
data: {
id: id,
opt: opt
opt: opt,
type: 'brand'
},
success: function(data) {
if (data.code === 200) {
... ...
request('../shop/shop');
require('./shop/shop');
... ...
... ... @@ -2,10 +2,10 @@
* 品牌店铺首页
*/
var $ = require('jquery'),
IScroll = require('iscroll/iscroll-probe'),
lazyLoad = require('yoho.lazyload'),
Swiper = require('yoho.iswiper'),
var $ = require('yoho-jquery'),
IScroll = require('yoho-iscroll/build/iscroll-probe'),
lazyLoad = require('yoho-jquery-lazyload'),
Swiper = require('yoho-swiper'),
bannerSwiper,
multiSwiper,
myScroll,
... ... @@ -20,11 +20,13 @@ var $ = require('jquery'),
$nav2 = $('#pos-list'),
sTop;
var tip = require('../plugin/tip'),
filter = require('../plugin/filter'),
loading = require('../plugin/loading');
var tip = require('../../plugin/tip'),
filter = require('../../plugin/filter'),
loading = require('../../plugin/loading');
var $subNav = $('.home-sub-nav'),
$collect = $('#collect'),
$categoryList = $('.category-list'),
$goodsContainer = $('#goods-container'),
$goodsChildren = $goodsContainer.children(),
$ngc = $($goodsChildren.get(0)),
... ... @@ -38,12 +40,12 @@ var $subNav = $('.home-sub-nav'),
var winH = $(window).height(),
noResult = '<p class="no-result">未找到相关搜索结果</p>';
//默认筛选条件
var defaultOpt = require('./query-param');
// 默认筛选条件
var defaultOpt = require('../../common/query-param');
var $listNav = $('#list-nav'),
//导航数据信息
// 导航数据信息
navInfo = {
new: {
order: 1,
... ... @@ -76,17 +78,22 @@ var $listNav = $('#list-nav'),
end: false
}
},
$pre = $listNav.find('.active'), //纪录进入筛选前的active项,初始为选中项
$pre = $listNav.find('.active'), // 纪录进入筛选前的active项,初始为选中项
searching;
var viewType = 1,// 1-首页,2-上新,3-人气
var viewType = 1, // 1-首页,2-上新,3-人气
listCount = $('.category-list li').length,
listModValue = 4 - listCount % 4,
listIndex;
require('../../common');
lazyLoad($('img.lazy'));
//焦点效果
$('.main-wrap').css({
position: 'static'
});
// 焦点效果
if ($('.banner-swiper').find('li').size() > 1) {
bannerSwiper = new Swiper('.banner-swiper', {
lazyLoading: true,
... ... @@ -112,25 +119,25 @@ if ($('.multi-browse').find('li').size() > 1) {
});
}
//根据热门品类的个数来改变样式展示
// 根据热门品类的个数来改变样式展示
//
if ($('.category-list li').length % 4 !== 0) {
if ($categoryList.find('li').length % 4 !== 0) {
$('.category-list li:last-child').addClass('category-list-last-li');
}
if ($('.category-list li').length < 4) {
$('.category-list').addClass('category-list-top-board');
$('.category-list').find('.buriedpoint').addClass('category-list-only-one-row');
if ($categoryList.find('li').length < 4) {
$categoryList.addClass('category-list-top-board');
$categoryList.find('.buriedpoint').addClass('category-list-only-one-row');
}
if ($('.category-list li').length >= 5) {
if ($categoryList.find('li').length >= 5) {
for (listIndex = listModValue; listIndex >= 0; listIndex--) {
$('.category-list li').eq(listCount - 4 + listIndex - 1).addClass('category-list-last-full-row');
}
}
function getPageGoods(info) {
var nav,navType;
var nav, navType;
if (searching) {
return;
... ... @@ -139,7 +146,7 @@ function getPageGoods(info) {
navType = info.data.type;
nav = navInfo[navType];
//不需要重新加载并且数据请求结束
// 不需要重新加载并且数据请求结束
if (nav.end) {
return;
... ... @@ -148,10 +155,10 @@ function getPageGoods(info) {
searching = true;
$.ajax({
type: 'GET',
url: info.url,
url: '/product/search/search',
data: info.data,
success: function(data) {
if (data === ' ') {
if (data === '') {
nav.end = true;
}
... ... @@ -177,7 +184,6 @@ function getParam(req) {
function newData(callback) {
var req = {};
req.url = '/index/search/search';
req.data = {
type: 'newest',
order: '1',
... ... @@ -202,7 +208,6 @@ function newData(callback) {
function hotData(callback) {
var req = {};
req.url = '/index/search/search';
req.data = {
type: 'hot',
order: '1',
... ... @@ -234,7 +239,7 @@ function tabChange(dom, index) {
li.addClass('color');
}
//首页导航
// 首页导航
$.jqtab = function(nav, posNav, main) {
$(nav + ' li, ' + posNav + ' li').not('li.all-goods').on('touchstart', function() {
... ... @@ -271,8 +276,6 @@ $.jqtab = function(nav, posNav, main) {
$.jqtab('#nav', '#pos-nav', '.main');
$('#wrapper').addClass('scroll-wrapper');
// lazyLoad($('img.lazy'));
myScroll = new IScroll('#wrapper', {
probeType: 3,
mouseWheel: true,
... ... @@ -309,14 +312,14 @@ myScroll.on('scroll', function() {
}
if (!$nav2.hasClass('hide')) {
$nav2.addClass('hide');
} //滑动距离不到导航1
} // 滑动距离不到导航1
} else if (sTop < imgH + nav1H + main1oH) {
if ($nav1.hasClass('hide')) {
$nav1.removeClass('hide');
}
if (!$nav2.hasClass('hide')) {
$nav2.addClass('hide');
}//滑动距离不到导航2
}// 滑动距离不到导航2
if (sTop < imgH + main1H) {
if (!$nav1.hasClass('fixed-top')) {
... ... @@ -369,12 +372,7 @@ document.addEventListener('touchmove', function(e) {
e.preventDefault();
}, false);
/*if (!isIphone) {
return;
}*/
//window onload 后重新refresh iscroll
// window onload 后重新refresh iscroll
$(window).load(function() {
myScroll && myScroll.refresh();
imgH = $('#nav-top').outerHeight();
... ... @@ -400,16 +398,12 @@ function search(opt) {
page;
if (searching) {
return;
}
if (!opt.url) {
opt.url = '/index/search/search';
return false;
}
if (!opt.nextPage) {
//筛选项变更则重置reload为true
// 筛选项变更则重置reload为true
for (att in navInfo) {
if (navInfo.hasOwnProperty(att)) {
navInfo[att].reload = true;
... ... @@ -466,11 +460,11 @@ function search(opt) {
};
break;
}
$.extend(defaultOpt, ext); //扩展筛选项
$.extend(defaultOpt, ext); // 扩展筛选项
}
}
//导航类别
// 导航类别
if ($pre.hasClass('new')) {
navType = 'newest';
} else if ($pre.hasClass('price')) {
... ... @@ -485,7 +479,7 @@ function search(opt) {
page = 1;
} else if (nav.end) {
//不需要重新加载并且数据请求结束
// 不需要重新加载并且数据请求结束
return;
}
$.extend(setting, defaultOpt, {
... ... @@ -506,7 +500,7 @@ function search(opt) {
$.ajax({
type: 'GET',
url: opt.url ? opt.url : '',
url: '/product/search/search',
data: setting,
success: function(data) {
var $container,
... ... @@ -524,7 +518,7 @@ function search(opt) {
break;
}
if (data === ' ') {
if (data === '') {
nav.end = true;
if (nav.reload) {
... ... @@ -578,7 +572,7 @@ function getQueryString(name) {
$.ajax({
type: 'GET',
url: '/search/filter',
url: '/product/search/filter',
data: {
shop_id: brand ? '' : shopId,
brand: brand,
... ... @@ -588,12 +582,12 @@ $.ajax({
success: function(data) {
$goodsContainer.append(data);
//初始化filter&注册filter回调
// 初始化filter&注册filter回调
filter.initFilter({
fCbFn: search,
hCbFn: function() {
//切换active状态到$pre上
// 切换active状态到$pre上
$pre.addClass('active');
$pre.siblings('.filter').removeClass('active');
},
... ... @@ -628,11 +622,11 @@ $subNav.on('touchend touchcancel', function(e) {
if ($this.hasClass('filter')) {
//筛选面板切换状态
// 筛选面板切换状态
if ($this.hasClass('active')) {
filter.hideFilter();
//点击筛选钱的active项回复active
// 点击筛选钱的active项回复active
$pre.addClass('active');
$this.removeClass('active');
} else {
... ... @@ -659,7 +653,7 @@ $subNav.on('touchend touchcancel', function(e) {
if ($this.hasClass('active')) {
//最新无排序切换
// 最新无排序切换
if ($this.hasClass('new')) {
return;
}
... ... @@ -669,9 +663,9 @@ $subNav.on('touchend touchcancel', function(e) {
// 价格/折扣切换排序状态
$this.find('.icon > .iconfont').toggleClass('cur');
$pre = $this; //更新pre为当前项
nav.reload = true; //重置reload,HTML会被替换为逆序的HTML
nav.order = nav.order === 0 ? 1 : 0; //切换排序
$pre = $this; // 更新pre为当前项
nav.reload = true; // 重置reload,HTML会被替换为逆序的HTML
nav.order = nav.order === 0 ? 1 : 0; // 切换排序
$goodsContainer.children('.container:not(.hide)').addClass('hide');
... ... @@ -693,15 +687,15 @@ $subNav.on('touchend touchcancel', function(e) {
} else {
$active = $subNav.find('.active');
$pre = $this; //$pre为除筛选导航的其他导航项,若当前active的为筛选,则把$pre置为当前点击项
$pre = $this; // $pre为除筛选导航的其他导航项,若当前active的为筛选,则把$pre置为当前点击项
if ($active.hasClass('filter')) {
//若之前active项为筛选,则隐藏筛选面板
// 若之前active项为筛选,则隐藏筛选面板
filter.hideFilter();
} else {
//切换container显示
// 切换container显示
$goodsContainer.children('.container:not(.hide)').addClass('hide');
switch (navType) {
... ... @@ -728,7 +722,6 @@ $subNav.on('touchend touchcancel', function(e) {
type: 'shop_id',
id: shopId,
brand: brand,
url: '/index/search/search',
nextPage: false
});
}
... ... @@ -741,7 +734,7 @@ function scrollHandler() {
sTop = -myScroll.y;
//当scroll到1/4$goodsContainer高度后继续请求下一页数据
// 当scroll到1/4$goodsContainer高度后继续请求下一页数据
myScroll && myScroll.refresh();
if (sTop + winH > $('#scroller').height() - 0.25 * $goodsContainer.height() - 50) {
if ($pre !== undefined) {
... ... @@ -749,25 +742,23 @@ function scrollHandler() {
type: 'shop_id',
id: shopId,
brand: brand,
url: '/index/search/search',
nextPage: true
});
}
}
}
//srcoll to load more
// srcoll to load more
$(window).scroll(function() {
window.requestAnimationFrame(scrollHandler);
});
//初始请求最新第一页数据
// 初始请求最新第一页数据
search({
type: 'shop_id',
id: shopId,
brand: brand,
url: '/index/search/search',
nextPage: false
});
... ... @@ -785,7 +776,7 @@ $nav2.on('touchstart', 'li', function(e) {
myScroll.refresh();
});
//底部导航点击
// 底部导航点击
function fotterClick(group) {
$(group + ' li').on('touchstart', function() {
$('.sub-group').addClass('hide');
... ... @@ -813,31 +804,41 @@ $('.shop-foot-wrapper').bind('touchstart', function(e) {
stopPropagation(e);
});
//收藏
function postCollect(info) {
var url = '';
// 店铺收藏 || 取消收藏
$collect.on('touchstart', function() {
var opt;
if (searching) {
return;
}
searching = true;
$.ajax({
method: 'post',
url: info.url,
data: info.data,
if ($collect.hasClass('alreadyCollect')) {
opt = 'cancel';
} else {
opt = 'ok';
}
$.ajax({
type: 'POST',
url: '/product/opt/favoriteBrand',
data: {
id: favId ? favId : shopId,
appVersion: appVersion,
opt: opt,
type: 'shop'
},
success: function(data) {
if (data.code === 200) {
if ($('#collect').hasClass('alreadyCollect')) {
$('#collect').attr('class', 'notCollect');
if ($collect.hasClass('alreadyCollect')) {
$collect.attr('class', 'notCollect');
} else {
$('#collect').attr('class', 'alreadyCollect');
$collect.attr('class', 'alreadyCollect');
}
}
if (data.code === 401) {
if (data.code === 400) {
url = data.url;
$('body').append('<a href=\'' + url + '\'><span class="jump-login"><span></a>');
... ... @@ -851,38 +852,8 @@ function postCollect(info) {
searching = false;
},
error: function() {
alert('网络断开连接了~');
tip.show('网络断开连接了~');
searching = false;
}
});
}
function collectShop() {
var qew = {};
qew.url = '/product/index/shopFav';
qew.data = {
shop_id: favId ? favId : shopId,
app_version: appVersion
};
postCollect(qew);
}
function cancelShop() {
var qew = {};
qew.url = '/product/index/cancelShopFav';
qew.data = {
shop_id: favId ? favId : shopId,
app_version: appVersion
};
postCollect(qew);
}
$('#collect').on('touchstart', function(e) {
if ($('#collect').hasClass('alreadyCollect')) {
cancelShop();
} else {
collectShop();
}
});
\ No newline at end of file
});
... ...
... ... @@ -58,6 +58,11 @@
font-size: 14PX;
}
.nav-sub-right {
@extend nav;
right: 100px;
}
.nav-title {
position: absolute;
top: 0;
... ...
.shop-index {
.shop-index {
position: absolute;
top: 0;
bottom: 0;
... ... @@ -77,7 +77,7 @@
overflow: hidden;
border-sizing: border-box;
border-bottom: 1px solid #e1e1e1;
li{
color: #b1b1b1;
display: block;
... ... @@ -102,7 +102,7 @@
.color {
color: #000;
}
}
}
.main {
... ... @@ -143,8 +143,8 @@
font-size: 20px;
text-align: center;
padding-top: 25px;
margin-bottom: 30px;
overflow: hidden;
margin-bottom: 30px;
overflow: hidden;
p {
font-size: 30px;
... ... @@ -154,7 +154,7 @@
.multi-browse {
margin-top: 50px;
}
.brand-img {
margin-left: 30px;
width: 30%;
... ... @@ -295,7 +295,7 @@
}
.discount-area {
@extend .discount-page;
@extend .sale-page;
.list-nav li {
display: block;
... ... @@ -343,9 +343,9 @@
.active {
.cur {
color: #000;
}
}
}
.list-nav .icon .up {
top: -28px;
}
... ... @@ -460,7 +460,7 @@
}
.pos-list {
@extend .discount-page;
@extend .sale-page;
background: #fff;
width: 100%;
overflow: hidden;
... ... @@ -535,7 +535,7 @@
.category-list-top-board {
border-top: 1px solid #e0e0e0;
}
.category-list-last-li {
border-right: 1px solid #e0e0e0;
}
... ... @@ -547,4 +547,4 @@
.category-list-last-full-row {
border-bottom: 1px solid #e0e0e0;
}
}
\ No newline at end of file
}
... ...