package nckd.jxccl.swc.init.plugin.form;

import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.dataentity.utils.StringUtils;
import kd.bos.entity.datamodel.IDataModel;
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
import kd.sdk.plugin.Plugin;

/**
 * 退休人员信息  单据界面插件
 *  @author turborao
 *  创建时间 2026-01-09
 *  描述 自定义收入证明项目获取计算
 */
@SuppressWarnings("unused")
public class DelayedRetirementDateBillPlugin extends AbstractBillPlugIn implements Plugin {

    @Override
    public void propertyChanged(PropertyChangedArgs e) {

        super.propertyChanged(e);

        String fieldKey = e.getProperty().getName();
        //因为设置其他字段时，会触发值更新方法，通过缓存“noChange”来判断，避免重复执行值更新方法
        if(StringUtils.equals(this.getPageCache().get("noChange"), "true")){
            return;
        }

        if (StringUtils.equals("nckd_committype", fieldKey) ){
            IDataModel model = this.getModel();

            if(model.getValue("nckd_committype") != null){
                this.getPageCache().put("noChange", "true");
                String commitType =   model.getValue("nckd_committype").toString();
                Object legalDate = model.getValue("nckd_legaldate");
                Object newLegalDate = model.getValue("nckd_newlegaldate");
                if(StringUtils.equals(commitType, "olddate")){
                    //原法定退休日期
                    model.setValue("nckd_commitdate", legalDate);
                }
                if(StringUtils.equals(commitType, "newdate")){
                    //现法定退休日期
                    model.setValue("nckd_commitdate", newLegalDate);
                }
            }

            this.getPageCache().put("noChange", "false");
        }
    }
}