package xn.hxp.ui.adapter

import android.content.Context
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import xn.hxp.R
import com.rc.httpcore.bean.InventoryBean
import xn.hxp.weidith.TextTool

//库存台账 - 列表
class InventoryAdapter(private val ct: Context) :
    BaseQuickAdapter<InventoryBean, BaseViewHolder>(R.layout.item_inventory) {
    override fun convert(holder: BaseViewHolder, item: InventoryBean) {
        holder.setText(R.id.chemicalName, item.chemicalName)
        val chemicalNameView = holder.getView<TextView>(R.id.chemicalName)
        chemicalNameView.setOnClickListener { TextTool.showPop(context, chemicalNameView) }
        holder.setText(R.id.tagCode, item.tagCode)
        val tagCodeView = holder.getView<TextView>(R.id.tagCode)
        tagCodeView.setOnClickListener { TextTool.showPop(context, tagCodeView) }
        holder.setText(R.id.specNum, "${item.specNum}${item.specUnit}/${item.packUnit}")
        holder.setText(R.id.cabinetName, "${item.cabinetName}-${item.doorName}-${item.layers}层")
        val cabinetNameView = holder.getView<TextView>(R.id.cabinetName)
        cabinetNameView.setOnClickListener { TextTool.showPop(context, cabinetNameView) }
        if (item.expireTime != null) {
            if (item.expireStatus == 1) {
                holder.setTextColor(
                    R.id.expireTime,
                    ContextCompat.getColor(ct, R.color.purple_ffff7919)
                )
                holder.setText(R.id.expireTime, "${item.expireTime}已过期")
            } else {
                holder.setTextColor(R.id.expireTime, ContextCompat.getColor(ct, R.color.black))
                holder.setText(R.id.expireTime, item.expireTime)
            }
        } else {
            holder.setText(R.id.expireTime, "")
        }
        holder.setText(R.id.belongName, item.belongName)
        holder.setText(R.id.joinTime, item.joinTime)
        holder.setText(R.id.usages, "${item.usages}${item.specUnit}")
        holder.setText(R.id.outTime, item.outTime)
        holder.setText(R.id.statusStr, item.statusStr)
        holder.setText(R.id.surplus, "${item.surplus}${item.specUnit}")

    }
}