diff --git a/app/src/main/java/com/sw/inbound/ext/CommonExt.kt b/app/src/main/java/com/sw/inbound/ext/CommonExt.kt index e389a1c..02a7f2f 100644 --- a/app/src/main/java/com/sw/inbound/ext/CommonExt.kt +++ b/app/src/main/java/com/sw/inbound/ext/CommonExt.kt @@ -87,7 +87,7 @@ fun Float?.toSafeFloat(decimalPlaces: Int = 2): Float { */ private fun getDecimalPlaces(unitName: String?): Int { val decimalPlaces = when (unitName) { - "斤", "克", "公斤", "升" -> 2 + "斤", "公斤", "升" -> 2 else -> 0 } return decimalPlaces diff --git a/app/src/main/java/com/sw/inbound/model/response/GoodsInfo.kt b/app/src/main/java/com/sw/inbound/model/response/GoodsInfo.kt index 184f234..de6d100 100644 --- a/app/src/main/java/com/sw/inbound/model/response/GoodsInfo.kt +++ b/app/src/main/java/com/sw/inbound/model/response/GoodsInfo.kt @@ -3,6 +3,7 @@ package com.sw.inbound.model.response import android.os.Parcelable import com.sw.inbound.GlobalData import com.sw.inbound.ext.toFormattedString +import com.sw.inbound.ext.toSafeString import com.sw.inbound.model.response.SearchGoodsInfo.Record.UnitVo import kotlinx.parcelize.Parcelize import java.math.BigDecimal @@ -118,15 +119,11 @@ data class GoodsInfo( return recUnitPriceTaxIn?.toFormattedString() ?: "" } - var receiveCountStr: String - set(value) { -// receiveCount = value.toSafeFloat() - receiveCountStr = value - } + val receiveCountStr: String get() { return when (receiveCount) { 0f -> "" - else -> receiveCount?.toFormattedString() ?: "" + else -> receiveCount?.toSafeString(unitName) ?: "" } } diff --git a/app/src/main/java/com/sw/inbound/sdk/SensorScaleUtils.kt b/app/src/main/java/com/sw/inbound/sdk/SensorScaleUtils.kt index bfa16d1..316c395 100644 --- a/app/src/main/java/com/sw/inbound/sdk/SensorScaleUtils.kt +++ b/app/src/main/java/com/sw/inbound/sdk/SensorScaleUtils.kt @@ -33,7 +33,10 @@ object SensorScaleUtils { else -> "未知" } // Timber.d("readWeight state = ${stateStr}, weight = $value") - callback?.invoke(value) + // 只使用稳定值 + if (state == SensorScale.STATE_STABLE) { + callback?.invoke(value) + } } /** @@ -66,7 +69,7 @@ object SensorScaleUtils { if (open) { if (autoScale) { ThreadUtils.launchOnIo { - delay(2000) + delay(1000) // 打开后需要等待后才能调用,否则会 1001 SDK未初始化 mSensorScale?.startContinuousRead() } diff --git a/app/src/main/java/com/sw/inbound/ui/page/ReceiptProductScreen.kt b/app/src/main/java/com/sw/inbound/ui/page/ReceiptProductScreen.kt index 7a03a7d..adf18a8 100644 --- a/app/src/main/java/com/sw/inbound/ui/page/ReceiptProductScreen.kt +++ b/app/src/main/java/com/sw/inbound/ui/page/ReceiptProductScreen.kt @@ -283,7 +283,7 @@ fun UnadjustedView(purchaseOrderList: List, viewModel: ReceiptViewMod productList = purchaseOrderList, checkedItem = checkedItem, onItemCheckedClick = { - viewModel.updateSelectedItem(it) + viewModel.updateSelectedItemWithSwitch(it) }) } @@ -638,11 +638,12 @@ private fun ReceiptProductEditView( } val expectAmount = selectedItem!!.receivedNum!!.times(selectedItem!!.recUnitPriceTaxIn!!) + .toSafeFloat() Timber.d("金额判断:期望金额 = $expectAmount, 实际金额 = ${selectedItem!!.recPriceExItem}") - if (expectAmount != selectedItem!!.recPriceExItem) { - ToastUtils.showToast("数量和金额不符,请检查后再试") - return@clickable - } +// if (expectAmount != selectedItem!!.recPriceExItem) { +// ToastUtils.showToast("数量和金额不符,请检查后再试") +// return@clickable +// } viewModel.updatePurchaseItem(purchaseOrder = selectedItem!!.copy(isAdjusted = true)) viewModel.updateSelectedItem(null) }, painter = painterResource(R.mipmap.ic_btn_confirm), contentDescription = "确定") diff --git a/app/src/main/java/com/sw/inbound/ui/page/SelfProcurementScreen.kt b/app/src/main/java/com/sw/inbound/ui/page/SelfProcurementScreen.kt index 651ea02..771a4fb 100644 --- a/app/src/main/java/com/sw/inbound/ui/page/SelfProcurementScreen.kt +++ b/app/src/main/java/com/sw/inbound/ui/page/SelfProcurementScreen.kt @@ -776,12 +776,13 @@ private fun SelfProductEditView( ToastUtils.showToast(errInfo) return@CustomButton } - val expectAmount = selectedItem!!.goodsCount * selectedItem!!.goodsUnitPrice + val expectAmount = + (selectedItem!!.goodsCount.times(selectedItem!!.goodsUnitPrice)).toSafeDouble() Timber.d("金额判断:期望金额 = $expectAmount, 实际金额 = ${selectedItem!!.goodsPrice}") - if (expectAmount != selectedItem!!.goodsPrice) { - ToastUtils.showToast("数量和金额不符,请检查后再试") - return@CustomButton - } +// if (expectAmount != selectedItem!!.goodsPrice) { +// ToastUtils.showToast("数量和金额不符,请检查后再试") +// return@CustomButton +// } viewModel.addPurchaseItem(selectedItem!!) }) } diff --git a/app/src/main/java/com/sw/inbound/ui/weight/ReceiptUnadjustedListView.kt b/app/src/main/java/com/sw/inbound/ui/weight/ReceiptUnadjustedListView.kt index 9a7a716..11f4ad6 100644 --- a/app/src/main/java/com/sw/inbound/ui/weight/ReceiptUnadjustedListView.kt +++ b/app/src/main/java/com/sw/inbound/ui/weight/ReceiptUnadjustedListView.kt @@ -57,19 +57,19 @@ fun ReceiptUnadjustedListView( ) Spacer(modifier = Modifier.width(10.dp)) CustomSingleRightText( - modifier = Modifier.width(100.dp), + modifier = Modifier.width(120.dp), text = "单价(元)", style = AppTypography.gray96a0aaTextStyle.bold() ) Spacer(modifier = Modifier.width(20.dp)) CustomSingleRightText( - modifier = Modifier.width(100.dp), + modifier = Modifier.width(140.dp), text = "数量", style = AppTypography.gray96a0aaTextStyle.bold() ) Spacer(modifier = Modifier.width(20.dp)) CustomSingleRightText( - modifier = Modifier.width(110.dp), + modifier = Modifier.width(120.dp), text = "金额(元)", style = AppTypography.gray96a0aaTextStyle.bold() ) @@ -101,19 +101,19 @@ fun ReceiptUnadjustedListView( ) Spacer(modifier = Modifier.width(10.dp)) CustomSingleRightText( - modifier = Modifier.width(100.dp), + modifier = Modifier.width(120.dp), text = it.recUnitPriceTaxInStr, style = AppTypography.blackTextStyle ) Spacer(modifier = Modifier.width(20.dp)) CustomSingleRightText( - modifier = Modifier.width(100.dp), + modifier = Modifier.width(140.dp), text = "${it.receiveCountStr}${it.unitNameStr}", style = AppTypography.blackTextStyle ) Spacer(modifier = Modifier.width(20.dp)) CustomSingleRightText( - modifier = Modifier.width(110.dp), + modifier = Modifier.width(120.dp), text = it.recPriceExItemStr, style = AppTypography.blackTextStyle ) diff --git a/app/src/main/java/com/sw/inbound/viewmodel/ReceiptViewModel.kt b/app/src/main/java/com/sw/inbound/viewmodel/ReceiptViewModel.kt index 940645a..89d2309 100644 --- a/app/src/main/java/com/sw/inbound/viewmodel/ReceiptViewModel.kt +++ b/app/src/main/java/com/sw/inbound/viewmodel/ReceiptViewModel.kt @@ -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( diff --git a/app/src/main/java/com/sw/inbound/viewmodel/SelfProcurementViewModel.kt b/app/src/main/java/com/sw/inbound/viewmodel/SelfProcurementViewModel.kt index a4e8355..e16800f 100644 --- a/app/src/main/java/com/sw/inbound/viewmodel/SelfProcurementViewModel.kt +++ b/app/src/main/java/com/sw/inbound/viewmodel/SelfProcurementViewModel.kt @@ -113,16 +113,24 @@ class SelfProcurementViewModel @Inject constructor( val finalPrice = if (count == 0.0) { 0.0 - } else if (info.goodsPrice != 0.0 && !_countUserInput.value && !_priceUserInput.value) { - info.goodsPrice.div(count).toSafeDouble() + } else if (!_countUserInput.value && !_priceUserInput.value) { + if (info.goodsPriceTemp.isNotEmpty()) { + info.goodsPrice.div(count).toSafeDouble() + } else { + 0.0 + } } else info.goodsUnitPrice // 计算金额 单价不为空,不是数量输入 也不是金额输入 val finalAmount = if (count == 0.0) { 0.0 - } else if (info.goodsUnitPrice != 0.0 && !_countUserInput.value && !_amountUserInput.value) { - count.times(info.goodsUnitPrice).toSafeDouble() + } else if (!_countUserInput.value && !_amountUserInput.value) { + if (info.goodsUnitPriceTemp.isNotEmpty()) { + count.times(info.goodsUnitPrice).toSafeDouble() + } else { + 0.0 + } } else info.goodsPrice Timber.d("startSensorScale finalPrice = $finalPrice, finalAmount = $finalAmount ") _selectedItem.value = info.copy( @@ -154,7 +162,8 @@ class SelfProcurementViewModel @Inject constructor( if (purchaseOrder != null) { purchaseOrder.goodsCount.takeIf { it != 0.0 }?.let { receivedNum -> // 计算金额 单价不为空,并且金额没有手动输入 - if (purchaseOrder.goodsUnitPrice != 0.0 && !_amountUserInput.value) { +// if (purchaseOrder.goodsUnitPrice == 0.0 && !_amountUserInput.value) { + if (!_amountUserInput.value) { Timber.d("updateSelectedItem 计算金额") val result = receivedNum.times(purchaseOrder.goodsUnitPrice) @@ -162,7 +171,8 @@ class SelfProcurementViewModel @Inject constructor( purchaseOrder.goodsPriceTemp = result.toFormattedString() } // 计算单价 金额不为空,并且单价没有手动输入 - if (purchaseOrder.goodsPrice != 0.0 && !_priceUserInput.value) { +// if (purchaseOrder.goodsPrice == 0.0 && !_priceUserInput.value) { + if (!_priceUserInput.value) { Timber.d("updateSelectedItem 计算单价") val result = purchaseOrder.goodsPrice.div(receivedNum)