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

/**
 * 获取发票清单
 * @param {String} entTaxId 企业税号
 * @param {String} orderId 订单id
 * @param {Number} pageNum 当前页码  默认为1
 * @param {Number} pageSize 每页数量  默认为10
 */
function GetGoodsList(entTaxId, orderId, pageNum = 1, pageSize = 10) {
    const url = '/sys/invoice/pageItems'
    let token = cache.getToken()
    // let entTaxId = JSON.parse(cache.getLocal('company')).entTaxId
    let args = {
        orderId: orderId,
        pageNum: pageNum,
        pageSize: pageSize,
        entTaxId: entTaxId,
        reqChannel: 4
    }
    console.log('获取发票的项目明细 参数：')
    console.log(args)
    return new Promise(function (resolve, reject) {
        AxiosRequestData(url, token, args, false, 2)
            .then(val => {
                console.log('获取发票的项目明细 结果：')
                console.log(val)
                if (val.code === 0) {
                    resolve(val)
                } else {
                    reject(val.msg)
                }
            })
    })
}

/**
 * 获取正数发票版式文件下载地址
 * @param {String} invoiceCode 发票代码
 * @param {String} invoiceNumber 发票号码
 */
function GetInvoiceDownloadUrl({ invoiceCode, invoiceNumber }) {
    const url = '/sys/blueInvoice/formatFile'
    let token = cache.getToken()
    let company = JSON.parse(cache.getLocal('company'))
    let entTaxId = company.entTaxId
    let args = {
        invoiceCode: invoiceCode,
        invoiceNumber: invoiceNumber,
        entTaxId: entTaxId,
        reqChannel: 4,
    };
    console.log('获取正数发票版式文件下载地址 参数：')
    console.log(args)
    return new Promise(function (resolve, reject) {
        AxiosRequestData(url, token, args, false, 1)
            .then(val => {
                console.log('获取正数发票版式文件下载地址 结果：')
                console.log(val)
                if (val.code == 0) {
                    resolve(val)
                } else {
                    reject(val.msg)
                }
            })
    })
}

export {
    GetGoodsList,
    GetInvoiceDownloadUrl
}