diff --git a/module_base/src/main/java/com/lukouguoji/module_base/http/net/Api.kt b/module_base/src/main/java/com/lukouguoji/module_base/http/net/Api.kt index d95df45..72c2782 100644 --- a/module_base/src/main/java/com/lukouguoji/module_base/http/net/Api.kt +++ b/module_base/src/main/java/com/lukouguoji/module_base/http/net/Api.kt @@ -308,6 +308,12 @@ interface Api { @POST("typeCode/countryCode") suspend fun getCountryCodeList(): DictListBean + /** + * 获取国家代码(带始发站筛选) + */ + @POST("typeCode/countryCode") + suspend fun getCountryCodeListByFdep(@Query("fDep") fDep: String): DictListBean + /** * 获取通讯方式类型 */ diff --git a/module_gjj/src/main/java/com/lukouguoji/gjj/viewModel/IntArrSupplementInfoViewModel.kt b/module_gjj/src/main/java/com/lukouguoji/gjj/viewModel/IntArrSupplementInfoViewModel.kt index 679a9b3..996dfdd 100644 --- a/module_gjj/src/main/java/com/lukouguoji/gjj/viewModel/IntArrSupplementInfoViewModel.kt +++ b/module_gjj/src/main/java/com/lukouguoji/gjj/viewModel/IntArrSupplementInfoViewModel.kt @@ -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) + } + } + } } } }