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

/**
 * 修改企业开票所需简要信息
 * @param {String} entTaxId 企业税号
 * @param {String} entName 企业名
 * @param {String} entType 企业类型 一般纳税人：1; 小规模纳税人：2; 起征点以下纳税人：3
 */
function modifyEntBriefInfo({ entTaxId, entName, entType }) {
    const url = '/sys/entInfo/updateBriefInfo'
    let token = cache.getToken()
    let mobile = JSON.parse(cache.getLocal('user')).account
    let args = {
        entTaxId: entTaxId,
        entName: entName,
        entType: entType,
        mobile: mobile,
        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)
                }
            })
    })
}

/**
 * 企业绑定APPKey
 * @param {String} entTaxId 企业税号
 * @param {String} bwCloudAccount 百望云账户
 */
function bindAPPKey({ entTaxId, bwCloudAccount}) {
    const url = '/sys/entInfo/bindAppkey'
    let token = cache.getToken()
    let mobile = JSON.parse(cache.getLocal('user')).account
    let args = {
        entTaxId: entTaxId,
        bwCloudAccount: bwCloudAccount,
        mobile: mobile,
        reqChannel: 4,
    }
    console.log('企业绑定APPKey 参数：')
    console.log(args)
    return new Promise(function (resolve, reject) {
        AxiosRequestData(url, token, args, false, 1)
            .then(val => {
                console.log('企业绑定APPKey 结果：')
                console.log(val)
                if (val.code === 0) {
                    resolve(val)
                } else {
                    reject(val.msg)
                }
            })
    })
}

const ENT_INFO = {
    modifyEntBriefInfo,
    bindAPPKey
}

export default ENT_INFO