import request from '@/router/axios';

export const getList = (current, size, params) => {
    return request({
        url: '/api/blade-manager/wbsTree/lazy-tree?parentId=0',
        method: 'get',
        params: {
            ...params,
            current,
            size,
        }
    })
}

export const getLazytree = (wbsId, parentId, tenantId, params) => {
    return request({
        url: '/api/blade-manager/wbsTree/lazy-tree',
        method: 'get',
        params: {
            ...params,
            wbsId,
            parentId,
            tenantId,
        }
    })
}

export const getAlltree = (tenantId, type = '', wbsId, params) => {
    return request({
        url: '/api/blade-manager/wbsTree/tree',
        method: 'get',
        params: {
            ...params,
            tenantId,
            type,
            wbsId
        }
    })
}

export const getDetail = (id) => {
    return request({
        url: '/api/blade-manager/wbsTree/detail',
        method: 'get',
        params: {
            id
        }
    })
}

export const remove = (ids) => {
    return request({
        url: '/api/blade-manager/wbsTree/remove',
        method: 'post',
        params: {
            id: ids,
        }
    })
}

export const add = (row) => {
    return request({
        url: '/api/blade-manager/wbsTree/submit',
        method: 'post',
        data: row
    })
}

export const update = (row) => {
    return request({
        url: '/api/blade-manager/wbsTree/submit',
        method: 'post',
        data: row
    })
}

export const selectByNodeTable = (id, params) => {
    return request({
        url: '/api/blade-manager/wbsTree/getByNodeTable',
        method: 'get',
        params: {
            ...params,
            id
        }
    })
}

export const saveFormAndElement = (formElementDTO) => {
    return request({
        url: '/api/blade-manager/wbsTree/saveFormAndElement',
        method: 'post',
        data: formElementDTO
    })
}

export const selectFormElements = (id, params) => {
    return request({
        url: '/api/blade-manager/wbsTree/getFormElements',
        method: 'get',
        params: {
            ...params,
            id
        }
    })
}
export const removeTableById = (id, params) => {
    return request({
        url: '/api/blade-manager/wbsTree/removeTableById',
        method: 'get',
        params: {
            ...params,
            id
        }
    })
}

export const importWbsTree = (froms) => {
    return request({
        url: '/api/blade-manager/wbsTree/import-wbsTree',
        method: 'post',
        //设置请求头
        headers: { "Content-Type": "multipart/form-data" },
        data: froms
    })
}

export const exportTemplate = () => {
    return request({
        url: '/api/blade-manager/wbsTree/export-template',
        method: 'get',
        responseType: 'arraybuffer'
    })
}


//查询当前节点的同级节点
export const findWbsTreeSameLevel = (params) => {
    return request({
        url: '/api/blade-manager/wbsTree/getWbsTreeSameLevel',
        method: 'get',
        params
    })
}

//查询当前节点的同级节点
export const wbsTreeSort = (data) => {
    return request({
        url: '/api/blade-manager/wbsTree/submitWbsTreeSort',
        method: 'post',
        data
    })
}

//查询当前节点下的所有表单
export const findWbsTreeTableSameLevel = (params) => {
    return request({
        url: '/api/blade-manager/wbsFormElement/getWbsTreeTableSameLevel',
        method: 'get',
        params
    })
}

//表单排序
export const wbsTreeTableSort = (data) => {
    return request({
        url: '/api/blade-manager/wbsFormElement/submitWbsTreeTableSort',
        method: 'post',
        data
    })
}

// 私有wbs树当前节点同级节点
export const findWbsTreePrivateSameLevel = (params) => {
    return request({
        url: `/api/blade-manager/wbsPrivate/getWbsTreePrivateSameLevel`,
        method: 'get',
        params
    })
}

// wbs私有树节点手动排序
export const wbsTreePrivateSort = (data) => {
    return request({
        url: '/api/blade-manager/wbsPrivate/submitWbsTreePrivateSort',
        method: 'post',
        data
    })
}

// 节点参数列表
export const parameters = (params) => {
    return request({
        url: '/api/blade-manager/param/list',
        method: 'get',
        params
    })
}

// 保存参数
export const saveOrUpdateBatch = (data) => {
    return request({
        url: '/api/blade-manager/param/saveOrUpdateBatch',
        method: 'post',
        data
    })
}

// 参数名称接口
export const keymap = (params) => {
    return request({
        url: '/api/blade-manager/param/keymap',
        method: 'get',
        params
    })
}

// 上传元素
export const importwbsTreeFormBatch = (data) => {
    return request({
        url: '/api/blade-manager/wbsTree/import-wbsTreeFormBatch',
        method: 'post',
        data
    })
}

// 上传元素
export const exportBatchTemplate = (params) => {
    return request({
        url: '/api/blade-manager/wbsTree/export-batchTemplate',
        method: 'get',
        params
    })
}


// 公有编辑元素
export const updateBatchNodeTableInfo = (data) => {
    return request({
        url: '/api/blade-manager/wbsTree/updateBatchNodeTableInfo',
        method: 'post',
        data
    })
}


// 私有元素
export const updateBatchNodeTableInfo2 = (data) => {
    return request({
        url: '/api/blade-manager/wbsPrivate/updateBatchNodeTableInfo',
        method: 'post',
        data
    })
}

export const updateStatus = (params) => {
    return request({
        url: '/api/blade-manager/wbsPrivate/updateStatus',
        method: 'get',
        params
    })
}


export const getNodeTabAndParam = (id, params) => {
    return request({
        url: '/api/blade-manager/wbsTree/getNodeTabAndParam',
        method: 'get',
        params: {
            ...params,
            id
        }
    })
}

export const submitFullName = (id, fullNames, params) => {
    return request({
        url: '/api/blade-manager/wbsTree/submit-full-name',
        method: 'post',
        params: {
            ...params,
            id,
            fullNames,
        }
    })
}
