如果扫描用户,没有订单,不需要返回任何信息给用户

完成套餐从数据库中提取
This commit is contained in:
8vd8
2025-04-22 18:08:52 +08:00
parent 8431cdf2d6
commit d9e70d4eaf
21 changed files with 591 additions and 145 deletions
+88 -23
View File
@@ -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 {