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

/**
 * 企业资料领取方式查询
 */
function getEntDoc() {
    const url = '/sys/entDoc/send/getSendInfo'
    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} getWay 1：自取  2：邮寄到付 3：邮寄寄付后返款
 * @param {String} receiverName  收件人姓名
 * @param {String} receiverAddress  快递地址
 * @param {String} mobilePhoneNumber 移动电话
 * @param {String} zipCode 邮编
 * @param {String} fixedPhoneNumber 固定电话
 */
function saveEntDoc({getWay, receiverName, receiverAddress, mobilePhoneNumber, zipCode, fixedPhoneNumber }) {
    const url = '/sys/entDoc/send/save'
    let token = cache.getToken()
    let mobile = JSON.parse(cache.getSession('user')).account
    let entTaxId = JSON.parse(cache.getSession('company')).entTaxId
    let entName = JSON.parse(cache.getSession('company')).entName
    let args = {
        entTaxId: entTaxId,
        entName: entName,
        getWay: getWay,
        mobile: mobile,
        reqChannel: 4,
    }
    if (getWay == 2 || getWay == 3) {
        args.receiverName = receiverName;
        args.receiverAddress = receiverAddress;
        args.mobilePhoneNumber = mobilePhoneNumber;
        args.zipCode = zipCode;
        args.fixedPhoneNumber = fixedPhoneNumber;
    }
    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)
                }
            })
    })
}

const ENT_DOC = {
    getEntDoc,
    saveEntDoc
}

export default ENT_DOC