Authored by mark

add zan useful

... ... @@ -191,8 +191,7 @@ const indexConsult = (req, res, next) => {
let size = req.query.size || 10;
return service.indexConsultAsync(uid, pid, page, size).then(result => {
console.log('result=================');
console.log(result);
return res.json({
code: 200,
data: result
... ... @@ -237,8 +236,8 @@ const createConsult = (req, res, next) => {
const likeConsult = (req, res, next) => {
let uid = req.user.uid;
// let uid = '12696231';
let id = req.params.id || 0;
if (!id) {
return res.json({
code: 401,
... ...
... ... @@ -59,7 +59,7 @@ router.get(/\/pro_([\d]+)_([\d]+)\/(.*)/, detail.showMain); // 商å“
router.get('/detail/comment', detail.indexComment); // 商品评论
router.get('/detail/consult', detail.indexConsult); // 商品咨询
router.post('/detail/consult', auth, detail.createConsult); // 创建咨询
router.get('/detail/consult/like/:id', auth, detail.likeConsult); // 咨询喜欢
router.get('/detail/consult/like/:id', auth, detail.likeConsult); // 咨询喜欢
router.get('/detail/consult/useful/:id', auth, detail.usefulConsult); // 咨询有用
router.get('/detail/hotarea', detail.indexHotArea); // 商品热区
router.post('/index/favoriteBrand', favorite.changeFavoriteBrand); // 收藏品牌
... ...
... ... @@ -14,8 +14,14 @@
</p>
<div class="common-zan">
<div class="zan-content">
<span class="icon-border"><i class="iconfont{{#if isLike}} getzan{{/if}}">&#xe626;</i>赞({{like}}</span>
<span><i class="iconfont{{#if isUseful}} getzan{{/if}}">&#xe611;</i>有用({{useful}}</span>
<span class="icon-border" data-id="{{id}}">
<i class="iconfont cuslike{{#if isLike}} getzan{{/if}}" data-id="{{id}}" data-like="{{like}}">&#xe626;</i>
<em class="likeNum">{{like}}</em>
</span>
<span class="usefulData" data-id="{{id}}">
<i class="iconfont cususeful{{#if isUseful}} getzan{{/if}}" data-id="{{id}}" data-useful="{{useful}}">&#xe611;</i>有用
<em class="usefulNum">{{useful}}</em>
</span>
</div>
</div>
</div>
... ...
... ... @@ -979,7 +979,6 @@ function fetchComment() {
var totalnum;
if (data.code === 200) {
res = data.data;
if (res.length === 0) {
$consultsUl.next('.more-wrap').addClass('hide');
return;
... ... @@ -989,17 +988,55 @@ function fetchComment() {
$consultNum.text(res[0].total);
totalnum = Math.ceil(res[0].total / 10) * 20;
console.log(res);
$consultsUl.empty().append(consultsTpl({
consults: res
}));
$('#consults-ul .zan-content').on('click', '.iconfont', function() {
$('#consults-ul .zan-content').on('click', '.cuslike', function() {
var $this = $(this);
$this.addClass('getzan');
var id = $this.data('id');
var like = $this.data('like');
$.ajax({
type : 'GET',
url : '/product/detail/consult/like/' + id
}).then(function(data){
if(data && data.code === 400){
return window.jumpUrl(data.data.refer);
}
if(data && data.code === 200){
$this.addClass('getzan');
$('.zan-content .icon-border[data-id='+id+'] .likeNum')
.replaceWith('<em class="likeNum">'+(like+1)+'</em>');
}
});
});
$('#consults-ul .zan-content').on('click', '.cususeful', function() {
var $this = $(this);
var id = $this.data('id');
var useful = $this.data('useful');
$this.addClass('getzan');
$.ajax({
type : 'GET',
url : '/product/detail/consult/useful/' + id
}).then(function(data){
if(data && data.code === 400){
return window.jumpUrl(data.data.refer);
}
if(data && data.code === 200){
$('.zan-content .usefulData[data-id='+id+'] .usefulNum')
.replaceWith('<em class="usefulNum">'+(useful+1)+'</em>');
}
});
});
baseUrl = '/product/detail/consult?productId=' + id + '&filterId=7';
$('.consults-devide').empty().append(
... ...