如果扫描用户,没有订单,不需要返回任何信息给用户
完成套餐从数据库中提取
This commit is contained in:
+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()
|
||||
|
||||
Reference in New Issue
Block a user