更新购物车

This commit is contained in:
wwz
2025-03-28 18:29:06 +08:00
parent 75e5fb65be
commit 10a47abe13
12 changed files with 299 additions and 195 deletions

View File

@@ -7,7 +7,6 @@
<scroll-view scroll-y class="scroll-view">
<view class="head">
<view class="head_bg"></view>
<!-- <view class="tips" v-if="shopInfo.registerType == 'before'"> -->
<view class="tips">
<image class="informIcon"
src="https://czg-qr-order.oss-cn-beijing.aliyuncs.com/confirmOrder/informIcon.png"
@@ -65,32 +64,27 @@
<image class="img" :src="item.coverImg" mode="aspectFill" />
<view class="center">
<text class="center_title"> {{item.name}} </text>
<text class="type" v-if="item.skuList">
<text class="type" v-if="item.skuList && item.type == 'sku'">
<text v-for="i in item.skuList" :key="i.id">
{{item.id == i.productId && item.skuId == i.id ? i.specInfo :""}}
{{item.cartListinfo.sku_id == i.id ? i.name :""}}
</text>
</text>
<text class="type" v-if="item.type == 'package'">
<text v-for="(a,b) in dataprocessing(item.cartListinfo)" :key="b">
<text v-for="i in a.goods" :key="i.proId" style="margin-left: 4rpx;">
{{i.proName }}
</text>
</text>
</text>
<text class="num"> X{{ ifcartNumber(item) }}</text>
</view>
</view>
<text
class="price">{{shopInfo.isVip ==1 && shopInfo.isMemberPrice==1?(item.memberPrice||item.salePrice):item.salePrice}}</text>
<text class="price">
{{shopInfo.isVip ==1 && shopInfo.isMemberPrice==1?(item.memberPrice||item.salePrice):item.salePrice}}
</text>
</view>
<!-- 餐位费 -->
<view class="cell-item" v-if="shopTable.useNum>0">
<view class="label">餐位费</view>
<view class="val">
<view>X{{shopTable.seatNum}}</view>
<view style="font-size: 28rpx;"></view>
<view>{{Seatcharge}}</view>
</view>
</view>
<!-- <view class="totalPrice">
<text style="margin-bottom: 5rpx;">小计</text>
<text class="totalPriceNum"> {{totalCost}} </text>
</view> -->
<!-- <u-divider color="#fa3534" half-width="200" border-color="#6d6d6d">姑苏城外寒山寺</u-divider> -->
</view>
</view>
@@ -103,28 +97,12 @@
</view>
</view>
<!-- 支付方式 -->
<!-- <view style="padding: 0 20rpx;" v-if="shopInfo.registerType == 'before'">
<paymentMethod ref="paymentMethodref" @groupChange="groupChange">
</paymentMethod>
</view> -->
<!-- boutton -->
<view style="width: 100%;height: 200rpx;"> </view>
<view class="bottom">
<view class="bottom_left">
<text style="margin-bottom: 5rpx;">实付金额</text>
<text class="totalAmount">{{ totalPrices }} </text>
</view>
<!-- <block v-if="shopInfo.registerType == 'before'">
<view class="paymentBtnText" @tap="$u.debounce(orderdetail, 500)" v-if="shopInfo">
{{ paymentmethod.paymentBtnText }}
</view>
<view class="paymentBtnText" @tap="$u.debounce(orderdetail, 500)" v-else>
{{ paymentmethod.paymentBtnText }}
</view>
</block>
<block v-if="shopInfo.registerType == 'after'"> -->
<block>
<view class="paymentBtnText" @tap="$u.debounce(orderdetail, 500)"> 提交订单 </view>
</block>
@@ -231,7 +209,7 @@
if (shopInfo.isVip == 1 && shopInfo.isMemberPrice == 1) {
// memberPrice会员价
return total + parseFloat(item.memberPrice || item.salePrice) * parseFloat(item
.cartNumber);
.cartNumber);
} else {
// salePrice销售价
return total + parseFloat(item.salePrice || 0) * parseFloat(item.cartNumber);
@@ -353,7 +331,17 @@
// }
}
const dataprocessing = computed(() => {
return (item) => {
let res = null
try {
res = JSON.parse(item.pro_group_info)
} catch (error) {
//TODO handle the exception
}
return res
};
})
const thisdata = reactive({
opacitys: false,

View File

@@ -141,23 +141,26 @@
}
// 购物车加减
const cartListadd = async (item, i) => {
// 是否起售 如果小于或者大于都是1
const cartNumberFloat = parseFloat(item.cartNumber);
const suitNum = item.suitNum >= cartNumberFloat && i == '-' ? item.cartNumber : 1;
emits('customevent', {
id: item.cartListId ? item.cartListId : '',
type: 'shopping',
table_code: uni.cache.get('tableCode'),
shop_id: uni.cache.get('shopId'),
operate_type: calculateValue(item.cartNumber, i) == 'del' ? 'del' : item.cartListId &&
operate_type: calculateValue(item.cartNumber, i, suitNum) == 'del' ? 'del' : item.cartListId &&
item.cartNumber > 0 ? 'edit' : 'add',
product_id: item.id,
sku_id: item.skuId,
number: await calculateValue(item.cartNumber, i),
number: await calculateValue(item.cartNumber, i, suitNum),
is_print: 1,
})
}
const dataprocessing = computed(() => {
return (item) => {
console.log(item.pro_group_info)
let res = null
try {
res = JSON.parse(item.pro_group_info)
@@ -168,16 +171,16 @@
};
})
// 封装加法函数
const calculateValue = (cartNumber, i, step = 1) => {
if (i == '+') {
const result = parseFloat(cartNumber) + step;
const result = parseFloat(cartNumber) + parseFloat(step);
return result.toFixed(2);
} else {
const result = parseFloat(cartNumber) - step;
// 当减到0返回del
const result = parseFloat(cartNumber) - parseFloat(step);
return result == 0 ? 'del' : result.toFixed(2);
}
};
}
// 菜品备注修改
const productBlur = (item) => {

View File

@@ -43,6 +43,9 @@
<view class="panelfiveitemthere flex-start">
<text>招牌</text>
</view>
<view class="describe" v-if="item.suitNum>1 && item.type!= 'sku'" style="font-size: 20rpx;">
{{item.suitNum}}{{item.unitName}}起点
</view>
<!-- <view class="panelfiveitemfour">
{{item.shortTitle?item.shortTitle:''}}
</view>
@@ -56,10 +59,9 @@
<text class="tips"
:class="shopInfo.isVip == 0 || shopInfo.isMemberPrice==0?'lineThrough':''">¥</text>
<!-- 会员价与价格 -->
<text
class="price">{{shopInfo.isVip ==1 && shopInfo.isMemberPrice==1?(item.memberPrice||item.salePrice):item.salePrice}}</text>
<!-- 原价 -->
<!-- <text class="originalprice" v-if="item.originPrice">¥{{item.originPrice}}</text> -->
<text class="price">
{{shopInfo.isVip ==1 && shopInfo.isMemberPrice==1?(item.memberPrice||item.salePrice):item.salePrice}}
</text>
<!-- 单位 -->
<text class="unit" v-if="item.unitName">/{{item.unitName}}</text>
</view>
@@ -72,18 +74,19 @@
</view>
</view>
<view v-else class="flex-between" style="margin-top: 32rpx;margin-bottom: 48rpx;">
<view v-else class="flex-between"
style="margin-top: 32rpx;margin-bottom: 48rpx; flex-wrap: inherit">
<view class="panelfiveitemsex flex-between">
<view class="panelfiveitemsex_oen">
<text class="tips"
:class="shopInfo.isVip ==0 || shopInfo.isMemberPrice==0?'lineThrough':''">¥</text>
<!-- 会员价与价格 -->
<text
class="price">{{shopInfo.isVip ==1 && shopInfo.isMemberPrice==1?(item.memberPrice|| item.salePrice):item.salePrice}}</text>
<!-- 原价 -->
<!-- <text class="originalprice" v-if="item.originPrice">¥{{item.originPrice}}</text> -->
<!-- 单位 -->
<text class="price">
{{shopInfo.isVip ==1 && shopInfo.isMemberPrice==1?(item.memberPrice|| item.salePrice):item.salePrice}}
</text>
<text class="unit" v-if="item.unitName">/{{item.unitName}}</text>
<!-- <text v-if="item.suitNum>1 && item.type!= 'sku'"
style="font-size: 16rpx;">{{item.suitNum}}{{item.unitName}}起点</text> -->
</view>
</view>
<!-- single-单规格商品 sku-多规格商品 package-套餐商品 weight-称重商品 coupon-团购券 -->
@@ -105,8 +108,6 @@
</view>
</view>
<text class="num"> {{ ifcartNumber(item) }} </text>
<!-- <text class="dot num"
v-if="item.suitNum>1">{{item.suitNum<99?item.suitNum:'99+'}}</text> -->
<view class="btn">
<up-icon name="plus-circle-fill" color="#E9AB7A" size="25"></up-icon>
<view class="btnClick"
@@ -162,6 +163,11 @@
<view class="lookBack" v-if="specifications.item.isHot == 1">热销</view>
<view class="describe"> {{item1.shortTitle?item1.shortTitle:''}} </view>
<view class="describe" v-if="item1.suitNum>1 && item1.type!= 'sku'"
style="font-size: 20rpx;">
{{item1.suitNum}}{{item1.unitName}}起点
</view>
<view v-if="item1.isSoldStock == 1 || item1.isSaleTime == 0" class="flex-between">
<view class="money">
<view></view>
@@ -177,13 +183,17 @@
</view>
</view>
</view>
<view v-else class="flex-between">
<view v-else class="flex-between" style="flex-wrap: inherit;">
<view class="money">
<view></view>
<text class="money_num" style="margin-right: 10rpx;">
<text class="money_num">
{{shopInfo.isVip ==1 && shopInfo.isMemberPrice==1?(item1.memberPrice||item1.salePrice):item1.salePrice}}
</text>
<text v-if="item1.unitName">/{{item1.unitName}}</text>
<text class="money_num" v-if="item1.unitName">/{{item1.unitName}}</text>
<!-- <text v-if="item1.suitNum>1 && item1.type!= 'sku'"
style="font-size: 14rpx;">
{{item1.suitNum}}{{item1.unitName}}起点
</text> -->
</view>
<view class="flex-end"
v-if="item1.type == 'sku' || (item1.type == 'package' && item1.groupType == '1')">
@@ -233,8 +243,8 @@
<!-- 店铺详情 -->
<shopindex ref="showShopInfoRef"></shopindex>
<!-- 购物车 -->
<shoppingCartes :cartLists_count="cartLists_count" :cartList="matchedProducts" :showCart="showCart"
@customevent='websocketsendMessage' @close="showCart = !showCart">
<shoppingCartes :cartLists_count="cartLists_count" v-if="matchedProducts.length>0" :cartList="matchedProducts"
:showCart="showCart" @customevent='websocketsendMessage' @close="showCart = !showCart">
</shoppingCartes>
<!-- 显示购物车栏 -->
@@ -325,12 +335,21 @@
<text
class="num">{{shopInfo.isVip ==1 && shopInfo.isMemberPrice==1? (specifications.item.result.memberPrice||specifications.item.result.salePrice):specifications.item.result.salePrice}}</text>
<text class="i" v-if="specifications.item.unitName">/{{specifications.item.unitName}}</text>
<text v-if="specifications.item.result.suitNum>1">
{{specifications.item.result.suitNum}}{{specifications.item.result.unitName}}起点
</text>
</view>
<view class="price" v-else>
<text class="i"></text>
<text
class="num">{{shopInfo.isVip ==1 && shopInfo.isMemberPrice==1? (specifications.item.memberPrice||specifications.item.salePrice):specifications.item.salePrice}}</text>
<text class="i" v-if="specifications.item.unitName">/{{specifications.item.unitName}}</text>
<text class="num">
{{shopInfo.isVip ==1 && shopInfo.isMemberPrice==1? (specifications.item.memberPrice||specifications.item.salePrice):specifications.item.salePrice}}
</text>
<text class="i" v-if="specifications.item.unitName">
/{{specifications.item.unitName}}
</text>
<text v-if="specifications.item.suitNum>1">
{{specifications.item.suitNum}}{{specifications.item.unitName}}起点
</text>
</view>
@@ -393,6 +412,7 @@
import shoppingCartes from './components/shoppingCartes.vue'
import confirmorder from './components/confirmorder.vue'
import Loading from '@/components/Loading.vue';
// 获取全局属性
const {
proxy
@@ -468,9 +488,7 @@
try {
const shopExtend = uni.cache.get('shopTable').shopExtendMap.shopinfo_bg
} catch (error) {
//TODO handle the exception
}
} catch (error) {}
// 计算高度
const navScroll = ref(null)
@@ -591,11 +609,6 @@
uni.$u.debounce(store.scrollTop = res.scrollTop, 500)
uni.$u.debounce(navScroll.value = res.scrollTop, 500)
uni.$u.debounce(mainScroll(res), 500)
if (res.scrollTop >= 44) {
// store.showSearch = true
} else {
// store.showSearch = false
}
});
// 点击详情
@@ -683,8 +696,6 @@
}
};
// 存储选中的选项
// 监听 specifications 的变化
watch(
() => specifications.item.groupSnap,
@@ -695,7 +706,6 @@
}
);
// 存储选中的选项,二维数组
const selectedOptions = ref(
specifications.item.groupSnap.map(() => [])
@@ -763,12 +773,25 @@
//添加购物车数量
const shopCartNumber = ref(0)
// 多规格 去添加购物车
const shopCart = (i) => {
if (i == '+') {
shopCartNumber.value++;
// 多规格 套餐添加数量
const shopCart = async (i) => {
let res = await shoppingcart()
if (i == '-') {
if (!res && shopCartNumber.value == specifications.item.suitNum) {
uni.showToast({
title: `起点${specifications.item.suitNum}`,
icon: 'none'
})
return false;
} else {
shopCartNumber.value--;
}
} else {
shopCartNumber.value--;
if (!res && shopCartNumber.value < 1) {
shopCartNumber.value = parseFloat(specifications.item.suitNum);
} else {
shopCartNumber.value++;
}
}
}
@@ -844,62 +867,65 @@
});
}
// 判断多规格和套餐 商品是否在购物车有数据
const shoppingcart = async () => {
let res = null
if (specifications.item.type == "package") {
if (!allConditionsSatisfied.value) {
return false
}
// 是否是套餐package
selectedGroupSnap.value = specifications.item.groupSnap.map((setmenu, index) => {
return {
...setmenu,
goods: selectedOptions.value[index]
};
});
res = await matchingProduct(selectedGroupSnap.value)
} else {
if (!canSubmit.value) {
return false
}
res = await matchingProduct(specifications.item.result)
}
return res;
}
// 提交选择并执行下一步操作的方法
const submitSelection = async () => {
if (shopCartNumber.value <= 0) {
return;
}
let res = await shoppingcart()
console.log(res)
if (shopCartNumber.value > 0) {
let res = null
if (specifications.item.type == "package") {
if (!allConditionsSatisfied.value) {
return false
}
// 是否是套餐package
selectedGroupSnap.value = specifications.item.groupSnap.map((setmenu, index) => {
return {
...setmenu,
goods: selectedOptions.value[index]
};
});
res = await matchingProduct(selectedGroupSnap.value)
} else {
if (!canSubmit.value) {
return false
}
res = await matchingProduct(specifications.item.result)
}
console.log(res, 'res')
if (res) {
await calculateValue(res.cartNumber, '+', shopCartNumber.value)
}
// 是否是套餐 有就传
if (specifications.item.type != "package") {
selectedGroupSnap.value = []
}
websocketsendMessage({
id: res ? res.cartListId : '',
type: 'shopping',
table_code: uni.cache.get('tableCode'),
shop_id: uni.cache.get('shopId'),
operate_type: res ? 'edit' : 'add',
product_id: specifications.product_id,
sku_id: specifications.sku_id,
number: res ? await calculateValue(res.cartNumber, '+', shopCartNumber.value) :
shopCartNumber.value,
pro_group_info: selectedGroupSnap.value,
goods_type: specifications.item.type == "package" ? 'package' : '',
is_print: 1,
product_type: specifications.item.type
})
// 清空套餐选中
// 是否是套餐 有就传
if (specifications.item.type != "package") {
selectedGroupSnap.value = []
showShopsku.value = false
}
websocketsendMessage({
id: res ? res.cartListId : '',
type: 'shopping',
table_code: uni.cache.get('tableCode'),
shop_id: uni.cache.get('shopId'),
operate_type: res ? 'edit' : 'add',
product_id: specifications.product_id,
sku_id: specifications.sku_id,
number: res ? await calculateValue(res.cartNumber, '+', shopCartNumber.value) : shopCartNumber
.value,
pro_group_info: selectedGroupSnap.value,
goods_type: specifications.item.type == "package" ? 'package' : '',
is_print: 1,
product_type: specifications.item.type
})
// 清空套餐选中
selectedGroupSnap.value = []
showShopsku.value = false
}
//获取多规格数据
const clickspecifications = async (item, index, indexs, type) => {
if (item.isSoldStock == 1 || item.isSaleTime == 0) {
@@ -939,6 +965,7 @@
// 单规格
const singleclick = async (item, i) => {
console.log(item)
// 判断购物车是否有该选中商品
let res = null
try {
@@ -948,15 +975,24 @@
} catch (error) {
//TODO handle the exception
}
// 是否起售 如果小于或者大于都是1
let suitNum = 1;
const cartNumberFloat = parseFloat(item.cartNumber);
if (!res && item.suitNum > cartNumberFloat) {
suitNum = item.suitNum;
} else if (item.suitNum >= cartNumberFloat && i === '-') {
suitNum = item.cartNumber;
}
websocketsendMessage({
id: res ? item.cartListId : '',
type: 'shopping',
table_code: uni.cache.get('tableCode'),
shop_id: uni.cache.get('shopId'),
operate_type: await calculateValue(item.cartNumber, i) == 'del' ? 'del' : res ? 'edit' : 'add',
operate_type: await calculateValue(item.cartNumber, i, suitNum) == 'del' ? 'del' : res ?
'edit' : 'add',
product_id: item.id,
sku_id: item.skuId,
number: await calculateValue(item.cartNumber, i),
number: await calculateValue(item.cartNumber, i, suitNum),
is_print: 1,
product_type: item.type
})
@@ -1379,11 +1415,12 @@
} else {
uni.showToast({
title: '暂无列表数据...'
title: '暂无列表数据,请重新扫码',
icon: "none"
});
isDataLoaded.value = false;
setTimeout(() => {
uni.navigateBack()
uni.pro.switchTab('index/index')
}, 1000)
return false;
}