feat: 航班表单三个枚举下拉对接字典接口并补全字段
新增页补上飞行状态输入项;飞行状态、航班服务种类、航班状态三个 下拉改为调用 typeCode 字典接口,替换原有的硬编码选项(旧的航班 状态码值与服务端实际码值完全不同)。详情页加载同一批字典,按值 反查并显示 label。新增页与详情页字段对齐为同一套。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,8 @@ import com.lukouguoji.module_base.bean.FlightBean
|
||||
import com.lukouguoji.module_base.common.Constant
|
||||
import com.lukouguoji.module_base.http.net.NetApply
|
||||
import com.lukouguoji.module_base.ktx.launchLoadingCollect
|
||||
import com.lukouguoji.module_base.util.DictUtils
|
||||
import dev.utils.app.info.KeyValue
|
||||
|
||||
class FlightQueryDetailsViewModel : BaseViewModel() {
|
||||
|
||||
@@ -14,9 +16,24 @@ class FlightQueryDetailsViewModel : BaseViewModel() {
|
||||
|
||||
var dataBean = MutableLiveData<FlightBean>()
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// 枚举字段展示文案:接口已返回名称时原样显示,只返回值(code)时按字典反查名称
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
val countryTypeText = MutableLiveData("")
|
||||
val serviceTypeText = MutableLiveData("")
|
||||
val portCodeText = MutableLiveData("")
|
||||
val flightStatusText = MutableLiveData("")
|
||||
|
||||
private var countryTypeDict = emptyList<KeyValue>()
|
||||
private var serviceTypeDict = emptyList<KeyValue>()
|
||||
private var portCodeDict = emptyList<KeyValue>()
|
||||
private var flightStatusDict = emptyList<KeyValue>()
|
||||
|
||||
fun initOnCreated(intent: Intent) {
|
||||
id = intent.getStringExtra(Constant.Key.ID) ?: ""
|
||||
|
||||
loadDictLists()
|
||||
getData()
|
||||
}
|
||||
|
||||
@@ -27,8 +44,52 @@ class FlightQueryDetailsViewModel : BaseViewModel() {
|
||||
onSuccess = {
|
||||
it.data?.let { data ->
|
||||
dataBean.value = data
|
||||
refreshEnumText()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载四个枚举字典(与新增/编辑页同源),用于把 code 反查成 label
|
||||
*/
|
||||
private fun loadDictLists() {
|
||||
DictUtils.getCountryTypeList(addAll = false) {
|
||||
countryTypeDict = it
|
||||
refreshEnumText()
|
||||
}
|
||||
DictUtils.getFlightServiceTypeList(addAll = false) {
|
||||
serviceTypeDict = it
|
||||
refreshEnumText()
|
||||
}
|
||||
DictUtils.getFlightPortCodeList(addAll = false) {
|
||||
portCodeDict = it
|
||||
refreshEnumText()
|
||||
}
|
||||
DictUtils.getFlightStatusList(addAll = false) {
|
||||
flightStatusDict = it
|
||||
refreshEnumText()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据或字典任一就绪都重算一次,避免两者返回先后顺序影响展示
|
||||
*/
|
||||
private fun refreshEnumText() {
|
||||
val bean = dataBean.value ?: return
|
||||
countryTypeText.value = toLabel(countryTypeDict, bean.countryType)
|
||||
serviceTypeText.value = toLabel(serviceTypeDict, bean.serviceType)
|
||||
portCodeText.value = toLabel(portCodeDict, bean.portCode)
|
||||
flightStatusText.value = toLabel(flightStatusDict, bean.flightStatus)
|
||||
}
|
||||
|
||||
/**
|
||||
* 值转 label:先按 code 反查,命中不了再判断是否本身就是 label,仍不命中则原样返回
|
||||
*/
|
||||
private fun toLabel(dict: List<KeyValue>, raw: String?): String {
|
||||
if (raw.isNullOrEmpty()) return ""
|
||||
dict.firstOrNull { it.value == raw }?.let { return it.key }
|
||||
dict.firstOrNull { it.key == raw }?.let { return it.key }
|
||||
return raw
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
android:orientation="vertical"
|
||||
android:padding="15dp">
|
||||
|
||||
<!-- 第1行:航班日期、航班号、航程 -->
|
||||
<!-- 第1行:航班日期、航班号、机型 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -68,20 +68,69 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
enable="@{false}"
|
||||
title='@{"航程"}'
|
||||
title='@{"机型"}'
|
||||
titleLength="@{4}"
|
||||
type="@{DataLayoutType.INPUT}"
|
||||
value='@{viewModel.dataBean.range}' />
|
||||
value='@{viewModel.dataBean.aircraftCode}' />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 第2行:地区类型、服务类型、经停站 -->
|
||||
<!-- 第2行:始发港、经停港、目的港 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
enable="@{false}"
|
||||
title='@{"始发港"}'
|
||||
titleLength="@{4}"
|
||||
type="@{DataLayoutType.INPUT}"
|
||||
value='@{viewModel.dataBean.fdep}' />
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
enable="@{false}"
|
||||
title='@{"经停港"}'
|
||||
titleLength="@{4}"
|
||||
type="@{DataLayoutType.INPUT}"
|
||||
value='@{viewModel.dataBean.jtz}' />
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
enable="@{false}"
|
||||
title='@{"目的港"}'
|
||||
titleLength="@{4}"
|
||||
type="@{DataLayoutType.INPUT}"
|
||||
value='@{viewModel.dataBean.fdest}' />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 第3行:航程、地区类型、服务类型 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
enable="@{false}"
|
||||
title='@{"航程"}'
|
||||
titleLength="@{4}"
|
||||
type="@{DataLayoutType.INPUT}"
|
||||
value='@{viewModel.dataBean.range}' />
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -90,7 +139,7 @@
|
||||
title='@{"地区类型"}'
|
||||
titleLength="@{4}"
|
||||
type="@{DataLayoutType.INPUT}"
|
||||
value='@{viewModel.dataBean.countryType}' />
|
||||
value='@{viewModel.countryTypeText}' />
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
android:layout_width="0dp"
|
||||
@@ -100,21 +149,50 @@
|
||||
title='@{"服务类型"}'
|
||||
titleLength="@{4}"
|
||||
type="@{DataLayoutType.INPUT}"
|
||||
value='@{viewModel.dataBean.serviceType}' />
|
||||
value='@{viewModel.serviceTypeText}' />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 第4行:飞行状态、航班状态、延误原因 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
enable="@{false}"
|
||||
title='@{"经停站"}'
|
||||
title='@{"飞行状态"}'
|
||||
titleLength="@{4}"
|
||||
type="@{DataLayoutType.INPUT}"
|
||||
value='@{viewModel.dataBean.jtz}' />
|
||||
value='@{viewModel.portCodeText}' />
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
enable="@{false}"
|
||||
title='@{"航班状态"}'
|
||||
titleLength="@{4}"
|
||||
type="@{DataLayoutType.INPUT}"
|
||||
value='@{viewModel.flightStatusText}' />
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
enable="@{false}"
|
||||
title='@{"延误原因"}'
|
||||
titleLength="@{4}"
|
||||
type="@{DataLayoutType.INPUT}"
|
||||
value='@{viewModel.dataBean.delayFreeText}' />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 第3行:计划起飞、预计起飞、实际起飞 -->
|
||||
<!-- 第5行:计划起飞、预计起飞、实际起飞 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -153,7 +231,7 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 第4行:计划降落、预计降落、实际降落 -->
|
||||
<!-- 第6行:计划降落、预计降落、实际降落 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -192,72 +270,13 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 第5行:飞行状态、航班状态、延误原因 -->
|
||||
<!-- 第7行:机位、机号 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
enable="@{false}"
|
||||
title='@{"飞行状态"}'
|
||||
titleLength="@{4}"
|
||||
type="@{DataLayoutType.INPUT}"
|
||||
value='@{viewModel.dataBean.portCode}' />
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
enable="@{false}"
|
||||
title='@{"航班状态"}'
|
||||
titleLength="@{4}"
|
||||
type="@{DataLayoutType.INPUT}"
|
||||
value='@{viewModel.dataBean.flightStatus}' />
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
enable="@{false}"
|
||||
title='@{"延误原因"}'
|
||||
titleLength="@{4}"
|
||||
type="@{DataLayoutType.INPUT}"
|
||||
value='@{viewModel.dataBean.delayFreeText}' />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 第6行:机号、机型、机位 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
enable="@{false}"
|
||||
title='@{"机号"}'
|
||||
titleLength="@{4}"
|
||||
type="@{DataLayoutType.INPUT}"
|
||||
value='@{viewModel.dataBean.registration}' />
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
enable="@{false}"
|
||||
title='@{"机型"}'
|
||||
titleLength="@{4}"
|
||||
type="@{DataLayoutType.INPUT}"
|
||||
value='@{viewModel.dataBean.aircraftCode}' />
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -268,6 +287,21 @@
|
||||
type="@{DataLayoutType.INPUT}"
|
||||
value='@{viewModel.dataBean.standId}' />
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
enable="@{false}"
|
||||
title='@{"机号"}'
|
||||
titleLength="@{4}"
|
||||
type="@{DataLayoutType.INPUT}"
|
||||
value='@{viewModel.dataBean.registration}' />
|
||||
|
||||
<Space
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
Reference in New Issue
Block a user