package nckd.jxccl.hr.homs.plugin.form.orgbatch;

import kd.bos.form.FormShowParameter;
import kd.bos.form.ShowType;
import kd.bos.form.events.AfterDoOperationEventArgs;
import kd.bos.form.field.BasedataEdit;
import kd.bos.form.plugin.AbstractFormPlugin;
import nckd.jxccl.hr.homs.common.orgbatch.OrgBatchConstant;

import java.util.EventObject;

/**
 * 组织复制弹窗表单插件
 * @entity: nckd_adminorgcopydialog
 * @author: jtd
 * @date: 2025-09-26 16:35
 */
public class AdminOrgCopyDialogFormPlugin extends AbstractFormPlugin {

    @Override
    public void afterBindData(EventObject e) {
        super.afterBindData(e);

        // 界面构建完成后自动触发行政组织F7弹窗
        BasedataEdit adminOrg = this.getView().getControl(OrgBatchConstant.NCKD_ADMINORG_KEY);
        if (adminOrg != null) {
            adminOrg.click();
        }
    }

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

        if (afterDoOperationEventArgs.getOperationResult().isSuccess()) {
            // 创建弹出参数对象
            FormShowParameter formShowParameter = new FormShowParameter();
            // 设置要弹出的动态表单标识
            formShowParameter.setFormId("");
            // 设置打开方式为模态框
            formShowParameter.getOpenStyle().setShowType(ShowType.Modal);
            // 设置自定义参数
            formShowParameter.setCustomParam("adminOrg", this.getModel().getValue(OrgBatchConstant.NCKD_ADMINORG_KEY));// 行政组织
            formShowParameter.setCustomParam("includeAllAdminSubOrg", this.getModel().getValue(OrgBatchConstant.NCKD_INCLUDE_ALL_SUBORG_KEY));// 包含所有下级
            formShowParameter.setCustomParam("isCopyPosition", this.getModel().getValue(OrgBatchConstant.NCKD_IS_COPY_POSITION_KEY));// 是否复制岗位
            // 执行弹出操作
            //this.getView().showForm(formShowParameter);

            // 关闭当前表单
            this.getView().close();
        }
    }
}
