添加了图片拍照及识别逻辑
This commit is contained in:
@@ -10,7 +10,6 @@ import com.sw.inbound.model.response.GoodsInfo
|
||||
import com.sw.inbound.model.response.PurchaseInfo
|
||||
import com.sw.inbound.model.response.SearchGoodsInfo
|
||||
import com.sw.inbound.repository.RemoteRepository
|
||||
import com.sw.inbound.sdk.SensorScaleUtils
|
||||
import com.sw.inbound.utils.ToastUtils
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
@@ -63,10 +62,6 @@ class ReceiptViewModel @Inject constructor(
|
||||
private val _selectedItem = MutableStateFlow<GoodsInfo?>(null)
|
||||
val selectedItem: StateFlow<GoodsInfo?> = _selectedItem
|
||||
|
||||
// 搜索物品列表
|
||||
private val _searchListItems = MutableStateFlow<List<SearchGoodsInfo.Record>>(emptyList())
|
||||
val searchListItems: StateFlow<List<SearchGoodsInfo.Record>> = _searchListItems
|
||||
|
||||
// 收货请求结果
|
||||
private val _receiptResult = MutableStateFlow<Boolean>(false)
|
||||
val receiptResult: StateFlow<Boolean> = _receiptResult
|
||||
@@ -109,6 +104,16 @@ class ReceiptViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
override fun handleIdentityItem(goodsInfo: SearchGoodsInfo.Record) {
|
||||
val firstItem = unadjustedOrders.value.find { order ->
|
||||
order.goodId == goodsInfo.goodsId
|
||||
}
|
||||
updateLastPhotoUri(null)
|
||||
updateIdentityList(emptyList())
|
||||
_selectedItem.value = firstItem
|
||||
// updateSelectedItemWithSwitch(firstItem)
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新选中的item
|
||||
*/
|
||||
@@ -237,75 +242,67 @@ class ReceiptViewModel @Inject constructor(
|
||||
_amountUserInput.value = boolean
|
||||
}
|
||||
|
||||
fun startSensorScale() {
|
||||
Timber.d("开始称重")
|
||||
SensorScaleUtils.startScale(callback = { weight ->
|
||||
val currentItem = _selectedItem.value
|
||||
|
||||
currentItem?.let { info ->
|
||||
// 用户输入数量后不再通过重量反算
|
||||
if (_countUserInput.value) {
|
||||
_selectedItem.value = info.copy(
|
||||
goodsWeight = weight.toSafeBigDecimal(),
|
||||
)
|
||||
return@startScale
|
||||
}
|
||||
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)
|
||||
Timber.d("startSensorScale weight = $weight, count = $count, finalCount = $finalCount, consumeValue = $consumeValue, purchaseValue = $purchaseValue")
|
||||
// 计算单价
|
||||
val finalPrice = when {
|
||||
finalCount == 0f -> {
|
||||
0f
|
||||
}
|
||||
|
||||
_amountUserInput.value && !_priceUserInput.value -> {
|
||||
info.recPriceExItem!!.div(finalCount).toSafeFloat()
|
||||
}
|
||||
|
||||
else -> 0f
|
||||
}
|
||||
// 计算金额
|
||||
val finalAmount = when {
|
||||
finalCount == 0f -> {
|
||||
0f
|
||||
}
|
||||
|
||||
_priceUserInput.value && !_amountUserInput.value -> {
|
||||
finalCount.times(info.newRecUnitPriceTaxIn!!).toSafeFloat()
|
||||
}
|
||||
|
||||
else -> 0f
|
||||
}
|
||||
override fun handleSensorScale(weight: Double) {
|
||||
val currentItem = _selectedItem.value
|
||||
|
||||
currentItem?.let { info ->
|
||||
// 用户输入数量后不再通过重量反算
|
||||
if (_countUserInput.value) {
|
||||
_selectedItem.value = info.copy(
|
||||
goodsWeight = weight.toSafeBigDecimal(),
|
||||
// 收货数量
|
||||
receivedNumTemp = finalCount.toFormattedString(),
|
||||
receivedNum = finalCount,
|
||||
// 单价
|
||||
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(),
|
||||
)
|
||||
return
|
||||
}
|
||||
})
|
||||
}
|
||||
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)
|
||||
Timber.d("startSensorScale weight = $weight, count = $count, finalCount = $finalCount, consumeValue = $consumeValue, purchaseValue = $purchaseValue")
|
||||
// 计算单价
|
||||
val finalPrice = when {
|
||||
finalCount == 0f -> {
|
||||
0f
|
||||
}
|
||||
|
||||
fun stopSensorScale() {
|
||||
Timber.d("关闭称重")
|
||||
SensorScaleUtils.stopContinuousRead()
|
||||
_amountUserInput.value && !_priceUserInput.value -> {
|
||||
info.recPriceExItem!!.div(finalCount).toSafeFloat()
|
||||
}
|
||||
|
||||
else -> 0f
|
||||
}
|
||||
// 计算金额
|
||||
val finalAmount = when {
|
||||
finalCount == 0f -> {
|
||||
0f
|
||||
}
|
||||
|
||||
_priceUserInput.value && !_amountUserInput.value -> {
|
||||
finalCount.times(info.newRecUnitPriceTaxIn!!).toSafeFloat()
|
||||
}
|
||||
|
||||
else -> 0f
|
||||
}
|
||||
|
||||
_selectedItem.value = info.copy(
|
||||
goodsWeight = weight.toSafeBigDecimal(),
|
||||
// 收货数量
|
||||
receivedNumTemp = finalCount.toFormattedString(),
|
||||
receivedNum = finalCount,
|
||||
// 单价
|
||||
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(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun partialReceipt(uploadInfo: UploadInfo) {
|
||||
|
||||
Reference in New Issue
Block a user