Authored by 王水玲

Merge branch 'aaa' into feature/wsl5.3

/**
* 推荐商品(店铺推荐|为您优选|最近浏览)controller
* @author: wsl<shuiling.wang@yoho.cn>
* @date: 2016/11/21
*/
'use strict';
const _ = require('lodash');
const recommend = require('../models/recommend');
const getRecommendProduct = (req, res, next) => {
recommend.getRecommendProduct().then((result) => {
res.json(result);
});
};
module.exports = {
getRecommendProduct
};
... ...
/**
* 推荐商品(店铺推荐|为您优选|最近浏览)model
* @author: wsl<shuiling.wang@yoho.cn>
* @date: 2016/11/21
*/
'use strict';
const _ = require('lodash');
const api = global.yoho.API;
const logger = global.yoho.logger;
const getRecommendProduct = (params) => {
params = {
yh_channel: 4,
udid: '0f528764d624db129b32c21fbca0cb8d6',
limit: 5,
rec_pos: 100003
};
return api.get('app.home.newPreference', params).then((data) => {
if (data.code === 200 && data.data.length > 0) {
console.log(data);
return data.data;
} else {
logger.error('get recommend product data code is not 200');
return [];
}
});
};
module.exports = {
getRecommendProduct
};
... ...
... ... @@ -14,6 +14,7 @@ const item = require(cRoot + '/item');
const fav = require(cRoot + '/favorite');
const shop = require(cRoot + '/shop');
const query = require(cRoot + '/query');
const recommend = require(cRoot + '/recommend');
// Your controller here
router.get('/list', list.index); // 列表页面
... ... @@ -31,4 +32,6 @@ router.post('/brand/togglecollect', auth, fav.brand);
router.get('/query', query.index);
router.get('/getRecommendProduct', recommend.getRecommendProduct);
module.exports = router;
... ...
... ... @@ -301,6 +301,7 @@
</div>
{{/ details}}
</div>
<div class="recommend-product"></div>
</div>
{{/ content}}
</div>
... ...
... ... @@ -8,7 +8,8 @@ var $ = require('yoho-jquery'),
handlebars = require('yoho-handlebars'),
lazyload = require('yoho-jquery-lazyload'),
Dialog = require('../plugins/dialog').Dialog,
regx = require('../passport/common/mail-phone-regx').phoneRegx;
regx = require('../passport/common/mail-phone-regx').phoneRegx,
recProduct = require('./item/recommend-product');
var $main = $('.product-main'),
$mainThumb = $('#main-thumb'),
... ... @@ -47,6 +48,11 @@ require('../plugins/share');
lazyload($('img.lazy'));
recProduct.init({
dom: '.recommend-product',
isGoodsDetail: true
});
function changeThumb($dom) {
var data;
... ...
/**
* 为您优选 | 店铺推荐 | 最近浏览
* @author: wsl<shuiling.wang@yoho.cn>
* @date: 2016/11/21
*/
var recProduct = require('../../../tpl/product/recommend-product.hbs');
var recTemplet = require('../../../tpl/product/recommend-templet.hbs');
var recommmendProduct = {
init: function(params) {
var _this = this;
var obj = {
isGoodsDetail: false
};
if (params.isGoodsDetail) {
obj.isGoodsDetail = true;
}
$(params.dom).append(recTemplet(obj));
_this.getRecommendProduct({
page: 1,
dom: params.dom
});
},
getRecommendProduct: function(params) {
$.get('/product/getRecommendProduct', {
page: params.page
}, function(data) {
if (data) {
$(params.dom).find('.goods-area').html(recProduct(data));
}
});
}
};
module.exports = recommmendProduct;
... ...
... ... @@ -478,6 +478,55 @@
}
}
.recommend-product {
width: 100%;
margin-bottom: 55px;
.recommend-header {
height: 40px;
border-bottom: 1px solid #ddd;
}
.head-tab {
width: 140px;
height:40px;
line-height: 42px;
font-size: 14px;
text-align: center;
float: left;
cursor: pointer;
&.active {
font-weight: bold;
border: 1px solid #ddd;
border-bottom-color: #fff;
box-sizing: border-box;
}
}
.change-btn {
float: right;
font-size: 14px;
font-weight: bold;
line-height: 42px;
.iconfont {
font-size: 18px;
position: relative;
top: 2px;
margin-left: 5px;
}
}
.product-area {
img {
width: 214px;
height: 288px;
background: #f5f7f6;
}
}
}
.info-block {
border: 1px solid #f3f3f3;
padding: 40px 130px;
... ...
{{#each products}}
<div class="goods" data-id="{{productId}}" data-url="{{url}}">
<div class="goods-img">
<a href="{{https url}}" target="_blank">
<img class="lazy" data-original="{{image defaultImages 263 351}}" width="263" height="351" alt="">
</a>
</div>
<div class="goods-brand">{{brandName}}</div>
<div class="goods-name">{{productName}}</div>
<div class="goods-price">
<span>¥{{round salesPrice}}</span>
</div>
</div>
{{/each}}
... ...
<div class="recommend-header">
<span class="head-tab active">{{#if isGoodsDetail}}店铺推荐{{else}}为您优选{{/if}}</span>
<span class="head-tab">最近浏览</span>
<span class="change-btn">换一批<i class="iconfont">&#xe613;</i></span>
</div>
<div class="goods-area clearfix"></div>
... ...