package com.yem.ensign.weboffice.form;

import java.util.HashMap;
import java.util.Map;

import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.bill.OperationStatus;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.form.CloseCallBack;
import kd.bos.form.FormShowParameter;
import kd.bos.form.IFormView;
import kd.bos.form.ShowType;
import kd.bos.form.events.AfterDoOperationEventArgs;

/**
 * 业务单据webOffice表单插件
 * @author 86173
 *
 */
public class WebOfficeBillEdit extends AbstractBillPlugIn{
	@Override
	public void afterDoOperation(AfterDoOperationEventArgs e) {
		super.afterDoOperation(e);
		String key = e.getOperateKey();
		switch (key) {
			case "webofficeconfig":
				open(true);
				break;
			case "webofficeprint":
				open(false);
				break;
	
			default:
				break;
		}
	}
	
	private void open(boolean isEdit) {
		DynamicObject bill = this.getModel().getDataEntity(true);
		FormShowParameter fsp = new FormShowParameter();
		fsp.setStatus(OperationStatus.ADDNEW);
		fsp.getOpenStyle().setShowType(ShowType.Modal);
		Map<String, Object> entryInfo = new HashMap<String, Object>();
		entryInfo.put("yem_billId", bill.getLong("id"));
		entryInfo.put("yem_bill", bill.getDynamicObjectType().getName());
		entryInfo.put("isEdit", isEdit);
		entryInfo.put("attachmentpanel", "attachmentpanel");
		if(bill.containsProperty("yem_minerals")) {
			entryInfo.put("yem_ismaterialgroupid", true);
			entryInfo.put("yem_materialgroupid", bill.getDynamicObject("yem_minerals")==null?0L:bill.getDynamicObject("yem_minerals").getLong("id"));
		}
		fsp.setCustomParams(entryInfo);
		CloseCallBack callBack = new CloseCallBack(this, "yem_webofficemodelchoice");
		fsp.setCloseCallBack(callBack);
		fsp.setFormId("yem_webofficemodelchoice");
		IFormView view = this.getView();
		view.showForm(fsp);
	}
}
