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

/**
 * 百望账户查询
 * @param {String} entTaxId 企业税号
 * @param {String} entName 企业名称
 * @param {Number} pageNum 页码
 * @param {Number} pageSize 每页数据条数
 */
function queryBWCloudInfo(entTaxId, entName, pageNum = 1, pageSize = 10) {
    const url = '/sys/bw/cloudInfo/findPage'
    let token = cache.getToken()
    let mobile = JSON.parse(cache.getLocal('user')).account
    let args = {
        entTaxId: entTaxId,
        entName: entName,
        pageNum: pageNum,
        pageSize: pageSize,
        mobile: mobile,
    };
    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} entTaxId 企业税号
 * @param {String} account 百望云账户
 * @param {String} passwd 百望云账户密码
 */
function saveBWCloudInfo(entTaxId, account, passwd) {
    const url = '/sys/bw/cloudInfo/save'
    let token = cache.getToken()
    let mobile = JSON.parse(cache.getLocal('user')).account
    let args = {
        entTaxId: entTaxId,
        account: account,
        passwd: passwd,
        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)
                }
            })
    })
}

export {
    queryBWCloudInfo,
    saveBWCloudInfo
}