feat: 开始计重新增托盘信息并自动计算运抵重量
国际出港开始计重页面新增托盘数量、托盘自重输入框(自重默认18可编辑), 运抵重量自动按“地磅称重 -(托盘数量 × 托盘自重)”计算; 分托计重与完成计重提交均携带 trayNumber、trayTotalWeight; “托盘车号”“托盘车自重”标签改为“平板车”“平板车自重”。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -66,6 +66,10 @@ class GjcWeighingStartViewModel : BaseViewModel() {
|
||||
|
||||
val pageRemark = MutableLiveData("") // 备注
|
||||
|
||||
// 托盘信息(运抵重量 = 地磅称重 - 托盘数量 × 托盘自重)
|
||||
val trayNumber = MutableLiveData("") // 托盘数量
|
||||
val trayWeight = MutableLiveData("18") // 托盘自重(默认18,可编辑)
|
||||
|
||||
// 下拉选择数据源
|
||||
val channelList = MutableLiveData<List<KeyValue>>() // 通道号列表
|
||||
val agentList = MutableLiveData<List<KeyValue>>() // 代理人列表
|
||||
@@ -82,11 +86,10 @@ class GjcWeighingStartViewModel : BaseViewModel() {
|
||||
// 获取传入的运单ID
|
||||
maWbId = intent.getLongExtra(Constant.Key.MAWB_ID, 0)
|
||||
|
||||
// 监听地磅称重输入,单向同步到运抵重量
|
||||
diBangWeight.observe(activity as LifecycleOwner) { weight ->
|
||||
// 同步到运抵重量(单向,不做反向同步)
|
||||
arriveWeight.value = weight ?: "0"
|
||||
}
|
||||
// 监听地磅称重、托盘数量、托盘自重输入,自动计算运抵重量
|
||||
diBangWeight.observe(activity as LifecycleOwner) { recalculateArriveWeight() }
|
||||
trayNumber.observe(activity as LifecycleOwner) { recalculateArriveWeight() }
|
||||
trayWeight.observe(activity as LifecycleOwner) { recalculateArriveWeight() }
|
||||
|
||||
// 监听运抵重量变化,自动计算运抵体积
|
||||
arriveWeight.observe(activity as LifecycleOwner) { weightStr ->
|
||||
@@ -113,6 +116,32 @@ class GjcWeighingStartViewModel : BaseViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动计算运抵重量:地磅称重 - (托盘数量 × 托盘自重)
|
||||
*/
|
||||
private fun recalculateArriveWeight() {
|
||||
val gross = diBangWeight.value?.toDoubleOrNull() ?: 0.0
|
||||
val trayTotal = getTrayTotalWeight()
|
||||
val net = gross - trayTotal
|
||||
arriveWeight.value = if (net > 0) formatWeight(net) else "0"
|
||||
}
|
||||
|
||||
/**
|
||||
* 托盘总重量 = 托盘数量 × 托盘自重
|
||||
*/
|
||||
private fun getTrayTotalWeight(): Double {
|
||||
val num = trayNumber.value?.toIntOrNull() ?: 0
|
||||
val weight = trayWeight.value?.toDoubleOrNull() ?: 0.0
|
||||
return num * weight
|
||||
}
|
||||
|
||||
/**
|
||||
* 重量格式化:最多保留两位小数,去掉多余的0
|
||||
*/
|
||||
private fun formatWeight(value: Double): String {
|
||||
return String.format("%.2f", value).trimEnd('0').trimEnd('.')
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载通道号列表 (国际出港专用)
|
||||
*/
|
||||
@@ -391,6 +420,10 @@ class GjcWeighingStartViewModel : BaseViewModel() {
|
||||
passageWay = this@GjcWeighingStartViewModel.channelList.value?.firstOrNull{ it.value == channel.value }?.key ?: ""
|
||||
passageWayId = this@GjcWeighingStartViewModel.channel.value
|
||||
|
||||
// 托盘信息
|
||||
trayNumber = this@GjcWeighingStartViewModel.trayNumber.value?.toIntOrNull()
|
||||
trayTotalWeight = getTrayTotalWeight()
|
||||
|
||||
remark = pageRemark.value
|
||||
}
|
||||
|
||||
@@ -417,6 +450,8 @@ class GjcWeighingStartViewModel : BaseViewModel() {
|
||||
arrivePc.value = ""
|
||||
arriveWeight.value = ""
|
||||
arriveVolume.value = ""
|
||||
trayNumber.value = ""
|
||||
trayWeight.value = "18"
|
||||
|
||||
pageRemark.value = ""
|
||||
|
||||
@@ -499,6 +534,8 @@ class GjcWeighingStartViewModel : BaseViewModel() {
|
||||
"goodsCn" to bean.goodsCn,
|
||||
"businessType" to bean.businessType,
|
||||
"carId" to bean.carId,
|
||||
"trayNumber" to trayNumber.value?.toIntOrNull(),
|
||||
"trayTotalWeight" to getTrayTotalWeight(),
|
||||
"remark" to pageRemark.value,
|
||||
"checkIn" to "1", // 收运状态设置为已收运
|
||||
"passageWayId" to channel.value, // 通道号参数
|
||||
|
||||
@@ -313,7 +313,45 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 第6行:运抵件数、运抵重量、运抵体积 -->
|
||||
<!-- 第6行:托盘数量、托盘自重(用于自动计算运抵重量) -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
hint='@{"请输入托盘数量"}'
|
||||
inputType="@{android.text.InputType.TYPE_CLASS_NUMBER}"
|
||||
title='@{"托盘数量"}'
|
||||
titleLength="@{5}"
|
||||
type="@{DataLayoutType.INPUT}"
|
||||
value='@={viewModel.trayNumber}'
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
hint='@{"请输入托盘自重"}'
|
||||
inputType="@{android.text.InputType.TYPE_CLASS_NUMBER | android.text.InputType.TYPE_NUMBER_FLAG_DECIMAL}"
|
||||
title='@{"托盘自重"}'
|
||||
titleLength="@{5}"
|
||||
type="@{DataLayoutType.INPUT}"
|
||||
value='@={viewModel.trayWeight}'
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="15dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<View
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="15dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 第7行:运抵件数、运抵重量、运抵体积 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -356,7 +394,7 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 第7行:托盘车号、托盘车自重、业务类型 -->
|
||||
<!-- 第8行:平板车、平板车自重、业务类型 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -364,9 +402,9 @@
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
hint='@{"请输入托盘车号"}'
|
||||
hint='@{"请输入平板车号"}'
|
||||
setRefreshCallBack="@{viewModel::onCarIdInputComplete}"
|
||||
title='@{"托盘车号"}'
|
||||
title='@{"平 板 车"}'
|
||||
titleLength="@{5}"
|
||||
type="@{DataLayoutType.INPUT}"
|
||||
value='@={viewModel.maWbBean.carId}'
|
||||
@@ -376,7 +414,7 @@
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
enable="@{false}"
|
||||
title='@{"托盘车自重"}'
|
||||
title='@{"平板车自重"}'
|
||||
titleLength="@{5}"
|
||||
type="@{DataLayoutType.INPUT}"
|
||||
value='@{viewModel.carWeight}'
|
||||
@@ -399,7 +437,7 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 第8行:备注 -->
|
||||
<!-- 第9行:备注 -->
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
hint='@{"请输入备注"}'
|
||||
inputHeight="@{80}"
|
||||
|
||||
Reference in New Issue
Block a user