成功修改订单页面套餐金额 为 套餐金额/套餐小时 ,而不是固定的10元/小时
This commit is contained in:
+136
-136
@@ -1,137 +1,137 @@
|
||||
<template>
|
||||
<view>
|
||||
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
wxLogin,
|
||||
} from '../../../util/index'
|
||||
|
||||
import {
|
||||
getMyIndexInfo
|
||||
} from "../../../config/user.js";
|
||||
import {
|
||||
queryHasOrder
|
||||
} from "../../../config/user.js";
|
||||
import {
|
||||
checkOrdersByStatus
|
||||
} from "../../../config/user.js";
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
|
||||
}
|
||||
},
|
||||
async onLoad(option) {
|
||||
console.log('bagCheck onLoad option:', option);
|
||||
try {
|
||||
uni.showLoading({
|
||||
title: '处理中...',
|
||||
mask: true
|
||||
});
|
||||
|
||||
// 检查是否传入设备编号
|
||||
if (!option || !option.deviceNo) {
|
||||
throw new Error('未识别到设备编号');
|
||||
}
|
||||
|
||||
const deviceNo = option.deviceNo;
|
||||
|
||||
// 检查用户是否有进行中(in_used)或待支付(waiting_for_payment)的订单
|
||||
const statusesToCheck = ['in_used', 'waiting_for_payment'];
|
||||
const res = await checkOrdersByStatus(deviceNo, statusesToCheck);
|
||||
|
||||
if (res.code === 200 && res.data && res.data.length > 0) {
|
||||
// 找到相关订单,取最新的一条
|
||||
const latestOrder = res.data[0]; // 假设返回结果按时间倒序
|
||||
|
||||
if (latestOrder.orderStatus === 'in_used') {
|
||||
// 如果是使用中的订单,跳转到归还页面
|
||||
console.log('检测到使用中订单,跳转归还页:', latestOrder.orderId);
|
||||
uni.redirectTo({
|
||||
url: `/pages/device/return?orderId=${latestOrder.orderId}`
|
||||
});
|
||||
} else if (latestOrder.orderStatus === 'waiting_for_payment') {
|
||||
// 如果是待支付订单,跳转到支付页面,并传递必要信息
|
||||
console.log('检测到待支付订单,跳转支付页:', latestOrder.orderId);
|
||||
|
||||
// 获取套餐时间(分钟)
|
||||
const packageTimeMinutes = latestOrder.packageTime || 60;
|
||||
|
||||
// 套餐小时数
|
||||
const packageTimeHours = (packageTimeMinutes / 60).toFixed(1);
|
||||
|
||||
// 套餐价格
|
||||
const packagePrice = latestOrder.packagePrice || '0.00';
|
||||
|
||||
// 计算每小时费率
|
||||
const hourlyRate = (parseFloat(packagePrice) / (packageTimeMinutes / 60)).toFixed(2);
|
||||
|
||||
// 押金金额
|
||||
const depositAmount = latestOrder.depositAmount || '99.00';
|
||||
|
||||
// 计算总金额(套餐+押金)
|
||||
const totalAmount = (parseFloat(depositAmount) + parseFloat(packagePrice)).toFixed(2);
|
||||
|
||||
uni.redirectTo({
|
||||
url: `/pages/order/payment?orderId=${latestOrder.orderId}&packageTimeHours=${packageTimeHours}&packagePrice=${packagePrice}&hourlyRate=${hourlyRate}&totalAmount=${totalAmount}&depositAmount=${depositAmount}`
|
||||
});
|
||||
} else {
|
||||
// 其他状态(理论上不应该到这里,除非statusesToCheck配置错误),默认到详情页
|
||||
console.log('检测到其他状态订单,跳转详情页:', latestOrder.orderId);
|
||||
uni.redirectTo({
|
||||
url: `/pages/device/detail?deviceNo=${deviceNo}`
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// 没有找到相关状态的订单,跳转到设备详情页进行租借
|
||||
console.log('未检测到相关订单,跳转详情页');
|
||||
uni.redirectTo({
|
||||
url: `/pages/device/detail?deviceNo=${deviceNo}`
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
// 只处理真正的错误,不是"没有订单"的情况
|
||||
if (error.message && (
|
||||
error.message.includes('未识别到设备编号') ||
|
||||
error.message.includes('网络请求失败') ||
|
||||
error.message.includes('服务器错误')
|
||||
)) {
|
||||
console.error('扫码检查订单失败:', error);
|
||||
uni.showToast({
|
||||
title: error.message || '处理失败,请稍后重试',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
} else {
|
||||
// 对于其他错误,包括"没有找到订单",直接跳转到详情页,不显示错误消息
|
||||
console.log('没有找到符合条件的订单或发生其他错误,直接跳转详情页');
|
||||
}
|
||||
|
||||
// 无论什么情况,都跳转到一个可用页面
|
||||
setTimeout(() => {
|
||||
if (option && option.deviceNo) {
|
||||
uni.redirectTo({
|
||||
url: `/pages/device/detail?deviceNo=${option.deviceNo}`
|
||||
});
|
||||
} else {
|
||||
// 如果连deviceNo都没有,则返回首页
|
||||
uni.switchTab({ url: '/pages/index/index' });
|
||||
}
|
||||
}, 2000);
|
||||
} finally {
|
||||
uni.hideLoading();
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
<template>
|
||||
<view>
|
||||
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
wxLogin,
|
||||
} from '../../../util/index'
|
||||
|
||||
import {
|
||||
getMyIndexInfo
|
||||
} from "../../../config/user.js";
|
||||
import {
|
||||
queryHasOrder
|
||||
} from "../../../config/user.js";
|
||||
import {
|
||||
checkOrdersByStatus
|
||||
} from "../../../config/user.js";
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
|
||||
}
|
||||
},
|
||||
async onLoad(option) {
|
||||
console.log('bagCheck onLoad option:', option);
|
||||
try {
|
||||
uni.showLoading({
|
||||
title: '处理中...',
|
||||
mask: true
|
||||
});
|
||||
|
||||
// 检查是否传入设备编号
|
||||
if (!option || !option.deviceNo) {
|
||||
throw new Error('未识别到设备编号');
|
||||
}
|
||||
|
||||
const deviceNo = option.deviceNo;
|
||||
|
||||
// 检查用户是否有进行中(in_used)或待支付(waiting_for_payment)的订单
|
||||
const statusesToCheck = ['in_used', 'waiting_for_payment'];
|
||||
const res = await checkOrdersByStatus(deviceNo, statusesToCheck);
|
||||
|
||||
if (res.code === 200 && res.data && res.data.length > 0) {
|
||||
// 找到相关订单,取最新的一条
|
||||
const latestOrder = res.data[0]; // 假设返回结果按时间倒序
|
||||
|
||||
if (latestOrder.orderStatus === 'in_used') {
|
||||
// 如果是使用中的订单,跳转到归还页面
|
||||
console.log('检测到使用中订单,跳转归还页:', latestOrder.orderId);
|
||||
uni.redirectTo({
|
||||
url: `/pages/device/return?orderId=${latestOrder.orderId}`
|
||||
});
|
||||
} else if (latestOrder.orderStatus === 'waiting_for_payment') {
|
||||
// 如果是待支付订单,跳转到支付页面,并传递必要信息
|
||||
console.log('检测到待支付订单,跳转支付页:', latestOrder.orderId);
|
||||
|
||||
// 获取套餐时间(分钟)
|
||||
const packageTimeMinutes = latestOrder.packageTime || 60;
|
||||
|
||||
// 套餐小时数
|
||||
const packageTimeHours = (packageTimeMinutes / 60).toFixed(1);
|
||||
|
||||
// 套餐价格
|
||||
const packagePrice = latestOrder.packagePrice || '0.00';
|
||||
|
||||
// 计算每小时费率
|
||||
const hourlyRate = (parseFloat(packagePrice) / (packageTimeMinutes / 60)).toFixed(2);
|
||||
|
||||
// 押金金额
|
||||
const depositAmount = latestOrder.depositAmount || '99.00';
|
||||
|
||||
// 计算总金额(套餐+押金)
|
||||
const totalAmount = (parseFloat(depositAmount) + parseFloat(packagePrice)).toFixed(2);
|
||||
|
||||
uni.redirectTo({
|
||||
url: `/pages/order/payment?orderId=${latestOrder.orderId}&packageTimeHours=${packageTimeHours}&packagePrice=${packagePrice}&hourlyRate=${hourlyRate}&totalAmount=${totalAmount}&depositAmount=${depositAmount}`
|
||||
});
|
||||
} else {
|
||||
// 其他状态(理论上不应该到这里,除非statusesToCheck配置错误),默认到详情页
|
||||
console.log('检测到其他状态订单,跳转详情页:', latestOrder.orderId);
|
||||
uni.redirectTo({
|
||||
url: `/pages/device/detail?deviceNo=${deviceNo}`
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// 没有找到相关状态的订单,跳转到设备详情页进行租借
|
||||
console.log('未检测到相关订单,跳转详情页');
|
||||
uni.redirectTo({
|
||||
url: `/pages/device/detail?deviceNo=${deviceNo}`
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
// 只处理真正的错误,不是"没有订单"的情况
|
||||
if (error.message && (
|
||||
error.message.includes('未识别到设备编号') ||
|
||||
error.message.includes('网络请求失败') ||
|
||||
error.message.includes('服务器错误')
|
||||
)) {
|
||||
console.error('扫码检查订单失败:', error);
|
||||
uni.showToast({
|
||||
title: error.message || '处理失败,请稍后重试',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
} else {
|
||||
// 对于其他错误,包括"没有找到订单",直接跳转到详情页,不显示错误消息
|
||||
console.log('没有找到符合条件的订单或发生其他错误,直接跳转详情页');
|
||||
}
|
||||
|
||||
// 无论什么情况,都跳转到一个可用页面
|
||||
setTimeout(() => {
|
||||
if (option && option.deviceNo) {
|
||||
uni.redirectTo({
|
||||
url: `/pages/device/detail?deviceNo=${option.deviceNo}`
|
||||
});
|
||||
} else {
|
||||
// 如果连deviceNo都没有,则返回首页
|
||||
uni.switchTab({ url: '/pages/index/index' });
|
||||
}
|
||||
}, 2000);
|
||||
} finally {
|
||||
uni.hideLoading();
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
</style>
|
||||
Reference in New Issue
Block a user