From 76ace545cd54c8041cc58e3ec31d8ecb2b788970 Mon Sep 17 00:00:00 2001 From: YANG JIANKUAN Date: Thu, 2 Apr 2026 16:48:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9B=BD=E9=99=85=E8=BF=9B=E6=B8=AF?= =?UTF-8?q?=E5=8E=9F=E5=A7=8B=E8=88=B1=E5=8D=95=E8=A1=A5=E5=85=85=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E9=A1=B5=E6=8C=89=E5=A7=8B=E5=8F=91=E7=AB=99/?= =?UTF-8?q?=E7=9B=AE=E7=9A=84=E7=AB=99=E8=87=AA=E5=8A=A8=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E5=9B=BD=E5=AE=B6=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.6 --- .../lukouguoji/module_base/http/net/Api.kt | 6 +++ .../IntArrSupplementInfoViewModel.kt | 45 +++++++++++++++++++ 2 files changed, 51 insertions(+) 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) + } + } + } } } }