From 3cda8987566b47dc236b2ab42ad31bcdf55c6d22 Mon Sep 17 00:00:00 2001 From: zxj <275873859@qq.com> Date: Fri, 22 Aug 2025 14:51:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E6=B6=88=E8=80=97?= =?UTF-8?q?=E5=80=BC=E4=B8=BA=E7=A9=BA=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=97=B6?= =?UTF-8?q?=E9=87=8D=E9=87=8F=E4=B8=8D=E6=98=BE=E7=A4=BA=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20=E4=BF=AE=E5=A4=8D=E4=BA=86=E7=9B=B8=E6=9C=BA?= =?UTF-8?q?=E6=9C=AA=E5=88=9D=E5=A7=8B=E5=8C=96=E6=88=96=E5=B7=B2=E5=85=B3?= =?UTF-8?q?=E9=97=AD=E6=97=B6=E8=B0=83=E7=94=A8=E6=8B=8D=E7=85=A7=E6=8A=A5?= =?UTF-8?q?=E9=94=99=E9=97=AE=E9=A2=98=20=E8=B0=83=E6=95=B4=E4=BA=86?= =?UTF-8?q?=E6=9C=AA=E7=A1=AE=E8=AE=A4=E5=88=97=E8=A1=A8=E5=85=81=E8=AE=B8?= =?UTF-8?q?=E6=94=B6=E8=B4=A7=20=E8=B0=83=E6=95=B4=E4=BA=86=E9=87=8D?= =?UTF-8?q?=E9=87=8F=E5=A4=A7=E4=BA=8E1kg=E6=97=B6=E6=98=BE=E7=A4=BAkg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/request/PurchaseWarehouseParam.kt | 4 ++-- .../sw/inbound/model/response/GoodsInfo.kt | 12 ++++++++-- .../inbound/ui/page/ReceiptProductScreen.kt | 2 +- .../com/sw/inbound/ui/weight/IdentityView.kt | 24 +++++++++++++++++-- .../ui/weight/dialog/ReceiptTipDialog.kt | 2 +- .../sw/inbound/viewmodel/ReceiptViewModel.kt | 11 +++++---- .../viewmodel/SelfProcurementViewModel.kt | 2 +- 7 files changed, 43 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/sw/inbound/model/request/PurchaseWarehouseParam.kt b/app/src/main/java/com/sw/inbound/model/request/PurchaseWarehouseParam.kt index ff5e99b..5bd9543 100644 --- a/app/src/main/java/com/sw/inbound/model/request/PurchaseWarehouseParam.kt +++ b/app/src/main/java/com/sw/inbound/model/request/PurchaseWarehouseParam.kt @@ -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 { "千克" 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 40b449f..0446817 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 @@ -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 { "千克" 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 6d695b1..b63c507 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 @@ -94,7 +94,7 @@ fun ReceiptProductScreen( LaunchedEffect(receiptResult) { if (receiptResult) { - ToastUtils.showToast("收货成功") +// ToastUtils.showToast("收货成功") controller.popBackStack() } } diff --git a/app/src/main/java/com/sw/inbound/ui/weight/IdentityView.kt b/app/src/main/java/com/sw/inbound/ui/weight/IdentityView.kt index 5a7053e..4c208bd 100644 --- a/app/src/main/java/com/sw/inbound/ui/weight/IdentityView.kt +++ b/app/src/main/java/com/sw/inbound/ui/weight/IdentityView.kt @@ -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(), diff --git a/app/src/main/java/com/sw/inbound/ui/weight/dialog/ReceiptTipDialog.kt b/app/src/main/java/com/sw/inbound/ui/weight/dialog/ReceiptTipDialog.kt index 639fe7f..5f64a6b 100644 --- a/app/src/main/java/com/sw/inbound/ui/weight/dialog/ReceiptTipDialog.kt +++ b/app/src/main/java/com/sw/inbound/ui/weight/dialog/ReceiptTipDialog.kt @@ -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 ), 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 fbba48c..668bd7b 100644 --- a/app/src/main/java/com/sw/inbound/viewmodel/ReceiptViewModel.kt +++ b/app/src/main/java/com/sw/inbound/viewmodel/ReceiptViewModel.kt @@ -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 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 f141f05..67ba6a1 100644 --- a/app/src/main/java/com/sw/inbound/viewmodel/SelfProcurementViewModel.kt +++ b/app/src/main/java/com/sw/inbound/viewmodel/SelfProcurementViewModel.kt @@ -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