1.前端页面接入商品收藏接口,
2.暂时使用alert弹出框提示收藏和取消收藏,回头改成颜色显示效果
This commit is contained in:
parent
1fa68d070b
commit
83d8bc4fab
@ -31,3 +31,10 @@ export function getProductSpuInfo(id) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function collectionSpu(spuId,hasCollectionType) {
|
||||
return request({
|
||||
url: '/product-api/users/spu/collection/'+spuId+'/' + hasCollectionType,
|
||||
method: 'post'
|
||||
});
|
||||
}
|
||||
|
@ -16,6 +16,15 @@ export function DelFavorite(id){
|
||||
})
|
||||
}
|
||||
|
||||
export function hasUserSpuFavorite(spuId){
|
||||
return request({
|
||||
url: '/user-api/users/favorite/hasUserFavorite',
|
||||
method: 'get',
|
||||
params: {spuId}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
export function GetCoupon(data){
|
||||
return request({
|
||||
url: '/User/GetCoupon',
|
||||
|
@ -98,7 +98,7 @@
|
||||
</div>
|
||||
<van-goods-action>
|
||||
|
||||
<van-goods-action-mini-btn icon="like-o" @click="sorry">
|
||||
<van-goods-action-mini-btn icon="like-o" @click="onFavoriteClicked">
|
||||
收藏
|
||||
</van-goods-action-mini-btn>
|
||||
<van-goods-action-mini-btn icon="cart" :info="cartCount > 0 ? cartCount : undefined" @click="onClickCart">
|
||||
@ -171,8 +171,9 @@
|
||||
|
||||
<script>
|
||||
// import skuData from '../../data/sku';
|
||||
import {getProductSpuInfo} from '../../api/product';
|
||||
import {getProductSpuInfo,collectionSpu} from '../../api/product';
|
||||
import {addCart, countCart, getCartCalcSkuPrice} from '../../api/order';
|
||||
import {hasUserSpuFavorite} from '../../api/user';
|
||||
import {Dialog} from 'vant';
|
||||
import {checkLogin} from "../../utils/cache";
|
||||
|
||||
@ -290,6 +291,7 @@
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
onClickCart() {
|
||||
this.$router.push('/cart');
|
||||
},
|
||||
@ -305,6 +307,35 @@
|
||||
onClickShowTag() {
|
||||
this.showTag = true;
|
||||
},
|
||||
onFavoriteClicked(){
|
||||
if (!checkLogin()) {
|
||||
Dialog.alert({
|
||||
title: '系统提示',
|
||||
message: '未登陆用户,暂时不支持使用购物车',
|
||||
});
|
||||
return;
|
||||
}
|
||||
let id = this.$route.params.id; // 商品编号
|
||||
let hasCollectionType = 1; // 收藏类型 默认收藏
|
||||
hasUserSpuFavorite(id).then(data => {
|
||||
let hasCollection = data;
|
||||
// alert("是否收藏==" + hasCollection);
|
||||
if (hasCollection){
|
||||
hasCollectionType = 2;
|
||||
}
|
||||
|
||||
// alert("hasCollectionType==" + hasCollectionType);
|
||||
collectionSpu(id,hasCollectionType).then(data =>{
|
||||
let v = data;
|
||||
if (hasCollectionType == 1 && v){
|
||||
alert("商品已收藏");
|
||||
}else if (hasCollectionType == 2 && v){
|
||||
alert("商品已取消");
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
},
|
||||
onBuyClicked(data) {
|
||||
const { selectedNum } = data;
|
||||
this.$router.push({
|
||||
|
@ -39,8 +39,16 @@ public class UserFavoriteController {
|
||||
@DeleteMapping("remove")
|
||||
@RequiresLogin
|
||||
@ApiOperation(value = "用户商品收藏-删除")
|
||||
public CommonResult<Boolean> removeFavorite(@RequestParam("spuId") final Integer spuId) {
|
||||
public CommonResult<Boolean> removeUserFavorite(@RequestParam("spuId") final Integer spuId) {
|
||||
final Integer userId = UserSecurityContextHolder.getContext().getUserId();
|
||||
return userProductSpuCollectionsService.deleteUserProductSpuCollections(userId, spuId);
|
||||
}
|
||||
|
||||
@GetMapping("hasUserFavorite")
|
||||
@RequiresLogin
|
||||
@ApiOperation(value = "用户商品收藏-是否收藏")
|
||||
public CommonResult<Boolean> hasUserSpuFavorite(@RequestParam("spuId") final Integer spuId) {
|
||||
final Integer userId = UserSecurityContextHolder.getContext().getUserId();
|
||||
return userProductSpuCollectionsService.hasUserSpuFavorite(spuId, userId);
|
||||
}
|
||||
}
|
||||
|
@ -51,4 +51,14 @@ public interface UserProductSpuCollectionsService {
|
||||
* @return
|
||||
*/
|
||||
CommonResult<Boolean> deleteUserProductSpuCollections(Integer userId, Integer spuId);
|
||||
|
||||
|
||||
/**
|
||||
* 检验用户商品是否收藏
|
||||
* @param spuId
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
CommonResult<Boolean> hasUserSpuFavorite(Integer spuId, Integer userId);
|
||||
|
||||
}
|
||||
|
@ -96,11 +96,26 @@ public class UserProductSpuCollectionsServiceImpl implements UserProductSpuColle
|
||||
if (userProductSpuCollectionsBO != null) {
|
||||
// 未取消收藏的数据
|
||||
if (userProductSpuCollectionsBO.getDeleted().equals(DeletedStatusEnum.DELETED_NO.getValue())) {
|
||||
UserProductSpuCollectionsUpdateDTO userProductSpuCollectionsUpdateDTO = new UserProductSpuCollectionsUpdateDTO().setId(userProductSpuCollectionsBO.getId())
|
||||
.setUpdateTime(new Date()).setDeleted(DeletedStatusEnum.DELETED_YES.getValue());
|
||||
UserProductSpuCollectionsUpdateDTO userProductSpuCollectionsUpdateDTO = new UserProductSpuCollectionsUpdateDTO()
|
||||
.setId(userProductSpuCollectionsBO.getId()).setUpdateTime(new Date())
|
||||
.setDeleted(DeletedStatusEnum.DELETED_YES.getValue());
|
||||
result = this.updateUserProductSpuCollections(userProductSpuCollectionsUpdateDTO);
|
||||
}
|
||||
}
|
||||
return CommonResult.success(result > 0 ? Boolean.TRUE : Boolean.FALSE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> hasUserSpuFavorite(final Integer spuId, final Integer userId) {
|
||||
UserProductSpuCollectionsBO userProductSpuCollectionsBO = this
|
||||
.getUserSpuCollectionsByUserIdAndSpuId(userId, spuId);
|
||||
|
||||
if (userProductSpuCollectionsBO != null) {
|
||||
// 收藏
|
||||
final boolean hasCollect = userProductSpuCollectionsBO.getDeleted()
|
||||
.equals(DeletedStatusEnum.DELETED_NO.getValue());
|
||||
return CommonResult.success(hasCollect);
|
||||
}
|
||||
return CommonResult.success(Boolean.FALSE);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user