package nckd.jimin.jyyy.bd.plugin.workflow;

import kd.bos.form.IFormView;
import kd.bos.form.IPageCache;
import kd.bos.workflow.design.plugin.AbstractWorkflowPlugin;
import kd.bos.workflow.engine.WfUtils;
import java.util.EventObject;
import static kd.bos.workflow.taskcenter.plugin.util.ApprovalPluginUtil.isPCShow;

/**
 * 会签节点审批意见不允许修改
 * 表单标识：审批处理页面(nckd_wf_approvalpage__ext)
 * @author wanghaiwu_kd
 * @date 2025/11/20
 */
public class ApprovalPageFieldEnablePlugin extends AbstractWorkflowPlugin {
    @Override
    public void afterBindData(EventObject e) {
        super.afterBindData(e);

        IFormView view = this.getView();
        boolean isPcShow = isPCShow(view.getFormShowParameter());

        if (!WfUtils.isNullObject(view)) {
            IPageCache pageCache;
            String fieldName = "";

            if (isPcShow) {
                pageCache = view.getPageCache();

                fieldName = "msg_approval";
            } else {
                IFormView parentView = view.getParentView();
                if (WfUtils.isNullObject(parentView)) {
                    return;
                }
                pageCache = parentView.getPageCache();

                fieldName = "approvalmsg";
            }

            String entityName = pageCache.get("entitynumber");
            String curnode = pageCache.get("CURNODE");

            //控制审批意见锁定：商旅对账单
            //approvalmsg
            if (curnode.contains("YunzhijiaTask")
                    && ("nckd_bustravelcheckbill".equals(entityName) || "nckd_bustravelcheckbill_mob".equals(entityName))) {
                this.getView().setEnable(false, fieldName);
            }
        }
    }
}
