购物车修改

This commit is contained in:
yuanteng0011 2024-12-18 19:40:47 +08:00
parent 45f43ae9c0
commit 6a0aad3fdf
4 changed files with 72 additions and 51 deletions

View File

@ -2,4 +2,4 @@ export const Url = 'http://localhost:9092/api' //后端接口文档
export const testUrl = 'http://123.249.108.160:8888/api' //自己组的服务器接口地址 export const testUrl = 'http://123.249.108.160:8888/api' //自己组的服务器接口地址
export const suiUrl = 'http://154.8.193.216:9092/api' //隋宇霏的接口地址 export const suiUrl = 'http://154.8.193.216:9092/api' //隋宇霏的接口地址
export const baseUrl = testUrl export const baseUrl = Url

View File

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

View File

@ -82,11 +82,8 @@
cookie: wx.getStorageSync('cookie') cookie: wx.getStorageSync('cookie')
}, },
data: { data: {
userId: userInfo.value.id,
goodId: productBrief.value.id, goodId: productBrief.value.id,
quantity: quantity.value, quantity: quantity.value
subtotal: productBrief.value.price * quantity.value,
isGoodType: productBrief.value.isGoodType
} }
}) })
if (res.data.code === 1) { if (res.data.code === 1) {
@ -107,7 +104,7 @@
// //
const decrease = () => { const decrease = () => {
// console.log('index-->',index); // console.log('index-->',index);
if (quantity.value > 0) { if (quantity.value != 1) {
quantity.value -= 1 quantity.value -= 1
} }
} }

View File

@ -2,7 +2,7 @@
<template> <template>
<view class="flex-col page"> <view class="flex-col page">
<view class="flex-col"> <view class="flex-col">
<view class="flex-col justify-start items-end text-wrapper"><text class="font text">编辑</text></view> <view class="flex-col justify-start items-end text-wrapper"><text class="font text" @click="changeState">{{ stateText.topBtn }}</text></view>
<!-- <view class="flex-col justify-start items-end text-wrapper"><text class="font text">完成</text></view> --> <!-- <view class="flex-col justify-start items-end text-wrapper"><text class="font text">完成</text></view> -->
<view class="flex-col section"> <view class="flex-col section">
<view class="flex-row justify-between self-stretch group"> <view class="flex-row justify-between self-stretch group">
@ -20,23 +20,22 @@
<view class="flex-row flex-1 self-center group_2"> <view class="flex-row flex-1 self-center group_2">
<image <image
class="shrink-0 image" class="shrink-0 image"
:src="item.goodVO.goodImg" :src="item.cartGoodVO.goodImg"
@click="jump_product" @click="jump_product"
/> />
<view class="flex-col flex-1 group_3 ml-12"> <view class="flex-col flex-1 group_3 ml-12">
<view class="flex-row group_4"> <view class="flex-row group_4">
<text class="font_2" @click="jump_product">{{ item.goodVO.name }}</text> <text class="font_2" @click="jump_product">{{ item.cartGoodVO.name }}</text>
<text class="font_2 ml-4" @click="jump_product">{{ item.goodVO.type }}</text> <text class="font_2 ml-4" @click="jump_product">{{ item.cartGoodVO.type }}</text>
</view> </view>
<view class="flex-row items-center mt-47"> <view class="flex-row items-center mt-47">
<view class="flex-row items-center self-stretch group_5"> <view class="flex-row items-center self-stretch group_5">
<text class="font_3 text_3" @click="jump_product"><text class="font_4"></text>{{ item.goodVO.price }}.<text class="font_4">00</text></text> <text class="font_3 text_3" @click="jump_product"><text class="font_4"></text>{{ item.cartGoodVO.price }}</text>
<!-- <image <!-- <image
class="image_6" class="image_6"
src="https://carbon2.obs.cn-north-4.myhuaweicloud.com:443/feiyi%2Ftest%2F0%2FJipaVPoQ-storeRmb.png" src="https://carbon2.obs.cn-north-4.myhuaweicloud.com:443/feiyi%2Ftest%2F0%2FJipaVPoQ-storeRmb.png"
/> --> /> -->
</view> </view>
</view> </view>
</view> </view>
</view> </view>
@ -122,7 +121,7 @@
src="https://carbon2.obs.cn-north-4.myhuaweicloud.com:443/feiyi%2Ftest%2F0%2FJipaVPoQ-storeRmb.png" src="https://carbon2.obs.cn-north-4.myhuaweicloud.com:443/feiyi%2Ftest%2F0%2FJipaVPoQ-storeRmb.png"
/> />
<text class="font text_12">{{ totalPrice }}</text> <text class="font text_12">{{ totalPrice }}</text>
<view class="flex-col justify-start items-center shrink-0 text-wrapper_3" @click="goToBuy"><text class="text_11">去结算</text></view> <view class="flex-col justify-start items-center shrink-0 text-wrapper_3" @click="editOrSettle"><text class="text_11">{{ stateText.bottomBtn }}</text></view>
<!-- <view class="flex-col justify-start items-center shrink-0 text-wrapper_3"><text class="text_11">删除</text></view> --> <!-- <view class="flex-col justify-start items-center shrink-0 text-wrapper_3"><text class="text_11">删除</text></view> -->
</view> </view>
</view> </view>
@ -130,7 +129,7 @@
</template> </template>
<script setup> <script setup>
import { ref , onMounted} from 'vue' import { ref , onMounted , toRaw} from 'vue'
import { onShow } from "@dcloudio/uni-app"; import { onShow } from "@dcloudio/uni-app";
import { baseUrl , testUrl ,suiUrl} from '../../../api/request'; import { baseUrl , testUrl ,suiUrl} from '../../../api/request';
const products = ref([]) const products = ref([])
@ -139,12 +138,12 @@ const allCheck = ref(false) //全选
const checkedData = ref([]) // const checkedData = ref([]) //
const totalPrice = ref(0) const totalPrice = ref(0)
const userInfo = wx.getStorageSync('userInfo') const userInfo = wx.getStorageSync('userInfo')
onMounted(()=>{ const stateText = ref({
topBtn: '编辑',
bottomBtn: '去结算'
}) })
onShow(()=>{ onShow(()=>{
getProductCart() // getProductCart() //
// getServiceCart()
}) })
//id //id
const getProductCart = async ()=>{ const getProductCart = async ()=>{
@ -155,14 +154,13 @@ const getProductCart = async ()=>{
'cookie': wx.getStorageSync('cookie') 'cookie': wx.getStorageSync('cookie')
} }
}) })
// console.log(res.data); // console.log('res--->',res.data);
if(res.data.code === 1) { if(res.data.code === 1) {
products.value = res.data.data products.value = res.data.data
products.value.forEach((item)=>{ products.value.forEach((item)=>{
item.checked = false item.checked = false
}) })
} }
console.log('res--->',res);
console.log('products-->',products.value); console.log('products-->',products.value);
} }
const getServiceCart =()=>{ const getServiceCart =()=>{
@ -181,27 +179,32 @@ const getTextStyle = (num) => ({
}); });
// //
const checkBoxChange =(event)=>{ const checkBoxChange =(event)=>{
console.log('方法被触发');
//checkboxvalue allChecktrue //checkboxvalue allChecktrue
console.log('length---->',event.detail.value.length); console.log('length---->',event.detail.value.length);
// console.log('product--->',products.value);
if(event.detail.value.length == products.value.length) { if(event.detail.value.length == products.value.length) {
allCheck.value = true allCheck.value = true
} else { } else {
allCheck.value = false allCheck.value = false
} }
checkedData.value = [{}] // checkedData.value = [] //
totalPrice.value = 0; totalPrice.value = 0;
let count = 0; //checkedDatanull let count = 0; //checkedDatanull
console.log('event--->',event.detail); console.log('event--->',event.detail);
if(event.detail.value.length) {
products.value[parseInt(event.detail.value)].checked = true; // products.value[parseInt(event.detail.value)].checked = true; //
} else {
products.value.forEach((item)=>{
item.checked = false
})
}
// //
for(let key in event.detail.value) { for(let key in event.detail.value) {
let temp = parseInt(event.detail.value[parseInt(key)]) // let temp = parseInt(event.detail.value[parseInt(key)]) //
computed(products.value[temp].goodVO.price , products.value[temp].quantity) computed(products.value[temp].cartGoodVO.price , products.value[temp].quantity)
} }
event.detail.value.forEach((item)=>{ event.detail.value.forEach((item)=>{
products.value[parseInt(item)].checked = true products.value[parseInt(item)].checked = true
// allCheck.value = false
}) })
//checkboxGroup detail.valueidcheckedtrue() //checkboxGroup detail.valueidcheckedtrue()
products.value.forEach((x)=>{ products.value.forEach((x)=>{
@ -215,10 +218,11 @@ const checkBoxChange =(event)=>{
console.log('products.value[parseInt(item)].goodId',products.value[parseInt(item)].goodId); console.log('products.value[parseInt(item)].goodId',products.value[parseInt(item)].goodId);
if(products.value[parseInt(item)] !== null) { if(products.value[parseInt(item)] !== null) {
// console.log('item--->',item); // console.log('item--->',item);
checkedData.value[count] = { // checkedData.value[count] = {
goodId: products.value[parseInt(item)].goodId, // goodId: products.value[parseInt(item)].goodId,
quantity: products.value[parseInt(item)].quantity, // quantity: products.value[parseInt(item)].quantity,
} // }
checkedData.value.push(products.value[parseInt(item)].id)
// console.log(products.value[parseInt(item)].goodId); // console.log(products.value[parseInt(item)].goodId);
count += 1 count += 1
} }
@ -235,13 +239,13 @@ const allChecked = ()=>{
if ( allCheck.value == true ) { if ( allCheck.value == true ) {
products.value.forEach((item)=>{ products.value.forEach((item)=>{
item.checked = true // item.checked = true //
// console.log('item--->',item); computed(item.cartGoodVO.price , item.quantity)
computed(item.goodVO.price , item.quantity)
}) })
checkedData.value = products.value.map((item)=>({ // checkedData.value = products.value.map((item)=>({
goodId: item.goodId, // goodId: item.goodId,
quantity: item.quantity // quantity: item.quantity
})) //checkedData // })) //checkedData
checkedData.value = products.value.map((item)=>( item.id ))
console.log('checkedData--->',checkedData.value); console.log('checkedData--->',checkedData.value);
} else { } else {
products.value.forEach((item)=>{ products.value.forEach((item)=>{
@ -251,22 +255,24 @@ const allChecked = ()=>{
} }
// //
const decrease =(index , item)=>{ //item const decrease =(index , item)=>{ //item
// console.log('index-->',index); console.log('decrease,index-->',index);
// console.log('item-->',item); console.log('decrease,item-->',item);
if(products.value[index].quantity > 1) { if(products.value[index].quantity > 1) {
products.value[index].quantity -= 1 products.value[index].quantity -= 1
if(item && products.value[index].quantity >= 1) { if(item && products.value[index].quantity >= 1) {
computed(-products.value[index].goodVO.price, 1) computed(-products.value[index].cartGoodVO.price, 1)
} }
} }
} }
// 11.8 //
const increase =(index , item) =>{ //item const increase =(index , item) =>{ //item
console.log('increase,index-->',index);
console.log('increase,item-->',item);
if(products.value[index].quantity <= 99) { if(products.value[index].quantity <= 99) {
products.value[index].quantity += 1 products.value[index].quantity += 1
} }
if(item) { if(item) {
computed(products.value[index].goodVO.price, 1) computed(products.value[index].cartGoodVO.price, 1)
} }
} }
// //
@ -279,11 +285,36 @@ const jump_product =()=>{
url:'../../../pages/store-home/ProductDetails/ProductDetails' url:'../../../pages/store-home/ProductDetails/ProductDetails'
}) })
} }
const goToBuy =()=>{ const editOrSettle = async ()=>{
console.log('要传到订单详情页面的checked--->',checkedData.value); // console.log('checked--->',checkedData.value);
if(stateText.value.bottomBtn === '去结算') {
uni.navigateTo({ uni.navigateTo({
url: '/pages/order/product-waitpay/product-waitpay?cartInfo=' + JSON.stringify(checkedData.value) url: '/pages/order/product-waitpay/product-waitpay?cartInfo=' + JSON.stringify(checkedData.value)
}) })
} else {
const res = await uni.request({
url: baseUrl + '/cart/delete',
method: 'POST',
data: checkedData.value ,
header: {
'cookie': wx.getStorageSync('cookie')
}
})
console.log(res.data);
if(res.data.code === 1) {
getProductCart() //
totalPrice.value = 0
}
}
}
const changeState =()=>{ //
if(stateText.value.topBtn === '编辑') {
stateText.value.topBtn = '完成',
stateText.value.bottomBtn = '删除'
} else {
stateText.value.topBtn = '编辑',
stateText.value.bottomBtn = '去结算'
}
} }
</script> </script>