package yem.wm.cm.csrm.utils;

import kd.bos.bill.OperationStatus;
import kd.bos.form.FormShowParameter;
import kd.bos.form.IFormView;
import kd.bos.form.ShowType;
import kd.bos.form.StyleCss;
import yem.base.common.utils.YEM;

import java.util.Map;

/**
 * @Description TODO
 * @Author yunshuaiwei
 * @Date 2024/6/28 9:50
 * @Version 1.0
 **/
public class BillCommonUtils {

    /**
     * 打开目标单据
     *
     * @Author yunshuaiwei
     * @Date 2024/6/28 10:02
     **/
    public static void openTargetBill(IFormView view, Map<String, Object> maps, String formId, String targetKey, OperationStatus status, ShowType showType, StyleCss styleCss) {
        FormShowParameter showParameter = new FormShowParameter();
        showParameter.setStatus(status);
        showParameter.getOpenStyle().setShowType(showType);
        showParameter.setFormId(formId);
        if (YEM.isNotEmpty(targetKey)) {
            showParameter.getOpenStyle().setTargetKey(targetKey);
        }
        if (YEM.isNotEmpty(maps)) {
            showParameter.setCustomParams(maps);
        }
        if (styleCss != null) {
            showParameter.getOpenStyle().setInlineStyleCss(styleCss);
        }
        view.showForm(showParameter);
    }


    /**
     * 打开目标单据
     *
     * @Author yunshuaiwei
     * @Date 2024/6/28 9:51
     **/
    public static void openTargetBill(IFormView view, Map<String, Object> maps, String formId, String targetKey, OperationStatus status, ShowType showType) {
        openTargetBill(view, maps, formId, targetKey, status, showType, null);
    }

    public static void openTargetBill(IFormView view, Map<String, Object> maps, String formId, OperationStatus status, ShowType showType) {
        openTargetBill(view, maps, formId, "", status, showType, null);
    }

    public static void openTargetBill(IFormView view, String formId, OperationStatus status, ShowType showType) {
        openTargetBill(view, null, formId, "", status, showType, null);
    }

    /**
     * 内嵌表单
     *
     * @Author yunshuaiwei
     * @Date 2024/6/28 11:43
     **/
    public static void openTargetInContainerBill(IFormView view, String formId, String targetKey) {
        openTargetBill(view, null, formId, targetKey, OperationStatus.ADDNEW, ShowType.InContainer, null);
    }

    /**
     * 内嵌表单
     *
     * @Author yunshuaiwei
     * @Date 2024/6/28 11:43
     **/
    public static void openTargetInContainerBill(IFormView view,Map<String, Object> maps, String formId, String targetKey) {
        openTargetBill(view, maps, formId, targetKey, OperationStatus.ADDNEW, ShowType.InContainer, null);
    }

    /**
     * 内嵌表单
     *
     * @Author yunshuaiwei
     * @Date 2024/6/28 11:43
     **/
    public static void openTargetInContainerBill(IFormView view, Map<String, Object> maps,String formId, String targetKey, StyleCss styleCss) {
        openTargetBill(view, maps, formId, targetKey, OperationStatus.ADDNEW, ShowType.InContainer, styleCss);
    }
}
