收藏商品及取消收藏

This commit is contained in:
clay
2023-01-19 16:37:14 +08:00
parent 7d0b6274f1
commit 133a0e77f4
3 changed files with 46 additions and 18 deletions

View File

@@ -31,7 +31,7 @@
</view> </view>
<u-button v-if="type==1" type="success" text="移除" color="#0EBB5B" @click="deleteProduct(item)"> <u-button v-if="type==1" type="success" text="移除" color="#0EBB5B" @click="deleteProduct(item)">
</u-button> </u-button>
<u-button v-if="type==2" type="success" text="取消收藏" color="#0EBB5B" @click="deleteProduct(item)"> <u-button v-if="type==2" type="success" text="取消收藏" color="#0EBB5B" @click="cancelCollect(item)">
</u-button> </u-button>
</u-grid-item> </u-grid-item>
</u-grid> </u-grid>
@@ -77,6 +77,7 @@
methods: { methods: {
//获取历史记录 //获取历史记录
getHistoryOrCollection() { getHistoryOrCollection() {
console.log(uni.getStorageSync('token'));
this.$apiServe.getHistoryOrCollection(this.type).then(res => { this.$apiServe.getHistoryOrCollection(this.type).then(res => {
let data = res.data.data let data = res.data.data
for (const item of data) { for (const item of data) {
@@ -85,7 +86,7 @@
item.tags = this.tagsArray[0] item.tags = this.tagsArray[0]
item.create_time = dateFormatHistory(item.create_time) item.create_time = dateFormatHistory(item.create_time)
} }
// console.log('获取历史记录', data); console.log('获取历史记录', data);
this.productList = data this.productList = data
}).finally(_ => { }).finally(_ => {
@@ -96,21 +97,41 @@
var that = this var that = this
uni.showModal({ uni.showModal({
title: '提示', title: '提示',
content: '你确定要除吗', content: '你确定要除吗',
success: function(res) { success: function(res) {
if (res.confirm) { if (res.confirm) {
that.$apiServe.deleteHistoryOrCollection(item.id).then(res => { that.$apiServe.deleteHistoryOrCollection(item.id).then(res => {
if (res.data.code == 1) { if (res.data.code == 1) {
that.$toast.warn('除成功') that.$toast.warn('除成功')
} }
that.getHistoryOrCollection() that.getHistoryOrCollection()
}).finally(_ => {}) }).finally(_ => {})
} else if (res.cancel) { } else if (res.cancel) {
that.$toast.warn('取消除') that.$toast.warn('取消除')
} }
} }
}) })
} },
//取消收藏按钮
cancelCollect(item) {
var that = this
uni.showModal({
title: '提示',
content: '你确定要取消收藏吗',
success: function(res) {
if (res.confirm) {
that.$apiServe.deleteHistoryOrCollection(item.id).then(res => {
if (res.data.code == 1) {
that.$toast.warn('取消收藏成功')
}
that.getHistoryOrCollection()
}).finally(_ => {})
} else if (res.cancel) {
that.$toast.warn('取消操作')
}
}
})
},
} }
} }
</script> </script>

View File

@@ -5,10 +5,10 @@
</u-image> </u-image>
<view class="collect" @click="starTap"> <view class="collect" @click="starTap">
<view class="star"> <view class="star">
<u-image v-if="detailList.type==0" src="/static/detail/xp_icon_wstar.png" width="28rpx" <u-image v-if="detailList.is_fav==0" src="/static/detail/xp_icon_wstar.png" width="28rpx"
height="28rpx"> height="28rpx">
</u-image> </u-image>
<u-image v-if="detailList.type==1" src="/static/detail/xp_icon_star.png" width="28rpx" <u-image v-if="detailList.is_fav==1" src="/static/detail/xp_icon_star.png" width="28rpx"
height="28rpx"> height="28rpx">
</u-image> </u-image>
</view> </view>
@@ -100,6 +100,7 @@
methods: { methods: {
//获取详情信息 //获取详情信息
getProductDetail() { getProductDetail() {
console.log(this.id);
this.$apiServe.getProductDetail(this.id).then(res => { this.$apiServe.getProductDetail(this.id).then(res => {
console.log('产品详情页', res.data) console.log('产品详情页', res.data)
if (res.data.data.thumb) { if (res.data.data.thumb) {
@@ -119,16 +120,15 @@
}, },
//收藏按钮 //收藏按钮
starTap() { starTap() {
this.detailList.type = !this.detailList.type this.$apiServe.collect(this.id).then(res => {
// this.$apiServe.collect(this.id).then(res => { console.log('收藏成功', res.data)
// console.log('收藏成功', res.data) if (res.data.code == 1) {
// if (res.data.code == 1) { this.detailList.is_fav = 1
// this.detailList.type = 1 this.$toast.warn('收藏成功')
// this.$toast.warn('收藏成功') } else {
// } else { this.$toast.warn('收藏失败')
// this.$toast.warn('收藏失败') }
// } }).finally(_ => {})
// }).finally(_ => {})
}, },
//点赞按钮 //点赞按钮
heartTap() { heartTap() {

View File

@@ -326,6 +326,13 @@ const apiService = {
resolve(service.get(url)) resolve(service.get(url))
}) })
}, },
//修改个人信息
getUser() {
const url = `/center/userinfo`
return new Promise((resolve, reject) => {
resolve(service.get(url))
})
},
// 获取首页分类Tag // 获取首页分类Tag
getTags(data) { getTags(data) {
const url = `/home/tags` const url = `/home/tags`