|
@@ -1,47 +1,34 @@
|
|
|
package com.example.pda.ui
|
|
|
-
|
|
|
import androidx.compose.foundation.layout.*
|
|
|
import androidx.compose.foundation.lazy.LazyColumn
|
|
|
import androidx.compose.foundation.lazy.itemsIndexed
|
|
|
+import androidx.compose.foundation.rememberScrollState
|
|
|
import androidx.compose.foundation.text.KeyboardOptions
|
|
|
-import androidx.compose.material3.SnackbarHost
|
|
|
-import androidx.compose.material3.SnackbarHostState
|
|
|
-
|
|
|
+import androidx.compose.foundation.verticalScroll
|
|
|
import androidx.compose.material.icons.Icons
|
|
|
import androidx.compose.material.icons.filled.ArrowBack
|
|
|
import androidx.compose.material.icons.filled.Home
|
|
|
-
|
|
|
-import androidx.compose.material3.Scaffold
|
|
|
import androidx.compose.material3.*
|
|
|
-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.runtime.*
|
|
|
import androidx.compose.ui.Alignment
|
|
|
import androidx.compose.ui.Modifier
|
|
|
+import androidx.compose.ui.graphics.Color
|
|
|
import androidx.compose.ui.res.painterResource
|
|
|
+import androidx.compose.ui.text.font.FontWeight
|
|
|
import androidx.compose.ui.text.input.KeyboardType
|
|
|
+import androidx.compose.ui.text.style.TextAlign
|
|
|
import androidx.compose.ui.text.style.TextOverflow
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
|
|
-
|
|
|
import com.example.pda.R
|
|
|
import com.example.pda.function.ResultCount
|
|
|
import com.example.pda.function.ResultCounter
|
|
|
import com.example.pda.model.AppPrefs
|
|
|
-import com.example.pda.ui.viewmodel.InventoryViewModel
|
|
|
-import com.example.pda.model.InventoryItem
|
|
|
import com.example.pda.model.ContainerData
|
|
|
+import com.example.pda.model.InventoryItem
|
|
|
+import com.example.pda.ui.viewmodel.InventoryViewModel
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
|
|
-
|
|
|
@OptIn(ExperimentalMaterial3Api::class)
|
|
|
@Composable
|
|
|
fun DetailsScreen(
|
|
@@ -50,38 +37,28 @@ fun DetailsScreen(
|
|
|
onBack: () -> Unit,
|
|
|
onMainScreen: () -> Unit,
|
|
|
onShelfScan: () -> Unit,
|
|
|
-
|
|
|
- ) {
|
|
|
+) {
|
|
|
val snackbarHostState = remember { SnackbarHostState() }
|
|
|
val scope = rememberCoroutineScope()
|
|
|
val resultCounter = ResultCounter()
|
|
|
val viewModel: InventoryViewModel = viewModel()
|
|
|
- val editableResults = remember {
|
|
|
- mutableStateListOf<ResultCount>().apply {
|
|
|
- addAll(resultCounter.getStatistics())
|
|
|
- }
|
|
|
- }
|
|
|
- // 使用 mutableStateList 保证Compose能感知变化
|
|
|
+ val editableResults = remember { mutableStateListOf<ResultCount>() }
|
|
|
val inventoryitems = remember { mutableStateListOf<InventoryItem>() }
|
|
|
+ var showConfirmationDialog by remember { mutableStateOf(false) }
|
|
|
|
|
|
-
|
|
|
- // 初始化数据
|
|
|
LaunchedEffect(Unit) {
|
|
|
- result.split(",").forEach {
|
|
|
- resultCounter.addResult(it)
|
|
|
- }
|
|
|
+ result.split(",").forEach { resultCounter.addResult(it) }
|
|
|
editableResults.clear()
|
|
|
editableResults.addAll(
|
|
|
- resultCounter.getStatistics().map {
|
|
|
+ resultCounter.getStatistics(false).map {
|
|
|
ResultCount(
|
|
|
normalizedResult = it.normalizedResult,
|
|
|
occurrences = it.occurrences,
|
|
|
- selectedSpec = ResultCount.Spec.OPTION_30KG
|
|
|
+ selectedSpec = ResultCount.Spec.OPTION_25KG
|
|
|
)
|
|
|
}
|
|
|
)
|
|
|
|
|
|
- // 初始化库存列表
|
|
|
inventoryitems.clear()
|
|
|
inventoryitems.addAll(
|
|
|
editableResults.map {
|
|
@@ -89,8 +66,8 @@ fun DetailsScreen(
|
|
|
it.normalizedResult,
|
|
|
it.occurrences,
|
|
|
specification = when (it.selectedSpec) {
|
|
|
- is ResultCount.Spec.OPTION_30KG -> 30
|
|
|
is ResultCount.Spec.OPTION_25KG -> 25
|
|
|
+ is ResultCount.Spec.OPTION_20KG -> 20
|
|
|
is ResultCount.Spec.CUSTOM -> it.customValue.toIntOrNull() ?: 0
|
|
|
}
|
|
|
)
|
|
@@ -98,7 +75,26 @@ fun DetailsScreen(
|
|
|
)
|
|
|
}
|
|
|
|
|
|
- // 更新文本输入时的数据同步
|
|
|
+ fun updateSpecification(index: Int, newSpec: Int) {
|
|
|
+ val (specType, customVal) = when (newSpec) {
|
|
|
+ 20 -> ResultCount.Spec.OPTION_20KG to ""
|
|
|
+ 25 -> ResultCount.Spec.OPTION_25KG to ""
|
|
|
+ else -> ResultCount.Spec.CUSTOM to newSpec.toString()
|
|
|
+ }
|
|
|
+
|
|
|
+ val newResult = editableResults[index].copy(
|
|
|
+ selectedSpec = specType,
|
|
|
+ customValue = customVal
|
|
|
+ )
|
|
|
+
|
|
|
+ editableResults[index] = newResult
|
|
|
+ inventoryitems[index] = InventoryItem(
|
|
|
+ newResult.normalizedResult,
|
|
|
+ newResult.occurrences,
|
|
|
+ specification = newSpec
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
fun updateInventoryItem(index: Int, newCount: Int) {
|
|
|
val newItem = editableResults[index].copy(occurrences = newCount)
|
|
|
editableResults[index] = newItem
|
|
@@ -106,21 +102,38 @@ fun DetailsScreen(
|
|
|
newItem.normalizedResult,
|
|
|
newCount,
|
|
|
specification = when (newItem.selectedSpec) {
|
|
|
- is ResultCount.Spec.OPTION_30KG -> 30
|
|
|
is ResultCount.Spec.OPTION_25KG -> 25
|
|
|
+ is ResultCount.Spec.OPTION_20KG -> 20
|
|
|
is ResultCount.Spec.CUSTOM -> newItem.customValue.toIntOrNull() ?: 0
|
|
|
}
|
|
|
)
|
|
|
}
|
|
|
-
|
|
|
- // 提交按钮的统一处理
|
|
|
- fun onSubmit() {
|
|
|
- val items = editableResults.map {
|
|
|
- InventoryItem(it.normalizedResult, it.occurrences,30)
|
|
|
- }
|
|
|
- inventoryitems.clear()
|
|
|
- inventoryitems.addAll(items)
|
|
|
+ fun updateSpecification(index: Int, newSpec: Int, customValue: String = "") {
|
|
|
+ val newItem = editableResults[index].copy(
|
|
|
+ selectedSpec = when (newSpec) {
|
|
|
+ 25 -> ResultCount.Spec.OPTION_25KG
|
|
|
+ 20 -> ResultCount.Spec.OPTION_20KG
|
|
|
+ else -> {
|
|
|
+ // 当是自定义规格时同时更新customValue
|
|
|
+ editableResults[index] = editableResults[index].copy(
|
|
|
+ customValue = customValue
|
|
|
+ )
|
|
|
+ ResultCount.Spec.CUSTOM
|
|
|
+ }
|
|
|
+ }
|
|
|
+ )
|
|
|
+ editableResults[index] = newItem
|
|
|
+ inventoryitems[index] = InventoryItem(
|
|
|
+ newItem.normalizedResult,
|
|
|
+ newItem.occurrences,
|
|
|
+ specification = when (newSpec) {
|
|
|
+ 20 -> 20
|
|
|
+ 25 -> 25
|
|
|
+ else -> customValue.toIntOrNull() ?: 0
|
|
|
+ }
|
|
|
+ )
|
|
|
}
|
|
|
+
|
|
|
val uiState = viewModel.uiState.collectAsState()
|
|
|
|
|
|
LaunchedEffect(uiState.value) {
|
|
@@ -147,235 +160,264 @@ fun DetailsScreen(
|
|
|
snackbarHost = { SnackbarHost(snackbarHostState) },
|
|
|
topBar = {
|
|
|
TopAppBar(
|
|
|
- title = { Text("扫描详情") },
|
|
|
+ title = {
|
|
|
+ Text("扫描详情",
|
|
|
+ style = MaterialTheme.typography.titleLarge.copy(
|
|
|
+ fontWeight = FontWeight.Bold
|
|
|
+ ))
|
|
|
+ },
|
|
|
+ colors = TopAppBarDefaults.topAppBarColors(
|
|
|
+ containerColor = Color(0xFFBCD0C5), // 自定义颜色
|
|
|
+ titleContentColor = MaterialTheme.colorScheme.onPrimary,
|
|
|
+ actionIconContentColor = MaterialTheme.colorScheme.onPrimary
|
|
|
+ ),
|
|
|
navigationIcon = {
|
|
|
IconButton(onClick = onBack) {
|
|
|
- Icon(
|
|
|
- imageVector = Icons.Default.ArrowBack,
|
|
|
- contentDescription = "返回"
|
|
|
- )
|
|
|
+ Icon(Icons.Default.ArrowBack,
|
|
|
+ "返回",
|
|
|
+ tint = MaterialTheme.colorScheme.onPrimaryContainer)
|
|
|
}
|
|
|
}
|
|
|
)
|
|
|
},
|
|
|
floatingActionButton = {
|
|
|
Box(
|
|
|
- modifier = Modifier.fillMaxWidth(),
|
|
|
- contentAlignment = Alignment.Center
|
|
|
-
|
|
|
- ) {
|
|
|
- Row(
|
|
|
- modifier = Modifier
|
|
|
- .fillMaxWidth().padding(20.dp) ,
|
|
|
- verticalAlignment = Alignment.CenterVertically,
|
|
|
- horizontalArrangement = Arrangement.SpaceEvenly,
|
|
|
-
|
|
|
+ modifier = Modifier.fillMaxWidth(),
|
|
|
+ contentAlignment = Alignment.Center
|
|
|
) {
|
|
|
- Spacer(Modifier.width(18.dp)) // 添加间距
|
|
|
- ExtendedFloatingActionButton(
|
|
|
- modifier = Modifier.weight(1f),
|
|
|
- onClick = onMainScreen,
|
|
|
- icon = {
|
|
|
- Icon(
|
|
|
- imageVector = Icons.Default.Home,
|
|
|
- contentDescription = "返回主页"
|
|
|
- )
|
|
|
- },
|
|
|
- text = { Text("主页") }
|
|
|
- )
|
|
|
-
|
|
|
- Spacer(Modifier.width(8.dp)) // 添加间距
|
|
|
-
|
|
|
- ExtendedFloatingActionButton(
|
|
|
- modifier = Modifier.weight(1f),
|
|
|
- onClick = onShelfScan,
|
|
|
- icon = {
|
|
|
- Icon(
|
|
|
- painter = painterResource(id = R.drawable.ic_scan),
|
|
|
- contentDescription = "货架扫描"
|
|
|
- )
|
|
|
- },
|
|
|
- text = { Text("托盘") }
|
|
|
- )
|
|
|
- Spacer(Modifier.width(8.dp)) // 添加间距
|
|
|
-
|
|
|
- ExtendedFloatingActionButton(
|
|
|
- modifier = Modifier.weight(1f),
|
|
|
-
|
|
|
- onClick ={
|
|
|
- onSubmit()
|
|
|
- val containerData = ContainerData(
|
|
|
- container = container,
|
|
|
- batches = inventoryitems.toList(),
|
|
|
- username = AppPrefs.username
|
|
|
- )
|
|
|
- viewModel.submitData(containerData)
|
|
|
- } ,
|
|
|
- icon = {
|
|
|
- Icon(
|
|
|
- painter = painterResource(id = R.drawable.component),
|
|
|
- contentDescription = "组盘入库"
|
|
|
- )
|
|
|
- },
|
|
|
- text = { Text("组盘") }
|
|
|
- )
|
|
|
- }
|
|
|
+ Row(
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
+ .padding(20.dp),
|
|
|
+ verticalAlignment = Alignment.CenterVertically,
|
|
|
+ horizontalArrangement = Arrangement.SpaceEvenly,
|
|
|
+ ) {
|
|
|
+ Spacer(Modifier.width(30.dp))
|
|
|
+ ExtendedFloatingActionButton(
|
|
|
+ modifier = Modifier.weight(1f),
|
|
|
+ onClick = onMainScreen,
|
|
|
+ icon = { Icon(Icons.Default.Home, "返回主页") },
|
|
|
+ text = { Text("主页") }
|
|
|
+ )
|
|
|
+
|
|
|
+ Spacer(Modifier.width(8.dp))
|
|
|
+
|
|
|
+ ExtendedFloatingActionButton(
|
|
|
+ modifier = Modifier.weight(1f),
|
|
|
+ onClick = onShelfScan,
|
|
|
+ icon = { Icon(painterResource(R.drawable.ic_scan), "货架扫描") },
|
|
|
+ text = { Text("托盘") }
|
|
|
+ )
|
|
|
+
|
|
|
+ Spacer(Modifier.width(8.dp))
|
|
|
+
|
|
|
+ ExtendedFloatingActionButton(
|
|
|
+ modifier = Modifier.weight(1f),
|
|
|
+ onClick = {
|
|
|
+ if (inventoryitems.isEmpty()) {
|
|
|
+ scope.launch {
|
|
|
+ snackbarHostState.showSnackbar("请先扫描至少一个条码")
|
|
|
+ }
|
|
|
+ return@ExtendedFloatingActionButton
|
|
|
+ }
|
|
|
+ showConfirmationDialog = true
|
|
|
+ },
|
|
|
+ icon = { Icon(painterResource(R.drawable.component), "组盘入库") },
|
|
|
+ text = { Text("组盘") }
|
|
|
+ )
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
) { innerPadding ->
|
|
|
- Column(
|
|
|
+ LazyColumn( // ✅ 使用单一滚动容器
|
|
|
modifier = Modifier
|
|
|
.padding(innerPadding)
|
|
|
.fillMaxSize()
|
|
|
- .padding(24.dp)
|
|
|
+ .padding(horizontal = 24.dp),
|
|
|
+ verticalArrangement = Arrangement.spacedBy(16.dp)
|
|
|
) {
|
|
|
- Text(
|
|
|
- text = "托盘编码:",
|
|
|
- style = MaterialTheme.typography.titleLarge
|
|
|
- )
|
|
|
-
|
|
|
- Spacer(modifier = Modifier.height(16.dp))
|
|
|
+ // 托盘信息区块
|
|
|
+ item {
|
|
|
+ Column(modifier = Modifier.padding(vertical = 8.dp)) {
|
|
|
+ Text(
|
|
|
+ "托盘编码:",
|
|
|
+ style = MaterialTheme.typography.titleMedium
|
|
|
+ .copy(color = MaterialTheme.colorScheme.primary)
|
|
|
+ )
|
|
|
+ Card(
|
|
|
+ modifier = Modifier.fillMaxWidth(),
|
|
|
+ colors = CardDefaults.cardColors(
|
|
|
+ containerColor = MaterialTheme.colorScheme.surfaceVariant,
|
|
|
+ contentColor = MaterialTheme.colorScheme.onSurfaceVariant
|
|
|
+ ),
|
|
|
+ elevation = CardDefaults.cardElevation(4.dp)
|
|
|
+ ) {
|
|
|
+ Text(
|
|
|
+ text = container,
|
|
|
+ modifier = Modifier.padding(16.dp),
|
|
|
+ style = MaterialTheme.typography.titleMedium,
|
|
|
+ overflow = TextOverflow.Ellipsis,
|
|
|
+ maxLines = 2
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- Card(
|
|
|
- modifier = Modifier.fillMaxWidth()
|
|
|
- ) {
|
|
|
+ Spacer(modifier = Modifier.height(24.dp))
|
|
|
+ // 扫描结果标题
|
|
|
Text(
|
|
|
- text = container,
|
|
|
- modifier = Modifier.padding(16.dp),
|
|
|
- style = MaterialTheme.typography.bodyLarge,
|
|
|
- overflow = TextOverflow.Ellipsis,
|
|
|
- maxLines = 5
|
|
|
+ "扫描结果(${editableResults.size}项)",
|
|
|
+ style = MaterialTheme.typography.titleLarge.copy(
|
|
|
+ fontWeight = FontWeight.SemiBold
|
|
|
+ ),
|
|
|
+ modifier = Modifier.padding(bottom = 16.dp)
|
|
|
)
|
|
|
}
|
|
|
- // 观察状态变化
|
|
|
-
|
|
|
- // 新增统计列表
|
|
|
- Spacer(modifier = Modifier.height(24.dp))
|
|
|
- Row(
|
|
|
- modifier = Modifier.fillMaxWidth(),
|
|
|
- horizontalArrangement = Arrangement.SpaceBetween
|
|
|
- ) {
|
|
|
- Text("条码", style = MaterialTheme.typography.titleMedium)
|
|
|
- Text("数量", style = MaterialTheme.typography.titleMedium)
|
|
|
- Text("规格", style = MaterialTheme.typography.titleMedium)
|
|
|
-
|
|
|
- }
|
|
|
|
|
|
-// 修改 LazyColumn 部分
|
|
|
- LazyColumn(
|
|
|
- modifier = Modifier
|
|
|
- .fillMaxWidth()
|
|
|
- .padding(16.dp)
|
|
|
- ) {
|
|
|
- itemsIndexed(editableResults) { index, item ->
|
|
|
+ // 扫描结果列表
|
|
|
|
|
|
+ itemsIndexed(editableResults) { index, item ->
|
|
|
var expanded by remember { mutableStateOf(false) }
|
|
|
var customDialogVisible by remember { mutableStateOf(false) }
|
|
|
- Row(
|
|
|
- modifier = Modifier
|
|
|
- .fillMaxWidth()
|
|
|
- .padding(vertical = 8.dp),
|
|
|
- verticalAlignment = Alignment.CenterVertically,
|
|
|
- horizontalArrangement = Arrangement.SpaceBetween
|
|
|
- ) {
|
|
|
- // 第一列:条码
|
|
|
- Text(
|
|
|
- text = item.normalizedResult,
|
|
|
- modifier = Modifier.weight(1f),
|
|
|
- overflow = TextOverflow.Ellipsis,
|
|
|
- maxLines = 2
|
|
|
- )
|
|
|
|
|
|
- // 第二列:数量输入
|
|
|
- OutlinedTextField(
|
|
|
- value = item.occurrences.toString(),
|
|
|
- onValueChange = { newValue ->
|
|
|
- newValue.toIntOrNull()?.let { updateInventoryItem(index, it) }
|
|
|
- },
|
|
|
- modifier = Modifier
|
|
|
- .width(70.dp)
|
|
|
- .padding(horizontal = 4.dp),
|
|
|
- keyboardOptions = KeyboardOptions.Default.copy(
|
|
|
- keyboardType = KeyboardType.Number
|
|
|
- )
|
|
|
+ Card(
|
|
|
+ elevation = CardDefaults.cardElevation(2.dp),
|
|
|
+ colors = CardDefaults.cardColors(
|
|
|
+ containerColor = MaterialTheme.colorScheme.surface
|
|
|
)
|
|
|
-
|
|
|
- // 第三列:规格选择
|
|
|
- ExposedDropdownMenuBox(
|
|
|
- expanded = expanded,
|
|
|
- onExpandedChange = { expanded = expanded.not() },
|
|
|
+ ) {
|
|
|
+ Column(
|
|
|
modifier = Modifier
|
|
|
- .weight(1f)
|
|
|
- .padding(start = 8.dp)
|
|
|
+ .padding(16.dp)
|
|
|
+ .fillMaxWidth(),
|
|
|
+ verticalArrangement = Arrangement.spacedBy(12.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()
|
|
|
+ // 条码信息
|
|
|
+ Text(
|
|
|
+ text = item.normalizedResult,
|
|
|
+ style = MaterialTheme.typography.bodyLarge.copy(
|
|
|
+ fontWeight = FontWeight.Medium
|
|
|
+ ),
|
|
|
+ color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
|
)
|
|
|
|
|
|
- ExposedDropdownMenu(
|
|
|
- expanded = expanded,
|
|
|
- onDismissRequest = { expanded = false }
|
|
|
+ // 数量规格输入行
|
|
|
+ Row(
|
|
|
+ verticalAlignment = Alignment.CenterVertically,
|
|
|
+ horizontalArrangement = Arrangement.SpaceBetween,
|
|
|
+ modifier = Modifier.fillMaxWidth()
|
|
|
) {
|
|
|
- // 30kg选项
|
|
|
- DropdownMenuItem(
|
|
|
- text = { Text("30kg/组") },
|
|
|
- onClick = {
|
|
|
- editableResults[index] = item.copy(
|
|
|
- selectedSpec = ResultCount.Spec.OPTION_30KG
|
|
|
- )
|
|
|
- expanded = false
|
|
|
- }
|
|
|
- )
|
|
|
+ // 数量输入
|
|
|
+ Column(Modifier.weight(1f)) {
|
|
|
+ Text(
|
|
|
+ "数量",
|
|
|
+ style = MaterialTheme.typography.labelMedium,
|
|
|
+ color = MaterialTheme.colorScheme.outline
|
|
|
+ )
|
|
|
+ OutlinedTextField(
|
|
|
+ value = item.occurrences.toString(),
|
|
|
+ onValueChange = { newValue ->
|
|
|
+ newValue.toIntOrNull()?.let {
|
|
|
+ updateInventoryItem(index, it)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ modifier = Modifier.width(100.dp),
|
|
|
+ keyboardOptions = KeyboardOptions(
|
|
|
+ keyboardType = KeyboardType.Number
|
|
|
+ ),
|
|
|
+ textStyle = LocalTextStyle.current.copy(
|
|
|
+ textAlign = TextAlign.End
|
|
|
+ ),
|
|
|
+ suffix = { Text("件") }
|
|
|
+ )
|
|
|
+ }
|
|
|
|
|
|
- // 25kg选项
|
|
|
- DropdownMenuItem(
|
|
|
- text = { Text("25kg/组") },
|
|
|
- onClick = {
|
|
|
- editableResults[index] = item.copy(
|
|
|
- selectedSpec = ResultCount.Spec.OPTION_25KG
|
|
|
+ Spacer(Modifier.width(16.dp))
|
|
|
+
|
|
|
+ // 规格选择
|
|
|
+ Column(Modifier.weight(1.5f)) {
|
|
|
+ Text(
|
|
|
+ "规格",
|
|
|
+ style = MaterialTheme.typography.labelMedium,
|
|
|
+ color = MaterialTheme.colorScheme.outline
|
|
|
+ )
|
|
|
+ ExposedDropdownMenuBox(
|
|
|
+ expanded = expanded,
|
|
|
+ onExpandedChange = { expanded = it }
|
|
|
+ ) {
|
|
|
+ OutlinedTextField(
|
|
|
+ value = when (item.selectedSpec) {
|
|
|
+ is ResultCount.Spec.OPTION_25KG -> "25 kg/组"
|
|
|
+ is ResultCount.Spec.OPTION_20KG -> "20 kg/组"
|
|
|
+ is ResultCount.Spec.CUSTOM ->
|
|
|
+ if (item.customValue.isEmpty()) "自定义"
|
|
|
+ else "${item.customValue} kg/组"
|
|
|
+ },
|
|
|
+ onValueChange = {},
|
|
|
+ readOnly = true,
|
|
|
+ trailingIcon = {
|
|
|
+ ExposedDropdownMenuDefaults.TrailingIcon(expanded)
|
|
|
+ },
|
|
|
+ colors = TextFieldDefaults.colors(
|
|
|
+ focusedContainerColor = MaterialTheme.colorScheme.surface,
|
|
|
+ unfocusedContainerColor = MaterialTheme.colorScheme.surface
|
|
|
+ ),
|
|
|
+ textStyle = LocalTextStyle.current.copy(
|
|
|
+ color = MaterialTheme.colorScheme.primary
|
|
|
+ ),
|
|
|
+ modifier = Modifier.menuAnchor()
|
|
|
)
|
|
|
- expanded = false
|
|
|
- }
|
|
|
- )
|
|
|
|
|
|
- // 自定义选项
|
|
|
- DropdownMenuItem(
|
|
|
- text = { Text("自定义kg/组") },
|
|
|
- onClick = {
|
|
|
- expanded = false
|
|
|
- customDialogVisible = true
|
|
|
+ ExposedDropdownMenu(
|
|
|
+ expanded = expanded,
|
|
|
+ onDismissRequest = { expanded = false }
|
|
|
+ ) {
|
|
|
+ DropdownMenuItem(
|
|
|
+ text = { Text("20kg/组") },
|
|
|
+ onClick = {
|
|
|
+ editableResults[index] = item.copy(
|
|
|
+ selectedSpec = ResultCount.Spec.OPTION_20KG
|
|
|
+ )
|
|
|
+ updateSpecification(index, 20)
|
|
|
+ expanded = false
|
|
|
+ }
|
|
|
+ )
|
|
|
+ DropdownMenuItem(
|
|
|
+ text = { Text("25kg/组") },
|
|
|
+ onClick = {
|
|
|
+ editableResults[index] = item.copy(
|
|
|
+ selectedSpec = ResultCount.Spec.OPTION_25KG
|
|
|
+ )
|
|
|
+ updateSpecification(index, 25)
|
|
|
+ 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
|
|
|
+ // 使用editableResults中的customValue
|
|
|
+ value = editableResults[index].customValue,
|
|
|
+ onValueChange = { newValue ->
|
|
|
+ // 直接更新editableResults中的customValue
|
|
|
+ editableResults[index] = editableResults[index].copy(
|
|
|
+ customValue = newValue
|
|
|
)
|
|
|
},
|
|
|
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
|
|
@@ -384,7 +426,18 @@ fun DetailsScreen(
|
|
|
},
|
|
|
confirmButton = {
|
|
|
TextButton(
|
|
|
- onClick = { customDialogVisible = false }
|
|
|
+ onClick = {
|
|
|
+ // 提交时调用更新函数
|
|
|
+ val customValue = editableResults[index].customValue
|
|
|
+ if (customValue.isNotEmpty()) {
|
|
|
+ updateSpecification(
|
|
|
+ index,
|
|
|
+ customValue.toIntOrNull() ?: 0,
|
|
|
+ customValue
|
|
|
+ )
|
|
|
+ }
|
|
|
+ customDialogVisible = false
|
|
|
+ }
|
|
|
) {
|
|
|
Text("确定")
|
|
|
}
|
|
@@ -392,10 +445,65 @@ fun DetailsScreen(
|
|
|
)
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
+
|
|
|
+ item { Spacer(Modifier.height(80.dp)) }
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
-
|
|
|
|
|
|
+ if (showConfirmationDialog) {
|
|
|
+ AlertDialog(
|
|
|
+ onDismissRequest = { showConfirmationDialog = false },
|
|
|
+ title = { Text("确认提交组盘信息") },
|
|
|
+ text = {
|
|
|
+ Column(Modifier.verticalScroll(rememberScrollState())) {
|
|
|
+ Text("托盘编码:$container", style = MaterialTheme.typography.bodyLarge)
|
|
|
+ Spacer(Modifier.height(8.dp))
|
|
|
+ Text("包含物料:", style = MaterialTheme.typography.bodyMedium)
|
|
|
+
|
|
|
+ inventoryitems.forEach { item ->
|
|
|
+ Column(Modifier.padding(vertical = 4.dp)) {
|
|
|
+ Text("条码:${item.normalizedResult}")
|
|
|
+ Row(
|
|
|
+ horizontalArrangement = Arrangement.SpaceBetween,
|
|
|
+ modifier = Modifier.fillMaxWidth()
|
|
|
+ ) {
|
|
|
+ Text("数量:${item.occurrences}")
|
|
|
+ Text("规格:${item.specification}kg/组")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Divider()
|
|
|
+ }
|
|
|
|
|
|
+ val totalWeight = inventoryitems.sumOf { it.occurrences * it.specification }
|
|
|
+ Spacer(Modifier.height(12.dp))
|
|
|
+ Text(
|
|
|
+ "总重量:$totalWeight kg",
|
|
|
+ style = MaterialTheme.typography.bodyLarge.copy(
|
|
|
+ color = MaterialTheme.colorScheme.primary,
|
|
|
+ fontWeight = FontWeight.Bold
|
|
|
+ )
|
|
|
+ )
|
|
|
+ }
|
|
|
+ },
|
|
|
+ confirmButton = {
|
|
|
+ TextButton(
|
|
|
+ onClick = {
|
|
|
+ showConfirmationDialog = false
|
|
|
+ viewModel.submitData(
|
|
|
+ ContainerData(
|
|
|
+ container = container,
|
|
|
+ batches = inventoryitems.toList(),
|
|
|
+ username = AppPrefs.username
|
|
|
+ )
|
|
|
+ )
|
|
|
+ }
|
|
|
+ ) { Text("确认提交") }
|
|
|
+ },
|
|
|
+ dismissButton = {
|
|
|
+ TextButton(
|
|
|
+ onClick = { showConfirmationDialog = false }
|
|
|
+ ) { Text("取消") }
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+}
|