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

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

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.common.config.Config;
import cn.net.caoyao.cpzshandset.service.thread.ThreadReqTools;


public class CarLingLiaoAdapter extends BaseAdapter{
	private List<Map<String ,String>> list;
	
	public CarLingLiaoAdapter(List<Map<String ,String>> list) {
		this.list = list;
	}
	public void refreshData(List<Map<String ,String>> list){
		this.list = list;
		notifyDataSetChanged();
	}
	@Override
	public int getCount() {
		
		return list.size();
	}

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

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

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Context context = parent.getContext();
		ViewHolder holder = null;
		
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.car_sale_listitem, parent, false);
			holder = new ViewHolder();
			holder.tv_item1 = (TextView) convertView.findViewById(R.id.tv_item1);
			holder.tv_item2 = (TextView) convertView.findViewById(R.id.tv_item2);
			holder.tv_item3 = (TextView) convertView.findViewById(R.id.tv_item3);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		Map<String,String> b = list.get(position);
		
		holder.tv_item1.setText("车  牌  号：" + b.get("car_no"));
		holder.tv_item2.setText("领料日期："+b.get("lingLiaodate"));
		
		int submit_status = Integer.parseInt(b.get("submit_status"));
		if (submit_status == Config.SUBMIT_STATUS_SUBMIT_FAIL) {
			holder.tv_item3.setText("状        态：提交失败(错误码:" + b.get("error_code") + ")\n原        因：" + ThreadReqTools.getErrorMsg(Integer.parseInt(b.get("error_code"))));
		} else if(submit_status == Config.SUBMIT_STATUS_PIC_SUBMIT_FAIL){
			holder.tv_item3.setText("状        态:上传图片失败("+b.get("error_code")+")");
		} else {
			holder.tv_item3.setText("状        态:");
		}
		
		
		/*int errCode  =  Integer.parseInt(b.get("error_code"));
		if(errCode!=0){
			
			holder.tv_item3.setText("状        态：提交失败(错误码:" + b.get("error_code") + ")\n原        因：" + ThreadReqTools.getErrorMsg(Integer.parseInt(b.get("error_code"))));
		}else{
			holder.tv_item3.setText("状        态:");
		} */ 
		
	
		return convertView;
	}
	private class ViewHolder{
		TextView tv_item1;
		TextView tv_item2;
		TextView tv_item3;
	}
}
