package com.example.chemical.ui.adapter

import android.content.Context
import android.view.View
import android.widget.AdapterView
import android.widget.Spinner
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.chemical.R
import com.example.chemical.utils.ConversionUtils
import com.rc.core.log.RcLog
import com.rc.httpcore.bean.StockModel
import java.math.BigDecimal

//新增入库信息
class ChemicalsAdapter(private val ct: Context) :
    BaseQuickAdapter<StockModel, BaseViewHolder>(R.layout.item_chemicals_view) {

    init {
        addChildClickViewIds(R.id.imgDelete)//删除当前信息
    }

    private var layersCount: List<String>? = null

    override fun convert(holder: BaseViewHolder, item: StockModel) {
        holder.setText(R.id.chemicalName, item.chemicalName)
        holder.setText(R.id.specifications,"${item!!.specNum}${item!!.specUnit}/${item!!.packUnit}")
        holder.setText(R.id.net_content, "${item.netContent}${item.specUnit}")
        if (item.isNew){
            holder.setText(R.id.net_content, "${item!!.specNum}${item!!.specUnit}")
        }else{
            holder.setText(R.id.net_content, "${item.netContent}${item.specUnit}")
        }
        holder.setText(R.id.number, "${item.chemicalNumber}")
        holder.setText(R.id.layers, "${item.layers}层")

//        RcLog.info("=====新增 入库===当前层数 ${item.layers}")
//        if (layersCount != null) {
//            RcLog.info("=====新增 入库===共计层数 ${layersCount!!.size}")
//        }


//        val sPinner = holder.getView<Spinner>(R.id.sPinner)
//
//
//        val customAdapter = CustomSpinnerAdapter(ct, layersCount!!)
//        sPinner.adapter = customAdapter
//        RcLog.info("=======当前3选择${item.layers}")
//        RcLog.info("=======当前9选择${item.layersTow}")
//        sPinner.setSelection(item.layers - 1)
//        sPinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
//            override fun onItemSelected(
//                parent: AdapterView<*>?,
//                view: View?,
//                position: Int,
//                id: Long
//            ) {
//                // 当用户选择某一项时被调用
//                RcLog.info("=======当前选择 ${layersCount!![position]}")
//                // 在这里可以使用 selectedPosition 来执行相应的操作
//                item.layers = layersCount!![position].toInt()
//            }
//
//            override fun onNothingSelected(parent: AdapterView<*>?) {
//                // 当没有任何项被选择时被调用
//            }
//        }

    }

    fun updateData(item: Int) {
        // 在这里处理传递过来的动态值
        val lists = mutableListOf<String>()  //层数
        //初始化柜子层数
        for (i in 1..item) {
            lists.add("$i")
        }
        layersCount = lists
    }
}