下单详情

This commit is contained in:
wwz
2025-03-06 18:48:38 +08:00
parent 56799f41f6
commit 70edc6756d
20 changed files with 4477 additions and 319 deletions

View File

@@ -232,7 +232,8 @@
</view>
</view>
</view>
<confirmorder :cartLists_count="cartLists_count" :cartList="matchedProducts" :totalPrices='totalPrices'
:confirmordershow="confirmordershow" @close="confirmordershow = !confirmordershow"></confirmorder>
<!-- 店铺详情 -->
<shopindex ref="showShopInfoRef"></shopindex>
<!-- 购物车 -->
@@ -241,7 +242,7 @@
</shoppingCartes>
<!-- 显示购物车栏 -->
<view class="cart-wrap" v-if="cartLists_count>0">
<view class="cart-wrap" v-if="cartLists_count>0 && !confirmordershow">
<view class="cart-content">
<view class="left">
<view class="iconBox">
@@ -253,7 +254,7 @@
</view>
<text class="i"></text>
<text class="num">{{TotalPrices}}</text>
<text class="num">{{totalPrices}}</text>
</view>
<view class="btn" @tap="$u.debounce(orderdetail, 500)">
<text class="t">去结算</text>
@@ -341,15 +342,6 @@
</view>
</view>
</up-popup>
<!-- <view>
<button @click="manualClose">手动关闭连接</button>
<p>连接状态: {{ isConnected ? '已连接' : '未连接' }}</p>
<view>收到的消息</view>
<view>
<view v-for="(message, index) in receivedMessages" :key="index">{{ message }}</view>
</view>
</view> -->
</view>
</template>
@@ -360,7 +352,8 @@
onMounted,
watchEffect,
getCurrentInstance,
computed
computed,
watch
} from "vue";
import {
@@ -374,6 +367,7 @@
import Nav from '@/components/CustomNavbar.vue';
import shopindex from './components/shopindex.vue'
import shoppingCartes from './components/shoppingCartes.vue'
import confirmorder from './components/confirmorder.vue'
// 获取全局属性
const {
proxy
@@ -394,8 +388,14 @@
import {
useNavbarStore
} from '@/stores/navbarStore';
const store = useNavbarStore();
// 结账管理
import {
Memberpay
} from '@/stores/pay.js';
const storeMemberpay = Memberpay();
const store = useNavbarStore();
import {
productStore
@@ -403,6 +403,12 @@
const userStore = productStore();
// 金额管理
import {
useCartStore
} from '@/stores/order.js';
const cartStore = useCartStore()
// 动态更新导航栏配置
store.updateNavbarConfig({
showBack: true, //左边返回键
@@ -413,7 +419,6 @@
hasPlaceholder: false //是否要占位符
});
const userInfo = uni.cache.get('userInfo')
const shopInfo = uni.cache.get('shopInfo')
const shopTable = uni.cache.get('shopTable')
const distance = uni.cache.get('distance') //距离
@@ -434,9 +439,6 @@
// 计算高度
const navScroll = ref(null)
// 用餐人数
const dinersNum = ref(0)
// 获取商品数据
const shopProductList = reactive({
hots: [],
@@ -809,6 +811,9 @@
//购物车显示
const showCart = ref(false)
// 提交订单显示
const confirmordershow = ref(false)
// 购物车数组
const cartList = ref([])
@@ -863,14 +868,21 @@
const Message = receivedMessages.value[receivedMessages.value.length - 1];
if (Message) {
// 心跳返回 过滤
if (Message.type == "p") {
if (Message.type == "ping_interval" || Message.msg_id == "ping_interval") {
return false
}
// 清空购物车
if (Message.operate_type == 'shopping_cleanup') {
cartList.value = []
showCart.value = false
// 初始化
if (Message.operate_type == "shopping_init") {
cartList.value = Message.data
}
// 购物车数据更新从新请求
if (Message.type == 'product') {
isDataLoaded.value = false;
await productqueryProduct()
// 数据可以更新
}
// 初始化购物车数据
@@ -959,29 +971,27 @@
}, 0);
});
// 计算购物车商品费用
const totalPrices = ref(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;
watchEffect(() => {
if (matchedProducts.value.length > 0) {
totalPrices.value = cartStore.getTotalTotalPrices(matchedProducts.value).value;
}
});
// matchedProducts 变化时,更新总打包费用
watch(() => matchedProducts.value, () => {
if (matchedProducts.value.length > 0) {
totalPrices.value = cartStore.getTotalTotalPrices(matchedProducts.value).value;
}
});
// 结账
const orderdetail = async () => {
confirmordershow.value = true
}
// 定义 ifcartNumber 计算属性方法 展示数量
const ifcartNumber = computed(() => {
return (item) => {
@@ -1007,7 +1017,6 @@
};
})
// 计算处理后的购物车列表 // 用于筛选后的购物车数组
const cartListFilter = computed(() => {
// 使用 reduce 方法对 cartList 进行处理
@@ -1034,20 +1043,6 @@
}));
})
// 结账
const orderdetail = () => {
if (this.cartLists.data.length == 0) {
uni.showToast({
title: '请先添加商品',
icon: 'none'
})
return false
}
}
// 列表请求
const productqueryProduct = async () => {
shopProductList.hots = await productminiApphotsquery()
@@ -1079,8 +1074,13 @@
const currentPage = pages[pages.length - 1];
// 获取页面参数
const options = currentPage.options;
dinersNum.value = options.dinersNum
await productqueryProduct()
orderId.value = options.orderId
let res = await APIshopUserInfo({
shopId: uni.cache.get('shopId')
})
cartStore.shopInfo = uni.cache.get('shopInfo')
setTimeout(() => {
getElementTop()
}, 500)