package nckd.jxccl.sit.hcsi.formplugin.web.annualincome;

import kd.bos.form.CloseCallBack;
import kd.bos.form.FormShowParameter;
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.list.plugin.AbstractListPlugin;
import kd.sdk.plugin.Plugin;

import java.util.Map;

/**
 * 标准单据列表插件
 */
public class SitAnnualIncomeBillListPlugin extends AbstractListPlugin implements Plugin {

    @Override
    public void beforeDoOperation(BeforeDoOperationEventArgs args) {
        super.beforeDoOperation(args);
        FormOperate formOperate = (FormOperate)args.getSource();
        String opKey = formOperate.getOperateKey();
        switch (opKey) {
            case "donothing_calculate":
                this.openCalculatePage();
                break;
        }
    }

    public void openCalculatePage() {
        FormShowParameter formShowParameter = new FormShowParameter();
        formShowParameter.setShowTitle(false);
        formShowParameter.setFormId("nckd_incomecalselectform");
        formShowParameter.getOpenStyle().setShowType(ShowType.Modal);
        formShowParameter.setCloseCallBack(new CloseCallBack(this, "calculate"));
        this.getView().showForm(formShowParameter);
    }

    @Override
    public void closedCallBack(ClosedCallBackEvent closedCallBackEvent) {
        super.closedCallBack(closedCallBackEvent);
        String actionId = closedCallBackEvent.getActionId();
        if ("calculate".equals(actionId)) {
            if(closedCallBackEvent.getReturnData() != null) {
                int successCount = (int) closedCallBackEvent.getReturnData();
                this.getView().showSuccessNotification("计算成功，共" + successCount + "条数据");
                this.getView().invokeOperation("refresh");
            }
        }
    }
}