98 lines
3.6 KiB
Kotlin
98 lines
3.6 KiB
Kotlin
package com.sw.inbound.activity
|
|
|
|
import android.annotation.SuppressLint
|
|
import androidx.lifecycle.Lifecycle
|
|
import androidx.lifecycle.lifecycleScope
|
|
import androidx.lifecycle.repeatOnLifecycle
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
import com.sw.inbound.adapter.ReceiptGoodsAdapter
|
|
import com.sw.inbound.model.response.DictType
|
|
import com.sw.inbound.utils.ext.gone
|
|
import com.sw.inbound.utils.ext.toast
|
|
import com.sw.inbound.utils.ext.visible
|
|
import kotlinx.coroutines.launch
|
|
|
|
class ReceiptActivity : GoodsListActivity() {
|
|
|
|
private val adapter by lazy {
|
|
ReceiptGoodsAdapter(goodsList).apply {
|
|
setOnItemClickListener { adapter, view, position ->
|
|
goodsList[position].let {
|
|
it.isSelected = it.isSelected.not()
|
|
}
|
|
notifyItemChanged(position)
|
|
}
|
|
}
|
|
}
|
|
|
|
override fun initRecyclerView() {
|
|
binding.rvGoodsList.let {
|
|
it.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
|
|
it.adapter = adapter
|
|
}
|
|
}
|
|
|
|
@SuppressLint("NotifyDataSetChanged")
|
|
override fun initView() {
|
|
//initRvTestData()
|
|
binding.tvConfirmNum.run {
|
|
if (isNewReceipt) gone() else visible()
|
|
}
|
|
binding.tvNotConfirmNum.run {
|
|
if (isNewReceipt) gone() else visible()
|
|
}
|
|
binding.btnConfirmReceipt.setOnClickListener {
|
|
if (isNewReceipt) {
|
|
selfProcurementSubmit()
|
|
} else {
|
|
receiptSubmit()
|
|
}
|
|
}
|
|
if (isNewReceipt.not()) {
|
|
viewModel.getReceiveDetail(id) { detail ->
|
|
runOnUiThread {
|
|
if (detail == null) {
|
|
toast("未查询到数据")
|
|
return@runOnUiThread
|
|
}
|
|
binding.tvPurchaseNo.text = "采购单号:${detail.purCode}"
|
|
val list = detail.receiveGoodsInfoList
|
|
goodsList.addAll(list)
|
|
adapter.notifyDataSetChanged()
|
|
val confirmOrderCount = list.count { it.isAdjusted }
|
|
binding.tvConfirmNum.text =
|
|
getSpannable("已确认 ", num = confirmOrderCount, color = "#FF009632")
|
|
val notConfirmOrderCount = goodsList.size - confirmOrderCount
|
|
binding.tvNotConfirmNum.text =
|
|
getSpannable("未确认 ", num = notConfirmOrderCount, color = "#FFFF0000")
|
|
}
|
|
}
|
|
} else {
|
|
binding.tvPurchaseNo.text = "新增收货"
|
|
}
|
|
|
|
// lifecycleScope.launch {
|
|
// repeatOnLifecycle(Lifecycle.State.CREATED) {
|
|
// launch {
|
|
// viewModel.adjustedOrders.collect {
|
|
// val confirmOrderCount = it.size
|
|
// binding.tvConfirmNum.text = getSpannable("已确认 ", num = confirmOrderCount, color = "#FF009632")
|
|
// val notConfirmOrderCount = goodsList.size - confirmOrderCount
|
|
// binding.tvNotConfirmNum.text = getSpannable("未确认 ", num = notConfirmOrderCount, color = "#FF009632")
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
}
|
|
|
|
override fun getWarehouseList(): List<DictType> {
|
|
return goodsList.filter {
|
|
it.warehouseId.isNullOrBlank().not() && it.warehouseName.isNullOrBlank().not()
|
|
}
|
|
.distinctBy { it.warehouseId }
|
|
.map {
|
|
DictType(id = it.warehouseId!!, value = it.warehouseName!!)
|
|
}
|
|
}
|
|
|
|
} |