package com.yem.em.ass.assequipment.from;

import com.yem.wm.utils.StringUtils;
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 kd.bos.form.plugin.AbstractFormPlugin;

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

/**
 * @author zhouc
 * @date 2023/10/31 18:15
 * @className AssEquipmentDynamicEdit
 * @description 总成配件图册表单插件
 */
public class AssEquipmentDynamicEdit extends AbstractFormPlugin {
    @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());
        }
        if (customParas.containsKey("yem_analysistdate")) {
            cache.put("yem_analysistdate",customParas.get("yem_analysistdate").toString());
        }
        DynamicObject dataEntity = this.getModel().getDataEntity(true);
        //电子目录编码
        String number = dataEntity.getString("number");
        if (StringUtils.isNotEmpty(number)) {
            FormShowParameter bsp = new FormShowParameter();
            bsp.setFormId("yem_em_assepcdynamic");
            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("type", "assets");
//            entryInfo.put("parentpageid", cache.get("parentpageid"));
            if (cache.get("complete") != null) {
                entryInfo.put("complete", cache.get("complete"));
            }
            if (cache.get("complete") != null) {
                entryInfo.put("yem_analysistdate", cache.get("yem_analysistdate"));
            }
            bsp.setCustomParams(entryInfo);
            bsp.setHasRight(true);
            bsp.setStatus(OperationStatus.ADDNEW);
            bsp.setOpenStyle(openStyle);
            this.getView().showForm(bsp);
        }
    }
}
