购物车计算

This commit is contained in:
wwz
2025-03-01 18:30:19 +08:00
parent 04a84aa17f
commit c0af79f666
10 changed files with 216 additions and 152 deletions

View File

@@ -1,7 +1,7 @@
<template>
<view class="content">
<view class="contentbox"
:style="'background:url('+(shopExtend?shopExtend.value:'https://czg-qr-order.oss-cn-beijing.aliyuncs.com/indexs/shuangbackground.png')+') no-repeat center center / cover' ">
:style="'background:url('+(shopExtend.index_bg?shopExtend.index_bg.value:'https://czg-qr-order.oss-cn-beijing.aliyuncs.com/indexs/shuangbackground.png')+') no-repeat center center / cover' ">
<view class="contentboxitem flex-between">
<view class="contentboxitemleft flex-colum" @click="scanCodehandle(0)">
<image src="https://czg-qr-order.oss-cn-beijing.aliyuncs.com/indexs/Xdiancan.png" mode="aspectFill">
@@ -10,7 +10,8 @@
<text class="contentboxitemlefttexttow">在线点不排队</text>
</view>
<view class="contentboxitemright">
<view class="contentboxitemright_item flex-between" @click="memberindex('user/member/memberdetails')">
<view class="contentboxitemright_item flex-between"
@click="memberindex('user/member/memberdetails')">
<image src="https://czg-qr-order.oss-cn-beijing.aliyuncs.com/indexs/Xvip.png" mode="aspectFill">
</image>
<view class="contentboxitemright_itembox flex-colum">
@@ -41,11 +42,14 @@
import {
productStore
} from '@/stores/user.js';
const shopExtend = uni.cache.get('shopTable').shopExtendMap.index_bg
const shopExtend = uni.cache.get('shopTable').shopExtendMap
const scanCodehandle = async (i) => {
const store = productStore();
await store.scanCodeactions()
}
const memberindex = (url) => {
uni.pro.navigateTo(url, {
shopId: uni.cache.get('shopId'),
@@ -60,6 +64,8 @@
}
return null;
}
onMounted(() => {
})
</script>
<style scoped lang="scss">

View File

@@ -6,7 +6,7 @@
<view class="content">
<view class="title">
<view class="title_text">请选择就餐人数</view>
<view class="title_tabNum">桌号{{tableCode}}</view>
<view class="title_tabNum">桌号{{shopTable.name}}</view>
</view>
<view class="num" :class="{'active':numIndex==-1}">
<view class="item" @click="tabCut(index)" v-for="(item,index) in 9" :key="index">

View File

@@ -15,7 +15,7 @@
<view class="shop-item" v-for="(item,index) in props.cartList" :key="item.id">
<view class="shop-item-content">
<view class="cover" v-if="item.productId!=-999">
<up-image :src="item.coverImg" width="120" radius="10" height="120"></up-image>
<up-image :src="item.coverImg" width="80" radius="10" height="80"></up-image>
</view>
<view class="info">
<view class="name"> {{ item.name }} </view>

View File

@@ -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()

View File

@@ -40,9 +40,9 @@
<!-- <u-picker :show="calendarShow" ref="uPicker" :columns="columns" @confirm="confirm" @change="changeHandler"></u-picker> -->
<!-- <picker :show="calendarShow" mode="date"></picker> -->
<up-datetime-picker mode="date" @cancel="calendarShow = false" :show="calendarShow"
minDate="-2208988800000" v-model="value1" itemHeight="66" visibleItemCount="5"
:minDate="-2208988800000" v-model="value1" itemHeight="66" visibleItemCount="5"
@confirm="confirmTime"></up-datetime-picker>
<u-icon name="arrow-down-fill" color="#000" size="23"></u-icon>
<up-icon name="arrow-down-fill" color="#000" size="10"></up-icon>
</view>
<view class="reg-cell">
<view class="lable">手机号</view>
@@ -92,6 +92,10 @@
type: Object,
default: () => ({})
},
memberOpen: {
type: Boolean,
default: false
},
});
const formInfo = reactive({
@@ -107,8 +111,6 @@
// 用户图片
const userHeadImg = ref('')
//显示隐藏
const memberOpen = ref(false)
//显示隐藏
const isProtocol = ref(false)
@@ -286,7 +288,7 @@
}
const registerMember = async() => {
const registerMember = async () => {
// if ( userHeadImg.value == "" || userHeadImg.value == null ) {
// uni.showToast({
// title: '请选择会员头像',

View File

@@ -94,7 +94,8 @@
</view>
<view class="recharge" @tap="$u.debounce(userbalancerechangesub, 500)">立即充值</view>
</view>
<!-- <registermember :show="memberOpen" :shopId="shopId" @getRegisterMember="getRegisterMember"></registermember> -->
<registermember :show="infoForn.shopUserInfo.isVip == 1? false : true" :shopUserInfo="infoForn.shopUserInfo">
</registermember>
</view>
</template>
@@ -105,7 +106,7 @@
reactive,
onMounted
} from 'vue';
// import registermember from './components/registermember.vue'
import registermember from './components/registermember.vue'
import {
APIuseractivate,

View File

@@ -88,7 +88,7 @@
</view>
</view>
<registermember :show="memberOpen" :shopUserInfo="shopUserInfo.shopInfo" @getRegisterMember="getRegisterMember">
<registermember :show="shopUserInfo.shopInfo.isVip == 1? false : true" :shopUserInfo="shopUserInfo.shopInfo">
</registermember>
</view>
@@ -115,7 +115,7 @@
})
const form = reactive({
memberOpen: '',
memberOpen: false,
shopName: "",
amount: '',
lucky: {