feat: 进港舱单 新增/编辑
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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=删除
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<List<KeyValue>>()
|
||||
private var businessType = ""
|
||||
val businessType = MutableLiveData("")
|
||||
|
||||
// 包装类型 列表
|
||||
val packageTypeList = MutableLiveData<List<KeyValue>>()
|
||||
private var packageType = ""
|
||||
val packageType = MutableLiveData("")
|
||||
|
||||
// 代理列表
|
||||
val agentList = MutableLiveData<List<KeyValue>>()
|
||||
private var agent = ""
|
||||
val agent = MutableLiveData("")
|
||||
|
||||
// 特码列表
|
||||
val specialCodeList = MutableLiveData<List<KeyValue>>()
|
||||
private var specialCode = ""
|
||||
val specialCode = MutableLiveData("")
|
||||
|
||||
// 货物类型
|
||||
val goodsTypeList = MutableLiveData<List<KeyValue>>()
|
||||
private var goodsType = ""
|
||||
val goodsType = MutableLiveData("")
|
||||
|
||||
// 运单类型
|
||||
val waybillTypeList = MutableLiveData<List<KeyValue>>()
|
||||
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<String>(ConstantEvent.EVENT_REFRESH).emit("refresh")
|
||||
}
|
||||
|
||||
view.context.finish()
|
||||
} else {
|
||||
showToast(it.msg.noNull("保存失败"))
|
||||
}
|
||||
}
|
||||
|
||||
onComplete = {
|
||||
dismissLoading()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<String>(ConstantEvent.EVENT_REFRESH).emit("refresh")
|
||||
}
|
||||
refresh()
|
||||
} else {
|
||||
showToast(it.msg.noNull("删除失败"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.setNegativeButton("取消", null)
|
||||
.show()
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除按钮点击
|
||||
*/
|
||||
fun onDeleteClick() {
|
||||
val list = pageModel.rv?.commonAdapter()?.items as? List<GjjManifest> ?: return
|
||||
|
||||
Reference in New Issue
Block a user