成功修改订单页面套餐金额 为 套餐金额/套餐小时 ,而不是固定的10元/小时
This commit is contained in:
+176
-141
@@ -110,9 +110,28 @@
|
||||
onLoad(options) {
|
||||
// console.log(options);
|
||||
this.deviceId = options.deviceNo
|
||||
this.checkOrderStatus() // 新增状态检查
|
||||
console.log(options.deviceNo);
|
||||
this.getDeviceInfo()
|
||||
|
||||
// 如果URL中包含了feeConfig参数,直接使用它
|
||||
if (options.feeConfig) {
|
||||
try {
|
||||
console.log('从URL获取到feeConfig:', options.feeConfig)
|
||||
const feeConfigStr = decodeURIComponent(options.feeConfig)
|
||||
// 存储到设备信息中,这样后续处理逻辑可以保持不变
|
||||
this.deviceInfo = { ...this.deviceInfo, feeConfig: feeConfigStr }
|
||||
// 马上解析feeConfig并生成套餐选项
|
||||
this.parseFeeConfig()
|
||||
} catch (e) {
|
||||
console.error('解析URL中的feeConfig失败:', e)
|
||||
// 如果解析失败,继续正常流程获取设备信息
|
||||
this.checkOrderStatus()
|
||||
this.getDeviceInfo()
|
||||
}
|
||||
} else {
|
||||
// 正常流程
|
||||
this.checkOrderStatus() // 新增状态检查
|
||||
console.log(options.deviceNo);
|
||||
this.getDeviceInfo()
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
// 检查登录状态和订单
|
||||
@@ -148,133 +167,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
// 解析feeConfig并生成套餐选项
|
||||
if (this.deviceInfo.feeConfig) {
|
||||
try {
|
||||
const feeConfig = JSON.parse(this.deviceInfo.feeConfig);
|
||||
|
||||
// 检查是否为新格式 [{"hour":1,"timesPrice":4},{"hour":3,"timesPrice":10},{"hour":5,"timesPrice":15}]
|
||||
if (feeConfig.length > 0 && 'hour' in feeConfig[0] && 'timesPrice' in feeConfig[0]) {
|
||||
// 新格式处理 - 直接使用所有套餐
|
||||
this.packages = feeConfig.map(pkg => {
|
||||
const hour = pkg.hour;
|
||||
const price = pkg.timesPrice;
|
||||
const unitPrice = (price / hour).toFixed(2);
|
||||
|
||||
return {
|
||||
time: `${hour}小时`,
|
||||
price: price.toFixed(2),
|
||||
unitPrice: unitPrice,
|
||||
hour: hour // 添加小时信息,用于后续处理
|
||||
};
|
||||
});
|
||||
|
||||
// 按小时排序
|
||||
this.packages.sort((a, b) => a.hour - b.hour);
|
||||
} 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'
|
||||
}
|
||||
];
|
||||
}
|
||||
// 使用抽取的方法解析feeConfig并生成套餐选项
|
||||
this.parseFeeConfig();
|
||||
}
|
||||
},
|
||||
|
||||
@@ -355,16 +249,8 @@
|
||||
return
|
||||
}
|
||||
|
||||
const selectedPkg = this.packages[this.selectedPackage]
|
||||
uni.showModal({
|
||||
title: '确认租借',
|
||||
content: `确认支付押金¥{{ depositAmount }}及${selectedPkg.time}套餐费用¥${selectedPkg.price}?`,
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
this.submitRentOrder()
|
||||
}
|
||||
}
|
||||
})
|
||||
// 直接提交订单,不显示确认对话框
|
||||
this.submitRentOrder()
|
||||
},
|
||||
|
||||
// 提交租借订单
|
||||
@@ -424,7 +310,7 @@
|
||||
|
||||
// 跳转到订单支付页面,传递订单ID、套餐信息和总金额
|
||||
uni.redirectTo({
|
||||
url: `/pages/order/payment?orderId=${order.orderId}&packageTimeHours=${selectedPkg.time.replace('小时', '')}&packagePrice=${selectedPkg.price}&totalAmount=${totalAmount}&depositAmount=${this.depositAmount}`
|
||||
url: `/pages/order/payment?orderId=${order.orderId}&packageTimeHours=${selectedPkg.time.replace('小时', '')}&packagePrice=${selectedPkg.price}&totalAmount=${totalAmount}&depositAmount=${this.depositAmount}${this.deviceInfo && this.deviceInfo.feeConfig ? '&feeConfig=' + encodeURIComponent(this.deviceInfo.feeConfig) : ''}`
|
||||
})
|
||||
} catch (error) {
|
||||
uni.hideLoading()
|
||||
@@ -433,6 +319,155 @@
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
// 单独抽取解析feeConfig的逻辑
|
||||
parseFeeConfig() {
|
||||
if (this.deviceInfo.feeConfig) {
|
||||
try {
|
||||
const feeConfig = JSON.parse(this.deviceInfo.feeConfig);
|
||||
|
||||
// 检查是否为新格式 [{"hour":1,"timesPrice":4},{"hour":3,"timesPrice":10},{"hour":5,"timesPrice":15}]
|
||||
if (feeConfig.length > 0 && 'hour' in feeConfig[0] && 'timesPrice' in feeConfig[0]) {
|
||||
// 新格式处理 - 直接使用所有套餐
|
||||
this.packages = feeConfig.map(pkg => {
|
||||
const hour = pkg.hour;
|
||||
const price = pkg.timesPrice;
|
||||
const unitPrice = (price / hour).toFixed(2);
|
||||
|
||||
return {
|
||||
time: `${hour}小时`,
|
||||
price: price.toFixed(2),
|
||||
unitPrice: unitPrice,
|
||||
hour: hour // 添加小时信息,用于后续处理
|
||||
};
|
||||
});
|
||||
|
||||
// 按小时排序
|
||||
this.packages.sort((a, b) => a.hour - b.hour);
|
||||
} 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),
|
||||
hour: 1
|
||||
},
|
||||
{
|
||||
time: '6小时',
|
||||
price: (hourPrice * 6).toFixed(2),
|
||||
unitPrice: hourPrice.toFixed(2),
|
||||
hour: 6
|
||||
},
|
||||
{
|
||||
time: '12小时',
|
||||
price: (hourPrice * 12).toFixed(2),
|
||||
unitPrice: hourPrice.toFixed(2),
|
||||
hour: 12
|
||||
}
|
||||
];
|
||||
} else if (this.deviceInfo.feeType === 'times') {
|
||||
// 按次收费
|
||||
const timesPrice = commonConfig.timesPrice;
|
||||
this.packages = [
|
||||
{
|
||||
time: '1次',
|
||||
price: timesPrice.toFixed(2),
|
||||
unitPrice: timesPrice.toFixed(2),
|
||||
hour: 1
|
||||
}
|
||||
];
|
||||
} else {
|
||||
// 默认套餐
|
||||
this.packages = [
|
||||
{
|
||||
time: '1小时',
|
||||
price: '2.00',
|
||||
unitPrice: '2.00',
|
||||
hour: 1
|
||||
},
|
||||
{
|
||||
time: '6小时',
|
||||
price: '10.00',
|
||||
unitPrice: '1.67',
|
||||
hour: 6
|
||||
},
|
||||
{
|
||||
time: '12小时',
|
||||
price: '15.00',
|
||||
unitPrice: '1.25',
|
||||
hour: 12
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 默认选中中间套餐
|
||||
this.selectedPackage = Math.min(1, this.packages.length - 1);
|
||||
} catch (e) {
|
||||
console.error('解析设备费用配置失败:', e);
|
||||
// 使用默认套餐
|
||||
this.packages = [
|
||||
{
|
||||
time: '1小时',
|
||||
price: '2.00',
|
||||
unitPrice: '2.00',
|
||||
hour: 1
|
||||
},
|
||||
{
|
||||
time: '6小时',
|
||||
price: '10.00',
|
||||
unitPrice: '1.67',
|
||||
hour: 6
|
||||
},
|
||||
{
|
||||
time: '12小时',
|
||||
price: '15.00',
|
||||
unitPrice: '1.25',
|
||||
hour: 12
|
||||
}
|
||||
];
|
||||
|
||||
// 默认选中中间套餐
|
||||
this.selectedPackage = 1;
|
||||
}
|
||||
} else {
|
||||
// 如果没有feeConfig,使用默认套餐
|
||||
this.packages = [
|
||||
{
|
||||
time: '1小时',
|
||||
price: '2.00',
|
||||
unitPrice: '2.00',
|
||||
hour: 1
|
||||
},
|
||||
{
|
||||
time: '6小时',
|
||||
price: '10.00',
|
||||
unitPrice: '1.67',
|
||||
hour: 6
|
||||
},
|
||||
{
|
||||
time: '12小时',
|
||||
price: '15.00',
|
||||
unitPrice: '1.25',
|
||||
hour: 12
|
||||
}
|
||||
];
|
||||
|
||||
// 默认选中中间套餐
|
||||
this.selectedPackage = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user