package com.mq.zhongzhuanzhuangche;

import android.support.annotation.Nullable;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mq.mylibrary.db.grain_type.GrainTypeDao;
import com.mq.mylibrary.db.grain_type.GrainTypeEntity;
import com.mq.zhongzhuanzhuangche.db.ZhongZhuanZhuangCheEntity;

import java.util.List;

/**
 * 创建人 mQ
 * 创建时间 2019/8/14 0014 19:29
 * 文件名称 LogAdapter
 * 说明:
 **/
public class LogAdapter extends BaseQuickAdapter<ZhongZhuanZhuangCheEntity, BaseViewHolder> {

    public CallBack mCallBack;

    public LogAdapter(@Nullable List<ZhongZhuanZhuangCheEntity> data) {
        super(R.layout.item_log, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, ZhongZhuanZhuangCheEntity item) {
        GrainTypeEntity grain = GrainTypeDao.get().getGrain(App.getDBHelper(), item.grain);
        if (grain != null)
            helper.setText(R.id.tv_grain, grain.grain_name);

        helper
                .setText(R.id.tv_work_number, item.order_number)
                .setText(R.id.tv_pick_up_goods_num, item.pick_up_goods_num)
                .setText(R.id.tv_car, item.car)
                .setText(R.id.tv_train_code, item.train_code)
                .setText(R.id.tv_platform, item.platform)
                .setText(R.id.tv_position, item.position)
                .setText(R.id.tv_entd, item.entd)
                .setText(R.id.tv_start_time, item.start_time)
                .setText(R.id.tv_end_time, item.end_time)
        ;

        helper.getView(R.id.layout_item).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //查看
                if (mCallBack != null) {
                    mCallBack.onLookListener(item);
                }
            }
        });
        helper.getView(R.id.btn_look).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //查看
                if (mCallBack != null) {
                    mCallBack.onLookListener(item);
                }
            }
        });
        helper.getView(R.id.btn_card).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //补卡
                if (mCallBack != null) {
                    mCallBack.onCardListener(item);
                }
            }
        });

    }

    public void setCallBack(CallBack callBack) {
        mCallBack = callBack;
    }

    public interface CallBack {
        public void onLookListener(ZhongZhuanZhuangCheEntity entity);

        public void onCardListener(ZhongZhuanZhuangCheEntity entity);
    }
}
