下单页面调整,确认订单页面调整
This commit is contained in:
parent
94cc918357
commit
7c182023a5
16
App.vue
16
App.vue
|
|
@ -1,4 +1,7 @@
|
|||
<script setup>
|
||||
import {
|
||||
useCartsStore
|
||||
} from '@/stores/carts.js';
|
||||
import {
|
||||
useNavbarStore
|
||||
} from '@/stores/navbarStore';
|
||||
|
|
@ -16,6 +19,12 @@
|
|||
import {
|
||||
Storelogin
|
||||
} from '@/stores/user.js';
|
||||
|
||||
import {
|
||||
useCartStore
|
||||
} from '@/stores/order.js';
|
||||
// websocket
|
||||
|
||||
const {
|
||||
proxy
|
||||
} = getCurrentInstance()
|
||||
|
|
@ -26,7 +35,9 @@
|
|||
await nextTick()
|
||||
const store = useNavbarStore();
|
||||
await store.initNavbarHeight();
|
||||
|
||||
getApp().globalData.websocket=null;
|
||||
const cartsStore=useCartsStore()
|
||||
cartsStore.isloading=false;
|
||||
});
|
||||
onShow(async () => {
|
||||
try {
|
||||
|
|
@ -75,6 +86,7 @@
|
|||
// console.log(error)
|
||||
// }
|
||||
// #endif
|
||||
|
||||
})
|
||||
// onHide: function() {}
|
||||
// }
|
||||
|
|
@ -84,5 +96,5 @@
|
|||
/*每个页面公共css */
|
||||
@import "@/uni_modules/uview-plus/index.scss";
|
||||
@import '@/common/css/flex.css';
|
||||
@import "@/common/css/common.css";
|
||||
@import "@/common/css/common.scss";
|
||||
</style>
|
||||
|
|
@ -4,6 +4,10 @@ export default (params) => {
|
|||
let data = params.data || {};
|
||||
let type = params.type || 1;
|
||||
let toast = params.toast || true;
|
||||
let token=uni.cache.get('token') || '';
|
||||
// #ifdef H5
|
||||
token="b152112b96e24feb8aa47062136c043b"
|
||||
// #endif
|
||||
let header = {
|
||||
version: uni.conf.version,
|
||||
type: uni.getSystemInfoSync().platform,
|
||||
|
|
@ -19,7 +23,7 @@ export default (params) => {
|
|||
// #ifdef MP-ALIPAY
|
||||
platformType: 'ALI',
|
||||
// #endif
|
||||
token: uni.cache.get('token') || '',
|
||||
token,
|
||||
id: uni.cache.get('userInfo').id || '',
|
||||
shopId: uni.cache.get('shopId') || '',
|
||||
userId: uni.cache.get('userInfo').id || '',
|
||||
|
|
|
|||
|
|
@ -4,6 +4,14 @@ const urlAccount = '/account'
|
|||
const urlProduct = '/product'
|
||||
const urlOrder = '/order'
|
||||
|
||||
//桌码获取详细台桌信息
|
||||
export const getTableInfo = (data) => {
|
||||
return request({
|
||||
url: urlAccount + '/user/shopInfo/tableInfo',
|
||||
method: 'get',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
//商品列表
|
||||
export const APIgeocodelocation = (data) => {
|
||||
return request({
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
export default {
|
||||
main:'#E8AD7B'
|
||||
}
|
||||
|
|
@ -43,4 +43,13 @@ page,
|
|||
|
||||
image {
|
||||
display: block;
|
||||
}
|
||||
.absolute{
|
||||
position: absolute;
|
||||
}
|
||||
.color-main{
|
||||
color:$my-main-color;
|
||||
}
|
||||
.bg-main{
|
||||
background-color: $my-main-color;
|
||||
}
|
||||
|
|
@ -0,0 +1,360 @@
|
|||
import {
|
||||
ref,
|
||||
onMounted,
|
||||
onBeforeUnmount
|
||||
} from 'vue';
|
||||
|
||||
const useWebSocket = (options = {}) => {
|
||||
const {
|
||||
heartbeatInterval = 10000, //心跳是10秒一次
|
||||
reconnectInterval = 3000, //重新连接间隔时间的一个参数
|
||||
maxReconnectAttempts = 3, //最大重连接次数
|
||||
initialReconnectInterval = 3000, // 初始重连间隔
|
||||
initMessage,
|
||||
initMessageRetryCount = 3, // 新增:初始化消息发送重试次数
|
||||
initMessageRetryInterval = 2000, // 新增:初始化消息重试间隔
|
||||
maxReconnectDuration = Infinity,
|
||||
onMessage
|
||||
} = options;
|
||||
const autoReconnect = ref(true); //是否自动重新连接
|
||||
const socketTask = ref(null);
|
||||
const isConnected = ref(false); //表示是否已连接上。
|
||||
const heartbeatTimer = ref(null); //心跳定时器
|
||||
const reconnectTimer = ref(null); //重连定时器
|
||||
const reconnectAttempts = ref(0); //重连的尝试次数
|
||||
const isNetworkConnected = ref(true); //监听当前网络连接状态
|
||||
const isManuallyClosed = ref(false); //是否是被手动关闭的
|
||||
const receivedMessages = ref(); //储从 WebSocket 服务器接收到的消息
|
||||
const initMessageSendAttempts = ref(0); //初始化连接多少次
|
||||
const reconnectStartTime = ref(0); //新增:记录重连开始时间
|
||||
const isPongReceived = ref(false)
|
||||
const allowReconnect = ref(true); // 新增:控制是否允许重连
|
||||
// 关闭现有连接并清理资源
|
||||
const closeExistingConnection = () => {
|
||||
if (socketTask.value) {
|
||||
// 关闭 WebSocket 连接
|
||||
socketTask.value.close({
|
||||
success: () => {
|
||||
console.log('WebSocket 连接已关闭');
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('关闭 WebSocket 连接失败:', err);
|
||||
}
|
||||
});
|
||||
|
||||
// 清除心跳定时器
|
||||
clearInterval(heartbeatTimer.value);
|
||||
heartbeatTimer.value = null;
|
||||
|
||||
// 清除重连定时器
|
||||
clearTimeout(reconnectTimer.value);
|
||||
reconnectTimer.value = null;
|
||||
|
||||
// 标记连接已断开
|
||||
isConnected.value = false;
|
||||
}
|
||||
};
|
||||
const websocketsendMessage = (data) => {
|
||||
uni.$u.debounce(sendMessage(data), 500)
|
||||
}
|
||||
// 连接 WebSocket
|
||||
const connect = (connectMsg) => {
|
||||
if (!isNetworkConnected.value) {
|
||||
uni.showToast({
|
||||
title: '网络未连接...',
|
||||
icon: 'none'
|
||||
})
|
||||
setTimeout(() => {
|
||||
uni.pro.switchTab('index/index')
|
||||
}, 1000)
|
||||
console.log('网络未连接,暂不尝试连接 WebSocket');
|
||||
return;
|
||||
}
|
||||
|
||||
// 关闭现有连接并清理资源
|
||||
closeExistingConnection();
|
||||
socketTask.value = uni.connectSocket({
|
||||
url: uni.conf.baseUrlwws,
|
||||
success: (res) => {
|
||||
isConnected.value = true;
|
||||
// 监听初始化成功在开启心跳
|
||||
startHeartbeat();
|
||||
},
|
||||
fail: () => {
|
||||
console.error('WebSocket 连接失败,尝试重连');
|
||||
if (autoReconnect.value && allowReconnect.value) {
|
||||
handleReconnect();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (socketTask.value) {
|
||||
socketTask.value.onOpen(() => {
|
||||
// 初始化 初始购物车
|
||||
sendMessage(connectMsg ? connectMsg : initMessage)
|
||||
});
|
||||
socketTask.value.onMessage((res) => {
|
||||
receivedMessages.value = JSON.parse(res.data)
|
||||
websocketsendMessage({
|
||||
type: 'receipt',
|
||||
msg_id: receivedMessages.value.msg_id
|
||||
})
|
||||
if (onMessage) {
|
||||
onMessage(receivedMessages.value)
|
||||
}
|
||||
// receivedMessages.value.push(list);
|
||||
if (receivedMessages.value == 'ok' || receivedMessages.value.operate_type == 'init') {
|
||||
console.log('初始化正常,心跳响应正常');
|
||||
// 清除重连定时器
|
||||
clearTimeout(reconnectTimer.value);
|
||||
allowReconnect.value = false
|
||||
reconnectTimer.value = null;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
socketTask.value.onClose((res) => {
|
||||
console.log(res, 'WebSocket 连接已关闭,尝试重连');
|
||||
isConnected.value = false;
|
||||
clearInterval(heartbeatTimer.value); // 停止心跳定时器
|
||||
clearTimeout(reconnectTimer.value); // 清除重连定时器
|
||||
if (res.code == '1006' && !allowReconnect.value) {
|
||||
uni.showToast({
|
||||
title: '网络异常,请重新扫码',
|
||||
icon: 'none'
|
||||
});
|
||||
autoReconnect.value = false;
|
||||
setTimeout(() => {
|
||||
uni.pro.switchTab('index/index');
|
||||
}, 1000)
|
||||
return false;
|
||||
}
|
||||
if (autoReconnect.value && !isManuallyClosed.value) {
|
||||
handleReconnect();
|
||||
}
|
||||
});
|
||||
|
||||
socketTask.value.onError((err) => {
|
||||
console.error('WebSocket 连接发生错误:', err);
|
||||
isConnected.value = false;
|
||||
clearInterval(heartbeatTimer.value);
|
||||
if (autoReconnect.value && !isManuallyClosed.value) {
|
||||
handleReconnect();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.error('socketTask 未正确初始化');
|
||||
}
|
||||
};
|
||||
|
||||
// 启动心跳机制
|
||||
const startHeartbeat = () => {
|
||||
if (!isNetworkConnected.value) {
|
||||
console.log('网络未连接,暂停心跳');
|
||||
uni.showToast({
|
||||
title: '网络未连接...',
|
||||
icon: 'none'
|
||||
});
|
||||
setTimeout(() => {
|
||||
uni.pro.switchTab('index/index');
|
||||
}, 1000);
|
||||
return;
|
||||
}
|
||||
heartbeatTimer.value = setInterval(() => {
|
||||
if (isConnected.value) {
|
||||
console.log('发送心跳消息');
|
||||
isPongReceived.value = false; // 每次发送心跳消息前重置标记
|
||||
socketTask.value.send({
|
||||
data: JSON.stringify({
|
||||
type: 'ping_interval',
|
||||
set: 'shopping'
|
||||
}),
|
||||
success: () => {
|
||||
console.log('心跳消息发送成功');
|
||||
const pongTimer = setTimeout(() => {
|
||||
if (!isPongReceived.value) {
|
||||
console.error('心跳超时,未收到响应,尝试重连');
|
||||
clearInterval(heartbeatTimer.value);
|
||||
if (autoReconnect.value && reconnectAttempts.value <
|
||||
maxReconnectAttempts && allowReconnect.value) {
|
||||
handleReconnect();
|
||||
} else {
|
||||
console.error('重连次数达到上限,停止重连和心跳');
|
||||
clearInterval(heartbeatTimer.value);
|
||||
autoReconnect.value = false;
|
||||
uni.pro.switchTab('index/index');
|
||||
}
|
||||
}
|
||||
}, heartbeatInterval * 1.2);
|
||||
|
||||
const handlePong = (res) => {
|
||||
try {
|
||||
let data = JSON.parse(res.data);
|
||||
if (data.operate_type == "init" || (data.msg === 'ok' &&
|
||||
data.msg_id ==
|
||||
'ping_interval')) {
|
||||
isPongReceived.value = true;
|
||||
console.log('收到心跳响应,清除超时定时器');
|
||||
clearTimeout(pongTimer);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('解析心跳响应数据时出错:', error);
|
||||
}
|
||||
};
|
||||
socketTask.value.onMessage(handlePong);
|
||||
},
|
||||
fail: () => {
|
||||
console.error('心跳消息发送失败,尝试重连');
|
||||
clearInterval(heartbeatTimer.value);
|
||||
if (autoReconnect.value && reconnectAttempts.value <
|
||||
maxReconnectAttempts && allowReconnect.value) {
|
||||
handleReconnect();
|
||||
} else {
|
||||
console.error('重连次数达到上限,停止重连和心跳');
|
||||
clearInterval(heartbeatTimer.value);
|
||||
autoReconnect.value = false;
|
||||
uni.pro.switchTab('index/index');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}, heartbeatInterval);
|
||||
};
|
||||
|
||||
|
||||
// 手动关闭连接
|
||||
const closeSocket = () => {
|
||||
isManuallyClosed.value = true;
|
||||
closeExistingConnection();
|
||||
};
|
||||
|
||||
// 发送消息
|
||||
const sendMessage = async (data) => {
|
||||
if (isConnected.value) {
|
||||
await socketTask.value.send({
|
||||
data: JSON.stringify(data),
|
||||
success: () => {
|
||||
// console.log('消息发送成功');
|
||||
},
|
||||
fail: () => {
|
||||
// console.error('消息发送失败');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.error('WebSocket 未连接,无法发送消息');
|
||||
}
|
||||
};
|
||||
|
||||
// 处理重连逻辑
|
||||
const handleReconnect = () => {
|
||||
if (!isNetworkConnected.value) {
|
||||
console.log('网络未连接,暂停重连');
|
||||
return;
|
||||
}
|
||||
if (isManuallyClosed.value) {
|
||||
console.log('手动关闭连接,不进行重连');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!allowReconnect.value) {
|
||||
console.log('重连功能已关闭,不进行重连');
|
||||
return;
|
||||
}
|
||||
|
||||
if (reconnectAttempts.value < maxReconnectAttempts) {
|
||||
reconnectAttempts.value++;
|
||||
const reconnectInterval = initialReconnectInterval * Math.pow(2, reconnectAttempts.value - 1);
|
||||
const randomizedInterval = reconnectInterval + Math.floor(Math.random() * 1000);
|
||||
uni.showLoading({
|
||||
title: `正在努力连接..`,
|
||||
mask: true
|
||||
})
|
||||
console.log(`尝试第 ${reconnectAttempts.value} 次重连,重连间隔: ${randomizedInterval}ms...`);
|
||||
|
||||
reconnectTimer.value = setTimeout(() => {
|
||||
connect();
|
||||
}, randomizedInterval);
|
||||
} else {
|
||||
console.error('重连次数达到上限,停止重连');
|
||||
uni.showToast({
|
||||
title: '重连次数达到上限,停止重连',
|
||||
icon: 'none'
|
||||
});
|
||||
clearInterval(heartbeatTimer.value);
|
||||
autoReconnect.value = false;
|
||||
setTimeout(() => {
|
||||
uni.hideLoading();
|
||||
uni.pro.switchTab('index/index');
|
||||
}, 1000)
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// / 网络状态监听
|
||||
const initNetworkListener = () => {
|
||||
uni.getSystemInfo({
|
||||
success: (res) => {
|
||||
if (res.platform !== 'devtools') {
|
||||
uni.onNetworkStatusChange((statusRes) => {
|
||||
isNetworkConnected.value = statusRes.isConnected;
|
||||
if (statusRes.isConnected && !isManuallyClosed.value) {
|
||||
console.log('网络已连接,尝试重新连接 WebSocket');
|
||||
if (!isConnected.value && autoReconnect.value) {
|
||||
connect();
|
||||
}
|
||||
} else if (!statusRes.isConnected) {
|
||||
console.log('网络已断开,暂停 WebSocket 操作');
|
||||
clearInterval(heartbeatTimer.value);
|
||||
clearTimeout(reconnectTimer.value);
|
||||
if (socketTask.value) {
|
||||
socketTask.value.close();
|
||||
isConnected.value = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('获取系统信息失败:', err);
|
||||
}
|
||||
});
|
||||
|
||||
uni.getNetworkType({
|
||||
success: (res) => {
|
||||
isNetworkConnected.value = res.networkType !== 'none';
|
||||
if (!isNetworkConnected.value) {
|
||||
console.log('初始网络未连接,暂不尝试连接 WebSocket');
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// 页面显示,尝试连接 WebSocket
|
||||
const onShowconnect = () => {
|
||||
if (autoReconnect.value) {
|
||||
uni.showLoading({
|
||||
title: `尝试再次连接`,
|
||||
mask: true
|
||||
})
|
||||
connect();
|
||||
}
|
||||
}
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
closeSocket();
|
||||
});
|
||||
|
||||
return {
|
||||
isConnected,
|
||||
sendMessage,
|
||||
closeSocket,
|
||||
receivedMessages,
|
||||
closeExistingConnection,
|
||||
connect,
|
||||
onShowconnect,
|
||||
initNetworkListener,
|
||||
connect
|
||||
};
|
||||
};
|
||||
|
||||
export default useWebSocket;
|
||||
|
|
@ -13,7 +13,8 @@ const useWebSocket = (options = {}) => {
|
|||
initMessage,
|
||||
initMessageRetryCount = 3, // 新增:初始化消息发送重试次数
|
||||
initMessageRetryInterval = 2000, // 新增:初始化消息重试间隔
|
||||
maxReconnectDuration = Infinity
|
||||
maxReconnectDuration = Infinity,
|
||||
onMessage
|
||||
} = options;
|
||||
|
||||
const autoReconnect = ref(true); //是否自动重新连接
|
||||
|
|
@ -56,7 +57,7 @@ const useWebSocket = (options = {}) => {
|
|||
};
|
||||
|
||||
// 连接 WebSocket
|
||||
const connect = () => {
|
||||
const connect = (connectMsg) => {
|
||||
if (!isNetworkConnected.value) {
|
||||
uni.showToast({
|
||||
title: '网络未连接...',
|
||||
|
|
@ -71,7 +72,6 @@ const useWebSocket = (options = {}) => {
|
|||
|
||||
// 关闭现有连接并清理资源
|
||||
closeExistingConnection();
|
||||
|
||||
socketTask.value = uni.connectSocket({
|
||||
url: uni.conf.baseUrlwws,
|
||||
success: (res) => {
|
||||
|
|
@ -90,10 +90,13 @@ const useWebSocket = (options = {}) => {
|
|||
if (socketTask.value) {
|
||||
socketTask.value.onOpen(() => {
|
||||
// 初始化 初始购物车
|
||||
sendMessage(initMessage)
|
||||
sendMessage(connectMsg?connectMsg:initMessage)
|
||||
});
|
||||
socketTask.value.onMessage((res) => {
|
||||
receivedMessages.value = JSON.parse(res.data)
|
||||
if(onMessage){
|
||||
onMessage(receivedMessages.value)
|
||||
}
|
||||
// receivedMessages.value.push(list);
|
||||
if (receivedMessages.value == 'ok' || receivedMessages.value.operate_type == 'init') {
|
||||
console.log('初始化正常,心跳响应正常');
|
||||
|
|
@ -341,7 +344,7 @@ const useWebSocket = (options = {}) => {
|
|||
sendMessage,
|
||||
closeSocket,
|
||||
receivedMessages,
|
||||
closeExistingConnection,
|
||||
closeExistingConnection,connect,
|
||||
onShowconnect,
|
||||
initNetworkListener
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// const debug = process.env.NODE_ENV == 'development' ? true : false;
|
||||
const debug = false
|
||||
const debug = true
|
||||
// #ifdef H5
|
||||
const proxyApi = "/api"
|
||||
// #endif
|
||||
|
|
@ -13,8 +13,8 @@ const proxyApiwws = 'ws://192.168.1.31:2348' // 调试地址
|
|||
// #endif
|
||||
|
||||
// #ifdef H5
|
||||
const baseUrl = debug ? proxyApi : "https://tapi.cashier.sxczgkj.cn"
|
||||
const baseUrlwws = 'wss://sockets.sxczgkj.com/wss'
|
||||
const baseUrl = debug ? proxyApi : "http://192.168.1.31"
|
||||
const baseUrlwws = 'ws://192.168.1.31:2348'
|
||||
// #endif
|
||||
|
||||
// #ifdef APP || MP-WEIXIN || MP-ALIPAY
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ function get(key) {
|
|||
if (!res) {
|
||||
return ''
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (res.expiretime && res.expiretime < Date.now()) {
|
||||
|
|
|
|||
1
main.js
1
main.js
|
|
@ -21,6 +21,7 @@ import {
|
|||
createUnistorage
|
||||
} from './uni_modules/pinia-plugin-unistorage';
|
||||
|
||||
|
||||
export function createApp() {
|
||||
// 创建 SSR 应用实例
|
||||
const app = createSSRApp(App);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,6 @@
|
|||
"dayjs": "^1.11.13",
|
||||
"jsbarcode": "^3.11.6",
|
||||
"pinia": "^2.3.1",
|
||||
"pinia-plugin-persistedstate": "^4.2.0"
|
||||
"pinia-plugin-unistorage": "^0.1.2"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
22
pages.json
22
pages.json
|
|
@ -161,6 +161,28 @@
|
|||
"style": {
|
||||
"navigationBarTitleText": "叫号"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path" : "pages/test/test",
|
||||
"style" :
|
||||
{
|
||||
"navigationBarTitleText" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"path" : "pages/order/histpry-order/histpry-order",
|
||||
"style" :
|
||||
{
|
||||
"navigationBarTitleText" : ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"path" : "pages/order/confirm-order",
|
||||
"style" :
|
||||
{
|
||||
"navigationBarTitleText" : "确认订单",
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
}
|
||||
],
|
||||
"uniIdRouter": {},
|
||||
|
|
|
|||
|
|
@ -0,0 +1,474 @@
|
|||
<template>
|
||||
<view class="card_item">
|
||||
<!-- <view class="head">
|
||||
<view class="head_left">
|
||||
<text class="placeNum">当前购物车</text>
|
||||
</view>
|
||||
</view> -->
|
||||
<!-- 订单详情 -->
|
||||
<view class="shop-info">
|
||||
<view class="item" v-for="item in nowCarts" :key="item.id">
|
||||
<view class="cover">
|
||||
<up-image width="76" height="76" radius="16" :src="item.productImg"
|
||||
v-if="item.productId!=-999"></up-image>
|
||||
<up-image width="76" height="76" radius="16"
|
||||
:src="'https://czg-qr-order.oss-cn-beijing.aliyuncs.com/confirmOrder/table.png'"
|
||||
mode="heightFix" v-else></up-image>
|
||||
</view>
|
||||
<view class="info">
|
||||
<text class="productName">{{item.productName}}</text>
|
||||
<text class="productSkuName" v-if="item.skuName">{{item.skuName}}</text>
|
||||
</view>
|
||||
|
||||
<view class="price">
|
||||
<view class="priceAmount">
|
||||
<text v-if="changeFreeenable">{{item.price}}</text>
|
||||
<text v-else>
|
||||
¥{{useVipPrice?(item.memberPrice|| item.price):item.price}}
|
||||
</text>
|
||||
</view>
|
||||
<view class="num">x{{item.num}}</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!--<view class="status" v-if="listinfo.status == 'unpaid' || listinfo.status == 'paying'">未付款</view>
|
||||
<view class="totalAmount">
|
||||
<view class="label">小计¥</view>
|
||||
<view class="price"> {{item.totalAmount}} </view>
|
||||
</view> -->
|
||||
|
||||
<!-- <view class="semicircle_icon" v-if="index > 0">
|
||||
<view class="semicircle_left_icon"></view>
|
||||
<view class="semicircle_right_icon"></view>
|
||||
</view> -->
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import {
|
||||
ref,
|
||||
reactive,
|
||||
defineProps,
|
||||
computed,
|
||||
defineEmits,
|
||||
watch,
|
||||
watchEffect,
|
||||
defineExpose,
|
||||
onMounted
|
||||
} from 'vue'
|
||||
const props = defineProps({
|
||||
changeFreeenable: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
useVipPrice: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
nowCarts: {
|
||||
type: Array,
|
||||
default: () => {
|
||||
return []
|
||||
}
|
||||
}
|
||||
})
|
||||
onMounted(() => {
|
||||
console.log('props.nowCarts');
|
||||
console.log(props.nowCarts);
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.card_item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
position: relative;
|
||||
padding: 0 34rpx;
|
||||
|
||||
.head {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
// padding: 32rpx 0;
|
||||
|
||||
.head_left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
.placeNum {
|
||||
font-weight: bold;
|
||||
font-size: 32rpx;
|
||||
color: #333333;
|
||||
margin-right: 32rpx;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.placeTime {
|
||||
font-weight: 400;
|
||||
font-size: 32rpx;
|
||||
color: #666666;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
.shop-info {
|
||||
padding-top: 28rpx;
|
||||
|
||||
.item:nth-child(1) {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.item {
|
||||
margin-bottom: 32rpx;
|
||||
display: flex;
|
||||
&:last-child{
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.cover {}
|
||||
|
||||
.info {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding-left: 16upx;
|
||||
|
||||
.productName {
|
||||
font-weight: bold;
|
||||
font-size: 28rpx;
|
||||
color: #333333;
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
|
||||
.productSkuName {
|
||||
font-weight: 400;
|
||||
font-size: 24rpx;
|
||||
color: #999999;
|
||||
display: -webkit-box;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-line-clamp: 3;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.n {
|
||||
font-size: 24upx;
|
||||
color: #999;
|
||||
}
|
||||
}
|
||||
|
||||
.price {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-end;
|
||||
padding-left: 68rpx;
|
||||
|
||||
.priceAmount {
|
||||
font-weight: 500;
|
||||
font-size: 28rpx;
|
||||
color: #333333;
|
||||
margin-top: 26rpx;
|
||||
}
|
||||
|
||||
.num {
|
||||
font-weight: 400;
|
||||
font-size: 24rpx;
|
||||
color: #999999;
|
||||
margin-top: 22rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.status {
|
||||
align-self: flex-end;
|
||||
width: 92rpx;
|
||||
height: 40rpx;
|
||||
line-height: 40rpx;
|
||||
text-align: center;
|
||||
background: #999999;
|
||||
border-radius: 10rpx 10rpx 10rpx 10rpx;
|
||||
font-weight: 400;
|
||||
font-size: 22rpx;
|
||||
color: #FFFFFF;
|
||||
margin-top: 32rpx;
|
||||
}
|
||||
|
||||
.totalAmount {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: flex-end;
|
||||
padding: 32rpx 0;
|
||||
border-bottom: 2rpx dashed #e5e5e5;
|
||||
|
||||
.label {
|
||||
font-weight: bold;
|
||||
font-size: 28rpx;
|
||||
color: #333333;
|
||||
}
|
||||
|
||||
.price {
|
||||
font-weight: bold;
|
||||
font-size: 36rpx;
|
||||
color: #333333;
|
||||
}
|
||||
}
|
||||
|
||||
.semicircle_icon {
|
||||
width: 100%;
|
||||
position: absolute;
|
||||
top: -22.5rpx;
|
||||
left: 0;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
|
||||
.semicircle_left_icon {
|
||||
width: 45rpx;
|
||||
height: 45rpx;
|
||||
margin-left: -22.5rpx;
|
||||
background-color: #f9f9f9;
|
||||
border-radius: 50%;
|
||||
// box-shadow: inset -20rpx 0rpx 22rpx -20rpx rgba(87, 86, 86, 0.35);
|
||||
|
||||
}
|
||||
|
||||
.semicircle_right_icon {
|
||||
width: 45rpx;
|
||||
height: 45rpx;
|
||||
margin-right: -22.5rpx;
|
||||
background-color: #f9f9f9;
|
||||
border-radius: 50%;
|
||||
// box-shadow: inset 13rpx 0rpx 16rpx -9rpx rgba(87, 86, 86, 0.35);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.cell-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 32rpx 34rpx 0 34rpx;
|
||||
|
||||
.label {
|
||||
font-weight: bold;
|
||||
font-size: 32rpx;
|
||||
color: #333333;
|
||||
padding-bottom: 32rpx;
|
||||
}
|
||||
|
||||
.val {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
padding-bottom: 32rpx;
|
||||
border-bottom: 2rpx dashed #e5e5e5;
|
||||
|
||||
view:nth-child(1) {
|
||||
font-weight: 400;
|
||||
font-size: 24rpx;
|
||||
color: #999999;
|
||||
margin-right: 42rpx;
|
||||
}
|
||||
|
||||
view:nth-child(2) {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
font-weight: bold;
|
||||
font-size: 36rpx;
|
||||
color: #333333;
|
||||
}
|
||||
}
|
||||
|
||||
.val.column {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.productCoupon {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
margin: 0 0 10rpx 0;
|
||||
|
||||
.name {
|
||||
font-weight: 400;
|
||||
font-size: 26rpx;
|
||||
color: #999;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.num {
|
||||
font-weight: 400;
|
||||
font-size: 26rpx;
|
||||
color: #999;
|
||||
margin: 0 30rpx;
|
||||
line-height: 20rpx;
|
||||
}
|
||||
|
||||
.amount {
|
||||
font-weight: bold;
|
||||
font-size: 26rpx;
|
||||
color: #333;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.favorable {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 0 30rpx;
|
||||
box-sizing: border-box;
|
||||
padding-bottom: 26rpx;
|
||||
padding-top: 26rpx;
|
||||
border-bottom: 2rpx solid #E5E5E5;
|
||||
|
||||
.favorable_left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
.icon {
|
||||
width: 40rpx;
|
||||
height: 40rpx;
|
||||
margin-right: 16rpx;
|
||||
}
|
||||
|
||||
.name {
|
||||
font-size: 28rpx;
|
||||
font-weight: 400rpx;
|
||||
color: #333;
|
||||
}
|
||||
}
|
||||
|
||||
.favorable_right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
.favorable_right_text {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
font-weight: 400rpx;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
.favorable_right {
|
||||
.column {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-end;
|
||||
|
||||
.favorable_right_text {
|
||||
margin-bottom: 10rpx;
|
||||
|
||||
text:nth-child(1) {
|
||||
font-size: 26rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
text:nth-child(2) {
|
||||
font-size: 26rpx;
|
||||
color: #999;
|
||||
margin: 0 30rpx;
|
||||
}
|
||||
|
||||
text:nth-child(3) {
|
||||
font-size: 26rpx;
|
||||
color: #333;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.favorable_right.column {
|
||||
align-items: flex-start;
|
||||
}
|
||||
}
|
||||
|
||||
.favorable.column {
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.cell-item.column {
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.total-wrap {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: flex-end;
|
||||
padding: 0 34rpx;
|
||||
font-weight: bold;
|
||||
font-size: 28rpx;
|
||||
color: #333333;
|
||||
margin-top: 64rpx;
|
||||
|
||||
.price {
|
||||
font-weight: bold;
|
||||
font-size: 36rpx;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
.order_footer {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 34rpx;
|
||||
position: relative;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
.fixedview {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
|
||||
.flex-between {
|
||||
width: 100%;
|
||||
padding: 36rpx 54rpx 102rpx 54rpx;
|
||||
background: #FFFFFF;
|
||||
|
||||
.fixedview_one {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
|
||||
.fixedview_oneone {
|
||||
font-weight: 400;
|
||||
font-size: 28rpx;
|
||||
color: #666666;
|
||||
}
|
||||
|
||||
.fixedview_onetow {
|
||||
font-weight: bold;
|
||||
font-size: 32rpx;
|
||||
color: #333333;
|
||||
|
||||
text {
|
||||
font-size: 24rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.fixedview_tow {
|
||||
width: 140rpx;
|
||||
height: 56rpx;
|
||||
line-height: 56rpx;
|
||||
text-align: center;
|
||||
background: #E3AD7F;
|
||||
border-radius: 12rpx 12rpx 12rpx 12rpx;
|
||||
font-weight: 400;
|
||||
font-size: 28rpx;
|
||||
color: #FFFFFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,8 @@
|
|||
<template>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
</script>
|
||||
|
||||
<style>
|
||||
</style>
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -164,12 +164,26 @@
|
|||
if (!item.show) {
|
||||
return false;
|
||||
}
|
||||
// 查找选中的数组里面 统计指定 id 的重复次数
|
||||
const count = Selectedlist.value.filter(item => item.id === item.id).length;
|
||||
if (item.Selected) {
|
||||
Selectedlist.value = Selectedlist.value.filter(i => i.id !== item.id)
|
||||
fromInfo.list[index].Selected = false
|
||||
return
|
||||
}
|
||||
|
||||
// 查找选中的数组里面 统计指定 id 的重复次数
|
||||
const foundObject = mergedArray.value.find(i => i.productId === item.proId)
|
||||
if (foundObject.num <= count) {
|
||||
const canSelMaxNum = Orderinfo.shoppingCart.filter((v) => v.productId == item.proId).reduce((prve,
|
||||
cur) => {
|
||||
return prve + cur.num * 1
|
||||
}, 0)
|
||||
if (canSelMaxNum <= 0) {
|
||||
uni.showToast({
|
||||
title: '不可多余商品!',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
// 查找选中的数组里面 统计指定 id 的重复次数
|
||||
const count = Selectedlist.value.filter(v => v.couponId == item.couponId).length;
|
||||
if (count >= canSelMaxNum) {
|
||||
uni.showToast({
|
||||
title: '不可多余商品!',
|
||||
icon: 'none'
|
||||
|
|
@ -190,18 +204,14 @@
|
|||
// return false;
|
||||
// }
|
||||
|
||||
if (item.Selected) {
|
||||
Selectedlist.value = Selectedlist.value.filter(i => i.id !== item.id)
|
||||
} else {
|
||||
// 筛查出最低价格
|
||||
await productmethod()
|
||||
const matchedItem = lowestPrices.value.find(cartItem => cartItem.productId == item.proId);
|
||||
Selectedlist.value.push({
|
||||
...item,
|
||||
price: matchedItem.price,
|
||||
memberPrice: matchedItem.memberPrice
|
||||
})
|
||||
}
|
||||
// 筛查出最低价格
|
||||
await productmethod()
|
||||
const matchedItem = lowestPrices.value.find(cartItem => cartItem.productId == item.proId);
|
||||
Selectedlist.value.push({
|
||||
...item,
|
||||
price: matchedItem.price,
|
||||
memberPrice: matchedItem.memberPrice
|
||||
})
|
||||
fromInfo.list[index].Selected = !item.Selected
|
||||
}
|
||||
|
||||
|
|
@ -272,13 +282,14 @@
|
|||
shopUserId: Orderinfo.shopUserId,
|
||||
})
|
||||
|
||||
if (Orderinfo.typeOrder == 2 && res.length>0) {
|
||||
if (Orderinfo.typeOrder == 2 && res.length > 0) {
|
||||
res.forEach((item) => {
|
||||
item.Selected = false
|
||||
})
|
||||
res = res.map(item => {
|
||||
const matchedItem = Orderinfo.shoppingCart.find(cartItem => cartItem.productId == item
|
||||
.proId);
|
||||
const matchedItem = Orderinfo.shoppingCart.find(cartItem => {
|
||||
return cartItem.productId == item.proId
|
||||
});
|
||||
const hasMatch = Boolean(matchedItem);
|
||||
return {
|
||||
...item,
|
||||
|
|
@ -336,7 +347,10 @@
|
|||
|
||||
Orderinfo.shopUserId = options.shopUserId
|
||||
Orderinfo.payAmount = options.payAmount
|
||||
console.log('coupon mounted');
|
||||
console.log(Orderinfo.payAmount)
|
||||
console.log(options);
|
||||
console.log(JSON.parse(decodeURIComponent(options.shoppingCart)));
|
||||
Orderinfo.shoppingCart = JSON.parse(decodeURIComponent(options.shoppingCart))
|
||||
}
|
||||
getCouponList()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
<template>
|
||||
<view>
|
||||
历史订单
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
</style>
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
<template>
|
||||
<view>
|
||||
<up-popup :show="confirmordershow" :round="20" :safeAreaInsetBottom="false" :zIndex="105"
|
||||
close-on-click-overlay
|
||||
:overlayStyle="{ zIndex: 98 }" @close="close">
|
||||
<!-- 头部内容 -->
|
||||
<view class="container">
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
</view>
|
||||
<view class="flex-between" @click="cartclear">
|
||||
<up-icon name="trash" color="#999" size="20"></up-icon>
|
||||
<text class="t">清空购物车</text>
|
||||
<text class="clear-btn">清空购物车</text>
|
||||
</view>
|
||||
|
||||
</view>
|
||||
|
|
@ -65,7 +65,7 @@
|
|||
|
||||
<view class="operation-wrap">
|
||||
<view class="btn">
|
||||
<up-icon name="minus-circle-fill" size="25"></up-icon>
|
||||
<up-icon color="#E8AD7B" name="minus-circle" size="25"></up-icon>
|
||||
<view class="btnClick" @click="cartListadd(item,'-')"></view>
|
||||
</view>
|
||||
<text class="num">{{ ifcartNumber(item) }}</text>
|
||||
|
|
@ -73,7 +73,7 @@
|
|||
<!-- <up-icon name="plus-circle-fill"
|
||||
:color="{shopInfo.isVip ==1 && shopInfo.isMemberPrice==1? '#CECECE' : '#E9AB7A'"
|
||||
size="25"></up-icon> -->
|
||||
<up-icon name="plus-circle-fill" color="#E9AB7A"
|
||||
<up-icon name="plus-circle-fill" color="#E8AD7B"
|
||||
size="25"></up-icon>
|
||||
<view class="btnClick" @click="cartListadd(item,'+')"></view>
|
||||
</view>
|
||||
|
|
@ -83,56 +83,7 @@
|
|||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 历史订单 -->
|
||||
<view class="card" v-if="orderinfo.detailMap">
|
||||
<!-- 订单头部 -->
|
||||
<view class="cardcalorders flex-between">
|
||||
<!-- ··· 历史订单 ··· -->
|
||||
<text>待支付订单</text>
|
||||
<view class="flex-start">
|
||||
<up-icon name="trash" color="#999" size="20"></up-icon>
|
||||
<text style="color:' #999;'" @click="clickcancelOrder('all')">清空历史订单</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="card_item" v-for="(value, key) in orderinfo.detailMap" :key="key">
|
||||
<view class="head">
|
||||
<view class="head_left">
|
||||
<text class="placeNum">第{{key}}次下单</text>
|
||||
<view class="placeTime flex-start">
|
||||
<up-icon name="trash" color="#999"></up-icon>
|
||||
<text class="t" @click="clickcancelOrder('Single',key)">清空</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 订单详情 -->
|
||||
<view class="shop-info">
|
||||
<view class="item" v-for="item in value" :key="item.id">
|
||||
<view class="cover">
|
||||
<up-image width="80" radius="10" height="80" :src="item.productImg"
|
||||
v-if="item.productId!=-999"></up-image>
|
||||
<up-image width="80" radius="10" height="80"
|
||||
:src="'https://czg-qr-order.oss-cn-beijing.aliyuncs.com/confirmOrder/table.png'"
|
||||
mode="heightFix" v-else></up-image>
|
||||
</view>
|
||||
<view class="info">
|
||||
<text class="productName">{{item.productName}}</text>
|
||||
<text class="productSkuName" v-if="item.skuName">{{item.skuName}}</text>
|
||||
</view>
|
||||
|
||||
<view class="price">
|
||||
<view class="priceAmount">
|
||||
¥{{shopInfo.isVip ==1 && shopInfo.isMemberPrice==1?(item.memberPrice||item.price):item.price}}
|
||||
</view>
|
||||
<view class="num">x{{item.num}}</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="semicircle_icon" v-if="index > 0">
|
||||
<view class="semicircle_left_icon"></view>
|
||||
<view class="semicircle_right_icon"></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
|
|
@ -289,6 +240,11 @@
|
|||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.clear-btn{
|
||||
color: #333;
|
||||
font-size: 24rpx;
|
||||
font-weight: 500;
|
||||
}
|
||||
.cart-list-wrap {
|
||||
.cart-header {
|
||||
display: flex;
|
||||
|
|
|
|||
|
|
@ -8,8 +8,13 @@
|
|||
mode="aspectFill">
|
||||
</image>
|
||||
<view class="panelone flex-start">
|
||||
<view>
|
||||
{{ shopInfo.shopName }}
|
||||
<view class="u-flex u-flex-y-center">
|
||||
<text>
|
||||
{{ shopInfo.shopName }}
|
||||
</text>
|
||||
<view class="u-flex u-flex-y-center u-m-t-4">
|
||||
<up-icon name="arrow-right" color="#999999" size="14"></up-icon>
|
||||
</view>
|
||||
</view>
|
||||
<!-- <up-icon name="arrow-right" color="#999999" size="14"></up-icon> -->
|
||||
</view>
|
||||
|
|
@ -31,7 +36,8 @@
|
|||
<view class="panelfour" v-if="shopProductList.hots && shopProductList.hots.length > 0">
|
||||
本店招牌菜
|
||||
</view>
|
||||
<view class="panelfive">
|
||||
<view class="panelfive ">
|
||||
|
||||
<scroll-view :scroll-x="true" :scroll-with-animation="false">
|
||||
<view class="panelfive_list">
|
||||
<view class="panelfiveitem" @click="clickspecifications(item,index,index,'热销')"
|
||||
|
|
@ -142,7 +148,7 @@
|
|||
</view>
|
||||
|
||||
<!-- 滚动区域 -->
|
||||
<view class="scroll-panel" id="scroll-panel" :class="{ 'grayscale':!isBusinessTime }">
|
||||
<view class="scroll-panel " id="scroll-panel" :class="{ 'grayscale':!isBusinessTime }">
|
||||
<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"
|
||||
|
|
@ -257,6 +263,8 @@
|
|||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
|
||||
</view>
|
||||
|
||||
<confirmorder ref="confirmorderref" :cartLists_count="cartLists_count" :cartList="matchedProducts"
|
||||
|
|
@ -288,7 +296,7 @@
|
|||
<text class="num">{{totalPrices}}</text>
|
||||
</view>
|
||||
<view class="btn" @tap="$u.debounce(orderdetail, 500)">
|
||||
<text class="t">去结算</text>
|
||||
<text class="t">结算</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
|
@ -406,7 +414,10 @@
|
|||
</view>
|
||||
</view>
|
||||
</up-popup>
|
||||
|
||||
<view class="history_order" @click="toHistory" v-if="shopInfo&&shopInfo.registerType == 'after'&&orderinfo.id">
|
||||
<image class="img" src="@/static/history.png" mode=""></image>
|
||||
<text>已下单菜品</text>
|
||||
</view>
|
||||
<Loading :isLoading="isLoading" />
|
||||
</view>
|
||||
</template>
|
||||
|
|
@ -1123,7 +1134,6 @@
|
|||
shop_id: uni.cache.get('shopId')
|
||||
}
|
||||
}
|
||||
|
||||
const {
|
||||
isConnected,
|
||||
sendMessage,
|
||||
|
|
@ -1140,8 +1150,6 @@
|
|||
// 提交订单显示
|
||||
const confirmordershow = ref(false)
|
||||
|
||||
// 购物车数组
|
||||
const cartList = ref([])
|
||||
|
||||
// 更新商品数量的方法
|
||||
const updateProductQuantities = () => {
|
||||
|
|
@ -1195,6 +1203,7 @@
|
|||
if (isDataLoaded.value && receivedMessages.value) {
|
||||
const Message = receivedMessages.value
|
||||
if (Message) {
|
||||
console.log(Message.data);
|
||||
// 心跳返回 过滤
|
||||
if (Message.type == "ping_interval" || Message.msg_id == "ping_interval") {
|
||||
isLoading.value = false;
|
||||
|
|
@ -1208,14 +1217,14 @@
|
|||
|
||||
// 初始化
|
||||
if (Message.operate_type == "init") {
|
||||
cartList.value = Message.data
|
||||
cartStore.carts = Message.data
|
||||
uni.hideLoading();
|
||||
isLoading.value = false;
|
||||
}
|
||||
|
||||
// 清空购物车
|
||||
if (Message.operate_type == 'cleanup') {
|
||||
cartList.value = []
|
||||
cartStore.carts = []
|
||||
setTimeout(() => {
|
||||
Historicalorders()
|
||||
}, 400)
|
||||
|
|
@ -1225,18 +1234,18 @@
|
|||
// 删除除购物车
|
||||
if (Message.operate_type == 'del' && Message.status == 1) {
|
||||
// 优化:使用可选链操作符避免报错
|
||||
cartList.value = cartList.value.filter(item => item.id !== Message.data?.id);
|
||||
// cartList.value = cartList.value.filter(item => item.id != Message.data.id);
|
||||
cartStore.carts = cartStore.carts.filter(item => item.id !== Message.data?.id);
|
||||
// cartStore.carts = cartStore.carts.filter(item => item.id != Message.data.id);
|
||||
}
|
||||
|
||||
// 添加或者减少购物后返回
|
||||
if (Message.operate_type == 'add' || Message.operate_type == 'edit') {
|
||||
[Message.data].forEach((objA) => {
|
||||
const index = cartList.value.findIndex((objB) => objB.id == objA.id);
|
||||
const index = cartStore.carts.findIndex((objB) => objB.id == objA.id);
|
||||
if (index !== -1) {
|
||||
cartList.value[index] = objA;
|
||||
cartStore.carts[index] = objA;
|
||||
} else {
|
||||
cartList.value.push(objA);
|
||||
cartStore.carts.push(objA);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -1295,7 +1304,7 @@
|
|||
|
||||
// 更新购物车数据shopProductList.hots
|
||||
const matchedProducts = computed(() => {
|
||||
if (cartList.value.length > 0) {
|
||||
if (cartStore.carts.length > 0) {
|
||||
let Specialstop = null
|
||||
|
||||
try {
|
||||
|
|
@ -1308,7 +1317,7 @@
|
|||
Specialstop = shopProductList.productInfo
|
||||
//TODO handle the exception
|
||||
}
|
||||
return cartList.value.flatMap((cartItem) => {
|
||||
return cartStore.carts.flatMap((cartItem) => {
|
||||
for (const group of Specialstop) {
|
||||
for (const product of group.productList) {
|
||||
if (product.id == cartItem.product_id) {
|
||||
|
|
@ -1365,6 +1374,12 @@
|
|||
|
||||
// 结账
|
||||
const orderdetail = async () => {
|
||||
uni.navigateTo({
|
||||
url: '/pages/order/confirm-order?tableCode=' + uni.cache.get('tableCode') + '&shopId=' + uni
|
||||
.cache.get(
|
||||
'shopId')
|
||||
})
|
||||
return
|
||||
try {
|
||||
await Historicalorders()
|
||||
} catch (error) {}
|
||||
|
|
@ -1374,16 +1389,18 @@
|
|||
|
||||
// 历史订单
|
||||
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
|
||||
} else {
|
||||
let res = await APIhistoryOrder({
|
||||
tableCode: uni.cache.get('tableCode'),
|
||||
})
|
||||
orderinfo.value = {
|
||||
id: res.id,
|
||||
detailMap: res.detailMap,
|
||||
placeNum: res.placeNum
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1449,7 +1466,7 @@
|
|||
}
|
||||
}, 0);
|
||||
}
|
||||
cart = parseFloat(cartone) + parseFloat(cart)
|
||||
cart = parseFloat(cart)
|
||||
// 向上取整并保留两位小数
|
||||
return parseFloat(cart.toFixed(2));
|
||||
});
|
||||
|
|
@ -1467,7 +1484,7 @@
|
|||
return sum + num;
|
||||
}, 0);
|
||||
|
||||
const totalCount = orderInfoCount + matchedProductsCount;
|
||||
const totalCount = matchedProductsCount;
|
||||
return parseFloat(totalCount.toFixed(2));
|
||||
});
|
||||
|
||||
|
|
@ -1499,7 +1516,7 @@
|
|||
// 计算处理后的购物车列表 // 用于筛选后的购物车数组
|
||||
const cartListFilter = computed(() => {
|
||||
// 使用 reduce 方法对 cartList 进行处理
|
||||
const grouped = cartList.value.reduce((acc, item) => {
|
||||
const grouped = cartStore.carts.reduce((acc, item) => {
|
||||
const productId = item.product_id;
|
||||
const num = parseFloat(item.number);
|
||||
|
||||
|
|
@ -1554,6 +1571,7 @@
|
|||
|
||||
// 列表请求
|
||||
const productqueryProduct = async () => {
|
||||
cartStore.goodsIsloading = false;
|
||||
try {
|
||||
shopProductList.hots = await productminiApphotsquery()
|
||||
shopProductList.productInfo = await APIgroupquery()
|
||||
|
|
@ -1574,12 +1592,15 @@
|
|||
product.cartNumber = 0;
|
||||
product.isSaleTimeshow = await isProductAvailable(product.days, product
|
||||
.startTime, product.endTime)
|
||||
cartStore.setGoodsMap(product.id, product)
|
||||
});
|
||||
});
|
||||
shopProductList.hots.forEach(async (i) => {
|
||||
i.cartNumber = 0
|
||||
i.isSaleTimeshow = await isProductAvailable(i.days, i.startTime, i.endTime)
|
||||
cartStore.setGoodsMap(i.id, i)
|
||||
})
|
||||
cartStore.goodsIsloading = true;
|
||||
scrollTopSize.value = 0
|
||||
topArr.value = []
|
||||
// userStore.actionsAPIuser()
|
||||
|
|
@ -1623,13 +1644,34 @@
|
|||
const currentPage = pages[pages.length - 1];
|
||||
// 获取页面参数
|
||||
const options = currentPage.options;
|
||||
let res = await APIhistoryOrder({
|
||||
tableCode: uni.cache.get('tableCode'),
|
||||
})
|
||||
|
||||
await productqueryProduct()
|
||||
if (res && res.id && shopInfo.registerType == "after") {
|
||||
toHistory()
|
||||
return
|
||||
}
|
||||
setTimeout(() => {
|
||||
// 启动网络监听
|
||||
initNetworkListener()
|
||||
getElementTop()
|
||||
}, 500)
|
||||
})
|
||||
|
||||
|
||||
//跳转历史订单
|
||||
function toHistory() {
|
||||
uni.navigateTo({
|
||||
url: '/pages/order/confirm-order?tableCode=' + uni.cache.get('tableCode') + '&shopId=' + uni
|
||||
.cache.get(
|
||||
'shopId')
|
||||
})
|
||||
// uni.navigateTo({
|
||||
// url: '/pages/order/confirm-order?orderId=' + orderinfo.id + '&shopId=' + uni.cache.get('shopId')+'&tableCode='+uni.cache.get('tableCode')
|
||||
// })
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
|
@ -1893,6 +1935,8 @@
|
|||
}
|
||||
|
||||
.scroll-panel {
|
||||
position: relative;
|
||||
|
||||
.list-box {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
|
|
@ -2538,14 +2582,36 @@
|
|||
height: 64rpx;
|
||||
line-height: 64rpx;
|
||||
text-align: center;
|
||||
background: #E7AE7B;
|
||||
background: #FEFAF7;
|
||||
border-radius: 36rpx 36rpx 36rpx 36rpx;
|
||||
border: 2rpx solid #E8AD7B;
|
||||
border: 2rpx solid $my-main-color;
|
||||
font-weight: bold;
|
||||
font-size: 28rpx;
|
||||
color: #FFFFFF;
|
||||
color: $my-main-color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.history_order {
|
||||
background-color: #fff;
|
||||
padding: 12rpx 16rpx;
|
||||
font-size: 24rpx;
|
||||
color: #333;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
box-shadow: 0rpx 6rpx 12rpx 2rpx rgba(0, 0, 0, 0.16);
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
right: 0;
|
||||
transform: translateY(-50%);
|
||||
border-radius: 100px 0 0 100px;
|
||||
z-index: 20;
|
||||
|
||||
.img {
|
||||
width: 36rpx;
|
||||
margin-right: 8rpx;
|
||||
height: 36rpx;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
<template>
|
||||
<view class="u-p-30">
|
||||
<view>
|
||||
<up-button type="warning" @click="popupShow">初始化</up-button>
|
||||
</view>
|
||||
<view class="u-m-t-30">
|
||||
<up-button type="primary" @click="toCreate">去下单</up-button>
|
||||
</view>
|
||||
|
||||
<up-popup :show="show" mode="bottom" close-on-click-overlay @close="resetForm">
|
||||
<view class="u-p-30">
|
||||
<up-form label-width="80" ref="refForm">
|
||||
<up-form-item label="台桌码">
|
||||
<up-input v-model="form.tableCode" placeholder="请输入台桌码"></up-input>
|
||||
</up-form-item>
|
||||
</up-form>
|
||||
<view class="u-flex gap-20 u-m-t-30">
|
||||
<up-button @click="show=false">取消</up-button>
|
||||
<up-button type="primary" @click="scanCodehandle">确定</up-button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
</up-popup>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import {onLoad} from '@dcloudio/uni-app'
|
||||
import { reactive,ref} from 'vue'
|
||||
import {
|
||||
productStore
|
||||
} from '@/stores/user.js';
|
||||
const store = productStore();
|
||||
const scanCodehandle = async (i) => {
|
||||
await store.scanCodeactions(form)
|
||||
}
|
||||
const show=ref(false);
|
||||
const options=ref({})
|
||||
function popupShow(){
|
||||
show.value=true;
|
||||
}
|
||||
const refForm=ref(null);
|
||||
const form=reactive({
|
||||
tableCode:"40963902920"
|
||||
})
|
||||
function resetForm(){
|
||||
form.tableCode=""
|
||||
}
|
||||
onLoad((opt)=>{
|
||||
console.log(opt);
|
||||
options.value=opt
|
||||
})
|
||||
function toCreate(){
|
||||
uni.navigateTo({
|
||||
url:'/pages/index/index'
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.gap-20{
|
||||
gap: 20rpx;
|
||||
}
|
||||
|
||||
</style>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 619 B |
Binary file not shown.
|
After Width: | Height: | Size: 918 B |
Binary file not shown.
|
After Width: | Height: | Size: 964 B |
Binary file not shown.
|
After Width: | Height: | Size: 693 B |
|
|
@ -0,0 +1,452 @@
|
|||
import {
|
||||
defineStore
|
||||
} from 'pinia';
|
||||
import {
|
||||
ref,
|
||||
computed,
|
||||
reactive,
|
||||
watchEffect
|
||||
} from 'vue';
|
||||
import {
|
||||
productminiApphotsquery,
|
||||
APIgroupquery,
|
||||
} from "@/common/api/product/product.js";
|
||||
export const useCartsStore = defineStore('cart',
|
||||
() => {
|
||||
// const dinersNum = uni.cache.get('dinersNum')
|
||||
// const isVip = uni.cache.get('orderVIP').isVip //此用户是否是会员
|
||||
// const isMemberPrice = uni.cache.get('ordershopUserInfo').isMemberPrice //此店是否可以用会员
|
||||
// const isTableFee = uni.cache.get('ordershopUserInfo').isTableFee //此店是否免桌位费
|
||||
// const tableFee = uni.cache.get('ordershopUserInfo').tableFee //一个餐位费多钱
|
||||
|
||||
const goodsIsloading = ref(true);
|
||||
|
||||
|
||||
|
||||
//商品数据Map
|
||||
const goodsMap = reactive({})
|
||||
//获取商品数据
|
||||
async function goodsInit() {
|
||||
goodsIsloading.value=true;
|
||||
//获取招牌菜商品
|
||||
const hotres = await productminiApphotsquery();
|
||||
for (let product of hotres) {
|
||||
setGoodsMap(product.id, product)
|
||||
}
|
||||
//获取分组商品
|
||||
const groupres = await APIgroupquery()
|
||||
for (let group of groupres) {
|
||||
for (let product of group.productList) {
|
||||
setGoodsMap(product.id, product)
|
||||
}
|
||||
}
|
||||
goodsIsloading.value = false
|
||||
}
|
||||
|
||||
function setGoodsMap(product_id, data) {
|
||||
goodsMap[product_id] = data;
|
||||
}
|
||||
|
||||
//websocket回执
|
||||
const websocketsendMessage = (data) => {
|
||||
uni.$u.debounce(sendMessage(data), 500)
|
||||
}
|
||||
|
||||
const isLoading = ref(true);
|
||||
|
||||
function getProductDetails(v) {
|
||||
const goods = goodsMap[v.product_id]
|
||||
if (!goods) {
|
||||
return undefined
|
||||
}
|
||||
let skuData = undefined;
|
||||
skuData = goods?.skuList.find((sku) => sku.id == v.sku_id);
|
||||
|
||||
// if (goods.type == 'package') {
|
||||
// //套餐商品
|
||||
// const SnapSku = findInGroupSnapSku(goods.groupSnap, v.sku_id)
|
||||
// skuData = { ...SnapSku, salePrice: SnapSku ? SnapSku.price : 0 }
|
||||
// } else {
|
||||
// skuData = goods?.skuList.find((sku: { id: string, salePrice: number }) => sku.id == v.sku_id);
|
||||
// }
|
||||
skuData = goods?.skuList.find((sku) => sku.id == v.sku_id);
|
||||
|
||||
if (skuData) {
|
||||
return {
|
||||
...v,
|
||||
productId: v.product_id,
|
||||
salePrice: skuData ? skuData.salePrice : 0,
|
||||
price: skuData ? skuData.salePrice : 0,
|
||||
memberPrice: skuData ? skuData.memberPrice : 0,
|
||||
coverImg: goods.coverImg,
|
||||
productImg: goods.coverImg,
|
||||
name: goods.name,
|
||||
productName: goods.name,
|
||||
specInfo: skuData.specInfo,
|
||||
packFee: goods.packFee || 0,
|
||||
type: goods.type,
|
||||
skuData,
|
||||
skuName: skuData.name,
|
||||
num: v.number * 1
|
||||
}
|
||||
} else {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
// 用于记录已经处理过的消息的 msg_id
|
||||
const processedMessageIds = new Set();
|
||||
|
||||
//购物车商品信息补全初始化
|
||||
function cartsGoodsInfoInit(arr) {
|
||||
carts.value = arr.map(v => {
|
||||
return getProductDetails(v)
|
||||
}).filter(v => v)
|
||||
}
|
||||
|
||||
|
||||
//收到socket消息时对购物车进行处理
|
||||
async function onMessage(Message) {
|
||||
console.log('Message');
|
||||
console.log(Message);
|
||||
if (Message) {
|
||||
// 心跳返回 过滤
|
||||
if (Message.type == "ping_interval" || Message.msg_id == "ping_interval") {
|
||||
isLoading.value = false;
|
||||
return false
|
||||
}
|
||||
// 检查消息是否已经处理过
|
||||
if (processedMessageIds.has(Message.msg_id)) {
|
||||
return;
|
||||
}
|
||||
processedMessageIds.add(Message.msg_id);
|
||||
const msgData = Message.data
|
||||
// 初始化
|
||||
if (Message.operate_type == "init") {
|
||||
console.log('carts init', msgData);
|
||||
cartsGoodsInfoInit(msgData)
|
||||
uni.hideLoading();
|
||||
isLoading.value = false;
|
||||
}
|
||||
|
||||
// 清空购物车
|
||||
if (Message.operate_type == 'cleanup') {
|
||||
carts.value = []
|
||||
}
|
||||
|
||||
// 删除除购物车
|
||||
if (Message.operate_type == 'del' && Message.status == 1) {
|
||||
// 优化:使用可选链操作符避免报错
|
||||
carts.value = carts.value.filter(item => item.id !== msgData?.id);
|
||||
// carts.value = carts.value.filter(item => item.id != Message.data.id);
|
||||
}
|
||||
|
||||
// 添加或者减少购物后返回
|
||||
if (Message.operate_type == 'add' || Message.operate_type == 'edit') {
|
||||
const index = carts.value.findIndex((v => v.id == msgData.id))
|
||||
if (index !== -1) {
|
||||
carts.value[index] = getProductDetails(msgData);
|
||||
} else {
|
||||
carts.value.push(getProductDetails(msgData));
|
||||
}
|
||||
}
|
||||
|
||||
// 历史订单
|
||||
if (Message.operate_type == 'clearOrder') {}
|
||||
|
||||
// 购物车数据更新从新请求
|
||||
if (Message.type == 'product' && Message.data_type == 'product_update' && Message
|
||||
.operate_type == 'product_update') {
|
||||
await goodsInit()
|
||||
await cartsGoodsInfoInit()
|
||||
}
|
||||
|
||||
// 提示
|
||||
if (Message.status == 0 && Message.type != 'no_suit_num') {
|
||||
uni.showToast({
|
||||
title: Message.msg,
|
||||
icon: "none"
|
||||
})
|
||||
}
|
||||
|
||||
if (Message.type == 'no_suit_num') {
|
||||
// console.log(specifications)
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
showCancel: false,
|
||||
content: '此商品库存不足起售数量!',
|
||||
success: async (data) => {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//购物车数据
|
||||
const carts = ref([])
|
||||
|
||||
//历史订单数据
|
||||
const oldOrder = ref({
|
||||
detailMap: {},
|
||||
originAmount: 0
|
||||
})
|
||||
|
||||
|
||||
// 会员信息
|
||||
const orderVIP = ref(uni.cache.get('orderVIP') || {
|
||||
isVip: false
|
||||
})
|
||||
|
||||
function updateData(key, newval) {
|
||||
if (key === 'orderVIP') {
|
||||
uni.cache.set('orderVIP', newval)
|
||||
return orderVIP.value = newval
|
||||
}
|
||||
if (key === 'shopInfo') {
|
||||
uni.cache.set('shopInfo', newval)
|
||||
return shopInfo.value = newval
|
||||
}
|
||||
}
|
||||
|
||||
// 商品订单会员
|
||||
const shopInfo = ref(uni.cache.get('shopInfo') || {
|
||||
isMemberPrice: 0
|
||||
})
|
||||
|
||||
//是否使用会员价
|
||||
const useVipPrice = computed(() => {
|
||||
const isUse=(orderVIP.value.isVip && shopInfo.value.isMemberPrice)?true:false
|
||||
console.log('useVipPrice',isUse);
|
||||
return isUse
|
||||
})
|
||||
function currentCalcMpneyNumber(item){
|
||||
const n=item.number-(item.returnNum||0)
|
||||
return n<=0?0:n
|
||||
}
|
||||
//历史订单商品价格总和
|
||||
const oldOrderMoney = computed(() => {
|
||||
let total = 0
|
||||
for (let i in oldOrder.value.detailMap) {
|
||||
total += oldOrder.value.detailMap[i].reduce((prve, cur) => {
|
||||
if (cur.isGift) {
|
||||
return prve + 0
|
||||
}
|
||||
const discount_sale_amount = cur.discount_sale_amount * 1 || 0
|
||||
const memberPrice = cur.skuData ? (cur.skuData.memberPrice || cur.skuData
|
||||
.salePrice) : 0
|
||||
const price = (discount_sale_amount || cur.salePrice || 0)
|
||||
const number =currentCalcMpneyNumber(cur)
|
||||
return prve + (number <= 0 ? 0 : number) * (discount_sale_amount || (useVipPrice
|
||||
.value ? memberPrice : price))
|
||||
}, 0)
|
||||
}
|
||||
return total
|
||||
})
|
||||
|
||||
//当前购物车总价格
|
||||
const totalPrice = computed(() => {
|
||||
const money = carts.value.reduce((prve, cur) => {
|
||||
const memberPrice = cur.memberPrice || cur.salePrice
|
||||
const price = useVipPrice.value ? memberPrice : cur.salePrice;
|
||||
const curMoney = price * currentCalcMpneyNumber(cur)
|
||||
return prve + curMoney
|
||||
}, 0)
|
||||
return money
|
||||
})
|
||||
// 霸王餐购物车原价,不享受任何优惠
|
||||
const totalOriginPrice = computed(() => {
|
||||
const money = carts.value.reduce((prve, cur) => {
|
||||
const curMoney = cur.salePrice * currentCalcMpneyNumber(cur)
|
||||
return prve + curMoney
|
||||
}, 0)
|
||||
return money
|
||||
})
|
||||
|
||||
//商品券抵扣金额
|
||||
// const productCouponDiscountAmount = computed(() => {
|
||||
// let index = -1;
|
||||
// return quansSelArr.value.reduce((pre, cur) => {
|
||||
// index++;
|
||||
// return pre + returnProDiscount(cur, index) * 1;
|
||||
// }, 0);
|
||||
// });
|
||||
|
||||
|
||||
//返回打包数量(称重商品打包数量最大为1)
|
||||
function returnCartPackNumber(cur) {
|
||||
const maxReturnNum = cur.number - (cur.returnNum || 0);
|
||||
let pack_number = cur.number;
|
||||
pack_number = (cur.product_type == 'weight' && pack_number > 1) ? 1 : pack_number;
|
||||
pack_number = Math.min(maxReturnNum, pack_number);
|
||||
pack_number = pack_number <= 0 ? 0 : pack_number
|
||||
return pack_number * 1
|
||||
}
|
||||
|
||||
|
||||
//当前购物车打包费
|
||||
const totalPackFee = computed(() => {
|
||||
const money = carts.value.reduce((prve, cur) => {
|
||||
const curMoney = (cur.packFee || 0) * currentCalcMpneyNumber(cur)
|
||||
return prve + curMoney
|
||||
}, 0)
|
||||
return money
|
||||
})
|
||||
|
||||
//打包费
|
||||
const packFee = computed(() => {
|
||||
const nowPackFee = carts.value.reduce((acc, cur) => {
|
||||
return acc + (cur.packFee || 0) * returnCartPackNumber(cur)
|
||||
}, 0)
|
||||
let oldPackfee = 0;
|
||||
for (let i in oldOrder.value.detailMap) {
|
||||
oldPackfee += oldOrder.value.detailMap[i].reduce((prve, cur) => {
|
||||
return prve + (cur.packFee || 0) * returnCartPackNumber(cur)
|
||||
}, 0)
|
||||
}
|
||||
return nowPackFee + oldPackfee
|
||||
})
|
||||
|
||||
//购物车是否为空
|
||||
const isEmpty = computed(() => {
|
||||
return !carts.value || carts.value.length <= 0
|
||||
})
|
||||
// 计算向上取整
|
||||
const roundUpToTwoDecimals = (num, i) => {
|
||||
// 先将数字乘以 100 并转换为字符串保留足够的小数位
|
||||
let temp = (num * 100).toFixed(10);
|
||||
// 向上取整
|
||||
let rounded = null
|
||||
if (i == 'upward') {
|
||||
rounded = Math.ceil(parseFloat(temp));
|
||||
} else {
|
||||
rounded = Math.floor(parseFloat(temp));
|
||||
}
|
||||
// 再除以 100 得到保留两位小数的结果
|
||||
return rounded / 100;
|
||||
};
|
||||
|
||||
// 精确计算函数
|
||||
const preciseCalculation = (num1, num2) => {
|
||||
// 将数字转换为整数,乘以 100 以保留两位小数
|
||||
const int1 = BigInt(Math.round(num1 * 100));
|
||||
const int2 = BigInt(Math.round(num2 * 100));
|
||||
// 执行乘法运算
|
||||
const result = int1 * int2;
|
||||
// 再除以 10000 以还原为原来的小数
|
||||
return Number(result) / 10000;
|
||||
};
|
||||
|
||||
// 计算购物车商品总价格
|
||||
const getTotalTotalPrices = (matchedProducts, isBwc = true) => {
|
||||
if (!matchedProducts || !Array.isArray(matchedProducts)) {
|
||||
return 0;
|
||||
}
|
||||
// console.log(uni.cache.get('orderVIP').isVip, uni.cache.get('ordershopUserInfo').isMemberPrice,
|
||||
// 111)
|
||||
// 购物车总数价格
|
||||
console.log('isBwc');
|
||||
console.log(isBwc);
|
||||
let cart = matchedProducts.reduce((total, item) => {
|
||||
if(isBwc===true){
|
||||
return total + (parseFloat(item.price) * parseFloat(item.num - item.returnNum));
|
||||
}
|
||||
// 是否启用会员价 0否1是
|
||||
if (useVipPrice.value) {
|
||||
// memberPrice会员价
|
||||
return total + (parseFloat(item.memberPrice || item.price) * parseFloat(item
|
||||
.num - item
|
||||
.returnNum));
|
||||
} else {
|
||||
// salePrice销售价
|
||||
return total + (parseFloat(item.price) * parseFloat(item.num - item.returnNum));
|
||||
}
|
||||
}, 0);
|
||||
|
||||
cart = cart.toFixed(2)
|
||||
console.log(parseFloat(cart))
|
||||
// 向上取整并保留两位小数
|
||||
// let result = roundUpToTwoDecimals(cart, 'upward')
|
||||
return parseFloat(cart);
|
||||
};
|
||||
|
||||
// 计算商品卷所选择的总价格
|
||||
const getTotalProductroll = (matchedProducts) => computed(() => {
|
||||
if (!matchedProducts || !Array.isArray(matchedProducts)) {
|
||||
return 0;
|
||||
}
|
||||
// 购物车总数价格
|
||||
let cart = matchedProducts.reduce((total, item) => {
|
||||
// 是否启用会员价 0否1是
|
||||
if (useVipPrice.value) {
|
||||
// memberPrice会员价
|
||||
return total + parseFloat(item.memberPrice || item.price)
|
||||
} else {
|
||||
// salePrice销售价
|
||||
return total + parseFloat(item.price)
|
||||
}
|
||||
}, 0);
|
||||
// 向上取整并保留两位小数
|
||||
let result = roundUpToTwoDecimals(cart, 'upward')
|
||||
return result;
|
||||
});
|
||||
|
||||
// 桌位置
|
||||
const getTotalSeatcharge = (seatNum) => computed(() => {
|
||||
// 是否免除桌位费 0 否 1 是
|
||||
let cart = 0
|
||||
|
||||
if (uni.cache.get('ordershopUserInfo').isTableFee == 0 && seatNum) {
|
||||
cart = parseFloat(seatNum) * parseFloat(uni.cache.get('ordershopUserInfo').tableFee)
|
||||
|
||||
// Math.ceil(parseFloat(seatNum) * parseFloat(
|
||||
// uni.cache.get('ordershopUserInfo').tableFee) * 100) / 100;
|
||||
}
|
||||
// 向下取整并保留两位小数
|
||||
let result = roundUpToTwoDecimals(cart, 'downward')
|
||||
return result;
|
||||
});
|
||||
|
||||
// 计算购物车总打包费用(向下取整并保留两位小数)
|
||||
const getTotalPackFee = (cartList) => computed(() => {
|
||||
const total = cartList.reduce((sum, item) => {
|
||||
return sum + (parseFloat(item.packAmount) * (parseFloat(item.packNumber) || (
|
||||
parseFloat(item.num) - parseFloat(item.returnNum))));
|
||||
}, 0);
|
||||
// 向下取整并保留两位小数
|
||||
let result = roundUpToTwoDecimals(total, 'downward')
|
||||
return result;
|
||||
// return Math.floor(total * 100) / 100;
|
||||
});
|
||||
|
||||
//获取热门商品
|
||||
async function getHotProduct() {
|
||||
|
||||
}
|
||||
|
||||
//获取分组商品
|
||||
async function getGroupProduct() {
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
getTotalPackFee,
|
||||
getTotalSeatcharge,
|
||||
getTotalTotalPrices,
|
||||
getTotalProductroll,
|
||||
carts,
|
||||
isEmpty,
|
||||
setGoodsMap,
|
||||
goodsIsloading,
|
||||
goodsInit,
|
||||
onMessage,
|
||||
totalPrice,
|
||||
totalPackFee,
|
||||
updateData,
|
||||
useVipPrice,totalOriginPrice
|
||||
};
|
||||
}
|
||||
);
|
||||
249
stores/order.js
249
stores/order.js
|
|
@ -2,130 +2,159 @@ import {
|
|||
defineStore
|
||||
} from 'pinia';
|
||||
import {
|
||||
ref,
|
||||
computed,
|
||||
reactive,
|
||||
watchEffect
|
||||
} from 'vue';
|
||||
import {
|
||||
ref
|
||||
} from 'vue';
|
||||
|
||||
export const useCartStore = defineStore('cart', () => {
|
||||
// const dinersNum = uni.cache.get('dinersNum')
|
||||
// const isVip = uni.cache.get('orderVIP').isVip //此用户是否是会员
|
||||
// const isMemberPrice = uni.cache.get('ordershopUserInfo').isMemberPrice //此店是否可以用会员
|
||||
// const isTableFee = uni.cache.get('ordershopUserInfo').isTableFee //此店是否免桌位费
|
||||
// const tableFee = uni.cache.get('ordershopUserInfo').tableFee //一个餐位费多钱
|
||||
export const useCartStore = defineStore('cart',
|
||||
() => {
|
||||
// const dinersNum = uni.cache.get('dinersNum')
|
||||
// const isVip = uni.cache.get('orderVIP').isVip //此用户是否是会员
|
||||
// const isMemberPrice = uni.cache.get('ordershopUserInfo').isMemberPrice //此店是否可以用会员
|
||||
// const isTableFee = uni.cache.get('ordershopUserInfo').isTableFee //此店是否免桌位费
|
||||
// const tableFee = uni.cache.get('ordershopUserInfo').tableFee //一个餐位费多钱
|
||||
|
||||
// 计算向上取整
|
||||
const roundUpToTwoDecimals = (num, i) => {
|
||||
// 先将数字乘以 100 并转换为字符串保留足够的小数位
|
||||
let temp = (num * 100).toFixed(10);
|
||||
// 向上取整
|
||||
let rounded = null
|
||||
if (i == 'upward') {
|
||||
rounded = Math.ceil(parseFloat(temp));
|
||||
} else {
|
||||
rounded = Math.floor(parseFloat(temp));
|
||||
//商品数据Map
|
||||
const goodsMap = reactive({})
|
||||
|
||||
function setGoodsMap(product_id, data) {
|
||||
goodsMap[product_id] = data;
|
||||
}
|
||||
// 再除以 100 得到保留两位小数的结果
|
||||
return rounded / 100;
|
||||
};
|
||||
|
||||
// 精确计算函数
|
||||
const preciseCalculation = (num1, num2) => {
|
||||
// 将数字转换为整数,乘以 100 以保留两位小数
|
||||
const int1 = BigInt(Math.round(num1 * 100));
|
||||
const int2 = BigInt(Math.round(num2 * 100));
|
||||
// 执行乘法运算
|
||||
const result = int1 * int2;
|
||||
// 再除以 10000 以还原为原来的小数
|
||||
return Number(result) / 10000;
|
||||
};
|
||||
|
||||
// 计算购物车商品总价格
|
||||
const getTotalTotalPrices = (matchedProducts, changeFreeenable = true) => computed(() => {
|
||||
if (!matchedProducts || !Array.isArray(matchedProducts)) {
|
||||
return 0;
|
||||
}
|
||||
// console.log(uni.cache.get('orderVIP').isVip, uni.cache.get('ordershopUserInfo').isMemberPrice,
|
||||
// 111)
|
||||
// 购物车总数价格
|
||||
let cart = matchedProducts.reduce((total, item) => {
|
||||
// 是否启用会员价 0否1是
|
||||
if (uni.cache.get('orderVIP').isVip == 1 && uni.cache.get('ordershopUserInfo')
|
||||
.isMemberPrice == 1 && changeFreeenable) {
|
||||
// memberPrice会员价
|
||||
return total + (parseFloat(item.memberPrice || item.price) * parseFloat(item
|
||||
.num - item
|
||||
.returnNum));
|
||||
|
||||
//购物车数据
|
||||
const carts = ref([])
|
||||
//购物车是否为空
|
||||
const isEmpty = computed(() => {
|
||||
return !carts.value || carts.value.length <= 0
|
||||
})
|
||||
// 计算向上取整
|
||||
const roundUpToTwoDecimals = (num, i) => {
|
||||
// 先将数字乘以 100 并转换为字符串保留足够的小数位
|
||||
let temp = (num * 100).toFixed(10);
|
||||
// 向上取整
|
||||
let rounded = null
|
||||
if (i == 'upward') {
|
||||
rounded = Math.ceil(parseFloat(temp));
|
||||
} else {
|
||||
// salePrice销售价
|
||||
return total + (parseFloat(item.price) * parseFloat(item.num - item.returnNum));
|
||||
rounded = Math.floor(parseFloat(temp));
|
||||
}
|
||||
}, 0);
|
||||
|
||||
cart = cart.toFixed(2)
|
||||
console.log(parseFloat(cart))
|
||||
// 向上取整并保留两位小数
|
||||
// let result = roundUpToTwoDecimals(cart, 'upward')
|
||||
return parseFloat(cart);
|
||||
});
|
||||
// 再除以 100 得到保留两位小数的结果
|
||||
return rounded / 100;
|
||||
};
|
||||
|
||||
// 计算商品卷所选择的总价格
|
||||
const getTotalProductroll = (matchedProducts) => computed(() => {
|
||||
if (!matchedProducts || !Array.isArray(matchedProducts)) {
|
||||
return 0;
|
||||
}
|
||||
// 购物车总数价格
|
||||
let cart = matchedProducts.reduce((total, item) => {
|
||||
// 是否启用会员价 0否1是
|
||||
if (uni.cache.get('orderVIP').isVip == 1 && uni.cache.get('ordershopUserInfo')
|
||||
.isMemberPrice == 1) {
|
||||
// memberPrice会员价
|
||||
return total + parseFloat(item.memberPrice || item.price)
|
||||
} else {
|
||||
// salePrice销售价
|
||||
return total + parseFloat(item.price)
|
||||
// 精确计算函数
|
||||
const preciseCalculation = (num1, num2) => {
|
||||
// 将数字转换为整数,乘以 100 以保留两位小数
|
||||
const int1 = BigInt(Math.round(num1 * 100));
|
||||
const int2 = BigInt(Math.round(num2 * 100));
|
||||
// 执行乘法运算
|
||||
const result = int1 * int2;
|
||||
// 再除以 10000 以还原为原来的小数
|
||||
return Number(result) / 10000;
|
||||
};
|
||||
|
||||
// 计算购物车商品总价格
|
||||
const getTotalTotalPrices = (matchedProducts, changeFreeenable = true) => computed(() => {
|
||||
if (!matchedProducts || !Array.isArray(matchedProducts)) {
|
||||
return 0;
|
||||
}
|
||||
}, 0);
|
||||
// 向上取整并保留两位小数
|
||||
let result = roundUpToTwoDecimals(cart, 'upward')
|
||||
return result;
|
||||
});
|
||||
// console.log(uni.cache.get('orderVIP').isVip, uni.cache.get('ordershopUserInfo').isMemberPrice,
|
||||
// 111)
|
||||
// 购物车总数价格
|
||||
let cart = matchedProducts.reduce((total, item) => {
|
||||
// 是否启用会员价 0否1是
|
||||
if (uni.cache.get('orderVIP').isVip == 1 && uni.cache.get('ordershopUserInfo')
|
||||
.isMemberPrice == 1 && changeFreeenable) {
|
||||
// memberPrice会员价
|
||||
return total + (parseFloat(item.memberPrice || item.price) * parseFloat(item
|
||||
.num - item
|
||||
.returnNum));
|
||||
} else {
|
||||
// salePrice销售价
|
||||
return total + (parseFloat(item.price) * parseFloat(item.num - item.returnNum));
|
||||
}
|
||||
}, 0);
|
||||
|
||||
// 桌位置
|
||||
const getTotalSeatcharge = (seatNum) => computed(() => {
|
||||
// 是否免除桌位费 0 否 1 是
|
||||
let cart = 0
|
||||
cart = cart.toFixed(2)
|
||||
console.log(parseFloat(cart))
|
||||
// 向上取整并保留两位小数
|
||||
// let result = roundUpToTwoDecimals(cart, 'upward')
|
||||
return parseFloat(cart);
|
||||
});
|
||||
|
||||
if (uni.cache.get('ordershopUserInfo').isTableFee == 0 && seatNum) {
|
||||
cart = parseFloat(seatNum) * parseFloat(uni.cache.get('ordershopUserInfo').tableFee)
|
||||
// 计算商品卷所选择的总价格
|
||||
const getTotalProductroll = (matchedProducts) => computed(() => {
|
||||
if (!matchedProducts || !Array.isArray(matchedProducts)) {
|
||||
return 0;
|
||||
}
|
||||
// 购物车总数价格
|
||||
let cart = matchedProducts.reduce((total, item) => {
|
||||
// 是否启用会员价 0否1是
|
||||
if (uni.cache.get('orderVIP').isVip == 1 && uni.cache.get('ordershopUserInfo')
|
||||
.isMemberPrice == 1) {
|
||||
// memberPrice会员价
|
||||
return total + parseFloat(item.memberPrice || item.price)
|
||||
} else {
|
||||
// salePrice销售价
|
||||
return total + parseFloat(item.price)
|
||||
}
|
||||
}, 0);
|
||||
// 向上取整并保留两位小数
|
||||
let result = roundUpToTwoDecimals(cart, 'upward')
|
||||
return result;
|
||||
});
|
||||
|
||||
// 桌位置
|
||||
const getTotalSeatcharge = (seatNum) => computed(() => {
|
||||
// 是否免除桌位费 0 否 1 是
|
||||
let cart = 0
|
||||
|
||||
if (uni.cache.get('ordershopUserInfo').isTableFee == 0 && seatNum) {
|
||||
cart = parseFloat(seatNum) * parseFloat(uni.cache.get('ordershopUserInfo').tableFee)
|
||||
|
||||
// Math.ceil(parseFloat(seatNum) * parseFloat(
|
||||
// uni.cache.get('ordershopUserInfo').tableFee) * 100) / 100;
|
||||
}
|
||||
// 向下取整并保留两位小数
|
||||
let result = roundUpToTwoDecimals(cart, 'downward')
|
||||
return result;
|
||||
});
|
||||
|
||||
// 计算购物车总打包费用(向下取整并保留两位小数)
|
||||
const getTotalPackFee = (cartList) => computed(() => {
|
||||
const total = cartList.reduce((sum, item) => {
|
||||
return sum + (parseFloat(item.packAmount) * (parseFloat(item.packNumber) || (
|
||||
parseFloat(item.num) - parseFloat(item.returnNum))));
|
||||
}, 0);
|
||||
// 向下取整并保留两位小数
|
||||
let result = roundUpToTwoDecimals(total, 'downward')
|
||||
console.log(result)
|
||||
return result;
|
||||
// return Math.floor(total * 100) / 100;
|
||||
});
|
||||
|
||||
//获取热门商品
|
||||
async function getHotProduct() {
|
||||
|
||||
// Math.ceil(parseFloat(seatNum) * parseFloat(
|
||||
// uni.cache.get('ordershopUserInfo').tableFee) * 100) / 100;
|
||||
}
|
||||
// 向下取整并保留两位小数
|
||||
let result = roundUpToTwoDecimals(cart, 'downward')
|
||||
return result;
|
||||
});
|
||||
|
||||
// 计算购物车总打包费用(向下取整并保留两位小数)
|
||||
const getTotalPackFee = (cartList) => computed(() => {
|
||||
const total = cartList.reduce((sum, item) => {
|
||||
return sum + (parseFloat(item.packAmount) * (parseFloat(item.packNumber) || (
|
||||
parseFloat(item.num) - parseFloat(item.returnNum))));
|
||||
}, 0);
|
||||
// 向下取整并保留两位小数
|
||||
let result = roundUpToTwoDecimals(total, 'downward')
|
||||
console.log(result)
|
||||
return result;
|
||||
// return Math.floor(total * 100) / 100;
|
||||
});
|
||||
//获取分组商品
|
||||
async function getGroupProduct() {
|
||||
|
||||
return {
|
||||
getTotalPackFee,
|
||||
getTotalSeatcharge,
|
||||
getTotalTotalPrices,
|
||||
getTotalProductroll
|
||||
};
|
||||
});
|
||||
}
|
||||
return {
|
||||
getTotalPackFee,
|
||||
getTotalSeatcharge,
|
||||
getTotalTotalPrices,
|
||||
getTotalProductroll,
|
||||
carts,
|
||||
isEmpty,
|
||||
setGoodsMap
|
||||
};
|
||||
}, {
|
||||
unistorage: true, // 开启后对 state 的数据读写都将持久化
|
||||
},
|
||||
);
|
||||
|
|
@ -241,6 +241,8 @@ export const Memberpay = defineStore('memberpay', {
|
|||
placeNum: data.placeNum, //当前订单下单次数
|
||||
waitCall: data.waitCall //是否等叫 0 否 1 等叫
|
||||
})
|
||||
console.log('actionscreateOrder res:');
|
||||
console.log(res);
|
||||
if (res) {
|
||||
resolve(res)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -9,16 +9,21 @@ import {
|
|||
APIuser
|
||||
} from '@/common/api/api.js'
|
||||
import {
|
||||
APIproductqueryShop,
|
||||
APIproductqueryShop,APIusershopInfodetail,
|
||||
APIshopUserInfo
|
||||
} from '@/common/api/member.js'
|
||||
export const Storelogin = defineStore('login', {
|
||||
state: () => ({
|
||||
token: '',
|
||||
miniAppOpenId: '',
|
||||
userInfo: ''
|
||||
userInfo: '',
|
||||
shopInfo:{}
|
||||
}),
|
||||
actions: {
|
||||
async getShopInfo(shopId){
|
||||
const shopRes=await APIusershopInfodetail({shopId})
|
||||
console.log(shopRes);
|
||||
},
|
||||
actionslogin() {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
// #ifdef MP-WEIXIN
|
||||
|
|
@ -98,21 +103,26 @@ export const productStore = defineStore('product', {
|
|||
scanCodeactions(q) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
if (q) {
|
||||
console.log(q)
|
||||
let tableCode =""
|
||||
// #ifdef MP-WEIXIN
|
||||
let tableCode = this.getQueryString(decodeURIComponent(q), 'code')
|
||||
tableCode = this.getQueryString(decodeURIComponent(q), 'code')
|
||||
// #endif
|
||||
// #ifdef MP-ALIPAY
|
||||
let tableCode = q
|
||||
tableCode = q
|
||||
// #endif
|
||||
|
||||
// #ifdef H5
|
||||
tableCode= q.tableCode
|
||||
// #endif
|
||||
console.log(tableCode);
|
||||
// 储存卓玛
|
||||
uni.cache.set('tableCode', tableCode)
|
||||
if (tableCode) {
|
||||
let data = await this.actionsproductqueryShop()
|
||||
console.log(uni.cache.get('tableCode'));
|
||||
let data = await this.actionsproductqueryShop(tableCode)
|
||||
// -4请求登录
|
||||
const store = Storelogin()
|
||||
if (data.code == '500') {
|
||||
if (await store.actionslogin()) {
|
||||
if (await this.actionslogin()) {
|
||||
// 成功 接着在调用
|
||||
await this.actionsproductqueryShop()
|
||||
}
|
||||
|
|
@ -166,51 +176,17 @@ export const productStore = defineStore('product', {
|
|||
});
|
||||
// #endif
|
||||
}
|
||||
// #ifdef H5
|
||||
if (uni.cache.get('tableCode')) {
|
||||
let data = await this.actionsproductqueryShop()
|
||||
// -4请求登录
|
||||
const store = Storelogin()
|
||||
if (data.code == '-4') {
|
||||
if (await store.actionslogin()) {
|
||||
// 成功 接着在调用
|
||||
await this.actionsproductqueryShop()
|
||||
}
|
||||
}
|
||||
// idle-空闲 using-使用中 subscribe预定,closed--关台, opening 开台中,cleaning 台桌清理中
|
||||
if (uni.cache.get('shopTable').status == 'cleaning' || uni.cache.get(
|
||||
'shopTable').status == 'cleaning') {
|
||||
uni.showToast({
|
||||
title: '此台桌暂不可用...',
|
||||
icon: 'none'
|
||||
})
|
||||
return false;
|
||||
}
|
||||
|
||||
if (uni.cache.get('shopInfo').isTableFee == 0) {
|
||||
uni.navigateTo({
|
||||
url: '/pages/product/choosetable'
|
||||
});
|
||||
} else {
|
||||
uni.reLaunch({
|
||||
url: '/pages/product/index'
|
||||
});
|
||||
// uni.pro.navigateTo('product/index', {
|
||||
// tableCode: uni.cache.get('tableCode'),
|
||||
// })
|
||||
}
|
||||
|
||||
}
|
||||
// #endif
|
||||
|
||||
})
|
||||
},
|
||||
|
||||
// /通过桌码获取当前店铺信息
|
||||
actionsproductqueryShop() {
|
||||
actionsproductqueryShop(tableCode) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
// try {
|
||||
|
||||
let res = await APIproductqueryShop({
|
||||
tableCode: uni.cache.get('tableCode'),
|
||||
tableCode: tableCode?tableCode:uni.cache.get('tableCode'),
|
||||
})
|
||||
res.shopInfo.isVip = res.vip ? '1' : '0'
|
||||
res.shopTable.shopExtendMap = res.shopExtendMap
|
||||
|
|
|
|||
2
uni.scss
2
uni.scss
|
|
@ -73,3 +73,5 @@ $uni-color-subtitle: #555555; // 二级标题颜色
|
|||
$uni-font-size-subtitle:26px;
|
||||
$uni-color-paragraph: #3F536E; // 文章段落颜色
|
||||
$uni-font-size-paragraph:15px;
|
||||
|
||||
$my-main-color:#E8AD7B;
|
||||
|
|
@ -0,0 +1,264 @@
|
|||
export function isTui(item) {
|
||||
return item.status == "return" || item.status == "refund" || item.status == "refunding";
|
||||
}
|
||||
//是否使用会员价
|
||||
export function isUseVipPrice(vipUser, goods) {
|
||||
return vipUser.id && vipUser.isVip;
|
||||
}
|
||||
|
||||
//计算商品券优惠价格
|
||||
export function returnProductCouponPrice(coup, goodsArr, vipUser) {
|
||||
const item = goodsArr.find((v) => v.productId == coup.proId);
|
||||
if (!item) {
|
||||
return 0;
|
||||
}
|
||||
const discountSaleAmount = item.discountSaleAmount * 1;
|
||||
if (discountSaleAmount > 0) {
|
||||
return discountSaleAmount * coup.num;
|
||||
}
|
||||
const memberPrice = item.memberPrice ? item.memberPrice : item.price;
|
||||
const price = item ? (isUseVipPrice(vipUser, item) ? memberPrice : item.price) : 0;
|
||||
return price * coup.num;
|
||||
}
|
||||
//返回新的商品列表,过滤掉退菜的,退单的商品
|
||||
export function returnNewGoodsList(arr) {
|
||||
let goodsMap = {};
|
||||
return arr.filter((v) => !isTui(v));
|
||||
}
|
||||
//根据当前购物车商品以及数量,已选券对应商品数量,判断该商品券是否可用
|
||||
export function returnCoupCanUse(goodsArr = [], coup, selCoupArr = []) {
|
||||
// if(!coup.use){
|
||||
// return false
|
||||
// }
|
||||
const findGoods = goodsArr.filter((v) => v.productId == coup.proId);
|
||||
if (!findGoods.length) {
|
||||
return false;
|
||||
}
|
||||
const findGoodsTotalNumber = findGoods.reduce((prve, cur) => {
|
||||
const num = cur.num - cur.refundNum - cur.returnNum;
|
||||
return prve + (num <= 0 ? 0 : num);
|
||||
}, 0);
|
||||
const selCoupNumber = selCoupArr
|
||||
.filter((v) => v.proId == coup.proId)
|
||||
.reduce((prve, cur) => {
|
||||
return prve + cur.num * 1;
|
||||
}, 0);
|
||||
if (selCoupNumber >= findGoodsTotalNumber) {
|
||||
return false;
|
||||
}
|
||||
return findGoodsTotalNumber < selCoupNumber ? false : true;
|
||||
}
|
||||
//查找购物车商品根据购物车商品数据返回商品券信息(抵扣价格以及是否满足可用需求)
|
||||
export function returnProductCoupon(coup, goodsArr, vipUser, selCoupArr = []) {
|
||||
const newGoodsArr = returnNewGoodsList(goodsArr);
|
||||
const item = newGoodsArr.find((v) => v.productId == coup.proId);
|
||||
if (!item) {
|
||||
return {
|
||||
...coup,
|
||||
discountAmount: 0,
|
||||
use: false,
|
||||
};
|
||||
}
|
||||
const discountSaleAmount = item.discountSaleAmount * 1;
|
||||
const memberPrice = item.memberPrice ? item.memberPrice : item.price;
|
||||
let price = item ? (isUseVipPrice(vipUser, item) ? memberPrice : item.price) : 0;
|
||||
price = discountSaleAmount > 0 ? discountSaleAmount : price;
|
||||
const discountAmount = (price * coup.num).toFixed(2);
|
||||
// const canUse = !coup.use ? false : (discountAmount > 0 && returnCoupCanUse(goodsArr, coup, selCoupArr))
|
||||
// const canUse=discountAmount>0
|
||||
const canUse = coup.use;
|
||||
return {
|
||||
...coup,
|
||||
discountAmount: discountAmount,
|
||||
use: canUse,
|
||||
};
|
||||
}
|
||||
/**
|
||||
* 根据购物车商品计算商品券抵扣价格以及是否满足可用需求
|
||||
* 1.商品券对应商品数量大于购物车对应商品数量不可用
|
||||
* 2.未在购物车找到相关商品不可用
|
||||
* @param {*} coupArr
|
||||
* @param {*} goodsArr
|
||||
* @param {*} vipUser
|
||||
* @returns
|
||||
*/
|
||||
export function returnProductAllCoup(coupArr, goodsArr, vipUser) {
|
||||
return coupArr.map((v) => {
|
||||
return returnProductCoupon(v, goodsArr, vipUser);
|
||||
});
|
||||
}
|
||||
//返回商品实际支付价格
|
||||
export function returnProductPayPrice(goods, vipUser) {
|
||||
const discountSaleAmount = goods.discountSaleAmount * 1;
|
||||
const memberPrice = goods.memberPrice ? goods.memberPrice : goods.price;
|
||||
const price = isUseVipPrice(vipUser, goods) ? memberPrice : goods.price;
|
||||
if (discountSaleAmount) {
|
||||
return discountSaleAmount;
|
||||
}
|
||||
return price;
|
||||
}
|
||||
//返回商品券抵扣的商品价格
|
||||
export function returnProductCoupAllPrice(productPriceArr, startIndex, num = 1, isVip = true) {
|
||||
num = num || 1;
|
||||
return productPriceArr.slice(startIndex, startIndex + num).reduce((prve, cur) => {
|
||||
let curPrice = 0;
|
||||
if (typeof cur === "object") {
|
||||
if (cur.discountSaleAmount * 1 > 0) {
|
||||
curPrice = cur.discountSaleAmount * 1;
|
||||
} else {
|
||||
curPrice = isVip ? cur.memberPrice * 1 : cur.price;
|
||||
}
|
||||
} else {
|
||||
curPrice = cur * 1;
|
||||
}
|
||||
|
||||
return prve + curPrice;
|
||||
}, 0);
|
||||
}
|
||||
|
||||
//返回商品券可抵扣的商品数量
|
||||
export function returnProductCanUseNum(productPriceArr, startIndex, num) {
|
||||
let n = 0;
|
||||
for (let i = 0; i < num; i++) {
|
||||
if (productPriceArr[startIndex * 1 + i]) {
|
||||
n += 1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
//返回同类商品券在同类商品价格数组里的开始位置
|
||||
export function returnProCoupStartIndex(coupArr, index) {
|
||||
return coupArr.slice(0, index).reduce((prve, cur) => {
|
||||
return prve + cur.num * 1;
|
||||
}, 0);
|
||||
}
|
||||
//返回商品数量从0到n每一个对应的价格对照表
|
||||
export function returnGoodsPayPriceMap(goodsArr) {
|
||||
return goodsArr.reduce((prve, cur) => {
|
||||
if (!prve.hasOwnProperty(cur.productId)) {
|
||||
prve[cur.productId] = [];
|
||||
}
|
||||
const n = cur.num - cur.returnNum;
|
||||
const arr = new Array(n <= 0 ? 0 : n).fill(cur).map((v) => {
|
||||
return {
|
||||
memberPrice: v.memberPrice ? v.memberPrice : v.price,
|
||||
price: v.price,
|
||||
discountSaleAmount: v.discountSaleAmount * 1,
|
||||
};
|
||||
});
|
||||
prve[cur.productId].push(...arr);
|
||||
return prve;
|
||||
}, {});
|
||||
}
|
||||
//计算商品券总优惠价格
|
||||
export function returnProductCouponAllPrice(coupArr, goodsArr, vipUser) {
|
||||
if (coupArr.length == 0) {
|
||||
return 0;
|
||||
}
|
||||
//商品分组
|
||||
const goodsMap = {};
|
||||
//商品数量从0到n每一个对应的价格
|
||||
const goodsPayPriceMap = {};
|
||||
//商品券分组
|
||||
let coupMap = {};
|
||||
for (let i in coupArr) {
|
||||
const coup = coupArr[i];
|
||||
if (coupMap.hasOwnProperty(coup.proId)) {
|
||||
coupMap[coup.proId].push(coup);
|
||||
} else {
|
||||
coupMap[coup.proId] = [coup];
|
||||
}
|
||||
}
|
||||
let total = 0;
|
||||
for (let key in coupMap) {
|
||||
const arr = coupMap[key];
|
||||
for (let i in arr) {
|
||||
const coup = arr[i];
|
||||
if (!goodsMap.hasOwnProperty(coup.proId)) {
|
||||
goodsMap[coup.proId] = goodsArr
|
||||
.filter((v) => v.productId == coup.proId)
|
||||
.map((v) => {
|
||||
return {
|
||||
...v,
|
||||
payPrice: returnProductPayPrice(v, vipUser),
|
||||
};
|
||||
})
|
||||
.sort((a, b) => {
|
||||
const aPrice = a.payPrice;
|
||||
const bPrice = b.payPrice;
|
||||
return aPrice - bPrice;
|
||||
});
|
||||
goodsPayPriceMap[coup.proId] = goodsMap[coup.proId].reduce((prve, cur) => {
|
||||
const arr = new Array(cur.num).fill(cur.payPrice);
|
||||
prve.push(...arr);
|
||||
return prve;
|
||||
}, []);
|
||||
}
|
||||
const proCoupStartIndex = returnProCoupStartIndex(arr, i);
|
||||
const coupNum = Math.min(goodsPayPriceMap[coup.proId].length, coup.num);
|
||||
total += returnProductCoupAllPrice(goodsPayPriceMap[coup.proId], proCoupStartIndex, coupNum);
|
||||
}
|
||||
}
|
||||
|
||||
return total.toFixed(2);
|
||||
}
|
||||
//计算满减券总优惠价格
|
||||
export function returnFullReductionCouponAllPrice(coupArr) {
|
||||
if (coupArr.length == 0) {
|
||||
return 0;
|
||||
}
|
||||
return coupArr
|
||||
.filter((v) => v.type == 1)
|
||||
.reduce((a, b) => {
|
||||
const price = b.discountAmount;
|
||||
return a + price;
|
||||
}, 0)
|
||||
.toFixed(2);
|
||||
}
|
||||
//计算优惠券总价格
|
||||
export function returnCouponAllPrice(coupArr, goodsArr, vipUser) {
|
||||
const poductAllprice = returnProductCouponAllPrice(coupArr, goodsArr, vipUser);
|
||||
const pointAllPrice = returnFullReductionCouponAllPrice(coupArr);
|
||||
return (poductAllprice * 1 + pointAllPrice * 1).toFixed(2);
|
||||
}
|
||||
|
||||
//返回当前满减券列表可用状态
|
||||
export function returnCanUseFullReductionCoupon(coupArr, payPrice, selCoup) {
|
||||
return coupArr
|
||||
.map((v) => {
|
||||
if (v.id == selCoup.id) {
|
||||
return { ...v, use: true };
|
||||
}
|
||||
const isfullAmount = payPrice * 1 >= v.fullAmount * 1;
|
||||
if (payPrice <= 0) {
|
||||
return {
|
||||
...v,
|
||||
use: false,
|
||||
};
|
||||
}
|
||||
return {
|
||||
...v,
|
||||
use: v.use && isfullAmount,
|
||||
};
|
||||
})
|
||||
.filter((v) => v.use);
|
||||
}
|
||||
|
||||
//根据商品数量还有商品券数量返回优惠券可以使用的数量数组
|
||||
export function returnCanUseNumProductCoup(coupArr) {
|
||||
let productCoup = coupArr.filter((v) => v.type == 2);
|
||||
//商品券分组
|
||||
let coupMap = {};
|
||||
for (let i in productCoup) {
|
||||
const coup = productCoup[i];
|
||||
if (coupMap.hasOwnProperty(coup.proId)) {
|
||||
coupMap[coup.proId].push(coup);
|
||||
} else {
|
||||
coupMap[coup.proId] = [coup];
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
export const back=()=>{
|
||||
console.log('back');
|
||||
try {
|
||||
const arr= getCurrentPages()
|
||||
if(arr.length>=2){
|
||||
return uni.navigateBack()
|
||||
}else{
|
||||
uni.reLaunch({
|
||||
url:'/pages/index/index'
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('页面返回出错',error)
|
||||
//TODO handle the exception
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ export default defineConfig({
|
|||
hmr: true,
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: 'https://tapi.cashier.sxczgkj.cn',
|
||||
target: 'http://192.168.1.31',
|
||||
changeOrigin: true,
|
||||
rewrite: path => path.replace(/^\/api/, ''),
|
||||
secure: false
|
||||
|
|
|
|||
Loading…
Reference in New Issue