【商品详情】

1. 接入收藏逻辑
pull/1/MERGE
YunaiV 2023-06-09 20:43:37 +08:00
parent e68d39c99c
commit 8fbdec3738
2 changed files with 74 additions and 34 deletions

22
api/product/favorite.js Normal file
View File

@ -0,0 +1,22 @@
import request from "@/utils/request.js";
// 检查是否收藏过商品
export function isFavoriteExists(spuId) {
return request.get('app-api/product/favorite/exits', {
spuId
});
}
// 添加商品收藏
export function createFavorite(spuId) {
return request.post('app-api/product/favorite/create', {
spuId
});
}
// 取消商品收藏
export function deleteFavorite(spuId) {
return request.delete('app-api/product/favorite/delete', {
spuId
});
}

View File

@ -306,12 +306,14 @@
import home from '@/components/home';
import parser from "@/components/jyf-parser/jyf-parser";
import * as ProductSpuApi from '@/api/product/spu.js';
import * as ProductFavoriteApi from '@/api/product/favorite.js';
import * as TradeCartApi from '@/api/trade/cart.js';
import * as Util from '@/utils/util.js';
import * as ProductUtil from '@/utils/product.js';
// #ifdef MP
import { base64src } from '@/utils/base64src.js'
import { getQrcode } from '@/api/api.js';
import {createFavorite, deleteFavorite} from "../../api/product/favorite";
// #endif
const app = getApp();
export default {
@ -352,7 +354,7 @@
reply: [], //
replyChance: 0, // TODO
// ========== TODO ==========
// ========== ==========
userCollect: false,
// ========== TODO ==========
@ -418,7 +420,8 @@
if (newV === true) {
that.getCouponList();
that.getCartCount();
}
that.isFavoriteExists();
}
},
deep: true
}
@ -525,7 +528,6 @@
let skus = res.data.skus;
this.$set(this, 'productInfo', productInfo);
this.$set(this, 'spu', spu);
this.$set(this, 'userCollect', res.data.userCollect); // TODO
this.$set(this.attr, 'properties', ProductUtil.convertProductPropertyList(skus));
this.$set(this, 'skuMap', ProductUtil.convertProductSkuMap(skus));
// // TODO
@ -542,6 +544,7 @@
//
if (this.isLogin) {
this.getCartCount();
this.isFavoriteExists();
// #ifdef H5
this.make();
this.ShareInfo();
@ -768,6 +771,52 @@
});
},
// ========== TODO ==========
getProductReplyList: function() {
getReplyProduct(this.id).then(res => {
this.reply = res.data.productReply ? [res.data.productReply] : [];
})
},
getProductReplyCount: function() {
let that = this;
getReplyConfig(that.id).then(res => {
that.$set(that, 'replyChance', res.data.replyChance * 100);
that.$set(that, 'replyCount', res.data.sumCount);
});
},
// ========== ==========
/**
* 获得是否收藏
*/
isFavoriteExists: function() {
ProductFavoriteApi.isFavoriteExists(this.id).then(res => {
this.userCollect = res.data;
});
},
/**
* 收藏 / 取消商品
*/
setCollect: function() {
if (!this.isLogin) {
toLogin();
return;
}
//
if (this.userCollect) {
ProductFavoriteApi.deleteFavorite(this.id).then(res => {
this.$set(this, 'userCollect', false);
})
//
} else {
ProductFavoriteApi.createFavorite(this.id).then(res => {
this.$set(this, 'userCollect', true);
})
}
},
// === TODO ====
kefuClick() {
@ -868,18 +917,6 @@
})
});
},
getProductReplyList: function() {
getReplyProduct(this.id).then(res => {
this.reply = res.data.productReply ? [res.data.productReply] : [];
})
},
getProductReplyCount: function() {
let that = this;
getReplyConfig(that.id).then(res => {
that.$set(that, 'replyChance', res.data.replyChance * 100);
that.$set(that, 'replyCount', res.data.sumCount);
});
},
/**
* 获取优惠券
*/
@ -911,25 +948,6 @@
that.$set(that.coupon, 'list', that.coupon.list);
that.$set(that.coupon, 'coupon', false);
},
/**
* 收藏商品
*/
setCollect: function() {
let that = this;
if (this.isLogin === false) {
toLogin();
} else {
if (this.userCollect) {
collectDel(this.productInfo.id).then(res => {
that.$set(that, 'userCollect', !that.userCollect);
})
} else {
collectAdd(this.productInfo.id).then(res => {
that.$set(that, 'userCollect', !that.userCollect);
})
}
}
},
/**
* 打开优惠券插件
*/