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

/**
 * 根据用户当前选中的税号查询企业信息
 */
function FindEntInfoByCurrentEnt() {
    const url = '/sys/entInfo/findByEntTaxId'
    let token = cache.getToken()
    let entTaxId = JSON.parse(cache.getSession('company')).entTaxId
    let args = {
        entTaxId: entTaxId
    }
    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)
                }
            })
    })
}

/**
 * 获取发票认证网站地址
 */
function GetInvoiceAuthenUrl() {
    const url = '/sys/entInfo/getInvoiceAuthenUrl'
    let token = cache.getToken()
    let entTaxId = JSON.parse(cache.getSession('company')).entTaxId
    let args = {
        entTaxId: entTaxId
    }
    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} ispId 服务商id
 */
function syncSkRates(ispId = '') {
    const url = '/sys/entInfo/syncSkRates'
    let token = cache.getToken()
    let entTaxId = JSON.parse(cache.getSession('company')).entTaxId
    let args = {
        entTaxId: entTaxId,
        reqChannel: 4
    }
    if (ispId) {
        args.ispId = ispId;
    }
    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 {
    FindEntInfoByCurrentEnt,
    GetInvoiceAuthenUrl,
    syncSkRates
}
