diff --git a/module_base/src/main/java/com/lukouguoji/module_base/bean/GjjManifest.kt b/module_base/src/main/java/com/lukouguoji/module_base/bean/GjjManifest.kt index e3aa982..a70b966 100644 --- a/module_base/src/main/java/com/lukouguoji/module_base/bean/GjjManifest.kt +++ b/module_base/src/main/java/com/lukouguoji/module_base/bean/GjjManifest.kt @@ -1,6 +1,7 @@ package com.lukouguoji.module_base.bean import androidx.databinding.ObservableBoolean +import java.io.Serializable /** * 国际进港舱单Bean @@ -54,8 +55,9 @@ data class GjjManifest( var subCode: String = "", // 子代码 var unNumber: String = "", // 危险品编号 var activeId: Long = 0 // 活动ID -) { - // 选中状态(用于多选功能) +) : Serializable { + // 选中状态(用于多选功能)- 不参与序列化 + @Transient val checked: ObservableBoolean = ObservableBoolean(false) // 兼容现有API的isSelected属性 diff --git a/module_base/src/main/java/com/lukouguoji/module_base/common/Constant.kt b/module_base/src/main/java/com/lukouguoji/module_base/common/Constant.kt index 1c218b5..bf004f2 100644 --- a/module_base/src/main/java/com/lukouguoji/module_base/common/Constant.kt +++ b/module_base/src/main/java/com/lukouguoji/module_base/common/Constant.kt @@ -370,6 +370,9 @@ interface Constant { // 运单主键ID const val MAWB_ID = "maWbId" + // 舱单ID + const val MF_ID = "MF_ID" + // 运单前缀 const val PREFIX = "prefix" diff --git a/module_gjj/src/main/java/com/lukouguoji/gjj/activity/GjjManifestAddActivity.kt b/module_gjj/src/main/java/com/lukouguoji/gjj/activity/GjjManifestAddActivity.kt index 327de3f..823794b 100644 --- a/module_gjj/src/main/java/com/lukouguoji/gjj/activity/GjjManifestAddActivity.kt +++ b/module_gjj/src/main/java/com/lukouguoji/gjj/activity/GjjManifestAddActivity.kt @@ -9,6 +9,7 @@ import com.lukouguoji.gjj.databinding.ActivityGjjManifestAddBinding import com.lukouguoji.gjj.viewModel.GjjManifestAddViewModel import com.lukouguoji.module_base.base.BaseBindingActivity import com.lukouguoji.module_base.common.Constant +import com.lukouguoji.module_base.common.DetailsPageType import com.lukouguoji.module_base.ktx.noNull class GjjManifestAddActivity : @@ -19,21 +20,40 @@ class GjjManifestAddActivity : override fun viewModelClass() = GjjManifestAddViewModel::class.java override fun initOnCreate(savedInstanceState: Bundle?) { - setBackArrow("国际进港舱单新增") - viewModel.fid = intent.getStringExtra(Constant.Key.ID).noNull() - viewModel.departure.value = intent.getStringExtra(Constant.Key.DEPARTURE).noNull() - viewModel.destination.value = intent.getStringExtra(Constant.Key.DESTINATION).noNull() + // 动态设置标题 + val title = when { + viewModel.pageType.value == DetailsPageType.Modify -> "国际进港舱单编辑" + else -> "国际进港舱单新增" + } + setBackArrow(title) + binding.viewModel = viewModel + viewModel.initOnCreated(intent) } companion object { + /** + * 新增舱单 + */ @JvmStatic fun start(context: Context, fid: String = "", dep: String, dest: String) { val starter = Intent(context, GjjManifestAddActivity::class.java) + .putExtra(Constant.Key.PAGE_TYPE, DetailsPageType.Add.name) .putExtra(Constant.Key.ID, fid) .putExtra(Constant.Key.DEPARTURE, dep) .putExtra(Constant.Key.DESTINATION, dest) context.startActivity(starter) } + + /** + * 编辑舱单(通过Bean对象) + */ + @JvmStatic + fun startForEdit(context: Context, bean: com.lukouguoji.module_base.bean.GjjManifest) { + val starter = Intent(context, GjjManifestAddActivity::class.java) + .putExtra(Constant.Key.PAGE_TYPE, DetailsPageType.Modify.name) + .putExtra(Constant.Key.BEAN, bean) + context.startActivity(starter) + } } } \ No newline at end of file diff --git a/module_gjj/src/main/java/com/lukouguoji/gjj/holder/IntImpManifestViewHolder.kt b/module_gjj/src/main/java/com/lukouguoji/gjj/holder/IntImpManifestViewHolder.kt index a3b032a..1807e66 100644 --- a/module_gjj/src/main/java/com/lukouguoji/gjj/holder/IntImpManifestViewHolder.kt +++ b/module_gjj/src/main/java/com/lukouguoji/gjj/holder/IntImpManifestViewHolder.kt @@ -17,10 +17,20 @@ class IntImpManifestViewHolder(view: View) : binding.position = position binding.executePendingBindings() - // 添加图标点击事件 - 切换选择状态 + // 选中图标点击 - 切换选择状态 binding.ivIcon.setOnClickListener { bean.checked.set(!bean.checked.get()) binding.executePendingBindings() } + + // 编辑按钮点击 + binding.btnEdit.setOnClickListener { + clickListener?.onItemClick(position, 101) // 101=编辑 + } + + // 删除按钮点击 + binding.btnDelete.setOnClickListener { + clickListener?.onItemClick(position, 102) // 102=删除 + } } } diff --git a/module_gjj/src/main/java/com/lukouguoji/gjj/viewModel/GjjManifestAddViewModel.kt b/module_gjj/src/main/java/com/lukouguoji/gjj/viewModel/GjjManifestAddViewModel.kt index ef9fa31..84fcb0e 100644 --- a/module_gjj/src/main/java/com/lukouguoji/gjj/viewModel/GjjManifestAddViewModel.kt +++ b/module_gjj/src/main/java/com/lukouguoji/gjj/viewModel/GjjManifestAddViewModel.kt @@ -1,26 +1,52 @@ package com.lukouguoji.gjj.viewModel +import android.content.Intent import android.view.View import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.viewModelScope import com.lukouguoji.module_base.base.BaseViewModel +import com.lukouguoji.module_base.common.Constant +import com.lukouguoji.module_base.common.ConstantEvent +import com.lukouguoji.module_base.common.DetailsPageType import com.lukouguoji.module_base.http.net.NetApply +import com.lukouguoji.module_base.impl.FlowBus import com.lukouguoji.module_base.ktx.finish import com.lukouguoji.module_base.ktx.launchCollect +import com.lukouguoji.module_base.ktx.launchLoadingCollect import com.lukouguoji.module_base.ktx.noNull import com.lukouguoji.module_base.ktx.showToast import com.lukouguoji.module_base.ktx.toRequestBody import com.lukouguoji.module_base.ktx.verifyNullOrEmpty import com.lukouguoji.module_base.util.DictUtils import dev.utils.app.info.KeyValue +import kotlinx.coroutines.launch class GjjManifestAddViewModel : BaseViewModel() { + // 页面类型(必须用LiveData) + val pageType = MutableLiveData(DetailsPageType.Add) + + // 舱单ID(编辑时使用) + var mfId: Long = 0 + // 航班ID var fid: String = "" + // 航班日期 + val flightDate = MutableLiveData("") + + // 航班号 + val flightNo = MutableLiveData("") + + // 航程 + val range = MutableLiveData("") + // 运单号 val waybillNo = MutableLiveData("") + // UN编号 + val unNumber = MutableLiveData("") + // 运单件数 val waybillNum = MutableLiveData("") @@ -51,27 +77,27 @@ class GjjManifestAddViewModel : BaseViewModel() { // 业务类型 列表 val businessTypeList = MutableLiveData>() - private var businessType = "" + val businessType = MutableLiveData("") // 包装类型 列表 val packageTypeList = MutableLiveData>() - private var packageType = "" + val packageType = MutableLiveData("") // 代理列表 val agentList = MutableLiveData>() - private var agent = "" + val agent = MutableLiveData("") // 特码列表 val specialCodeList = MutableLiveData>() - private var specialCode = "" + val specialCode = MutableLiveData("") // 货物类型 val goodsTypeList = MutableLiveData>() - private var goodsType = "" + val goodsType = MutableLiveData("") // 运单类型 val waybillTypeList = MutableLiveData>() - private var waybillType = "" + val waybillType = MutableLiveData("") init { DictUtils.getAgentList(addAll = false) { @@ -105,45 +131,56 @@ class GjjManifestAddViewModel : BaseViewModel() { } /** - * 代理点击 + * 初始化(从Intent获取参数) */ - fun onAgentSelected(position: Int) { - agent = agentList.value?.get(position)?.value.noNull() + fun initOnCreated(intent: Intent) { + // 获取页面类型 + pageType.value = DetailsPageType.valueOf( + intent.getStringExtra(Constant.Key.PAGE_TYPE) ?: DetailsPageType.Add.name + ) + + // 获取航班ID + fid = intent.getStringExtra(Constant.Key.ID).noNull() + departure.value = intent.getStringExtra(Constant.Key.DEPARTURE).noNull() + destination.value = intent.getStringExtra(Constant.Key.DESTINATION).noNull() + + // 编辑模式:从Bean对象加载数据 + if (pageType.value == DetailsPageType.Modify) { + val bean = intent.getSerializableExtra(Constant.Key.BEAN) as? com.lukouguoji.module_base.bean.GjjManifest + if (bean != null) { + loadManifestFromBean(bean) + } + } } /** - * 特码点击 + * 从Bean对象加载数据(编辑模式) */ - fun onSpecialCodeSelected(position: Int) { - specialCode = specialCodeList.value?.get(position)?.value.noNull() - } + private fun loadManifestFromBean(manifest: com.lukouguoji.module_base.bean.GjjManifest) { + // 保存舱单ID + mfId = manifest.mfId + fid = manifest.fid.toString() - /** - * 包装类型点击 - */ - fun onPackageTypeSelected(position: Int) { - packageType = packageTypeList.value?.get(position)?.value.noNull() - } + // 填充表单字段 + waybillNo.value = manifest.wbNo + waybillNum.value = manifest.totalPc.toString() + actualNum.value = manifest.pc.toString() + actualWeight.value = manifest.weight.toString() + billingWeight.value = manifest.cashWeight.toString() + departure.value = manifest.origin + destination.value = manifest.dest + goodsNameCn.value = manifest.goodsCn + goodsNameEn.value = manifest.goods + unNumber.value = manifest.unNumber + remark.value = manifest.remark - /** - * 业务类型点击 - */ - fun onBusinessTypeSelected(position: Int) { - businessType = businessTypeList.value?.get(position)?.value.noNull() - } - - /** - * 货物类型点击 - */ - fun onGoodsTypeSelected(position: Int) { - goodsType = goodsTypeList.value?.get(position)?.value.noNull() - } - - /** - * 运单类型点击 - */ - fun onWaybillTypeSelected(position: Int) { - waybillType = waybillTypeList.value?.get(position)?.value.noNull() + // 设置下拉框选中值 + agent.value = manifest.agentCode + specialCode.value = manifest.spCode + packageType.value = manifest.packageType + businessType.value = manifest.businessType + goodsType.value = manifest.cargoType + waybillType.value = manifest.awbType } /** @@ -151,53 +188,62 @@ class GjjManifestAddViewModel : BaseViewModel() { */ fun onSaveClick(view: View) { if ((waybillNo.value.verifyNullOrEmpty("请输入运单号") - || agent.verifyNullOrEmpty("请选择代理") + || agent.value.verifyNullOrEmpty("请选择代理") || waybillNum.value.verifyNullOrEmpty("请输入运单件数") || actualNum.value.verifyNullOrEmpty("请输入实到数量") || goodsNameEn.value.verifyNullOrEmpty("请输入品名(英)") || actualWeight.value.verifyNullOrEmpty("请输入实到重量") - || packageType.verifyNullOrEmpty("请选择包装类型") + || packageType.value.verifyNullOrEmpty("请选择包装类型") ) ) { return } - showLoading() - launchCollect({ - NetApply.api.gjjManifestInsert( - mapOf( - "fid" to fid, - "wbNo" to waybillNo.value, - "agent" to agent, - "spCode" to specialCode, - "businessType" to businessType, - "awbpc" to waybillNum.value, - "pc" to actualNum.value, - "weight" to actualWeight.value, - "planweight" to billingWeight.value, - "packagecode" to packageType, - "dep" to departure.value, - "origin" to departure.value, - "dest" to destination.value, - "goods" to goodsNameEn.value, - "goodsCn" to goodsNameCn.value, - "awbType" to waybillType, - "cargoType" to goodsType, - "remark" to remark.value, - ).toRequestBody() - ) + + val params = mapOf( + "mfId" to if (pageType.value == DetailsPageType.Modify) mfId else null, + "fid" to fid, + "wbNo" to waybillNo.value, + "agent" to agent.value, + "spCode" to specialCode.value, + "businessType" to businessType.value, + "awbpc" to waybillNum.value, + "pc" to actualNum.value, + "weight" to actualWeight.value, + "planweight" to billingWeight.value, + "packagecode" to packageType.value, + "dep" to departure.value, + "origin" to departure.value, + "dest" to destination.value, + "goods" to goodsNameEn.value, + "goodsCn" to goodsNameCn.value, + "awbType" to waybillType.value, + "cargoType" to goodsType.value, + "unNumber" to unNumber.value, + "remark" to remark.value, + ).toRequestBody(removeEmptyOrNull = true) + + launchLoadingCollect({ + if (pageType.value == DetailsPageType.Modify) { + NetApply.api.gjjManifestUpdate(params) + } else { + NetApply.api.gjjManifestInsert(params) + } }) { onSuccess = { if (it.verifySuccess()) { - showToast("保存成功") + val successMsg = if (pageType.value == DetailsPageType.Modify) "修改成功" else "保存成功" + showToast(successMsg) + + // 发送刷新事件 + viewModelScope.launch { + FlowBus.with(ConstantEvent.EVENT_REFRESH).emit("refresh") + } + view.context.finish() } else { showToast(it.msg.noNull("保存失败")) } } - - onComplete = { - dismissLoading() - } } } diff --git a/module_gjj/src/main/java/com/lukouguoji/gjj/viewModel/IntImpManifestViewModel.kt b/module_gjj/src/main/java/com/lukouguoji/gjj/viewModel/IntImpManifestViewModel.kt index 51776b2..3393fbd 100644 --- a/module_gjj/src/main/java/com/lukouguoji/gjj/viewModel/IntImpManifestViewModel.kt +++ b/module_gjj/src/main/java/com/lukouguoji/gjj/viewModel/IntImpManifestViewModel.kt @@ -1,9 +1,11 @@ package com.lukouguoji.gjj.viewModel import android.app.Activity +import androidx.appcompat.app.AlertDialog import androidx.lifecycle.MutableLiveData import androidx.lifecycle.viewModelScope import com.lukouguoji.gjj.R +import com.lukouguoji.gjj.activity.GjjManifestAddActivity import com.lukouguoji.gjj.holder.IntImpManifestViewHolder import com.lukouguoji.module_base.base.BasePageViewModel import com.lukouguoji.module_base.bean.GjjManifest @@ -14,6 +16,7 @@ import com.lukouguoji.module_base.impl.FlowBus import com.lukouguoji.module_base.ktx.commonAdapter import com.lukouguoji.module_base.ktx.launchCollect import com.lukouguoji.module_base.ktx.launchLoadingCollect +import com.lukouguoji.module_base.ktx.noNull import com.lukouguoji.module_base.ktx.showToast import com.lukouguoji.module_base.ktx.toRequestBody import com.lukouguoji.module_base.model.ScanModel @@ -83,11 +86,73 @@ class IntImpManifestViewModel : BasePageViewModel() { * 新增按钮点击 */ fun onAddClick() { - showToast("新增功能开发中") + // 获取当前航班信息 + val fid = getCurrentFlightId() + + GjjManifestAddActivity.start( + context = getTopActivity(), + fid = fid, + dep = fdep.value ?: "", + dest = "" // 目的站暂时留空 + ) } /** - * 删除按钮点击 + * 获取当前航班ID(从列表第一项获取) + */ + private fun getCurrentFlightId(): String { + val firstItem = pageModel.rv?.commonAdapter()?.items?.firstOrNull() as? GjjManifest + return firstItem?.fid?.toString() ?: "" + } + + /** + * Item点击处理(侧滑按钮) + */ + override fun onItemClick(position: Int, type: Int) { + val bean = pageModel.rv?.commonAdapter()?.getItem(position) as? GjjManifest ?: return + + when (type) { + 101 -> { + // 编辑(传递整个Bean对象) + GjjManifestAddActivity.startForEdit(getTopActivity(), bean) + } + 102 -> { + // 删除 + deleteManifest(bean) + } + } + } + + /** + * 删除单个舱单 + */ + private fun deleteManifest(bean: GjjManifest) { + AlertDialog.Builder(getTopActivity()) + .setTitle("提示") + .setMessage("确定要删除运单号 ${bean.getWaybillNo()} 的舱单吗?") + .setPositiveButton("确定") { _, _ -> + val params = mapOf("mfId" to bean.mfId).toRequestBody() + + launchLoadingCollect({ NetApply.api.gjjManifestDelete(params) }) { + onSuccess = { + if (it.verifySuccess()) { + showToast("删除成功") + viewModelScope.launch { + FlowBus.with(ConstantEvent.EVENT_REFRESH).emit("refresh") + } + refresh() + } else { + showToast(it.msg.noNull("删除失败")) + } + } + } + } + .setNegativeButton("取消", null) + .show() + } + + /** + * 批量删除按钮点击 */ fun onDeleteClick() { val list = pageModel.rv?.commonAdapter()?.items as? List ?: return diff --git a/module_gjj/src/main/res/layout/activity_gjj_manifest_add.xml b/module_gjj/src/main/res/layout/activity_gjj_manifest_add.xml index 948696e..10ba9f2 100644 --- a/module_gjj/src/main/res/layout/activity_gjj_manifest_add.xml +++ b/module_gjj/src/main/res/layout/activity_gjj_manifest_add.xml @@ -1,532 +1,373 @@ + + + + - + android:background="@color/color_f2"> - + android:layout_height="match_parent" + android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + android:layout_weight="1"> - + - + - + + - + - + - + - + - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/module_gjj/src/main/res/layout/item_int_imp_manifest.xml b/module_gjj/src/main/res/layout/item_int_imp_manifest.xml index 9d97eb3..07ceec8 100644 --- a/module_gjj/src/main/res/layout/item_int_imp_manifest.xml +++ b/module_gjj/src/main/res/layout/item_int_imp_manifest.xml @@ -15,145 +15,41 @@ type="Integer" /> - + android:layout_marginBottom="10dp"> - - - - + + android:background="@drawable/bg_white_radius_8" + android:orientation="horizontal" + android:padding="15dp" + android:gravity="center_vertical"> - + + + + + android:layout_marginLeft="15dp" + android:layout_weight="1" + android:orientation="vertical"> - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -161,161 +57,272 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" completeSpace="@{5}" - android:text="实到件数:" + android:text="运单号:" android:textColor="@color/text_normal" android:textSize="16sp" /> + android:text="@{bean.getWaybillNo()}" + android:textColor="@color/colorPrimary" + android:textSize="18sp" + android:textStyle="bold" /> - - - - - - + - + + android:layout_weight="1" + android:gravity="center_vertical" + android:orientation="horizontal"> - + + + + + + + + android:layout_weight="1" + android:gravity="center_vertical" + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + + + + + + - + - + + android:layout_weight="1" + android:gravity="center_vertical" + android:orientation="horizontal"> - + + + + + + + + android:layout_weight="1" + android:gravity="center_vertical" + android:orientation="horizontal"> + + + + + + + + + + + + + + + + + + + + + + + + - + - + + android:layout_weight="1" + android:gravity="center_vertical" + android:orientation="horizontal"> - + - + - - - - - - - - - - - - - - - - - - - - + @@ -323,6 +330,28 @@ - + + + + + + + + + + + +