import requestKaiPiao from "@/utils/requestKaiPiao"
import requestMemberApi from "@/utils/requestMemberApi"
import requestOld from "@/utils/requestOld"


// 获取app_token
export async function handleGetAppToken(params?: any) {
    const data = await requestKaiPiao.post('/api/getAppToken.do', params)
    return data
}

// 获取 token 
export async function handleGetSDToken(params?: any) {
    const data = await requestKaiPiao.post('/api/login.do', params)
    return data
}

// 开票申请
export async function handleGetKaiPiao(bodyData: any, accessToken: string) {
    const data = await requestKaiPiao.post('/kapi/app/sim/openApi', bodyData, {
        params: {
            access_token: accessToken
        },
        headers: {
            'access_token': accessToken
        }
    })
    return data
}



// 开票申请单发票查询
export async function handleGetInvoiceSearch(bodyData: any, accessToken: string) {
    const data = await requestKaiPiao.post('/kapi/app/sim/openApi', bodyData, {
        params: {
            access_token: accessToken
        },
        headers: {
            'access_token': accessToken
        }
    })
    return data
}


// 我们自己的 开票同步接口
export async function handleSynchroBILLInterface(params: any) {
    const data = await requestOld.post('/Invoice/SynchroBILL', params)
    return data
}


// 获取用户信息
export async function handleGetPassportInfoById(params: any) {
    const data = await requestOld(`/Logging/GetPassportInfoById?UserIdEncrypted=${params?.UserIdEncrypted}`, {
        method: 'POST',
        // data:params
    })

    if (data.Result_Code !== 100) {
        return data
    }

    return data.Result_Data
}


// 获取票据信息表列表
export async function handleGetBILLList(params: any) {
    const data = await requestOld(`/Invoice/GetBILLList`, {
        method: 'POST',
        data: params
    })

    if (data.Result_Code !== 100) {
        return data
    }

    return data.Result_Data.List
}


// 票据信息的流程
export async function handleSynchroAPPLYAPPROVE(params: any) {
    const data = await requestOld(`/Office/SynchroAPPLYAPPROVE`, {
        method: 'POST',
        data: params
    })

    if (data.Result_Code !== 100) {
        return data
    }

    return data
}


// 拿到票据明细列表
export async function handleGetBILLDETAILList(params: any) {
    const data = await requestOld(`/Invoice/GetBILLDETAILList`, {
        method: 'POST',
        data: params
    })

    if (data.Result_Code !== 100) {
        return data
    }

    return data.Result_Data.List
}

// 批量同步票据明细
export async function handleSynchroBILLDETAILList(params: any) {
    const data = await requestOld(`/Invoice/SynchroBILLDETAILList`, {
        method: 'POST',
        data: params
    })

    if (data.Result_Code !== 100) {
        return data
    }

    return data
}


// 包一层的中转接口 用来解决金飘云的跨域问题
export async function handleGetForwardJDPJInterface(params: any) {
    const data = await requestMemberApi(`/ThirdInterface/ForwardJDPJInterface`, {
        method: 'POST',
        data: params
    })

    if (data.Result_Code !== 100) {
        return data
    }

    return data
}


// 拿到票据的审批流程
export async function handleGetAPPLYAPPROVEList(params: any) {
    const data = await requestOld(`/Office/GetAPPLYAPPROVEList`, {
        method: 'POST',
        data: params
    })

    if (data.Result_Code !== 100) {
        return data
    }

    return data.Result_Data.List
}