Authored by 李靖

为你优选

... ... @@ -108,6 +108,6 @@
<div class="toper">
<div class="title">为你优选</div>
</div>
<div class="container"></div>
<div class="container clearfix"></div>
</div>
</div>
\ No newline at end of file
... ...
'use strict';
const newRecommendModel = require('../models/new-recommend');
exports.getRecommend = (req, res, next) => {
let params = {
yh_channel: req.query.yh_channel || '1',
udid: req.sessionID,
limit: 10,
rec_pos: '100004',
uid: req.user.uid || 0,
client_id: req.cookies._yasvd || '',
page: req.query.page || 1
};
req.ctx(newRecommendModel).getRecommend(params).then(result => {
res.json(result);
}).catch(next);
};
\ No newline at end of file
... ...
'use strict';
const helpers = global.yoho.helpers;
const _ = require('lodash');
const utils = '../../../utils';
const productNameProcess = require(`${utils}/product-name-process`);
class storeHome extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
getPreferenceData(data) {
let dest = {
goods: []
};
let list = data.data || {};
_.forEach(list && list.product_list, value => {
if (!value.product_skn || !value.goods_list || !value.goods_list.length) {
return;
}
value.goodsId = value.goods_list && value.goods_list[0] && value.goods_list[0].goods_id;
if (value.cn_alphabet) {
value.cn_alphabet = productNameProcess(value.cn_alphabet);
}
let goods = {
product_skn: value.product_skn,
product_name: value.product_name,
default_images: value.default_images,
is_soon_sold_out: value.is_soon_sold_out === 'Y',
url: helpers.urlFormat(`/product/${value.product_skn}.html`), // 商品url改版
market_price: value.market_price === value.sales_price ? false : value.market_price,
sales_price: value.sales_price
};
let tags = {};
_.forEach(value.tags, tag => {
tags[tag] = true;
});
goods.tags = tags;
goods.similar = true;
if (tags.is_solded === true) {
goods.is_solded = true;
}
dest.goods.push(goods);
});
dest.code = data.code;
dest.rec_id = list.rec_id;
dest.message = data.message;
return dest;
}
getRecommend(params) {
let options = {
data: {
method: 'app.home.newPreference',
yh_channel: params.yh_channel,
udid: params.udid,
limit: params.limit,
rec_pos: params.rec_pos,
uid: params.uid,
client_id: params.client_id,
page: params.page
}
};
return this.get(options).then(result => {
return this.getPreferenceData(result);
});
}
}
module.exports = storeHome;
... ...
... ... @@ -59,6 +59,8 @@ const globalPro = require(`${cRoot}/global`);
// 找相似
const similar = require(`${cRoot}/similar`);
const newRecommend = require(`${cRoot}/new-recommend`);
// routers
// /pro_136349_455445/HEARTSOFARMianMaShuJiaoXiuXianKuPS1684.html
... ... @@ -217,4 +219,6 @@ router.get('/global/gethtml', globalPro.gethtml); // 全球购商品信息
router.get('/similar', similar.index); // 找相似
router.get('/new-recommend/getRecommend', newRecommend.getRecommend); // 新为你优选
module.exports = router;
... ...
{{#if this}} {{!-- 剔除值为false的项 --}}
{{# goods}}
<div class="good-info {{#if @root.sale_vip_login}}sale-vip{{/if}}" data-good-id="{{product_id}}"
data-id="{{product_skn}}" data-bp-id="guang_goodList_{{product_name}}_false">
<div class="tag-container clearfix">
{{# tags}}
{{# is_new}}
<p class="good-tag new-tag">NEW</p>
{{/ is_new}}
{{# is_hot}}
<p class="good-tag hot-tag">HOT</p>
{{/ is_hot}}
{{# is_advance}}
<p class="good-tag renew-tag">再到着</p>
{{/ is_advance}}
{{# is_discount}}
<p class="good-tag sale-tag">SALE</p>
{{/ is_discount}}
{{# is_yohood}}
<p class="good-tag new-festival-tag">新品节</p>
{{/ is_yohood}}
{{# is_limited}}
<p class="good-tag limit-tag">限量</p>
{{/ is_limited}}
{{# is_presell}}
<p class="good-tag is-presell">预售</p>
{{/ is_presell}}
{{# is_global}}
<p class="good-tag is-global">
<span>{{../tbl_country_name}}</span>
</p>
{{/ is_global}}
{{/ tags}}
</div>
<div class="good-detail-img">
<a class="good-thumb" href="{{url}}">
{{#if @root._noLazy}}
<img src="{{image2 default_images w=235 h=314 q=60}}"/>
{{else}}
<img class="lazy" data-original="{{image2 default_images w=235 h=314 q=60}}"/>
{{/if}}
</a>
{{# is_soon_sold_out}}
<p class="few-tag">即将售罄</p>
{{/ is_soon_sold_out}}
{{# is_solded}}
<p class="out-tag">已售罄</p>
{{/ is_solded}}
{{!-- {{# noStorage}}
<div class="no-storage">
<div class="no-storage-img"></div>
</div>
{{/ noStorage}} --}}
{{#if similar}}
{{> common/similar}}
{{/if}}
</div>
<div class="good-detail-text">
<div class="name">
<a href="{{url}}">{{product_name}}</a>
</div>
<div class="price">
{{#if @root.saleViplogin}}
<i class="vip-grade vip-grade-{{@root.vipLevel}}"></i>
<span class="sale-price {{^market_price}}no-price{{/market_price}}">¥
{{#if @root.vipPrice1}}{{round vip1_price}}{{/if}}
{{#if @root.vipPrice2}}{{round vip2_price}}{{/if}}
{{#if @root.vipPrice3}}{{round vip3_price}}{{/if}}
</span>
{{else}}
<span class="sale-price {{^market_price}}no-price{{/market_price}}">¥{{round sales_price}}</span>
{{/if}}
{{#market_price}}
<span class="market-price">¥{{round .}}</span>
{{/market_price}}
</div>
{{#if @root.saleVip}}
<div class="vip-info">
<i class="vip-icon"></i>更优惠
</div>
{{/if}}
{{#if similar}}
<a class="similar-btn iconfont">&#xe606;</a>
{{/if}}
</div>
</div>
{{/ goods}}
{{/if}}
... ...
import 'home/new-home.page.css';
import 'product/new-recommend.css';
import 'product/new-recommend/new-recommend';
import $ from 'yoho-jquery';
import Page from 'yoho-page';
... ...
import 'product/new-recommend/new-recommend.css';
import $ from 'yoho-jquery';
import Page from 'yoho-page';
import goodsRender from 'product/new-recommend/goods.hbs';
import tip from 'plugin/tip';
import lazyLoad from 'yoho-jquery-lazyload';
class NewRecommend extends Page {
constructor() {
super();
this.selector = {
$goodsContainer: $('#new-recommend-c').find('.container')
};
this.view = {
goodsRender
};
this.init();
this.page = 1;
}
init() {
this.getRecommend();
}
moreGoods() {
this.page++;
this.getRecommend();
}
getRecommend() {
this.ajax({
url: '/product/new-recommend/getRecommend',
data: {
page: this.page
}
}).then((result) => {
if (result) {
if (result.goods.length > 0) {
let goodsData = {
goods: result.goods
};
let $goodsData = $(this.view.goodsRender(goodsData));
this.selector.$goodsContainer.append($goodsData);
lazyLoad($goodsData.find('img.lazy'));
} else {
tip.show('没有更多了~~');
}
}
}).catch(error => {
console.error(error);
});
}
}
$(() => {
new NewRecommend();
});
... ...
@import "common/good";
#new-recommend-c {
width: 750px;
background-color: #fff;
padding-bottom: 80px;
.toper {
padding: 24px 30px;
... ... @@ -16,4 +17,8 @@
border-left: solid 4px #444;
}
}
.container {
padding-left: 15px;
}
}
... ...