This commit is contained in:
zhenxianyimeng 2019-07-10 23:22:04 +08:00
commit c1e34b908c
8 changed files with 107 additions and 24 deletions

View File

@ -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'
});
}

View File

@ -1,21 +1,30 @@
import request from "../config/request"; import request from "../config/request";
export function GetFavorite(data){ export function GetFavoritePage(pageNo,pageSize){
return request({ return request({
url: '/User/GetFavorite', url: '/user-api/users/favorite/page',
method: 'post', method: 'get',
params: { data } params: { pageNo,pageSize }
}) })
} }
export function DelFavorite(id){ export function DelFavorite(spuId){
return request({ return request({
url: '/User/DelFavorite', url: '/user-api/users/favorite/remove',
method: 'get', method: 'DELETE',
params: { id:id } params: { spuId }
}) })
} }
export function hasUserSpuFavorite(spuId){
return request({
url: '/user-api/users/favorite/hasUserFavorite',
method: 'get',
params: {spuId}
})
}
export function GetCoupon(data){ export function GetCoupon(data){
return request({ return request({
url: '/User/GetCoupon', url: '/User/GetCoupon',

View File

@ -98,7 +98,7 @@
</div> </div>
<van-goods-action> <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>
<van-goods-action-mini-btn icon="cart" :info="cartCount > 0 ? cartCount : undefined" @click="onClickCart"> <van-goods-action-mini-btn icon="cart" :info="cartCount > 0 ? cartCount : undefined" @click="onClickCart">
@ -171,8 +171,9 @@
<script> <script>
// import skuData from '../../data/sku'; // import skuData from '../../data/sku';
import {getProductSpuInfo} from '../../api/product'; import {getProductSpuInfo,collectionSpu} from '../../api/product';
import {addCart, countCart, getCartCalcSkuPrice} from '../../api/order'; import {addCart, countCart, getCartCalcSkuPrice} from '../../api/order';
import {hasUserSpuFavorite} from '../../api/user';
import {Dialog} from 'vant'; import {Dialog} from 'vant';
import {checkLogin} from "../../utils/cache"; import {checkLogin} from "../../utils/cache";
@ -290,6 +291,7 @@
} }
}); });
}, },
onClickCart() { onClickCart() {
this.$router.push('/cart'); this.$router.push('/cart');
}, },
@ -305,6 +307,35 @@
onClickShowTag() { onClickShowTag() {
this.showTag = true; 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) { onBuyClicked(data) {
const { selectedNum } = data; const { selectedNum } = data;
this.$router.push({ this.$router.push({

View File

@ -9,6 +9,7 @@
<div v-for="(item,index) in list" :key="index"> <div v-for="(item,index) in list" :key="index">
<van-swipe-cell :right-width="65" :on-close="onClose(item)"> <van-swipe-cell :right-width="65" :on-close="onClose(item)">
<product-card :product='item' /> <product-card :product='item' />
<span>{{item.spuName}}</span>
<span slot="right" >删除</span> <span slot="right" >删除</span>
</van-swipe-cell> </van-swipe-cell>
</div> </div>
@ -17,7 +18,7 @@
</template> </template>
<script> <script>
import { GetFavorite ,DelFavorite} from "../../../api/user.js"; import { GetFavoritePage ,DelFavorite} from "../../../api/user.js";
export default { export default {
data(){ data(){
@ -26,6 +27,7 @@ export default {
finished:false, finished:false,
list:[], list:[],
page:0, page:0,
pageSize:10
} }
}, },
methods:{ methods:{
@ -41,7 +43,7 @@ export default {
this.$dialog.confirm({ this.$dialog.confirm({
message: '确定删除吗?' message: '确定删除吗?'
}).then(() => { }).then(() => {
DelFavorite(item.id).then(response=>{ DelFavorite(item.spuId).then(response=>{
this.$toast('删除成功'); this.$toast('删除成功');
this.$router.go(0); this.$router.go(0);
}) })
@ -54,13 +56,15 @@ export default {
} }
}, },
onLoad() { onLoad() {
this.page++; let pageNo = this.page + 1;
GetFavorite().then(response=>{ GetFavoritePage(pageNo,this.pageSize).then(response=>{
response.list.forEach(item => { this.page = pageNo;
this.list.push(item); this.list.push(...response.list);
}); // response.list.forEach(item => {
// this.list.push(item);
// });
this.loading = false; this.loading = false;
if(response.TotalPage<=this.page){ if(this.list.length >= response.total){
this.finished = true; this.finished = true;
} }

View File

@ -39,8 +39,16 @@ public class UserFavoriteController {
@DeleteMapping("remove") @DeleteMapping("remove")
@RequiresLogin @RequiresLogin
@ApiOperation(value = "用户商品收藏-删除") @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(); final Integer userId = UserSecurityContextHolder.getContext().getUserId();
return userProductSpuCollectionsService.deleteUserProductSpuCollections(userId, spuId); 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);
}
} }

View File

@ -51,4 +51,14 @@ public interface UserProductSpuCollectionsService {
* @return * @return
*/ */
CommonResult<Boolean> deleteUserProductSpuCollections(Integer userId, Integer spuId); CommonResult<Boolean> deleteUserProductSpuCollections(Integer userId, Integer spuId);
/**
* 检验用户商品是否收藏
* @param spuId
* @param userId
* @return
*/
CommonResult<Boolean> hasUserSpuFavorite(Integer spuId, Integer userId);
} }

View File

@ -96,11 +96,26 @@ public class UserProductSpuCollectionsServiceImpl implements UserProductSpuColle
if (userProductSpuCollectionsBO != null) { if (userProductSpuCollectionsBO != null) {
// 未取消收藏的数据 // 未取消收藏的数据
if (userProductSpuCollectionsBO.getDeleted().equals(DeletedStatusEnum.DELETED_NO.getValue())) { if (userProductSpuCollectionsBO.getDeleted().equals(DeletedStatusEnum.DELETED_NO.getValue())) {
UserProductSpuCollectionsUpdateDTO userProductSpuCollectionsUpdateDTO = new UserProductSpuCollectionsUpdateDTO().setId(userProductSpuCollectionsBO.getId()) UserProductSpuCollectionsUpdateDTO userProductSpuCollectionsUpdateDTO = new UserProductSpuCollectionsUpdateDTO()
.setUpdateTime(new Date()).setDeleted(DeletedStatusEnum.DELETED_YES.getValue()); .setId(userProductSpuCollectionsBO.getId()).setUpdateTime(new Date())
.setDeleted(DeletedStatusEnum.DELETED_YES.getValue());
result = this.updateUserProductSpuCollections(userProductSpuCollectionsUpdateDTO); result = this.updateUserProductSpuCollections(userProductSpuCollectionsUpdateDTO);
} }
} }
return CommonResult.success(result > 0 ? Boolean.TRUE : Boolean.FALSE); 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);
}
} }

View File

@ -24,7 +24,6 @@
<where> <where>
user_id = #{userId} AND deleted = 0 user_id = #{userId} AND deleted = 0
</where> </where>
ORDER BY sort ASC
<if test="offset != null and limit != null"> <if test="offset != null and limit != null">
LIMIT #{offset}, #{limit} LIMIT #{offset}, #{limit}
</if> </if>