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.core.log.RcLog
import com.rc.httpcore.bean.HxpStockWaitListBean
import java.math.BigDecimal

//待入库清单
class InventoryListAdapter(private val ct: Context) :
    BaseQuickAdapter<HxpStockWaitListBean, BaseViewHolder>(R.layout.item_inventory_list) {
    override fun convert(holder: BaseViewHolder, item: HxpStockWaitListBean) {
        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.casNum, ContextCompat.getColor(ct, R.color.white))
            holder.setTextColor(R.id.chemicalPurity, ContextCompat.getColor(ct, R.color.white))
            holder.setTextColor(R.id.specifications, ContextCompat.getColor(ct, R.color.white))
            holder.setTextColor(R.id.belonging_person, ContextCompat.getColor(ct, R.color.white))
            holder.setTextColor(R.id.applyNum, 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.casNum, ContextCompat.getColor(ct, R.color.black))
            holder.setTextColor(R.id.chemicalPurity, ContextCompat.getColor(ct, R.color.black))
            holder.setTextColor(R.id.specifications, ContextCompat.getColor(ct, R.color.black))
            holder.setTextColor(R.id.belonging_person, ContextCompat.getColor(ct, R.color.black))
            holder.setTextColor(R.id.applyNum, ContextCompat.getColor(ct, R.color.black))

        }
        holder.setText(R.id.chemicalName, "${item.chemicalName}")
        if (item.casNum!=null){
            holder.setText(R.id.casNum, "${item.casNum}")
        }
        if (item.chemicalPurity!=null){
            holder.setText(R.id.chemicalPurity, "${item.chemicalPurity}")
        }

        holder.setText(R.id.specifications, "${item.normsNum}${item.normsUnit}/${item.applyUnit}")
        if (item.topicGroup) {
            holder.setText(R.id.belonging_person, "${item.topicGroupName}")
        } else {
            holder.setText(R.id.belonging_person, "${item.applyUserName}")
        }
        //applyNum - stockNum

        holder.setText(R.id.applyNum, "${item.applyNum.subtract(BigDecimal(item.stockNum!!))}")
    }
}