package com.yem.wm.im.servicerepair.form;

import com.google.common.collect.Maps;
import com.yem.wm.utils.FunctionalCommon;
import com.yem.wm.utils.YEM;
import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.datamodel.IDataModel;
import kd.bos.extplugin.sample.AbstractFormPlugin;
import kd.bos.form.CloseCallBack;
import kd.bos.form.FormShowParameter;
import kd.bos.form.IFormView;
import kd.bos.form.ShowType;
import kd.bos.form.events.BeforeDoOperationEventArgs;
import kd.bos.form.events.ClosedCallBackEvent;
import kd.bos.form.operate.FormOperate;
import kd.bos.servicehelper.operation.SaveServiceHelper;

import java.util.HashMap;

/**
 * @Description: TODO
 * @Date: 2024/8/29 10:55
 * @Created: by ZZSLL
 */

public class ServiceRepairFormPlugin extends AbstractBillPlugIn {
    @Override
    public void beforeDoOperation(BeforeDoOperationEventArgs e) {
        super.beforeDoOperation(e);
        FormOperate source = (FormOperate) e.getSource();
        String key = source.getOperateKey();
        IFormView view = this.getView();
        if ("do_void".equals(key)) {
            FormShowParameter fsp = new FormShowParameter();
            fsp.setFormId("yem_voidreason");
            fsp.getOpenStyle().setShowType(ShowType.Modal);
            fsp.setCloseCallBack(new CloseCallBack(this, "voidreason"));
            view.showForm(fsp);
        }
    }

    @Override
    public void closedCallBack(ClosedCallBackEvent e) {
        super.closedCallBack(e);
        IFormView view = this.getView();
        String actionId = e.getActionId();
        IDataModel model = this.getModel();
        DynamicObject dataEntity = model.getDataEntity(true);
        if ("voidreason".equals(actionId)) {
            SaveServiceHelper.save(new DynamicObject[]{dataEntity});
            view.invokeOperation("refresh");
        }
    }
}
