如果扫描用户,没有订单,不需要返回任何信息给用户
完成套餐从数据库中提取
This commit is contained in:
@@ -96,8 +96,11 @@ export default {
|
||||
})
|
||||
return
|
||||
}
|
||||
const res = await queryById(Number(this.orderNo))
|
||||
console.log(res);
|
||||
if(this.orderId.length!=0||this.orderNo.length!=0){
|
||||
const res = await queryById(Number(this.orderId))
|
||||
console.log(res);
|
||||
}
|
||||
|
||||
// if(this.orderNo.length!=0){
|
||||
// uni.showToast({
|
||||
// title:'当前存在进行中的订单',
|
||||
|
||||
+158
-21
@@ -73,7 +73,7 @@
|
||||
<view class="bottom-bar">
|
||||
<view class="price-info" v-if="!hasActiveOrder">
|
||||
<text class="deposit-text">押金:</text>
|
||||
<text class="deposit-amount">¥99</text>
|
||||
<text class="deposit-amount">¥{{ depositAmount }}</text>
|
||||
</view>
|
||||
<button class="action-btn" :class="hasActiveOrder ? 'return' : 'rent'" @click="handleRent">
|
||||
{{ hasActiveOrder ? '归还设备' : '立即租借' }}
|
||||
@@ -101,22 +101,8 @@
|
||||
class: 'available'
|
||||
},
|
||||
selectedPackage: 1,
|
||||
packages: [{
|
||||
time: '1小时',
|
||||
price: '2.00',
|
||||
unitPrice: '2.00'
|
||||
},
|
||||
{
|
||||
time: '4小时',
|
||||
price: '6.00',
|
||||
unitPrice: '1.50'
|
||||
},
|
||||
{
|
||||
time: '12小时',
|
||||
price: '15.00',
|
||||
unitPrice: '1.25'
|
||||
}
|
||||
],
|
||||
packages: [],
|
||||
depositAmount: "99.00", // 默认押金金额
|
||||
isLoggedIn: true,
|
||||
phoneNumber: ''
|
||||
}
|
||||
@@ -133,7 +119,158 @@
|
||||
async getDeviceInfo() {
|
||||
const res = await getDeviceInfo(this.deviceId);
|
||||
if (res.code == 200) {
|
||||
this.deviceInfo = res.data
|
||||
this.deviceInfo = res.data.device || {};
|
||||
|
||||
// 更新设备位置信息
|
||||
if (this.deviceInfo.deviceLocation) {
|
||||
this.deviceLocation = this.deviceInfo.deviceLocation;
|
||||
} else if (res.data.position && res.data.position.name) {
|
||||
this.deviceLocation = res.data.position.name;
|
||||
}
|
||||
|
||||
// 获取押金金额
|
||||
if (this.deviceInfo.depositAmount) {
|
||||
this.depositAmount = this.deviceInfo.depositAmount;
|
||||
}
|
||||
|
||||
// 更新设备状态
|
||||
if (this.deviceInfo.status) {
|
||||
if (this.deviceInfo.status === 'online') {
|
||||
this.deviceStatus = {
|
||||
text: '可使用',
|
||||
class: 'available'
|
||||
};
|
||||
} else if (this.deviceInfo.status === 'offline') {
|
||||
this.deviceStatus = {
|
||||
text: '离线',
|
||||
class: 'offline'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 解析feeConfig并生成套餐选项
|
||||
if (this.deviceInfo.feeConfig) {
|
||||
try {
|
||||
const feeConfig = JSON.parse(this.deviceInfo.feeConfig);
|
||||
|
||||
// 检查是否为新格式 [{"Hour":1,"Price":4},{"Hour":3,"Price":10},{"Hour":5,"Price":15}]
|
||||
if (feeConfig.length > 0 && 'Hour' in feeConfig[0] && 'Price' in feeConfig[0]) {
|
||||
// 新格式处理
|
||||
this.packages = feeConfig.map(pkg => {
|
||||
const hour = pkg.Hour;
|
||||
const price = pkg.Price;
|
||||
const unitPrice = (price / hour).toFixed(2);
|
||||
|
||||
return {
|
||||
time: `${hour}${hour > 1 ? '小时' : '小时'}`,
|
||||
price: price.toFixed(2),
|
||||
unitPrice: unitPrice
|
||||
};
|
||||
});
|
||||
} else {
|
||||
// 旧格式处理
|
||||
// 通常使用common规格的配置
|
||||
const commonConfig = feeConfig.find(item => item.specCode === 'common') || feeConfig[0];
|
||||
|
||||
if (commonConfig) {
|
||||
// 根据收费类型生成套餐
|
||||
if (this.deviceInfo.feeType === 'hour') {
|
||||
// 按小时收费
|
||||
const hourPrice = commonConfig.hourPrice > 0 ? commonConfig.hourPrice : commonConfig.timesPrice / 6;
|
||||
|
||||
this.packages = [
|
||||
{
|
||||
time: '1小时',
|
||||
price: hourPrice.toFixed(2),
|
||||
unitPrice: hourPrice.toFixed(2)
|
||||
},
|
||||
{
|
||||
time: '6小时',
|
||||
price: (hourPrice * 6).toFixed(2),
|
||||
unitPrice: hourPrice.toFixed(2)
|
||||
},
|
||||
{
|
||||
time: '12小时',
|
||||
price: (hourPrice * 12).toFixed(2),
|
||||
unitPrice: hourPrice.toFixed(2)
|
||||
}
|
||||
];
|
||||
} else if (this.deviceInfo.feeType === 'times') {
|
||||
// 按次收费
|
||||
const timesPrice = commonConfig.timesPrice;
|
||||
this.packages = [
|
||||
{
|
||||
time: '1次',
|
||||
price: timesPrice.toFixed(2),
|
||||
unitPrice: timesPrice.toFixed(2)
|
||||
}
|
||||
];
|
||||
} else {
|
||||
// 默认套餐
|
||||
this.packages = [
|
||||
{
|
||||
time: '1小时',
|
||||
price: '2.00',
|
||||
unitPrice: '2.00'
|
||||
},
|
||||
{
|
||||
time: '6小时',
|
||||
price: '10.00',
|
||||
unitPrice: '1.67'
|
||||
},
|
||||
{
|
||||
time: '12小时',
|
||||
price: '15.00',
|
||||
unitPrice: '1.25'
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 默认选中中间套餐
|
||||
this.selectedPackage = Math.min(1, this.packages.length - 1);
|
||||
} catch (e) {
|
||||
console.error('解析设备费用配置失败:', e);
|
||||
// 使用默认套餐
|
||||
this.packages = [
|
||||
{
|
||||
time: '1小时',
|
||||
price: '2.00',
|
||||
unitPrice: '2.00'
|
||||
},
|
||||
{
|
||||
time: '6小时',
|
||||
price: '10.00',
|
||||
unitPrice: '1.67'
|
||||
},
|
||||
{
|
||||
time: '12小时',
|
||||
price: '15.00',
|
||||
unitPrice: '1.25'
|
||||
}
|
||||
];
|
||||
}
|
||||
} else {
|
||||
// 如果没有feeConfig,使用默认套餐
|
||||
this.packages = [
|
||||
{
|
||||
time: '1小时',
|
||||
price: '2.00',
|
||||
unitPrice: '2.00'
|
||||
},
|
||||
{
|
||||
time: '6小时',
|
||||
price: '10.00',
|
||||
unitPrice: '1.67'
|
||||
},
|
||||
{
|
||||
time: '12小时',
|
||||
price: '15.00',
|
||||
unitPrice: '1.25'
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -217,7 +354,7 @@
|
||||
const selectedPkg = this.packages[this.selectedPackage]
|
||||
uni.showModal({
|
||||
title: '确认租借',
|
||||
content: `确认支付押金¥99.00及${selectedPkg.time}套餐费用¥${selectedPkg.price}?`,
|
||||
content: `确认支付押金¥{{ depositAmount }}及${selectedPkg.time}套餐费用¥${selectedPkg.price}?`,
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
this.submitRentOrder()
|
||||
@@ -274,7 +411,7 @@
|
||||
// --- 更新结束 ---
|
||||
|
||||
// --- 新增:计算总金额 ---
|
||||
const deposit = 99.00; // 固定押金
|
||||
const deposit = parseFloat(this.depositAmount);
|
||||
const packagePrice = parseFloat(selectedPkg.price);
|
||||
const totalAmount = (deposit + packagePrice).toFixed(2);
|
||||
// --- 计算结束 ---
|
||||
@@ -283,7 +420,7 @@
|
||||
|
||||
// 跳转到订单支付页面,传递订单ID、套餐信息和总金额
|
||||
uni.redirectTo({
|
||||
url: `/pages/order/payment?orderId=${order.orderId}&packageTime=${selectedPkg.time}&packagePrice=${selectedPkg.price}&totalAmount=${totalAmount}`
|
||||
url: `/pages/order/payment?orderId=${order.orderId}&packageTimeHours=${selectedPkg.time.replace('小时', '')}&packagePrice=${selectedPkg.price}&totalAmount=${totalAmount}&depositAmount=${this.depositAmount}`
|
||||
})
|
||||
} catch (error) {
|
||||
uni.hideLoading()
|
||||
|
||||
+88
-23
@@ -37,11 +37,7 @@
|
||||
</view>
|
||||
<view class="price-item">
|
||||
<text class="label">套餐</text>
|
||||
<text class="value">{{ packageInfo.time }} (¥{{ packageInfo.price }})</text>
|
||||
</view>
|
||||
<view class="price-item">
|
||||
<text class="label">租借费用</text>
|
||||
<text class="value">¥{{ orderInfo.amount || packageInfo.price }}</text>
|
||||
<text class="value">{{ packageInfo.price }}元/{{ packageInfo.time }}小时</text>
|
||||
</view>
|
||||
<view class="price-item total">
|
||||
<text class="label">合计</text>
|
||||
@@ -65,6 +61,7 @@
|
||||
|
||||
<script>
|
||||
import { queryById } from '@/config/user.js'
|
||||
import { getDeviceInfo } from '@/config/user.js'
|
||||
import { updateOrderPackage } from '@/config/user.js'
|
||||
import { updateUserBalance } from '@/config/user.js'
|
||||
import {
|
||||
@@ -75,11 +72,13 @@ export default {
|
||||
data() {
|
||||
return {
|
||||
orderId: null,
|
||||
deviceNo: null,
|
||||
orderInfo: {},
|
||||
packageInfo: {
|
||||
time: '',
|
||||
price: '0.00'
|
||||
},
|
||||
deviceInfo: null,
|
||||
passedTotalAmount: null,
|
||||
passedDepositAmount: null,
|
||||
orderStatus: {
|
||||
@@ -94,23 +93,15 @@ export default {
|
||||
if (this.passedTotalAmount !== null) {
|
||||
return parseFloat(this.passedTotalAmount).toFixed(2);
|
||||
}
|
||||
const deposit = parseFloat(this.orderInfo.deposit || 99)
|
||||
const amount = parseFloat(this.orderInfo.amount || this.packageInfo.price || 0)
|
||||
return (deposit + amount).toFixed(2)
|
||||
const deposit = parseFloat(this.orderInfo.deposit || this.passedDepositAmount || 99)
|
||||
const packagePrice = parseFloat(this.packageInfo.price || 0)
|
||||
return (deposit + packagePrice).toFixed(2)
|
||||
}
|
||||
},
|
||||
onLoad(options) {
|
||||
if (options && options.orderId) {
|
||||
this.orderId = options.orderId
|
||||
|
||||
// 获取传递的套餐信息
|
||||
if (options.packageTime && options.packagePrice) {
|
||||
this.packageInfo = {
|
||||
time: options.packageTime,
|
||||
price: options.packagePrice
|
||||
}
|
||||
}
|
||||
|
||||
if (options.totalAmount) {
|
||||
this.passedTotalAmount = options.totalAmount;
|
||||
}
|
||||
@@ -164,15 +155,12 @@ export default {
|
||||
deviceNo: orderData.deviceNo,
|
||||
createTime: formattedTime,
|
||||
phone: orderData.phone,
|
||||
deposit: this.passedDepositAmount || orderData.depositAmount || '99.00', // 优先使用传递的押金,然后是订单中的押金,最后默认99元
|
||||
amount: orderData.amount || this.packageInfo.price || '0.00'
|
||||
deposit: this.passedDepositAmount || orderData.depositAmount || '99.00',
|
||||
}
|
||||
|
||||
// 如果订单中没有套餐信息,但URL参数中有,则使用URL参数中的套餐信息
|
||||
if (!orderData.packageTime && this.packageInfo.time) {
|
||||
this.orderInfo.packageTime = this.packageInfo.time
|
||||
this.orderInfo.packagePrice = this.packageInfo.price
|
||||
}
|
||||
// 获取设备信息并解析套餐
|
||||
this.deviceNo = orderData.deviceNo;
|
||||
await this.loadDeviceInfo();
|
||||
} else {
|
||||
throw new Error('获取订单信息失败')
|
||||
}
|
||||
@@ -187,6 +175,83 @@ export default {
|
||||
}
|
||||
},
|
||||
|
||||
// 加载设备信息并解析套餐
|
||||
async loadDeviceInfo() {
|
||||
if (!this.deviceNo) return;
|
||||
|
||||
try {
|
||||
const res = await getDeviceInfo(this.deviceNo);
|
||||
if (res.code === 200 && res.data) {
|
||||
this.deviceInfo = res.data.device;
|
||||
|
||||
// 解析feeConfig获取套餐信息
|
||||
if (this.deviceInfo && this.deviceInfo.feeConfig) {
|
||||
try {
|
||||
const feeConfig = JSON.parse(this.deviceInfo.feeConfig);
|
||||
|
||||
// 检查是否为新格式 [{"Hour":1,"Price":4},{"Hour":3,"Price":10},{"Hour":5,"Price":15}]
|
||||
if (feeConfig.length > 0 && 'Hour' in feeConfig[0] && 'Price' in feeConfig[0]) {
|
||||
// 尝试找到对应包时长的套餐
|
||||
// 默认使用6小时或最接近的套餐
|
||||
const targetHours = 6;
|
||||
let closestPackage = feeConfig[0];
|
||||
|
||||
// 找出最接近目标时长的套餐
|
||||
feeConfig.forEach(pkg => {
|
||||
if (Math.abs(pkg.Hour - targetHours) < Math.abs(closestPackage.Hour - targetHours)) {
|
||||
closestPackage = pkg;
|
||||
}
|
||||
});
|
||||
|
||||
this.packageInfo.time = closestPackage.Hour.toString();
|
||||
this.packageInfo.price = closestPackage.Price.toString();
|
||||
} else {
|
||||
// 旧格式处理
|
||||
// 通常使用common配置
|
||||
const selectedConfig = feeConfig.find(item => item.specCode === 'common') || feeConfig[0];
|
||||
|
||||
if (selectedConfig) {
|
||||
// 套餐时间
|
||||
const packageHours = 6; // 默认6小时
|
||||
|
||||
// 如果是按次收费,则直接使用timesPrice
|
||||
if (this.deviceInfo.feeType === 'times') {
|
||||
this.packageInfo.price = selectedConfig.timesPrice.toString();
|
||||
this.packageInfo.time = '1次';
|
||||
}
|
||||
// 如果是按小时收费
|
||||
else if (this.deviceInfo.feeType === 'hour') {
|
||||
if (selectedConfig.hourPrice > 0) {
|
||||
// 如果有设置小时价格,计算套餐价格
|
||||
this.packageInfo.price = (selectedConfig.hourPrice * packageHours).toString();
|
||||
} else {
|
||||
// 否则使用timesPrice作为套餐价格
|
||||
this.packageInfo.price = selectedConfig.timesPrice.toString();
|
||||
}
|
||||
this.packageInfo.time = packageHours.toString();
|
||||
}
|
||||
// 如果是其他收费类型,使用timesPrice
|
||||
else {
|
||||
this.packageInfo.price = selectedConfig.timesPrice.toString();
|
||||
this.packageInfo.time = packageHours.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('解析设备费用配置失败:', e);
|
||||
}
|
||||
}
|
||||
|
||||
// 设置存款金额
|
||||
if (this.deviceInfo && this.deviceInfo.depositAmount) {
|
||||
this.orderInfo.deposit = this.deviceInfo.depositAmount;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取设备信息失败:', error);
|
||||
}
|
||||
},
|
||||
|
||||
// 处理支付
|
||||
async handlePayment() {
|
||||
try {
|
||||
|
||||
@@ -57,13 +57,27 @@
|
||||
} else if (latestOrder.orderStatus === 'waiting_for_payment') {
|
||||
// 如果是待支付订单,跳转到支付页面,并传递必要信息
|
||||
console.log('检测到待支付订单,跳转支付页:', latestOrder.orderId);
|
||||
const packageTime = latestOrder.packageTime ? `${latestOrder.packageTime / 60}小时` : '默认套餐'; // 示例转换
|
||||
|
||||
// 获取套餐时间(分钟)
|
||||
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}&packageTime=${packageTime}&packagePrice=${packagePrice}&totalAmount=${totalAmount}&depositAmount=${depositAmount}`
|
||||
url: `/pages/order/payment?orderId=${latestOrder.orderId}&packageTimeHours=${packageTimeHours}&packagePrice=${packagePrice}&hourlyRate=${hourlyRate}&totalAmount=${totalAmount}&depositAmount=${depositAmount}`
|
||||
});
|
||||
} else {
|
||||
// 其他状态(理论上不应该到这里,除非statusesToCheck配置错误),默认到详情页
|
||||
@@ -80,13 +94,24 @@
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('扫码检查订单失败:', error);
|
||||
uni.showToast({
|
||||
title: error.message || '处理失败,请稍后重试',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
// 错误时也尝试跳转到详情页,给用户一个操作入口
|
||||
// 只处理真正的错误,不是"没有订单"的情况
|
||||
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({
|
||||
|
||||
Reference in New Issue
Block a user