Authored by 郭成尧

bundle-add

... ... @@ -4,6 +4,8 @@
'use strict';
const _ = require('lodash');
const commentModel = require('./consult-comment');
const bundle = require('./bundle');
const productProcess = require(`${utils}/product-process`);
const api = global.yoho.API;
... ... @@ -205,6 +207,23 @@ const tool = {
});
}
return feedbacks;
},
/**
* 套餐数据处理
* @param bundleData
* @param skn
* @returns {{}}
*/
processBundle(bundleData, skn) {
return {
title: '优惠套装',
href: helpers.urlFormat('/product/bundle/detail', {skn: skn}),
description: '立省¥' +
(parseInt(_.get(bundleData, 'bundleInfo.salesPrice', 0), 10) -
parseInt(_.get(bundleData, 'bundleInfo.discountPrice', 0), 10)) + '元',
productList: productProcess.processProductList(bundleData && bundleData.productList)
};
}
};
... ... @@ -253,7 +272,8 @@ const newDetail = {
}), // 1 评论信息
commentModel.getCommonConsult(), // 2 默认咨询信息
commentModel.getConsults(productId, 1, 2), // 3 咨询列表
this.queryPromotion(skn) // 4 促销活动
this.queryPromotion(skn), // 4 促销活动
bundle.getBundleBySkn(skn)
]).then(info => {
let finalResult = {
promotion: null,
... ... @@ -272,6 +292,20 @@ const newDetail = {
userConsult: info[3]
}, productId);
let bundleData = _.get(info[5], 'data', null);
/* 套装 */
if (bundleData && _.get(bundleData, 'bundleInfo.discountType', null) === 1) {
finalResult.bundleData = tool.processBundle(bundleData, skn);
}
/* 量贩 */
if (bundleData && _.get(bundleData, 'bundleInfo.discountType', null) === 2) {
finalResult.discountBuy = {
num: _.get(bundleData, 'bundleInfo.bundleCount', 1),
promotionPhrase: _.get(bundleData, 'bundleInfo.promotionPhrase', '')
};
}
return finalResult;
});
},
... ...
... ... @@ -71,6 +71,9 @@
{{!-- 占位: 用户反馈, 店铺入口 --}}
<div id="placeholder-feedback-store"></div>
{{!-- 占位: 套装 --}}
<div id="placeholder-bundle"></div>
<div id="productDesc" class="product-desc {{#if limit}}limit{{/if}}"></div>
{{> detail/recommend-for-you}}
... ...
{{# bundleData}}
<div class="bundle">
<div class="bundle-nav">
<div class="bundle-title">{{title}}</div>
... ... @@ -19,4 +20,5 @@
{{/ productList}}
</div>
</div>
</div>
\ No newline at end of file
</div>
{{/ bundleData}}
\ No newline at end of file
... ...
... ... @@ -194,10 +194,12 @@ setTimeout(() => {
var promotionT = require('product/detail/promotion.hbs');
var feedbackT = require('product/detail/feedbacks.hbs');
var enterStoreT = require('product/detail/enterStore.hbs');
var bundleT = require('product/detail/bundle.hbs');
// placeholder
var $feedbackStore = $('#placeholder-feedback-store');
var $promotion = $('#placeholder-promotion');
var $bundle = $('#placeholder-bundle');
/**
* 渲染 feedback, 店铺, 替换placeholder
... ... @@ -236,6 +238,20 @@ setTimeout(() => {
return $placeholder.replaceWith(promotionHtml);
}
/**
* 渲染 套装,替换placeholder
* @param data
* @param $placeholder
* @returns {*}
*/
function renderBundle(data, $placeholder) {
var bundleHtml = bundleT({
bundleData: data.bundleData
});
return $placeholder.replaceWith(bundleHtml);
}
function promotionInit() {
var $goodsDiscount = $('#goodsDiscount');
var $discountFirstItem = $goodsDiscount.find('.first-item');
... ... @@ -275,9 +291,14 @@ setTimeout(() => {
renderFeedbackStore(info, $feedbackStore);
renderPromotion(info, $promotion);
if (info.bundleData) {
renderBundle(info, $bundle);
}
// step2: init js
require('./detail/comments-consults');
require('./detail/consultform'); // TODO
require('./detail/bundle');
promotionInit();
window.rePosFooter && window.rePosFooter();
});
... ...