package nckd.jimin.jyyy.hr.wtc.wtabm.opplugin.web.vaapply;

import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.bill.BillOperationStatus;
import kd.bos.bill.BillShowParameter;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.form.field.FieldEdit;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.orm.query.QFilter;
import kd.hr.hbp.business.servicehelper.HRBaseServiceHelper;
import kd.sdk.plugin.Plugin;
import kd.wtc.wtabm.formplugin.web.vaupdate.VaUpdateBillEdit;

import java.util.EventObject;

/**
 * 单据界面插件
 */
public class VaUpdateBillEditEx extends AbstractBillPlugIn implements Plugin {

    private static final Log LOG = LogFactory.getLog(VaUpdateBillEditEx.class);


    @Override
    public void afterBindData(EventObject e) {
        super.afterBindData(e);
        this.getModel().beginInit();
        BillShowParameter formShowParameter = (BillShowParameter)this.getView().getFormShowParameter();
        BillOperationStatus status = formShowParameter.getBillStatus();
        Long id;
        if (status.equals(BillOperationStatus.ADDNEW)) {
            id = (Long)formShowParameter.getCustomParam("parentid");
            this.copyModel(id);
            this.getModel().endInit();
        }
    }

    /**
     * 携带二开字段到变更单上
     * @param parentId
     */
    private void copyModel(Long parentId) {
        HRBaseServiceHelper serviceHelper = new HRBaseServiceHelper("wtabm_vaapply");
        DynamicObject parentDynObj = serviceHelper.loadDynamicObject(new QFilter("id", "=", parentId));
        this.getModel().setValue("nckd_isupdateperson", parentDynObj.get("nckd_isupdateperson"));
        this.getModel().setValue("nckd_islongleave", parentDynObj.get("nckd_islongleave"));
        this.getModel().setValue("nckd_iscancelleave", parentDynObj.get("nckd_iscancelleave"));
        this.getView().updateView("fieldsetpanelap21");
    }
}