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

/**
 * 待开抬头分页查询
 * @param {String} customerName 原发票请求流水号
 * @param {String} createTimeEnd 范围查询-结束时间
 * @param {String} createTimeBegin 范围查询-开始时间
 */
function getTaitouTodo({ customerName, createTimeEnd, createTimeBegin, pageNum = 1, pageSize = 10 }) {
    const url = '/sys/taitou/todo/findPage'
    let token = cache.getToken()
    let mobile = JSON.parse(cache.getSession('user')).account
    let company = JSON.parse(cache.getSession('company'))
    let entTaxId = company.entTaxId
    let args = {
        belongEntTaxId: entTaxId,
        mobile: mobile,
        reqChannel: 4,
        pageNum: pageNum,
        pageSize: pageSize,
    };
    if (customerName != '') {
        args.customerName = customerName
    }
    if (createTimeEnd != '') {
        args.createTimeEnd = createTimeEnd
    }
    if (createTimeBegin != '') {
        args.createTimeBegin = createTimeBegin
    }
    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 {Array} delList : 待开抬头列表
 */
function deleteTaitouTodo(delList) {
    let mobile = JSON.parse(cache.getSession('user')).account
    const url = '/sys/taitou/todo/delete'
    let token = cache.getToken()
    let args = {
        mobile: mobile,
        reqChannel: 4,
        delList: delList
    }
    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 {
    getTaitouTodo,
    deleteTaitouTodo
}
