package com.wd.workoffice.ui.adapter;


import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.wd.workoffice.R;
import com.wd.workoffice.bean.LogisticDetailBean;
import com.wd.workoffice.bean.ProductBean;
import com.wd.workoffice.util.MathUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by flexible on 2018/8/13.
 */

public class TradingProDetailAdapter extends BaseQuickAdapter<ProductBean.RecordsBean, BaseViewHolder> {


    int choosePos = -1;

    public TradingProDetailAdapter(int layoutResId, List data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, ProductBean.RecordsBean item) {
        helper.setText(R.id.tv_name, item.getName());
        helper.setText(R.id.tv_card, item.getSoleCode());
        helper.setText(R.id.tv_card_name, item.getSimpleCode());
        helper.setText(R.id.tv_spec, item.getSpec());
        helper.setText(R.id.tv_price, MathUtils.converData(item.getInternalPrice(), 3));
        CheckBox cbChoose = helper.getView(R.id.cb_check);
        if (helper.getAdapterPosition() == choosePos) {
            cbChoose.setChecked(true);
        } else {
            cbChoose.setChecked(false);
        }
        cbChoose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (choosePos ==helper.getAdapterPosition()){

                }else {
                    choosePos = helper.getAdapterPosition();
                    notifyDataSetChanged();
                }
            }
        });
//        cbChoose.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
//            @Override
//            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//                notifyItemChanged(choosePos);
//                choosePos = helper.getAdapterPosition();
////                cbChoose.setChecked(isChecked);
//            }
//        });
    }

    public int getChoosePos() {
        return choosePos;
    }

    public void setChoosePos(int choosePos) {
        this.choosePos = choosePos;
    }
}

