|
@@ -30,9 +30,10 @@ import androidx.lifecycle.viewmodel.compose.viewModel
|
|
import com.example.pda.R
|
|
import com.example.pda.R
|
|
import com.example.pda.function.ResultCount
|
|
import com.example.pda.function.ResultCount
|
|
import com.example.pda.function.ResultCounter
|
|
import com.example.pda.function.ResultCounter
|
|
|
|
+import com.example.pda.model.AppPrefs
|
|
import com.example.pda.ui.viewmodel.InventoryViewModel
|
|
import com.example.pda.ui.viewmodel.InventoryViewModel
|
|
import com.example.pda.model.InventoryItem
|
|
import com.example.pda.model.InventoryItem
|
|
-import com.example.pda.ui.viewmodel.PingViewmodel
|
|
|
|
|
|
+import com.example.pda.model.ContainerData
|
|
import kotlinx.coroutines.launch
|
|
import kotlinx.coroutines.launch
|
|
|
|
|
|
|
|
|
|
@@ -56,7 +57,10 @@ fun DetailsScreen(
|
|
addAll(resultCounter.getStatistics())
|
|
addAll(resultCounter.getStatistics())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- val Inventoryitems: MutableList<InventoryItem> = mutableListOf()
|
|
|
|
|
|
+ // 使用 mutableStateList 保证Compose能感知变化
|
|
|
|
+ val inventoryitems = remember { mutableStateListOf<InventoryItem>() }
|
|
|
|
+
|
|
|
|
+
|
|
// 初始化数据
|
|
// 初始化数据
|
|
LaunchedEffect(Unit) {
|
|
LaunchedEffect(Unit) {
|
|
result.split(",").forEach {
|
|
result.split(",").forEach {
|
|
@@ -64,6 +68,29 @@ fun DetailsScreen(
|
|
}
|
|
}
|
|
editableResults.clear()
|
|
editableResults.clear()
|
|
editableResults.addAll(resultCounter.getStatistics())
|
|
editableResults.addAll(resultCounter.getStatistics())
|
|
|
|
+
|
|
|
|
+ // 初始化库存列表
|
|
|
|
+ inventoryitems.clear()
|
|
|
|
+ inventoryitems.addAll(
|
|
|
|
+ editableResults.map {
|
|
|
|
+ InventoryItem(it.normalizedResult, it.occurrences)
|
|
|
|
+ }
|
|
|
|
+ )
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 更新文本输入时的数据同步
|
|
|
|
+ fun updateInventoryItem(index: Int, newCount: Int) {
|
|
|
|
+ editableResults[index] = editableResults[index].copy(occurrences = newCount)
|
|
|
|
+ inventoryitems[index] = inventoryitems[index].copy(occurrences = newCount)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 提交按钮的统一处理
|
|
|
|
+ fun onSubmit() {
|
|
|
|
+ val items = editableResults.map {
|
|
|
|
+ InventoryItem(it.normalizedResult, it.occurrences)
|
|
|
|
+ }
|
|
|
|
+ inventoryitems.clear()
|
|
|
|
+ inventoryitems.addAll(items)
|
|
}
|
|
}
|
|
val uiState = viewModel.uiState.collectAsState()
|
|
val uiState = viewModel.uiState.collectAsState()
|
|
|
|
|
|
@@ -144,29 +171,24 @@ fun DetailsScreen(
|
|
|
|
|
|
ExtendedFloatingActionButton(
|
|
ExtendedFloatingActionButton(
|
|
modifier = Modifier.weight(1f),
|
|
modifier = Modifier.weight(1f),
|
|
- onClick ={onsubmit(resultCounter,editableResults,Inventoryitems)} ,
|
|
|
|
- icon = {
|
|
|
|
- Icon(
|
|
|
|
- painter = painterResource(id = R.drawable.ic_scan),
|
|
|
|
- contentDescription = "确认入库"
|
|
|
|
- )
|
|
|
|
- },
|
|
|
|
- text = { Text("确认入库") }
|
|
|
|
- )
|
|
|
|
|
|
|
|
- ExtendedFloatingActionButton(
|
|
|
|
- modifier = Modifier.weight(1f),
|
|
|
|
- onClick ={viewModel.submitData(Inventoryitems)} ,
|
|
|
|
|
|
+ onClick ={
|
|
|
|
+ onSubmit()
|
|
|
|
+ val containerData = ContainerData(
|
|
|
|
+ container = container,
|
|
|
|
+ batches = inventoryitems.toList(),
|
|
|
|
+ username = AppPrefs.username
|
|
|
|
+ )
|
|
|
|
+ viewModel.submitData(containerData)
|
|
|
|
+ } ,
|
|
icon = {
|
|
icon = {
|
|
Icon(
|
|
Icon(
|
|
painter = painterResource(id = R.drawable.ic_scan),
|
|
painter = painterResource(id = R.drawable.ic_scan),
|
|
- contentDescription = "ping"
|
|
|
|
|
|
+ contentDescription = "组盘入库"
|
|
)
|
|
)
|
|
},
|
|
},
|
|
- text = { Text("ping") }
|
|
|
|
|
|
+ text = { Text("组盘入库") }
|
|
)
|
|
)
|
|
-
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -232,13 +254,8 @@ fun DetailsScreen(
|
|
OutlinedTextField(
|
|
OutlinedTextField(
|
|
value = item.occurrences.toString(),
|
|
value = item.occurrences.toString(),
|
|
onValueChange = { newValue ->
|
|
onValueChange = { newValue ->
|
|
- newValue.toIntOrNull()?.let {
|
|
|
|
- val newList = editableResults.toMutableList().apply {
|
|
|
|
- set(index, item.copy(occurrences = it))
|
|
|
|
- }
|
|
|
|
- editableResults.clear()
|
|
|
|
- editableResults.addAll(newList)
|
|
|
|
- }
|
|
|
|
|
|
+ newValue.toIntOrNull()?.let { updateInventoryItem(index, it) }
|
|
|
|
+
|
|
},
|
|
},
|
|
modifier = Modifier.width(100.dp),
|
|
modifier = Modifier.width(100.dp),
|
|
keyboardOptions = KeyboardOptions.Default.copy(
|
|
keyboardOptions = KeyboardOptions.Default.copy(
|
|
@@ -254,19 +271,5 @@ fun DetailsScreen(
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-private fun onsubmit(resultCounter: ResultCounter, editableResults: MutableList<ResultCount>, items: MutableList<InventoryItem>) {
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- // 使用 map 进行转换,并更新 items
|
|
|
|
- items.clear()
|
|
|
|
- items.addAll(editableResults.map { result ->
|
|
|
|
- InventoryItem(
|
|
|
|
- normalizedResult = result.normalizedResult, // 将对应字段映射到 InventoryItem 中
|
|
|
|
- occurrences = result.occurrences // 将对应字段映射到 InventoryItem 中
|
|
|
|
- )
|
|
|
|
- })
|
|
|
|
- resultCounter.clear()
|
|
|
|
- editableResults.clear()
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
|