Showing
8 changed files
with
268 additions
and
3 deletions
@@ -108,6 +108,6 @@ | @@ -108,6 +108,6 @@ | ||
108 | <div class="toper"> | 108 | <div class="toper"> |
109 | <div class="title">为你优选</div> | 109 | <div class="title">为你优选</div> |
110 | </div> | 110 | </div> |
111 | - <div class="container"></div> | 111 | + <div class="container clearfix"></div> |
112 | </div> | 112 | </div> |
113 | </div> | 113 | </div> |
apps/product/controllers/new-recommend.js
0 → 100644
1 | +'use strict'; | ||
2 | + | ||
3 | +const newRecommendModel = require('../models/new-recommend'); | ||
4 | + | ||
5 | +exports.getRecommend = (req, res, next) => { | ||
6 | + let params = { | ||
7 | + yh_channel: req.query.yh_channel || '1', | ||
8 | + udid: req.sessionID, | ||
9 | + limit: 10, | ||
10 | + rec_pos: '100004', | ||
11 | + uid: req.user.uid || 0, | ||
12 | + client_id: req.cookies._yasvd || '', | ||
13 | + page: req.query.page || 1 | ||
14 | + }; | ||
15 | + | ||
16 | + req.ctx(newRecommendModel).getRecommend(params).then(result => { | ||
17 | + res.json(result); | ||
18 | + }).catch(next); | ||
19 | +}; |
apps/product/models/new-recommend.js
0 → 100644
1 | +'use strict'; | ||
2 | + | ||
3 | +const helpers = global.yoho.helpers; | ||
4 | +const _ = require('lodash'); | ||
5 | +const utils = '../../../utils'; | ||
6 | +const productNameProcess = require(`${utils}/product-name-process`); | ||
7 | + | ||
8 | +class storeHome extends global.yoho.BaseModel { | ||
9 | + constructor(ctx) { | ||
10 | + super(ctx); | ||
11 | + } | ||
12 | + | ||
13 | + getPreferenceData(data) { | ||
14 | + let dest = { | ||
15 | + goods: [] | ||
16 | + }; | ||
17 | + | ||
18 | + let list = data.data || {}; | ||
19 | + | ||
20 | + _.forEach(list && list.product_list, value => { | ||
21 | + | ||
22 | + if (!value.product_skn || !value.goods_list || !value.goods_list.length) { | ||
23 | + return; | ||
24 | + } | ||
25 | + value.goodsId = value.goods_list && value.goods_list[0] && value.goods_list[0].goods_id; | ||
26 | + | ||
27 | + if (value.cn_alphabet) { | ||
28 | + value.cn_alphabet = productNameProcess(value.cn_alphabet); | ||
29 | + } | ||
30 | + | ||
31 | + let goods = { | ||
32 | + product_skn: value.product_skn, | ||
33 | + product_name: value.product_name, | ||
34 | + default_images: value.default_images, | ||
35 | + is_soon_sold_out: value.is_soon_sold_out === 'Y', | ||
36 | + url: helpers.urlFormat(`/product/${value.product_skn}.html`), // 商品url改版 | ||
37 | + market_price: value.market_price === value.sales_price ? false : value.market_price, | ||
38 | + sales_price: value.sales_price | ||
39 | + }; | ||
40 | + | ||
41 | + let tags = {}; | ||
42 | + | ||
43 | + _.forEach(value.tags, tag => { | ||
44 | + tags[tag] = true; | ||
45 | + }); | ||
46 | + | ||
47 | + goods.tags = tags; | ||
48 | + goods.similar = true; | ||
49 | + | ||
50 | + if (tags.is_solded === true) { | ||
51 | + goods.is_solded = true; | ||
52 | + } | ||
53 | + | ||
54 | + dest.goods.push(goods); | ||
55 | + }); | ||
56 | + | ||
57 | + | ||
58 | + | ||
59 | + dest.code = data.code; | ||
60 | + dest.rec_id = list.rec_id; | ||
61 | + dest.message = data.message; | ||
62 | + | ||
63 | + return dest; | ||
64 | + } | ||
65 | + | ||
66 | + getRecommend(params) { | ||
67 | + let options = { | ||
68 | + data: { | ||
69 | + method: 'app.home.newPreference', | ||
70 | + yh_channel: params.yh_channel, | ||
71 | + udid: params.udid, | ||
72 | + limit: params.limit, | ||
73 | + rec_pos: params.rec_pos, | ||
74 | + uid: params.uid, | ||
75 | + client_id: params.client_id, | ||
76 | + page: params.page | ||
77 | + } | ||
78 | + }; | ||
79 | + | ||
80 | + return this.get(options).then(result => { | ||
81 | + return this.getPreferenceData(result); | ||
82 | + }); | ||
83 | + } | ||
84 | +} | ||
85 | + | ||
86 | +module.exports = storeHome; |
@@ -59,6 +59,8 @@ const globalPro = require(`${cRoot}/global`); | @@ -59,6 +59,8 @@ const globalPro = require(`${cRoot}/global`); | ||
59 | // 找相似 | 59 | // 找相似 |
60 | const similar = require(`${cRoot}/similar`); | 60 | const similar = require(`${cRoot}/similar`); |
61 | 61 | ||
62 | +const newRecommend = require(`${cRoot}/new-recommend`); | ||
63 | + | ||
62 | // routers | 64 | // routers |
63 | 65 | ||
64 | // /pro_136349_455445/HEARTSOFARMianMaShuJiaoXiuXianKuPS1684.html | 66 | // /pro_136349_455445/HEARTSOFARMianMaShuJiaoXiuXianKuPS1684.html |
@@ -217,4 +219,6 @@ router.get('/global/gethtml', globalPro.gethtml); // 全球购商品信息 | @@ -217,4 +219,6 @@ router.get('/global/gethtml', globalPro.gethtml); // 全球购商品信息 | ||
217 | 219 | ||
218 | router.get('/similar', similar.index); // 找相似 | 220 | router.get('/similar', similar.index); // 找相似 |
219 | 221 | ||
222 | +router.get('/new-recommend/getRecommend', newRecommend.getRecommend); // 新为你优选 | ||
223 | + | ||
220 | module.exports = router; | 224 | module.exports = router; |
public/hbs/product/new-recommend/goods.hbs
0 → 100644
1 | +{{#if this}} {{!-- 剔除值为false的项 --}} | ||
2 | + {{# goods}} | ||
3 | + <div class="good-info {{#if @root.sale_vip_login}}sale-vip{{/if}}" data-good-id="{{product_id}}" | ||
4 | + data-id="{{product_skn}}" data-bp-id="guang_goodList_{{product_name}}_false"> | ||
5 | + <div class="tag-container clearfix"> | ||
6 | + {{# tags}} | ||
7 | + {{# is_new}} | ||
8 | + <p class="good-tag new-tag">NEW</p> | ||
9 | + {{/ is_new}} | ||
10 | + {{# is_hot}} | ||
11 | + <p class="good-tag hot-tag">HOT</p> | ||
12 | + {{/ is_hot}} | ||
13 | + {{# is_advance}} | ||
14 | + <p class="good-tag renew-tag">再到着</p> | ||
15 | + {{/ is_advance}} | ||
16 | + {{# is_discount}} | ||
17 | + <p class="good-tag sale-tag">SALE</p> | ||
18 | + {{/ is_discount}} | ||
19 | + {{# is_yohood}} | ||
20 | + <p class="good-tag new-festival-tag">新品节</p> | ||
21 | + {{/ is_yohood}} | ||
22 | + {{# is_limited}} | ||
23 | + <p class="good-tag limit-tag">限量</p> | ||
24 | + {{/ is_limited}} | ||
25 | + {{# is_presell}} | ||
26 | + <p class="good-tag is-presell">预售</p> | ||
27 | + {{/ is_presell}} | ||
28 | + {{# is_global}} | ||
29 | + <p class="good-tag is-global"> | ||
30 | + <span>{{../tbl_country_name}}</span> | ||
31 | + </p> | ||
32 | + {{/ is_global}} | ||
33 | + {{/ tags}} | ||
34 | + </div> | ||
35 | + <div class="good-detail-img"> | ||
36 | + <a class="good-thumb" href="{{url}}"> | ||
37 | + {{#if @root._noLazy}} | ||
38 | + <img src="{{image2 default_images w=235 h=314 q=60}}"/> | ||
39 | + {{else}} | ||
40 | + <img class="lazy" data-original="{{image2 default_images w=235 h=314 q=60}}"/> | ||
41 | + {{/if}} | ||
42 | + </a> | ||
43 | + {{# is_soon_sold_out}} | ||
44 | + <p class="few-tag">即将售罄</p> | ||
45 | + {{/ is_soon_sold_out}} | ||
46 | + | ||
47 | + {{# is_solded}} | ||
48 | + <p class="out-tag">已售罄</p> | ||
49 | + {{/ is_solded}} | ||
50 | + | ||
51 | + {{!-- {{# noStorage}} | ||
52 | + <div class="no-storage"> | ||
53 | + <div class="no-storage-img"></div> | ||
54 | + </div> | ||
55 | + {{/ noStorage}} --}} | ||
56 | + {{#if similar}} | ||
57 | + {{> common/similar}} | ||
58 | + {{/if}} | ||
59 | + </div> | ||
60 | + <div class="good-detail-text"> | ||
61 | + <div class="name"> | ||
62 | + <a href="{{url}}">{{product_name}}</a> | ||
63 | + </div> | ||
64 | + <div class="price"> | ||
65 | + {{#if @root.saleViplogin}} | ||
66 | + <i class="vip-grade vip-grade-{{@root.vipLevel}}"></i> | ||
67 | + <span class="sale-price {{^market_price}}no-price{{/market_price}}">¥ | ||
68 | + {{#if @root.vipPrice1}}{{round vip1_price}}{{/if}} | ||
69 | + {{#if @root.vipPrice2}}{{round vip2_price}}{{/if}} | ||
70 | + {{#if @root.vipPrice3}}{{round vip3_price}}{{/if}} | ||
71 | + </span> | ||
72 | + {{else}} | ||
73 | + <span class="sale-price {{^market_price}}no-price{{/market_price}}">¥{{round sales_price}}</span> | ||
74 | + {{/if}} | ||
75 | + {{#market_price}} | ||
76 | + <span class="market-price">¥{{round .}}</span> | ||
77 | + {{/market_price}} | ||
78 | + </div> | ||
79 | + {{#if @root.saleVip}} | ||
80 | + <div class="vip-info"> | ||
81 | + <i class="vip-icon"></i>更优惠 | ||
82 | + </div> | ||
83 | + {{/if}} | ||
84 | + {{#if similar}} | ||
85 | + <a class="similar-btn iconfont"></a> | ||
86 | + {{/if}} | ||
87 | + </div> | ||
88 | + </div> | ||
89 | + {{/ goods}} | ||
90 | +{{/if}} |
1 | +import 'product/new-recommend/new-recommend.css'; | ||
2 | +import $ from 'yoho-jquery'; | ||
3 | +import Page from 'yoho-page'; | ||
4 | +import goodsRender from 'product/new-recommend/goods.hbs'; | ||
5 | +import tip from 'plugin/tip'; | ||
6 | +import lazyLoad from 'yoho-jquery-lazyload'; | ||
7 | + | ||
8 | +class NewRecommend extends Page { | ||
9 | + constructor() { | ||
10 | + super(); | ||
11 | + | ||
12 | + this.selector = { | ||
13 | + $goodsContainer: $('#new-recommend-c').find('.container') | ||
14 | + }; | ||
15 | + | ||
16 | + this.view = { | ||
17 | + goodsRender | ||
18 | + }; | ||
19 | + | ||
20 | + this.init(); | ||
21 | + this.page = 1; | ||
22 | + } | ||
23 | + | ||
24 | + init() { | ||
25 | + this.getRecommend(); | ||
26 | + } | ||
27 | + | ||
28 | + moreGoods() { | ||
29 | + this.page++; | ||
30 | + this.getRecommend(); | ||
31 | + } | ||
32 | + | ||
33 | + getRecommend() { | ||
34 | + this.ajax({ | ||
35 | + url: '/product/new-recommend/getRecommend', | ||
36 | + data: { | ||
37 | + page: this.page | ||
38 | + } | ||
39 | + }).then((result) => { | ||
40 | + if (result) { | ||
41 | + if (result.goods.length > 0) { | ||
42 | + let goodsData = { | ||
43 | + goods: result.goods | ||
44 | + }; | ||
45 | + let $goodsData = $(this.view.goodsRender(goodsData)); | ||
46 | + | ||
47 | + this.selector.$goodsContainer.append($goodsData); | ||
48 | + lazyLoad($goodsData.find('img.lazy')); | ||
49 | + } else { | ||
50 | + tip.show('没有更多了~~'); | ||
51 | + } | ||
52 | + } | ||
53 | + }).catch(error => { | ||
54 | + console.error(error); | ||
55 | + }); | ||
56 | + } | ||
57 | +} | ||
58 | + | ||
59 | +$(() => { | ||
60 | + new NewRecommend(); | ||
61 | +}); |
1 | +@import "common/good"; | ||
2 | + | ||
1 | #new-recommend-c { | 3 | #new-recommend-c { |
2 | width: 750px; | 4 | width: 750px; |
3 | background-color: #fff; | 5 | background-color: #fff; |
4 | - padding-bottom: 80px; | ||
5 | 6 | ||
6 | .toper { | 7 | .toper { |
7 | padding: 24px 30px; | 8 | padding: 24px 30px; |
@@ -16,4 +17,8 @@ | @@ -16,4 +17,8 @@ | ||
16 | border-left: solid 4px #444; | 17 | border-left: solid 4px #444; |
17 | } | 18 | } |
18 | } | 19 | } |
20 | + | ||
21 | + .container { | ||
22 | + padding-left: 15px; | ||
23 | + } | ||
19 | } | 24 | } |
-
Please register or login to post a comment