小程序及我的收藏接口对接 #71

Merged
pikvyz67s merged 1 commits from Brunch_DBK into main 1 month ago

@ -10,4 +10,13 @@ export const cancelOrderApi = (parm) => {
}
export const commentListApi = (parm) => {
return http.get("/wxapi/comment/commentList", parm)
}
export const addCollectApi = (parm) => {
return http.post("/wxapi/collect/addCollect", parm)
}
export const hasCollectApi = (parm) => {
return http.get("/wxapi/collect/hasCollect", parm)
}
export const cancelCollectApi = (parm) => {
return http.post("/wxapi/collect/cancelCollect", parm)
}

@ -92,4 +92,10 @@ export const saveOrUpdateApi = (parm) => {
//新增评论
export const addCommentApi = (parm) => {
return http.post("/wxapi/comment/addComment", parm)
}
export const listCollectApi = (parm) => {
return http.get("/wxapi/collect/list", parm)
}
export const deleteCollectApi = (parm) => {
return http.post("/wxapi/collect/deleteCollect", parm)
}

@ -65,6 +65,13 @@
{
"navigationBarTitleText" : ""
}
},
{
"path" : "pages/collect/collect",
"style" :
{
"navigationBarTitleText" : ""
}
}
],
"globalStyle": {

@ -0,0 +1,164 @@
<template>
<view class="item" v-for="(res, index) in siteList.list" :key="res.id">
<image class="uimage" :src="res.goodsImage.split(',')[0]"></image>
<view style="flex-grow: 1;display: flex;justify-content: space-between;">
<view class="top">
<view class="name">{{ res.goodsName }}</view>
</view>
<view class="bottom">
<u-icon @click="update(res)" name="close" :size="35" color="#999999"></u-icon>
</view>
</view>
</view>
</template>
<script setup>
import {
onLoad,
onShow
} from '@dcloudio/uni-app';
import {
reactive,
ref
} from 'vue'
import {
addressStore
} from '../../store/address.js'
import {
listCollectApi,
deleteCollectApi
} from '../../api/user.js'
const store = addressStore()
const avatarUrl = ref('/static/user.jpg')
//
const siteList = reactive({
list: []
})
//
const getList = async () => {
let res = await listCollectApi({
openid: uni.getStorageSync('openid')
})
console.log(res)
if (res && res.code == 200) {
siteList.list = res.data
}
}
//
const toAddSite = () => {
uni.navigateTo({
url: '../address/address'
});
}
//
const update = async (item) => {
console.log(item)
let res = await deleteCollectApi({
collectId: item.collectId
})
if (res && res.code == 200) {
uni.showToast({
icon: 'none',
title: res.msg
})
getList()
}
}
//
const radioChange = (e) => {
console.log(e)
if (e.detail.value) {
let item = JSON.parse(e.detail.value)
store.checkedId = item.addressId
store.userName = item.userName
store.phone = item.phone
store.area = item.area
store.address = item.address
//
uni.navigateBack()
}
}
onShow(() => {
getList()
})
</script>
<style lang="scss" scoped>
.uimage {
height: 50px;
width: 50px;
border-radius: 50%;
margin: 5px 10px 5px 0px;
}
.item {
padding: 40rpx 20rpx;
display: flex;
align-items: center;
border-bottom: 1px solid #efefef;
.top {
display: flex;
font-weight: bold;
font-size: 34rpx;
.phone {
margin-left: 60rpx;
}
.tag {
display: flex;
font-weight: normal;
align-items: center;
text {
display: block;
width: 60rpx;
height: 34rpx;
line-height: 34rpx;
color: #ffffff;
font-size: 20rpx;
border-radius: 6rpx;
text-align: center;
margin-left: 30rpx;
background-color: rgb(49, 145, 253);
}
.red {
background-color: red
}
}
}
.bottom {
display: flex;
margin-top: 20rpx;
font-size: 28rpx;
justify-content: space-between;
color: #999999;
}
}
.addSite {
display: flex;
justify-content: space-around;
width: 600rpx;
line-height: 100rpx;
position: absolute;
bottom: 30rpx;
left: 80rpx;
background-color: #F3AF28;
border-radius: 60rpx;
font-size: 30rpx;
.add {
display: flex;
align-items: center;
color: #ffffff;
.icon {
margin-right: 10rpx;
}
}
}
</style>

@ -63,6 +63,11 @@
<u-icon name="home" :size="40" :color="$u.color['contentColor']"></u-icon>
<view class="text u-line-1">首页</view>
</view>
<view class="item" @click="toCollect">
<u-icon v-if="hasCollect == '1'" color="#F3AF28" :size="40" name="star"></u-icon>
<u-icon v-if="hasCollect == '0'" :size="40" name="star"></u-icon>
<view class="text u-line-1">收藏</view>
</view>
<view class="item car" @click="toCar">
<u-badge class="car-num" :count="carCount" type="error" :offset="[-3, -6]"></u-badge>
<u-icon name="shopping-cart" :size="40" :color="$u.color['contentColor']"></u-icon>
@ -91,7 +96,10 @@
carStore
} from '../../store/car.js'
import {
commentListApi
commentListApi,
addCollectApi,
hasCollectApi,
cancelCollectApi
} from '../../api/order.js'
import {
orderStore
@ -107,6 +115,7 @@
const carCount = computed(() => {
return store.carList.length
})
const hasCollect = ref('0')
//
const content = ref('')
const current = ref(0)
@ -220,6 +229,48 @@
url: '../car/car'
});
}
//
const toCollect = async () => {
if (hasCollect.value == '0') { //
let res = await addCollectApi({
openid: uni.getStorageSync('openid'),
goodsId: carData.value.goodsId
})
if (res && res.code == 200) {
hasCollectMeth()
uni.showToast({
icon: 'none',
title: res.msg
})
}
} else { //
let res = await cancelCollectApi({
openid: uni.getStorageSync('openid'),
goodsId: carData.value.goodsId
})
if (res && res.code == 200) {
hasCollectMeth()
uni.showToast({
icon: 'none',
title: res.msg
})
}
}
}
const hasCollectMeth = async () => {
let res = await hasCollectApi({
openid: uni.getStorageSync('openid'),
goodsId: carData.value.goodsId
})
console.log(res)
if (res.data && res.data == '1') {
hasCollect.value = '1'
} else {
hasCollect.value = '0'
}
}
onLoad((options) => {
userLogin()
const goods = JSON.parse(options.goods)
@ -237,6 +288,7 @@
carData.value.specsName = goods.specs[0].specsName
carData.value.price = goods.specs[0].goodsPrice
carData.value.goodsImage = goods.goodsImage.split(',')[0]
hasCollectMeth()
getCommentList()
nextTick(() => {
setSwiperHeight()

Loading…
Cancel
Save