feat: 国际进港原始舱单补充信息页按始发站/目的站自动匹配国家代码

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-02 16:48:40 +08:00
parent cf8a7f38fb
commit 76ace545cd
2 changed files with 51 additions and 0 deletions

View File

@@ -308,6 +308,12 @@ interface Api {
@POST("typeCode/countryCode")
suspend fun getCountryCodeList(): DictListBean
/**
* 获取国家代码(带始发站筛选)
*/
@POST("typeCode/countryCode")
suspend fun getCountryCodeListByFdep(@Query("fDep") fDep: String): DictListBean
/**
* 获取通讯方式类型
*/

View File

@@ -65,6 +65,51 @@ class IntArrSupplementInfoViewModel : BaseViewModel() {
} else null
} ?: emptyList()
countryCodeList.value = keyValueList
// 全量加载完成后,按始发站过滤查询,若唯一则自动选中
autoMatchCountryCodeByFdep()
}
}
}
/**
* 根据始发站/目的站自动匹配国家代码
* - 始发站(fdep) → 匹配发货人国家代码
* - 目的站(fdest) → 匹配收货人国家代码
*/
private fun autoMatchCountryCodeByFdep() {
val manifest = manifestList.firstOrNull() ?: return
val bean = dataBean.value ?: return
// 始发站 → 发货人国家代码
if (manifest.fdep.isNotEmpty() && bean.consignorCountryCode.isEmpty()) {
launchCollect({ NetApply.api.getCountryCodeListByFdep(manifest.fdep) }) {
onSuccess = { result ->
val filtered = result.data?.mapNotNull { dictBean ->
if (dictBean.code != null && dictBean.name != null) KeyValue(dictBean.name, dictBean.code) else null
} ?: emptyList()
if (filtered.size == 1) {
dataBean.value?.let { current ->
dataBean.value = current.copy(consignorCountryCode = filtered.first().value)
}
}
}
}
}
// 目的站 → 收货人国家代码
if (manifest.fdest.isNotEmpty() && bean.consigneeCountryCode.isEmpty()) {
launchCollect({ NetApply.api.getCountryCodeListByFdep(manifest.fdest) }) {
onSuccess = { result ->
val filtered = result.data?.mapNotNull { dictBean ->
if (dictBean.code != null && dictBean.name != null) KeyValue(dictBean.name, dictBean.code) else null
} ?: emptyList()
if (filtered.size == 1) {
dataBean.value?.let { current ->
dataBean.value = current.copy(consigneeCountryCode = filtered.first().value)
}
}
}
}
}
}