fix: 设备扫码检测到订单为in_used状态,跳转不成功的问题

This commit is contained in:
8vd8
2025-04-10 14:46:29 +08:00
parent 3491d93e27
commit 2da6ef8f41
12 changed files with 269 additions and 55 deletions
+11 -2
View File
@@ -3,6 +3,7 @@ const common_vendor = require("../common/vendor.js");
const config_url = require("./url.js");
const request = (option) => {
return new Promise((resolve, reject) => {
common_vendor.index.__f__("log", "at config/http.js:9", `发起请求: ${option.method} ${config_url.URL + option.url}`, option.data);
common_vendor.index.request({
url: config_url.URL + option.url,
method: option.method,
@@ -15,17 +16,25 @@ const request = (option) => {
"Clientid": common_vendor.index.getStorageSync("client_id")
},
success(res) {
common_vendor.index.__f__("log", "at config/http.js:24", `请求响应: ${option.url}`, res);
if (res.statusCode !== 200) {
common_vendor.index.__f__("error", "at config/http.js:28", `HTTP状态码错误: ${res.statusCode}`, res.data);
if (res.data) {
resolve(res.data);
return;
}
reject({ msg: `请求失败,状态码:${res.statusCode}` });
return;
}
if (res.data.code !== 200) {
reject(res.data);
if (res.data && res.data.code !== 200) {
common_vendor.index.__f__("warn", "at config/http.js:42", `业务状态码错误: ${res.data.code}`, res.data);
resolve(res.data);
return;
}
resolve(res.data);
},
fail(err) {
common_vendor.index.__f__("error", "at config/http.js:53", `请求失败: ${option.url}`, err);
reject(err);
}
});
+4 -2
View File
@@ -1,4 +1,5 @@
"use strict";
const common_vendor = require("../common/vendor.js");
const config_http = require("./http.js");
const login = (data) => {
return config_http.request({
@@ -40,9 +41,10 @@ const queryById = (id) => {
method: "get"
});
};
const overOrderById = (data) => {
const overOrderById = (orderId) => {
common_vendor.index.__f__("log", "at config/user.js:78", `调用结束订单API, orderId: ${orderId}`);
return config_http.request({
url: `/app/order/close/${data}`,
url: `/app/order/close/${orderId}`,
method: "get"
});
};
+10 -3
View File
@@ -14,6 +14,7 @@ const _sfc_main = {
});
let deviceNo = util_index.getQueryString(scanResult.path, "deviceNo");
common_vendor.index.__f__("log", "at pages/index/index.vue:64", "扫码路径:", scanResult.path);
common_vendor.index.__f__("log", "at pages/index/index.vue:65", "解析到的设备号:", deviceNo);
const inUseRes = await common_vendor.index.request({
url: `${common_vendor.index.getStorageSync("baseUrl") || "http://127.0.0.1:8080"}/app/order/inUse`,
method: "GET",
@@ -22,11 +23,14 @@ const _sfc_main = {
"Clientid": common_vendor.index.getStorageSync("client_id")
}
});
common_vendor.index.__f__("log", "at pages/index/index.vue:77", "使用中订单检查结果:", JSON.stringify(inUseRes));
if (inUseRes.statusCode === 200 && inUseRes.data.code === 200 && inUseRes.data.data) {
const inUseOrder = inUseRes.data.data;
common_vendor.index.navigateTo({
url: `/pages/return/index?orderId=${inUseOrder.orderId}&deviceId=${deviceNo}`
common_vendor.index.__f__("log", "at pages/index/index.vue:82", "检测到使用中订单,准备跳转:", inUseOrder);
common_vendor.index.reLaunch({
url: `/pages/return/index?orderId=${inUseOrder.orderId}&deviceId=${deviceNo || inUseOrder.deviceNo}`
});
common_vendor.index.__f__("log", "at pages/index/index.vue:88", "已发起页面跳转");
return;
}
const orderRes = await common_vendor.index.request({
@@ -37,18 +41,21 @@ const _sfc_main = {
"Clientid": common_vendor.index.getStorageSync("client_id")
}
});
common_vendor.index.__f__("log", "at pages/index/index.vue:102", "待支付订单检查结果:", JSON.stringify(orderRes));
if (orderRes.statusCode === 200 && orderRes.data.code === 200 && orderRes.data.data) {
const unpaidOrder = orderRes.data.data;
common_vendor.index.__f__("log", "at pages/index/index.vue:107", "检测到待支付订单,准备跳转:", unpaidOrder);
common_vendor.index.navigateTo({
url: `/pages/order/payment?orderId=${unpaidOrder.orderId}`
});
} else {
common_vendor.index.__f__("log", "at pages/index/index.vue:113", "无待支付订单,跳转到设备检查页面, deviceNo:", deviceNo);
common_vendor.index.navigateTo({
url: `/pages/serve/bagCheck/index?deviceNo=${deviceNo}`
});
}
} catch (error) {
common_vendor.index.__f__("error", "at pages/index/index.vue:108", "扫码处理失败:", error);
common_vendor.index.__f__("error", "at pages/index/index.vue:119", "扫码处理失败:", error);
common_vendor.index.showToast({
title: "扫码失败",
icon: "none"
+85 -14
View File
@@ -16,10 +16,26 @@ const _sfc_main = {
};
},
onLoad(options) {
this.deviceId = options.deviceId || "";
common_vendor.index.__f__("log", "at pages/return/index.vue:77", "Return page loaded with options:", JSON.stringify(options));
this.orderInfo.orderId = options.orderId || "";
this.getOrderDetails();
this.startTimer();
this.deviceId = options.deviceId || "";
common_vendor.index.__f__("log", "at pages/return/index.vue:83", `初始化参数: orderId=${this.orderInfo.orderId}, deviceId=${this.deviceId}`);
if (!this.orderInfo.orderId && this.deviceId) {
this.getOrderByDevice();
} else if (this.orderInfo.orderId) {
this.getOrderDetails();
this.startTimer();
} else {
common_vendor.index.showToast({
title: "缺少订单信息",
icon: "none"
});
setTimeout(() => {
common_vendor.index.reLaunch({
url: "/pages/index/index"
});
}, 1500);
}
},
onUnload() {
this.clearTimer();
@@ -32,26 +48,35 @@ const _sfc_main = {
if (!this.orderInfo.orderId) {
throw new Error("订单ID不能为空");
}
common_vendor.index.__f__("log", "at pages/return/index.vue:122", "请求订单详情, orderId:", this.orderInfo.orderId);
const result = await config_user.queryById(this.orderInfo.orderId);
common_vendor.index.__f__("log", "at pages/return/index.vue:124", "订单详情结果:", JSON.stringify(result));
if (result.code === 200 && result.data) {
const orderData = result.data;
common_vendor.index.__f__("log", "at pages/return/index.vue:128", "订单数据:", JSON.stringify(orderData));
this.updateOrderInfo(orderData);
const rawTime = orderData.startTime;
common_vendor.index.__f__("log", "at pages/return/index.vue:105", "始时间:", rawTime);
const fixedTime = rawTime.replace(" ", "T");
const date = new Date(fixedTime);
common_vendor.index.__f__("log", "at pages/return/index.vue:108", "原始时间:", rawTime);
if (isNaN(date.getTime())) {
this.orderInfo.startTime = "时间解析错误";
common_vendor.index.__f__("log", "at pages/return/index.vue:135", "始时间:", rawTime);
if (rawTime) {
try {
const date = new Date(rawTime.replace(" ", "T"));
if (!isNaN(date.getTime())) {
this.orderInfo.startTime = this.formatTime(date);
} else {
this.orderInfo.startTime = rawTime;
}
} catch (e) {
common_vendor.index.__f__("error", "at pages/return/index.vue:148", "时间格式化错误:", e);
this.orderInfo.startTime = rawTime;
}
} else {
common_vendor.index.__f__("log", "at pages/return/index.vue:112", "原始时间:", rawTime);
this.orderInfo.startTime = this.formatTime(date);
this.orderInfo.startTime = "未知";
}
this.calculateUsedTime(orderData.createTime);
this.orderInfo.currentFee = orderData.amount || "0.00";
} else {
throw new Error("获取订单详情失败");
throw new Error(result.msg || "获取订单详情失败");
}
} catch (error) {
common_vendor.index.__f__("error", "at pages/return/index.vue:158", "获取订单详情错误:", error);
common_vendor.index.showToast({
title: error.message || "获取订单信息失败",
icon: "none"
@@ -76,8 +101,12 @@ const _sfc_main = {
},
// 使用后端返回的使用时长和费用数据
updateOrderInfo(orderData) {
common_vendor.index.__f__("log", "at pages/return/index.vue:188", "更新订单信息:", JSON.stringify(orderData));
this.orderInfo.usedTime = orderData.usedTime || "0分钟";
this.orderInfo.currentFee = orderData.currentFee || "0.00";
if (orderData.deviceNo && !this.deviceId) {
this.deviceId = orderData.deviceNo;
}
},
// 更新使用时长的定时器
startTimer() {
@@ -113,7 +142,9 @@ const _sfc_main = {
common_vendor.index.hideLoading();
return;
}
common_vendor.index.__f__("log", "at pages/return/index.vue:239", `准备结束订单, orderId: ${this.orderInfo.orderId}`);
const result = await config_user.overOrderById(this.orderInfo.orderId);
common_vendor.index.__f__("log", "at pages/return/index.vue:244", "结束订单结果:", JSON.stringify(result));
if (result.code === 200) {
common_vendor.index.showToast({
title: "归还成功",
@@ -128,6 +159,7 @@ const _sfc_main = {
throw new Error(result.msg || "归还失败");
}
} catch (error) {
common_vendor.index.__f__("error", "at pages/return/index.vue:262", "归还操作错误:", error);
common_vendor.index.showToast({
title: error.message || "归还失败,请重试",
icon: "none"
@@ -136,6 +168,45 @@ const _sfc_main = {
this.unlocking = false;
common_vendor.index.hideLoading();
}
},
// 通过设备号查询使用中的订单
async getOrderByDevice() {
try {
common_vendor.index.showLoading({ title: "加载中" });
if (!this.deviceId) {
throw new Error("设备号不能为空");
}
const inUseRes = await common_vendor.index.request({
url: `${common_vendor.index.getStorageSync("baseUrl") || "http://127.0.0.1:8080"}/app/order/inUse`,
method: "GET",
header: {
"Authorization": "Bearer " + common_vendor.index.getStorageSync("token"),
"Clientid": common_vendor.index.getStorageSync("client_id")
}
});
common_vendor.index.__f__("log", "at pages/return/index.vue:292", "通过设备号查询订单结果:", JSON.stringify(inUseRes));
if (inUseRes.statusCode === 200 && inUseRes.data.code === 200 && inUseRes.data.data) {
const inUseOrder = inUseRes.data.data;
this.orderInfo.orderId = inUseOrder.orderId;
this.getOrderDetails();
this.startTimer();
} else {
throw new Error("未找到使用中的订单");
}
} catch (error) {
common_vendor.index.__f__("error", "at pages/return/index.vue:307", "通过设备号查询订单失败:", error);
common_vendor.index.showToast({
title: error.message || "获取订单信息失败",
icon: "none"
});
setTimeout(() => {
common_vendor.index.reLaunch({
url: "/pages/index/index"
});
}, 1500);
} finally {
common_vendor.index.hideLoading();
}
}
}
};