import request from '@/utils/request'
import { download } from '@/utils/request'
import {blobValidate} from "@/utils/ruoyi";
import errorCode from "@/utils/errorCode";
import {ElMessage} from "element-plus";
// 查询划款明细列表
export function listCollection(query) {
    request.defaults.baseURL = '/ezhizao-yzbh-financial'
    return request({
        url: '/business/collectionDetail/DetailList',
        method: 'post',
        data: query
    })
}

export function exportCollection(query,filename) {
    request.defaults.baseURL = '/ezhizao-yzbh-financial'
    return request({
        url: `/business/collectionDetail/export`,
        method: 'post',
        data: query,
        responseType: 'blob',
        timeout: 1000000
    }).then(async (data) => {
        const isLogin = await blobValidate(data);
        if (isLogin) {
            const blob = new Blob([data]);
            saveAs(blob, filename);
        } else {
            const resText = await data.text();
            const rspObj = JSON.parse(resText);
            const errMsg =
                errorCode[rspObj.code] || rspObj.msg || errorCode["default"];
            ElMessage.error(errMsg);
        }
    })
        .catch((r) => {
            console.error(r);
            ElMessage.error("下载文件出现错误，请联系管理员！");
        });
}