自采入库、新增物品、上传图片、全部收货接口调试,其它逻辑优化

This commit is contained in:
2025-10-29 20:08:12 +08:00
parent 0611005d04
commit 7930ba0cd1
24 changed files with 651 additions and 306 deletions
@@ -1,10 +1,13 @@
package com.sw.inbound.viewmodel
import android.net.Uri
import android.util.Log
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.GoodsAddParam
import com.sw.inbound.model.request.PurchaseWarehouseParam
import com.sw.inbound.model.request.UploadInfo
import com.sw.inbound.model.response.DictType
@@ -13,6 +16,7 @@ import com.sw.inbound.model.response.PurchaseInfo
import com.sw.inbound.model.response.SearchGoodsInfo
import com.sw.inbound.repository.RemoteRepository
import com.sw.inbound.utils.ToastUtils
import com.sw.inbound.utils.ext.toJsonString
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
@@ -150,7 +154,7 @@ class ReceiptViewModel @Inject constructor(
// _selectedItem.value = purchaseOrder
// }
fun getReceiveDetail(id: String, action:(PurchaseInfo?)->Unit = {}) {
fun getReceiveDetail(id: String, action: (PurchaseInfo?) -> Unit = {}) {
launchWithLoading {
val response = repository.getReceiveDetail(id)
if (parseResponse(response)) {
@@ -245,12 +249,13 @@ class ReceiptViewModel @Inject constructor(
_amountUserInput.value = boolean
}
private var weightCallback:((Int)->Unit)?=null
fun readWeight(callback:(Int)->Unit) {
weightCallback = callback
}
//private var weightCallback: ((Int) -> Unit)? = null
//fun readWeight(callback: (Int) -> Unit) {
// weightCallback = callback
//}
override fun handleSensorScale(weight: Double) {
weightCallback?.invoke((weight*1000).toInt())
// weightCallback?.invoke((weight * 1000).toInt())
// val currentItem = _selectedItem.value
//
// currentItem?.let { info ->
@@ -346,4 +351,35 @@ class ReceiptViewModel @Inject constructor(
callback(resp.data == true)
}
}
fun uploadImage(imageUri: Uri, callback: (String?) -> Unit) {
launchWithLoading {
val resp = repository.uploadImage(imageUri)
if (!parseResponse(resp)) {
callback(null)
return@launchWithLoading
}
callback(resp.data)
}
}
fun createNewGoods(imageUri: Uri? = null, param: GoodsAddParam, callback: (Boolean) -> Unit) {
launchWithLoading {
if (imageUri != null) {
val resp = repository.uploadImage(imageUri)
if (!parseResponse(resp)) {
callback(false)
return@launchWithLoading
}
param.relativeUrl = resp.data
}
Timber.tag("ReceiptViewModel").d("createNewGoods入参:${param.toJsonString()}")
val response = repository.selfPurchaseGoodsAdd(param)
if (!parseResponse(response)) {
callback(false)
return@launchWithLoading
}
callback(true)
}
}
}