Authored by 张文文

发现好货修改 review by lea.guo

const FindGoods = require('../models/find-goods');
const _ = require('lodash');
const stringProcess = require('../../../utils/string-process');
const helpers = global.yoho.helpers;
exports.index = function(req, res, next) {
let qcdn = _.get(req.app.locals, 'wap.qcloud_cdn');
... ... @@ -68,3 +69,95 @@ exports.fetchMore = function(req, res, next) {
})
.catch(next);
};
exports.userFavGoods = function(req, res, next) {
let qcdn = _.get(req.app.locals, 'wap.qcloud_cdn');
const { page = 1 } = req.query || {};
req.ctx(FindGoods)
.queryUserFavFindgoods({ page })
.then(result => {
if (!result) {
return next();
}
const title =
stringProcess.paramsFilter(req.query.title) || '我喜欢的发现好货';
const shareId = _.parseInt(
stringProcess.paramsFilter(req.query.share_id),
);
// 唤起 APP 的路径
res.locals.appPath = `yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.h5","params":{"param":{"share_id":"${shareId}","title":"${title}"},"share":"/operations/api/v5/webshare/getShare","shareparam":{"share_id":"${shareId}"},"title":"${title}","url":"https://activity.yoho.cn/activity/find/userFavGoods.html"}}`;
const jsSdk = global.yoho.config.jsSdk;
res.render('find-goods/index', {
module: 'activity',
page: 'find-goods',
title: title,
content: result.data,
isFeature: true,
wechatShare: true,
localCss: true,
loadJs: [
{
src: qcdn ?
jsSdk.replace(
/\/\/cdn.yoho.cn/gi,
'//qcdn.yoho.cn',
) :
jsSdk,
},
],
});
})
.catch(next);
};
exports.updateFavGoodsStatus = function(req, res, next) {
let refer = helpers.urlFormat('/signin.html', {
refer: req.headers.referer
});
console.log('-------1---------');
let result = {
code: 400,
message: '未登录',
data: refer
};
/* 判断是不是AJAX请求 */
if (!req.xhr) {
res.jsonp(result);
return;
}
/* 判断参数是否有效 */
let goodsId = req.body.goodsId,
status = req.body.status || '1',
uid = req.user.uid;
if (!stringProcess.isNumeric(goodsId) || !stringProcess.isNumeric(uid)) {
res.jsonp(result);
return;
}
console.log('------------updateFavGoodsStatus--------');
// 执行收藏或取消操作
return req.ctx(FindGoods).updateFavFindgoods(uid, goodsId, status).then(data => {
if (!data) {
res.jsonp({
code: 400,
message: '操作失败'
});
return;
}
res.jsonp({
code: 200,
message: data.message,
data: ''
});
}).catch(next);
};
... ...
... ... @@ -16,9 +16,48 @@ module.exports = class FindGoods extends global.yoho.BaseModel {
data: Object.assign(
{
method: 'app.grass.findGrassGoods',
uid: '500031858',
debug: 'XYZ'
},
params,
),
});
}
/**
* 个人好货喜欢
* @param {*} {uid, page, limit}
*/
queryUserFavFindgoods(params) {
return this.get({
data: Object.assign(
{
method: 'app.grass.queryUserFavFindgoods',
uid: '500031858',
debug: 'XYZ'
},
params,
),
});
}
/**
* @param {[int]} uid [用户ID]
* @param {[int]} id [好货ID]
* @param {string} status [操作(0取消,1喜欢)]
* @return {[array]}
*/
updateFavFindgoods(uid, goodsId, status) {
return this.get({
data: Object.assign(
{
method: 'app.grass.updateFavFindgoods',
uid,
status,
findgoodsId: goodsId,
debug: 'XYZ'
}
),
});
}
};
... ...
... ... @@ -474,5 +474,8 @@ router.get('/group/loadOrder', auth, group.loadOrder); // 加载拼团列表
// 发现好货
router.get('/find/goods.html', FindGoods.index);
router.get('/find/goods/more', FindGoods.fetchMore);
router.get('/find/userFavGoods.html', FindGoods.userFavGoods); // 用户喜欢的好货
router.post('/find/updateFavGoodsStatus', auth, FindGoods.updateFavGoodsStatus); // 好货收藏/取消收藏
module.exports = router;
... ...
... ... @@ -12,11 +12,19 @@
<div class="item-detail">
<div class="desc-wrapper" onclick="onItemClick({{stringify this}})">
<div class="item-name">{{findGood.productName}}</div>
<div class="item-desc">{{content}}</div>
<div class="item-desc">哈哈哈先写上后期别忘了改回来</div>
</div>
<div class="action-tip">
<span class="action-name">SHOP NOW</span>
<span class="action-icon"></span>
<div class="like-option">
<p class="like-option-btn {{#if findGood.isFavorite}}fav{{/if}}" data-data="{{stringify this}}">
<span class="iconfont favorite">&#xe605;</span>
<span class="fav-text">
{{#if findGood.favoriteNum}}
{{findGood.favoriteNum}}人喜欢
{{else}}
喜欢
{{/if}}
</span>
</p>
</div>
</div>
</div>
... ...
... ... @@ -14,7 +14,6 @@ const isTest = process.env.NODE_ENV === 'test3' || process.env.NODE_ENV === 'tes
const domains = {
// api: 'http://api.yoho.cn/',
//
// service: 'http://service.yoho.cn/',
// yoLuck: 'https://action.yoho.cn',
... ...
const $ = require('yoho-jquery');
const lazyLoad = require('js/plugin/lazyload');
const tip = require('js/plugin/tip');
require('scss/activity/find-goods.page.scss');
const EVENT_SCROLL = 'scroll';
... ... @@ -76,8 +77,65 @@ window.onAuthorClick = function(item = {}) {
yoho.goUserCenter({ authorUid, authorType });
};
// 收藏
window.onLike = function() {};
function likedGoodsInit() {
let $likeOption = $('.like-option-btn');
$likeOption.click(function() {
let $this = $(this);
let goodData = $this.data('data');
let goodsId = goodData.findGood.id;
let cancel = $this.hasClass('fav');
let self = $(this);
let favNum;
let $favText = $this.find('.fav-text');
let firstIndex = $favText.text().indexOf('人');
if (firstIndex >= 0) {
favNum = $favText.text().substr(0, firstIndex);
} else {
favNum = 0;
}
cancel ? favNum-- : favNum++;
$this.toggleClass('fav');
if (favNum > 0) {
$favText.text(`${favNum}人喜欢`);
} else {
$favText.text('喜欢');
}
// hhh
$.ajax({
method: 'post',
url: '/find/updateFavGoodsStatus',
dataType: 'jsonp',
data: {
goodsId: goodsId,
status: cancel ? '0' : '1',
},
xhrFields: {
withCredentials: true
},
success: function(data) {
if (data.code === 200) {
if (self.hasClass('fav')) {
tip.show('取消收藏成功!');
} else {
tip.show('收藏成功!');
}
}
},
error: function() {
tip.show('网络断开连接了~');
}
});
});
}
$(function() {
/**
... ... @@ -85,6 +143,11 @@ $(function() {
*/
onPullUp();
/**
* 好货喜欢
*/
likedGoodsInit();
document.title = '发现好货';
// 商品曝光事件上报
... ...