浏览代码

组盘信息完善

flower_mr 1 周之前
父节点
当前提交
7977e1125a

二进制
PDA.jks


+ 6 - 5
app/build.gradle.kts

@@ -46,14 +46,14 @@ dependencies {
     implementation(libs.androidx.activity.compose)
 
     // Compose BOM(确保版本 ≥ 2023.08.00)
-    implementation(platform("androidx.compose:compose-bom:2023.10.01")) // 关键改动:直接指定最新 BOM
+    implementation(platform("androidx.compose:compose-bom:2023.10.01"))
     implementation("androidx.compose.ui:ui")
     implementation("androidx.compose.ui:ui-graphics")
     implementation("androidx.compose.ui:ui-tooling-preview")
-    implementation("androidx.compose.material3:material3") // 关键改动:通过 BOM 自动匹配版本
+    implementation("androidx.compose.material3:material3")
+    implementation ("androidx.compose.animation:animation:1.3.0")
+    implementation ("androidx.compose.ui:ui:1.3.0")
 
-    // 移除重复的 material3 声明(避免版本冲突)
-    // implementation ("androidx.compose.material3:material3:1.2.2") // ⚠️ 注释掉这行
 
     // 其他依赖...
     implementation(files("libs\\platform_sdk_v3.0.0514.jar"))
@@ -69,11 +69,12 @@ dependencies {
     implementation("com.squareup.okhttp3:logging-interceptor:4.10.0")
 
     // Coroutines
-    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3") // 关键改动:升级协程版本
+    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
     implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3")
 
     // ViewModel
     implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.6.2")
 
     // 测试依赖...
+    testImplementation ("junit:junit:4.13.2")
 }

二进制
app/release/app-release.apk


二进制
app/release/baselineProfiles/0/app-release.dm


二进制
app/release/baselineProfiles/1/app-release.dm


+ 37 - 0
app/release/output-metadata.json

@@ -0,0 +1,37 @@
+{
+  "version": 3,
+  "artifactType": {
+    "type": "APK",
+    "kind": "Directory"
+  },
+  "applicationId": "com.example.pda",
+  "variantName": "release",
+  "elements": [
+    {
+      "type": "SINGLE",
+      "filters": [],
+      "attributes": [],
+      "versionCode": 1,
+      "versionName": "1.0",
+      "outputFile": "app-release.apk"
+    }
+  ],
+  "elementType": "File",
+  "baselineProfiles": [
+    {
+      "minApi": 28,
+      "maxApi": 30,
+      "baselineProfiles": [
+        "baselineProfiles/1/app-release.dm"
+      ]
+    },
+    {
+      "minApi": 31,
+      "maxApi": 2147483647,
+      "baselineProfiles": [
+        "baselineProfiles/0/app-release.dm"
+      ]
+    }
+  ],
+  "minSdkVersionForDexing": 24
+}

+ 57 - 5
app/src/main/java/com/example/pda/function/ResultCounter.kt

@@ -4,22 +4,21 @@ package com.example.pda.function
 data class ResultCount(
     val normalizedResult: String,
     var occurrences: Int,
-    var selectedSpec: Spec = Spec.OPTION_30KG,
+    var selectedSpec: Spec = Spec.OPTION_25KG,
     var customValue: String = ""
 ) {
     sealed class Spec(val display: String) {
-        object OPTION_30KG : Spec("30kg/组")
         object OPTION_25KG : Spec("25kg/组")
+        object OPTION_20KG : Spec("20kg/组")
         object CUSTOM : Spec("自定义kg/组")
     }
 }
 
-class ResultCounter {
+class ResultCounterMap {
     // 使用LinkedHashMap保持插入顺序(可选)
     private val resultMap = mutableMapOf<String, Int>()
 
-    // 线程安全版本(如需多线程访问):
-    // private val resultMap = java.util.concurrent.ConcurrentHashMap<String, Int>()
+
 
     /**
      * 添加结果并进行标准化处理
@@ -71,4 +70,57 @@ class ResultCounter {
         ALPHABETICAL, // 字母顺序
         OCCURRENCE    // 出现次数
     }
+}
+
+class ResultCounter {
+    // 改为使用List记录原始数据
+    private val resultList = mutableListOf<String>()
+    private val orderMap = mutableMapOf<String, Int>() // 用于记录首次出现顺序
+
+    /**
+     * 添加结果(保留重复项)
+     */
+    fun addResult(rawResult: String) {
+        val normalized = normalizeResult(rawResult)
+        resultList.add(normalized)
+        if (!orderMap.containsKey(normalized)) {
+            orderMap[normalized] = orderMap.size // 记录首次出现顺序
+        }
+    }
+
+    /**
+     * 获取所有结果(带可选去重)
+     */
+    fun getStatistics(distinct: Boolean = true): List<ResultCount> {
+        return if (distinct) {
+            orderMap.entries
+                .sortedBy { it.value } // 按首次出现顺序排序
+                .map { (k, _) ->
+                    val count = resultList.count { it == k }
+                    ResultCount(
+                        normalizedResult = k,
+                        occurrences = count
+                    )
+                }
+        } else {
+            resultList.mapIndexed { index, s ->
+                ResultCount(
+                    normalizedResult = s, // 添加序号区分重复项
+                    occurrences = 1
+                )
+            }
+        }
+    }
+
+    private fun normalizeResult(input: String): String {
+        return input
+    }
+
+    // 可选:重置统计
+    fun clear() {
+        resultList.clear()
+        orderMap.clear()
+    }
+
+
 }

+ 0 - 2
app/src/main/java/com/example/pda/navigation/NavGraph.kt

@@ -30,8 +30,6 @@ fun NavGraphBuilder.appNavGraph(navController: NavController) {
                 onPingScreen = { navController.navigate("ping") },
 
             )
-
-
         }
         // 定义 "main" 路由,显示主屏幕
         composable("main") {

+ 344 - 236
app/src/main/java/com/example/pda/ui/DetailsScreen.kt

@@ -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("取消") }
+            }
+        )
+    }
+}