扫码排队
This commit is contained in:
@@ -133,7 +133,7 @@
|
||||
<view class="list-box">
|
||||
<view class="left" :style="{top: `${store.height}px`}">
|
||||
<scroll-view :scroll-into-view="leftIntoView" :scroll-with-animation="false" :scroll-y="true"
|
||||
:style="{height:`${store.screenHeight - store.height}px`}">
|
||||
:style="{height:`${store.screenHeight - store.height}px`}" style="padding-bottom: 200rpx;">
|
||||
<view class="item" v-for="(item,index) in shopProductList.productInfo" :key="index"
|
||||
:class="{ 'active':index==leftIndex }" :id="'left-'+index" :data-index="index"
|
||||
@click="leftTap(index)"><text>{{item.name}}</text></view>
|
||||
@@ -243,9 +243,9 @@
|
||||
<!-- 店铺详情 -->
|
||||
<shopindex ref="showShopInfoRef"></shopindex>
|
||||
<!-- 购物车 -->
|
||||
<shoppingCartes :cartLists_count="cartLists_count" v-if="matchedProducts.length>0" :cartList="matchedProducts"
|
||||
:showCart="showCart" @customevent='websocketsendMessage' @close="showCart = !showCart"
|
||||
:orderinfo="orderinfo" @clickcancelOrder='clickcancelOrder'>
|
||||
<shoppingCartes :cartLists_count="cartLists_count" :cartList="matchedProducts" :showCart="showCart"
|
||||
@customevent='websocketsendMessage' @close="showCart = !showCart" :orderinfo="orderinfo"
|
||||
@clickcancelOrder='clickcancelOrder' v-if="cartLists_count > 0">
|
||||
</shoppingCartes>
|
||||
|
||||
<!-- 显示购物车栏 -->
|
||||
@@ -353,7 +353,6 @@
|
||||
</text>
|
||||
</view>
|
||||
|
||||
|
||||
<view class="operation-wrap">
|
||||
<view class="btn">
|
||||
<up-icon name="minus-circle-fill" color="#E9AB7A" size="25"
|
||||
@@ -677,13 +676,11 @@
|
||||
specInfo: selectedSpecsStr.value,
|
||||
id: specifications.item.id
|
||||
});
|
||||
// console.log(result)
|
||||
if (result != true) {
|
||||
specifications.sku_id = result.id
|
||||
specifications.product_id = result.productId
|
||||
// 添加多规格分组
|
||||
specifications.item.result = result
|
||||
// console.log(specifications.item)
|
||||
if (result.isPauseSale == 0) {
|
||||
canSubmit.value = true;
|
||||
} else {
|
||||
@@ -778,11 +775,15 @@
|
||||
|
||||
// 多规格 套餐添加数量
|
||||
const shopCart = async (i) => {
|
||||
if (i == '-' && shopCartNumber.value >= 0) {
|
||||
shopCartNumber.value = 0
|
||||
return false;
|
||||
}
|
||||
let res = await shoppingcart()
|
||||
if (i == '-') {
|
||||
if (!res && shopCartNumber.value == specifications.item.suitNum) {
|
||||
uni.showToast({
|
||||
title: `起点${specifications.item.suitNum}`,
|
||||
title: `起点${specifications.item.suitNum}个`,
|
||||
icon: 'none'
|
||||
})
|
||||
return false;
|
||||
@@ -859,7 +860,6 @@
|
||||
// 直接返回布尔值
|
||||
return result;
|
||||
} else if (specifications.item.type == 'sku') {
|
||||
// console.log(product,data, 'product,data')
|
||||
// 多规格
|
||||
return product.cartListinfo.sku_id == data.id && product.cartListinfo.product_id == data
|
||||
.productId
|
||||
@@ -897,41 +897,50 @@
|
||||
|
||||
// 提交选择并执行下一步操作的方法
|
||||
const submitSelection = async () => {
|
||||
// 数量不能少于0
|
||||
if (shopCartNumber.value <= 0) {
|
||||
return;
|
||||
}
|
||||
let res = await shoppingcart()
|
||||
console.log(res)
|
||||
if ((specifications.item.type == 'package' && allConditionsSatisfied.value) || (specifications.item.type ==
|
||||
'sku' && canSubmit.value)) {
|
||||
let res = await shoppingcart()
|
||||
|
||||
// 是否是套餐 有就传
|
||||
if (specifications.item.type != "package") {
|
||||
// 是否是套餐 有就传
|
||||
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
|
||||
})
|
||||
// 清空套餐选中
|
||||
selectedGroupSnap.value = []
|
||||
showShopsku.value = false
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
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) {
|
||||
// 商品类型 single-单规格商品 sku-多规格商品 package-套餐商品 weight-称重商品 coupon-团购券
|
||||
if (item.isSoldStock == 1 || item.isSaleTime == 0 || item.type == 'single' || item.type == 'weight' || (item.type == 'package' && item.groupType == '0')) {
|
||||
return false;
|
||||
}
|
||||
// 数量清零
|
||||
@@ -1033,7 +1042,6 @@
|
||||
initNetworkListener
|
||||
} = useWebSocket(options);
|
||||
|
||||
|
||||
//购物车显示
|
||||
const showCart = ref(false)
|
||||
|
||||
@@ -1116,6 +1124,9 @@
|
||||
// 清空购物车
|
||||
if (Message.operate_type == 'cleanup') {
|
||||
cartList.value = []
|
||||
setTimeout(() => {
|
||||
Historicalorders()
|
||||
}, 400)
|
||||
showCart.value = false
|
||||
}
|
||||
|
||||
@@ -1138,6 +1149,11 @@
|
||||
});
|
||||
}
|
||||
|
||||
// 历史订单
|
||||
if (Message.operate_type == 'clearOrder') {
|
||||
Historicalorders()
|
||||
}
|
||||
|
||||
// 购物车数据更新从新请求
|
||||
if (Message.type == 'product' && Message.data_type == 'product_update' && Message
|
||||
.operate_type == 'product_update') {
|
||||
@@ -1207,26 +1223,95 @@
|
||||
|
||||
})
|
||||
|
||||
// 计算购物车商品总数量
|
||||
const cartLists_count = computed(() => {
|
||||
if (matchedProducts.value.length > 0) {
|
||||
return matchedProducts.value.reduce((sum, item) => {
|
||||
// 将 cartNumberToAdd 转换为数字
|
||||
// const num = typeof item.cartNumberToAdd === 'string' ? parseFloat(item.cartNumberToAdd) : item.cartNumberToAdd;
|
||||
const num = typeof item.cartNumber === 'string' ? parseFloat(item.cartNumber) : item
|
||||
.cartNumber;
|
||||
return sum + num;
|
||||
}, 0);
|
||||
//删除某一个待支付订单
|
||||
const clickcancelOrder = async (data) => {
|
||||
if (data.i == 'all') {
|
||||
await APIcancelOrder({
|
||||
shopId: uni.cache.get('shopId'),
|
||||
orderId: orderinfo.value.id,
|
||||
})
|
||||
} else {
|
||||
return 0;
|
||||
await APIrmPlaceOrder({
|
||||
shopId: uni.cache.get('shopId'),
|
||||
orderId: orderinfo.value.id,
|
||||
placeNum: data.key
|
||||
})
|
||||
}
|
||||
});
|
||||
Historicalorders()
|
||||
}
|
||||
|
||||
// 计算购物车商品总价格
|
||||
// 储存是否存在多次下单
|
||||
const orderinfo = ref({})
|
||||
const confirmorderref = ref(null)
|
||||
|
||||
// 结账
|
||||
const orderdetail = async () => {
|
||||
try {
|
||||
await Historicalorders()
|
||||
} catch (error) {}
|
||||
confirmordershow.value = true
|
||||
showCart.value = false
|
||||
}
|
||||
|
||||
// 历史订单
|
||||
const Historicalorders = async (W) => {
|
||||
let res = await APIhistoryOrder({
|
||||
tableCode: uni.cache.get('tableCode'),
|
||||
})
|
||||
orderinfo.value = {
|
||||
id: res.id,
|
||||
detailMap: res.detailMap,
|
||||
placeNum: res.placeNum
|
||||
}
|
||||
if (W) {
|
||||
showCart.value = !showCart.value
|
||||
}
|
||||
}
|
||||
|
||||
// 提取合并 orderinfo.detailMap 数组的逻辑
|
||||
function combineOrderInfoDetailMap(orderinfo) {
|
||||
if (!orderinfo) return [];
|
||||
let combinedArray = [];
|
||||
for (const key in orderinfo.detailMap) {
|
||||
if (orderinfo.detailMap.hasOwnProperty(key)) {
|
||||
let subArray = orderinfo.detailMap[key];
|
||||
combinedArray = [...combinedArray, ...subArray];
|
||||
}
|
||||
}
|
||||
return combinedArray;
|
||||
}
|
||||
|
||||
// 计算购物车商品费用
|
||||
const totalPrices = computed(() => {
|
||||
// 待支付订单
|
||||
let cartone = 0
|
||||
if (orderinfo.value) {
|
||||
let combinedArray = [];
|
||||
for (const key in orderinfo.value.detailMap) {
|
||||
if (orderinfo.value.detailMap.hasOwnProperty(key)) {
|
||||
let subArray = orderinfo.value.detailMap[key];
|
||||
combinedArray = [...combinedArray, ...subArray]
|
||||
}
|
||||
}
|
||||
// 购物车总数价格
|
||||
cartone = combinedArray.reduce((total, item) => {
|
||||
// 是否启用会员价 0否1是
|
||||
if (shopInfo.isVip == 1 && shopInfo.isMemberPrice == 1) {
|
||||
// memberPrice会员价
|
||||
return total + (parseFloat(item.memberPrice || item.price) * parseFloat(item.num - item
|
||||
.returnNum));
|
||||
} else {
|
||||
// salePrice销售价
|
||||
return total + (parseFloat(item.price || 0) * parseFloat(item.num - item.returnNum));
|
||||
}
|
||||
}, 0);
|
||||
}
|
||||
console.log(cartone, 'orderinfo.value')
|
||||
// 购物车总数价格
|
||||
let cart = 0
|
||||
if (matchedProducts.value.length > 0) {
|
||||
// 购物车总数价格
|
||||
let cart = matchedProducts.value.reduce((total, item) => {
|
||||
cart = matchedProducts.value.reduce((total, item) => {
|
||||
if (item.type == 'sku') {
|
||||
item.skuList.forEach((i, t) => {
|
||||
if (item.cartListinfo.sku_id == i.id) {
|
||||
@@ -1245,56 +1330,29 @@
|
||||
return total + parseFloat(item.salePrice || 0) * parseFloat(item.cartNumber);
|
||||
}
|
||||
}, 0);
|
||||
return parseFloat(cart.toFixed(2));
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
|
||||
cart = parseFloat(cartone) + parseFloat(cart)
|
||||
console.log(cart, 'orderinfo.value')
|
||||
// 向上取整并保留两位小数
|
||||
return parseFloat(cart.toFixed(2));
|
||||
});
|
||||
|
||||
//删除某一个待支付订单
|
||||
const clickcancelOrder = async (i, key) => {
|
||||
if (i == 'all') {
|
||||
await APIcancelOrder({
|
||||
shopId: uni.cache.get('shopId'),
|
||||
orderId: orderinfo.id,
|
||||
})
|
||||
} else {
|
||||
await APIrmPlaceOrder({
|
||||
shopId: uni.cache.get('shopId'),
|
||||
orderId: orderinfo.id,
|
||||
placeNum: key
|
||||
})
|
||||
}
|
||||
Historicalorders()
|
||||
}
|
||||
// 计算购物车商品总数量
|
||||
const cartLists_count = computed(() => {
|
||||
const combinedOrderInfo = combineOrderInfoDetailMap(orderinfo.value);
|
||||
const orderInfoCount = combinedOrderInfo.reduce((sum, item) => {
|
||||
return sum + parseFloat(item.num);
|
||||
}, 0);
|
||||
|
||||
// 储存是否存在多次下单
|
||||
const orderinfo = ref({})
|
||||
const confirmorderref = ref(null)
|
||||
const matchedProductsCount = matchedProducts.value.reduce((sum, item) => {
|
||||
const num = typeof item.cartNumber === 'string' ? parseFloat(item.cartNumber) : item
|
||||
.cartNumber;
|
||||
return sum + num;
|
||||
}, 0);
|
||||
|
||||
// 结账
|
||||
const orderdetail = async () => {
|
||||
try {
|
||||
await Historicalorders()
|
||||
} catch (error) {}
|
||||
confirmordershow.value = true
|
||||
}
|
||||
|
||||
// 历史订单
|
||||
const Historicalorders = async (W) => {
|
||||
let res = await APIhistoryOrder({
|
||||
tableCode: uni.cache.get('tableCode'),
|
||||
})
|
||||
orderinfo.value = {
|
||||
id: res.id,
|
||||
detailMap: res.detailMap,
|
||||
placeNum: res.placeNum
|
||||
}
|
||||
if (W) {
|
||||
showCart.value = !showCart.value
|
||||
}
|
||||
}
|
||||
const totalCount = orderInfoCount + matchedProductsCount;
|
||||
return parseFloat(totalCount.toFixed(2));
|
||||
});
|
||||
|
||||
// 定义 ifcartNumber 计算属性方法 展示数量
|
||||
const ifcartNumber = computed(() => {
|
||||
@@ -1407,7 +1465,8 @@
|
||||
// userStore.actionsAPIuser()
|
||||
// 数据可以更新
|
||||
isDataLoaded.value = true;
|
||||
|
||||
// 历史订单
|
||||
Historicalorders()
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: '暂无列表数据,请重新扫码',
|
||||
|
||||
Reference in New Issue
Block a user