feat: opt 板箱过磅 auto calc
This commit is contained in:
@@ -35,7 +35,8 @@
|
||||
"Bash(grep:*)",
|
||||
"Bash(sort:*)",
|
||||
"Bash(ls:*)",
|
||||
"Bash(xargs rm:*)"
|
||||
"Bash(xargs rm:*)",
|
||||
"Bash(git -C /Users/kid/Development/Fusion/Projects/aerologic-app stash)"
|
||||
],
|
||||
"deny": [],
|
||||
"ask": []
|
||||
|
||||
63
CLAUDE.md
63
CLAUDE.md
@@ -505,6 +505,69 @@ dataBean.value = bean
|
||||
**类型**: `INPUT` / `SPINNER` / `DATE`
|
||||
**注意**: 使用 PadDataLayout 时,`titleLength` 通常设置为 5
|
||||
|
||||
#### PadDataLayoutNew - 输入完成回调
|
||||
|
||||
**使用场景**: 当需要在用户完成输入(失去焦点)时触发自动查询或其他操作
|
||||
|
||||
**正确用法**: 使用方法引用语法 `viewModel::methodName`
|
||||
|
||||
```xml
|
||||
<!-- 输入完成后自动查询 -->
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
android:id="@+id/carIdInput"
|
||||
hint='@{"请输入架子车号"}'
|
||||
setRefreshCallBack="@{viewModel::onCarIdInputComplete}"
|
||||
title='@{"架子车号"}'
|
||||
titleLength="@{5}"
|
||||
type="@{DataLayoutType.INPUT}"
|
||||
value='@={viewModel.carId}'
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<!-- 日期选择完成后触发回调 -->
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
setRefreshCallBack="@{viewModel::onFlightDateInputComplete}"
|
||||
title='@{"航班日期"}'
|
||||
titleLength="@{5}"
|
||||
type="@{DataLayoutType.DATE}"
|
||||
value='@={viewModel.flightDate}'
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" />
|
||||
```
|
||||
|
||||
**ViewModel 中的实现**:
|
||||
|
||||
```kotlin
|
||||
/**
|
||||
* 架子车号输入完成时调用
|
||||
*/
|
||||
fun onCarIdInputComplete() {
|
||||
val id = carId.value
|
||||
if (!id.isNullOrEmpty() && id != lastQueriedCarId) {
|
||||
lastQueriedCarId = id
|
||||
queryFlatcarInfo(id)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 航班日期选择完成时调用
|
||||
*/
|
||||
fun onFlightDateInputComplete() {
|
||||
// 清除查询标记,以便重新查询
|
||||
lastQueriedFlight = ""
|
||||
queryFlightIfReady()
|
||||
}
|
||||
```
|
||||
|
||||
**关键要点**:
|
||||
- ✅ **正确**: `setRefreshCallBack="@{viewModel::methodName}"` - 使用方法引用
|
||||
- ❌ **错误**: `setRefreshCallBack="@{() -> viewModel.methodName()}"` - Lambda 表达式会导致编译错误
|
||||
- 回调在输入框失去焦点时触发 (INPUT/SPINNER 类型)
|
||||
- 回调在日期选择完成后触发 (DATE 类型)
|
||||
- 适合实现输入完成后的自动查询功能
|
||||
|
||||
### 开发检查清单
|
||||
|
||||
#### ⚠️ 重要提醒
|
||||
|
||||
@@ -298,6 +298,12 @@ interface Api {
|
||||
@POST("eqm/uld/queryUld")
|
||||
suspend fun getUldDetails(@Query("id") id: String): BaseResultBean<ULDBean>
|
||||
|
||||
/**
|
||||
* 根据ULD编号查询ULD信息(新接口)
|
||||
*/
|
||||
@GET("eqm/uld/queryUld")
|
||||
suspend fun queryUldByCode(@Query("uld") uld: String): BaseResultBean<ULDBean>
|
||||
|
||||
/**
|
||||
* 获取运单信息 - 国际出
|
||||
*/
|
||||
@@ -1042,6 +1048,12 @@ interface Api {
|
||||
@POST("flt/queryFlightById")
|
||||
suspend fun getFlightDetails(@Query("id") id: String): BaseResultBean<FlightBean>
|
||||
|
||||
/**
|
||||
* 根据航班日期和航班号查询航班
|
||||
*/
|
||||
@POST("flt/queryFlight")
|
||||
suspend fun queryFlightByDateAndNo(@Body data: RequestBody): BaseResultBean<FlightBean>
|
||||
|
||||
/**
|
||||
* 获取航班目的站、经停站
|
||||
*/
|
||||
|
||||
@@ -49,6 +49,12 @@ class GjcBoxWeighingAddViewModel : BaseViewModel() {
|
||||
val netWeight = MutableLiveData("0") // 装机重(蓝色)
|
||||
val cargoWeight = MutableLiveData("0") // 货重(绿色)
|
||||
|
||||
// 需要自动查询的独立字段(用于监听输入变化)
|
||||
val carId = MutableLiveData("") // 架子车号
|
||||
val uldNo = MutableLiveData("") // ULD编号
|
||||
val flightNo = MutableLiveData("") // 航班号
|
||||
val flightDate = MutableLiveData("") // 航班日期
|
||||
|
||||
// 下拉选择数据源
|
||||
val passagewayList = MutableLiveData<List<KeyValue>>() // 通道号列表
|
||||
val piCloseList = MutableLiveData<List<KeyValue>>() // 探板收口列表
|
||||
@@ -56,6 +62,11 @@ class GjcBoxWeighingAddViewModel : BaseViewModel() {
|
||||
// 打印挂签
|
||||
val printTag = MutableLiveData(false)
|
||||
|
||||
// 标记位,避免重复查询
|
||||
private var lastQueriedFlight = ""
|
||||
private var lastQueriedCarId = ""
|
||||
private var lastQueriedUld = ""
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
@@ -95,7 +106,84 @@ class GjcBoxWeighingAddViewModel : BaseViewModel() {
|
||||
loadPiCloseList()
|
||||
|
||||
// 初始化航班日期为今天
|
||||
dataBean.value?.fdate = Date().formatDate()
|
||||
val today = Date().formatDate()
|
||||
flightDate.value = today
|
||||
dataBean.value?.fdate = today
|
||||
}
|
||||
|
||||
/**
|
||||
* 架子车号输入完成时调用
|
||||
*/
|
||||
fun onCarIdInputComplete() {
|
||||
val id = carId.value
|
||||
if (!id.isNullOrEmpty() && id != lastQueriedCarId) {
|
||||
lastQueriedCarId = id
|
||||
queryFlatcarInfo(id)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ULD编号输入完成时调用
|
||||
*/
|
||||
fun onUldNoInputComplete() {
|
||||
val uld = uldNo.value
|
||||
if (!uld.isNullOrEmpty() && uld != lastQueriedUld) {
|
||||
lastQueriedUld = uld
|
||||
queryUldInfo(uld)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 航班号输入完成时调用
|
||||
*/
|
||||
fun onFlightNoInputComplete() {
|
||||
queryFlightIfReady()
|
||||
}
|
||||
|
||||
/**
|
||||
* 航班日期输入完成时调用
|
||||
*/
|
||||
fun onFlightDateInputComplete() {
|
||||
// 清除查询标记,以便重新查询
|
||||
lastQueriedFlight = ""
|
||||
queryFlightIfReady()
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查航班日期和航班号,如果都有值则查询航班信息
|
||||
*/
|
||||
private fun queryFlightIfReady() {
|
||||
val fdate = flightDate.value
|
||||
val fno = flightNo.value
|
||||
if (!fdate.isNullOrEmpty() && !fno.isNullOrEmpty()) {
|
||||
val key = "$fdate-$fno"
|
||||
if (key != lastQueriedFlight) {
|
||||
lastQueriedFlight = key
|
||||
queryFlightInfo(fdate, fno)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询航班信息,自动填充目的港
|
||||
*/
|
||||
private fun queryFlightInfo(fdate: String, fno: String) {
|
||||
val params = mapOf(
|
||||
"fdate" to fdate,
|
||||
"fno" to fno,
|
||||
"countryType" to "1" // 国际航班
|
||||
).toRequestBody()
|
||||
|
||||
launchCollect({ NetApply.api.queryFlightByDateAndNo(params) }) {
|
||||
onSuccess = { result ->
|
||||
val flight = result.data
|
||||
if (flight != null) {
|
||||
dataBean.value = dataBean.value?.apply {
|
||||
fdest = flight.fdest
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,11 +234,16 @@ class GjcBoxWeighingAddViewModel : BaseViewModel() {
|
||||
* 航班日期点击
|
||||
*/
|
||||
fun flightDateClick(view: View) {
|
||||
Common.onYearMonthDay(view.context.getActivity(), dataBean.value?.fdate) { year, month, day ->
|
||||
Common.onYearMonthDay(view.context.getActivity(), flightDate.value) { year, month, day ->
|
||||
val calendar = Calendar.getInstance()
|
||||
calendar.set(year, month - 1, day)
|
||||
val date = calendar.time.formatDate()
|
||||
// 清除查询标记,以便重新查询
|
||||
lastQueriedFlight = ""
|
||||
flightDate.value = date
|
||||
dataBean.value = dataBean.value?.apply { fdate = date }
|
||||
// 日期选择完成后立即触发查询
|
||||
onFlightDateInputComplete()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,8 +265,10 @@ class GjcBoxWeighingAddViewModel : BaseViewModel() {
|
||||
* 重置按钮点击
|
||||
*/
|
||||
fun resetClick() {
|
||||
val today = Date().formatDate()
|
||||
|
||||
dataBean.value = GjcUldUseBean().apply {
|
||||
fdate = Date().formatDate()
|
||||
fdate = today
|
||||
}
|
||||
diBangWeight.value = "0"
|
||||
totalWeight.value = "0"
|
||||
@@ -181,6 +276,17 @@ class GjcBoxWeighingAddViewModel : BaseViewModel() {
|
||||
cargoWeight.value = "0"
|
||||
channel.value = ""
|
||||
printTag.value = false
|
||||
|
||||
// 重置独立字段
|
||||
carId.value = ""
|
||||
uldNo.value = ""
|
||||
flightNo.value = ""
|
||||
flightDate.value = today
|
||||
|
||||
// 重置查询标记
|
||||
lastQueriedFlight = ""
|
||||
lastQueriedCarId = ""
|
||||
lastQueriedUld = ""
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -189,6 +295,12 @@ class GjcBoxWeighingAddViewModel : BaseViewModel() {
|
||||
fun confirmClick() {
|
||||
val bean = dataBean.value ?: return
|
||||
|
||||
// 同步独立字段到 dataBean
|
||||
bean.carId = carId.value ?: ""
|
||||
bean.uld = uldNo.value ?: ""
|
||||
bean.fno = flightNo.value ?: ""
|
||||
bean.fdate = flightDate.value ?: ""
|
||||
|
||||
// 验证必填字段
|
||||
if (bean.carId.verifyNullOrEmpty("请输入架子车号")) return
|
||||
if (bean.uld.verifyNullOrEmpty("请输入ULD编号")) return
|
||||
@@ -241,14 +353,18 @@ class GjcBoxWeighingAddViewModel : BaseViewModel() {
|
||||
val content = data.getStringExtra(Constant.Result.CODED_CONTENT).noNull()
|
||||
when (requestCode) {
|
||||
Constant.RequestCode.ULD -> {
|
||||
// 更新独立字段
|
||||
uldNo.value = content
|
||||
dataBean.value = dataBean.value?.apply { uld = content }
|
||||
// 查询ULD信息,获取ULD自重
|
||||
queryUldInfo(content)
|
||||
// 扫码完成后立即查询
|
||||
onUldNoInputComplete()
|
||||
}
|
||||
Constant.RequestCode.CAR -> {
|
||||
// 更新独立字段
|
||||
carId.value = content
|
||||
dataBean.value = dataBean.value?.apply { carId = content }
|
||||
// 查询架子车信息,获取架子车自重
|
||||
queryFlatcarInfo(content)
|
||||
// 扫码完成后立即查询
|
||||
onCarIdInputComplete()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -258,7 +374,7 @@ class GjcBoxWeighingAddViewModel : BaseViewModel() {
|
||||
* 查询ULD信息
|
||||
*/
|
||||
private fun queryUldInfo(uldNo: String) {
|
||||
launchCollect({ NetApply.api.getUldDetails(uldNo) }) {
|
||||
launchCollect({ NetApply.api.queryUldByCode(uldNo) }) {
|
||||
onSuccess = { result ->
|
||||
val uldBean = result.data
|
||||
if (uldBean != null) {
|
||||
|
||||
@@ -57,11 +57,13 @@
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
android:id="@+id/carIdInput"
|
||||
hint='@{"请输入架子车号"}'
|
||||
setRefreshCallBack="@{viewModel::onCarIdInputComplete}"
|
||||
title='@{"架子车号"}'
|
||||
titleLength="@{5}"
|
||||
type="@{DataLayoutType.INPUT}"
|
||||
value='@={viewModel.dataBean.carId}'
|
||||
value='@={viewModel.carId}'
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" />
|
||||
@@ -88,11 +90,13 @@
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
android:id="@+id/uldNoInput"
|
||||
hint='@{"请输入ULD编号"}'
|
||||
setRefreshCallBack="@{viewModel::onUldNoInputComplete}"
|
||||
title='@{"ULD编号"}'
|
||||
titleLength="@{5}"
|
||||
type="@{DataLayoutType.INPUT}"
|
||||
value='@={viewModel.dataBean.uld}'
|
||||
value='@={viewModel.uldNo}'
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" />
|
||||
@@ -302,20 +306,23 @@
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
setRefreshCallBack="@{viewModel::onFlightDateInputComplete}"
|
||||
title='@{"航班日期"}'
|
||||
titleLength="@{5}"
|
||||
type="@{DataLayoutType.DATE}"
|
||||
value='@={viewModel.dataBean.fdate}'
|
||||
value='@={viewModel.flightDate}'
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
|
||||
android:id="@+id/flightNoInput"
|
||||
hint='@{"请输入航班号"}'
|
||||
setRefreshCallBack="@{viewModel::onFlightNoInputComplete}"
|
||||
title='@{"航班号"}'
|
||||
titleLength="@{5}"
|
||||
type="@{DataLayoutType.INPUT}"
|
||||
value='@={viewModel.dataBean.fno}'
|
||||
value='@={viewModel.flightNo}'
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="15dp"
|
||||
|
||||
Reference in New Issue
Block a user