Commit d48e5574 authored by GuanHua's avatar GuanHua

fix: 进货单购买数量不在价格范围内时取值问题

parent e3a9a36e
......@@ -201,8 +201,8 @@
color: #FFF;
height: 50px;
font-size: 16px;
background-color: #D32F2F;
border-color: #D32F2F;
background-color: var(--mall_main_color);
border-color: var(--mall_main_color);
border-radius: 0;
outline: none;
cursor: pointer;
......@@ -264,4 +264,4 @@
}
}
}
}
\ No newline at end of file
}
......@@ -309,7 +309,7 @@ const PurchaseOrder: React.FC<PurchaseOrderPropsType> = (props) => {
}
}
if (isEmpty(priceItem)) {
priceItem = getMaxCountRange(priceRange)
priceItem = getMaxCountRange(priceRange, count)
}
return parseFloat(priceItem.price) * count
}
......@@ -663,7 +663,7 @@ const PurchaseOrder: React.FC<PurchaseOrderPropsType> = (props) => {
return Number(count) >= Number(item.min) && Number(count) <= Number(item.max)
})
if (isEmpty(temp)) {
const maxItem = getMaxCountRange(detail.priceRange)
const maxItem = getMaxCountRange(detail.priceRange, count)
unitPrice = maxItem.price
} else {
unitPrice = temp[0]?.price
......@@ -673,14 +673,12 @@ const PurchaseOrder: React.FC<PurchaseOrderPropsType> = (props) => {
return unitPrice
}
const getMaxCountRange = (priceRange) => {
let maxItem: any = {}
for (const item of priceRange) {
if (Number(item.max) > Number(maxItem.max || 0)) {
maxItem = item
}
}
return maxItem
const getMaxCountRange = (priceRange, buyCount) => {
const priceList = [...priceRange]
const result = priceList.sort((a, b) => (Number(b.max) < Number(buyCount) && Number(buyCount) < Number(a.min) ? 1 : -1))
// const result = priceList.sort((a, b) => Math.abs(Number(b.max) - Number(buyCount)) < Math.abs(Number(a.min) - Number(buyCount)) ? 1 : -1 )
return result[0]
}
const getDetailLink = (info) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment