|
|
@ -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('方法被触发');
|
|
|
|
|
|
|
|
//如果选中的checkbox的value的数组长度和后端传过来的数组长度相等则为全选状态 allCheck为true
|
|
|
|
//如果选中的checkbox的value的数组长度和后端传过来的数组长度相等则为全选状态 allCheck为true
|
|
|
|
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; //用于记录checkedData不为null的个数
|
|
|
|
let count = 0; //用于记录checkedData不为null的个数
|
|
|
|
console.log('event--->',event.detail);
|
|
|
|
console.log('event--->',event.detail);
|
|
|
|
products.value[parseInt(event.detail.value)].checked = true; //勾选
|
|
|
|
if(event.detail.value.length) {
|
|
|
|
|
|
|
|
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.value中有某个id则把这些元素的checked属性置为true(选中状态)
|
|
|
|
//然后假如checkboxGroup传过来的 detail.value中有某个id则把这些元素的checked属性置为true(选中状态)
|
|
|
|
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);
|
|
|
|
uni.navigateTo({
|
|
|
|
if(stateText.value.bottomBtn === '去结算') {
|
|
|
|
url: '/pages/order/product-waitpay/product-waitpay?cartInfo=' + JSON.stringify(checkedData.value)
|
|
|
|
uni.navigateTo({
|
|
|
|
})
|
|
|
|
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>
|
|
|
|
|
|
|
|
|
|
|
|