import { AxiosRequestData, AxiosRequestFile } from '@/data/axios_request'
import cache from "@/utils/cache"

/**
 * 业务附属文件上传
 */
function attachedFileUpload(resultFiles, bizTyp) {
    const url = '/exts/attachedFile/upload'
    let token = cache.getToken()

    let formData = new FormData();
    formData.append('bizType', bizTyp);
    formData.append('file', resultFiles[0]);
    formData.append('reqChannel', 4);

    console.log('业务附属文件上传 参数：')
    for (var [a, b] of formData.entries()) {
        console.log(a, b);
    }
    return new Promise(function (resolve, reject) {
        AxiosRequestFile(url, token, formData).then(val => {
            console.log('业务附属文件上传 结果：');
            console.log(val);
            if (val.code == 0) {
                resolve(val);
            } else {
                reject(val.msg);
            }
        });
    })
}

const ExtService = {
    attachedFileUpload
}

export default ExtService