体重使用稳定值,移除金额校验

This commit is contained in:
zxj
2025-07-10 15:32:38 +08:00
parent b657821b23
commit d92702a657
8 changed files with 66 additions and 37 deletions
@@ -20,6 +20,7 @@ import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject
@@ -102,6 +103,12 @@ class ReceiptViewModel @Inject constructor(
_showReceiptDialog.value = showDialog
}
fun updateSelectedItemWithSwitch(purchaseOrder: GoodsInfo?) {
viewModelScope.launch {
updateSelectedItem(purchaseOrder)
}
}
/**
* 更新选中的item
*/
@@ -109,14 +116,16 @@ class ReceiptViewModel @Inject constructor(
if (purchaseOrder != null) {
purchaseOrder.receivedNum.takeIf { it != 0f }?.let { receivedNum ->
// 计算金额 单价不为空,并且金额没有手动输入
if (purchaseOrder.recUnitPriceTaxIn != null && purchaseOrder.recUnitPriceTaxIn == 0f && !_amountUserInput.value) {
// if (purchaseOrder.recUnitPriceTaxIn != null && purchaseOrder.recUnitPriceTaxIn == 0f && !_amountUserInput.value) {
if (purchaseOrder.recUnitPriceTaxIn != null && !_amountUserInput.value) {
val result =
receivedNum.times(purchaseOrder.recUnitPriceTaxIn!!)
purchaseOrder.recPriceExItem = result.toSafeFloat()
purchaseOrder.recPriceExItemTemp = result.toFormattedString()
}
// 计算单价 金额不为空,并且单价没有手动输入
if (purchaseOrder.recPriceExItem != null && purchaseOrder.recPriceExItem == 0f && !_priceUserInput.value) {
// if (purchaseOrder.recPriceExItem != null && purchaseOrder.recPriceExItem == 0f && !_priceUserInput.value) {
if (purchaseOrder.recPriceExItem != null && !_priceUserInput.value) {
val result =
purchaseOrder.recPriceExItem!!.div(receivedNum)
purchaseOrder.recUnitPriceTaxIn = result.toSafeFloat()
@@ -247,14 +256,22 @@ class ReceiptViewModel @Inject constructor(
// 计算单价
val finalPrice = if (count == 0.0) {
0f
} else if (info.recPriceExItem != null && info.recPriceExItem != 0f && !_countUserInput.value && !_priceUserInput.value) {
info.recPriceExItem!!.div(count).toSafeFloat()
} else if (!_countUserInput.value && !_priceUserInput.value) {
if (info.recPriceExItemTemp.isNotEmpty()) {
info.recPriceExItem!!.div(count).toSafeFloat()
} else {
0f
}
} else info.recUnitPriceTaxIn ?: 0f
// 计算金额
val finalAmount = if (count == 0.0) {
0f
} else if (info.recUnitPriceTaxIn != null && info.recUnitPriceTaxIn != 0f && !_countUserInput.value && !_amountUserInput.value) {
count.times(info.recUnitPriceTaxIn!!).toSafeFloat()
} else if (!_countUserInput.value && !_amountUserInput.value) {
if (info.recUnitPriceTaxInTemp.isNotEmpty()) {
count.times(info.recUnitPriceTaxIn!!).toSafeFloat()
} else {
0f
}
} else info.recPriceExItem ?: 0f
_selectedItem.value = info.copy(