问题修复
This commit is contained in:
360
http/websock.js
360
http/websock.js
@@ -1,157 +1,241 @@
|
|||||||
import {
|
import { reactive, ref } from 'vue';
|
||||||
reactive,
|
|
||||||
ref
|
|
||||||
} from 'vue';
|
|
||||||
// WebSocket 工具类,封装了 WebSocket 的连接、发送、接收、心跳、重连和关闭等操作
|
// WebSocket 工具类,封装了 WebSocket 的连接、发送、接收、心跳、重连和关闭等操作
|
||||||
class WebsocketUtil {
|
class WebsocketUtil {
|
||||||
|
|
||||||
// 构造函数,初始化 WebSocket 连接
|
// 构造函数,初始化 WebSocket 连接
|
||||||
constructor(url, time, params) {
|
constructor(url, time, params) {
|
||||||
this.url = url; // WebSocket 服务器的 URL
|
this.url = url; // WebSocket 服务器的 URL
|
||||||
this.params = params; // WebSocket 服务器的 URL
|
this.params = params; // WebSocket 连接参数
|
||||||
this.time = time; // 心跳发送的间隔时间(秒)
|
this.time = time; // 心跳发送的间隔时间(毫秒)
|
||||||
this.socketTask = null; // WebSocket 任务对象
|
this.socketTask = null; // WebSocket 任务对象
|
||||||
this.isOpen = false; // WebSocket 连接是否打开
|
this.isOpen = false; // WebSocket 连接是否打开
|
||||||
this.reconnectTimeout = null; // 重连定时器
|
|
||||||
this.heartbeatInterval = null; // 心跳定时器
|
|
||||||
this.messageCallbacks = []; // 存储外部注册的消息回调函数的数组
|
|
||||||
this.messageCallbacks = []; // 存储外部注册的消息回调函数的数组
|
|
||||||
|
|
||||||
// 初始化 WebSocket 连接
|
// 定时器相关
|
||||||
this.initializeWebSocket();
|
this.reconnectTimeout = null; // 重连定时器
|
||||||
}
|
this.heartbeatInterval = null; // 心跳定时器
|
||||||
|
this.heartbeatTimeout = null; // 心跳超时定时器(检测 pong 响应)
|
||||||
|
this.checkConnectionInterval = null; // 连接状态主动检查定时器
|
||||||
|
|
||||||
// 初始化 WebSocket 连接
|
// 消息回调数组
|
||||||
initializeWebSocket() {
|
this.messageCallbacks = []; // 存储外部注册的消息回调函数的数组
|
||||||
console.log('初始化WebSocket连接');
|
|
||||||
if (this.isOpen) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
this.socketTask = uni.connectSocket({
|
|
||||||
url: this.url,
|
|
||||||
success: () => {
|
|
||||||
console.log('WebSocket连接成功');
|
|
||||||
return this.socketTask;
|
|
||||||
},
|
|
||||||
fail: (error) => {
|
|
||||||
console.error('WebSocket连接失败', error);
|
|
||||||
uni.$emit('is-socket-open', true)
|
|
||||||
this.reconnect();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.socketTask.onOpen((res) => {
|
// 重连策略配置
|
||||||
console.log('WebSocket连接正常!==', res);
|
this.reconnectAttempts = 0; // 当前重连次数
|
||||||
this.isOpen = true;
|
this.reconnectMaxAttempts = 5; // 最大重连次数(设为 Infinity 表示无限重试)
|
||||||
// 连接成功后启动心跳和消息监听
|
this.reconnectDelay = 3000; // 基础重连延迟(毫秒)
|
||||||
this.startHeartbeat();
|
this.maxReconnectDelay = 30000; // 最大重连延迟(毫秒)
|
||||||
this.listenForMessages();
|
|
||||||
uni.$emit('is-socket-open', true)
|
|
||||||
|
|
||||||
});
|
// 初始化 WebSocket 连接
|
||||||
this.socketTask.onError((res) => {
|
this.initializeWebSocket();
|
||||||
console.log('WebSocket连接失败!==', res);
|
|
||||||
uni.$emit('is-socket-open', false)
|
|
||||||
this.reconnect();
|
|
||||||
});
|
|
||||||
// 注意:这里的 onClose 监听器应该放在 uni.connectSocket 调用之后
|
|
||||||
this.socketTask.onClose((result) => {
|
|
||||||
this.isOpen = false;
|
|
||||||
// if( this.isOpen ){
|
|
||||||
this.reconnect();
|
|
||||||
// }
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
// 监听设备唤醒事件(浏览器环境)
|
||||||
|
if (typeof document !== 'undefined') {
|
||||||
|
document.addEventListener('visibilitychange', () => {
|
||||||
|
if (document.visibilityState === 'visible') {
|
||||||
|
// 页面可见时,主动检查连接
|
||||||
|
this.checkConnection();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 启动心跳检测
|
// 初始化 WebSocket 连接
|
||||||
startHeartbeat() {
|
initializeWebSocket() {
|
||||||
if (this.heartbeatInterval) {
|
console.log('初始化WebSocket连接');
|
||||||
clearInterval(this.heartbeatInterval);
|
if (this.isOpen) {
|
||||||
}
|
return;
|
||||||
this.heartbeatInterval = setInterval(() => {
|
}
|
||||||
if (this.isOpen) {
|
|
||||||
this.send(JSON.stringify({"type": "ping_interval","set": "pad"}));
|
|
||||||
}
|
|
||||||
}, this.time);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 发送消息
|
this.socketTask = uni.connectSocket({
|
||||||
send(data, type) {
|
url: this.url,
|
||||||
if (this.socketTask && this.isOpen) {
|
success: () => {
|
||||||
this.socketTask.send({
|
console.log('WebSocket连接请求发送成功');
|
||||||
data: data,
|
},
|
||||||
success: (res) => {
|
fail: (error) => {
|
||||||
// console.log('消息发送成功', res);
|
console.error('WebSocket连接失败', error);
|
||||||
this.startHeartbeat();
|
uni.$emit('is-socket-open', false);
|
||||||
},
|
this.reconnect();
|
||||||
fail: (error) => {
|
}
|
||||||
console.error('消息发送失败', error);
|
});
|
||||||
this.reconnect(); // 这里可能需要根据实际情况判断是否重连
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 监听 WebSocket 消息
|
// 连接打开事件
|
||||||
listenForMessages() {
|
this.socketTask.onOpen((res) => {
|
||||||
if (this.socketTask) {
|
console.log('WebSocket连接正常!==', res);
|
||||||
this.socketTask.onMessage((res) => {
|
this.isOpen = true;
|
||||||
const {
|
// 重置重连状态
|
||||||
data
|
this.reconnectAttempts = 0;
|
||||||
} = res;
|
this.reconnectDelay = 3000;
|
||||||
this.messageCallbacks.forEach(callback => callback(data
|
// 启动心跳和消息监听
|
||||||
.toString())); // 假设 data 是字符串或可转换为字符串
|
this.startHeartbeat();
|
||||||
});
|
this.listenForMessages();
|
||||||
// this.send("WebSocket连接正常");
|
uni.$emit('is-socket-open', true);
|
||||||
} else {
|
});
|
||||||
console.error('WebSocket 连接尚未建立,无法监听消息');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 重连 WebSocket
|
// 连接错误事件
|
||||||
reconnect() {
|
this.socketTask.onError((res) => {
|
||||||
if (this.reconnectTimeout) {
|
console.log('WebSocket连接错误!==', res);
|
||||||
clearTimeout(this.reconnectTimeout);
|
uni.$emit('is-socket-open', false);
|
||||||
}
|
this.reconnect();
|
||||||
this.reconnectTimeout = setTimeout(() => {
|
});
|
||||||
this.initializeWebSocket();
|
|
||||||
}, 3000);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 关闭 WebSocket 连接
|
// 连接关闭事件
|
||||||
closeSocket() {
|
this.socketTask.onClose((result) => {
|
||||||
if (this.socketTask) {
|
console.log('WebSocket连接已关闭', result);
|
||||||
uni.closeSocket({
|
this.isOpen = false;
|
||||||
success: () => {
|
this.reconnect();
|
||||||
console.log('WebSocket连接已关闭');
|
});
|
||||||
this.isOpen = false;
|
|
||||||
},
|
|
||||||
fail: (error) => {
|
|
||||||
console.error('关闭WebSocket连接失败', error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.socketTask = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 外部注册消息回调函数
|
// 启动连接状态主动检查(30秒一次)
|
||||||
onMessage(callback) {
|
this.startConnectionCheck();
|
||||||
this.messageCallbacks.push(callback);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 外部注销消息回调函数
|
// 启动心跳检测
|
||||||
offMessage(callback) {
|
startHeartbeat() {
|
||||||
this.messageCallbacks = []
|
// 清除现有定时器
|
||||||
}
|
if (this.heartbeatInterval) clearInterval(this.heartbeatInterval);
|
||||||
|
if (this.heartbeatTimeout) clearTimeout(this.heartbeatTimeout);
|
||||||
|
|
||||||
// 销毁 WebSocket 连接,清理资源
|
this.heartbeatInterval = setInterval(() => {
|
||||||
destroy() {
|
if (this.isOpen) {
|
||||||
this.closeSocket();
|
// 发送心跳包
|
||||||
clearInterval(this.heartbeatInterval);
|
this.send(JSON.stringify({ "type": "ping_interval", "set": "pad" }));
|
||||||
clearTimeout(this.reconnectTimeout);
|
// 设置5秒超时:若未收到pong则重连
|
||||||
this.messageCallbacks = [];
|
this.heartbeatTimeout = setTimeout(() => {
|
||||||
}
|
console.log('心跳超时,主动断开并重连');
|
||||||
|
this.closeSocket();
|
||||||
|
this.reconnect();
|
||||||
|
}, 5000);
|
||||||
|
}
|
||||||
|
}, this.time);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 启动连接状态主动检查(30秒一次)
|
||||||
|
startConnectionCheck() {
|
||||||
|
if (this.checkConnectionInterval) clearInterval(this.checkConnectionInterval);
|
||||||
|
this.checkConnectionInterval = setInterval(() => {
|
||||||
|
if (!this.isOpen && !this.reconnectTimeout) {
|
||||||
|
console.log('主动检查到连接断开,触发重连');
|
||||||
|
this.reconnect();
|
||||||
|
}
|
||||||
|
}, 30000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 发送消息
|
||||||
|
send(data, type) {
|
||||||
|
if (this.socketTask && this.isOpen) {
|
||||||
|
this.socketTask.send({
|
||||||
|
data: data,
|
||||||
|
success: (res) => {
|
||||||
|
// 发送成功,重置心跳(可选,根据业务需求)
|
||||||
|
this.startHeartbeat();
|
||||||
|
},
|
||||||
|
fail: (error) => {
|
||||||
|
console.error('消息发送失败', error);
|
||||||
|
this.reconnect();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.warn('WebSocket未连接,无法发送消息');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 监听 WebSocket 消息
|
||||||
|
listenForMessages() {
|
||||||
|
if (this.socketTask) {
|
||||||
|
this.socketTask.onMessage((res) => {
|
||||||
|
const data = res.data.toString();
|
||||||
|
try {
|
||||||
|
// 尝试解析JSON,处理pong响应
|
||||||
|
const message = JSON.parse(data);
|
||||||
|
if (message.type === 'pong') {
|
||||||
|
// 收到pong,清除心跳超时
|
||||||
|
if (this.heartbeatTimeout) clearTimeout(this.heartbeatTimeout);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('消息解析失败(非JSON格式):', e);
|
||||||
|
}
|
||||||
|
// 触发外部注册的回调函数
|
||||||
|
this.messageCallbacks.forEach(callback => callback(data));
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.error('WebSocket 连接尚未建立,无法监听消息');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重连 WebSocket(指数退避策略)
|
||||||
|
reconnect() {
|
||||||
|
if (this.reconnectTimeout) clearTimeout(this.reconnectTimeout);
|
||||||
|
|
||||||
|
// 达到最大重连次数,停止重试(可根据需求调整为无限重试)
|
||||||
|
if (this.reconnectAttempts >= this.reconnectMaxAttempts) {
|
||||||
|
console.log(`已达最大重连次数 ${this.reconnectMaxAttempts},停止重连`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 指数退避:延迟时间 = 基础延迟 * 2^重连次数,最大不超过maxReconnectDelay
|
||||||
|
const delay = Math.min(
|
||||||
|
this.reconnectDelay * Math.pow(2, this.reconnectAttempts),
|
||||||
|
this.maxReconnectDelay
|
||||||
|
);
|
||||||
|
|
||||||
|
this.reconnectTimeout = setTimeout(() => {
|
||||||
|
this.reconnectAttempts++;
|
||||||
|
console.log(`重连尝试 ${this.reconnectAttempts}/${this.reconnectMaxAttempts},延迟 ${delay}ms`);
|
||||||
|
this.initializeWebSocket();
|
||||||
|
}, delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 主动检查连接状态
|
||||||
|
checkConnection() {
|
||||||
|
if (!this.isOpen && !this.reconnectTimeout) {
|
||||||
|
this.reconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关闭 WebSocket 连接
|
||||||
|
closeSocket() {
|
||||||
|
if (this.socketTask) {
|
||||||
|
uni.closeSocket({
|
||||||
|
success: () => {
|
||||||
|
console.log('WebSocket连接已关闭');
|
||||||
|
this.isOpen = false;
|
||||||
|
},
|
||||||
|
fail: (error) => {
|
||||||
|
console.error('关闭WebSocket连接失败', error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.socketTask = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 外部注册消息回调函数
|
||||||
|
onMessage(callback) {
|
||||||
|
this.messageCallbacks.push(callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 外部注销消息回调函数
|
||||||
|
offMessage(callback) {
|
||||||
|
// 若传入callback,则移除指定回调;否则清空所有回调
|
||||||
|
if (callback) {
|
||||||
|
this.messageCallbacks = this.messageCallbacks.filter(cb => cb !== callback);
|
||||||
|
} else {
|
||||||
|
this.messageCallbacks = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 销毁 WebSocket 连接,清理资源
|
||||||
|
destroy() {
|
||||||
|
this.closeSocket();
|
||||||
|
// 清除所有定时器
|
||||||
|
clearInterval(this.heartbeatInterval);
|
||||||
|
clearTimeout(this.heartbeatTimeout);
|
||||||
|
clearTimeout(this.reconnectTimeout);
|
||||||
|
clearInterval(this.checkConnectionInterval);
|
||||||
|
// 清空回调数组
|
||||||
|
this.messageCallbacks = [];
|
||||||
|
console.log('WebSocket资源已销毁');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default WebsocketUtil;
|
export default WebsocketUtil;
|
||||||
@@ -2,12 +2,18 @@
|
|||||||
<view class="page-gray u-font-28">
|
<view class="page-gray u-font-28">
|
||||||
<up-sticky offsetTop="0" customNavHeight="0">
|
<up-sticky offsetTop="0" customNavHeight="0">
|
||||||
<view class="navbar">
|
<view class="navbar">
|
||||||
<image
|
<view class="u-flex"
|
||||||
src="/static/iconImg/exit.svg"
|
@click="loginOut()"
|
||||||
class="exit"
|
|
||||||
mode=""
|
>
|
||||||
@click="toDiancan"
|
<image
|
||||||
></image>
|
src="/static/iconImg/exit.svg"
|
||||||
|
class="exit"
|
||||||
|
mode=""
|
||||||
|
></image>
|
||||||
|
<text class="u-font-32 color-333 u-m-l-16">退出</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
<text class="font-700 u-font-40 color-333">台桌列表</text>
|
<text class="font-700 u-font-40 color-333">台桌列表</text>
|
||||||
<view class="u-flex navbar-right" style="gap: 134rpx">
|
<view class="u-flex navbar-right" style="gap: 134rpx">
|
||||||
<up-icon name="scan" size="64rpx" color="#999"></up-icon>
|
<up-icon name="scan" size="64rpx" color="#999"></up-icon>
|
||||||
@@ -215,6 +221,13 @@ onShow(async () => {
|
|||||||
getTable();
|
getTable();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function loginOut() {
|
||||||
|
uni.clearStorage();
|
||||||
|
uni.redirectTo({
|
||||||
|
url: "/pages/login/index",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 扫码上传
|
* 扫码上传
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -293,20 +293,7 @@ const vdata = reactive({
|
|||||||
loginType: "merchant",
|
loginType: "merchant",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
vdata.formData.merchantName = "19107220837";
|
|
||||||
vdata.formData.username = "19111112222";
|
|
||||||
vdata.formData.pwd = "123456";
|
|
||||||
vdata.formData.code = "666666";
|
|
||||||
// #ifdef H5
|
|
||||||
// vdata.formData.merchantName = "19191703856";
|
|
||||||
// vdata.formData.username = "18888888888";
|
|
||||||
// vdata.formData.pwd = "123456";
|
|
||||||
// vdata.formData.code = "666666";
|
|
||||||
// #endif
|
|
||||||
// #ifdef MP-WEIXIN
|
|
||||||
// vdata.formData.username = '15699991111'
|
|
||||||
// vdata.formData.pwd = 'qwer1234'
|
|
||||||
// #endif
|
|
||||||
|
|
||||||
function accountTypeChange(e) {
|
function accountTypeChange(e) {
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
|
|||||||
@@ -125,7 +125,7 @@
|
|||||||
class="u-p-t-32 u-p-b-32 u-p-r-28 u-p-l-28 u-m-t-40 bg-fff u-flex u-row-between"
|
class="u-p-t-32 u-p-b-32 u-p-r-28 u-p-l-28 u-m-t-40 bg-fff u-flex u-row-between"
|
||||||
>
|
>
|
||||||
<view class="color-333" style="font-weight: bold">历史订单</view>
|
<view class="color-333" style="font-weight: bold">历史订单</view>
|
||||||
<view class="color-666">
|
<!-- <view class="color-666">
|
||||||
<uni-icons color="#666" type="trash"></uni-icons>
|
<uni-icons color="#666" type="trash"></uni-icons>
|
||||||
<text
|
<text
|
||||||
class="u-m-l-10"
|
class="u-m-l-10"
|
||||||
@@ -134,7 +134,7 @@
|
|||||||
"
|
"
|
||||||
>清空历史订单</text
|
>清空历史订单</text
|
||||||
>
|
>
|
||||||
</view>
|
</view> -->
|
||||||
</view>
|
</view>
|
||||||
<view
|
<view
|
||||||
v-for="(item, index) in historyOrder"
|
v-for="(item, index) in historyOrder"
|
||||||
@@ -581,7 +581,7 @@ function getshopsInfo() {
|
|||||||
|
|
||||||
async function workerConfirm() {
|
async function workerConfirm() {
|
||||||
//debugger
|
//debugger
|
||||||
form.workerAccount=accountStore.staffUserName
|
// form.workerAccount=accountStore.staffUserName
|
||||||
if (!form.workerAccount) {
|
if (!form.workerAccount) {
|
||||||
return infoBox.showToast("请输入服务员账号");
|
return infoBox.showToast("请输入服务员账号");
|
||||||
}
|
}
|
||||||
@@ -603,7 +603,7 @@ async function workerConfirm() {
|
|||||||
placeNum: 1, //当前订单下单次数
|
placeNum: 1, //当前订单下单次数
|
||||||
waitCall: 0, //是否等叫 0 否 1 等叫
|
waitCall: 0, //是否等叫 0 否 1 等叫
|
||||||
vipPrice: false, //是否使用会员价
|
vipPrice: false, //是否使用会员价
|
||||||
limitRate: null,
|
limitRate: props.limitTimeDiscount,
|
||||||
subStatus: subStatus.value,
|
subStatus: subStatus.value,
|
||||||
orderId: props.orderInfo.id?props.orderInfo.id:"",
|
orderId: props.orderInfo.id?props.orderInfo.id:"",
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -523,10 +523,7 @@ function onMessage() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (msg.status == 0 && msg.type != "time_discount") {
|
||||||
msg.status == 0 &&
|
|
||||||
msg.type != "time_discount"
|
|
||||||
) {
|
|
||||||
console.log("msg", msg);
|
console.log("msg", msg);
|
||||||
infoBox.showToast(msg.msg || "添加失败");
|
infoBox.showToast(msg.msg || "添加失败");
|
||||||
data.isGoodsAdd = true;
|
data.isGoodsAdd = true;
|
||||||
@@ -646,7 +643,7 @@ async function getHistoryOrderDetail() {
|
|||||||
if (shopInfo.registerType == "before") {
|
if (shopInfo.registerType == "before") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(!data.table.tableCode){
|
if (!data.table.tableCode) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
data.historyOrder = [];
|
data.historyOrder = [];
|
||||||
@@ -1962,10 +1959,6 @@ onShow(() => {
|
|||||||
data.userInfo = shopif;
|
data.userInfo = shopif;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 判断是否token过期,是否有名字
|
|
||||||
if (!data.userInfo.shopName) {
|
|
||||||
loginShowOut();
|
|
||||||
}
|
|
||||||
|
|
||||||
getHistoryOrderDetail();
|
getHistoryOrderDetail();
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
@@ -2018,7 +2011,7 @@ async function getLimit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getTableDetail() {
|
async function getTableDetail() {
|
||||||
if(!data.table.tableCode){
|
if (!data.table.tableCode) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let res = await $returnTableDetail({
|
let res = await $returnTableDetail({
|
||||||
|
|||||||
@@ -180,6 +180,10 @@ function returnLimitPrice(data) {
|
|||||||
shopUserInfo: cartStore.shopUserInfo,
|
shopUserInfo: cartStore.shopUserInfo,
|
||||||
idKey: "productId",
|
idKey: "productId",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log("cartStore.shopInfo", cartStore.shopInfo);
|
||||||
|
console.log("cartStore.limitTimeDiscount", cartStore.limitTimeDiscount);
|
||||||
|
console.log("cartStore.shopUserInfo", cartStore.shopUserInfo);
|
||||||
return price;
|
return price;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -515,6 +515,7 @@ async function discountconfirm(form) {
|
|||||||
product_id: modelData.data.product_id,
|
product_id: modelData.data.product_id,
|
||||||
sku_id: modelData.data.sku_id,
|
sku_id: modelData.data.sku_id,
|
||||||
discount_sale_amount: discount_sale_amount,
|
discount_sale_amount: discount_sale_amount,
|
||||||
|
is_time_discount: discount_sale_amount>0 ? 0 : (modelData.data.is_time_discount||modelData.data.isTimeDiscount)
|
||||||
// discount_sale_note: str + form.note,
|
// discount_sale_note: str + form.note,
|
||||||
};
|
};
|
||||||
updateCart(par);
|
updateCart(par);
|
||||||
|
|||||||
@@ -1,195 +1,203 @@
|
|||||||
<template>
|
<template>
|
||||||
<my-model ref="model" :title="title" iconColor="#000" @close="resetForm">
|
<my-model ref="model" :title="title" iconColor="#000" @close="resetForm">
|
||||||
<template #desc>
|
<template #desc>
|
||||||
<view class="u-text-left u-p-30 color-666 u-font-28">
|
<view class="u-text-left u-p-30 color-666 u-font-28">
|
||||||
<view class="u-m-t-32 u-flex ">
|
<view class="u-m-t-32 u-flex">
|
||||||
<view class="" v-if="accountPoints.calcRes.usable">
|
<view class="" v-if="accountPoints.calcRes.usable">
|
||||||
<text class="color-red">*</text>
|
<text class="color-red">*</text>
|
||||||
<text class=""
|
<text class="" v-if="accountPoints.calcRes.equivalentPoints"
|
||||||
v-if="accountPoints.calcRes.equivalentPoints">100积分等于{{to2(accountPoints.calcRes.equivalentPoints*100)}}元,</text>
|
>{{ accountPoints.calcRes.equivalentPoints }}积分等于1元,</text
|
||||||
<text>
|
>
|
||||||
最大抵扣积分{{accountPoints.calcRes.maxUsablePoints}}
|
<text>
|
||||||
</text>
|
最大抵扣积分{{ accountPoints.calcRes.maxUsablePoints }}
|
||||||
<text>,
|
</text>
|
||||||
最小抵扣积分0
|
<text>, 最小抵扣积分0 </text>
|
||||||
</text>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
<view class="u-m-t-40 u-flex">
|
||||||
<view class="u-m-t-40 u-flex ">
|
<view>积分</view>
|
||||||
<view>积分</view>
|
<view class="u-m-l-32 border u-p-l-10 u-p-r-10 u-flex-1">
|
||||||
<view class="u-m-l-32 border u-p-l-10 u-p-r-10 u-flex-1">
|
<uni-easyinput
|
||||||
<uni-easyinput type="number" @input="pointsInput" @change="pointsChange" paddingNone
|
type="number"
|
||||||
:inputBorder="false" v-model="form.points" placeholder="输入积分抵扣数量"></uni-easyinput>
|
@input="pointsInput"
|
||||||
</view>
|
@change="pointsChange"
|
||||||
</view>
|
paddingNone
|
||||||
</view>
|
:inputBorder="false"
|
||||||
</template>
|
v-model="form.points"
|
||||||
<template #btn>
|
placeholder="输入积分抵扣数量"
|
||||||
<view class="u-p-30">
|
></uni-easyinput>
|
||||||
<view class="u-m-t-10">
|
</view>
|
||||||
<my-button @tap="confirm" shape="circle" fontWeight="700">修改</my-button>
|
</view>
|
||||||
<view class="">
|
</view>
|
||||||
<my-button @tap="close" type="cancel" bgColor="#fff">取消</my-button>
|
</template>
|
||||||
</view>
|
<template #btn>
|
||||||
</view>
|
<view class="u-p-30">
|
||||||
</view>
|
<view class="u-m-t-10">
|
||||||
</template>
|
<my-button @tap="confirm" shape="circle" fontWeight="700"
|
||||||
</my-model>
|
>修改</my-button
|
||||||
|
>
|
||||||
|
<view class="">
|
||||||
|
<my-button @tap="close" type="cancel" bgColor="#fff"
|
||||||
|
>取消</my-button
|
||||||
|
>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
</my-model>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import {
|
import { reactive, nextTick, ref, watch } from "vue";
|
||||||
reactive,
|
import myModel from "@/components/my-components/my-model.vue";
|
||||||
nextTick,
|
import myButton from "@/components/my-components/my-button.vue";
|
||||||
ref,
|
import myTabs from "@/components/my-components/my-tabs.vue";
|
||||||
watch
|
import infoBox from "@/commons/utils/infoBox.js";
|
||||||
} from 'vue';
|
const props = defineProps({
|
||||||
import myModel from '@/components/my-components/my-model.vue'
|
title: {
|
||||||
import myButton from '@/components/my-components/my-button.vue'
|
type: String,
|
||||||
import myTabs from '@/components/my-components/my-tabs.vue'
|
default: "积分抵扣",
|
||||||
import infoBox from '@/commons/utils/infoBox.js'
|
},
|
||||||
const props = defineProps({
|
accountPoints: {
|
||||||
title: {
|
type: Object,
|
||||||
type: String,
|
default: () => {
|
||||||
default: '积分抵扣'
|
return {
|
||||||
},
|
calcRes: {
|
||||||
accountPoints:{
|
usable: false,
|
||||||
type:Object,
|
unusableReason: "",
|
||||||
default:()=>{
|
minDeductionPoints: 0,
|
||||||
return {
|
maxUsablePoints: 0,
|
||||||
calcRes:{
|
},
|
||||||
usable: false,
|
};
|
||||||
unusableReason: '',
|
},
|
||||||
minDeductionPoints: 0,
|
},
|
||||||
maxUsablePoints: 0
|
price: {
|
||||||
}
|
type: [Number, String],
|
||||||
}
|
default: 0,
|
||||||
}
|
},
|
||||||
},
|
});
|
||||||
price: {
|
|
||||||
type: [Number, String],
|
|
||||||
default: 0
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
function to2(n) {
|
function to2(n) {
|
||||||
if (!n) {
|
if (!n) {
|
||||||
return ''
|
return "";
|
||||||
}
|
}
|
||||||
return n.toFixed(2)
|
return n.toFixed(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
function pointsInput(e){
|
function pointsInput(e) {
|
||||||
setTimeout(()=>{
|
setTimeout(() => {
|
||||||
form.points=Math.floor(e)
|
form.points = Math.floor(e);
|
||||||
},100)
|
}, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pointsChange(newval) {
|
||||||
|
form.points = Math.floor(newval);
|
||||||
|
if (newval < 0) {
|
||||||
|
form.points = 0;
|
||||||
|
return infoBox.showToast("积分抵扣不能小于0");
|
||||||
|
}
|
||||||
|
if (newval > props.accountPoints.calcRes.maxUsablePoints) {
|
||||||
|
form.points = props.price;
|
||||||
|
return infoBox.showToast(
|
||||||
|
"积分抵扣不能大于" + props.accountPoints.calcRes.maxUsablePoints
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function pointsChange(newval) {
|
const form = reactive({
|
||||||
form.points=Math.floor(newval)
|
points: props.price,
|
||||||
if (newval < 0) {
|
});
|
||||||
form.points = 0
|
watch(
|
||||||
return infoBox.showToast('积分抵扣不能小于0')
|
() => props.price,
|
||||||
}
|
(newval) => {
|
||||||
if (newval > props.accountPoints.calcRes.maxUsablePoints) {
|
form.points = newval;
|
||||||
form.points = props.price
|
}
|
||||||
return infoBox.showToast('积分抵扣不能大于'+props.accountPoints.calcRes.maxUsablePoints)
|
);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
function resetForm() {
|
||||||
|
form.points = 0;
|
||||||
|
}
|
||||||
|
|
||||||
const form = reactive({
|
const model = ref(null);
|
||||||
points: props.price,
|
|
||||||
})
|
|
||||||
watch(() => props.price, (newval) => {
|
|
||||||
form.points = newval
|
|
||||||
})
|
|
||||||
|
|
||||||
function resetForm() {
|
function open() {
|
||||||
form.points=0
|
model.value.open();
|
||||||
}
|
form.points = props.price;
|
||||||
|
}
|
||||||
|
|
||||||
const model = ref(null)
|
function close() {
|
||||||
|
model.value.close();
|
||||||
|
}
|
||||||
|
const emits = defineEmits(["confirm"]);
|
||||||
|
|
||||||
function open() {
|
function confirm() {
|
||||||
model.value.open()
|
emits("confirm", Math.floor(form.points));
|
||||||
form.points = props.price
|
close();
|
||||||
}
|
}
|
||||||
|
defineExpose({
|
||||||
function close() {
|
open,
|
||||||
model.value.close()
|
close,
|
||||||
}
|
});
|
||||||
const emits = defineEmits(['confirm'])
|
|
||||||
|
|
||||||
function confirm() {
|
|
||||||
emits('confirm',Math.floor(form.points) )
|
|
||||||
close()
|
|
||||||
}
|
|
||||||
defineExpose({
|
|
||||||
open,
|
|
||||||
close
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.border {
|
.border {
|
||||||
border-radius: 8rpx;
|
border-radius: 8rpx;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
border-color: #999;
|
border-color: #999;
|
||||||
}
|
}
|
||||||
|
|
||||||
.lh34 {
|
.lh34 {
|
||||||
line-height: 34rpx;
|
line-height: 34rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tag {
|
.tag {
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
border: 1px solid #E5E5E5;
|
border: 1px solid #e5e5e5;
|
||||||
line-height: inherit;
|
line-height: inherit;
|
||||||
font-size: 24rpx;
|
font-size: 24rpx;
|
||||||
color: #666666;
|
color: #666666;
|
||||||
padding: 6rpx 20rpx;
|
padding: 6rpx 20rpx;
|
||||||
border-radius: 8rpx;
|
border-radius: 8rpx;
|
||||||
|
|
||||||
&.active {
|
&.active {
|
||||||
border-color: #E6F0FF;
|
border-color: #e6f0ff;
|
||||||
color: $my-main-color;
|
color: $my-main-color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.hover-class {
|
.hover-class {
|
||||||
background-color: #E5E5E5;
|
background-color: #e5e5e5;
|
||||||
}
|
}
|
||||||
|
|
||||||
.discount {
|
.discount {
|
||||||
.u-absolute {
|
.u-absolute {
|
||||||
top: 0;
|
top: 0;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.bg1 {
|
.bg1 {
|
||||||
background: #F7F7FA;
|
background: #f7f7fa;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tab {
|
.tab {
|
||||||
padding: 0 80rpx;
|
padding: 0 80rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.border {
|
.border {
|
||||||
border: 1px solid #E5E5E5;
|
border: 1px solid #e5e5e5;
|
||||||
border-radius: 4rpx;
|
border-radius: 4rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.input-box {
|
.input-box {
|
||||||
padding: 22rpx 32rpx;
|
padding: 22rpx 32rpx;
|
||||||
font-size: 28rpx;
|
font-size: 28rpx;
|
||||||
color: #666;
|
color: #666;
|
||||||
}
|
}
|
||||||
|
|
||||||
.placeholder-class {
|
.placeholder-class {
|
||||||
font-size: 28rpx;
|
font-size: 28rpx;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -998,6 +998,9 @@ watch(
|
|||||||
if (newval) {
|
if (newval) {
|
||||||
getNewUserDiscount();
|
getNewUserDiscount();
|
||||||
// getShopUserDetail();
|
// getShopUserDetail();
|
||||||
|
}else{
|
||||||
|
newUserDiscount.value =0
|
||||||
|
newUserDiscountRes.value =null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ export const useCartStore = defineStore("cart", {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (msg.status == 0&&msg.type!="time_discount") {
|
if (msg.status == 0 && msg.type != "time_discount") {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: "添加失败",
|
title: "添加失败",
|
||||||
icon: "none",
|
icon: "none",
|
||||||
@@ -204,6 +204,9 @@ export const useCartStore = defineStore("cart", {
|
|||||||
this.limitTimeDiscount = msg.time_dis_info;
|
this.limitTimeDiscount = msg.time_dis_info;
|
||||||
this.getOrder();
|
this.getOrder();
|
||||||
break;
|
break;
|
||||||
|
case "reload":
|
||||||
|
this.getOrder();
|
||||||
|
break;
|
||||||
case "pad_add":
|
case "pad_add":
|
||||||
case "add":
|
case "add":
|
||||||
break;
|
break;
|
||||||
@@ -224,7 +227,7 @@ export const useCartStore = defineStore("cart", {
|
|||||||
break;
|
break;
|
||||||
case "pad_cleanup":
|
case "pad_cleanup":
|
||||||
case "cleanup":
|
case "cleanup":
|
||||||
this.goodsList=[]
|
this.goodsList = [];
|
||||||
break;
|
break;
|
||||||
case "product_update":
|
case "product_update":
|
||||||
break;
|
break;
|
||||||
@@ -277,6 +280,7 @@ export const useCartStore = defineStore("cart", {
|
|||||||
*/
|
*/
|
||||||
setOrder(order) {
|
setOrder(order) {
|
||||||
this.order = order;
|
this.order = order;
|
||||||
|
this.limitTimeDiscount = order.limitRate;
|
||||||
this.oldCartList = Object.values(order.detailMap).reduce((pre, cur) => {
|
this.oldCartList = Object.values(order.detailMap).reduce((pre, cur) => {
|
||||||
pre.push(
|
pre.push(
|
||||||
...cur.map((v) => {
|
...cur.map((v) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user