/**
 * FlowUtil流程操作工具类
 * @author cls
 * @date 2021-01-30
 * import { FlowUtil } from "@birt/funclib/FlowUtil"
 */
import hiSetting from '@birt/hiSetting';

export const FlowUtil = {
    /**
     * showdoc
     * @catalog JS工具类/FlowUtil
     * @title 审批意见
     * @description 根据任务参数，获取流程审批信息
     * @method static
     * @url FlowUtil.getApprovalInfo({ request, url, ftaskguid, flowtype })
     * @param request 请求对象
     * @param url 请求地址 
     * @param ftaskguid 任务GUID
     * @param flowtype 任务类型 
     * @return 审批信息
     * @remark 测试用例
     */
    getApprovalInfo({ request, url, ftaskguid, flowtype }) {
        let promise
        let dataUrl = url || hiSetting.getApprovalInfo
        if (ftaskguid) {
            if (dataUrl.indexOf('?') == -1)
                dataUrl = dataUrl + "?ftaskguid=" + ftaskguid;
            else
                dataUrl = dataUrl + "&ftaskguid=" + ftaskguid;
        }
        if (flowtype) {
            if (dataUrl.indexOf('?') == -1)
                dataUrl = dataUrl + "?flowtype=" + flowtype;
            else
                dataUrl = dataUrl + "&flowtype=" + flowtype;
        }

        promise = request({
            url: dataUrl,
            method: 'post'
        })
        return promise
    },
    // 处理流程
    processFlow({ request, url, data }) {
        let promise;
        let dataUrl = url || hiSetting.processFlow;
        promise = request({
            url: dataUrl,
            data: {
                __body: JSON.stringify(data)
            },
            method: 'post'
        })
        return promise
    },
    // 任务中心查询
    queryTask({ request, url, param }) {
        let promise;
        let dataUrl = url || hiSetting.queryTask;
        promise = request({
            url: dataUrl,
            data: param,
            method: 'post'
        })
        return promise
    },
    // 打开流程接口
    getFlowInfo({ request, url, data }) {
        let promise;
        promise = request({
            url: url,
            data: data,
            method: 'post'
        })
        return promise
    },
    // 根据单号打开流程
    openByNumber({ request, url, fordernumber }) {
        let promise;
        let dataUrl = url || hiSetting.openByNumber;
        let openurl = `${dataUrl}?fordernumber=${fordernumber}`
        promise = request({
            url: openurl,
            method: 'get'
        })
        return promise
    },
    // 撤回
    withdrawtask({ request, url, ftaskguid }) {
        let promise;
        let dataUrl = url || hiSetting.withdrawtask;
        let path = `${dataUrl}?ftaskguid=${ftaskguid}`
        promise = request({
            url: path,
            method: 'get'
        })
        return promise
    },
    // 流程监控
    taskDiagram({ request, url, forderguid, fmodelpath, fversion }) {
        let promise;
        let dataUrl = url || hiSetting.taskDiagram;
        let path = `${dataUrl}?forderguid=${forderguid}&fmodelpath=${fmodelpath}&fversion=${fversion}`
        promise = request({
            url: path,
            method: 'get'
        })
        return promise
    }
};
