diff --git a/app/src/main/java/com/sw/inbound/adapter/FormFieldAdapter.kt b/app/src/main/java/com/sw/inbound/adapter/FormFieldAdapter.kt index efaf93c..0d35ea1 100644 --- a/app/src/main/java/com/sw/inbound/adapter/FormFieldAdapter.kt +++ b/app/src/main/java/com/sw/inbound/adapter/FormFieldAdapter.kt @@ -25,6 +25,9 @@ import java.text.SimpleDateFormat import java.util.Calendar import java.util.Locale import kotlin.math.min +import kotlin.text.clear +import kotlin.text.get +import kotlin.text.set /** * 动态表单字段 Adapter,配合 FlexboxLayoutManager 实现两列自动换行布局 @@ -123,18 +126,11 @@ class FormFieldAdapter( popHeight = popHeight ) { dictType -> item.value = dictType.value ?: "" - item.valueId = dictType.id ?: "" b.tvDropdownValue.text = item.value // 将 extraApiKeys 映射的 DictType 字段值写入 extraValues item.extraValues.clear() item.extraApiKeys.forEach { (apiKey, dictField) -> - val fieldValue = when (dictField) { - "id" -> dictType.id ?: "" - "value" -> dictType.value ?: "" - "type" -> dictType.type - else -> "" - } - item.extraValues[apiKey] = fieldValue + item.extraValues[apiKey] = dictType[dictField] } }.also { it.bgLayout = b.flDropdown @@ -161,7 +157,6 @@ class FormFieldAdapter( } // value 存显示格式,valueId 存 ISO 格式供提交使用 item.value = displayDateFormat.format(selected.time) - item.valueId = isoFormat.format(selected.time) b.tvDateValue.text = item.value }, cal.get(Calendar.YEAR), diff --git a/app/src/main/java/com/sw/inbound/dialog/InboundGoodsStoreDialog.kt b/app/src/main/java/com/sw/inbound/dialog/InboundGoodsStoreDialog.kt index 809da2e..8332167 100644 --- a/app/src/main/java/com/sw/inbound/dialog/InboundGoodsStoreDialog.kt +++ b/app/src/main/java/com/sw/inbound/dialog/InboundGoodsStoreDialog.kt @@ -133,8 +133,7 @@ class InboundGoodsStoreDialog( FieldType.DATE_PICKER, apiKey = "inboundTime", required = true, - hint = "请选择入库时间", - submitValueId = true + hint = "请选择入库时间" ), FormField( "存放区域", FieldType.DROPDOWN, @@ -205,15 +204,13 @@ class InboundGoodsStoreDialog( "操作时间", FieldType.DATE_PICKER, apiKey = "inboundTime", - hint = "请选择操作时间", - submitValueId = true + hint = "请选择操作时间" ), FormField( "保质期至", FieldType.DATE_PICKER, apiKey = "expiryDate", - hint = "请选择保质期", - submitValueId = true + hint = "请选择保质期" ), FormField( "存放区域", FieldType.DROPDOWN, @@ -304,13 +301,13 @@ class InboundGoodsStoreDialog( val map = mutableMapOf() for (field in fields) { if (field.extraApiKeys.isNotEmpty()) { - field.extraValues.forEach { (apiKey, raw) -> - if (raw.isNotBlank()) map[apiKey] = raw + field.extraValues.forEach { (apiKey, value) -> + map[apiKey] = value } continue } if (field.apiKey.isBlank()) continue - val raw = if (field.submitValueId) field.valueId else field.value + val raw = field.value if (raw.isBlank()) continue val converted: Any = when (field.apiKey) { "quantity" -> raw.toIntOrNull() ?: continue @@ -326,7 +323,7 @@ class InboundGoodsStoreDialog( val param = buildParamMap() // weight 来自秤,不在表单中,额外注入 param["weight"] = realWeight / 1000.0 - + param["materId"] = goods?.materId ?:"" Loading.show(storeActivity ?: return) storeActivity?.storeViewModel?.submitRawInbound(param) { success, msg -> Loading.dismiss() @@ -346,6 +343,7 @@ class InboundGoodsStoreDialog( param["weight"] = realWeight / 1000.0 // inboundTime 净菜取当前时间,不在表单中 param["inboundTime"] = isoFormat.format(Date()) + param["materId"] = goods?.materId ?:"" Loading.show(storeActivity ?: return) storeActivity?.storeViewModel?.submitCleanInbound(param) { success, msg -> diff --git a/app/src/main/java/com/sw/inbound/model/FormField.kt b/app/src/main/java/com/sw/inbound/model/FormField.kt index 22cfbdc..5fae931 100644 --- a/app/src/main/java/com/sw/inbound/model/FormField.kt +++ b/app/src/main/java/com/sw/inbound/model/FormField.kt @@ -26,9 +26,7 @@ enum class FieldType { * @param hidden 是否隐藏,hidden=true 时不渲染该字段 * @param hint 校验失败提示文案,同时作为输入框 hint * @param options 下拉框选项列表(DROPDOWN 类型使用) - * @param submitValueId 提交时使用 valueId 而非 value;DATE_PICKER 选 ISO 格式时设为 true * @param value 当前显示值/输入值;DATE_PICKER 存 yyyy-MM-dd 显示格式 - * @param valueId DATE_PICKER 存 ISO 格式 yyyy-MM-dd'T'HH:mm:ss * @param extraValues 下拉选中后按 extraApiKeys 映射存储的提交值,key=接口参数名 */ data class FormField( @@ -40,8 +38,6 @@ data class FormField( val hidden: Boolean = false, val hint: String = "", val options: List = emptyList(), - val submitValueId: Boolean = false, var value: String = "", - var valueId: String = "", val extraValues: MutableMap = mutableMapOf() ) diff --git a/app/src/main/java/com/sw/inbound/model/response/DictType.kt b/app/src/main/java/com/sw/inbound/model/response/DictType.kt index ada2d13..1b12bac 100644 --- a/app/src/main/java/com/sw/inbound/model/response/DictType.kt +++ b/app/src/main/java/com/sw/inbound/model/response/DictType.kt @@ -11,4 +11,14 @@ data class DictType( val id: String? = null, val value: String? = null, val type: String = "" -) : Parcelable +) : Parcelable { + + /** + * 按字段名取值,供 extraApiKeys 映射直接使用 + */ + operator fun get(fieldName: String): String = when (fieldName) { + "id" -> id ?: "" + "value" -> value ?: "" + else -> type + } +}