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.OrderDetail;
import com.wd.workoffice.bean.event.SendWeightEvent;
import com.wd.workoffice.util.WorkUtils;
import com.wd.workoffice.widget.AddAndReduceDoubleView;
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 WorkSendApplyAddAdapter extends BaseQuickAdapter<OrderDetail.OrderItemsBean, BaseViewHolder> {

    Map<Integer, Boolean> isChoose = new HashMap<>();

    public WorkSendApplyAddAdapter(int layoutResId, List data) {
        super(layoutResId, data);
        for (int i = 0; i < isChoose.entrySet().size(); i++) {
            isChoose.put(i, false);

        }
    }

    @Override
    protected void convert(BaseViewHolder helper, OrderDetail.OrderItemsBean item) {
        helper.setText(R.id.tv_name, item.getProductSimpleCode());
        helper.setText(R.id.tv_card, item.getProductSoleCode());
        helper.setText(R.id.tv_card_name, item.getProductName ());
        helper.setText(R.id.tv_spec, item.getProductSpec());
        helper.setText(R.id.tv_price, "￥".concat(String.valueOf(item.getInnerPrice())));
//        helper.setText(R.id.tv_all_price, "￥".concat(String.valueOf(item.getInnerPrice())));
        helper.setText(R.id.tv_unit, item.getProductUnit());
//        helper.setText(R.id.tv_from, WorkUtils.getOrderFrom(item.getType()));
        helper.setText(R.id.tv_num, String.valueOf(item.getProductCount()));
        helper.setText(R.id.tv_apply_send_num, String.valueOf(item.getStoreSum()));
        helper.setText(R.id.tv_send_num, "发货数量："+String.valueOf(item.getUsedSum()));
        AddAndReduceView nrcNum = helper.getView(R.id.arv_num);
        nrcNum.setMaxNum(item.getStoreSum());
        nrcNum.setOnNumberChangedListener(new AddAndReduceView.OnNumberChangedListener() {
            @Override
            public void OnNumberChanged(String vs) {
                item.setChooseNum(vs);
                EventBus.getDefault().post(new SendWeightEvent());
            }
        });
        CheckBox cbChoose = helper.getView(R.id.cb_check);
        cbChoose.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                isChoose.put(helper.getAdapterPosition(), cbChoose.isChecked());

                EventBus.getDefault().post(new SendWeightEvent());
            }
        });
    }

    public Map<Integer, Boolean> getIsChoose() {
        return isChoose;
    }

    public void setIsChoose(Map<Integer, Boolean> isChoose) {
        this.isChoose = isChoose;
    }
}

