package com.example.chemical.ui.adapter

import android.content.Context
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.chemical.R
import com.rc.httpcore.bean.QueryTwoListBean

//标签列表
class ChemicalLabelingAdapter(private val ct: Context) :
    BaseQuickAdapter<QueryTwoListBean, BaseViewHolder>(R.layout.item_chemical_labeling) {
    override fun convert(holder: BaseViewHolder, item: QueryTwoListBean) {

        if (item.isType) {
            holder.setBackgroundResource(R.id.cont, R.color.purple_ff54a2ea)
            holder.setTextColor(R.id.chemicalName, ContextCompat.getColor(ct, R.color.white))
            holder.setTextColor(R.id.tagCode, ContextCompat.getColor(ct, R.color.white))
            holder.setTextColor(R.id.rfidCode, ContextCompat.getColor(ct, R.color.white))
            holder.setTextColor(R.id.specNum, ContextCompat.getColor(ct, R.color.white))
            holder.setTextColor(R.id.belongName, ContextCompat.getColor(ct, R.color.white))
        } else {
            holder.setBackgroundResource(R.id.cont, R.color.white)
            holder.setTextColor(R.id.chemicalName, ContextCompat.getColor(ct, R.color.black))
            holder.setTextColor(R.id.tagCode, ContextCompat.getColor(ct, R.color.black))
            holder.setTextColor(R.id.rfidCode, ContextCompat.getColor(ct, R.color.black))
            holder.setTextColor(R.id.specNum, ContextCompat.getColor(ct, R.color.black))
            holder.setTextColor(R.id.belongName, ContextCompat.getColor(ct, R.color.black))
        }

        holder.setText(R.id.chemicalName, item.chemicalName)
        holder.setText(R.id.tagCode, item.tagCode)
        if (item.rfidCode != null) {
            holder.setText(R.id.rfidCode, item.rfidCode)
        } else {
            holder.setText(R.id.rfidCode, "无")
        }
        holder.setText(R.id.specNum, "${item.specNum}${item.specUnit}/${item.packUnit}")
        holder.setText(R.id.belongName, item.belongName)
    }
}