Commit aa2f0c82 by liimin

fix(订单工具): 修复calcOrderProp函数中数值计算和默认值问题

安全地解构订单对象并提供默认值,避免undefined错误
优化价格计算逻辑,处理小数精度并明确类型转换
1 parent 43c69220
...@@ -150,11 +150,22 @@ export function getOrderDetailButtons(order) { ...@@ -150,11 +150,22 @@ export function getOrderDetailButtons(order) {
// return AFTER_SALE_STATUS[_status_] || {}; // return AFTER_SALE_STATUS[_status_] || {};
// } // }
export function calcOrderProp(order) { export function calcOrderProp(order = {}) {
const { applyQty, sellQty, redeemPoints, freightAmount = 0 } = order; // 安全地解构,提供默认值
const { applyQty = 0, sellQty = 0, redeemPoints = 0, freightAmount = 0 } = order;
const ___qty = sellQty || applyQty || 0; const ___qty = sellQty || applyQty || 0;
const ___price = (redeemPoints || 0) * ___qty;
const ___totalPrice = (redeemPoints || 0) * ___qty + +freightAmount; // 计算基础价格,避免重复计算
const basePrice = redeemPoints * ___qty;
// 计算价格,处理小数
let ___price = basePrice;
___price = Number.isInteger(___price) ? ___price : parseFloat(___price.toFixed(2));
// 计算总价,明确类型转换
let ___totalPrice = basePrice + Number(freightAmount);
___totalPrice = Number.isInteger(___totalPrice) ? ___totalPrice : parseFloat(___totalPrice.toFixed(2));
return { ___qty, ___price, ___totalPrice }; return { ___qty, ___price, ___totalPrice };
} }
export const APIS = { export const APIS = {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!