From dba601cf8b79aa8635bd47501f1c4a635583eaa2 Mon Sep 17 00:00:00 2001
From: yyq <kingcoon@163.com>
Date: Tue, 28 Jun 2016 18:20:49 +0800
Subject: [PATCH] 为你优选

---
 apps/product/controllers/detail.js                              |  11 +++++------
 apps/product/models/detail.js                                   |   6 ++----
 apps/product/models/preference.js                               |  38 +++++++++++++++++++++++++++++++++-----
 apps/product/views/action/detail/preference.hbs                 |   2 +-
 apps/product/views/partial/product/detail/recommend-content.hbs |  18 ++++++++++++++++++
 public/scss/product/detail/_comments-consults.css               | 200 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 public/scss/product/detail/_detail.css                          | 197 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 public/scss/product/detail/_recommend-for-you.css               |  15 ++++++---------
 8 files changed, 262 insertions(+), 225 deletions(-)
 create mode 100644 apps/product/views/partial/product/detail/recommend-content.hbs

diff --git a/apps/product/controllers/detail.js b/apps/product/controllers/detail.js
index 31b4408..324eb94 100644
--- a/apps/product/controllers/detail.js
+++ b/apps/product/controllers/detail.js
@@ -70,14 +70,13 @@ exports.intro = (req, res) => {
  */
 exports.preference = (req, res) => {
     preference({
-        productskn: req.params.productskn,
-        yhchannel: req.params.yhchannel,
-        brandId: req.params.brandId
+        productskn: req.query.productSkn,
+        yhchannel: 1,
+        brandId: req.query.brandId
     }).then((result) => {
-        res.render('detail/preference', {
-            result: result,
+        res.render('detail/preference', Object.assign({
             layout: false
-        });
+        }, result));
     });
 };
 
diff --git a/apps/product/models/detail.js b/apps/product/models/detail.js
index 0a32d3e..49a0847 100644
--- a/apps/product/models/detail.js
+++ b/apps/product/models/detail.js
@@ -288,11 +288,9 @@ const detailDataPkg = (origin, uid, vipLevel, ua) => {
 
     // 品牌信息
     if (origin.brand) {
+        let extra = `?productSkn=${origin.erpProductId}&brandId=${origin.brand.id}`;
 
-        dest.preferenceUrl = helpers.urlFormat('/product/detail/preference', {
-            productSkn: origin.erpProductId,
-            brandId: origin.brand.id
-        });
+        dest.preferenceUrl = `/product/detail/preference${extra}`;
     }
 
     dest.productSkn = origin.erpProductId;
diff --git a/apps/product/models/preference.js b/apps/product/models/preference.js
index d15d598..bb25015 100644
--- a/apps/product/models/preference.js
+++ b/apps/product/models/preference.js
@@ -7,12 +7,41 @@
 
 'use strict';
 const _ = require('lodash');
-const productProcess = require(`${global.utils}/product-process`);
 
 const api = global.yoho.API;
+const helpers = global.yoho.helpers;
+
+const _formatProduct = (data) => {
+    let list = [];
+
+    _.forEach(data, function(value) {
+        if (!value.product_skn || !value.goods_list || !value.goods_list.length) {
+            return;
+        }
+        value.goodsId = value.goods_list[0].goods_id;
+
+        let goods = {
+            salePrice: value.sales_price ? value.sales_price : '',
+            price: value.market_price ? value.market_price : '',
+            url: helpers.urlFormat(`/product/pro_${value.product_id}_${value.goodsId}/${value.cn_alphabet}.html`),
+            thumb: value.default_images,
+            name: value.product_name
+
+        };
+
+        // 市场价和售价一样,则不显示市场价
+        if (goods.salePrice === goods.price) {
+            goods.price = false;
+        }
+
+        list.push(goods);
+    });
+
+    return list;
+};
 
 module.exports = (data) => {
-    let finalResult;
+    let finalResult = {};
 
     return api.get('', {
         method: 'h5.preference.Search',
@@ -20,9 +49,8 @@ module.exports = (data) => {
         yhchannel: data.yhchannel,
         brandId: data.brandId
     }).then(result => {
-        if (!_.isEmpty(result) && result.code === 200) {
-            // 为你优选数据处理,接口没有数据,待处理,待验证
-            finalResult = productProcess.processProductList(result.data);
+        if (result) {
+            finalResult.recommendList = _formatProduct(result);
         }
 
         return finalResult;
diff --git a/apps/product/views/action/detail/preference.hbs b/apps/product/views/action/detail/preference.hbs
index 6865054..5a9ae33 100644
--- a/apps/product/views/action/detail/preference.hbs
+++ b/apps/product/views/action/detail/preference.hbs
@@ -1 +1 @@
-{{> product/detail/recommend-for-you}}
\ No newline at end of file
+{{> product/detail/recommend-content}}
\ No newline at end of file
diff --git a/apps/product/views/partial/product/detail/recommend-content.hbs b/apps/product/views/partial/product/detail/recommend-content.hbs
new file mode 100644
index 0000000..4834885
--- /dev/null
+++ b/apps/product/views/partial/product/detail/recommend-content.hbs
@@ -0,0 +1,18 @@
+<div class="title">为您优选新品</div>
+<div id="swiper-recommend" class="swiper-container">
+    <div class="swiper-wrapper swiper-wrapper-recommend">
+        {{# recommendList}}
+        <a class="swiper-slide" href="{{url}}">
+            <img class="swiper-lazy img-box" data-src="{{image thumb 299 388}}">
+            <div class="sale-name">
+               {{name}}
+            </div>
+            <div class="price">
+                <span class="sale-price {{^price}}no-price{{/price}}">¥{{salePrice}}</span>
+                {{#price}}<span class="old-price">¥{{.}}</span>{{/price}}
+            </div>
+            <div class="swiper-lazy-preloader"></div>
+        </a>
+        {{/ recommendList}}
+    </div>
+</div>
\ No newline at end of file
diff --git a/public/scss/product/detail/_comments-consults.css b/public/scss/product/detail/_comments-consults.css
index f373412..e4614fe 100644
--- a/public/scss/product/detail/_comments-consults.css
+++ b/public/scss/product/detail/_comments-consults.css
@@ -256,203 +256,3 @@
         margin-top: 20px;
     }
 }
-
-.good-detail-page {
-    .feedback-list {
-        padding-top: 30px;
-        margin-bottom: 30px;
-        background-color: #f0f0f0;
-
-        .nav-tab {
-            width: 100%;
-            height: 60px;
-            padding: 10px 0;
-            background-color: #fff;
-            border-top: 1px solid $borderC;
-            border-bottom: 1px solid $borderC;
-        }
-
-        .comment-nav,
-        .consult-nav {
-            box-sizing: border-box;
-            float: left;
-            width: 50%;
-            height: 60px;
-            line-height: 60px;
-            font-size: 28px;
-            text-align: center;
-            color: $subFontC;
-
-            &.focus {
-                color: #000;
-            }
-        }
-
-        .comment-nav {
-            border-right: 1px solid #ccc;
-        }
-
-        .content-main {
-            background-color: #fff;
-            border-bottom: 1px solid $borderC;
-        }
-
-        .content-main.comment-content-main {
-            .user-name {
-                font-size: 24px;
-                line-height: 62px;
-                color: $mainFontC;
-                padding-left: 28px;
-                padding-right: 18px;
-            }
-
-            .goods-spec,
-            .comment-time {
-                font-size: 24px;
-                line-height: 62px;
-            }
-
-            .detail-content {
-                font-size: 24px;
-                line-height: 62px;
-                color: $mainFontC;
-                padding-left: 28px;
-                padding-right: 18px;
-            }
-
-            .goods-spec,
-            .comment-time {
-                font-size: 24px;
-                line-height: 62px;
-            }
-
-            .detail-content {
-                font-size: 28px;
-                line-height: 36px;
-            }
-
-            .goods-spec,
-            .detail-content {
-                color: $mainFontC;
-            }
-
-            .detail-content,
-            .comment-time {
-                padding-left: 28px;
-            }
-
-            .detail-content {
-                padding-right: 28px;
-                padding-left: 28px;
-            }
-
-            .detail-content {
-                padding-right: 28px;
-            }
-
-            .comment-time {
-                color: #c1c1c1;
-            }
-        }
-
-        .content-main.consult-content-main {
-            padding-right: 28px;
-            padding-left: 28px;
-            padding-top: 20px;
-            padding-bottom: 20px;
-
-            .question {
-                font-size: 24px;
-                color: $mainFontC;
-
-                span {
-                    display: block;
-                    float: left;
-                    font-size: inherit;
-                    padding-right: 15px;
-                }
-
-                p {
-                    overflow: hidden;
-                }
-            }
-
-            .time {
-                font-size: 22px;
-                color: $subFontC;
-            }
-
-            .answer {
-                font-size: 24px;
-                line-height: 36px;
-                color: $subFontC;
-                margin-top: 14px;
-
-                span {
-                    display: block;
-                    float: left;
-                    font-size: inherit;
-                    color: $mainFontC;
-                    padding-right: 15px;
-                }
-
-                p {
-                    overflow: hidden;
-                }
-            }
-        }
-
-        .content-main.no-item {
-            height: 200px;
-            line-height: 200px;
-            color: #e0e0e0;
-            font-size: 16PX;
-            text-align: center;
-
-            span {
-                display: inline-block;
-                font-size: 16PX;
-                padding-right: 5PX;
-            }
-        }
-
-        .comment-content-footer,
-        .consult-content-footer {
-            display: block;
-            min-height: 88px;
-            text-align: center;
-            background-color: #fff;
-            border-bottom: 1px solid $borderC;
-            line-height: 88px;
-            font-size: 28px;
-            color: #b0b0b0;
-
-            .iconfont {
-                font-size: inherit;
-            }
-        }
-
-        .content.hide {
-            display: none;
-        }
-
-        .nodata {
-            height: 88px;
-            font-size: 28px;
-            line-height: 88px;
-            background-color: #fff;
-            padding: 0 28px;
-            border-top: 1px solid $borderC;
-            border-bottom: 1px solid $borderC;
-
-            .go-consult {
-                float: right;
-                color: $subFontC;
-
-                span {
-                    font-size: 28px;
-                }
-            }
-        }
-    }
-}
diff --git a/public/scss/product/detail/_detail.css b/public/scss/product/detail/_detail.css
index 6b350ef..eacd573 100644
--- a/public/scss/product/detail/_detail.css
+++ b/public/scss/product/detail/_detail.css
@@ -490,6 +490,203 @@ $basicBtnC: #eb0313;
         }
     }
 
+    .feedback-list {
+        padding-top: 30px;
+        margin-bottom: 30px;
+        background-color: #f0f0f0;
+
+        .nav-tab {
+            width: 100%;
+            padding: 10px 0;
+            background-color: #fff;
+            border-top: 1px solid $borderC;
+            border-bottom: 1px solid $borderC;
+        }
+
+        .comment-nav,
+        .consult-nav {
+            box-sizing: border-box;
+            float: left;
+            width: 50%;
+            height: 60px;
+            line-height: 60px;
+            font-size: 28px;
+            text-align: center;
+            color: $subFontC;
+
+            &.focus {
+                color: #000;
+            }
+        }
+
+        .comment-nav {
+            border-right: 1px solid #ccc;
+        }
+
+        .content-main {
+            background-color: #fff;
+            border-bottom: 1px solid $borderC;
+        }
+
+        .content-main.comment-content-main {
+            .user-name {
+                font-size: 24px;
+                line-height: 62px;
+                color: $mainFontC;
+                padding-left: 28px;
+                padding-right: 18px;
+            }
+
+            .goods-spec,
+            .comment-time {
+                font-size: 24px;
+                line-height: 62px;
+            }
+
+            .detail-content {
+                font-size: 24px;
+                line-height: 62px;
+                color: $mainFontC;
+                padding-left: 28px;
+                padding-right: 18px;
+            }
+
+            .goods-spec,
+            .comment-time {
+                font-size: 24px;
+                line-height: 62px;
+            }
+
+            .detail-content {
+                font-size: 28px;
+                line-height: 36px;
+            }
+
+            .goods-spec,
+            .detail-content {
+                color: $mainFontC;
+            }
+
+            .detail-content,
+            .comment-time {
+                padding-left: 28px;
+            }
+
+            .detail-content {
+                padding-right: 28px;
+                padding-left: 28px;
+            }
+
+            .detail-content {
+                padding-right: 28px;
+            }
+
+            .comment-time {
+                color: #c1c1c1;
+            }
+        }
+
+        .content-main.consult-content-main {
+            padding-right: 28px;
+            padding-left: 28px;
+            padding-top: 20px;
+            padding-bottom: 20px;
+
+            .question {
+                font-size: 24px;
+                color: $mainFontC;
+
+                span {
+                    display: block;
+                    float: left;
+                    font-size: inherit;
+                    padding-right: 15px;
+                }
+
+                p {
+                    overflow: hidden;
+                }
+            }
+
+            .time {
+                font-size: 22px;
+                color: $subFontC;
+            }
+
+            .answer {
+                font-size: 24px;
+                line-height: 36px;
+                color: $subFontC;
+                margin-top: 14px;
+
+                span {
+                    display: block;
+                    float: left;
+                    font-size: inherit;
+                    color: $mainFontC;
+                    padding-right: 15px;
+                }
+
+                p {
+                    overflow: hidden;
+                }
+            }
+        }
+
+        .content-main.no-item {
+            height: 200px;
+            line-height: 200px;
+            color: #e0e0e0;
+            font-size: 16PX;
+            text-align: center;
+
+            span {
+                display: inline-block;
+                font-size: 16PX;
+                padding-right: 5PX;
+            }
+        }
+
+        .comment-content-footer,
+        .consult-content-footer {
+            display: block;
+            min-height: 88px;
+            text-align: center;
+            background-color: #fff;
+            border-bottom: 1px solid $borderC;
+            line-height: 88px;
+            font-size: 28px;
+            color: #b0b0b0;
+
+            .iconfont {
+                font-size: inherit;
+            }
+        }
+
+        .content.hide {
+            display: none;
+        }
+
+        .nodata {
+            height: 88px;
+            font-size: 28px;
+            line-height: 88px;
+            background-color: #fff;
+            padding: 0 28px;
+            border-top: 1px solid $borderC;
+            border-bottom: 1px solid $borderC;
+
+            .go-consult {
+                float: right;
+                color: $subFontC;
+
+                span {
+                    font-size: 28px;
+                }
+            }
+        }
+    }
+
     /*
     底部固定栏
      */
diff --git a/public/scss/product/detail/_recommend-for-you.css b/public/scss/product/detail/_recommend-for-you.css
index cba6be1..e551684 100644
--- a/public/scss/product/detail/_recommend-for-you.css
+++ b/public/scss/product/detail/_recommend-for-you.css
@@ -3,6 +3,7 @@
     border-top: 1px solid #e0e0e0;
     border-bottom: 1px solid #e0e0e0;
     background: #fff;
+    font-size: 12px;
 
     .title {
         color: #444;
@@ -15,19 +16,15 @@
         padding: 30px 0 20px;
         width: 100%;
 
+        .swiper-wrapper {
+            padding: 0 30px;
+        }
+
         .swiper-slide {
             float: left;
-            padding: 0 10px;
+            margin: 0 10px;
             width: 156px;
 
-            &:first-child {
-                padding-left: 30px;
-            }
-
-            &:last-child {
-                padding-right: 30px;
-            }
-
             img {
                 width: 100%;
                 height: 208px;
--
libgit2 0.24.0