Authored by 姜枫

add shop&brand collect

... ... @@ -37,6 +37,66 @@ const product = (req, res, next) => {
res.json(resData);
};
const brand = (req, res, next) => {
let uid = req.user.uid;
let pid = req.body.brandId;
let type = (req.body.type === 'add');
let resData = {
code: 400,
message: '操作失败'
};
if (uid) {
if (pid) {
fav.toggleFavBrand(pid, uid, type).then(result => {
res.json(result);
}).catch(next);
return;
}
} else {
Object.assign(resData, {
code: 403,
message: '请登录后执行该操作',
data: {
refer: helpers.urlFormat('/signin')
}
});
}
res.json(resData);
};
const shop = (req, res, next) => {
let uid = req.user.uid;
let pid = req.body.shopId;
let type = (req.body.type === 'add');
let resData = {
code: 400,
message: '操作失败'
};
if (uid) {
if (pid) {
fav.toggleFavShop(pid, uid, type).then(result => {
res.json(result);
}).catch(next);
return;
}
} else {
Object.assign(resData, {
code: 403,
message: '请登录后执行该操作',
data: {
refer: helpers.urlFormat('/signin')
}
});
}
res.json(resData);
};
module.exports = {
product // 组件demo页
product,
brand,
shop
};
... ...
... ... @@ -60,7 +60,6 @@ const shop = {
q.page = parseInt(q.page || 1, 10);
ShopData.getShopHeadData(domain, uid).then(result => {
data.banner = result;
if (data.banner.banner) {
... ...
... ... @@ -19,9 +19,9 @@ const getDomainInfo = domain => {
})();
};
const getBrandInfo = bid => {
const getBrandInfo = (bid, uid) => {
return co(function*() {
let brandInfo = yield api.getBrandInfo(bid);
let brandInfo = yield api.getBrandInfo(bid, uid);
if (!brandInfo.data || brandInfo.code !== 200) {
return {};
... ...
... ... @@ -8,21 +8,21 @@
const api = global.yoho.API;
const addFavAsync = (uid, pid) => {
const addFavAsync = (uid, id, type) => {
return api.get('', {
method: 'app.favorite.add',
id: pid,
id: id,
uid: uid,
type: 'product'
type: type
});
};
const cancelFavAsync = (uid, pid) => {
const cancelFavAsync = (uid, id, type) => {
return api.get('', {
method: 'app.favorite.cancel',
fav_id: pid,
fav_id: id,
uid: uid,
type: 'product'
type: type
});
};
... ...
... ... @@ -10,13 +10,31 @@ const FavAPI = require('./favorite-api');
const toggleFavProduct = (productId, uid, isadd) => {
if (isadd) {
return FavAPI.addFavAsync(uid, productId);
return FavAPI.addFavAsync(uid, productId, 'product');
} else {
return FavAPI.cancelFavAsync(uid, productId);
return FavAPI.cancelFavAsync(uid, productId, 'product');
}
};
const toggleFavBrand = (brandId, uid, isadd) => {
if (isadd) {
return FavAPI.addFavAsync(uid, brandId, 'brand');
} else {
return FavAPI.cancelFavAsync(uid, brandId, 'brand');
}
};
const toggleFavShop = (shopId, uid, isadd) => {
if (isadd) {
return FavAPI.addFavAsync(uid, shopId, 'shop');
} else {
return FavAPI.cancelFavAsync(uid, shopId, 'shop');
}
};
module.exports = {
toggleFavProduct
toggleFavProduct,
toggleFavBrand,
toggleFavShop
};
... ...
... ... @@ -122,6 +122,8 @@ const ShopService = {
let brandId = domainInfo.id;
let brandInfo = yield BrandService.getBrandInfo(brandId, uid);
console.log(brandInfo);
info.name = brandInfo.brandName;
info.info = brandInfo.brandIntro;
info.btnName = '品牌介绍';
... ...
... ... @@ -23,6 +23,8 @@ router.post('/item/togglecollect', fav.product); // 商品详情页
router.get('/shop/:domain/list', shop.list);
router.get('/shop/:domain', shop.index);
router.post('/shop/togglecollect', fav.shop);
router.post('/brand/togglecollect', fav.brand);
router.get('/query', query.index);
... ...
{{# banner}}
<div class="brand-banner">
<div class="brand-banner" data-brand="{{brandId}}" data-shop="{{shopId}}">
<div class="brand-img" style="height:150px; background: url('{{image banner 1150 150}}')"></div>
<p class="opts">
<a id="brand-info">
... ...
... ... @@ -19,7 +19,7 @@ module.exports = {
},
cookieDomain: 'yohoblk.com',
domains: {
api: 'http://testapi.yoho.cn:28078/', // devapi.yoho.cn:58078 testapi.yoho.cn:28078 devapi.yoho.cn:58078
api: 'http://api.yoho.cn/', // devapi.yoho.cn:58078 testapi.yoho.cn:28078 devapi.yoho.cn:58078
service: 'http://testservice.yoho.cn:28077/', // testservice.yoho.cn:28077 devservice.yoho.cn:58077
search: 'http://192.168.102.216:8080/yohosearch/'
},
... ...
require('./list/list-search');
require('./list/favorite');
... ...
/**
* 品牌或店铺收藏
* @author: jiangfeng<jeff.jiang@yoho.cn>
* @date: 16/7/19
*/
function _favBack(data) {
if (data && data.code === 200) {
$('#brand-fav').toggleClass('coled');
}
}
function _favShop(shopId, isAdd) {
$.post('/product/shop/togglecollect', {shopId: shopId, type: isAdd ? '' : 'add'}, function(data) {
_favBack(data);
});
}
function _favBrand(brandId, isAdd) {
$.post('/product/brand/togglecollect', {brandId: brandId, type: isAdd ? '' : 'add'}, function(data) {
_favBack(data);
});
}
$('#brand-fav').click(function() {
var shopId = $(this).parents('.brand-banner').data('shop');
var brandId = $(this).parents('.brand-banner').data('brand');
var isAdd = $(this).hasClass('coled');
if (shopId) {
_favShop(shopId, isAdd);
} else if (brandId) {
_favBrand(brandId, isAdd);
}
});
... ...
... ... @@ -8,7 +8,7 @@ var Dialog = require('../plugins/dialog').Dialog;
var Shop = {
init: function() {
require('./list/list-search');
require('./list/favorite');
$('#brand-info').click(function() {
Shop.brandInfoDialog().show();
... ...
var lazyload = require('yoho-jquery-lazyload');
lazyload();
require('./list/favorite');
... ...
... ... @@ -28,6 +28,14 @@
display: inline-block;
}
.brand-info {
cursor: pointer;
}
.brand-fav {
cursor: pointer;
}
.iconfont {
font-size: 12px;
}
... ...
... ... @@ -20,11 +20,17 @@
border: 1px solid #fff;
padding: 10px;
margin-left: 10px;
cursor: pointer;
.iconfont {
font-size: 14px;
}
}
.brand-fav.coled .iconfont {
color: #000;
}
}
}
... ...