init: init proj

This commit is contained in:
2025-11-10 18:21:19 +08:00
commit b65b28ec9e
1796 changed files with 187617 additions and 0 deletions

View File

@@ -0,0 +1,196 @@
package com.lukouguoji.gjc.viewModel
import android.app.Activity.RESULT_OK
import android.content.Intent
import android.view.View
import androidx.lifecycle.MutableLiveData
import com.lukouguoji.gjc.R
import com.lukouguoji.gjc.activity.GjcBoxAssembleAddActivity
import com.lukouguoji.module_base.base.BasePageViewModel
import com.lukouguoji.module_base.bean.GjcBoxAssembleBean
import com.lukouguoji.module_base.common.Constant
import com.lukouguoji.module_base.http.net.NetApply
import com.lukouguoji.module_base.interfaces.IOnItemClickListener
import com.lukouguoji.module_base.ktx.commonAdapter
import com.lukouguoji.module_base.ktx.formatDate
import com.lukouguoji.module_base.ktx.getActivity
import com.lukouguoji.module_base.ktx.launchCollect
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.trim
import com.lukouguoji.module_base.model.ScanModel
import com.lukouguoji.module_base.util.Common
import com.lukouguoji.module_base.util.DictUtils
import dev.DevUtils
import dev.utils.app.info.KeyValue
import java.util.*
class BoxAssembleViewModel : BasePageViewModel(), IOnItemClickListener {
// 组装日期
val date = MutableLiveData(Date().formatDate())
// 平板车号
val car = MutableLiveData("")
// ULD编号
val uld = MutableLiveData("")
// 复磅状态
val status = MutableLiveData("")
// 截载状态
val cutStatus = MutableLiveData("0")
// 复磅状态列表
val statusList = DictUtils.reWeightStatusList
// 截载状态列表
val cutStatusList = DictUtils.cutStatusList
val count = MutableLiveData(0)
/**
* 获取数据
*/
override fun getData() {
launchCollect({
NetApply.api.getBoxList(
mapOf(
"carid" to car.value,
"uld" to uld.value,
"opdate" to date.value + " 00:00:00",
"cflag" to status.value,
"mcloseStatus" to cutStatus.value,
).trim().toRequestBody()
)
}) {
onSuccess = {
pageModel.handleDataList(it.data)
count.postValue(it.data?.size)
}
onComplete = {
pageModel.finishLoading()
}
}
}
/**
* 组装日期点击
*/
fun dateClick(view: View) {
Common.onYearMonthDay(view.context.getActivity(), date.value) { year, month, day ->
val calendar = Calendar.getInstance()
calendar.set(year, month - 1, day)
date.value = calendar.time.formatDate()
}
}
/**
* 平板车 扫描
*/
fun carScan(view: View) {
ScanModel.startScan(view.context.getActivity(), Constant.RequestCode.gjc_fubang_car_id)
}
/**
* ULD编号 扫描
*/
fun uldScan(view: View) {
ScanModel.startScan(view.context.getActivity(), Constant.RequestCode.gjc_fubang_uld_id)
}
/**
* 复磅状态 选中
*/
fun statusSelected(position: Int) {
status.value = statusList[position].value
}
/**
* 截载状态 点击
*/
fun cutStatusSelected(position: Int) {
cutStatus.value = cutStatusList[position].value
}
/**
* 搜索 点击
*/
fun searchClick(view: View) {
refresh()
}
/**
* 添加 点击
*/
fun addClick(view: View) {
GjcBoxAssembleAddActivity.start(view.context, "")
}
/**
* item 点击
*/
override fun onItemClick(position: Int, type: Int) {
val bean =
pageModel.rv!!.commonAdapter()!!.getItem(position) as GjcBoxAssembleBean
when (type) {
R.id.tv_details -> {
GjcBoxAssembleAddActivity.start(DevUtils.getTopActivity(), bean.locId.noNull())
}
R.id.tv_delete -> {
Common.secondConfirmDialog(
DevUtils.getTopActivity().getActivity(),
"确认删除?"
) { dialog ->
dialog.dismiss()
deleteItem(bean.locId.noNull())
}
}
else -> {}
}
}
private fun deleteItem(id: String) {
showLoading()
launchCollect({
NetApply.api.gjcBoxAssembleDelete(id)
}) {
onSuccess = {
if (it.verifySuccess()) {
showToast(it.msg.noNull("删除成功"))
refresh()
} else {
showToast(it.msg.noNull("删除失败"))
}
}
onComplete = {
dismissLoading()
}
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (resultCode == RESULT_OK && data != null) {
when (requestCode) {
Constant.RequestCode.gjc_fubang_car_id -> {
car.value =
data.getStringExtra(Constant.Result.CODED_CONTENT).noNull()
}
Constant.RequestCode.gjc_fubang_uld_id -> {
uld.value =
data.getStringExtra(Constant.Result.CODED_CONTENT).noNull()
}
else -> {}
}
}
}
}

View File

@@ -0,0 +1,588 @@
package com.lukouguoji.gjc.viewModel
import android.app.Activity.RESULT_OK
import android.content.Context
import android.content.Intent
import android.view.View
import androidx.lifecycle.MutableLiveData
import com.lukouguoji.gjc.R
import com.lukouguoji.gjc.activity.GjcUnLoadListActivity
import com.lukouguoji.gjc.dialog.BoxBatchDialogModel
import com.lukouguoji.module_base.bean.GcjBoxAddReqBean
import com.lukouguoji.gjc.dialog.GjcBoxAddSelectDialogModel
import com.lukouguoji.gjc.dialog.GjcUldSelectDialogModel
import com.lukouguoji.module_base.base.BasePageViewModel
import com.lukouguoji.module_base.bean.FlatcarBean
import com.lukouguoji.module_base.bean.GjcBoxAddListBean
import com.lukouguoji.module_base.bean.GjcWaybillBean
import com.lukouguoji.module_base.bean.JianBean
import com.lukouguoji.module_base.bean.ULDBean
import com.lukouguoji.module_base.common.Constant
import com.lukouguoji.module_base.common.ConstantEvent
import com.lukouguoji.module_base.http.net.NetApply
import com.lukouguoji.module_base.impl.FlowBus
import com.lukouguoji.module_base.interfaces.IOnItemClickListener
import com.lukouguoji.module_base.ktx.commonAdapter
import com.lukouguoji.module_base.ktx.finish
import com.lukouguoji.module_base.ktx.getActivity
import com.lukouguoji.module_base.ktx.handle
import com.lukouguoji.module_base.ktx.launchCollect
import com.lukouguoji.module_base.ktx.limit
import com.lukouguoji.module_base.ktx.loge
import com.lukouguoji.module_base.ktx.noNull
import com.lukouguoji.module_base.ktx.showToast
import com.lukouguoji.module_base.ktx.toJson
import com.lukouguoji.module_base.ktx.toMap
import com.lukouguoji.module_base.ktx.toRequestBody
import com.lukouguoji.module_base.model.ScanModel
import com.lukouguoji.module_base.util.Common
import dev.DevUtils
import dev.utils.common.NumberUtils
import java.util.LinkedList
import java.util.Queue
class GjcBoxAssembleAddViewModel : BasePageViewModel(), IOnItemClickListener {
val isAdd = MutableLiveData(true)
// 平板车或ULD
val plateOrUld = MutableLiveData<String>()
// 运单号或件号
val waybillOrPiece = MutableLiveData<String>()
val checkPBC = MutableLiveData(true)
val checkULD = MutableLiveData(false)
// 平板车信息
val flatcarBean = MutableLiveData<FlatcarBean>()
// ULD信息
val uldBean = MutableLiveData<ULDBean>()
// 插入数据ID
var insertId = ""
// 总件数
val totalCount = MutableLiveData(0)
// 总重量
val totalWeight = MutableLiveData(0.0)
///////////////////////////////////////////////////////////////////////////
// 方法区
///////////////////////////////////////////////////////////////////////////
/**
* 获取详细信息
*/
override fun getData() {
if (isAdd.value != true && insertId.isNotEmpty()) {
showLoading()
launchCollect({
NetApply.api
.getGjcBoxAssembleDetail(insertId)
}) {
onSuccess = {
if (it.verifySuccess()) {
val details = it.data!!
// 设置ULD和平板车信息
flatcarBean.value = details.flatCar
uldBean.value = details.eqmUld
// 刷新选中列表
val list = details.warehousePclistDTOList?.map { it.toGjcBoxAddListBean() }
?: emptyList()
pageModel.handleDataList(list)
computeTotal(list)
} else {
showToast(it.msg.noNull("获取数据失败"))
}
}
onComplete = {
dismissLoading()
}
}
}
}
/**
* 筛选点击
*/
fun onFilterClick(view: View) {
if (verifyCarULD()) {
GjcUnLoadListActivity.start(view.context)
}
}
/**
* 校验当前平板车和ULD是否都扫描成功
*/
private fun verifyCarULD(): Boolean {
if ((flatcarBean.value == null || flatcarBean.value?.carId.isNullOrEmpty()) && uldBean.value == null) {
showToast("请扫描平板车或ULD信息")
return false
}
return true
}
/**
* 校验当前是否已经空数据
*/
private fun verifyIsEmpty(): Boolean {
return (pageModel.rv?.commonAdapter()?.itemCount ?: 0) <= 0
}
/**
* 运单选中返回
*/
fun onWaybillListSelected(context: Context, list: List<GjcWaybillBean>) {
val adapter = pageModel.rv!!.commonAdapter()!!
val items = (adapter.items as List<GjcBoxAddListBean>).map { it.waybillBean }
// 筛选出来已有的运单信息,并弹窗做选择
val map = linkedMapOf<String, ArrayList<GjcWaybillBean>>()
// 添加选中的运单
list.forEach {
it.checked.set(false)
val waybillBeans = map[it.getWaybillCode()] ?: arrayListOf()
if (waybillBeans.find { b -> b.whid == it.whid } == null) {
waybillBeans.add(it)
}
map[it.getWaybillCode()] = waybillBeans
}
// 添加列表中已有的运单
items.forEach {
it.checked.set(false)
val waybillBeans = map[it.getWaybillCode()] ?: arrayListOf()
if (waybillBeans.find { b -> b.whid == it.whid } == null) {
waybillBeans.add(it)
}
map[it.getWaybillCode()] = waybillBeans
}
// 单条数据加入到列表
map.values.filter { it.size == 1 }
.forEach { l ->
val bean = l.first()
if (items.find { b -> b.getWaybillCode() == bean.getWaybillCode() } == null) {
loge("添加到列表 ${bean.getWaybillCode()}")
adapter.addItem(GjcBoxAddListBean(bean))
} else {
loge("列表中已经有了 ${bean.getWaybillCode()}")
}
}
// 多条数据转换为队列
val queue = LinkedList<List<GjcWaybillBean>>()
loge("数量列表 : ${map.values.map { it.size }.toJson()}")
map.values.filter { it.size > 1 }
.forEach { l ->
queue.offer(l)
}
loge("队列数量 : ${queue.size}")
showSelectDialog(context, queue)
computeTotal()
}
/**
* 展示选择弹窗
* 仅用于选择返回
*/
private fun showSelectDialog(context: Context, queue: Queue<List<GjcWaybillBean>>) {
val adapter = pageModel.rv!!.commonAdapter()!!
val list = queue.poll() ?: return
loge("展示选择弹窗 : ${list.size}")
GjcBoxAddSelectDialogModel(list) { bean ->
val items = adapter.items as List<GjcBoxAddListBean>
items.find { it.waybillBean.getWaybillCode() == bean.getWaybillCode() }
.handle({
// 如果查询到运单号一致的数据,则更新数据
if (it.waybillBean.whid != bean.whid) {
it.waybillBean = bean
adapter.notifyItemChanged(items.indexOf(it))
}
}) {
val listBean = GjcBoxAddListBean(bean)
adapter.addItem(listBean)
}
computeTotal()
showSelectDialog(context, queue)
}.show(context)
}
/**
* 确认 点击
*/
fun onConfirmClick(view: View) {
val adapter = pageModel.rv!!.commonAdapter()!!
val items = adapter.items as List<GjcBoxAddListBean>
if (items.isEmpty()) {
showToast("请扫描或选择运单")
return
}
if (!verifyCarULD()) {
return
}
Common.secondConfirmDialog(
DevUtils.getTopActivity(),
"是否确认组装?"
) { dialog ->
dialog.dismiss()
doConfirm(view, items)
}
}
private fun doConfirm(view: View, items: List<GjcBoxAddListBean>) {
val bean = GcjBoxAddReqBean(locId = insertId)
bean.setGjcBoxAddList(items, uldBean.value?.uldWeight.noNull("0.0"))
showLoading()
launchCollect({
val map = bean.toMap()
map["isAdd"] = isAdd.value!!
NetApply.api
.gjcBoxAddConfirm(map.toRequestBody())
}) {
onSuccess = {
if (it.verifySuccess()) {
showToast("操作成功")
FlowBus.with<Any>(ConstantEvent.GJC_BOX_ADD_SUCCESS)
.tryEmit(true)
view.context.finish()
} else {
showToast(it.msg.noNull("操作失败"))
}
}
onComplete = {
dismissLoading()
}
}
}
/**
* 平板或Uld 扫描 点击
*/
fun onPlateOrUldClick(view: View) {
if (!verifyIsEmpty()) {
showToast("请清理所有运单后再进行扫描")
return
}
ScanModel.startScan(
view.context.getActivity(),
Constant.RequestCode.gjc_fubang_car_id
)
}
/**
* 运单或件号 扫描 点击
*/
fun onWaybillOrPieceClick(view: View) {
if (!verifyCarULD()) {
return
}
ScanModel.startScan(
view.context.getActivity(),
Constant.RequestCode.WAYBILL
)
}
/**
* 条目点击事件
*/
override fun onItemClick(position: Int, type: Int) {
val adapter = pageModel.rv!!.commonAdapter()!!
val items = adapter.items as List<GjcBoxAddListBean>
when (type) {
R.id.tv_batch -> {
val bean = items[position].waybillBean
BoxBatchDialogModel(bean) {
addWaybillInfo(bean.getWaybillCode(), whid = bean.whid.noNull())
}.show(DevUtils.getTopActivity())
}
R.id.tv_delete_order -> {
Common.secondConfirmDialog(
DevUtils.getTopActivity(),
"是否确认删除该运单信息?"
) { dialog ->
adapter.removeItem(position)
computeTotal()
dialog.dismiss()
}
}
// 删件
R.id.tv_delete_matter -> {
val bean = items[position]
if (bean.jianList.filter { it.checked.get() }.isEmpty()) {
showToast("请先选择要删除的件号")
return
}
Common.secondConfirmDialog(
DevUtils.getTopActivity(),
"是否确认删除选中件号?"
) { dialog ->
bean.jianList.removeIf { it.checked.get() }
adapter.notifyItemChanged(position)
computeTotal()
dialog.dismiss()
}
}
R.id.iv_show -> {
if (items[position].show.get()) {
items[position].show.set(false)
} else {
items.forEachIndexed { index, bean ->
if (bean.show.get() != (index == position)) {
bean.show.set(index == position)
}
}
}
}
else -> {}
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (resultCode == RESULT_OK && data != null) {
when (requestCode) {
Constant.RequestCode.gjc_fubang_car_id -> {
val id = data.getStringExtra(Constant.Result.CODED_CONTENT).noNull()
plateOrUld.value = id
onPbcOrUldChange()
}
Constant.RequestCode.WAYBILL -> {
val id = data.getStringExtra(Constant.Result.CODED_CONTENT).noNull()
waybillOrPiece.value = id
onWaybillOrPieceChange()
}
else -> {}
}
}
}
/**
* 平板车或ULD 改变
*/
fun onPbcOrUldChange(focused: Boolean = false) {
if (focused) {
return
}
val id = plateOrUld.value ?: return
if (!verifyIsEmpty()) {
return
}
if (checkPBC.value!!) {
getFlatcarInfo(id)
} else {
getUldInfo(id)
}
}
/**
* 运单号或件号 改变
*/
fun onWaybillOrPieceChange(focused: Boolean = false) {
if (focused) {
return
}
val code = waybillOrPiece.value ?: return
if (NumberUtils.isNumber(code)) {
// 运单号
if (code.length == 11) {
addWaybillInfo(code)
}
// 运单号 + 件号
else if (code.length == 16) {
addWaybillInfo(code.substring(0, 11), code.substring(11))
}
}
if (code.length > 16) {
loge("件号 : $code")
addWaybillInfo(code, code)
}
}
/**
* 获取运单信息
* @param waybillCode 运单号
* @param jianCode 件号
* @param whid 仓库ID, 不为空,则视为更新
*/
private fun addWaybillInfo(waybillCode: String, jianCode: String = "", whid: String = "") {
// 非更新
if (whid.isEmpty()) {
val find =
(pageModel.rv!!.commonAdapter()!!.items as List<GjcBoxAddListBean>).find { it.waybillBean.getWaybillCode() == waybillCode }
if (find != null) {
if (jianCode.isEmpty()) {
showToast("该运单已在列表中")
} else {
addJian(jianCode, find)
}
return
}
}
launchCollect({
NetApply.api.getGjcWaybillInfo(waybillCode)
}) {
onSuccess = {
if (it.verifySuccess() && it.data != null && !it.data!!.whList.isNullOrEmpty()) {
val filter = it.data!!.whList!!.filter { bean -> bean.location.isNullOrEmpty() }
if (filter.isEmpty()) {
showToast("该运单已装配到设备上")
} else {
// 重新获取列表
val adapter = pageModel.rv!!.commonAdapter()!!
val list = adapter.items as List<GjcBoxAddListBean>
if (whid.isNotEmpty()) {
// 更新数据
filter.find { b -> b.whid == whid }?.let { b ->
list.find { l -> l.waybillBean.whid == whid }?.let { f ->
f.waybillBean = b
adapter.notifyItemChanged(list.indexOf(f))
addJian(jianCode, f)
}
}
} else if (filter.size > 1) {
GjcBoxAddSelectDialogModel(filter) {
val listBean = GjcBoxAddListBean(it)
adapter.addItem(listBean)
loge("新增数据 ${it.whid} , 添加件 : $jianCode")
addJian(jianCode, listBean)
}.show(DevUtils.getTopActivity())
} else {
val first = filter.first()
val listBean = GjcBoxAddListBean(first)
adapter.addItem(listBean)
loge("新增数据 ${first.whid} , 添加件 : $jianCode")
addJian(jianCode, listBean)
}
}
computeTotal()
} else {
showToast(it.msg.noNull("获取运单信息失败"))
}
}
}
}
/**
* 添加件号
*/
private fun addJian(code: String, bean: GjcBoxAddListBean) {
if (code.isEmpty()) {
computeTotal()
return
}
if (bean.jianList.find { b -> b.code == JianBean.getCode(code) } == null) {
bean.jianList.add(JianBean.create(code))
}
computeTotal()
}
/**
* 获取平板车数据
*/
private fun getFlatcarInfo(id: String) {
launchCollect({
NetApply.api
.getFlatcarInfo(id)
}) {
onSuccess = {
if (it.verifySuccess() && it.data != null) {
flatcarBean.value = it.data
insertCarOrULD()
} else {
showToast(it.msg.noNull("该平板车不存在"))
}
}
}
}
/**
* 获取ULD数据
*/
private fun getUldInfo(id: String) {
launchCollect({
NetApply.api
.getUldInfo(id)
}) {
onSuccess = {
if (it.verifySuccess() && it.data != null && it.data!!.isNotEmpty()) {
val data = it.data!!
if (data.size == 1) {
uldBean.value = data.first()
insertCarOrULD()
} else {
GjcUldSelectDialogModel(data) { b ->
uldBean.value = b
insertCarOrULD()
}.show()
}
} else {
showToast(it.msg.noNull("获取ULD信息失败"))
}
}
}
}
/**
* 插入数据
*/
private fun insertCarOrULD() {
val map = hashMapOf(
"carid" to flatcarBean.value?.carId,
"carweight" to flatcarBean.value?.carWeight,
"locId" to insertId,
"gjcLoading" to listOf(
mapOf(
"carid" to flatcarBean.value?.carId,
"locId" to insertId,
"maxweight" to flatcarBean.value?.maxWeight,
"maxvolume" to uldBean.value?.maxVolume,
"uld" to uldBean.value?.uld,
"uldflag" to uldBean.value?.uldFlag,
"uldweight" to uldBean.value?.uldWeight,
)
)
)
launchCollect({
NetApply.api
.gjcBoxInsert(map.toRequestBody())
}) {
onSuccess = {
if (!it.verifySuccess()) {
showToast(it.msg.noNull("插入数据失败"))
if (checkPBC.value!!) {
flatcarBean.value = FlatcarBean()
} else {
uldBean.value = ULDBean()
}
} else {
it.data?.locId?.let { id -> insertId = id }
}
}
}
}
/**
* 计算总数
*/
private fun computeTotal(list: List<GjcBoxAddListBean>? = null) {
val adapter = pageModel.rv!!.commonAdapter()!!
val items = list ?: adapter.items as List<GjcBoxAddListBean>
var count = 0
var weight = 0.0
items.forEach { bean ->
count += if (bean.jianList.isEmpty()) bean.waybillBean.pc.noNull("0")
.toInt() else bean.jianList.size
weight += (bean.waybillBean.weight.noNull().toDouble())
}
totalCount.value = count
totalWeight.value = weight.limit(2).toDouble()
}
}

View File

@@ -0,0 +1,219 @@
package com.lukouguoji.gjc.viewModel
import android.content.Context
import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.liveData
import com.alibaba.fastjson.JSONArray
import com.alibaba.fastjson.JSONObject
import com.lukouguoji.gjc.model.GjcFuBang
import com.lukouguoji.module_base.base.BaseViewModel
import com.lukouguoji.module_base.bean.BoxDetailsForCarIdBean
import com.lukouguoji.module_base.common.String.emptyToNull
import com.lukouguoji.module_base.http.net.NetApply
import com.lukouguoji.module_base.http.user.UserNetwork
import com.lukouguoji.module_base.ktx.launchCollect
import com.lukouguoji.module_base.ktx.noNull
import com.lukouguoji.module_base.ktx.showToast
import com.lukouguoji.module_base.ktx.toRequestBody
import kotlinx.coroutines.Dispatchers
class GjcFuBangViewModel : BaseViewModel() {
var plCloseList = JSONArray()
/**
* 接口返回复磅信息
*/
var fuBangInfoFormNetWork = JSONObject()
var fuBangInfo = GjcFuBang()
/**
* 集装器编号,查询集装器自重
*/
private val queryUldGjcReceiveLiveData = MutableLiveData<String>()
val queryUldGjcReceiveObserver =
Transformations.switchMap(queryUldGjcReceiveLiveData) { param ->
liveData(Dispatchers.IO) {
try {
var response = UserNetwork.queryUldGjcReceive(param)
emit(response)
} catch (e: Exception) {
Log.e("GoutStartViewModel", e.stackTraceToString())
}
}
}
fun queryUldGjcReceive(id: String) {
queryUldGjcReceiveLiveData.value = id
}
/**
* 托盘编号,查询托盘自重
*/
private val queryFlatcarGjcReceiveLiveData = MutableLiveData<String>()
val queryFlatcarGjcReceiveObserver =
Transformations.switchMap(queryFlatcarGjcReceiveLiveData) { param ->
liveData(Dispatchers.IO) {
try {
var response = UserNetwork.queryFlatcarGjcReceive(param)
emit(response)
} catch (e: Exception) {
Log.e("GoutStartViewModel", e.stackTraceToString())
}
}
}
// 板箱详情
val boxDetails = MutableLiveData<BoxDetailsForCarIdBean>()
fun queryFlatcarGjcReceive(id: String) {
queryFlatcarGjcReceiveLiveData.value = id
}
fun getBoxDetailsByCarId(carId: String) {
launchCollect({
NetApply.api.getGjcBoxAssembleByCarIdList(
mapOf(
"carid" to carId
).toRequestBody()
)
}) {
onSuccess = {
if (it.data != null) {
boxDetails.value = it.data
}
}
}
}
/**
* 完成复磅
*/
private val completedLiveData = MutableLiveData<JSONObject>()
val completedObserver = Transformations.switchMap(completedLiveData) { param ->
liveData(Dispatchers.IO) {
try {
val response = UserNetwork.completedGjcFuBang(param!!)
emit(response)
} catch (e: Exception) {
Log.e("GoutStartViewModel", e.stackTraceToString())
}
}
}
fun completed(gjcFuBang: GjcFuBang) {
val jsonObject = fuBangInfoFormNetWork
jsonObject["carId"] = gjcFuBang.carId
jsonObject["uld"] = gjcFuBang.uld
jsonObject["carWeight"] = gjcFuBang.carWeight
jsonObject["uldWeight"] = gjcFuBang.uldWeight
jsonObject["netWeight"] = gjcFuBang.netWeight
jsonObject["dgrCode"] = gjcFuBang.dgrCode
jsonObject["boardType"] = gjcFuBang.boardType
jsonObject["cargoWeight"] = gjcFuBang.cargoWeight
jsonObject["plClose"] = gjcFuBang.plClose
jsonObject["plCloseSize"] = gjcFuBang.plCloseSize
jsonObject["totalWeight"] = gjcFuBang.totalWeight
jsonObject["height"] = gjcFuBang.height
jsonObject["fdate"] = gjcFuBang.fdate
jsonObject["fno"] = gjcFuBang.fno
jsonObject["fdest"] = gjcFuBang.fdest
jsonObject["cargoType"] = gjcFuBang.cargoType
jsonObject["remark"] = gjcFuBang.remark
completedLiveData.value = jsonObject
}
fun onConfirmClick(context: Context, gjcFuBang: GjcFuBang, callBack: () -> Unit) {
showLoading()
launchCollect({
NetApply.api.gjcBoxWeighingSubmit(
mapOf(
"carid" to gjcFuBang.carId,
"carweight" to gjcFuBang.carWeight,
"locId" to boxDetails.value?.locId,
"totalWeight" to gjcFuBang.totalWeight,
"gjcLoading" to listOf(
mapOf(
"cargoweight" to gjcFuBang.cargoWeight,
"locId" to boxDetails.value?.locId,
"netweight" to gjcFuBang.netWeight,
"remark" to gjcFuBang.remark,
"uldweight" to gjcFuBang.uldWeight,
)
),
).toRequestBody()
)
}) {
onSuccess = {
if (it.verifySuccess()) {
showToast("提交成功")
callBack()
} else {
showToast(it.msg.noNull("提交失败"))
}
}
onComplete = {
dismissLoading()
}
}
}
/**
* 货物类型 下拉框
*/
var cargoList = JSONArray()
private val cargoLiveData = MutableLiveData<String>()
val cargoObserver = Transformations.switchMap(cargoLiveData) { _ ->
liveData(Dispatchers.IO) {
try {
var response = UserNetwork.cargoSelectGjc()
emit(response)
} catch (e: Exception) {
Log.e("GoutFuBangViewModel", e.stackTraceToString())
}
}
}
fun cargoSelect(type: String) {
cargoLiveData.value = type
}
/**
* 查询航班
*/
private val queryFlightLiveData = MutableLiveData<JSONObject>()
val queryFlightObserver = Transformations.switchMap(queryFlightLiveData) { param ->
liveData(Dispatchers.IO) {
try {
val response = UserNetwork.queryFlightMitInPack(param)
emit(response)
} catch (e: Exception) {
Log.e("GjcFuBangViewModel", e.stackTraceToString())
}
}
}
fun queryFlight(fdate: String, fno: String) {
val temObj = JSONObject()
temObj["countryType"] = null
temObj["fclose"] = null
temObj["fdate"] = fdate.emptyToNull()
temObj["fdep"] = null
temObj["fdest"] = null
temObj["fid"] = null
temObj["fno"] = fno.emptyToNull()
temObj["mclose"] = null
queryFlightLiveData.value = temObj
}
}
class CarParam(val carNo: String?, val userId: String?)

View File

@@ -0,0 +1,170 @@
package com.lukouguoji.gjc.viewModel
import android.app.Activity
import android.content.Intent
import android.view.View
import androidx.lifecycle.MutableLiveData
import com.lukouguoji.gjc.R
import com.lukouguoji.gjc.holder.GjcGoodsAddViewHolder
import com.lukouguoji.module_base.base.BasePageViewModel
import com.lukouguoji.module_base.bean.GjcGoodsAddBean
import com.lukouguoji.module_base.common.Constant
import com.lukouguoji.module_base.common.ConstantEvent
import com.lukouguoji.module_base.http.net.NetApply
import com.lukouguoji.module_base.impl.FlowBus
import com.lukouguoji.module_base.ktx.commonAdapter
import com.lukouguoji.module_base.ktx.finish
import com.lukouguoji.module_base.ktx.formatDate
import com.lukouguoji.module_base.ktx.getActivity
import com.lukouguoji.module_base.ktx.launchCollect
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
import com.lukouguoji.module_base.util.CheckUtil
import com.lukouguoji.module_base.util.Common
import java.util.Calendar
import java.util.Date
class GjcGoodsAddViewModel : BasePageViewModel() {
// 航班日期
var flightDate = MutableLiveData(Date().formatDate())
// 航班号
var flightNo = MutableLiveData<String>()
// 板车号
var truckNo = MutableLiveData<String>()
// ULD编号
var uldNo = MutableLiveData<String>()
val itemId = R.layout.item_goods_add
val itemHolder = GjcGoodsAddViewHolder::class.java
// 列表数量
val size = MutableLiveData(0)
override fun getData() {
launchCollect({
NetApply.api
.getGjcGoodsAddList(
mapOf(
"fdate" to flightDate.value,
"fno" to flightNo.value,
"carid" to truckNo.value,
"uld" to uldNo.value,
).toRequestBody()
)
}) {
onSuccess = {
pageModel.handleDataList(it.data)
size.value = it.data?.size ?: 0
}
}
}
override fun onItemClick(position: Int, type: Int) {
val adapter = pageModel.rv!!.commonAdapter()!!
val items = adapter.items
when (type) {
R.id.iv_show -> {
CheckUtil.handleSingleCheck(items as List<GjcGoodsAddBean>, "show", position, true)
adapter.notifyDataSetChanged()
}
R.id.tv_delete -> {
adapter.removeItem(position)
size.value = adapter.itemCount
}
else -> {}
}
}
/**
* 航班日期点击
*/
fun flightDateClick(view: View) {
Common.onYearMonthDay(view.context.getActivity(), flightDate.value) { year, month, day ->
val calendar = Calendar.getInstance()
calendar.set(year, month - 1, day)
flightDate.value = calendar.time.formatDate()
}
}
/**
* 板车号 扫描
*/
fun truckNoScan(view: View) {
ScanModel.startScan(view.context.getActivity(), Constant.RequestCode.CAR)
}
/**
* ULD编号 扫描
*/
fun uldNoScan(view: View) {
ScanModel.startScan(view.context.getActivity(), Constant.RequestCode.ULD)
}
/**
* 搜索点击
*/
fun searchClick(view: View) {
refresh()
}
/**
* 确认点击
*/
fun confirmClick(view: View) {
val list = pageModel.rv?.commonAdapter()?.items?.map { (it as GjcGoodsAddBean).locId }
?: emptyList()
if (list.isEmpty()) {
showToast("请先添加货物")
return
}
showLoading()
launchCollect({
NetApply.api
.gjcGoodsAdd(
mapOf(
"locIdList" to list
).toRequestBody()
)
}) {
onSuccess = {
if (it.verifySuccess()) {
FlowBus.with<Any>(ConstantEvent.GJC_HANDOVER_ADD_SUCCESS)
.tryEmit(true)
view.context.finish()
} else {
showToast(it.msg.noNull("操作失败"))
}
}
onComplete = {
dismissLoading()
}
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (resultCode == Activity.RESULT_OK && data != null) {
when (requestCode) {
Constant.RequestCode.CAR -> {
val id = data.getStringExtra(Constant.Result.CODED_CONTENT).noNull()
truckNo.value = id
}
Constant.RequestCode.ULD -> {
val id = data.getStringExtra(Constant.Result.CODED_CONTENT).noNull()
uldNo.value = id
}
else -> {}
}
}
}
}

View File

@@ -0,0 +1,140 @@
package com.lukouguoji.gjc.viewModel
import android.app.Activity
import android.content.Intent
import android.view.View
import androidx.lifecycle.MutableLiveData
import com.lukouguoji.gjc.R
import com.lukouguoji.gjc.activity.GjcGoodsAddActivity
import com.lukouguoji.gjc.activity.GjcGoodsManifestActivity
import com.lukouguoji.module_base.base.BasePageViewModel
import com.lukouguoji.module_base.bean.GjcGoodsBean
import com.lukouguoji.module_base.common.Constant
import com.lukouguoji.module_base.http.net.NetApply
import com.lukouguoji.module_base.interfaces.IOnItemClickListener
import com.lukouguoji.module_base.ktx.commonAdapter
import com.lukouguoji.module_base.ktx.formatDate
import com.lukouguoji.module_base.ktx.getActivity
import com.lukouguoji.module_base.ktx.launchCollect
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
import com.lukouguoji.module_base.util.Common
import dev.DevUtils
import java.util.Calendar
import java.util.Date
class GjcGoodsListViewModel : BasePageViewModel(), IOnItemClickListener {
// 航班日期
var flightDate = MutableLiveData(Date().formatDate())
// 航班号
var flightNo = MutableLiveData<String>()
// 板车号
var truckNo = MutableLiveData<String>()
// ULD编号
var uldNo = MutableLiveData<String>()
var count = MutableLiveData(0)
override fun getData() {
launchCollect({
NetApply.api
.gjcHandoverList(
mapOf(
"carid" to truckNo.value,
"fdate" to flightDate.value,
"fno" to flightNo.value,
"uld" to uldNo.value,
).toRequestBody()
)
}) {
onSuccess = {
if (it.verifySuccess()) {
pageModel.handleDataList(it.data ?: emptyList())
count.postValue(it.data?.size)
} else {
showToast(it.msg.noNull("获取数据失败"))
count.postValue(0)
}
}
}
}
/**
* 航班日期点击
*/
fun flightDateClick(view: View) {
Common.onYearMonthDay(view.context.getActivity(), flightDate.value) { year, month, day ->
val calendar = Calendar.getInstance()
calendar.set(year, month - 1, day)
flightDate.value = calendar.time.formatDate()
}
}
/**
* 板车号 扫描
*/
fun truckNoScan(view: View) {
ScanModel.startScan(view.context.getActivity(), Constant.RequestCode.CAR)
}
/**
* ULD编号 扫描
*/
fun uldNoScan(view: View) {
ScanModel.startScan(view.context.getActivity(), Constant.RequestCode.ULD)
}
/**
* 搜索点击
*/
fun searchClick(view: View) {
refresh()
}
/**
* 添加点击
*/
fun addClick(view: View) {
GjcGoodsAddActivity.start(view.context)
}
/**
* item点击
*/
override fun onItemClick(position: Int, type: Int) {
val bean = pageModel.rv!!.commonAdapter()!!.getItem(position) as GjcGoodsBean
when (type) {
R.id.tv_details -> {
GjcGoodsManifestActivity.start(DevUtils.getTopActivity(), bean.movID.noNull())
}
else -> {}
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (resultCode == Activity.RESULT_OK && data != null) {
when (requestCode) {
Constant.RequestCode.CAR -> {
val id = data.getStringExtra(Constant.Result.CODED_CONTENT).noNull()
truckNo.value = id
}
Constant.RequestCode.ULD -> {
val id = data.getStringExtra(Constant.Result.CODED_CONTENT).noNull()
uldNo.value = id
}
else -> {}
}
}
}
}

View File

@@ -0,0 +1,122 @@
package com.lukouguoji.gjc.viewModel
import android.content.Context
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.view.View
import androidx.lifecycle.MutableLiveData
import com.lukouguoji.gjc.R
import com.lukouguoji.gjc.holder.GjcGoodsManifestViewHolder
import com.lukouguoji.module_base.base.BasePageViewModel
import com.lukouguoji.module_base.bean.GjcGoodsDetailsBean
import com.lukouguoji.module_base.common.ConstantEvent
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.noNull
import com.lukouguoji.module_base.ktx.showToast
import com.lukouguoji.module_base.ktx.toBoolean
import com.lukouguoji.module_base.ui.signature.SignatureActivity
import dev.utils.common.cipher.Base64
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.MultipartBody
import okhttp3.RequestBody.Companion.asRequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import java.io.File
class GjcGoodsManifestViewModel : BasePageViewModel() {
var movID = ""
val itemLayoutId = R.layout.item_goods_manifest
val itemViewHolder = GjcGoodsManifestViewHolder::class.java
// 签名
val signature = MutableLiveData<String>()
// 返回签名
val resultSign = MutableLiveData<Bitmap>()
// 详情
val dataBean = MutableLiveData<GjcGoodsDetailsBean>()
///////////////////////////////////////////////////////////////////////////
// 方法区
///////////////////////////////////////////////////////////////////////////
override fun getData() {
showLoading()
launchCollect({
NetApply.api
.getGjcGoodsDetail(movID)
}) {
onSuccess = {
if (it.verifySuccess() && it.data != null) {
val data = it.data!!
pageModel.handleDataList(data.loadingHandoverList)
dataBean.postValue(data)
// 已交接 & 有签名
if (data.isCheck.toBoolean() && !data.sign.isNullOrEmpty()) {
val bytes = Base64.decode(
data.sign!!,
Base64.DEFAULT
)
val bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.size)
resultSign.postValue(bitmap)
}
} else {
showToast(it.msg.noNull("获取数据失败"))
}
}
onComplete = {
dismissLoading()
}
}
}
/**
* 打印点击
*/
fun printClick(view: View) {
view.context.finish()
}
/**
* 提交签名
*/
fun submitSignature(context: Context, signature: String) {
launchCollect({
val file = File(signature)
val body = file.asRequestBody("multipart/form-data".toMediaTypeOrNull())
val part = MultipartBody.Part.createFormData("file", file.name, body)
NetApply.api
.gjcGoodsSubmitSignature(
part, mutableMapOf(
"movID " to movID.toRequestBody("multipart/form-data".toMediaTypeOrNull()),
)
)
}) {
onSuccess = {
if (it.verifySuccess()) {
showToast(it.msg.noNull("提交成功"))
FlowBus.with<Any>(ConstantEvent.GJC_HANDOVER_SIGNATURE_SUCCESS)
.tryEmit(true)
context.finish()
} else {
showToast(it.msg.noNull("提交失败"))
}
}
}
}
/**
* 签字点击
*/
fun signClick(view: View) {
if (dataBean.value?.isCheck?.toBoolean() == false) {
SignatureActivity.start(view.context)
}
}
}

View File

@@ -0,0 +1,48 @@
package com.lukouguoji.gjc.viewModel
import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import androidx.lifecycle.liveData
import com.alibaba.fastjson.JSONObject
import com.lukouguoji.module_base.http.user.UserNetwork
import kotlinx.coroutines.Dispatchers
class GjcQueryInfoViewModel : ViewModel() {
private val logName = "GncQueryInfoViewModel"
var wayBillInfo = JSONObject()
var wbNo: String? = null
/**
* 查询详情
*/
inner class WaybillParam(val wbId: Int, val wbNo: String?)
private val wbIdData = MutableLiveData<WaybillParam>()
val waybillLiveData = Transformations.switchMap(wbIdData) { param ->
liveData(Dispatchers.IO) {
try {
var response = JSONObject()
if (param.wbId != -9999) {
response = UserNetwork.searchByIdGjcQuery(param.wbId)
} else if (param.wbNo != null) {
response = UserNetwork.searchByWbNoGncQuery(param.wbNo)
} else {
}
emit(response)
} catch (e: Exception) {
Log.e(logName, e.stackTraceToString())
}
}
}
fun queryWaybillById(wbId: Int, wbNo: String?) {
wbIdData.value = WaybillParam(wbId, wbNo)
}
}

View File

@@ -0,0 +1,168 @@
package com.lukouguoji.gjc.viewModel
import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import androidx.lifecycle.liveData
import com.alibaba.fastjson.JSONArray
import com.alibaba.fastjson.JSONObject
import com.lukouguoji.module_base.common.String.emptyToNull
import com.lukouguoji.module_base.http.user.UserNetwork
import kotlinx.coroutines.Dispatchers
class GjcQueryListViewModel : ViewModel() {
private val searchParam = MutableLiveData<JSONObject>()
val searchParamLive = Transformations.switchMap(searchParam) { param ->
liveData(Dispatchers.IO) { try {
val response = UserNetwork.searchGjcQuery(param)
emit(response)
} catch (e: Exception) {
Log.e("GoutCollectionViewModel", e.stackTraceToString())
}
}
}
fun search(
limit: Int,
page: Int,
carrier: String,//承运人
agentCode: String,//代理人
awbType: String,//运单类型
beginDate: String,
endDate: String,
fdate: String,//航班日期
fno: String,//航班编码
dest: String,//目的港
location: String,//舱位
range: String,
businessType: String,//业务类型
locStatus: String,//是否仓舱单
wbNo: String,
spCode: String, //特码
goods: String //商品名
) {
val param = JSONObject()
param["limit"] = limit
param["page"] = page
param["carrier"] = carrier.emptyToNull()
param["agentCode"] = agentCode.emptyToNull()
param["awbType"] = awbType.emptyToNull()
param["beginDate"] = beginDate.emptyToNull()
param["endDate"] = endDate.emptyToNull()
param["fdate"] = fdate.emptyToNull()
param["dest"] = dest.emptyToNull()
param["fno"] = fno.emptyToNull()
param["location"] = location.emptyToNull()
param["range"] = range.emptyToNull()
param["businessType"] = businessType.emptyToNull()
param["locStatus"] = locStatus.emptyToNull()
param["wbNo"] = wbNo.emptyToNull()
param["spCode"] = spCode.emptyToNull()
param["goods"] = goods.emptyToNull()
searchParam.value = param
}
/**
* 数据汇总
*/
val summaryObserver = Transformations.switchMap(searchParam) { param ->
liveData(Dispatchers.IO) {
try {
val response = UserNetwork.totalGjcQuery(param)
emit(response)
} catch (e: Exception) {
Log.e("GoutCollectionViewModel", e.stackTraceToString())
}
}
}
/**
* 代理人
*/
var agentCodeList = JSONArray()
private val agentCodeLiveData = MutableLiveData<String>()
fun agentCode(time: String) {
agentCodeLiveData.value = time
}
val agentCodeObserver = Transformations.switchMap(agentCodeLiveData) { _ ->
liveData(Dispatchers.IO) {
try {
var response = UserNetwork.agentCodeGjc()
emit(response)
} catch (e: Exception) {
Log.e("GoutStartViewModel", e.stackTraceToString())
}
}
}
/**
* 业务类型
*/
var businessList = JSONArray()
private val businessLiveData = MutableLiveData<String>()
fun business(type: String) {
businessLiveData.value = type
}
val businessObserver = Transformations.switchMap(businessLiveData) { type ->
liveData(Dispatchers.IO) {
try {
var response = UserNetwork.business(type)
emit(response)
} catch (e: Exception) {
Log.e("GoutStartViewModel", e.stackTraceToString())
}
}
}
/**
* 特码
*/
var specialCodeList = JSONArray()
private val specialCodeLiveData = MutableLiveData<String>()
fun specialCode(time: String) {
specialCodeLiveData.value = time
}
val specialCodeObserver = Transformations.switchMap(specialCodeLiveData) { _ ->
liveData(Dispatchers.IO) {
try {
var response = UserNetwork.specialCode()
emit(response)
} catch (e: Exception) {
Log.e("GoutStartViewModel", e.stackTraceToString())
}
}
}
/**
* 运单类型
*/
var awbList = JSONArray()
private val awbLiveData = MutableLiveData<String>()
fun awb(type: String) {
awbLiveData.value = type
}
val awbObserver = Transformations.switchMap(awbLiveData) { param ->
liveData(Dispatchers.IO) {
try {
var response = UserNetwork.awb(param)
emit(response)
} catch (e: Exception) {
Log.e("GoutStartViewModel", e.stackTraceToString())
}
}
}
}

View File

@@ -0,0 +1,38 @@
package com.lukouguoji.gjc.viewModel
import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import androidx.lifecycle.liveData
import com.alibaba.fastjson.JSONObject
import com.lukouguoji.module_base.http.user.UserNetwork
import kotlinx.coroutines.Dispatchers
class GjcReceiveListViewModel : ViewModel() {
private val searchParam = MutableLiveData<JSONObject>()
val searchParamLive = Transformations.switchMap(searchParam) { param ->
liveData(Dispatchers.IO) {
try {
val response = UserNetwork.searchGjcReceive(param)
emit(response)
} catch (e: Exception) {
Log.e("GoutCollectionViewModel", e.stackTraceToString())
}
}
}
fun search(limit: Int, page: Int, text: String) {
val param = JSONObject()
param["limit"] = limit
param["page"] = page
param["text"] = text
searchParam.value = param
}
}

View File

@@ -0,0 +1,219 @@
package com.lukouguoji.gjc.viewModel
import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import androidx.lifecycle.liveData
import com.alibaba.fastjson.JSONArray
import com.alibaba.fastjson.JSONObject
import com.lukouguoji.gjc.model.GjcStartReceiveWaybill
import com.lukouguoji.module_base.http.user.UserNetwork
import kotlinx.coroutines.Dispatchers
class GjcStartReceiveViewModel : ViewModel() {
var receiveWaybill = GjcStartReceiveWaybill()
var waybillFormNetWork = JSONObject()
var agentCodeList = JSONArray()
var businessList = JSONArray()
var specialCodeList = JSONArray()
var dgrDetailList = JSONArray()
private val wbIdData = MutableLiveData<WaybillParam>()
private val businessLiveData = MutableLiveData<String>()
private val specialCodeLiveData = MutableLiveData<String>()
inner class WaybillParam(val wbId: Int, val wbNo: String?)
val waybillLiveData = Transformations.switchMap(wbIdData) { param ->
liveData(Dispatchers.IO) {
try {
var response = JSONObject()
if (param.wbId != -9999) {
response = UserNetwork.queryWbByIdGjcReceive(param.wbId)
} else if (param.wbNo != null) {
response = UserNetwork.queryWbByNoGjcReceive(param.wbNo)
} else {
}
emit(response)
} catch (e: Exception) {
Log.e("GoutStartViewModel", e.stackTraceToString())
}
}
}
fun queryWaybillById(wbId: Int, wbNo: String?) {
wbIdData.value = WaybillParam(wbId, wbNo)
}
fun business(type: String) {
businessLiveData.value = type
}
val businessObserver = Transformations.switchMap(businessLiveData) { type ->
liveData(Dispatchers.IO) {
try {
var response = UserNetwork.business(type)
emit(response)
} catch (e: Exception) {
Log.e("GoutStartViewModel", e.stackTraceToString())
}
}
}
fun specialCode(time: String) {
specialCodeLiveData.value = time
}
val specialCodeObserver = Transformations.switchMap(specialCodeLiveData) { _ ->
liveData(Dispatchers.IO) {
try {
var response = UserNetwork.specialCode()
emit(response)
} catch (e: Exception) {
Log.e("GoutStartViewModel", e.stackTraceToString())
}
}
}
private val completedLiveData = MutableLiveData<JSONObject>()
val completedObserver = Transformations.switchMap(completedLiveData) { param ->
liveData(Dispatchers.IO) {
try {
val response = UserNetwork.completedGjcReceive(param!!)
emit(response)
} catch (e: Exception) {
Log.e("GoutStartViewModel", e.stackTraceToString())
}
}
}
fun completed(waybill: GjcStartReceiveWaybill) {
var prefix: String = ""
var no: String = ""
val jsonObject = waybillFormNetWork
jsonObject["maWbId"] = waybill.maWbId
jsonObject["wbNo"] = waybill.wbNo
jsonObject["agentCode"] = waybill.agentCode
jsonObject["goods"] = waybill.goods
jsonObject["spCode"] = waybill.spCode
jsonObject["businessType"] = waybill.businessType
jsonObject["awbType"] = waybill.awbType
jsonObject["pc"] = waybill.pc
jsonObject["weight"] = waybill.weight
jsonObject["volume"] = waybill.volume
jsonObject["arrivePc"] = waybill.arrivePc
jsonObject["arriveWeight"] = waybill.arriveWeight
jsonObject["arriveVolume"] = waybill.arriveVolume
jsonObject["activeId"] = waybill.activeId
jsonObject["remark"] = waybill.remark
jsonObject["dep"] = waybill.dep
jsonObject["dest"] = waybill.dest
jsonObject["dest1"] = waybill.dest1
jsonObject["by1"] = waybill.by1
jsonObject["checkIn"] = waybill.checkIn
completedLiveData.value = jsonObject
}
/**
* 集装器编号,查询集装器自重
*/
private val queryUldGjcReceiveLiveData = MutableLiveData<String>()
val queryUldGjcReceiveObserver = Transformations.switchMap(queryUldGjcReceiveLiveData) { param ->
liveData(Dispatchers.IO) {
try {
var response = UserNetwork.queryUldGjcReceive(param)
emit(response)
} catch (e: Exception) {
Log.e("GoutStartViewModel", e.stackTraceToString())
}
}
}
fun queryUldGjcReceive(id: String) {
queryUldGjcReceiveLiveData.value = id
}
/**
* 集装器编号校验ULD重量
*/
private val updateUldGjcReceiveLiveData = MutableLiveData<JSONObject>()
val updateUldGjcReceiveObserver = Transformations.switchMap(updateUldGjcReceiveLiveData) { param ->
liveData(Dispatchers.IO) {
try {
var response = UserNetwork.updateUldGjcReceive(param)
emit(response)
} catch (e: Exception) {
Log.e("GoutStartViewModel", e.stackTraceToString())
}
}
}
fun updateUldGjcReceive(uld: String, uldWeight: Double) {
val param = JSONObject()
param["uld"] = uld
param["uldWeight"] = uldWeight
updateUldGjcReceiveLiveData.value = param
}
/**
* 托盘编号,查询托盘自重
*/
private val queryFlatcarGjcReceiveLiveData = MutableLiveData<String>()
val queryFlatcarGjcReceiveObserver = Transformations.switchMap(queryFlatcarGjcReceiveLiveData) { param ->
liveData(Dispatchers.IO) {
try {
var response = UserNetwork.queryFlatcarGjcReceive(param)
emit(response)
} catch (e: Exception) {
Log.e("GoutStartViewModel", e.stackTraceToString())
}
}
}
fun queryFlatcarGjcReceive(id: String) {
queryFlatcarGjcReceiveLiveData.value = id
}
/**
* 托盘编号,校验平板车重量
*/
private val updateFlatcarGjcReceiveLiveData = MutableLiveData<JSONObject>()
val updateFlatcarGjcReceiveObserver = Transformations.switchMap(updateFlatcarGjcReceiveLiveData) { param ->
liveData(Dispatchers.IO) {
try {
var response = UserNetwork.updateFlatcarGjcReceive(param)
emit(response)
} catch (e: Exception) {
Log.e("GoutStartViewModel", e.stackTraceToString())
}
}
}
fun updateFlatcarGjcReceive(carId: String, carWeight: Double) {
val param = JSONObject()
param["carId"] = carId
param["carWeight"] = carWeight
updateFlatcarGjcReceiveLiveData.value = param
}
}

View File

@@ -0,0 +1,160 @@
package com.lukouguoji.gjc.viewModel
import android.view.View
import androidx.lifecycle.MutableLiveData
import com.lukouguoji.gjc.R
import com.lukouguoji.gjc.holder.GjcUnLoadViewHolder
import com.lukouguoji.module_base.base.BasePageViewModel
import com.lukouguoji.module_base.bean.GjcUnLoadListBean
import com.lukouguoji.module_base.bean.GjcWaybillBean
import com.lukouguoji.module_base.common.Constant
import com.lukouguoji.module_base.common.ConstantEvent
import com.lukouguoji.module_base.http.net.NetApply
import com.lukouguoji.module_base.impl.FlowBus
import com.lukouguoji.module_base.ktx.commonAdapter
import com.lukouguoji.module_base.ktx.finish
import com.lukouguoji.module_base.ktx.getActivity
import com.lukouguoji.module_base.ktx.launchCollect
import com.lukouguoji.module_base.ktx.loge
import com.lukouguoji.module_base.ktx.showToast
import com.lukouguoji.module_base.ktx.toRequestBody
import com.lukouguoji.module_base.model.ScanModel
import com.lukouguoji.module_base.util.CheckUtil
import com.lukouguoji.module_base.util.DictUtils
import dev.utils.app.info.KeyValue
class GjcUnLoadListViewModel : BasePageViewModel() {
// 目的港
val destPort = MutableLiveData("")
// 代理
val agent = MutableLiveData("")
// 特码
val specialCode = MutableLiveData("")
// 运单号
val waybillNo = MutableLiveData("")
val itemLayoutId = R.layout.item_gjc_un_load
val itemViewHolder = GjcUnLoadViewHolder::class.java
val agentList = MutableLiveData<List<KeyValue>>(emptyList())
val specialCodeList = MutableLiveData<List<KeyValue>>(emptyList())
// 选中条数
val count = MutableLiveData(0)
init {
DictUtils.getAgentList {
agentList.postValue(it)
}
DictUtils.getSpecialCodeList(flag = 1) {
specialCodeList.postValue(it)
}
}
/**
* 获取列表数据
*/
override fun getData() {
launchCollect({
NetApply.api
.getGjcUnloadWaybillList(
mapOf(
"dest" to destPort.value,
"agent" to agent.value,
"spCode" to specialCode.value,
"wbNo" to waybillNo.value,
).toRequestBody()
)
}) {
onSuccess = {
loge("获取列表数据成功 ${it.data?.size}")
pageModel.handleDataList(it.data)
}
onComplete = {
pageModel.finishLoading()
}
}
}
/**
* 搜索点击
*/
fun searchClick(view: View) {
refresh()
}
/**
* 运单号 扫描
*/
fun waybillNoScanClick(view: View) {
ScanModel.startScan(view.context.getActivity(), Constant.RequestCode.WAYBILL)
}
/**
* 按钮 点击
*/
fun btnClick(view: View) {
val list =
(pageModel.rv?.commonAdapter()?.items ?: emptyList()) as List<GjcWaybillBean>
val checkedList = list.filter { it.checked.get() }
if (checkedList.isEmpty()) {
showToast("请先选择运单")
return
}
FlowBus.with<List<GjcWaybillBean>>(ConstantEvent.GJC_UNLOAD_LIST_CHECKED)
.tryEmit(checkedList)
view.context.finish()
}
/**
* 代理 选中
*/
fun agentSelected(position: Int) {
agent.value = agentList.value?.get(position)?.value
}
/**
* 特码 选中
*/
fun specialCodeSelected(position: Int) {
specialCode.value = specialCodeList.value?.get(position)?.value
}
/**
* 全选 点击
*/
fun checkAllClick(view: View) {
CheckUtil.handleAllCheck(
pageModel.rv?.commonAdapter()?.items as? List<GjcWaybillBean> ?: emptyList()
)
computeSelectCount()
}
/**
* item 点击
*/
override fun onItemClick(position: Int, type: Int) {
when (type) {
R.id.iv_icon -> {
pageModel.rv?.commonAdapter()?.getItem(position)?.let { bean ->
(bean as GjcWaybillBean).checked.set(!bean.checked.get())
}
computeSelectCount()
}
else -> {}
}
}
private fun computeSelectCount() {
val list =
(pageModel.rv?.commonAdapter()?.items ?: emptyList()) as List<GjcWaybillBean>
count.postValue(list.filter { it.checked.get() }.size)
}
}

View File

@@ -0,0 +1,42 @@
package com.lukouguoji.gjc.viewModel
import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import androidx.lifecycle.liveData
import com.alibaba.fastjson.JSONObject
import com.lukouguoji.module_base.http.user.UserNetwork
import kotlinx.coroutines.Dispatchers
class GjcWareHouseInfoViewModel : ViewModel() {
private val logName = "GjcWareHouseInfoViewModel"
var wayBillInfo = JSONObject()
/**
* 查询详情
*/
private val queryInfoByIdWareHouseLiveData = MutableLiveData<Int>()
val queryInfoByIdWareHouseObserver = Transformations.switchMap(queryInfoByIdWareHouseLiveData) { param ->
liveData(Dispatchers.IO) {
try {
var response = JSONObject()
if (param != -9999) {
response = UserNetwork.queryInfoByIdGjcWareHouse(param)
}
emit(response)
} catch (e: Exception) {
Log.e(logName, e.stackTraceToString())
}
}
}
fun queryInfoByIdWareHouse(wbId: Int) {
queryInfoByIdWareHouseLiveData.value = wbId
}
}

View File

@@ -0,0 +1,124 @@
package com.lukouguoji.gjc.viewModel
import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import androidx.lifecycle.liveData
import com.alibaba.fastjson.JSONArray
import com.alibaba.fastjson.JSONObject
import com.lukouguoji.module_base.common.String.emptyToNull
import com.lukouguoji.module_base.http.user.UserNetwork
import kotlinx.coroutines.Dispatchers
class GjcWareHouseListViewModel : ViewModel() {
/**
* 分页搜索
*/
private val searchParam = MutableLiveData<JSONObject>()
val searchParamLive = Transformations.switchMap(searchParam) { param ->
liveData(Dispatchers.IO) {
try {
val response = UserNetwork.searchGjcWareHouse(param)
emit(response)
} catch (e: Exception) {
Log.e("GoutCollectionViewModel", e.stackTraceToString())
}
}
}
fun search(
limit: Int,
page: Int,
carrier: String,
beginDate: String,
endDate: String,
fdate: String,//航班日期
fno: String,//航班编码
dest: String,//目的港
businessType: String,//业务类型
range: String,
status: String,
wbNo: String,
groupName: String,
agentCode: String,
) {
val param = JSONObject()
param["limit"] = limit
param["page"] = page
param["carrier"] = carrier.emptyToNull()
param["beginDate"] = beginDate.emptyToNull()
param["endDate"] = endDate.emptyToNull()
param["fdate"] = fdate.emptyToNull()
param["dest"] = dest.emptyToNull()
param["fno"] = fno.emptyToNull()
param["businessType"] = businessType.emptyToNull()
param["range"] = range.emptyToNull()
param["locStatus"] = status.emptyToNull()
param["wbNo"] = wbNo.emptyToNull()
param["groupName"] = groupName.emptyToNull()
param["agentCode"] = agentCode.emptyToNull()
param["agentCode"] = agentCode.emptyToNull()
searchParam.value = param
}
/**
* 数据汇总
*/
val summaryObserver = Transformations.switchMap(searchParam) { param ->
liveData(Dispatchers.IO) {
try {
val response = UserNetwork.totalGjcWareHouse(param)
emit(response)
} catch (e: Exception) {
Log.e("GoutCollectionViewModel", e.stackTraceToString())
}
}
}
/**
* 代理人
*/
var agentCodeList = JSONArray()
private val agentCodeLiveData = MutableLiveData<String>()
fun agentCode(time: String) {
agentCodeLiveData.value = time
}
val agentCodeObserver = Transformations.switchMap(agentCodeLiveData) { _ ->
liveData(Dispatchers.IO) {
try {
var response = UserNetwork.agentCodeGjc()
emit(response)
} catch (e: Exception) {
Log.e("GoutStartViewModel", e.stackTraceToString())
}
}
}
/**
* 业务类型
*/
var businessList = JSONArray()
private val businessLiveData = MutableLiveData<String>()
fun business(type: String) {
businessLiveData.value = type
}
val businessObserver = Transformations.switchMap(businessLiveData) { type ->
liveData(Dispatchers.IO) {
try {
var response = UserNetwork.business(type)
emit(response)
} catch (e: Exception) {
Log.e("GoutStartViewModel", e.stackTraceToString())
}
}
}
}

View File

@@ -0,0 +1,77 @@
package com.lukouguoji.gjc.viewModel
import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import androidx.lifecycle.liveData
import com.alibaba.fastjson.JSONArray
import com.alibaba.fastjson.JSONObject
import com.lukouguoji.module_base.common.String.emptyToNull
import com.lukouguoji.module_base.http.user.UserNetwork
import kotlinx.coroutines.Dispatchers
import kotlin.collections.set
class GjcYiKu2ListViewModel : ViewModel() {
/**
* 分页搜索
*/
private val searchParam = MutableLiveData<JSONObject>()
val searchParamLive = Transformations.switchMap(searchParam) { param ->
liveData(Dispatchers.IO) {
try {
val response = UserNetwork.searchMovedGjcYiKu(param)
emit(response)
} catch (e: Exception) {
Log.e("GoutCollectionViewModel", e.stackTraceToString())
}
}
}
fun search(
limit: Int,
page: Int,
beginDate: String,
endDate: String,
awbType: String,
id: String,
wbNo: String
) {
val param = JSONObject()
param["limit"] = limit
param["page"] = page
param["beginDate"] = beginDate.emptyToNull()
param["endDate"] = endDate.emptyToNull()
param["awbType"] = awbType.emptyToNull()
param["id"] = id.emptyToNull()
param["wbNo"] = wbNo.emptyToNull()
searchParam.value = param
}
/**
* 运单类型
*/
var awbList = JSONArray()
private val awbLiveData = MutableLiveData<String>()
fun awb(type: String) {
awbLiveData.value = type
}
val awbObserver = Transformations.switchMap(awbLiveData) { param ->
liveData(Dispatchers.IO) {
try {
var response = UserNetwork.awb(param)
emit(response)
} catch (e: Exception) {
Log.e("GoutStartViewModel", e.stackTraceToString())
}
}
}
}

View File

@@ -0,0 +1,102 @@
package com.lukouguoji.gjc.viewModel
import android.util.Log
import androidx.lifecycle.*
import com.alibaba.fastjson.JSONObject
import com.lukouguoji.module_base.common.String.emptyToNull
import com.lukouguoji.module_base.http.user.UserNetwork
import kotlinx.coroutines.Dispatchers
class GjcYiKuListViewModel : ViewModel() {
/**
* 航班号
*/
var fid: Int? = null
/**
* 选中
*/
val checkCount: LiveData<Int>
get() = _checkCount
private val _checkCount = MutableLiveData<Int>()
init {
_checkCount.value = 0
}
fun plusOne() {
val count = _checkCount.value ?: 0
_checkCount.value = count + 1
}
fun subOne() {
val count = _checkCount.value ?: 0
_checkCount.value = count - 1
}
fun setCheckCount(count: Int) {
_checkCount.value = count
}
/**
* 分页搜索
*/
private val searchParam = MutableLiveData<JSONObject>()
val searchParamLive = Transformations.switchMap(searchParam) { param ->
liveData(Dispatchers.IO) {
try {
val response = UserNetwork.searchGjcYiKu(param)
emit(response)
} catch (e: Exception) {
Log.e("GoutCollectionViewModel", e.stackTraceToString())
}
}
}
fun search(
limit: Int,
page: Int,
wbNo: String,
dest: String,
carrier: String
) {
val param = JSONObject()
param["limit"] = limit
param["page"] = page
param["wbNo"] = wbNo.emptyToNull()
param["dest"] = dest.emptyToNull()
param["carrier"] = carrier.emptyToNull()
searchParam.value = param
}
/**
* 确认移库
*/
private val moveGnjYiKuLiveData = MutableLiveData<JSONObject>()
val moveGnjYiKuObserver = Transformations.switchMap(moveGnjYiKuLiveData) { param ->
liveData(Dispatchers.IO) {
try {
val response = UserNetwork.moveGjcYiKu(param)
emit(response)
} catch (e: Exception) {
Log.e("GoutCollectionViewModel", e.stackTraceToString())
}
}
}
fun moveGnjYiKu(ids: List<Int>) {
val temObj = JSONObject()
temObj["fid"] = 0 //随意填,不起作用
temObj["ids"] = ids
moveGnjYiKuLiveData.value = temObj
}
}