feat: 航班表单三个枚举下拉对接字典接口并补全字段
新增页补上飞行状态输入项;飞行状态、航班服务种类、航班状态三个 下拉改为调用 typeCode 字典接口,替换原有的硬编码选项(旧的航班 状态码值与服务端实际码值完全不同)。详情页加载同一批字典,按值 反查并显示 label。新增页与详情页字段对齐为同一套。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -41,6 +41,7 @@ class HbFlightEditViewModel : BaseViewModel() {
|
||||
val fdest = MutableLiveData("")
|
||||
val countryType = MutableLiveData("")
|
||||
val serviceType = MutableLiveData("")
|
||||
val portCode = MutableLiveData("")
|
||||
val scheduledTackOff = MutableLiveData("")
|
||||
val estimatedTakeOff = MutableLiveData("")
|
||||
val actualTakeOff = MutableLiveData("")
|
||||
@@ -64,42 +65,17 @@ class HbFlightEditViewModel : BaseViewModel() {
|
||||
val countryTypeList = MutableLiveData<List<KeyValue>>(emptyList())
|
||||
val serviceTypeList = MutableLiveData<List<KeyValue>>(emptyList())
|
||||
val flightStatusList = MutableLiveData<List<KeyValue>>(emptyList())
|
||||
val portCodeList = MutableLiveData<List<KeyValue>>(emptyList())
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// 选项定义(服务端入库/过滤用 code,详情接口返回中文名,回填时需反查)
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private val countryTypeOptions = listOf(
|
||||
KeyValue("国内", "0"),
|
||||
KeyValue("国际", "1"),
|
||||
KeyValue("地区", "2"),
|
||||
KeyValue("混合", "3"),
|
||||
)
|
||||
|
||||
private val serviceTypeOptions = listOf(
|
||||
KeyValue("客机", "0"),
|
||||
KeyValue("货机", "1"),
|
||||
KeyValue("卡车", "2"),
|
||||
)
|
||||
|
||||
private val statusOptions = listOf(
|
||||
KeyValue("出港", "0"),
|
||||
KeyValue("进港", "1"),
|
||||
)
|
||||
|
||||
private val flightStatusOptions = listOf(
|
||||
KeyValue("正常", "0"),
|
||||
KeyValue("登机", "1"),
|
||||
KeyValue("登机结束", "2"),
|
||||
KeyValue("起飞", "3"),
|
||||
KeyValue("到达", "4"),
|
||||
KeyValue("取消", "5"),
|
||||
KeyValue("备降", "6"),
|
||||
KeyValue("删除发布", "7"),
|
||||
KeyValue("延误", "8"),
|
||||
KeyValue("未知", "9"),
|
||||
)
|
||||
|
||||
private val cmFlagOptions = listOf(
|
||||
KeyValue("有货邮", "0"),
|
||||
KeyValue("无货邮", "1"),
|
||||
@@ -138,8 +114,12 @@ class HbFlightEditViewModel : BaseViewModel() {
|
||||
fdep.value = bean.fdep
|
||||
jtz.value = bean.jtz
|
||||
fdest.value = bean.fdest
|
||||
countryType.value = toCode(countryTypeOptions, bean.countryType)
|
||||
serviceType.value = toCode(serviceTypeOptions, bean.serviceType)
|
||||
// 枚举字段(地区类型/服务类型/航班状态/飞行状态)由详情接口返回中文名,
|
||||
// 统一在字典加载回调里转 code,此处先原样存放
|
||||
countryType.value = bean.countryType
|
||||
serviceType.value = bean.serviceType
|
||||
flightStatus.value = bean.flightStatus
|
||||
portCode.value = bean.portCode
|
||||
status = toCode(statusOptions, bean.status)
|
||||
scheduledTackOff.value = bean.scheduledTackOff
|
||||
estimatedTakeOff.value = bean.estimatedTakeOff
|
||||
@@ -150,7 +130,6 @@ class HbFlightEditViewModel : BaseViewModel() {
|
||||
standId.value = bean.standId
|
||||
registration.value = bean.registration
|
||||
prefix = bean.prefix.noNull()
|
||||
flightStatus.value = toCode(flightStatusOptions, bean.flightStatus)
|
||||
cmFlag = toCode(cmFlagOptions, bean.cmFlag)
|
||||
delayFreeText.value = bean.delayFreeText
|
||||
}
|
||||
@@ -161,27 +140,36 @@ class HbFlightEditViewModel : BaseViewModel() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载下拉列表(编辑模式传 checkedValue 置顶选中项)
|
||||
* 加载下拉列表(四个数据源均来自 typeCode 字典接口)
|
||||
*/
|
||||
private fun loadDictLists() {
|
||||
val isModify = pageType.value == DetailsPageType.Modify
|
||||
|
||||
DictUtils.getCountryTypeList(
|
||||
addAll = false,
|
||||
checkedValue = if (isModify) countryType.value else null
|
||||
) {
|
||||
countryTypeList.postValue(if (isModify) it else listOf(KeyValue("", "")) + it)
|
||||
}
|
||||
|
||||
serviceTypeList.value =
|
||||
buildStaticList(serviceTypeOptions, if (isModify) serviceType.value else null)
|
||||
|
||||
flightStatusList.value =
|
||||
buildStaticList(flightStatusOptions, if (isModify) flightStatus.value else null)
|
||||
DictUtils.getCountryTypeList(addAll = false) { applyDict(it, countryType, countryTypeList, isModify) }
|
||||
DictUtils.getFlightServiceTypeList(addAll = false) { applyDict(it, serviceType, serviceTypeList, isModify) }
|
||||
DictUtils.getFlightStatusList(addAll = false) { applyDict(it, flightStatus, flightStatusList, isModify) }
|
||||
DictUtils.getFlightPortCodeList(addAll = false) { applyDict(it, portCode, portCodeList, isModify) }
|
||||
}
|
||||
|
||||
/**
|
||||
* 值转 code:详情接口可能返回中文名(如“国际”“客机”),统一转为 code 用于回填与提交
|
||||
* 字典就绪后:编辑模式把详情返回的中文名统一转成 code,再把列表交给下拉框
|
||||
*
|
||||
* 下拉框带 hint,value 为空时自动停在 hint 项,因此新增模式无需补空项
|
||||
*/
|
||||
private fun applyDict(
|
||||
list: List<KeyValue>,
|
||||
field: MutableLiveData<String>,
|
||||
listField: MutableLiveData<List<KeyValue>>,
|
||||
isModify: Boolean,
|
||||
) {
|
||||
if (isModify) {
|
||||
field.value = toCode(list, field.value)
|
||||
}
|
||||
listField.value = list
|
||||
}
|
||||
|
||||
/**
|
||||
* 值转 code:详情接口返回的是中文名(如“国际”“客机”“延误”),统一转为 code 用于回填与提交
|
||||
*/
|
||||
private fun toCode(options: List<KeyValue>, raw: String?): String {
|
||||
if (raw.isNullOrEmpty()) return ""
|
||||
@@ -190,16 +178,6 @@ class HbFlightEditViewModel : BaseViewModel() {
|
||||
?: raw
|
||||
}
|
||||
|
||||
/**
|
||||
* 静态下拉列表:新增模式首位置空项;编辑模式将选中项置顶
|
||||
*/
|
||||
private fun buildStaticList(list: List<KeyValue>, checkedValue: String?): List<KeyValue> {
|
||||
if (checkedValue.isNullOrEmpty()) {
|
||||
return listOf(KeyValue("", "")) + list
|
||||
}
|
||||
return list.filter { it.value == checkedValue } + list.filter { it.value != checkedValue }
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存 点击
|
||||
*/
|
||||
@@ -239,6 +217,7 @@ class HbFlightEditViewModel : BaseViewModel() {
|
||||
"actualArrival" to actualArrival.value,
|
||||
"standId" to standId.value?.trim(),
|
||||
"registration" to registration.value?.trim(),
|
||||
"portCode" to portCode.value,
|
||||
"flightStatus" to flightStatus.value,
|
||||
"delayFreeText" to delayFreeText.value?.trim(),
|
||||
)
|
||||
|
||||
@@ -171,7 +171,50 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 第4行:计划起飞、预计起飞、实际起飞 -->
|
||||
<!-- 第4行:飞行状态、机位、机号 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
hint='@{"请选择飞行状态"}'
|
||||
list="@{viewModel.portCodeList}"
|
||||
title='@{"飞行状态"}'
|
||||
titleLength="@{4}"
|
||||
type="@{DataLayoutType.SPINNER}"
|
||||
value='@={viewModel.portCode}'
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
hint='@{"请输入机位"}'
|
||||
title='@{"机位"}'
|
||||
titleLength="@{4}"
|
||||
type="@{DataLayoutType.INPUT}"
|
||||
value='@={viewModel.standId}'
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="15dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
android:id="@+id/registrationInput"
|
||||
hint='@{"请输入机号"}'
|
||||
title='@{"机号"}'
|
||||
titleLength="@{4}"
|
||||
type="@{DataLayoutType.INPUT}"
|
||||
value='@={viewModel.registration}'
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="15dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 第5行:计划起飞、预计起飞、实际起飞 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -214,7 +257,7 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 第5行:计划降落、预计降落、实际降落 -->
|
||||
<!-- 第6行:计划降落、预计降落、实际降落 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -257,35 +300,13 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 第6行:机位、机号、延误原因 -->
|
||||
<!-- 第7行:延误原因 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
hint='@{"请输入机位"}'
|
||||
title='@{"机位"}'
|
||||
titleLength="@{4}"
|
||||
type="@{DataLayoutType.INPUT}"
|
||||
value='@={viewModel.standId}'
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
android:id="@+id/registrationInput"
|
||||
hint='@{"请输入机号"}'
|
||||
title='@{"机号"}'
|
||||
titleLength="@{4}"
|
||||
type="@{DataLayoutType.INPUT}"
|
||||
value='@={viewModel.registration}'
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="15dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
hint='@{"请输入延误原因"}'
|
||||
title='@{"延误原因"}'
|
||||
@@ -294,9 +315,14 @@
|
||||
value='@={viewModel.delayFreeText}'
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="15dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<Space
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="15dp"
|
||||
android:layout_weight="2" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
Reference in New Issue
Block a user