package com.wd.workoffice.ui.adapter;


import android.widget.CheckBox;
import android.widget.CompoundButton;

import com.alibaba.fastjson.JSON;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.wd.workoffice.R;
import com.wd.workoffice.bean.ProductBean;
import com.wd.workoffice.bean.event.ModifyCarEvent;
import com.wd.workoffice.util.MathUtils;
import com.wd.workoffice.widget.AddAndReduceView;

import org.greenrobot.eventbus.EventBus;

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

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

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

    public TradingProCarAdapter(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.getSoleCode());
        helper.setText(R.id.tv_spec, item.getSpec());
        helper.setText(R.id.tv_price, String.valueOf(item.getInternalPrice()));
        helper.setText(R.id.tv_all_price, "小计:"+MathUtils.multiply(item.getCarNum() + "", item.getInternalPrice() + "", 2));
        AddAndReduceView num = helper.getView(R.id.ar_num);
        num.setNumber(item.getCarNum());
        num.setOnNumberChangedListener(new AddAndReduceView.OnNumberChangedListener() {
            @Override
            public void OnNumberChanged(String vs) {
                item.setCarNum(vs);
                helper.setText(R.id.tv_all_price, "小计:"+MathUtils.multiply(vs + "", item.getInternalPrice() + "", 2));
                EventBus.getDefault().post(new ModifyCarEvent(JSON.toJSONString(getData())));
            }

        });
    }

}

