package cn.net.caoyao.cpzshandset.ui.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import cn.net.caoyao.cpzshandset.R;
import cn.net.caoyao.cpzshandset.bean.JinLiquorOutWarehouseBean;

public class JinLiquorOutWarehouseListAdapter extends BaseAdapter{
	private List<JinLiquorOutWarehouseBean> beans;
	public JinLiquorOutWarehouseListAdapter(List<JinLiquorOutWarehouseBean> beans) {
		this.beans = beans;
	}
	public void refeshData(List<JinLiquorOutWarehouseBean> beans){
		this.beans = beans;
		notifyDataSetChanged();
	}
	

	@Override
	public int getCount() {
		return beans.size();
	}

	@Override
	public Object getItem(int position) {
		return beans.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		Context context = parent.getContext();
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_jin_liquor_out_warehouse_item, parent, false);
			holder.tv_warehouse_his_serial = (TextView) convertView.findViewById(R.id.tv_warehouse_his_serial);
			holder.tv_warehouse_no = (TextView) convertView.findViewById(R.id.tv_warehouse_no);
			holder.tv_warehouse_dealer_name = (TextView) convertView.findViewById(R.id.tv_warehouse_dealer_name);
			holder.tv_warehouse_product_name = (TextView) convertView.findViewById(R.id.tv_warehouse_product_name);
			holder.tv_warehouse_plan_count = (TextView) convertView.findViewById(R.id.tv_warehouse_plan_count);
			holder.tv_warehouse_real_count = (TextView) convertView.findViewById(R.id.tv_warehouse_real_count);
			
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		/*if (position == 1) {
			convertView.setBackgroundColor(context.getResources().getColor(R.color.scanner_text_identify));
		} else {
			convertView.setBackgroundColor(context.getResources().getColor(R.color.white));
		}*/
		holder.tv_warehouse_his_serial.setText(beans.size() - position + "");
		JinLiquorOutWarehouseBean b = beans.get(position);
		holder.tv_warehouse_no.setText("单        号：" + b.getOutWarehouseNo().replaceAll("\\d{4}(?!$)", "$0  "));
		holder.tv_warehouse_dealer_name.setText("经  销  商："+ b.getDealerName());
		holder.tv_warehouse_product_name.setText("产品名称："+ b.getProductName());
		holder.tv_warehouse_plan_count.setText("订单数量：" + b.getPlanTrayCount()+"袋" );
		holder.tv_warehouse_real_count.setText("已出数量：" + b.getRealTrayCount()+"袋");
		
		return convertView;
	}

	private class ViewHolder{
		private TextView tv_warehouse_his_serial;
		private TextView tv_warehouse_no;
		private TextView tv_warehouse_dealer_name;
		private TextView tv_warehouse_product_name;
		private TextView tv_warehouse_plan_count;
		private TextView tv_warehouse_real_count;
	}
	
}
