package com.gx.obe.evaluation.step.composite.struct;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

import com.gx.obe.ColorConstants;
import com.gx.obe.components.core.vo.Performance;
import com.gx.obe.components.core.vo.PerformanceDetails;
import com.gx.obe.evaluation.step.inter.IStruct;
import com.gx.obe.util.utils.DateUtils;
import com.gx.obe.util.utils.ObjectUtils;
import com.gx.obe.web.entity.Struct;

/**
 * @Description: 同业业绩
 * @author chenxw
 */
public class PerformanceComposite extends Composite implements IStruct {
	private Label purchasingUnitLabel;
	private Label partnerLabel;
	private Label singningDateLabel;
	private Label singningTotalLabel;
	private Label purchaserLabel;
	private Label purchaserPhoneLabel;
	private Performance performance;
	private List<PerDetailsComposite> composites = new ArrayList<PerDetailsComposite>();
	private Struct struct;
	
	/**
	 * Create the composite.
	 * 
	 * @param parent
	 * @param style
	 */
	public PerformanceComposite(Composite parent, int style) {
		super(parent, style);
		setLayout(new GridLayout(2, false));
		
		Label label = new Label(this, SWT.NONE);
		label.setForeground(ColorConstants.FONT_BLACK_COLOR);
		label.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
		label.setText("采购单位：");
		
		purchasingUnitLabel = new Label(this, SWT.WRAP);
		purchasingUnitLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label label_1 = new Label(this, SWT.NONE);
		label_1.setForeground(ColorConstants.FONT_BLACK_COLOR);
		label_1.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
		label_1.setText("供货单位：");
		
		partnerLabel = new Label(this, SWT.WRAP);
		partnerLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label label_2 = new Label(this, SWT.NONE);
		label_2.setForeground(ColorConstants.FONT_BLACK_COLOR);
		label_2.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
		label_2.setText("签订日期：");
		
		singningDateLabel = new Label(this, SWT.WRAP);
		singningDateLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label label_3 = new Label(this, SWT.NONE);
		label_3.setForeground(ColorConstants.FONT_BLACK_COLOR);
		label_3.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
		label_3.setText("合同金额（万元）：");
		
		singningTotalLabel = new Label(this, SWT.WRAP);
		singningTotalLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label label_4 = new Label(this, SWT.NONE);
		label_4.setForeground(ColorConstants.FONT_BLACK_COLOR);
		label_4.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
		label_4.setText("买方业务代表：");
		
		purchaserLabel = new Label(this, SWT.WRAP);
		purchaserLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label label_5 = new Label(this, SWT.NONE);
		label_5.setForeground(ColorConstants.FONT_BLACK_COLOR);
		label_5.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
		label_5.setText("代表联系电话：");
		
		purchaserPhoneLabel = new Label(this, SWT.WRAP);
		purchaserPhoneLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
	}
	
	/**
	 * @Description: 刷新
	 * @author chenxw
	 * @param struct
	 */
	public void refresh(Struct struct) {
		this.struct = struct;
		performance = struct.getPerformance();
		purchasingUnitLabel.setText(ObjectUtils.getObjString(performance.getPurchasingUnit()));
		partnerLabel.setText(ObjectUtils.getObjString(performance.getPartner()));
		singningDateLabel.setText(ObjectUtils.getObjString(DateUtils.getFormat(performance.getSingningDate(), "yyyy年MM月dd日")));
		singningTotalLabel.setText(ObjectUtils.getObjString(performance.getSingningTotal()));
		purchaserLabel.setText(ObjectUtils.getObjString(performance.getPurchaser()));
		purchaserPhoneLabel.setText(ObjectUtils.getObjString(performance.getPurchaserPhone()));
		
		for (PerformanceDetails performanceDetails : performance.getDetailsList()) {
			PerDetailsComposite composite = new PerDetailsComposite(this, SWT.NONE);
			GridData gd_composite = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
			gd_composite.heightHint = 140;
			composite.setLayoutData(gd_composite);
			composite.refresh(performanceDetails);
			composites.add(composite);
		}
	}
	
	/**
	 * @Description: 设置是否编辑
	 * @author chenxw
	 * @param isEdit
	 */
	public void setEdit(boolean isEdit) {
		for (PerDetailsComposite composite : composites) {
			composite.setEdit(isEdit);
		}
	}
	
	/**
	 * @Description: 刷新编辑数据
	 * @author chenxw
	 */
	public void refreshEditData() {
		struct.setPerformance(performance);
	}
	
	/**
	 * @Description: 获取标题名称
	 * @author chenxw
	 * @return
	 */
	public String getTopName() {
		return ObjectUtils.getObjString(performance.getPurchasingUnit());
	}
	
	protected void checkSubclass() {}
	
}
