fix: 设备扫码检测到订单为in_used状态,跳转不成功的问题
This commit is contained in:
+10
-3
@@ -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
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user