package com.yem.ia.intebilllogon.dynamic;

import java.util.*;

import kd.bos.dataentity.resource.ResManager;
import kd.bos.dataentity.serialization.SerializationUtils;
import kd.bos.dataentity.utils.StringUtils;
import kd.bos.entity.EntityMetadataCache;
import kd.bos.entity.MainEntityType;
import kd.bos.entity.datamodel.IDataModel;
import kd.bos.entity.tree.TreeNode;
import kd.bos.form.FormShowParameter;
import kd.bos.form.IFormView;
import kd.bos.form.control.Control;
import kd.bos.form.control.TreeView;
import kd.bos.form.events.AfterDoOperationEventArgs;
import kd.bos.form.plugin.AbstractFormPlugin;

import java.util.EventObject;

/**
 * @author zhouc
 * @date 2023/8/16 15:30
 * @className SelectfieldDynmaico
 * @description 单据字段选择动态表单插件
 */
public class SelectfieldDynmaico extends AbstractFormPlugin {
    public SelectfieldDynmaico() {
    }

    @Override
    public void afterCreateNewData(EventObject e) {
        super.afterCreateNewData(e);
        IFormView view = this.getView();
        IDataModel model = this.getModel();
        FormShowParameter fsp = view.getFormShowParameter();
        Map<String, Object> customParams = fsp.getCustomParams();
        Object rowIndex = customParams.get("rowIndex");
        if (customParams.size() > 0) {
            String yem_formidnumber = (String) customParams.get("yem_formidnumber");
            String yem_iaentitytype = (String) customParams.get("yem_iaentitytype");//H:单据头  D:单据体
        }
    }

    @Override
    public void registerListener(EventObject e) {
        super.registerListener(e);
        this.addClickListeners(new String[]{"btnok", "btncancel"});
    }

    @Override
    public void click(EventObject evt) {
        super.click(evt);
        Control source = (Control) evt.getSource();
        String key = source.getKey();
        IFormView view = this.getView();
        IDataModel model = this.getModel();
        if (key.equals("btnok")) {
            btnok();
            view.close();
        }
    }

    @Override
    public void afterDoOperation(AfterDoOperationEventArgs e) {
        super.afterDoOperation(e);
    }

    /**
     * 点击确定事件
     */
    public void btnok() {
        IFormView view = this.getView();
        IDataModel model = this.getModel();
        FormShowParameter fsp = view.getFormShowParameter();
        Map<String, Object> customParams = fsp.getCustomParams();
        Map map = new HashMap();
        Object rowIndex = customParams.get("rowIndex");
        map.put("rowIndex", rowIndex);//行号
        map.put("yem_erpfiledformid", "billno");//ERP字段标识
        map.put("yem_erpfiledformname", "外销合同号");//ERP字段名称
        map.put("yem_erpfiledtype", "text");//ERP字段类型
        map.put("yem_filedtypename", "");//ERP基础资料标识
        map.put("yem_identifierbasic", "");//ERP基础数据唯一标识
        this.getView().returnDataToParent(map);
    }
}
