package com.wd.workoffice.ui.adapter;


import android.text.TextUtils;

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.util.MathUtils;

import java.util.List;

import androidx.annotation.Nullable;

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

public class StoreProductAdapter extends BaseQuickAdapter<ProductBean.RecordsBean, BaseViewHolder> {
    int type;//1坩埚页面 ,2 供应不显示销售价格

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

    public StoreProductAdapter(int layoutResId, @Nullable List<ProductBean.RecordsBean> data, int type) {
        super(layoutResId, data);
        this.type = type;
    }

    @Override
    protected void convert(BaseViewHolder helper, ProductBean.RecordsBean item) {
        helper.setText(R.id.tv_name, item.getSimpleCode());
        helper.setText(R.id.tv_card, item.getSoleCode());
        helper.setText(R.id.tv_card_name, item.getName());
        helper.setText(R.id.tv_spec, item.getSpec());
        helper.setText(R.id.tv_price, "￥".concat(MathUtils.converData(item.getInternalPrice(), 3)));
        helper.setText(R.id.tv_unit, String.valueOf(item.getWeight()).concat("吨"));
        if (!TextUtils.isEmpty(item.getCarNum())) {
            helper.setVisible(R.id.ll_car,true);
            helper.setText(R.id.tv_sale_price, MathUtils.converData(item.getCarPrice(), 3));
            helper.setText(R.id.tv_car_num, MathUtils.converData(item.getCarNum(), 3));
        }else{
            helper.setVisible(R.id.ll_car,false);
        }
        helper.addOnClickListener(R.id.tv_cart);
        if (type == 1) {
            helper.setGone(R.id.rl_num, true);
            helper.setText(R.id.tv_num, String.valueOf(item.getCanUseProductSum()));
        }
        if (type == 2) {
            helper.setGone(R.id.tv_price_desc, false);
            helper.setGone(R.id.tv_sale_price, false);
        }
    }
}

