feat(inbound): 添加规格下拉选择功能
- 新增 SpecOption 数据模型定义 - 在 GlobalData 中添加 specOptionList 全局变量 - 实现 InboundApiService 中的 getSpecOptions 接口 - 添加 InboundRepository 中的 getSpecOptions 方法 - 在 StoreViewModel 中添加 specOptions 相关状态管理 - 在 StoreActivity 预加载规格选项数据 - 将入库规格字段从文本框改为下拉选择框 - 修复代码中的空字符串初始化问题
This commit is contained in:
@@ -3,6 +3,7 @@ package com.sw.inbound.viewmodel
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.sw.inbound.model.response.IngredientByTrace
|
||||
import com.sw.inbound.model.response.SpecOption
|
||||
import com.sw.inbound.model.response.SupplierOption
|
||||
import com.sw.inbound.model.response.ZoneOption
|
||||
import com.sw.inbound.repository.InboundRepository
|
||||
@@ -24,6 +25,9 @@ class StoreViewModel @Inject constructor(
|
||||
private val _supplierOptions = MutableStateFlow<List<SupplierOption>>(emptyList())
|
||||
val supplierOptions: StateFlow<List<SupplierOption>> = _supplierOptions
|
||||
|
||||
private val _specOptions = MutableStateFlow<List<SpecOption>>(emptyList())
|
||||
val specOptions: StateFlow<List<SpecOption>> = _specOptions
|
||||
|
||||
/** 按溯源码查食材,结果通过 callback 返回 */
|
||||
fun getIngredientByTrace(
|
||||
traceCode: String,
|
||||
@@ -78,6 +82,21 @@ class StoreViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
/** 加载规格列表,结果同时更新 StateFlow 并通过 callback 返回 */
|
||||
fun loadSpecOptions(callback: ((List<SpecOption>) -> Unit)? = null) {
|
||||
viewModelScope.launch {
|
||||
val response = repository.getSpecOptions()
|
||||
if (response.isSuccess()) {
|
||||
val list = response.data ?: emptyList()
|
||||
_specOptions.value = list
|
||||
callback?.invoke(list)
|
||||
} else {
|
||||
Timber.e("loadSpecOptions failed: ${response.msg}")
|
||||
callback?.invoke(emptyList())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 毛菜入库提交 */
|
||||
fun submitRawInbound(param: Map<String, Any>, callback: (Boolean, String?) -> Unit) {
|
||||
viewModelScope.launch {
|
||||
|
||||
Reference in New Issue
Block a user