70 lines
2.3 KiB
Kotlin
70 lines
2.3 KiB
Kotlin
package com.sw.inbound.activity
|
|
|
|
import android.annotation.SuppressLint
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
import com.sw.inbound.R
|
|
import com.sw.inbound.adapter.SelfProcurementAdapter
|
|
import com.sw.inbound.dialog.WarnDialog
|
|
import com.sw.inbound.model.response.DictType
|
|
import com.sw.inbound.utils.ext.toJsonString
|
|
|
|
/**
|
|
* 自采入库
|
|
*/
|
|
class SelfProcurementActivity : GoodsListActivity() {
|
|
|
|
private val adapter by lazy {
|
|
SelfProcurementAdapter(goodsList).apply {
|
|
setOnItemClickListener { adapter, view, position ->
|
|
goodsList[position].let {
|
|
it.isSelected = it.isSelected.not()
|
|
}
|
|
notifyItemChanged(position)
|
|
}
|
|
addOnItemChildClickListener(R.id.ivState) { adapter, view, position ->
|
|
///删除行数据弹窗
|
|
showWarnDialog(content = "请确认是否删除该条入库数据,删除后将无法恢复?") {
|
|
removeAt(position)
|
|
userViewModel.putGoodsData(localGoodsKey, goodsList.toJsonString())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private fun showWarnDialog(content: String, callback: () -> Unit) {
|
|
WarnDialog(context = this, content = content, confirmBlock = callback).show()
|
|
}
|
|
|
|
override fun initRecyclerView() {
|
|
binding.rvGoodsList.let {
|
|
it.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
|
|
it.adapter = adapter
|
|
}
|
|
}
|
|
|
|
@SuppressLint("NotifyDataSetChanged")
|
|
override fun initView() {
|
|
binding.tvPurchaseNo.text = "自采入库"
|
|
binding.btnConfirmReceipt.setOnClickListener {
|
|
selfProcurementSubmit()
|
|
}
|
|
|
|
val localGodsList = userViewModel.getGoodsList(localGoodsKey)
|
|
if (localGodsList.isNullOrEmpty().not()) {
|
|
//本地数据为空则加载本地数据
|
|
goodsList.addAll(localGodsList)
|
|
adapter.notifyDataSetChanged()
|
|
}
|
|
}
|
|
|
|
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!!)
|
|
}
|
|
}
|
|
|
|
} |