diff --git a/module_gjc/src/main/java/com/lukouguoji/gjc/viewModel/GjcWeighingWbDetailViewModel.kt b/module_gjc/src/main/java/com/lukouguoji/gjc/viewModel/GjcWeighingWbDetailViewModel.kt index 0de37cf..2bf8a50 100644 --- a/module_gjc/src/main/java/com/lukouguoji/gjc/viewModel/GjcWeighingWbDetailViewModel.kt +++ b/module_gjc/src/main/java/com/lukouguoji/gjc/viewModel/GjcWeighingWbDetailViewModel.kt @@ -5,14 +5,18 @@ import androidx.lifecycle.MutableLiveData import com.lukouguoji.module_base.base.BaseViewModel import com.lukouguoji.module_base.bean.GjcWeighingRecordBean import com.lukouguoji.module_base.common.Constant +import com.lukouguoji.module_base.http.net.NetApply +import com.lukouguoji.module_base.ktx.formatDate +import com.lukouguoji.module_base.ktx.launchCollect import com.lukouguoji.module_base.ktx.showToast +import com.lukouguoji.module_base.util.DictUtils /** * 国际出港计重-运单详情 ViewModel(5.5寸手机版专属页面) * - * 只读展示计重记录列表传入的运单信息,无接口请求。 - * 注:设计稿中的「通道号」字段在 /IntExpCheckIn/checked/pageQuery 出参中不存在(后端缺口, - * 见接口问题清单),布局侧空值兜底显示 "-"。 + * 先展示计重记录列表传入的运单信息;/IntExpCheckIn/checked/pageQuery 出参中 + * 航班日期/航班号/航程/业务类型/备注恒为空(Bug #622),再按 11 位运单号调 + * /IntExpCheckIn/queryWbByNo 补齐这些字段(只补空值,不覆盖列表已有数据)。 */ class GjcWeighingWbDetailViewModel : BaseViewModel() { @@ -23,8 +27,37 @@ class GjcWeighingWbDetailViewModel : BaseViewModel() { val data = intent.getSerializableExtra(Constant.Key.BEAN) as? GjcWeighingRecordBean if (data != null) { bean.value = data + loadWaybillInfo(data) } else { showToast("参数错误") } } + + private fun loadWaybillInfo(data: GjcWeighingRecordBean) { + if (data.wbNo.isEmpty()) return + launchCollect({ NetApply.api.getIntExpCheckInWbByNo(data.wbNo) }) { + onSuccess = { result -> + result.data?.let { wb -> + if (data.fdate.isEmpty()) data.fdate = wb.fdate.formatDate() + if (data.fno.isEmpty()) data.fno = wb.fno.orEmpty() + if (data.range.isEmpty()) data.range = wb.range.orEmpty() + if (data.businessType.isEmpty()) data.businessType = wb.businessType.orEmpty() + if (data.businessName.isEmpty()) data.businessName = wb.businessName.orEmpty() + if (data.remark.isEmpty()) data.remark = wb.remark.orEmpty() + bean.value = data + fillBusinessName(data) + } + } + } + } + + /** queryWbByNo 只返回业务类型代码(如 ANR),按国际出港业务类型字典转成中文名(与开始计重页同源) */ + private fun fillBusinessName(data: GjcWeighingRecordBean) { + if (data.businessName.isNotEmpty() || data.businessType.isEmpty()) return + DictUtils.getBusinessTypeList(type = "IO", addAll = false) { list -> + val name = list.firstOrNull { it.value == data.businessType }?.key ?: return@getBusinessTypeList + data.businessName = name + bean.postValue(data) + } + } }