merge
This commit is contained in:
commit
c1e34b908c
@ -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'
|
||||
});
|
||||
}
|
||||
|
@ -1,21 +1,30 @@
|
||||
import request from "../config/request";
|
||||
|
||||
export function GetFavorite(data){
|
||||
export function GetFavoritePage(pageNo,pageSize){
|
||||
return request({
|
||||
url: '/User/GetFavorite',
|
||||
method: 'post',
|
||||
params: { data }
|
||||
url: '/user-api/users/favorite/page',
|
||||
method: 'get',
|
||||
params: { pageNo,pageSize }
|
||||
})
|
||||
}
|
||||
|
||||
export function DelFavorite(id){
|
||||
export function DelFavorite(spuId){
|
||||
return request({
|
||||
url: '/User/DelFavorite',
|
||||
method: 'get',
|
||||
params: { id:id }
|
||||
url: '/user-api/users/favorite/remove',
|
||||
method: 'DELETE',
|
||||
params: { spuId }
|
||||
})
|
||||
}
|
||||
|
||||
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({
|
||||
|
@ -9,6 +9,7 @@
|
||||
<div v-for="(item,index) in list" :key="index">
|
||||
<van-swipe-cell :right-width="65" :on-close="onClose(item)">
|
||||
<product-card :product='item' />
|
||||
<span>{{item.spuName}}</span>
|
||||
<span slot="right" >删除</span>
|
||||
</van-swipe-cell>
|
||||
</div>
|
||||
@ -17,7 +18,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { GetFavorite ,DelFavorite} from "../../../api/user.js";
|
||||
import { GetFavoritePage ,DelFavorite} from "../../../api/user.js";
|
||||
|
||||
export default {
|
||||
data(){
|
||||
@ -26,6 +27,7 @@ export default {
|
||||
finished:false,
|
||||
list:[],
|
||||
page:0,
|
||||
pageSize:10
|
||||
}
|
||||
},
|
||||
methods:{
|
||||
@ -41,9 +43,9 @@ export default {
|
||||
this.$dialog.confirm({
|
||||
message: '确定删除吗?'
|
||||
}).then(() => {
|
||||
DelFavorite(item.id).then(response=>{
|
||||
DelFavorite(item.spuId).then(response=>{
|
||||
this.$toast('删除成功');
|
||||
this.$router.go(0);
|
||||
this.$router.go(0);
|
||||
})
|
||||
instance.close();
|
||||
}).catch(() => {
|
||||
@ -54,16 +56,18 @@ export default {
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.page++;
|
||||
GetFavorite().then(response=>{
|
||||
response.list.forEach(item => {
|
||||
this.list.push(item);
|
||||
});
|
||||
let pageNo = this.page + 1;
|
||||
GetFavoritePage(pageNo,this.pageSize).then(response=>{
|
||||
this.page = pageNo;
|
||||
this.list.push(...response.list);
|
||||
// response.list.forEach(item => {
|
||||
// this.list.push(item);
|
||||
// });
|
||||
this.loading = false;
|
||||
if(response.TotalPage<=this.page){
|
||||
if(this.list.length >= response.total){
|
||||
this.finished = true;
|
||||
}
|
||||
|
||||
|
||||
})
|
||||
}
|
||||
},
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,6 @@
|
||||
<where>
|
||||
user_id = #{userId} AND deleted = 0
|
||||
</where>
|
||||
ORDER BY sort ASC
|
||||
<if test="offset != null and limit != null">
|
||||
LIMIT #{offset}, #{limit}
|
||||
</if>
|
||||
|
Loading…
Reference in New Issue
Block a user