Authored by htoooth

fix share

... ... @@ -5,17 +5,23 @@ const helpers = global.yoho.helpers;
const mRoot = '../models';
const service = require(`${mRoot}/erp2goods-service`);
const findBySkn = (req, res, next) => {
const find = (req, res, next) => {
let skn = req.query.skn || '';
let sku = req.query.sku || '';
service.findBySkn(skn).then((result) => {
service.find({
skn: skn,
sku: sku
}).then((result) => {
if (result.url) {
return res.redirect(helpers.urlFormat(result.url, null, 'item'));
}
return next();
}).catch(next);
};
module.exports = {
findBySkn
find
};
... ...
... ... @@ -12,7 +12,7 @@ const config = global.yoho.config;
* @param pid
* @returns {Promise.<type>}
*/
const getProductAsync = (skn) => {
const getProductBySknAsync = (skn) => {
let params = {
method: 'app.product.data',
product_skn: skn
... ... @@ -21,6 +21,16 @@ const getProductAsync = (skn) => {
return api.get('', params, config.apiCache);
};
const getProductBySkuAsync = (sku) => {
let params = {
method: 'app.shops.productListByskus',
skus: sku
};
return api.get('', params, config.apiCache);
};
module.exports = {
getProductAsync
getProductBySknAsync,
getProductBySkuAsync
};
... ...
... ... @@ -10,13 +10,44 @@ const _ = require('lodash');
const url = require('url');
const findBySkn = (skn) => {
return api.getProductAsync(skn).then((result) => {
return {
url: url.parse(_.get(result, 'data.product_url', '')).path
};
return api.getProductBySknAsync(skn).then((result) => {
if (result.code === 200 && result.data.product_url) {
return {
url: url.parse(_.get(result, 'data.product_url', '')).path
};
} else {
return {};
}
});
};
const findBySku = (sku) => {
return api.getProductBySkuAsync(`[${sku}]`).then((result) => {
if (result.code === 200 && !_.isEmpty(result.data)) {
let product = _.head(result.data) || {};
let skn = product.erpProductId || '';
if (skn) {
return findBySkn(skn);
}
return {};
} else {
return {};
}
});
};
const find = (q) => {
if (q.sku) {
return findBySku(q.sku);
} else if (q.skn) {
return findBySkn(q.skn);
} else {
return Promise.reject();
}
};
module.exports = {
findBySkn
find
};
... ...
... ... @@ -20,6 +20,6 @@ router.get('/recentReview', rvCtrl.index); // 最近浏览
router.post('/upload/image', multipartMiddleware, uploadCtrl.uploadImg);
router.get('/erp2goods', erp2goods.findBySkn);
router.get('/erp2goods', erp2goods.find);
module.exports = router;
... ...
/**
* 分享
* 这个商品详情页专用,绑定两次
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2016/3/1
*/
var $ = require('yoho-jquery');
function shareBase(options) {
... ... @@ -108,15 +111,17 @@ function share(channel, self) {
}
}
$('.share-wrapper').on('click', 'i', function() {
var $el = $(this),
type = $el.data('type'),
$weixinShareBox = $('.weixin-share-box');
module.exports = function() {
$('.share-wrapper').on('click', 'i', function() {
var $el = $(this),
type = $el.data('type'),
$weixinShareBox = $('.weixin-share-box');
if (type === 'weixin') {
share(type, $el);
} else {
$weixinShareBox.hide();
share(type);
}
});
if (type === 'weixin') {
share(type, $el);
} else {
$weixinShareBox.hide();
share(type);
}
});
};
... ...
... ... @@ -249,7 +249,8 @@ bindEvent.add(function() {
});
}());
require('../plugins/share');
// 这个文件商品详情页专用
require('../plugins/share')();
require('yoho-jquery-qrcode');
// 颜色
... ...