修复了部分问题

This commit is contained in:
zxj
2025-07-22 17:27:27 +08:00
parent 4c6fa31787
commit a2405a0992
8 changed files with 69 additions and 35 deletions
@@ -51,12 +51,12 @@ class ReceiptViewModel @Inject constructor(
// 已调整列表
val adjustedOrders: StateFlow<List<GoodsInfo>> = _orders
.map { orders -> orders.filter { it.isAdjusted && it.goodId != null } }
.map { orders -> orders.filter { it.isAdjusted } }
.stateIn(viewModelScope, SharingStarted.Lazily, emptyList())
// 未调整列表
val unadjustedOrders: StateFlow<List<GoodsInfo>> = _orders
.map { orders -> orders.filter { !it.isAdjusted && it.goodId != null } }
.map { orders -> orders.filter { !it.isAdjusted } }
.stateIn(viewModelScope, SharingStarted.Lazily, emptyList())
// 选中的商品
@@ -115,24 +115,24 @@ class ReceiptViewModel @Inject constructor(
fun updateSelectedItem(purchaseOrder: GoodsInfo?) {
if (purchaseOrder != null) {
if (purchaseOrder.receivedNum != null && purchaseOrder.receivedNum != 0f) {
if (purchaseOrder.recUnitPriceTaxInTemp.isNotEmpty()) { // 计算金额 单价不为空,并且金额没有手动输入
if (purchaseOrder.newRecUnitPriceTaxInTemp.isNotEmpty()) { // 计算金额 单价不为空,并且金额没有手动输入
val result =
purchaseOrder.receivedNum!!.times(purchaseOrder.recUnitPriceTaxIn!!)
purchaseOrder.receivedNum!!.times(purchaseOrder.newRecUnitPriceTaxIn!!)
purchaseOrder.recPriceExItem = result.toSafeFloat()
purchaseOrder.recPriceExItemTemp = result.toFormattedString()
} else if (purchaseOrder.recPriceExItemTemp.isNotEmpty()) { // 计算单价 金额不为空,并且单价没有手动输入
val result =
purchaseOrder.recPriceExItem!!.div(purchaseOrder.receivedNum!!)
purchaseOrder.recUnitPriceTaxIn = result.toSafeFloat()
purchaseOrder.recUnitPriceTaxInTemp = result.toFormattedString()
purchaseOrder.newRecUnitPriceTaxIn = result.toSafeFloat()
purchaseOrder.newRecUnitPriceTaxInTemp = result.toFormattedString()
}
} else {
if (_priceUserInput.value) {
purchaseOrder.recPriceExItem = 0f
purchaseOrder.recPriceExItemTemp = ""
} else if (_amountUserInput.value) {
purchaseOrder.recUnitPriceTaxIn = 0f
purchaseOrder.recUnitPriceTaxInTemp = ""
purchaseOrder.newRecUnitPriceTaxIn = 0f
purchaseOrder.newRecUnitPriceTaxInTemp = ""
}
}
} else {
@@ -176,7 +176,7 @@ class ReceiptViewModel @Inject constructor(
fun updatePurchaseItem(purchaseOrder: GoodsInfo) {
_orders.update { currentList ->
currentList.map { order ->
if (order.goodId == purchaseOrder.goodId) purchaseOrder else order
if (order.id == purchaseOrder.id) purchaseOrder else order
}
}
}
@@ -250,8 +250,14 @@ class ReceiptViewModel @Inject constructor(
)
return@startScale
}
val consumeValue = currentItem.consumeValue?.toDouble() ?: 1.0
val purchaseValue = currentItem.purchaseValue?.toDouble() ?: 1.0
var consumeValue = currentItem.consumeValue?.toDouble() ?: 1.0
var purchaseValue = currentItem.purchaseValue?.toDouble() ?: 1.0
if (consumeValue == 0.0) {
consumeValue = 1.0
}
if (purchaseValue == 0.0) {
purchaseValue = 1.0
}
val count =
weight * 1000 / consumeValue / purchaseValue
val finalCount = count.toSafeFloat(currentItem.unitName)
@@ -275,7 +281,7 @@ class ReceiptViewModel @Inject constructor(
}
_priceUserInput.value && !_amountUserInput.value -> {
finalCount.times(info.recUnitPriceTaxIn!!).toSafeFloat()
finalCount.times(info.newRecUnitPriceTaxIn!!).toSafeFloat()
}
else -> 0f
@@ -287,8 +293,8 @@ class ReceiptViewModel @Inject constructor(
receivedNumTemp = finalCount.toFormattedString(),
receivedNum = finalCount,
// 单价
recUnitPriceTaxIn = if (_priceUserInput.value) info.recUnitPriceTaxIn else finalPrice,
recUnitPriceTaxInTemp = if (_priceUserInput.value) info.recUnitPriceTaxInTemp else finalPrice.toFormattedString(),
newRecUnitPriceTaxIn = if (_priceUserInput.value) info.newRecUnitPriceTaxIn else finalPrice,
newRecUnitPriceTaxInTemp = if (_priceUserInput.value) info.newRecUnitPriceTaxInTemp else finalPrice.toFormattedString(),
// 金额
recPriceExItem = if (_amountUserInput.value) info.recPriceExItem else finalAmount,
recPriceExItemTemp = if (_amountUserInput.value) info.recPriceExItemTemp else finalAmount.toFormattedString(),