修复了消耗值为空字符串时重量不显示的问题

修复了相机未初始化或已关闭时调用拍照报错问题
调整了未确认列表允许收货
调整了重量大于1kg时显示kg
This commit is contained in:
zxj
2025-08-22 14:51:43 +08:00
parent d7536e75af
commit 3cda898756
7 changed files with 43 additions and 14 deletions
@@ -90,7 +90,7 @@ data class PurchaseWarehouseParam(
if (goodsWeight == null) return ""
// 小于10 kg 显示 g
if (goodsWeight!!.toInt() < 10) {
if (goodsWeight!!.toInt() < 1) {
return goodsWeight!!.multiply(BigDecimal(1000)).toString()
}
return goodsWeight?.toFormattedString() ?: ""
@@ -98,7 +98,7 @@ data class PurchaseWarehouseParam(
val goodsWeightUnitStr: String
get() {
return if (goodsWeight == null || goodsWeight!!.toInt() < 10) {
return if (goodsWeight == null || goodsWeight!!.toInt() < 1) {
""
} else {
"千克"
@@ -118,6 +118,14 @@ data class GoodsInfo(
return receivedNum?.toSafeString(unitName) ?: "-"
}
val receivedNumCount: String
get() {
if (receivedNum == null || receivedNum == 0f)
return "0"
return receivedNum?.toSafeString(unitName) ?: "0"
}
val dualCountStr: String
get() {
return if (receivedNum != null && receivedNum != 0f && receiveCount != null && receiveCount != 0f) {
@@ -188,7 +196,7 @@ data class GoodsInfo(
if (goodsWeight == null) return ""
// 小于10 kg 显示 g
if (goodsWeight!!.toInt() < 10) {
if (goodsWeight!!.toInt() < 1) {
return goodsWeight!!.multiply(BigDecimal(1000)).toString()
}
return goodsWeight?.toFormattedString() ?: ""
@@ -196,7 +204,7 @@ data class GoodsInfo(
val goodsWeightUnitStr: String
get() {
return if (goodsWeight == null || goodsWeight!!.toInt() < 10) {
return if (goodsWeight == null || goodsWeight!!.toInt() < 1) {
""
} else {
"千克"
@@ -94,7 +94,7 @@ fun ReceiptProductScreen(
LaunchedEffect(receiptResult) {
if (receiptResult) {
ToastUtils.showToast("收货成功")
// ToastUtils.showToast("收货成功")
controller.popBackStack()
}
}
@@ -22,6 +22,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.core.content.ContextCompat
import androidx.lifecycle.compose.LocalLifecycleOwner
import com.sw.inbound.ext.medium
import com.sw.inbound.model.request.PurchaseWarehouseParam
@@ -75,6 +76,7 @@ fun IdentityView(
searchList
}
val debouncer = remember { Debouncer(2000) }
var isCameraReady by remember { mutableStateOf(false) }
// CameraX 控制器
val cameraController = remember {
@@ -113,7 +115,10 @@ fun IdentityView(
// 绑定生命周期
DisposableEffect(lifecycleOwner) {
cameraController.bindToLifecycle(lifecycleOwner)
onDispose { /* 清理资源 */ }
onDispose {
cameraController.unbind()
isCameraReady = false
}
}
LaunchedEffect(weightInfo) {
@@ -132,13 +137,28 @@ fun IdentityView(
Timber.d("LaunchedEffect canIdentity = $canIdentity")
if (canIdentity) {
debouncer.debounce {
takePhoto()
Timber.d("LaunchedEffect isCameraReady = $isCameraReady")
if (isCameraReady) {
takePhoto()
}
}
}
}
lastWeight = weightInfo
}
// 监听相机初始化
LaunchedEffect(Unit) {
try {
cameraController.initializationFuture.addListener({
isCameraReady = true
Timber.d("Camera initialized successfully")
}, ContextCompat.getMainExecutor(context))
} catch (e: Exception) {
Timber.d("Camera initialized error = ${e.message}")
}
}
Column(
modifier = Modifier
.fillMaxSize(),
@@ -154,7 +154,7 @@ fun ReceiptTipDialog(
Spacer(modifier = Modifier.width(10.dp))
CustomSingleRightText(
modifier = Modifier.weight(1f),
text = "${goods.receivedNumListStr}${goods.unitNameStr}",
text = "${goods.receivedNumCount}${goods.unitNameStr}",
style = AppTypography.blackMediumTextStyle.withColor(
Color.Red
),
@@ -3,6 +3,7 @@ package com.sw.inbound.viewmodel
import androidx.lifecycle.viewModelScope
import com.sw.inbound.ext.toFormattedString
import com.sw.inbound.ext.toSafeBigDecimal
import com.sw.inbound.ext.toSafeDouble
import com.sw.inbound.ext.toSafeFloat
import com.sw.inbound.model.request.UploadInfo
import com.sw.inbound.model.response.DictType
@@ -91,10 +92,10 @@ class ReceiptViewModel @Inject constructor(
ToastUtils.showToast("订单为空或包含异常数据")
return
}
if (!unadjustedOrders.value.isEmpty()) {
ToastUtils.showToast("请先确认物品信息")
return
}
// if (!unadjustedOrders.value.isEmpty()) {
// ToastUtils.showToast("请先确认物品信息")
// return
// }
_showReceiptDialog.value = showDialog
}
@@ -253,7 +254,7 @@ class ReceiptViewModel @Inject constructor(
)
return
}
var consumeValue = currentItem.consumeValue?.toDouble() ?: 1.0
var consumeValue = currentItem.consumeValue?.toSafeDouble() ?: 1.0
var purchaseValue = currentItem.purchaseValue?.toDouble() ?: 1.0
if (consumeValue == 0.0) {
consumeValue = 1.0
@@ -114,7 +114,7 @@ class SelfProcurementViewModel @Inject constructor(
// val selectUnitType = currentItem.selectUnitType
// if (selectUnitType == null) return@startScale
var consumeValue = selectUnitType.consumeValue?.toDouble() ?: 1.0
var consumeValue = selectUnitType.consumeValue?.toSafeDouble() ?: 1.0
var purchaseValue = selectUnitType.purchaseValue?.toDouble() ?: 1.0
if (consumeValue == 0.0) {
consumeValue = 1.0