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

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
+11 -7
View File
@@ -153,20 +153,24 @@
try { try {
const feeConfig = JSON.parse(this.deviceInfo.feeConfig); const feeConfig = JSON.parse(this.deviceInfo.feeConfig);
// 检查是否为新格式 [{"Hour":1,"Price":4},{"Hour":3,"Price":10},{"Hour":5,"Price":15}] // 检查是否为新格式 [{"hour":1,"timesPrice":4},{"hour":3,"timesPrice":10},{"hour":5,"timesPrice":15}]
if (feeConfig.length > 0 && 'Hour' in feeConfig[0] && 'Price' in feeConfig[0]) { if (feeConfig.length > 0 && 'hour' in feeConfig[0] && 'timesPrice' in feeConfig[0]) {
// 新格式处理 // 新格式处理 - 直接使用所有套餐
this.packages = feeConfig.map(pkg => { this.packages = feeConfig.map(pkg => {
const hour = pkg.Hour; const hour = pkg.hour;
const price = pkg.Price; const price = pkg.timesPrice;
const unitPrice = (price / hour).toFixed(2); const unitPrice = (price / hour).toFixed(2);
return { return {
time: `${hour}${hour > 1 ? '小时' : '小时'}`, time: `${hour}小时`,
price: price.toFixed(2), price: price.toFixed(2),
unitPrice: unitPrice unitPrice: unitPrice,
hour: hour // 添加小时信息,用于后续处理
}; };
}); });
// 按小时排序
this.packages.sort((a, b) => a.hour - b.hour);
} else { } else {
// 旧格式处理 // 旧格式处理
// 通常使用common规格的配置 // 通常使用common规格的配置
+13 -2
View File
@@ -189,8 +189,19 @@ export default {
try { try {
const feeConfig = JSON.parse(this.deviceInfo.feeConfig); const feeConfig = JSON.parse(this.deviceInfo.feeConfig);
// 检查是否为新格式 [{"Hour":1,"Price":4},{"Hour":3,"Price":10},{"Hour":5,"Price":15}] // 检查是否为新格式 [{"hour":1,"timesPrice":4},{"hour":3,"timesPrice":10},{"hour":5,"timesPrice":15}]
if (feeConfig.length > 0 && 'Hour' in feeConfig[0] && 'Price' in feeConfig[0]) { 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小时或最接近的套餐 // 默认使用6小时或最接近的套餐
const targetHours = 6; const targetHours = 6;
@@ -1 +1 @@
{"version":3,"file":"detail.js","sources":["E:/迅雷下载/HBuilderX.4.57.2025032507/HBuilderX/plugins/uniapp-cli-vite/uniPage:/cGFnZXMvZGV2aWNlL2RldGFpbC52dWU"],"sourcesContent":["import MiniProgramPage from 'C:/Users/Administrator.DESKTOP-IRCM9I0/Desktop/locker-fans/locker-fans/uni-fans/pages/device/detail.vue'\nwx.createPage(MiniProgramPage)"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,GAAG,WAAW,eAAe;"} {"version":3,"file":"detail.js","sources":["E:/迅雷下载/HBuilderX.4.57.2025032507/HBuilderX/plugins/uniapp-cli-vite/uniPage:/cGFnZXMvZGV2aWNlL2RldGFpbC52dWU"],"sourcesContent":["import MiniProgramPage from 'C:/Users/Administrator.DESKTOP-IRCM9I0/Desktop/locker-fans/locker-fans/uni-fans/pages/device/detail.vue'\nwx.createPage(MiniProgramPage)"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,GAAG,WAAW,eAAe;"}
@@ -1 +1 @@
{"version":3,"file":"payment.js","sources":["E:/迅雷下载/HBuilderX.4.57.2025032507/HBuilderX/plugins/uniapp-cli-vite/uniPage:/cGFnZXMvb3JkZXIvcGF5bWVudC52dWU"],"sourcesContent":["import MiniProgramPage from 'C:/Users/Administrator.DESKTOP-IRCM9I0/Desktop/locker-fans/locker-fans/uni-fans/pages/order/payment.vue'\nwx.createPage(MiniProgramPage)"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,GAAG,WAAW,eAAe;"} {"version":3,"file":"payment.js","sources":["E:/迅雷下载/HBuilderX.4.57.2025032507/HBuilderX/plugins/uniapp-cli-vite/uniPage:/cGFnZXMvb3JkZXIvcGF5bWVudC52dWU"],"sourcesContent":["import MiniProgramPage from 'C:/Users/Administrator.DESKTOP-IRCM9I0/Desktop/locker-fans/locker-fans/uni-fans/pages/order/payment.vue'\nwx.createPage(MiniProgramPage)"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,GAAG,WAAW,eAAe;"}
+12 -9
View File
@@ -57,17 +57,20 @@ const _sfc_main = {
if (this.deviceInfo.feeConfig) { if (this.deviceInfo.feeConfig) {
try { try {
const feeConfig = JSON.parse(this.deviceInfo.feeConfig); const feeConfig = JSON.parse(this.deviceInfo.feeConfig);
if (feeConfig.length > 0 && "Hour" in feeConfig[0] && "Price" in feeConfig[0]) { if (feeConfig.length > 0 && "hour" in feeConfig[0] && "timesPrice" in feeConfig[0]) {
this.packages = feeConfig.map((pkg) => { this.packages = feeConfig.map((pkg) => {
const hour = pkg.Hour; const hour = pkg.hour;
const price = pkg.Price; const price = pkg.timesPrice;
const unitPrice = (price / hour).toFixed(2); const unitPrice = (price / hour).toFixed(2);
return { return {
time: `${hour}${hour > 1 ? "小时" : "小时"}`, time: `${hour}小时`,
price: price.toFixed(2), price: price.toFixed(2),
unitPrice unitPrice,
hour
// 添加小时信息,用于后续处理
}; };
}); });
this.packages.sort((a, b) => a.hour - b.hour);
} else { } else {
const commonConfig = feeConfig.find((item) => item.specCode === "common") || feeConfig[0]; const commonConfig = feeConfig.find((item) => item.specCode === "common") || feeConfig[0];
if (commonConfig) { if (commonConfig) {
@@ -122,7 +125,7 @@ const _sfc_main = {
} }
this.selectedPackage = Math.min(1, this.packages.length - 1); this.selectedPackage = Math.min(1, this.packages.length - 1);
} catch (e) { } catch (e) {
common_vendor.index.__f__("error", "at pages/device/detail.vue:234", "解析设备费用配置失败:", e); common_vendor.index.__f__("error", "at pages/device/detail.vue:238", "解析设备费用配置失败:", e);
this.packages = [ this.packages = [
{ {
time: "1小时", time: "1小时",
@@ -261,12 +264,12 @@ const _sfc_main = {
packagePrice: parseFloat(selectedPkg.price) packagePrice: parseFloat(selectedPkg.price)
}); });
if (updateRes.code !== 200) { if (updateRes.code !== 200) {
common_vendor.index.__f__("warn", "at pages/device/detail.vue:402", "更新订单套餐信息失败:", updateRes.msg); common_vendor.index.__f__("warn", "at pages/device/detail.vue:406", "更新订单套餐信息失败:", updateRes.msg);
} else { } else {
common_vendor.index.__f__("log", "at pages/device/detail.vue:405", "订单套餐信息已提前更新"); common_vendor.index.__f__("log", "at pages/device/detail.vue:409", "订单套餐信息已提前更新");
} }
} catch (updateError) { } catch (updateError) {
common_vendor.index.__f__("error", "at pages/device/detail.vue:408", "更新订单套餐信息时出错:", updateError); common_vendor.index.__f__("error", "at pages/device/detail.vue:412", "更新订单套餐信息时出错:", updateError);
} }
const deposit = parseFloat(this.depositAmount); const deposit = parseFloat(this.depositAmount);
const packagePrice = parseFloat(selectedPkg.price); const packagePrice = parseFloat(selectedPkg.price);
+12 -6
View File
@@ -107,7 +107,13 @@ const _sfc_main = {
if (this.deviceInfo && this.deviceInfo.feeConfig) { if (this.deviceInfo && this.deviceInfo.feeConfig) {
try { try {
const feeConfig = JSON.parse(this.deviceInfo.feeConfig); const feeConfig = JSON.parse(this.deviceInfo.feeConfig);
if (feeConfig.length > 0 && "Hour" in feeConfig[0] && "Price" in feeConfig[0]) { 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();
} else if (feeConfig.length > 0 && "Hour" in feeConfig[0] && "Price" in feeConfig[0]) {
const targetHours = 6; const targetHours = 6;
let closestPackage = feeConfig[0]; let closestPackage = feeConfig[0];
feeConfig.forEach((pkg) => { feeConfig.forEach((pkg) => {
@@ -138,7 +144,7 @@ const _sfc_main = {
} }
} }
} catch (e) { } catch (e) {
common_vendor.index.__f__("error", "at pages/order/payment.vue:241", "解析设备费用配置失败:", e); common_vendor.index.__f__("error", "at pages/order/payment.vue:252", "解析设备费用配置失败:", e);
} }
} }
if (this.deviceInfo && this.deviceInfo.depositAmount) { if (this.deviceInfo && this.deviceInfo.depositAmount) {
@@ -146,7 +152,7 @@ const _sfc_main = {
} }
} }
} catch (error) { } catch (error) {
common_vendor.index.__f__("error", "at pages/order/payment.vue:251", "获取设备信息失败:", error); common_vendor.index.__f__("error", "at pages/order/payment.vue:262", "获取设备信息失败:", error);
} }
}, },
// 处理支付 // 处理支付
@@ -175,7 +181,7 @@ const _sfc_main = {
try { try {
await config_user.updateUserBalance(this.orderId); await config_user.updateUserBalance(this.orderId);
} catch (error) { } catch (error) {
common_vendor.index.__f__("warn", "at pages/order/payment.vue:288", "更新用户余额失败:", error); common_vendor.index.__f__("warn", "at pages/order/payment.vue:299", "更新用户余额失败:", error);
} }
setTimeout(() => { setTimeout(() => {
common_vendor.index.redirectTo({ common_vendor.index.redirectTo({
@@ -184,7 +190,7 @@ const _sfc_main = {
}, 1500); }, 1500);
}, },
fail: (err) => { fail: (err) => {
common_vendor.index.__f__("error", "at pages/order/payment.vue:299", "支付失败:", err); common_vendor.index.__f__("error", "at pages/order/payment.vue:310", "支付失败:", err);
throw new Error("支付失败,请重试"); throw new Error("支付失败,请重试");
} }
}); });
@@ -281,7 +287,7 @@ const _sfc_main = {
throw new Error("查询订单状态失败"); throw new Error("查询订单状态失败");
} }
} catch (error) { } catch (error) {
common_vendor.index.__f__("error", "at pages/order/payment.vue:407", "查询订单状态错误:", error); common_vendor.index.__f__("error", "at pages/order/payment.vue:418", "查询订单状态错误:", error);
return null; return null;
} }
} }