313
检查项目设置-》套餐设置:折扣字段换算错误
This commit is contained in:
@@ -546,6 +546,7 @@ function loadPackageData(data) {
|
|||||||
frequency: item.frequency || '',
|
frequency: item.frequency || '',
|
||||||
days: item.days || '',
|
days: item.days || '',
|
||||||
quantity: item.quantity || 1,
|
quantity: item.quantity || 1,
|
||||||
|
originalUnitPrice: item.originalUnitPrice || item.unitPrice || 0,
|
||||||
unitPrice: item.unitPrice || 0,
|
unitPrice: item.unitPrice || 0,
|
||||||
unit: item.unit || '',
|
unit: item.unit || '',
|
||||||
amount: item.amount || 0,
|
amount: item.amount || 0,
|
||||||
@@ -908,6 +909,7 @@ function handleAddRow() {
|
|||||||
days: '',
|
days: '',
|
||||||
quantity: 1,
|
quantity: 1,
|
||||||
unit: '',
|
unit: '',
|
||||||
|
originalUnitPrice: 0,
|
||||||
unitPrice: 0,
|
unitPrice: 0,
|
||||||
amount: 0,
|
amount: 0,
|
||||||
serviceCharge: 0,
|
serviceCharge: 0,
|
||||||
@@ -1058,7 +1060,7 @@ function handleItemSelect(row) {
|
|||||||
if (item) {
|
if (item) {
|
||||||
row.itemName = item.name || item.itemName || ''
|
row.itemName = item.name || item.itemName || ''
|
||||||
row.code = item.busNo || item.code || item.itemCode || ''
|
row.code = item.busNo || item.code || item.itemCode || ''
|
||||||
row.unitPrice = parseFloat(item.retailPrice || item.unitPrice || item.price || 0)
|
row.originalUnitPrice = parseFloat(item.retailPrice || item.unitPrice || item.price || 0)
|
||||||
// permittedUnitCode_dictText是字典翻译后的值,permittedUnitCode是后端返回的原始值
|
// permittedUnitCode_dictText是字典翻译后的值,permittedUnitCode是后端返回的原始值
|
||||||
row.unit = item.permittedUnitCode_dictText || item.permittedUnitCode || ''
|
row.unit = item.permittedUnitCode_dictText || item.permittedUnitCode || ''
|
||||||
|
|
||||||
@@ -1074,7 +1076,15 @@ function handleItemSelect(row) {
|
|||||||
|
|
||||||
// 计算金额
|
// 计算金额
|
||||||
function calculateAmount(row) {
|
function calculateAmount(row) {
|
||||||
row.amount = (row.quantity || 0) * (row.unitPrice || 0)
|
// 获取折扣比例,默认100%
|
||||||
|
const discountRate = formData.discount ? parseFloat(formData.discount) / 100 : 1;
|
||||||
|
|
||||||
|
// 单价 = 原项目单价 × 折扣比例
|
||||||
|
row.unitPrice = row.originalUnitPrice * discountRate;
|
||||||
|
|
||||||
|
// 金额 = 折扣单价 × 数量
|
||||||
|
row.amount = (row.quantity || 0) * row.unitPrice;
|
||||||
|
|
||||||
calculateTotal(row)
|
calculateTotal(row)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1097,20 +1107,11 @@ function calculateTotalServiceFee() {
|
|||||||
formData.serviceFee = totalServiceFee
|
formData.serviceFee = totalServiceFee
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算套餐金额(应用折扣)
|
// 计算套餐金额(套餐金额=套餐明细总金额字段的值之和)
|
||||||
function calculatePackagePrice() {
|
function calculatePackagePrice() {
|
||||||
// 计算所有明细项目的总金额
|
// 套餐金额 = 所有明细项目的总金额之和
|
||||||
const total = detailData.value.reduce((sum, item) => sum + (item.total || 0), 0)
|
const total = detailData.value.reduce((sum, item) => sum + (item.total || 0), 0)
|
||||||
|
formData.packagePrice = total
|
||||||
// 如果有折扣,应用折扣计算
|
|
||||||
let finalPrice = total
|
|
||||||
if (formData.discount && parseFloat(formData.discount) > 0 && parseFloat(formData.discount) <= 100) {
|
|
||||||
const discountRate = parseFloat(formData.discount) / 100 // 将百分比转换为小数(如 10% -> 0.1)
|
|
||||||
const discountAmount = total * discountRate // 折扣金额
|
|
||||||
finalPrice = total - discountAmount // 折扣后金额
|
|
||||||
}
|
|
||||||
|
|
||||||
formData.packagePrice = finalPrice
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 折扣变更处理
|
// 折扣变更处理
|
||||||
@@ -1134,8 +1135,10 @@ function handleDiscountChange(value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重新计算套餐金额
|
// 重新计算所有明细行
|
||||||
calculatePackagePrice()
|
detailData.value.forEach(row => {
|
||||||
|
calculateAmount(row)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 套餐管理
|
// 套餐管理
|
||||||
@@ -1251,6 +1254,7 @@ async function handleSave() {
|
|||||||
days: item.days || '',
|
days: item.days || '',
|
||||||
quantity: parseInt(item.quantity) || 1,
|
quantity: parseInt(item.quantity) || 1,
|
||||||
unit: item.unit || '',
|
unit: item.unit || '',
|
||||||
|
originalUnitPrice: parseFloat(item.originalUnitPrice) || 0,
|
||||||
unitPrice: parseFloat(item.unitPrice) || 0,
|
unitPrice: parseFloat(item.unitPrice) || 0,
|
||||||
amount: parseFloat(item.amount) || 0,
|
amount: parseFloat(item.amount) || 0,
|
||||||
serviceCharge: parseFloat(item.serviceCharge) || 0,
|
serviceCharge: parseFloat(item.serviceCharge) || 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user