Authored by 李奇

商品详情页为你优选完成提交、大数据暂未实现暂时使用开关屏该模块

... ... @@ -9,10 +9,19 @@
// const helpers = global.yoho.helpers;
const api = global.yoho.API;
const md5 = require('md5');
const _ = require('lodash');
const requestIp = require('request-ip');
const model = require('../models/detail');
const searchModel = require('../models/search');
// 频道映射
const CHANNEL_MAP = {
'men': 1,
'women': 2,
'lifestyle': 4
};
// 保存在 gids 和 skns ,最近流览功能
const saveRecentGoodInCookies = (oldSkns, res, addSkns) => {
// oldSkns = oldSkns ? oldSkns.split(',') : [];
... ... @@ -28,6 +37,25 @@ const saveRecentGoodInCookies = (oldSkns, res, addSkns) => {
};
/**
* 获取客户端唯一标识
* @param req
* @param res
* @returns {*|string}
*/
const getUdid = (req, res) => {
let udid = req.cookies.udid;
if (!udid) {
udid = md5(req.ip || requestIp.getClientIp(req));
if (res && res.cookie) {
res.cookie('udid', udid);
}
}
return udid;
};
/**
* 商品详情
*/
const component = {
... ... @@ -175,7 +203,6 @@ const component = {
/**
* 是否支持退换货
*
* @param req
* @param res
* @param next
... ... @@ -188,6 +215,29 @@ const component = {
model.refundExchange(params).then(result => {
res.json(result);
}).catch(next);
},
/**
* 为你优选
* @param req
* @param res
* @param next
*/
prefer: (req, res, next) => {
let udid = getUdid(req, res);
let channel = req.query.channel || req.cookies._Channel || 'men';
let params = {
udid,
yh_channel: CHANNEL_MAP[channel] || 1,
limit: 30,
page: 1,
rec_pos: 100003
};
model.preferList(params)
.then((list) => {
res.json(list);
}).catch(next);
}
};
... ...
... ... @@ -6,6 +6,52 @@
'use strict';
const api = global.yoho.API;
const _ = require('lodash');
/**
*
* @param product
* @returns {*|string}
* @private
*/
const _procProductImg = (product) => {
if (product.gender === '2,3' || product.gender === '2' || product.gender === '3') {
return product.cover_2 || product.images_url || product.cover_1 || '';
}
return product.cover_1 || product.images_url || product.cover_2 || '';
};
/**
*
* @param list
* @returns {Array}
* @private
*/
const _processProduct = (list) => {
let newRes = [];
list = list || [];
list.forEach(item => {
let defaultGoods = _.find(item.goods_list, {is_default: 'Y'});
// 无默认商品取商品列表第一个
if (!defaultGoods) {
defaultGoods = item.goods_list[0];
}
item.default_images = _procProductImg(defaultGoods);
item.goodsUrl = `${config.siteUrl}/product/pro_${item.product_id}_${defaultGoods.goods_id}/${item.cn_alphabet}.html`; // eslint-disable-line
});
_.chunk(list, 5).forEach(item => {
newRes.push({
list: item
});
});
return newRes;
};
/**
* 商品详情
... ... @@ -83,13 +129,30 @@ const model = {
/**
* 是否支持退换货
*
* @param params
*/
refundExchange(params) {
return api.get('', Object.assign({
method: 'app.product.refundExchange'
}, params));
},
/**
* 为你优选
* @param params
* @param uid
* @returns {Array}
*/
preferList(params, uid) {
if (uid !== 0 && uid !== null) {
params.uid = uid;
}
return api.get('', Object.assign({
method: 'app.home.newPreference'
}, params)).then(data => {
return _processProduct(data.data.product_list);
});
}
};
... ...
... ... @@ -47,6 +47,7 @@ router.get(/\/product\/pro_([\d]+)_([\d]+)\/(.*).html/, detail.index); // 商品
router.get(/\/product\/product_([\d]+)\.json/, detail.product);
router.get(/\/product\/intro_([\d]+)\.json/, detail.intro);
router.get('/product/refundExchange/:skn', detail.supportRefundExchange); // 是否支持7天无理由退换货
router.get('/product/prefer', detail.prefer); // 为你优选列表
router.post(/\product\/cart.json/, detail.addToCart);
router.post(/\product\/favorite.json/, auth, detail.favorite);
router.get(/\/product\/cart-count.json/, detail.getCartCount);
... ...
... ... @@ -28,12 +28,8 @@
<show-box>
<ul class="service">
<li><i class="icon icon-real"></i>100%品牌正品</li>
<li v-if="intro.supportRefundExchange" class="return">
<i class="icon icon-seven"></i>支持7天无理由退换货
</li>
<li class="return">
<i class="icon icon-unsupport-seven"></i>不支持7天无理由退换货
</li>
<li class="return" v-if="intro.supportRefundExchange"><i class="icon icon-seven"></i>支持7天无理由退换货</li>
<li class="return"><i class="icon icon-unsupport-seven"></i>不支持7天无理由退换货</li>
<li><i class="icon icon-onlineservice"></i>便捷在线客服</li>
</ul>
</show-box>
... ... @@ -180,6 +176,10 @@
</show-box>
<show-box v-if="showPrefer" class="prefer-detail" :is-last="true">
<prefer-list :title="preferTitle" :list="preferList"></prefer-list>
</show-box>
<div class="control-box" v-if="isApp && isReady">
<button class="button control-button">
<span @click="yoho.goShopingCart()" style="position: relative;">
... ... @@ -261,23 +261,20 @@
font-size: 0;
li {
font-size: 24px;
width: 200px;
line-height: 40px;
width: 195px;
line-height: 22px;
text-align: center;
display: inline-block;
&.quality {
i.icon {
margin-right: 6px;
}
&.return {
width: 290px;
width: 300px;
border-left: 1px solid #eee;
border-right: 1px solid #eee;
}
&.cs {
}
}
}
... ... @@ -490,7 +487,10 @@
},
isApp: yoho.isApp,
isSoldOut: false,
isReady: false
isReady: false,
showPrefer: true, // TODO 为你优选大数据暂未实现,本期暂时屏蔽
preferTitle: '为你优选',
preferList: []
};
},
computed: {
... ... @@ -501,6 +501,7 @@
showBox: require('./show-box.vue'),
topNav: require('./top-nav.vue'),
shareBottom: require('component/tool/share-bottom.vue'),
preferList: require('component/product/preferList.vue')
},
methods: {
/**
... ... @@ -598,6 +599,29 @@
$.get(`/product/refundExchange/${data.product_skn}`).then(sd => {
this.intro['supportRefundExchange'] = sd[data.product_skn] === "Y";
});
if(self.showPrefer) {
$.get('/product/prefer').then(list => {
console.log(list.length)
self.preferList = list || [
{
goodsUrl: '//m.yohoblk.com',
default_images: '//img11.static.yhbimg.com/goodsimg/2016/12/26/17/01a77e16890169159034327b40ed95e0d9.png?imageMogr2/thumbnail/750x1000/extent/750x1000/background/d2hpdGU=/position/center/quality/80/interlace/1',
product_name: '测试产品fd测试产品fdsssfdssddfsdfsdfsssfdssddfsdfsdf',
market_price: '100',
sales_price: '50'
},{
goodsUrl: '//m.yohoblk.com',
default_images: '//img11.static.yhbimg.com/goodsimg/2016/12/26/17/01a77e16890169159034327b40ed95e0d9.png?imageMogr2/thumbnail/750x1000/extent/750x1000/background/d2hpdGU=/position/center/quality/80/interlace/1',
product_name: '测试产品测试产品fdsssfdssddfsdfsdffdsssfdssddfsdfsdf测试产品fdsssfdssddfsdfsdf',
market_price: '100',
sales_price: '50'
}
];
});
}
});
}
})
... ...