import { AxiosRequestByBearer } from '@/data/axios_request'
import cache from "@/utils/cache"

/**
 * 网上抄报税及反写清卡
 */
function taxDeclaration() {
    const url = '/v1/sk/online_tax_declaration'
    let token = cache.getToken()
    let company = JSON.parse(cache.getSession('company'))
    let entTaxId = company.entTaxId
    let taxDiscId = company.defaultDeviceInfo.taxDiscId
    let args = {
        tax_no: entTaxId,
        device_no: taxDiscId,
    }
    console.log('网上抄报税及反写清卡 参数：')
    console.log(args)
    return new Promise(function (resolve, reject) {
        AxiosRequestByBearer(url, token, args, false, 1)
            .then(val => {
                console.log('网上抄报税及反写清卡 结果：')
                console.log(val)
                if (val.code === 200) {
                    resolve(val)
                } else {
                    reject(val.msg)
                }
            })
    })
}

/**
 * 获取发票统计信息
 * @param {string} startDate 开始日期，格式yyyy-MM-dd
 * @param {string} endDate 结束日期，格式yyyy-MM-dd
 */
function getInvoiceStati(startDate, endDate) {
    const url = '/v1/sk/get_invoice_stati'
    let token = cache.getToken()
    let company = JSON.parse(cache.getSession('company'))
    let entTaxId = company.entTaxId
    let taxDiscId = company.defaultDeviceInfo.taxDiscId
    let args = {
        tax_no: entTaxId,
        device_no: taxDiscId,
        start_date: startDate,
        end_date: endDate,
    }
    console.log('获取发票统计信息 参数：')
    console.log(args)
    return new Promise(function (resolve, reject) {
        AxiosRequestByBearer(url, token, args, false, 1)
            .then(val => {
                console.log('获取发票统计信息 结果：')
                console.log(val)
                if (val.code === 200) {
                    resolve(val)
                } else {
                    reject(val.msg)
                }
            })
    })
}

const SKServer = {
    taxDeclaration,
    getInvoiceStati
}

export default SKServer