成功订单页面

This commit is contained in:
2026-02-12 12:44:30 +08:00
parent f562abc12f
commit b034e9371f
11 changed files with 300 additions and 104 deletions
@@ -1,17 +1,91 @@
package com.sw.inbound.activity
import android.annotation.SuppressLint
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.viewModels
import androidx.compose.runtime.collectAsState
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import com.sw.inbound.R
import com.sw.inbound.adapter.PurchaseOrderAdapter
import com.sw.inbound.databinding.ActivityPurchaseOrderBinding
import com.sw.inbound.dialog.Loading
import com.sw.inbound.model.response.SupplierInfo
import com.sw.inbound.utils.ext.clickWithDebounce
import com.sw.inbound.utils.ext.gone
import com.sw.inbound.utils.ext.startActivity
import com.sw.inbound.utils.ext.visible
import com.sw.inbound.viewmodel.PurchaseOrderViewModel
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
/**
* 采购单列表
*/
@AndroidEntryPoint
class PurchaseOrderActivity : ComponentActivity(){
class PurchaseOrderActivity : ComponentActivity() {
private var list = mutableListOf<SupplierInfo>()
private val adapter by lazy {
PurchaseOrderAdapter(list).apply {
setOnItemClickListener { adapter, view, position ->
openReceiptPage(list[position])
}
addOnItemChildClickListener(R.id.btnReceive) { adapter, view, position ->
openReceiptPage(list[position])
}
}
}
private fun openReceiptPage(item: SupplierInfo) {
startActivity<ReceiptActivity> {
putExtra(GoodsListActivity.ID, item.id)
putExtra(GoodsListActivity.SUPPLIER_ID, item.supplierId)
putExtra(GoodsListActivity.IS_RECEIPT_PAGE, true)
//putExtra(GoodsListActivity.IS_NEW_RECEIPT, false)
}
}
private lateinit var binding: ActivityPurchaseOrderBinding
val viewModel: PurchaseOrderViewModel by viewModels()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityPurchaseOrderBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.rvOrderList.let {
it.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)
it.adapter = adapter
}
binding.btnBack.setOnClickListener { finish() }
binding.btnAddReceipt.clickWithDebounce {
startActivity<SelfProcurementActivity> {
putExtra(GoodsListActivity.IS_RECEIPT_PAGE, false)
}
}
Loading.show(this)
viewModel.getOrderListNew(pageNum = 1, pageSize = 100) { suppliers ->
runOnUiThread {
binding.root.postDelayed({
Loading.dismiss()
}, 600)
updateSupplierList(suppliers)
}
}
}
@SuppressLint("NotifyDataSetChanged")
private fun updateSupplierList(suppliers: List<SupplierInfo>?) {
if (suppliers.isNullOrEmpty()) {
binding.rvOrderList.gone()
binding.layoutEmptyView.visible()
return
}
list.addAll(suppliers)
adapter.notifyDataSetChanged()
binding.rvOrderList.visible()
binding.layoutEmptyView.gone()
}
}
@@ -1,29 +1,59 @@
//package com.sw.inbound.adapter
//
//import android.content.Context
//import android.view.LayoutInflater
//import android.view.ViewGroup
//import com.chad.library.adapter4.BaseQuickAdapter
//import com.chad.library.adapter4.viewholder.QuickViewHolder
//import com.sw.inbound.databinding.ListItemCollectSearchBinding
//import com.sw.inbound.databinding.ListItemPurchaseOrderBinding
//import com.sw.inbound.model.response.SearchGoodsInfo
//import com.sw.inbound.model.response.SupplierInfo
//
////List<SupplierInfo?>
//class PurchaseOrderAdapter:BaseQuickAdapter<SupplierInfo, > {
//
// inner class VH(var binding: ListItemCollectSearchBinding) : QuickViewHolder(binding.root)
//
// override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
// val inflater = LayoutInflater.from(context)
// val binding = ListItemPurchaseOrderBinding.inflate(inflater, parent, false)
// return VH(binding)
// }
//
// override fun onBindViewHolder(holder: VH, position: Int, item: SupplierInfo) {
//
//
// }
//
//}
package com.sw.inbound.adapter
import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.core.view.updateLayoutParams
import com.chad.library.adapter4.BaseQuickAdapter
import com.chad.library.adapter4.viewholder.QuickViewHolder
import com.sw.inbound.R
import com.sw.inbound.databinding.ListItemPurchaseOrderBinding
import com.sw.inbound.ext.screenSize
import com.sw.inbound.ext.toFormattedString
import com.sw.inbound.model.response.SupplierInfo
import com.sw.inbound.utils.ext.dp
import com.sw.inbound.utils.ext.ifNullOrBlank
class PurchaseOrderAdapter(var list:List<SupplierInfo>):BaseQuickAdapter<SupplierInfo, PurchaseOrderAdapter.VH>(list) {
inner class VH(var binding: ListItemPurchaseOrderBinding) : QuickViewHolder(binding.root)
override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
val inflater = LayoutInflater.from(context)
val binding = ListItemPurchaseOrderBinding.inflate(inflater, parent, false)
return VH(binding)
}
override fun onBindViewHolder(holder: VH, position: Int, item: SupplierInfo?) {
val screenWidth = context.screenSize[0]
holder.itemView.updateLayoutParams {
width = (screenWidth - 2*60.dp) / 3
}
val binding = holder.binding
val receiveStatus = item?.receiveStatus?:""
val (statusColor, statusLabel) = when(receiveStatus) {
1 -> R.color.red to "待收货"
2 -> R.color.origin to "已收货"
3 -> R.color.black to "已关闭"
else -> R.color.black to "未知状态"
}
binding.tvReceiveState.run {
text = statusLabel
setTextColor(ContextCompat.getColor(context, statusColor))
}
binding.tvSupplierName.text = item?.supplierName.ifNullOrBlank("-")
binding.tvOrderNo.text = "单号 ${item?.purCode.ifNullOrBlank("-")}"
binding.tvGoodsCount.text = item?.goodCount?.toFormattedString()
binding.tvPurchaseDate.text = item?.purchaseDate.ifNullOrBlank("-")
binding.tvReceiveDate.text = item?.receiveDate.ifNullOrBlank("-")
binding.tvPurchaseMan.text = item?.receiveUser.ifNullOrBlank("-")
binding.btnReceive.text = if (item?.receiveStatus == 4) "部分收货" else "收货"
}
}
@@ -1,10 +1,16 @@
package com.sw.inbound.ext
import android.app.Activity
import android.content.Context
import android.util.DisplayMetrics
import android.view.WindowManager
fun Activity.getScreenWidth(): Int {
val Context.screenSize: IntArray
get() {
val windowManager = getSystemService(Context.WINDOW_SERVICE) as WindowManager
val displayMetrics = DisplayMetrics()
windowManager.defaultDisplay.getMetrics(displayMetrics)
return displayMetrics.widthPixels
}
return intArrayOf(
displayMetrics.widthPixels,
displayMetrics.heightPixels
)
}
@@ -26,6 +26,7 @@ import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import com.sw.inbound.R
import com.sw.inbound.activity.GoodsListActivity
import com.sw.inbound.activity.PurchaseOrderActivity
import com.sw.inbound.activity.SelfProcurementActivity
import com.sw.inbound.ui.Screen
import com.sw.inbound.ui.weight.TopTitleBar
@@ -79,12 +80,13 @@ fun HomeScreen(
interactionSource = remember { MutableInteractionSource() },
indication = null
) {
navController.navigate(Screen.PurchaseOrder.route)
// navController.navigate(Screen.PurchaseOrder.route)
//navController.context.startActivity<ReceiptActivity> {
// putExtra(GoodsListActivity.ID, "123123")
// putExtra(GoodsListActivity.SUPPLIER_ID, "123123123123")
// putExtra(GoodsListActivity.IS_RECEIPT_PAGE, true)
//}
navController.context.startActivity<PurchaseOrderActivity>()
},
painter = painterResource(R.mipmap.ic_order_purchase),
contentDescription = "采购单入库"
@@ -135,7 +135,7 @@ fun PurchaseOrderScreen(
if (first.value) {
return@Box
}
if (products.isEmpty()) {
if (products.isNullOrEmpty()) {
PurchaseEmptyItem()
} else {
LazyRow(
@@ -144,7 +144,7 @@ fun PurchaseOrderScreen(
contentPadding = PaddingValues(16.dp),
horizontalArrangement = Arrangement.spacedBy(30.dp)
) {
items(items = products, key = { it!!.id ?: "" }) { product ->
items(items = products!!, key = { it!!.id ?: "" }) { product ->
PurchaseOrderItem(product!!) {
// navController.navigate(
// Screen.ReceiptProduct.createRoute(
@@ -171,9 +171,7 @@ fun EditText.addOnActionSearchListener(searchCallback: () -> Unit) {
* @param action 点击执行逻辑
*/
fun View.clickWithDebounce(delay: Long = 300, action: () -> Unit) {
var job: Job? = null
setOnClickListener {
job?.cancel()
// 用View的tag存储是否可点击的状态(默认可点击)
if (tag as? Boolean ?: true) {
tag = false // 标记为不可点击
@@ -21,8 +21,8 @@ class PurchaseOrderViewModel @Inject constructor(
/**
* 采购订单-供应商列表
*/
private val _supplierList = MutableStateFlow<List<SupplierInfo?>>(emptyList())
val supplierList: StateFlow<List<SupplierInfo?>> = _supplierList
private val _supplierList = MutableStateFlow<List<SupplierInfo>?>(emptyList())
val supplierList: StateFlow<List<SupplierInfo>?> = _supplierList
private val _firstOperate = MutableStateFlow<Boolean>(true)
val firstOperate:StateFlow<Boolean> = _firstOperate
@@ -33,6 +33,14 @@ class PurchaseOrderViewModel @Inject constructor(
/**
* 获取采购订单-供应商列表
*/
fun getOrderListNew(pageNum: Int = 1, pageSize: Int = 5, block:(List<SupplierInfo>?)-> Unit) {
launch {
val response = repository.getReceiveList(pageNum, pageSize)
block(
if (parseResponse(response)) response.result else null
)
}
}
fun getOrderList(pageNum: Int = 1, pageSize: Int = 5) {
if (pageNum != 1) {
launch {
@@ -45,7 +53,7 @@ class PurchaseOrderViewModel @Inject constructor(
response.result?.let {
updateCanLoadMore(it.size >= pageSize)
Timber.d("加载更多 canLoadMore =${it.size >= pageSize}")
_supplierList.value = _supplierList.value + it
_supplierList.value = _supplierList.value?.plus(it)
}
}
updateFirstState(false)
@@ -54,9 +62,9 @@ class PurchaseOrderViewModel @Inject constructor(
launchWithLoading {
val response = repository.getReceiveList(pageNum, pageSize)
if (parseResponse(response)) {
response.result?.let {
_supplierList.value = it
}
_supplierList.value = response.result ?: emptyList()
} else {
_supplierList.value = null
}
updateFirstState(false)
}