package com.sw.inbound.activity import android.annotation.SuppressLint import androidx.recyclerview.widget.LinearLayoutManager import com.sw.inbound.R import com.sw.inbound.adapter.ReceiptGoodsAdapter import com.sw.inbound.model.response.DictType import com.sw.inbound.model.response.GoodsInfo import com.sw.inbound.utils.ext.clickWithDebounce import com.sw.inbound.utils.ext.toJsonString import com.sw.inbound.utils.ext.toast import com.sw.inbound.utils.ext.visible /** * 采购单入库 */ class ReceiptActivity : GoodsListActivity() { private val adapter by lazy { ReceiptGoodsAdapter(this, goodsList).apply { //addOnItemChildClickListener(R.id.ivClear) { adapter, view, 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.visible() binding.tvNotConfirmNum.visible() binding.btnConfirmReceipt.clickWithDebounce { receiptSubmit() } //if (isReceiptPage.not()) { // getNetOrder() //} else { // binding.tvPurchaseNo.text = "新增收货" //} val localGodsList = userViewModel.getGoodsList(localGoodsKey) if (localGodsList.isNullOrEmpty().not()) { val count = localGodsList.count { it.isLocalGoods } if (count > 0) { //存在修改后的本地数据 goodsList.clear() goodsList.addAll(localGodsList) adapter.notifyDataSetChanged() } else { getNetOrder() } } else { getNetOrder() } // 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") // } // } // } // } } @SuppressLint("NotifyDataSetChanged") private fun getNetOrder() { receiptViewModel.getReceiveDetail(id) { detail -> runOnUiThread { if (detail == null) { toast("未查询到数据") return@runOnUiThread } binding.tvPurchaseNo.text = "采购单号:${detail.purCode}" val list = detail.receiveGoodsInfoList list.forEach { goodsInfo -> resetGoods(goodsInfo) } goodsList.addAll(list) adapter.notifyDataSetChanged() setConfirmNum() } } } fun resetGoods(item: GoodsInfo) { item.recUnitPriceTaxInBak = item.recUnitPriceTaxIn item.recUnitPriceTaxIn = 0.0 item.recPriceExItemBak = item.recPriceExItem item.receiveCountBak = item.receiveCount item.unitNameBak = item.unitName item.receivedNumBak = item.receivedNum } override fun getWarehouseList(): List { return goodsList.filter { it.warehouseId.isNullOrBlank().not() && it.warehouseName.isNullOrBlank().not() } .distinctBy { it.warehouseId } .map { DictType(id = it.warehouseId!!, value = it.warehouseName!!) } } fun setConfirmNum() { val confirmOrderCount = goodsList.count { it.isAdjusted } binding.tvConfirmNum.text = getSpannable("已确认 ", num = confirmOrderCount, color = "#FF009632") val notConfirmOrderCount = goodsList.size - confirmOrderCount binding.tvNotConfirmNum.text = getSpannable("未确认 ", num = notConfirmOrderCount, color = "#FFFF0000") } }