package com.yem.em.bd.etcmanual.from;

import com.yem.wm.utils.StringUtils;
import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.bill.OperationStatus;
import kd.bos.context.RequestContext;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.form.FormShowParameter;
import kd.bos.form.IPageCache;
import kd.bos.form.OpenStyle;
import kd.bos.form.ShowType;

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

/**
 * @author zhouc
 * @date 2023/8/24 18:47
 * @className NewEtcmanualEdit
 * @description 设备电子目录(新)表单插件
 *
 */
public class NewEtcmanualEdit extends AbstractBillPlugIn {

    @Override
    public void afterBindData(EventObject e) {
        super.afterBindData(e);
        FormShowParameter showParameter = this.getView().getFormShowParameter();
        Map<String, Object> customParas = showParameter.getCustomParams();
        IPageCache cache = this.getPageCache();
        if(customParas.containsKey("parentpageid")){
            cache.put("parentpageid", customParas.get("parentpageid").toString());
        }
        if(customParas.containsKey("complete")){
            cache.put("complete", customParas.get("complete").toString());
        }
        DynamicObject dataEntity = this.getModel().getDataEntity(true);
        //电子目录编码
        String number = dataEntity.getString("number");
        if(StringUtils.isNotEmpty(number)){
            FormShowParameter bsp = new FormShowParameter();
            bsp.setFormId("yem_em_epcdynamic");
            OpenStyle openStyle = new OpenStyle();
            openStyle.setShowType(ShowType.InContainer);
           openStyle.setTargetKey("yem_flexpanelap");
//            openStyle.setTargetKey("yem_demo1");
            Map<String, Object> entryInfo = new HashMap<String, Object>();
            entryInfo.put("etcId", dataEntity.getString("id"));
            entryInfo.put("number", number);
            entryInfo.put("name", dataEntity.getString("name"));
            entryInfo.put("orgId", RequestContext.get().getOrgId());
            entryInfo.put("parentpageid", cache.get("parentpageid"));
            if(cache.get("complete")!=null){
                entryInfo.put("complete", cache.get("complete"));
            }
            bsp.setCustomParams(entryInfo);
            bsp.setHasRight(true);
            bsp.setStatus(OperationStatus.ADDNEW);
            bsp.setOpenStyle(openStyle);
            this.getView().showForm(bsp);
        }
    }
}