购物车计算
This commit is contained in:
@@ -52,12 +52,12 @@
|
||||
<view class="panelfiveitemsex flex-between">
|
||||
<view class="panelfiveitemsex_oen">
|
||||
<text class="tips"
|
||||
:class="shopInfo.isVip ==0 || shopInfo.isMemberPrice==0?'lineThrough':''">¥</text>
|
||||
:class="shopInfo.isVip == 0 || shopInfo.isMemberPrice==0?'lineThrough':''">¥</text>
|
||||
<!-- 会员价与价格 -->
|
||||
<text
|
||||
class="price">{{shopInfo.isVip ==1 && shopInfo.isMemberPrice==1?item.memberPrice:item.salePrice}}</text>
|
||||
<!-- 原价 -->
|
||||
<text class="originalprice" v-if="item.originPrice">¥{{item.originPrice}}</text>
|
||||
<!-- <text class="originalprice" v-if="item.originPrice">¥{{item.originPrice}}</text> -->
|
||||
<!-- 单位 -->
|
||||
<text class="unit" v-if="item.unitName">/{{item.unitName}}</text>
|
||||
</view>
|
||||
@@ -79,7 +79,7 @@
|
||||
<text
|
||||
class="price">{{shopInfo.isVip ==1 && shopInfo.isMemberPrice==1?item.memberPrice:item.salePrice}}</text>
|
||||
<!-- 原价 -->
|
||||
<text class="originalprice" v-if="item.originPrice">¥{{item.originPrice}}</text>
|
||||
<!-- <text class="originalprice" v-if="item.originPrice">¥{{item.originPrice}}</text> -->
|
||||
<!-- 单位 -->
|
||||
<text class="unit" v-if="item.unitName">/{{item.unitName}}</text>
|
||||
</view>
|
||||
@@ -164,12 +164,12 @@
|
||||
<text class="money_num"
|
||||
v-if="shopInfo.isVip ==1 && shopInfo.isMemberPrice==1"
|
||||
style="margin-right: 10rpx;">{{ item1.memberPrice }}</text>
|
||||
<view v-if="shopInfo.isVip ==1 && shopInfo.isMemberPrice==1"
|
||||
<!--<view v-if="shopInfo.isVip ==1 && shopInfo.isMemberPrice==1"
|
||||
:class="{lineThrough: shopInfo.isVip ==1 && shopInfo.isMemberPrice==1}">
|
||||
¥
|
||||
</view>
|
||||
<text class="money_num"
|
||||
:class="{lineThrough: shopInfo.isVip ==1 && shopInfo.isMemberPrice==1}">{{ item1.salePrice }}</text>
|
||||
<text class="money_num"
|
||||
:class="{lineThrough: shopInfo.isVip ==1 && shopInfo.isMemberPrice==1}">{{ item1.salePrice }}</text> -->
|
||||
<text v-if="item1.unitName">/{{item1.unitName}}</text>
|
||||
</view>
|
||||
<view class="flex-end">
|
||||
@@ -185,12 +185,12 @@
|
||||
<text class="money_num"
|
||||
v-if="shopInfo.isVip ==1 && shopInfo.isMemberPrice==1"
|
||||
style="margin-right: 10rpx;">{{ item1.memberPrice }}</text>
|
||||
<view v-if="shopInfo.isVip ==1 && shopInfo.isMemberPrice==1"
|
||||
<!--<view v-if="shopInfo.isVip ==1 && shopInfo.isMemberPrice==1"
|
||||
:class="{lineThrough: shopInfo.isVip ==1 && shopInfo.isMemberPrice==1}">
|
||||
¥
|
||||
</view>
|
||||
<text class="money_num"
|
||||
:class="{lineThrough: shopInfo.isVip ==1 && shopInfo.isMemberPrice==1}">{{ item1.salePrice }}</text>
|
||||
<text class="money_num"
|
||||
:class="{lineThrough: shopInfo.isVip ==1 && shopInfo.isMemberPrice==1}">{{ item1.salePrice }}</text> -->
|
||||
<text v-if="item1.unitName">/{{item1.unitName}}</text>
|
||||
</view>
|
||||
|
||||
@@ -240,7 +240,7 @@
|
||||
@customevent='websocketsendMessage' @close="showCart = !showCart">
|
||||
</shoppingCartes>
|
||||
|
||||
<!-- 购物车 -->
|
||||
<!-- 显示购物车栏 -->
|
||||
<view class="cart-wrap" v-if="cartLists_count>0">
|
||||
<view class="cart-content">
|
||||
<view class="left">
|
||||
@@ -253,9 +253,7 @@
|
||||
</view>
|
||||
|
||||
<text class="i">¥</text>
|
||||
<!-- <text class="num"
|
||||
v-if="shopInfo.isVip == 1 && cartLists.memberAmount > 0">{{cartLists.memberAmount||'0.00'}}</text>
|
||||
<text class="num" v-else>{{cartLists.amount||'0.00'}}</text> -->
|
||||
<text class="num">{{TotalPrices}}</text>
|
||||
</view>
|
||||
<view class="btn" @tap="$u.debounce(orderdetail, 500)">
|
||||
<text class="t">去结算</text>
|
||||
@@ -436,6 +434,9 @@
|
||||
// 计算高度
|
||||
const navScroll = ref(null)
|
||||
|
||||
// 用餐人数
|
||||
const dinersNum = ref(0)
|
||||
|
||||
// 获取商品数据
|
||||
const shopProductList = reactive({
|
||||
hots: [],
|
||||
@@ -762,7 +763,6 @@
|
||||
}
|
||||
// 判断购物车是否有该选中商品
|
||||
let res = await matchingProduct(item)
|
||||
console.log(res)
|
||||
websocketsendMessage({
|
||||
id: res ? item.cartListId : '',
|
||||
type: 'shopping',
|
||||
@@ -873,10 +873,6 @@
|
||||
showCart.value = false
|
||||
}
|
||||
|
||||
if (Message.type == 'bc') {
|
||||
console.log(Message)
|
||||
}
|
||||
|
||||
// 初始化购物车数据
|
||||
if (Message.operate_type == "shopping_init") {
|
||||
cartList.value = Message.data
|
||||
@@ -888,7 +884,8 @@
|
||||
}
|
||||
|
||||
// 添加或者减少购物后返回
|
||||
if (Message.operate_type == 'shopping_add' || Message.operate_type == 'sopping_edit' || Message.type == 'bc') {
|
||||
if (Message.operate_type == 'shopping_add' || Message.operate_type == 'sopping_edit' || Message
|
||||
.type == 'bc') {
|
||||
[Message.data].forEach((objA) => {
|
||||
const index = cartList.value.findIndex((objB) => objB.id == objA.id);
|
||||
if (index !== -1) {
|
||||
@@ -924,14 +921,25 @@
|
||||
for (const group of shopProductList.productInfo) {
|
||||
for (const product of group.productList) {
|
||||
if (product.id == cartItem.product_id) {
|
||||
console.log(cartItem, product)
|
||||
// 找到匹配的商品,添加 cartListId 属性
|
||||
// 多规格
|
||||
if (product.type == 'sku') {
|
||||
product.skuList.forEach((item) => {
|
||||
if (item.id == product.id && item.productId == product.id) {
|
||||
product.salePrice = item.salePrice
|
||||
product.memberPrice = item.memberPrice
|
||||
product.originPrice = item.originPrice
|
||||
}
|
||||
})
|
||||
}
|
||||
// 单规格
|
||||
return {
|
||||
...product,
|
||||
// cartListinfo:cartItem
|
||||
cartListId: cartItem.id,
|
||||
cartNumberToAdd: product.type == 'weight' ? 1 : cartItem.number //增加一个数量算法
|
||||
// cartNumberToAdd: product.type == 'weight' ? 1 : cartItem.number //增加一个数量算法
|
||||
cartNumberToAdd: cartItem.number //增加一个数量算法
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -944,12 +952,36 @@
|
||||
const cartLists_count = computed(() => {
|
||||
return matchedProducts.value.reduce((sum, item) => {
|
||||
// 将 cartNumberToAdd 转换为数字
|
||||
const num = typeof item.cartNumberToAdd === 'string' ? parseFloat(item.cartNumberToAdd) : item
|
||||
const num = typeof item.cartNumberToAdd === 'string' ? parseFloat(item
|
||||
.cartNumberToAdd) : item
|
||||
.cartNumberToAdd;
|
||||
return sum + num;
|
||||
}, 0);
|
||||
});
|
||||
|
||||
|
||||
// 使用 computed 计算购物车总价格
|
||||
const TotalPrices = computed(() => {
|
||||
// 购物车总数价格
|
||||
let cart = matchedProducts.value.reduce((total, item) => {
|
||||
// 是否启用会员价 0否1是
|
||||
if (shopInfo.isVip == 1 && shopInfo.isMemberPrice == 1) {
|
||||
// memberPrice会员价
|
||||
return total + parseFloat(item.memberPrice) * parseFloat(item.cartNumber);
|
||||
} else {
|
||||
// salePrice销售价
|
||||
return total + parseFloat(item.salePrice) * parseFloat(item.salePrice);
|
||||
}
|
||||
}, 0);
|
||||
// 是否免除桌位费 0否1是
|
||||
if (uni.cache.get('shopInfo').isTableFee == 0) {
|
||||
console.log( cart + dinersNum.value * parseFloat(uni.cache.get('shopInfo').tableFee))
|
||||
return cart + parseFloat(dinersNum.value) * parseFloat(uni.cache.get('shopInfo').tableFee)
|
||||
} else {
|
||||
return cart;
|
||||
}
|
||||
});
|
||||
|
||||
// 定义 ifcartNumber 计算属性方法 展示数量
|
||||
const ifcartNumber = computed(() => {
|
||||
return (item) => {
|
||||
@@ -978,7 +1010,6 @@
|
||||
|
||||
// 计算处理后的购物车列表 // 用于筛选后的购物车数组
|
||||
const cartListFilter = computed(() => {
|
||||
console.log(cartList.value)
|
||||
// 使用 reduce 方法对 cartList 进行处理
|
||||
const grouped = cartList.value.reduce((acc, item) => {
|
||||
const productId = item.product_id;
|
||||
@@ -1033,7 +1064,6 @@
|
||||
scrollTopSize.value = 0
|
||||
topArr.value = []
|
||||
userStore.actionsAPIuser()
|
||||
userInfo.value = uni.cache.get('userInfo')
|
||||
// 数据可以更新
|
||||
isDataLoaded.value = true;
|
||||
}
|
||||
@@ -1043,6 +1073,13 @@
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
// 获取当前页面栈
|
||||
const pages = getCurrentPages();
|
||||
// 获取当前页面实例
|
||||
const currentPage = pages[pages.length - 1];
|
||||
// 获取页面参数
|
||||
const options = currentPage.options;
|
||||
dinersNum.value = options.dinersNum
|
||||
await productqueryProduct()
|
||||
setTimeout(() => {
|
||||
getElementTop()
|
||||
|
||||
Reference in New Issue
Block a user