59 lines
2.3 KiB
Kotlin
59 lines
2.3 KiB
Kotlin
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 "收货"
|
|
|
|
|
|
}
|
|
|
|
} |