优化设备费用配置解析逻辑,支持新旧格式的费用配置处理。更新了套餐选择逻辑,默认选择中等时长套餐,并添加小时信息以便后续处理。

This commit is contained in:
8vd8
2025-04-22 18:10:22 +08:00
parent d9e70d4eaf
commit 9e10ea7f30
6 changed files with 50 additions and 26 deletions
+13 -2
View File
@@ -189,8 +189,19 @@ export default {
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]) {
// 检查是否为新格式 [{"hour":1,"timesPrice":4},{"hour":3,"timesPrice":10},{"hour":5,"timesPrice":15}]
if (feeConfig.length > 0 && 'hour' in feeConfig[0] && 'timesPrice' in feeConfig[0]) {
// 尝试找到对应包时长的套餐
// 默认使用中等时长的套餐
const allPackages = feeConfig.sort((a, b) => a.hour - b.hour);
const middleIndex = Math.floor(allPackages.length / 2);
const selectedPackage = allPackages[middleIndex];
this.packageInfo.time = selectedPackage.hour.toString();
this.packageInfo.price = selectedPackage.timesPrice.toString();
}
// 检查旧的大写格式 [{"Hour":1,"Price":4}]
else if (feeConfig.length > 0 && 'Hour' in feeConfig[0] && 'Price' in feeConfig[0]) {
// 尝试找到对应包时长的套餐
// 默认使用6小时或最接近的套餐
const targetHours = 6;