|
@@ -17,8 +17,13 @@ import androidx.compose.runtime.Composable
|
|
|
import androidx.compose.runtime.LaunchedEffect
|
|
|
import androidx.compose.runtime.collectAsState
|
|
|
import androidx.compose.runtime.mutableStateListOf
|
|
|
+import androidx.compose.runtime.mutableStateOf
|
|
|
import androidx.compose.runtime.remember
|
|
|
import androidx.compose.runtime.rememberCoroutineScope
|
|
|
+import androidx.compose.runtime.setValue
|
|
|
+// 添加缺失的导入
|
|
|
+import androidx.compose.runtime.getValue
|
|
|
+
|
|
|
import androidx.compose.ui.Alignment
|
|
|
import androidx.compose.ui.Modifier
|
|
|
import androidx.compose.ui.res.painterResource
|
|
@@ -39,7 +44,6 @@ import kotlinx.coroutines.launch
|
|
|
|
|
|
@OptIn(ExperimentalMaterial3Api::class)
|
|
|
@Composable
|
|
|
-
|
|
|
fun DetailsScreen(
|
|
|
container: String,
|
|
|
result: String,
|
|
@@ -67,27 +71,52 @@ fun DetailsScreen(
|
|
|
resultCounter.addResult(it)
|
|
|
}
|
|
|
editableResults.clear()
|
|
|
- editableResults.addAll(resultCounter.getStatistics())
|
|
|
+ editableResults.addAll(
|
|
|
+ resultCounter.getStatistics().map {
|
|
|
+ ResultCount(
|
|
|
+ normalizedResult = it.normalizedResult,
|
|
|
+ occurrences = it.occurrences,
|
|
|
+ selectedSpec = ResultCount.Spec.OPTION_30KG
|
|
|
+ )
|
|
|
+ }
|
|
|
+ )
|
|
|
|
|
|
// 初始化库存列表
|
|
|
inventoryitems.clear()
|
|
|
inventoryitems.addAll(
|
|
|
editableResults.map {
|
|
|
- InventoryItem(it.normalizedResult, it.occurrences)
|
|
|
+ InventoryItem(
|
|
|
+ it.normalizedResult,
|
|
|
+ it.occurrences,
|
|
|
+ specification = when (it.selectedSpec) {
|
|
|
+ is ResultCount.Spec.OPTION_30KG -> 30
|
|
|
+ is ResultCount.Spec.OPTION_25KG -> 25
|
|
|
+ is ResultCount.Spec.CUSTOM -> it.customValue.toIntOrNull() ?: 0
|
|
|
+ }
|
|
|
+ )
|
|
|
}
|
|
|
)
|
|
|
}
|
|
|
|
|
|
// 更新文本输入时的数据同步
|
|
|
fun updateInventoryItem(index: Int, newCount: Int) {
|
|
|
- editableResults[index] = editableResults[index].copy(occurrences = newCount)
|
|
|
- inventoryitems[index] = inventoryitems[index].copy(occurrences = newCount)
|
|
|
+ val newItem = editableResults[index].copy(occurrences = newCount)
|
|
|
+ editableResults[index] = newItem
|
|
|
+ inventoryitems[index] = InventoryItem(
|
|
|
+ newItem.normalizedResult,
|
|
|
+ newCount,
|
|
|
+ specification = when (newItem.selectedSpec) {
|
|
|
+ is ResultCount.Spec.OPTION_30KG -> 30
|
|
|
+ is ResultCount.Spec.OPTION_25KG -> 25
|
|
|
+ is ResultCount.Spec.CUSTOM -> newItem.customValue.toIntOrNull() ?: 0
|
|
|
+ }
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
// 提交按钮的统一处理
|
|
|
fun onSubmit() {
|
|
|
val items = editableResults.map {
|
|
|
- InventoryItem(it.normalizedResult, it.occurrences)
|
|
|
+ InventoryItem(it.normalizedResult, it.occurrences,30)
|
|
|
}
|
|
|
inventoryitems.clear()
|
|
|
inventoryitems.addAll(items)
|
|
@@ -118,7 +147,7 @@ fun DetailsScreen(
|
|
|
snackbarHost = { SnackbarHost(snackbarHostState) },
|
|
|
topBar = {
|
|
|
TopAppBar(
|
|
|
- title = { Text("扫描结果详情") },
|
|
|
+ title = { Text("扫描详情") },
|
|
|
navigationIcon = {
|
|
|
IconButton(onClick = onBack) {
|
|
|
Icon(
|
|
@@ -142,6 +171,7 @@ fun DetailsScreen(
|
|
|
horizontalArrangement = Arrangement.SpaceEvenly,
|
|
|
|
|
|
) {
|
|
|
+ Spacer(Modifier.width(18.dp)) // 添加间距
|
|
|
ExtendedFloatingActionButton(
|
|
|
modifier = Modifier.weight(1f),
|
|
|
onClick = onMainScreen,
|
|
@@ -183,11 +213,11 @@ fun DetailsScreen(
|
|
|
} ,
|
|
|
icon = {
|
|
|
Icon(
|
|
|
- painter = painterResource(id = R.drawable.ic_scan),
|
|
|
+ painter = painterResource(id = R.drawable.component),
|
|
|
contentDescription = "组盘入库"
|
|
|
)
|
|
|
},
|
|
|
- text = { Text("组盘入库") }
|
|
|
+ text = { Text("组盘") }
|
|
|
)
|
|
|
}
|
|
|
}
|
|
@@ -200,7 +230,7 @@ fun DetailsScreen(
|
|
|
.padding(24.dp)
|
|
|
) {
|
|
|
Text(
|
|
|
- text = "扫描结果:",
|
|
|
+ text = "托盘编码:",
|
|
|
style = MaterialTheme.typography.titleLarge
|
|
|
)
|
|
|
|
|
@@ -227,14 +257,20 @@ fun DetailsScreen(
|
|
|
) {
|
|
|
Text("条码", style = MaterialTheme.typography.titleMedium)
|
|
|
Text("数量", style = MaterialTheme.typography.titleMedium)
|
|
|
+ Text("规格", style = MaterialTheme.typography.titleMedium)
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+// 修改 LazyColumn 部分
|
|
|
LazyColumn(
|
|
|
modifier = Modifier
|
|
|
.fillMaxWidth()
|
|
|
- .weight(1f)
|
|
|
+ .padding(16.dp)
|
|
|
) {
|
|
|
itemsIndexed(editableResults) { index, item ->
|
|
|
+
|
|
|
+ var expanded by remember { mutableStateOf(false) }
|
|
|
+ var customDialogVisible by remember { mutableStateOf(false) }
|
|
|
Row(
|
|
|
modifier = Modifier
|
|
|
.fillMaxWidth()
|
|
@@ -242,31 +278,121 @@ fun DetailsScreen(
|
|
|
verticalAlignment = Alignment.CenterVertically,
|
|
|
horizontalArrangement = Arrangement.SpaceBetween
|
|
|
) {
|
|
|
+ // 第一列:条码
|
|
|
Text(
|
|
|
text = item.normalizedResult,
|
|
|
modifier = Modifier.weight(1f),
|
|
|
overflow = TextOverflow.Ellipsis,
|
|
|
- maxLines = 1
|
|
|
+ maxLines = 2
|
|
|
)
|
|
|
|
|
|
- Spacer(modifier = Modifier.width(16.dp))
|
|
|
-
|
|
|
+ // 第二列:数量输入
|
|
|
OutlinedTextField(
|
|
|
value = item.occurrences.toString(),
|
|
|
onValueChange = { newValue ->
|
|
|
newValue.toIntOrNull()?.let { updateInventoryItem(index, it) }
|
|
|
-
|
|
|
},
|
|
|
- modifier = Modifier.width(100.dp),
|
|
|
+ modifier = Modifier
|
|
|
+ .width(70.dp)
|
|
|
+ .padding(horizontal = 4.dp),
|
|
|
keyboardOptions = KeyboardOptions.Default.copy(
|
|
|
keyboardType = KeyboardType.Number
|
|
|
)
|
|
|
)
|
|
|
+
|
|
|
+ // 第三列:规格选择
|
|
|
+ ExposedDropdownMenuBox(
|
|
|
+ expanded = expanded,
|
|
|
+ onExpandedChange = { expanded = expanded.not() },
|
|
|
+ modifier = Modifier
|
|
|
+ .weight(1f)
|
|
|
+ .padding(start = 8.dp)
|
|
|
+ ) {
|
|
|
+ OutlinedTextField(
|
|
|
+ value = when (item.selectedSpec) {
|
|
|
+ is ResultCount.Spec.OPTION_30KG -> "30kg/组"
|
|
|
+ is ResultCount.Spec.OPTION_25KG -> "25kg/组"
|
|
|
+ is ResultCount.Spec.CUSTOM ->
|
|
|
+ if (item.customValue.isEmpty()) "自定义kg/组"
|
|
|
+ else "${item.customValue}kg/组"
|
|
|
+ },
|
|
|
+ onValueChange = {},
|
|
|
+ readOnly = true,
|
|
|
+ trailingIcon = {
|
|
|
+ ExposedDropdownMenuDefaults.TrailingIcon(expanded = expanded)
|
|
|
+ },
|
|
|
+ modifier = Modifier
|
|
|
+ .menuAnchor()
|
|
|
+ .fillMaxWidth()
|
|
|
+ )
|
|
|
+
|
|
|
+ ExposedDropdownMenu(
|
|
|
+ expanded = expanded,
|
|
|
+ onDismissRequest = { expanded = false }
|
|
|
+ ) {
|
|
|
+ // 30kg选项
|
|
|
+ DropdownMenuItem(
|
|
|
+ text = { Text("30kg/组") },
|
|
|
+ onClick = {
|
|
|
+ editableResults[index] = item.copy(
|
|
|
+ selectedSpec = ResultCount.Spec.OPTION_30KG
|
|
|
+ )
|
|
|
+ expanded = false
|
|
|
+ }
|
|
|
+ )
|
|
|
+
|
|
|
+ // 25kg选项
|
|
|
+ DropdownMenuItem(
|
|
|
+ text = { Text("25kg/组") },
|
|
|
+ onClick = {
|
|
|
+ editableResults[index] = item.copy(
|
|
|
+ selectedSpec = ResultCount.Spec.OPTION_25KG
|
|
|
+ )
|
|
|
+ expanded = false
|
|
|
+ }
|
|
|
+ )
|
|
|
+
|
|
|
+ // 自定义选项
|
|
|
+ DropdownMenuItem(
|
|
|
+ text = { Text("自定义kg/组") },
|
|
|
+ onClick = {
|
|
|
+ expanded = false
|
|
|
+ customDialogVisible = true
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 自定义输入对话框
|
|
|
+ if (customDialogVisible) {
|
|
|
+ AlertDialog(
|
|
|
+ onDismissRequest = { customDialogVisible = false },
|
|
|
+ title = { Text("输入自定义规格") },
|
|
|
+ text = {
|
|
|
+ OutlinedTextField(
|
|
|
+ value = item.customValue,
|
|
|
+ onValueChange = {
|
|
|
+ editableResults[index] = item.copy(
|
|
|
+ selectedSpec = ResultCount.Spec.CUSTOM,
|
|
|
+ customValue = it
|
|
|
+ )
|
|
|
+ },
|
|
|
+ keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
|
|
|
+ label = { Text("输入公斤数") }
|
|
|
+ )
|
|
|
+ },
|
|
|
+ confirmButton = {
|
|
|
+ TextButton(
|
|
|
+ onClick = { customDialogVisible = false }
|
|
|
+ ) {
|
|
|
+ Text("确定")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ )
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
}
|